From: Victor Julien Date: Thu, 5 May 2022 05:16:53 +0000 (+0200) Subject: memcmp: remove unreachable code from memcmp simd X-Git-Tag: suricata-5.0.10~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b05acda67000fd401a18203e7e3976de89071fe0;p=thirdparty%2Fsuricata.git memcmp: remove unreachable code from memcmp simd 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) --- diff --git a/src/util-memcmp.h b/src/util-memcmp.h index 3f026f4daf..2d25060f96 100644 --- a/src/util-memcmp.h +++ b/src/util-memcmp.h @@ -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 * - * 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;