History

Optimize mp3d_scale_pcm using ssat instruction.

lieff committed 6 years ago

Commit 60fd2171 parent 55da78c1 file · +16 −0Browse files

Unified · Split

minimp3.h+16−0
@@ -191,6 +191,16 @@ static int have_simd() · 190 unmodified lines
191#define HAVE_SIMD 0191#define HAVE_SIMD 0
192#endif /* !defined(MINIMP3_NO_SIMD) */192#endif /* !defined(MINIMP3_NO_SIMD) */
193 193
194#if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) && !defined(__aarch64__)
195#define HAVE_ARMV6 1
196static __inline__ __attribute__((always_inline)) int32_t minimp3_clip_int16_arm(int32_t a)
197{
198 int32_t x = 0;
199 __asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
200 return x;
201}
202#endif
203
194typedef struct204typedef struct
195{205{
196 const uint8_t *buf;206 const uint8_t *buf;
@@ -1407,10 +1417,16 @@ static void mp3d_DCT_II(float *grbuf, int n) · 1210 unmodified lines
1407#ifndef MINIMP3_FLOAT_OUTPUT1417#ifndef MINIMP3_FLOAT_OUTPUT
1408static int16_t mp3d_scale_pcm(float sample)1418static int16_t mp3d_scale_pcm(float sample)
1409{1419{
1420#if HAVE_ARMV6
1421 int32_t s32 = (int32_t)(sample + .5f);
1422 s32 -= (s32 < 0);
1423 int16_t s = (int16_t)minimp3_clip_int16_arm(s32);
1424#else
1410 if (sample >= 32766.5) return (int16_t) 32767;1425 if (sample >= 32766.5) return (int16_t) 32767;
1411 if (sample <= -32767.5) return (int16_t)-32768;1426 if (sample <= -32767.5) return (int16_t)-32768;
1412 int16_t s = (int16_t)(sample + .5f);1427 int16_t s = (int16_t)(sample + .5f);
1413 s -= (s < 0); /* away from zero, to be compliant */1428 s -= (s < 0); /* away from zero, to be compliant */
1429#endif
1414 return s;1430 return s;
1415}1431}
1416#else /* MINIMP3_FLOAT_OUTPUT */1432#else /* MINIMP3_FLOAT_OUTPUT */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t