Skip to content

Operator i_mult/i_mult_o/i_mult_sat use all wrong multiplication

The 16-bit operator i_mult and all of its derivates share a wrong multiplication: Word32 c = a * b; Correction: Word32 c = (Word32) a * b;

Due to the missing Word32-casting, the result of the product "a*b" got sign-extended from Word16 format to Word32, then went through saturate_o without any change, nor any overflow setting.

Note: This is experience with the one specific compiler, others might be different.

With the proposed correction, larger products may now need saturation, but in i_mult, the overflow pointer is set to NULL, thus leading to segfaults in saturate_o.

In order to circum-vent this problem, we can call i_mult_sat(a,b) in i_mult. Correction: Word16 i_mult( Word16 a, Word16 b ) { return i_mult_sat(a,b); }

Note: i_mult_o is only used at 2 places Note: i_mult is often (> 1000 times) used

In a first step, we should place an assert in i_mult/i_mult_o and catch situations, where the Word32-product requires saturation. These code lines might need some changes, some may be happy with saturated values as well.

In a 2nd step, all of these calls can be converted to calls of i_mult, that uses saturation (but w/o overflow flag), if needed at all or wanted.

If saturation is not requied, there is no more difference to the ORIGINAL_G7231 version.

Edited by Stefan Doehla