]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
memcmp: remove unreachable code from memcmp simd
authorVictor Julien <vjulien@oisf.net>
Thu, 5 May 2022 05:16:53 +0000 (07:16 +0200)
committerJeff Lucovsky <jeff@lucovsky.org>
Tue, 24 May 2022 13:40:31 +0000 (09:40 -0400)
cppcheck:

src/util-memcmp.h:281:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:280:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:269:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:281:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:344:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:343:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:318:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:344:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:171:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:170:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:159:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:171:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:233:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:232:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:208:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:233:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^

(cherry picked from commit ca97ed44361fe84cae72fad1807825f149f983eb)

src/util-memcmp.h

index 3f026f4dafdda4d7f63316207b072b60fffc8701..2d25060f96bf7d249ba6d5136c025af444b859d3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -20,7 +20,7 @@
  *
  * \author Victor Julien <victor@inliniac.net>
  *
- * Memcmp implementations for SSE3, SSE4.1, SSE4.2 and TILE-Gx SIMD.
+ * Memcmp implementations for SSE3, SSE4.1, SSE4.2.
  *
  * Both SCMemcmp and SCMemcmpLowercase return 0 on a exact match,
  * 1 on a failed match.
@@ -166,17 +166,8 @@ static inline int SCMemcmp(const void *s1, const void *s2, size_t len)
         b2 = _mm_loadu_si128((const __m128i *) s2);
         c = _mm_cmpeq_epi8(b1, b2);
 
-        int diff = len - offset;
-        if (diff < 16) {
-            int rmask = ~(0xFFFFFFFF << diff);
-
-            if ((_mm_movemask_epi8(c) & rmask) != rmask) {
-                return 1;
-            }
-        } else {
-            if (_mm_movemask_epi8(c) != 0x0000FFFF) {
-                return 1;
-            }
+        if (_mm_movemask_epi8(c) != 0x0000FFFF) {
+            return 1;
         }
 
         offset += SCMEMCMP_BYTES;
@@ -227,17 +218,8 @@ static inline int SCMemcmpLowercase(const void *s1, const void *s2, size_t len)
         /* now all is lowercase, let's do the actual compare (reuse mask1 reg) */
         mask1 = _mm_cmpeq_epi8(b1, b2);
 
-        int diff = len - offset;
-        if (diff < 16) {
-            int rmask = ~(0xFFFFFFFF << diff);
-
-            if ((_mm_movemask_epi8(mask1) & rmask) != rmask) {
-                return 1;
-            }
-        } else {
-            if (_mm_movemask_epi8(mask1) != 0x0000FFFF) {
-                return 1;
-            }
+        if (_mm_movemask_epi8(mask1) != 0x0000FFFF) {
+            return 1;
         }
 
         offset += SCMEMCMP_BYTES;
@@ -275,17 +257,8 @@ static inline int SCMemcmp(const void *s1, const void *s2, size_t len)
         b2 = _mm_loadu_si128((const __m128i *) s2);
         c = _mm_cmpeq_epi8(b1, b2);
 
-        int diff = len - offset;
-        if (diff < 16) {
-            int rmask = ~(0xFFFFFFFF << diff);
-
-            if ((_mm_movemask_epi8(c) & rmask) != rmask) {
-                return 1;
-            }
-        } else {
-            if (_mm_movemask_epi8(c) != 0x0000FFFF) {
-                return 1;
-            }
+        if (_mm_movemask_epi8(c) != 0x0000FFFF) {
+            return 1;
         }
 
         offset += SCMEMCMP_BYTES;
@@ -338,17 +311,8 @@ static inline int SCMemcmpLowercase(const void *s1, const void *s2, size_t len)
         /* now all is lowercase, let's do the actual compare (reuse mask1 reg) */
         mask1 = _mm_cmpeq_epi8(b1, b2);
 
-        int diff = len - offset;
-        if (diff < 16) {
-            int rmask = ~(0xFFFFFFFF << diff);
-
-            if ((_mm_movemask_epi8(mask1) & rmask) != rmask) {
-                return 1;
-            }
-        } else {
-            if (_mm_movemask_epi8(mask1) != 0x0000FFFF) {
-                return 1;
-            }
+        if (_mm_movemask_epi8(mask1) != 0x0000FFFF) {
+            return 1;
         }
 
         offset += SCMEMCMP_BYTES;