Skip to content

Commit 0618173

Browse files
karltrillian
authored andcommitted
fixed-point: introduce MULT16_32_32 to handle unexpected types in MULT16_32_Q15
1 parent 00d2e62 commit 0618173

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

libspeexdsp/arch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ typedef float spx_word32_t;
177177
#define ADD32(a,b) ((a)+(b))
178178
#define SUB32(a,b) ((a)-(b))
179179
#define MULT16_16_16(a,b) ((a)*(b))
180+
#define MULT16_32_32(a,b) ((a)*(b))
180181
#define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
181182
#define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
182183

libspeexdsp/fixed_debug.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ static inline short MULT16_16_16(int a, int b)
250250
return res;
251251
}
252252

253+
/* result fits in 32 bits */
254+
static inline int MULT16_32_32(int a, long long b)
255+
{
256+
long long res;
257+
if (!VERIFY_SHORT(a) || !VERIFY_INT(b))
258+
{
259+
fprintf (stderr, "MULT16_32_32: inputs are not short+int: %d %d\n", a, (int)b);
260+
}
261+
res = a*b;
262+
if (!VERIFY_INT(res))
263+
fprintf (stderr, "MULT16_32_32: output is not int: %d\n", (int)res);
264+
spx_mips++;
265+
return res;
266+
}
267+
253268
#define MULT16_16(a, b) _MULT16_16(a, b, __FILE__, __LINE__)
254269
static inline int _MULT16_16(int a, int b, char *file, int line)
255270
{

libspeexdsp/fixed_generic.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,18 @@
6969

7070

7171
/* result fits in 16 bits */
72-
#define MULT16_16_16(a,b) ((((spx_word16_t)(a))*((spx_word16_t)(b))))
72+
#define MULT16_16_16(a,b) (((spx_word16_t)(a))*((spx_word16_t)(b)))
73+
/* result fits in 32 bits */
74+
#define MULT16_32_32(a,b) (((spx_word16_t)(a))*((spx_word32_t)(b)))
7375

7476
/* (spx_word32_t)(spx_word16_t) gives TI compiler a hint that it's 16x16->32 multiply */
7577
#define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b)))
7678

7779
#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
7880

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)))
81+
#define MULT16_32_P15(a,b) ADD32(MULT16_32_32(a,SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
82+
#define MULT16_32_Q15(a,b) ADD32(MULT16_32_32(a,SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
83+
#define MAC16_32_Q15(c,a,b) ADD32(c,MULT16_32_Q15(a,b))
8284

8385

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

0 commit comments

Comments
 (0)