Author Topic: Codewarrior 7.1.2 optimisation problem  (Read 12589 times)

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Codewarrior 7.1.2 optimisation problem
« on: August 25, 2009, 10:08:45 AM »
Hi All

Below is a copy of a service request sent to Freescale concerning a problem which appeared with the CW 7.1.2 version.
See also the following for a workaround: http://www.utasker.com/forum/index.php?topic=657.0    



1) The TCP stack in the uTasker project is broken when using CW7.1.2 patch and level 4 optimization). No problems with CW7.1.1 patch.
2) In TCP reception code the FIN flag is not recognized at a critical location. At other code locations work normally.
3) Eg correct case: if (rx_tcp_packet->usHeaderLengthAndFlags & TCP_FLAG_RESET) here the assembler shows the variable being collected from 24 bytes offset from SP (corresponds with the struct) lea 24(a7),d1 - then bit test on d1
4) Eg. the incorrect case which causes the project to fail: if (rx_tcp_packet->usHeaderLengthAndFlags & TCP_FLAG_FIN) The assembler code does a bit check of a location 6 bytes offset to where the value really is - btst #0,30(a7)
5) This value is then never true and no TCP connections can be closed normally.
6) The problem can be reproduced by all uTasker project users (field problem reports for users moving from CW 7.1.1 to CW7.1.2). The problem disappears when optimization is removed.
7) Workaround: By copying the value where it is initialized (where it is correctly placed in the struct) to a register and using the register value for the compare solves the problem in the project case.
8 ) Complete project is available for download for test on M52235 EVB where it works normally with CW7.1.1 and earlier but fails with CW7.1.2. Please request if required - the error is also easily visible in the disassembly. Regards Mark Butcher



Regards

Mark

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: Codewarrior 7.1.2 optimisation problem
« Reply #1 on: November 30, 2009, 07:59:51 PM »
Mark,

Has Freescale updated you on this?  I noticed that the patches section shows 7.1.2a, but the actual download filename still says 7.1.2.  So I wasn't sure if I should stay away from 7.1.2 for now, or what.

Thanks,
Aaron

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Codewarrior 7.1.2 optimisation problem
« Reply #2 on: November 30, 2009, 08:08:33 PM »
Hi Aaron

I didn't get an update so am not sure whether there is a newer version with any fixes or not.

Since the problem is very reproducible it should be quite easy to test whether any particular compiler version suffers from it or not.

Regards

Mark

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: Codewarrior 7.1.2 optimisation problem
« Reply #3 on: February 23, 2010, 05:39:19 PM »
Has anyone tried out the new code warrior 7.2?  Is it good to use, or should it be avoided? ???

Aaron

Offline aersek

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Codewarrior 7.1.2 optimisation problem
« Reply #4 on: February 23, 2010, 07:17:36 PM »
I didn't tried Codewarrior 7.2 but I have found few posts on freescale forum about bug and problems with compiling in CW 7.2, so for now is best to still use 7.1 version. On freescale web can be downloaded beta version of Codewarrior 10.0, it is completely new concept, it is Eclipse based IDE, maybe there are solved compile optimizations problems.

Regards

Andrija

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: Codewarrior 7.1.2 optimisation problem
« Reply #5 on: March 16, 2010, 10:01:24 PM »
It looks like it's just a trade off of one set of compiler problems for another.  Going from 7.1.1a to 7.2.
7.2 did shave off 4k, but in quick tests it had issues with some of the saved parameters.

But 7.1.1a has it's own issues.  Below, in this function I had to move a text string into a buffer to send it, otherwise CW would optimize it out.  I even tried turning off optimizations, to no avail.
Oh well.
Code: [Select]
static void fnDNSListner(unsigned char ucEvent, unsigned char *ptrIP){
CHAR cBuf[16];
    switch (ucEvent) {
case DNS_EVENT_SUCCESS:
uStrcpy(cBuf, "DNS answer: ");
fnDebugMsg(cBuf);
//fnDebugMsg("DNS answer: ");  //code warror optimizes this line away
fnIPStr(ptrIP, cBuf);
fnDebugMsg(cBuf);
fnDebugMsg("\r\n");
//uMemcpy(ip_sockets.ip, ptrIP, IPV4_LENGTH);                      // save the IP address which has just been resolved
break;
default:                                                             // DNS error message
break;
    }
}

Aaron

Offline danh

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Codewarrior 7.1.2 optimisation problem
« Reply #6 on: March 26, 2010, 02:33:18 AM »
I just noticed some other distressing behavior related to Codewarrior 7.1.2.  Note the simple 'if' expression on the third line here. Using CW 6.3 and 7.1 (as well as the simulator), the expression evaluates correctly. But under CW 7.1.2, it always evaluates to false. Using 'and' instead of 'or' in the expression works fine. This problem happens with any level of optimization other than none.

Code: [Select]
if(!uStrncasecmp(p, "z1", 2)) {
   type = *(p+1) - 0x30;
   if((type == 1) || (type == 2))
       uPrintf("(%d == 1) || (%d == 2) is true\r\n", type, type);
   else
       uPrintf("(%d == 1) || (%d == 2) is false\r\n", type, type);
   if((type >= 1) && (type <= 2))
       uPrintf("(%d >= 1) && (%d <= 2) is true\r\n", type, type);
   else
       uPrintf("(%d >= 1) || (%d <= 2) is false\r\n", type, type);
 }

Simulator output:
(1 == 1) || (1 == 2) is true
(1 >= 1) && (1 <= 2) is true


Target output:
(1 == 1) || (1 == 2) is false
(1 >= 1) && (1 <= 2) is true