shithub: mp3dec

Download patch

ref: ab026df7d776aafa90e67e9894707279c2ec5214
parent: 29bae0fbd10a3e77dd73081e0f93261fb7573fb7
author: lieff <lieff@users.noreply.github.com>
date: Sat Jan 13 07:17:14 EST 2018

optimization: cpuid is bad instruction for performance - cache it

--- a/minimp3.h
+++ b/minimp3.h
@@ -126,13 +126,18 @@
 #endif
 static int have_simd()
 {
+    static int g_have_simd;
     int CPUInfo[4];
+    if (g_have_simd)
+        return g_have_simd - 1;
     minimp3_cpuid(CPUInfo, 0);
     if (CPUInfo[0] > 0)
     {
         minimp3_cpuid(CPUInfo, 1);
-        return (CPUInfo[3] & (1 << 26)); // SSE2
+        g_have_simd = (CPUInfo[3] & (1 << 26)) + 1; // SSE2
+        return g_have_simd - 1;
     }
+    g_have_simd = 1;
     return 0;
 }
 #elif defined(__arm)
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -6,7 +6,8 @@
 
 set -e
 
-gcc -O2 -g -Wall -Wextra -o minimp3 minimp3_test.c -lm
+gcc -O2 -g -Wall -Wextra -fno-asynchronous-unwind-tables -fno-stack-protector -ffunction-sections \
+-fdata-sections -Wl,--gc-sections -o minimp3 minimp3_test.c -lm
 
 APP=./minimp3