Retro68/gcc/libgcc/config/msp430/mpy.c

27 lines
334 B
C
Raw Normal View History

2014-09-21 17:33:12 +00:00
/* Public domain. */
extern int __mulhi3 (int, int);
int
__mulhi3 (int x, int y)
{
2017-04-10 11:32:00 +00:00
char bit;
int neg = 0;
int rv = 0;
2014-09-21 17:33:12 +00:00
2017-04-10 11:32:00 +00:00
if (y < 0)
2014-09-21 17:33:12 +00:00
{
2017-04-10 11:32:00 +00:00
y = - y;
neg = 1;
2014-09-21 17:33:12 +00:00
}
2017-04-10 11:32:00 +00:00
for (bit = 0; y && bit < sizeof (y) * 8; bit ++)
{
if (y & 1)
rv += x;
x <<= 1;
y >>= 1;
}
return neg ? - rv : rv;
2014-09-21 17:33:12 +00:00
}