<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic S12 unexpected code optimisation in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128772#M786</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;SPAN&gt;Hi &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am getting some puzzling optimisation from CodeWarrior HC12 4.5&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the following routine the optimiser decides to remove the second test of the resultant read from ESTAT. I get the "Removed dead code" message but I cannot see the rationale behind the optimisation (maybe I've been working too late!) After the code listing I have also shown the listing extract.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Colin&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;uint8 EE_Command(uint16* address, uint16 data, uint8 command){uint8 eeStatus;uint8 result = 0x00;*address = data;ECMD = command; ESTAT = ESTAT_CBEIF_MASK;eeStatus = ESTAT;if(eeStatus &amp;amp; ESTAT_PVIOL_MASK){ESTAT = ESTAT_PVIOL_MASK; result = ESTAT_PVIOL_MASK; }else if(eeStatus &amp;amp; ESTAT_ACCERR_MASK){ESTAT = ESTAT_ACCERR_MASK; // *** optimised outresult = ESTAT_ACCERR_MASK; // *** optimised out}else {while(!ESTAT_CCIF){// do nothing }}return result;}42: if(eeStatus &amp;amp; ESTAT_PVIOL_MASK)0017 8420 [1] ANDA #320019 2709 [3/1] BEQ *+11 ;abs = 002443: {44: ESTAT = ESTAT_PVIOL_MASK; 001b 8620 [1] LDAA #32001d 7a0000 [3] STAA _ESTAT45: result = ESTAT_PVIOL_MASK;0020 6a81 [2] STAA 1,SP46: }0022 2005 [3] BRA *+7 ;abs = 002947: else if(eeStatus &amp;amp; ESTAT_ACCERR_MASK)48: {49: ESTAT = ESTAT_ACCERR_MASK; 50: result = ESTAT_ACCERR_MASK;51: }52: else 53: {54: while(!ESTAT_CCIF)0024 1f000040fb [5] BRCLR _ESTAT,#64,*+0 ;abs = 002455: {56: // do nothing 57: }58: }59: 60: return result;0029 e681 [3] LDAB 1,SP61: }&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 1;"&gt;(Alban formatted code for lisibility - Use SRC button)&lt;/SPAN&gt;&lt;P&gt;Message Edited by Alban on &lt;SPAN class="date_text"&gt;2006-08-30&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:36 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Aug 2006 20:12:10 GMT</pubDate>
    <dc:creator>colinh</dc:creator>
    <dc:date>2006-08-30T20:12:10Z</dc:date>
    <item>
      <title>S12 unexpected code optimisation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128772#M786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;SPAN&gt;Hi &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am getting some puzzling optimisation from CodeWarrior HC12 4.5&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the following routine the optimiser decides to remove the second test of the resultant read from ESTAT. I get the "Removed dead code" message but I cannot see the rationale behind the optimisation (maybe I've been working too late!) After the code listing I have also shown the listing extract.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Colin&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;uint8 EE_Command(uint16* address, uint16 data, uint8 command){uint8 eeStatus;uint8 result = 0x00;*address = data;ECMD = command; ESTAT = ESTAT_CBEIF_MASK;eeStatus = ESTAT;if(eeStatus &amp;amp; ESTAT_PVIOL_MASK){ESTAT = ESTAT_PVIOL_MASK; result = ESTAT_PVIOL_MASK; }else if(eeStatus &amp;amp; ESTAT_ACCERR_MASK){ESTAT = ESTAT_ACCERR_MASK; // *** optimised outresult = ESTAT_ACCERR_MASK; // *** optimised out}else {while(!ESTAT_CCIF){// do nothing }}return result;}42: if(eeStatus &amp;amp; ESTAT_PVIOL_MASK)0017 8420 [1] ANDA #320019 2709 [3/1] BEQ *+11 ;abs = 002443: {44: ESTAT = ESTAT_PVIOL_MASK; 001b 8620 [1] LDAA #32001d 7a0000 [3] STAA _ESTAT45: result = ESTAT_PVIOL_MASK;0020 6a81 [2] STAA 1,SP46: }0022 2005 [3] BRA *+7 ;abs = 002947: else if(eeStatus &amp;amp; ESTAT_ACCERR_MASK)48: {49: ESTAT = ESTAT_ACCERR_MASK; 50: result = ESTAT_ACCERR_MASK;51: }52: else 53: {54: while(!ESTAT_CCIF)0024 1f000040fb [5] BRCLR _ESTAT,#64,*+0 ;abs = 002455: {56: // do nothing 57: }58: }59: 60: return result;0029 e681 [3] LDAB 1,SP61: }&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 1;"&gt;(Alban formatted code for lisibility - Use SRC button)&lt;/SPAN&gt;&lt;P&gt;Message Edited by Alban on &lt;SPAN class="date_text"&gt;2006-08-30&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:36 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Aug 2006 20:12:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128772#M786</guid>
      <dc:creator>colinh</dc:creator>
      <dc:date>2006-08-30T20:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: S12 unexpected code optimisation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128773#M787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi Colin,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I can confirm you have been working too late.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The "elseif" is indeed dead code because of its condition.&lt;/DIV&gt;&lt;DIV&gt;You are using &lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt; and you probably meant a &lt;STRONG&gt;&amp;amp;&amp;amp;&lt;/STRONG&gt; to use with a bit mask.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Am I right ?&lt;/DIV&gt;&lt;DIV&gt;Alvin.&lt;/DIV&gt;&lt;P&gt;Message Edited by Nabla69 on &lt;SPAN class="date_text"&gt;2006-08-30&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:42 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Aug 2006 21:40:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128773#M787</guid>
      <dc:creator>Nabla69</dc:creator>
      <dc:date>2006-08-30T21:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: S12 unexpected code optimisation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128774#M788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Alvin&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I've just had 2 cans of Coke so I should be at my peak &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt; &amp;nbsp;- Correct me if I'm wrong but it is a single &amp;amp; that does a bit wise AND between two entities.&amp;nbsp; &amp;amp;&amp;amp; is used to test that two logical conditions are both true.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Therefore in my code the first test should see if ESTAT_PVIOL_MASK is set, the second test should see if ESTAT_ACCERR_MASK is set.&amp;nbsp; The &amp;amp; test should not modify eeStatus so as far as I am concerned it should test PVIOL, and if it is not set it should then proceed to test ACCERR, finally if neither was set it should do the while loop.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Cheers&lt;/DIV&gt;&lt;DIV&gt;Colin&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Aug 2006 10:35:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128774#M788</guid>
      <dc:creator>colinh</dc:creator>
      <dc:date>2006-08-31T10:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: S12 unexpected code optimisation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128775#M789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; This needs to be investigated by our support team.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; Depending on the way the different elements are defined, the compiler may optimized code out.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; Please submit a service request through our on line support site (&lt;A href="http://www.freescale.com/webapp/sps/site/homepage.jsp?nodeId=054670&amp;amp;tid=FSH#online_self-help" rel="nofollow" target="_blank"&gt;http://www.freescale.com/webapp/sps/site/homepage.jsp?nodeId=054670&amp;amp;tid=FSH#online_self-help&lt;/A&gt;).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Make sure to provide a project reproducing the trouble (or at least the preprocessor listing of the source file where the function is implemented), We will also need to know which version of&amp;nbsp;CodeWarrior you are using and the options you are using to build the application.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;To retrieve CodeWarrior version number:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Start the IDE&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Select "Help" -&amp;gt; "About Metrowerks CodeWarrior "&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Click on "Installed Products"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Click on Save As and save the information in a text file that you send with your service request.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Aug 2006 17:49:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128775#M789</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2006-08-31T17:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: S12 code over-optimisation</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128776#M790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Colin,&lt;BR /&gt;&lt;BR /&gt;I guess I should trade my Frenchie double espresso for a sweeter drink then... :s&lt;BR /&gt;&lt;BR /&gt;Completely agree with you that the single &amp;amp; is for bite wise operation while the double &amp;amp;&amp;amp; is for logical ones.&lt;BR /&gt;&lt;BR /&gt;As a workaround to force its compilation, I think there is a switch for the compiler NOT to optimize "dead code". This will work if only the compiler is OK and the optimization is over optimistic &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;BR /&gt;&lt;BR /&gt;Another way would be to change the syntax for the software to do the same thing but in a different manner:&lt;BR /&gt;&lt;BR /&gt;if (eeStatus &amp;amp; ESTAT_ACCERR_MASK) with if (!(~eeStatus | ~ESTAT_ACCERR_MASK))...&lt;BR /&gt;&lt;BR /&gt;You never know &lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;BR /&gt;Alvin - Non Coke Drinker&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Aug 2006 21:40:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12-unexpected-code-optimisation/m-p/128776#M790</guid>
      <dc:creator>Nabla69</dc:creator>
      <dc:date>2006-08-31T21:40:08Z</dc:date>
    </item>
  </channel>
</rss>

