On Thursday, June 19, 2003, at 01:55 PM, Tyler Montbriand wrote:
Are the macro parameters for MAD_F_MLX, MAD_F_MLA, MAD_F_MLN, and mad_f_scale64 used ONLY as input parameters? 'cause if not, there's no way in heck to duplicate the full functionality of the macro in a function without operator overloading and hidden pointers; and MAD is a C project, not a C++ one.
MAD_F_MLX, MAD_F_MLA, and MAD_F_MLN all modify their first two arguments. These arguments must be lvalues, so you could take their addresses to pass to a function.
On the other hand, you really only need to define an implementation for mad_f_mul; all the other macros have default implementations written in terms of this one.
mad_fixed_t mad_f_mul(x, y) x: (in) 32-bit fixed-point multiplicand y: (in) 32-bit fixed-point multiplicand returns: 32-bit fixed-point product (x*y shifted by MAD_F_SCALEBITS)
[Note that MAD_F_SCALEBITS may be redefined in synth.c, so if the implementation for mad_f_mul calls a function, MAD_F_SCALEBITS may have to be included as a function argument. You can avoid this by defining mad_f_scale64 to nothing and always scaling by MAD_F_FRACBITS.]
If you want more accuracy, you should define MAD_F_MLX instead and let the default implementations define everything in terms of this.
void MAD_F_MLX(hi, lo, x, y) hi: (out) 32-bit high word of 64-bit x*y product lo: (out) 32-bit low word of 64-bit x*y product x: (in) 32-bit integer multiplicand y: (in) 32-bit integer multiplicand
Defining implementations for any of the other macros is optional, if you have an efficient or particularly effective alternative to the default implementations.