diff libgsmefr/basic_op.h @ 350:9b05bbc23b8a

libgsmefr inline: make shift count guards 100% robust
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 Apr 2024 05:34:54 +0000
parents ed8762eea8a1
children
line wrap: on
line diff
--- a/libgsmefr/basic_op.h	Mon Apr 22 08:14:20 2024 +0000
+++ b/libgsmefr/basic_op.h	Tue Apr 23 05:34:54 2024 +0000
@@ -4,7 +4,7 @@
  * The original version contained only function declarations,
  * resulting in a function call for every elementary operation;
  * the present version implements most of these operations as inline
- * functions.  (Further update: for extra speed-up, the some inline
+ * functions.  (Further update: for extra speed-up, some inline
  * function implementations have been lifted from PacketVideo AMR
  * version, aka libopencore-amrnb.)
  *
@@ -206,9 +206,9 @@
     Word16 var_out;
 
     if (unlikely(var2 < 0)) {
+        if (unlikely(var2 < -15))
+            var2 = -15;
         var2 = -var2;
-        if (unlikely(var2 > 15))
-            var2 = 15;
         var_out = var1 >> var2;
     } else {
         if (unlikely(var2 > 15))
@@ -262,9 +262,9 @@
     Word16 var_out;
 
     if (unlikely(var2 < 0)) {
+        if (unlikely(var2 < -15))
+            var2 = -15;
         var2 = -var2;
-        if (unlikely(var2 > 15))
-            var2 = 15;
         var_out = var1 << var2;
         if (unlikely(var_out >> var2 != var1))
         {
@@ -800,9 +800,9 @@
     Word32 L_var_out;
 
     if (unlikely(var2 < 0)) {
+        if (unlikely(var2 < -31))
+            var2 = -31;
         var2 = -var2;
-        if (unlikely(var2 > 31))
-            var2 = 31;
         L_var_out = L_var1 >> var2;
     } else {
         if (unlikely(var2 > 31))
@@ -853,9 +853,9 @@
     Word32 L_var_out;
 
     if (unlikely(var2 < 0)) {
+        if (unlikely(var2 < -31))
+            var2 = -31;
         var2 = -var2;
-        if (unlikely(var2 > 31))
-            var2 = 31;
         L_var_out = L_var1 << var2;
         if (unlikely(L_var_out >> var2 != L_var1))
             L_var_out = (L_var1 >> 31) ^ MAX_32;