libgcc/config/msp430/mpy.c
raw| 1 | /* Public domain. */ |
| 2 | extern int __mulhi3 (int, int); |
| 3 | |
| 4 | int |
| 5 | __mulhi3 (int x, int y) |
| 6 | { |
| 7 | char bit; |
| 8 | int neg = 0; |
| 9 | int rv = 0; |
| 10 | |
| 11 | if (y < 0) |
| 12 | { |
| 13 | y = - y; |
| 14 | neg = 1; |
| 15 | } |
| 16 | |
| 17 | for (bit = 0; y && bit < sizeof (y) * 8; bit ++) |
| 18 | { |
| 19 | if (y & 1) |
| 20 | rv += x; |
| 21 | x <<= 1; |
| 22 | y >>= 1; |
| 23 | } |
| 24 | |
| 25 | return neg ? - rv : rv; |
| 26 | } |