The following functions should be equivalent:
typedef f int16_t;
#define F_R 6
struct ff
{
uint8_t l;
int8_t m;
} b;
f fmul2_alt(f l, f r)
{
int32_t tl = l;
tl *= r;
return(tl >> F_R);
}
f fmul2(f l, f r)
{
int32_t tmp1, tmp2;
tmp2 = (ffcast(l)->l * ffcast(r)->m);
tmp2 += (ffcast(l)->m * ffcast(r)->l);
tmp2 <<= 8;
tmp1 = ffcast(l)->m * ffcast(r)->m;
tmp1 <<= 16;
tmp1 += (ffcast(l)->l * ffcast(r)->l);
tmp1 += tmp2;
return(tmp1 >> F_R);
}
On my host system using gcc I have tested them for all values of l, r
and get the same result. Compiled using sdcc --std-c99 -mz80 I get
different results though.
The functions are multiplications of 16 bit fixed point numbers, the
first one using a 32 bit multiplication (implemented by sdcc using 10 8
bit multiplications in device/lib/_mullong.c)), the second one my
attempt to do it faster using 4 8-bit multiplications.
Philipp
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user