Skip to content

Commit 9617cea

Browse files
karltrillian
authored andcommitted
fixed-point: don't truncate 32-bit arg to MULT16_32_Q15
The 32-bit arg and return value have one bit more than required to represent +/-32767 with 15 fractional bits. Keeping the most significant bit allows saturation for 16-bit conversion to sometimes be delayed until after these operations.
1 parent dc6394e commit 9617cea

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libspeexdsp/fixed_debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static inline int _MULT16_32_QX(int a, long long b, int Q, char *file, int line)
279279
{
280280
fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line);
281281
}
282-
if (ABS32(b)>=(EXTEND32(1)<<(15+Q)))
282+
if (ABS(b)>>(16+Q))
283283
fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line);
284284
res = (((long long)a)*(long long)b) >> Q;
285285
if (!VERIFY_INT(res))
@@ -295,7 +295,7 @@ static inline int MULT16_32_PX(int a, long long b, int Q)
295295
{
296296
fprintf (stderr, "MULT16_32_P%d: inputs are not short+int: %d %d\n", Q, (int)a, (int)b);
297297
}
298-
if (ABS32(b)>=(EXTEND32(1)<<(15+Q)))
298+
if (ABS(b)>>(16+Q))
299299
fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d\n", Q, (int)a, (int)b);
300300
res = ((((long long)a)*(long long)b) + ((EXTEND32(1)<<Q)>>1))>> Q;
301301
if (!VERIFY_INT(res))

libspeexdsp/fixed_generic.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676

7777
#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
7878

79-
#define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
80-
#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
81-
#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
79+
#define MULT16_32_P15(a,b) ADD32((a)*SHR((b),15), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
80+
#define MULT16_32_Q15(a,b) ADD32((a)*SHR((b),15), SHR(MULT16_16((a),((b)&0x00007fff)),15))
81+
#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32((a)*SHR((b),15), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
8282

8383

8484
#define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11)))

0 commit comments

Comments
 (0)