compiler support for 32*32->64-bit MUL/MAC ?

compiler support for 32*32->64-bit MUL/MAC ?

Post by Ronald H. » Wed, 29 Oct 2003 17:14:10


Do any of the ARM compilers include support for generating the
32 x 32 multiply and multiply-accumulate ARM instructions which
produce a 64-bit result, without dropping into assembly language?

If so, what does the C syntax look like?


Thanks.
--
Ron Nicholson rhn AT nicholson DOT com http://www.yqcomputer.com/
#include <canonical.disclaimer> // only my own opinions, etc.
 
 
 

compiler support for 32*32->64-bit MUL/MAC ?

Post by Kevin Brac » Thu, 30 Oct 2003 00:10:16

In message <bnl8gi$14a$ XXXX@XXXXX.COM >



The Norcroft compiler (as used in ARM's ADS) can produce the multiply
instructions (but not the multiply-accumulate, AFAIK).


/* assuming <stdint.h> types defined*/
int32_t a, b;
int64_t c;
c = (int64_t) a * b;

Even though that promotes a (and hence b) to int64_t and then does an
apparently 64 x 64 multiplication, the compiler notes that the operands have
just been converted from int32_t and uses a signed 32 x 32 -> 64 multiply
instead.

It'll do that for signed and unsigned cases, and it will also produce
32 x 64 and 64 x 64 multiply code inline using the MULL instructions if
required (maybe only if -Ospace, I'm not sure).

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.yqcomputer.com/

 
 
 

compiler support for 32*32->64-bit MUL/MAC ?

Post by Wilc » Fri, 31 Oct 2003 08:33:41


RVCT2.0.1 also supports S/UMLAL in the following way:

long long f(long long acc, int x, int y)
{ return acc + (long long) x * (long long) y; }

On a cpu with the E extension (eg ARM9E) it can use the SMULxx and
SMLAxx instructions if the operands are 16 bit signed (eg short):

int g(int x, int y)
{ return (short) x * (short)(y >> 16); } // uses SMULBT

Wilco
 
 
 

compiler support for 32*32->64-bit MUL/MAC ?

Post by Kevin Brac » Sat, 01 Nov 2003 00:43:34

In message <42Ynb.1244$ XXXX@XXXXX.COM >



That's nice to know. Any chance you could tell me the names of the equivalent
run-time support functions, so I can keep the RISC OS Norcroft compatible?
"_ll_mlass"?

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.yqcomputer.com/
 
 
 

compiler support for 32*32->64-bit MUL/MAC ?

Post by brycema » Sun, 02 Nov 2003 02:42:04


My GCC 3.3 with -O1 produces this optimal code:

long long acc;
<other code using acc, int_a, int_b>
acc += (long long) int_b * int_a;
83f8: e0c43897 smull r3, r4, r7, r8

- Bryce Schober
 
 
 

compiler support for 32*32->64-bit MUL/MAC ?

Post by Kevin Brac » Tue, 04 Nov 2003 20:21:01

In message < XXXX@XXXXX.COM >



Not so much optimal as incorrect, unless you've snipped the bit that
does the addition.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.yqcomputer.com/
 
 
 

compiler support for 32*32->64-bit MUL/MAC ?

Post by brycema » Wed, 05 Nov 2003 04:37:38


Yes, my snip was an incorrect example. But you don't have to take my
word for it. Try it yourself, GCC does indeed use (u/s)(mull/mlal) if
you ask for a 64-bit (long long ) result.