alager
Tester - PRO for PSoC
Reged: Aug 02 2007
Posts: 47
|
|
I read with great pleasure that the MAC is now going to be used with the official release of 9.61 Pro. So I installed it and ran a bit of test code Code:
void main(){ BYTE foo=10; WORD wfoo; wfoo = foo*200; }
But the ASM does not appear to use the MAC: Code:
;main.c: 502: wfoo = foo*200; 2170 0F64 55 6B 00 mov [?___wmul], 0 2171 0F67 55 6C C8 mov [?___wmul+1], 200 2172 0F6A 51 61 mov a, [??_main] 2173 0F6C 57 00 mov x, 0 2174 0F6E 7C 0B53 call ___wmul
___wmul: 1574 ;___wmul@multiplier stored from xa 1575 0B53 53 6E mov [??___wmul+1], a 1576 0B55 5A 6D mov [??___wmul], x 1577 ;wmul.c: 4: unsigned int product = 0; 1578 0B57 55 6F 00 mov [??___wmul+2], 0 1579 0B5A 55 70 00 mov [??___wmul+3], 0 1580 ;wmul.c: 6: do { 1581 ; 1582 0B5D l116: 1583 ;wmul.c: 7: if(multiplier & 1) 1584 0B5D 47 6E 01 tst [??___wmul+1], 1 1585 0B60 A009 jz l117 1586 ;wmul.c: 8: product += multiplicand; 1587 0B62 51 6C mov a, [?___wmul+1] 1588 0B64 04 70 add [??___wmul+3], a 1589 0B66 51 6B mov a, [?___wmul] 1590 0B68 0C 6F adc [??___wmul+2], a 1591 ; 1592 0B6A l117: 1593 ;wmul.c: 9: multiplicand <<= 1; 1594 0B6A 65 6C asl [?___wmul+1] 1595 0B6C 6B 6B rlc [?___wmul] 1596 ;wmul.c: 10: multiplier >>= 1; 1597 0B6E 70 FB and f, 0xFB 1598 0B70 6E 6D rrc [??___wmul] 1599 0B72 6E 6E rrc [??___wmul+1] 1600 ;wmul.c: 11: } while(multiplier != 0); 1601 0B74 51 6D mov a, [??___wmul] 1602 0B76 2A 6E or a, [??___wmul+1] 1603 0B78 BFE4 jnz l116 1604 ; 1605 ;wmul.c: 12: return product; 1606 0B7A 51 70 mov a, [??___wmul+3] 1607 0B7C 58 6F mov x, [??___wmul+2] 1608 ;wmul.c: 13: } 1609 ; 1610 0B7E 70 CF and f, 0xCF ;select user reg space 1611 0B80 7F ret 1612 0B81 __end_of___wmul:
Aaron
|
clyde
HI-TECH team member
   
Reged: Oct 16 2003
Posts: 633
|
|
The MAC hardware in the PSoC does signed byte multiplication. So it can't be used to synthesize multiplications of longer data types. Or if it can, I don't know how.
The MAC will be used if you multiply two bytes to get a byte result (high order result is discarded so the sign doesn't matter) or if you multiply two signed bytes to get a word result. All other multiplications are done in software.
|
alager
Tester - PRO for PSoC
Reged: Aug 02 2007
Posts: 47
|
|
Yes and no Clyde.
Nope on char*char=int or char*char=WORD
Code:
2197 ;main.c: 499: char foo=10,bar=120; 2198 0EC5 55 75 0A mov [??_main+1], 10 2199 0EC8 55 74 78 mov [??_main], 120 2200 ;main.c: 500: int wfoo; 2201 ;main.c: 502: wfoo = foo*bar; 2202 0ECB 5F 80 74 mov [?___wmul+1], [??_main] 2203 0ECE 55 7F 00 mov [?___wmul], 0 2204 0ED1 51 75 mov a, [??_main+1] 2205 0ED3 57 00 mov x, 0 2206 0ED5 7C 0B12 call ___wmul
Yes on char*char=char and char*char=BYTE and BYTE*BYTE=BYTE and char*BYTE=BYTE; Code:
2204 ;main.c: 503: wfoo = foo*bar; 2205 0EC1 51 74 mov a, [??_main] 2206 0EC3 60 E9 mov reg[233], a 2207 0EC5 51 76 mov a, [??_main+2] 2208 0EC7 60 E8 mov reg[232], a 2209 0EC9 5D EB mov a, reg[235] 2210 0ECB 53 75 mov [??_main+1], a
Note: I had to use a for loop, because assigning the locals in the declaration caused the compiler to do the math at compile time. Nice feature.
It doesn't seem to me like it's a big stretch to get the 16 bit result in the signed case. But of course I'm not a compiler programmer either...
Aaron
|
clyde
HI-TECH team member
   
Reged: Oct 16 2003
Posts: 633
|
|
Quote:
Yes and no Clyde.
Nope on char*char=int or char*char=WORD
It doesn't seem to me like it's a big stretch to get the 16 bit result in the signed case. But of course I'm not a compiler programmer either...
Aaron
It's not a stretch at all, you just didn't test it. Try "signed char".
|
alager
Tester - PRO for PSoC
Reged: Aug 02 2007
Posts: 47
|
|
ohhhh, section 3.3.3 of the manual shows the default 'char' is unsigned. Okay it all makes sense now...
Aaron
|
zsaravanja
Tester - PRO for PSoC
Reged: Jul 17 2007
Posts: 42
Loc: Land Downunder
|
|
Quote:
The MAC hardware in the PSoC does signed byte multiplication. So it can't be used to synthesize multiplications of longer data types. Or if it can, I don't know how.
The MAC will be used if you multiply two bytes to get a byte result (high order result is discarded so the sign doesn't matter) or if you multiply two signed bytes to get a word result. All other multiplications are done in software.
Dave Van Ess wrote a brilliant article on multi quadrant multiplication with multiple bytes both signed and unsigned. The relevant app notes are:
AN2038 Signed byte multiplication (16bit and higher using MAC) AN2032 Unsigned multiplication (8bits and beyond using MAC)
They are both informative, well written and handy in implementing fast multiplies including enough info to get floating point math with a MAC.
http://www.psocdeveloper.com/docs/appnotes/an-mode/detail/an-pointer/an2038/an-file/125.html
http://www.psocdeveloper.com/docs/appnotes/an-mode/detail/an-pointer/an2032/an-file/125.html
|
clyde
HI-TECH team member
   
Reged: Oct 16 2003
Posts: 633
|
|
Thanks for the link. Very useful.
|
alager
Tester - PRO for PSoC
Reged: Aug 02 2007
Posts: 47
|
|
Clyde,
Are there any plans to expand the use of the MAC to larger data types, based on the above post?
Aaron
|
clyde
HI-TECH team member
   
Reged: Oct 16 2003
Posts: 633
|
|
It's on the to-do list but I can't give a schedule for implementation at this stage.
Clyde
|