A little competition:
You can win nothing but glory, honor, and your mention in the source code.
Wanted is a terribly fast(er) implementation of this macro:
The rules:
a) Understand the macro.
b) Assembler is expressly permitted, but not a must. If c-code is used: Use GCC 4.8.4
c) Prove that your solution is faster. And correct.
d) There may be no quicker solution. That is bad luck.
e) It is fun to you.
Explanation: This macro is used in the Helix codecs (compressed audio). Not very often. But I do not like it.
Edit : it's for Teensy 3. y is signed int (32 Bit), n too, but only positive values for n. We use GCC 4.8.4.
n is NOT compile-time constant.
You can win nothing but glory, honor, and your mention in the source code.
Code:
/* From coder.h, ORIGINAL:
do y <<= n, clipping to range [-2^30, 2^30 - 1] (i.e. output has one guard bit)
*/
#define CLIP_2N_SHIFT(y, n) { \
int sign = (y) >> 31; \
if (sign != (y) >> (30 - (n))) { \
(y) = sign ^ (0x3fffffff); \
} else { \
(y) = (y) << (n); \
} \
}
Wanted is a terribly fast(er) implementation of this macro:
The rules:
a) Understand the macro.
b) Assembler is expressly permitted, but not a must. If c-code is used: Use GCC 4.8.4
c) Prove that your solution is faster. And correct.
d) There may be no quicker solution. That is bad luck.
e) It is fun to you.
Explanation: This macro is used in the Helix codecs (compressed audio). Not very often. But I do not like it.
Edit : it's for Teensy 3. y is signed int (32 Bit), n too, but only positive values for n. We use GCC 4.8.4.
n is NOT compile-time constant.
Last edited: