Skip to content

Commit 17190ae

Browse files
committed
abandon incomplete mixer asm math functions
1 parent 614962a commit 17190ae

1 file changed

Lines changed: 18 additions & 33 deletions

File tree

shared-module/audiocore/Mixer.c

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
7+
* 2018 DeanM for Adafruit Industries
8+
* 2019 Michael Schroeder
79
*
810
* Permission is hereby granted, free of charge, to any person obtaining a copy
911
* of this software and associated documentation files (the "Software"), to deal
@@ -105,7 +107,7 @@ uint32_t add8signed(uint32_t a, uint32_t b) {
105107
if (intermediate > CHAR_MAX) {
106108
intermediate = CHAR_MAX;
107109
} else if (intermediate < CHAR_MIN) {
108-
//intermediate = CHAR_MIN;
110+
intermediate = CHAR_MIN;
109111
}
110112
result |= (((uint32_t) intermediate) & 0xff) << (sizeof(int8_t) * 8 * i);
111113
}
@@ -114,13 +116,13 @@ uint32_t add8signed(uint32_t a, uint32_t b) {
114116
}
115117

116118
uint32_t add8unsigned(uint32_t a, uint32_t b) {
117-
#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
119+
/*#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
118120
// Subtract out the DC offset, add and then shift back.
119121
a = __USUB8(a, 0x80808080);
120122
b = __USUB8(b, 0x80808080);
121123
uint32_t sum = __QADD8(a, b);
122124
return __UADD8(sum, 0x80808080);
123-
#else
125+
#else*/
124126
uint32_t result = 0;
125127
for (int8_t i = 0; i < 4; i++) {
126128
uint8_t ai = (a >> (sizeof(uint8_t) * 8 * i));
@@ -132,13 +134,13 @@ uint32_t add8unsigned(uint32_t a, uint32_t b) {
132134
result |= ((uint32_t) intermediate & 0xff) << (sizeof(uint8_t) * 8 * i);
133135
}
134136
return result;
135-
#endif
137+
//#endif
136138
}
137139

138140
uint32_t add16signed(uint32_t a, uint32_t b) {
139-
#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
141+
/*#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
140142
return __QADD16(a, b);
141-
#else
143+
#else*/
142144
uint32_t result = 0;
143145
for (int8_t i = 0; i < 2; i++) {
144146
int16_t ai = a >> (sizeof(int16_t) * 8 * i);
@@ -152,7 +154,7 @@ uint32_t add16signed(uint32_t a, uint32_t b) {
152154
result |= (((uint32_t) intermediate) & 0xffff) << (sizeof(int16_t) * 8 * i);
153155
}
154156
return result;
155-
#endif
157+
//#endif
156158
}
157159

158160
uint32_t add16unsigned(uint32_t a, uint32_t b) {
@@ -183,17 +185,9 @@ static inline uint32_t mult8unsigned(uint32_t val, int32_t mul) {
183185
if (mul == 0) {
184186
return 0;
185187
}
186-
#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
187-
int32_t hi, lo;
188-
int32_t bits = 16; // saturate to 16 bits
189-
int32_t shift = 0; // shift is done automatically
190-
asm volatile("smulwb %0, %1, %2" : "=r" (lo) : "r" (mul), "r" (val));
191-
asm volatile("smulwt %0, %1, %2" : "=r" (hi) : "r" (mul), "r" (val));
192-
asm volatile("ssat %0, %1, %2, asr %3" : "=r" (lo) : "I" (bits), "r" (lo), "I" (shift));
193-
asm volatile("ssat %0, %1, %2, asr %3" : "=r" (hi) : "I" (bits), "r" (hi), "I" (shift));
194-
asm volatile("pkhbt %0, %1, %2, lsl #8" : "=r" (val) : "r" (lo), "r" (hi)); // pack
188+
/*#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
195189
return val;
196-
#else
190+
#else*/
197191
uint32_t result = 0;
198192
float mod_mul = (float) mul / (float) ((1<<15)-1);
199193
for (int8_t i = 0; i < 4; i++) {
@@ -206,7 +200,7 @@ static inline uint32_t mult8unsigned(uint32_t val, int32_t mul) {
206200
}
207201

208202
return result;
209-
#endif
203+
//#endif
210204
}
211205

212206
//TODO:
@@ -215,17 +209,11 @@ static inline uint32_t mult8signed(uint32_t val, int32_t mul) {
215209
if (mul == 0) {
216210
return 0;
217211
}
212+
/*
218213
#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
219-
int32_t hi, lo;
220-
int32_t bits = 16; // saturate to 16 bits
221-
int32_t shift = 0; // shift is done automatically
222-
asm volatile("smulwb %0, %1, %2" : "=r" (lo) : "r" (mul), "r" (val));
223-
asm volatile("smulwt %0, %1, %2" : "=r" (hi) : "r" (mul), "r" (val));
224-
asm volatile("ssat %0, %1, %2, asr %3" : "=r" (lo) : "I" (bits), "r" (lo), "I" (shift));
225-
asm volatile("ssat %0, %1, %2, asr %3" : "=r" (hi) : "I" (bits), "r" (hi), "I" (shift));
226-
asm volatile("pkhbt %0, %1, %2, lsl #8" : "=r" (val) : "r" (lo), "r" (hi)); // pack
227214
return val;
228215
#else
216+
*/
229217
uint32_t result = 0;
230218
float mod_mul = (float)mul / (float)((1<<15)-1);
231219
for (int8_t i = 0; i < 4; i++) {
@@ -239,7 +227,7 @@ static inline uint32_t mult8signed(uint32_t val, int32_t mul) {
239227
result |= (((uint32_t) intermediate) & 0xff) << (sizeof(int16_t) * 8 * i);
240228
}
241229
return result;
242-
#endif
230+
//#endif
243231
}
244232

245233
//TODO:
@@ -248,13 +236,11 @@ static inline uint32_t mult16unsigned(uint32_t val, int32_t mul) {
248236
if (mul == 0) {
249237
return 0;
250238
}
239+
/*
251240
#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
252-
int32_t hi, lo;
253-
asm volatile("umaal %0, %1, %2, %3" : "=r" (lo), "=r" (hi) : "r" (val), "r" (mul)); // unsigned accumulation mult (res=64bit)
254-
asm volatile("pkhbt %0, %1, %2, lsl #16" : "=r" (val) : "r" (lo), "r" (hi)); // pack
255241
return val;
256242
#else
257-
//mp_printf(&mp_plat_print, "mult16signed called:\n\tval: %u\t mul: %u\n", val, mul);
243+
*/
258244
uint32_t result = 0;
259245
float mod_mul = (float)mul / (float)((1<<15)-1);
260246
for (int8_t i = 0; i < 2; i++) {
@@ -267,9 +253,8 @@ static inline uint32_t mult16unsigned(uint32_t val, int32_t mul) {
267253
}
268254
result |= (((uint32_t) intermediate) + 0x8000) << (sizeof(int16_t) * 8 * i);
269255
}
270-
//mp_printf(&mp_plat_print, "\t mod_mul: %f\t result: %u\n", (double)mod_mul, result);
271256
return val;
272-
#endif
257+
//#endif
273258
}
274259

275260
static inline uint32_t mult16signed(uint32_t val, int32_t mul) {

0 commit comments

Comments
 (0)