<?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 CodeWarrior 8- &amp; 16-bit tools: Looking for 16 X 16 bits FAST multiplication trick in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/CodeWarrior-8-16-bit-tools-Looking-for-16-X-16-bits-FAST/m-p/124954#M138</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #ff0000;"&gt;To help you find solutions to problems that have already been solved, we have posted this message. It contains an entire topic ported from a separate forum. The original message and all replies are in this single message.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Posted: Jul 13, 2004 - 04:16 AM&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Dear all,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In my application I need to perform 16x16 bits, result on 32 bits multiplications but very fast.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When coding this :&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;long a;&lt;BR /&gt;int c,d;&lt;BR /&gt;a = c * d;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;the compiler uses _IMUL because it requires to be casted and of course the result is false but this is performed very fast.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When coding :&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;a = (long) c * d;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;The result is correct and the compiler uses _LMUL library function. The _LMUL routine calls other routines :&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;ENTER_BINARY_L&lt;BR /&gt;LMUL_k_is_k_mul_j&lt;BR /&gt;k_is_k_plus_j_l&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;This is very long to perform all these routines and I guess it could be improved&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Has anybody got trick on how to code a fast 16x16 multiplication ?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Best regards&lt;BR /&gt;Stephane&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; Posted: Jul 15, 2004 - 03:05 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;HiStephane,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You might see a slight speed improvement if you specified that the compiler should&amp;nbsp; optimize the code for time (-Ot) instead of size, which will place all the routines as inline code rather than separate functions.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Other than that, it really matters if on what processor you are using and a lot of other things. You'd have to open an service request and even then I cna't assure you that there will be a quick solution.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Ron&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;Posted: Jul 16, 2004 - 02:46 AM&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In fact I've coded something less heavy than the library multiplication.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;For instance on a HC08QL4 at clk=3.2MHz, , the 16x16 takes 200 us. When coding myslef a 16x16 it takes 60us. Better isn't it ?&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;But of course my function is less easy to use than the classic multiplication. The C multiplication manages all cases whereas I need to know exactly what I'm going to do when using my multiplication.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Now my problem is how to pass 2 16-bits paramters and how to read a 32-bit returned value&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;I'm investigating....&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Thanks for your answer.&lt;BR /&gt;Stephane&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Post&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Yes our engineers said the best thing would be for you to create your own function and use that instead of the multiplaction operator. Did you try long 16bitMul(short short) to pass 16's and return a 32 bit? (note that HC tools are no where near my area, and that is just a random thought from a C point of view)&lt;/DIV&gt;&lt;DIV&gt;Ron&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;_________________&lt;BR /&gt;Ron Liechty&lt;BR /&gt;Ombudsman for Metrowerks&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 28 Jan 2006 02:07:40 GMT</pubDate>
    <dc:creator>marc_paquette</dc:creator>
    <dc:date>2006-01-28T02:07:40Z</dc:date>
    <item>
      <title>CodeWarrior 8- &amp; 16-bit tools: Looking for 16 X 16 bits FAST multiplication trick</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/CodeWarrior-8-16-bit-tools-Looking-for-16-X-16-bits-FAST/m-p/124954#M138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #ff0000;"&gt;To help you find solutions to problems that have already been solved, we have posted this message. It contains an entire topic ported from a separate forum. The original message and all replies are in this single message.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Posted: Jul 13, 2004 - 04:16 AM&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Dear all,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In my application I need to perform 16x16 bits, result on 32 bits multiplications but very fast.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When coding this :&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;long a;&lt;BR /&gt;int c,d;&lt;BR /&gt;a = c * d;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;the compiler uses _IMUL because it requires to be casted and of course the result is false but this is performed very fast.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When coding :&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;a = (long) c * d;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;The result is correct and the compiler uses _LMUL library function. The _LMUL routine calls other routines :&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;ENTER_BINARY_L&lt;BR /&gt;LMUL_k_is_k_mul_j&lt;BR /&gt;k_is_k_plus_j_l&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;This is very long to perform all these routines and I guess it could be improved&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Has anybody got trick on how to code a fast 16x16 multiplication ?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Best regards&lt;BR /&gt;Stephane&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; Posted: Jul 15, 2004 - 03:05 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;HiStephane,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You might see a slight speed improvement if you specified that the compiler should&amp;nbsp; optimize the code for time (-Ot) instead of size, which will place all the routines as inline code rather than separate functions.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Other than that, it really matters if on what processor you are using and a lot of other things. You'd have to open an service request and even then I cna't assure you that there will be a quick solution.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Ron&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;Posted: Jul 16, 2004 - 02:46 AM&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In fact I've coded something less heavy than the library multiplication.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;For instance on a HC08QL4 at clk=3.2MHz, , the 16x16 takes 200 us. When coding myslef a 16x16 it takes 60us. Better isn't it ?&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;But of course my function is less easy to use than the classic multiplication. The C multiplication manages all cases whereas I need to know exactly what I'm going to do when using my multiplication.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Now my problem is how to pass 2 16-bits paramters and how to read a 32-bit returned value&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;I'm investigating....&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Thanks for your answer.&lt;BR /&gt;Stephane&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Post&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Yes our engineers said the best thing would be for you to create your own function and use that instead of the multiplaction operator. Did you try long 16bitMul(short short) to pass 16's and return a 32 bit? (note that HC tools are no where near my area, and that is just a random thought from a C point of view)&lt;/DIV&gt;&lt;DIV&gt;Ron&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;_________________&lt;BR /&gt;Ron Liechty&lt;BR /&gt;Ombudsman for Metrowerks&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jan 2006 02:07:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/CodeWarrior-8-16-bit-tools-Looking-for-16-X-16-bits-FAST/m-p/124954#M138</guid>
      <dc:creator>marc_paquette</dc:creator>
      <dc:date>2006-01-28T02:07:40Z</dc:date>
    </item>
  </channel>
</rss>

