The type of expression '1<<31' is signed int and this causes cppcheck to
issue the following warning.
src/gf_w32.c:681]: (error) Signed integer overflow for expression
'1<<31'.
Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
in gf_w32_cfmgk_multiply_region_from_single(), follow warning is
reported by gcc:
gf-complete/src/gf_w32.c:410:5: warning: ‘a’ may be used uninitialized
in this function [-Wmaybe-uninitialized]
g = _mm_insert_epi64 (a, g_star, 0);
^
actually, we are using `a` as a dummy parameter for initializing `g` and
`q`. and only the lower lower 64 bits of them are used when doing
calculation. but their lower 64 bits are always initialized using
_mm_insert_epi64(). so this is a false alarm.
but we can silence this warning by moving the statement initializing `a`
up before passing it to _mm_insert_epi64(). this change does not hurt
the performance.
Signed-off-by: Kefu Chai <kchai@redhat.com>
ax_ext.m4 no longer performs any CPU checks. Instead it just checks
if the the compile supports SIMD flags.
Runtime detection will choose the right methods base on CPU
instructions available.
Intel AVX support is still done through the build since it would
require a major refactoring of the code base to support it at runtime.
For now I added a configuration flag --enable-avx that can be used
to compile with AVX support.
Also use cpu intrinsics instead of __asm__
This commits adds support for runtime detection of SIMD instructions. The idea is that you would build once with all supported SIMD functions and the same binaries could run on different machines with varying support for SIMD. At runtime gf-complete will select the right functions based on the processor.
gf_cpu.c has the logic to detect SIMD instructions. On Intel processors this is done through cpuid. For ARM on linux we use getauxv.
The logic in gf_w*.c has been changed to check for runtime SIMD support and fallback to generic code.
Also a new test has been added. It compares the functions selected by gf_init when we enable/disable SIMD support through build flags, with runtime enabling/disabling. The test checks if the results are identical.
There is currently no way to figure out which functions were selected
during gf_init and as a result of SIMD options. This is not even possible
in gdb since most functions are static.
This commit adds a new macro SET_FUNCTION that records the name of the
function selected during init inside the gf_internal structure. This macro
only works when DEBUG_FUNCTIONS is defined during compile. Otherwise the
code works exactly as it did before this change.
The names of selected functions will be used during testing of SIMD
runtime detection.
All calls such as:
gf->multiply.w32 = gf_w16_shift_multiply;
need to be replaced with the following:
SET_FUNCTION(gf,multiply,w32,gf_w16_shift_multiply)
Also added a new flag to tools/gf_methods that will print the names of
functions selected during gf_init.
* (1 << w) are changed into ((uint32_t)1 << w)
* int are changed into uint32_t
gf.c: gf_composite_get_default_poly:
a larger unsigned were assigned to unsigned integers in which case
the type of the assigned variable is changed to be the same as the
value assigned to it.
gf_w16.c: GF_MULTBY_TWO
setting the parameter to a variable instead of passing the expression
resolves the warning for some reason.
Signed-off-by: Loic Dachary <loic@dachary.org>
Fix for Coverity issue (from Ceph):
CID 1193089 (#1 of 1): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << g_r with type
int (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in
a context that expects an expression of type uint64_t (64 bits, unsigned).
CID 1193090 (#1 of 1): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << g_s with type
int (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in
a context that expects an expression of type uint64_t (64 bits, unsigned).
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for Coverity issue (from Ceph):
CID 1193088 (#1 of 1): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << g_s with type
int (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in
a context that expects an expression of type uint64_t (64 bits, unsigned).
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for Coverity issue (from Ceph):
CID 1193087 (#1 of 1): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << g_r with type
int (32 bits, signed) is evaluated using 32-bit arithmetic, and then used
in a context that expects an expression of type uint64_t (64 bits, unsigned).
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for Coverity issue (from Ceph):
CID 1193086 (#1 of 1): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << g_r with type
int (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in
a context that expects an expression of type uint64_t (64 bits, unsigned).
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for Coverity issue:
CID 1297812 (#1 of 1): Constant variable guards dead code (DEADCODE)
dead_error_begin: Execution cannot reach this statement: fprintf(stderr,
"Code conta....
Local variable no_default_flag is assigned only once, to a constant
value, making it effectively constant throughout its scope. If this
is not the intent, examine the logic to see if there is a missing
assignment that would make no_default_flag not remain constant.
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for Coverity issue:
CID 1297852 (#1 of 1): 'Constant'; variable guards dead code (DEADCODE)
dead_error_begin: Execution cannot reach this statement:
fprintf(stderr, "Code conta....
Local variable no_default_flag is assigned only once, to a constant value,
making it effectively constant throughout its scope. If this is not the
intent, examine the logic to see if there is a missing assignment that
would make no_default_flag not remain constant.
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
When a fatal error (unaligned memory etc.) is detected, gf-complete should
assert(3) instead of exit(3) to give a chance to the calling program to
catch the exception and display a stack trace. Although it is possible
for gdb to display the stack trace and break on exit, libraries are not
usually expected to terminate the calling program in this way.
Signed-off-by: Loic Dachary <loic@dachary.org>
Optimisations for the 4,4 split table region multiplication and carry
less multiplication using NEON's polynomial long multiplication.
arm: w8: NEON carry less multiplication
Selected time_tool.sh results for a 1.7GHz cortex-a9:
Region Best (MB/s): 375.86 W-Method: 8 -m CARRY_FREE -
Region Best (MB/s): 142.94 W-Method: 8 -m TABLE -
Region Best (MB/s): 225.01 W-Method: 8 -m TABLE -r DOUBLE -
Region Best (MB/s): 211.23 W-Method: 8 -m TABLE -r DOUBLE -r LAZY -
Region Best (MB/s): 160.09 W-Method: 8 -m LOG -
Region Best (MB/s): 123.61 W-Method: 8 -m LOG_ZERO -
Region Best (MB/s): 123.85 W-Method: 8 -m LOG_ZERO_EXT -
Region Best (MB/s): 1183.79 W-Method: 8 -m SPLIT 8 4 -r SIMD -
Region Best (MB/s): 177.68 W-Method: 8 -m SPLIT 8 4 -r NOSIMD -
Region Best (MB/s): 87.85 W-Method: 8 -m COMPOSITE 2 - -
Region Best (MB/s): 428.59 W-Method: 8 -m COMPOSITE 2 - -r ALTMAP -
Optimisations for the single table region multiplication and carry less
multiplication using NEON's polynomial multiplication of 8-bit values.
The single polynomial multiplication is not that useful but vector
version is for region multiplication.
Selected time_tool.sh results for a 1.7GHz cortex-a9:
Region Best (MB/s): 672.72 W-Method: 4 -m CARRY_FREE -
Region Best (MB/s): 265.84 W-Method: 4 -m BYTWO_p -
Region Best (MB/s): 329.41 W-Method: 4 -m TABLE -r DOUBLE -
Region Best (MB/s): 278.63 W-Method: 4 -m TABLE -r QUAD -
Region Best (MB/s): 329.81 W-Method: 4 -m TABLE -r QUAD -r LAZY -
Region Best (MB/s): 1318.03 W-Method: 4 -m TABLE -r SIMD -
Region Best (MB/s): 165.15 W-Method: 4 -m TABLE -r NOSIMD -
Region Best (MB/s): 99.73 W-Method: 4 -m LOG -
Since there can only be one -m, base cannot be set by -m COMPOSITE and
then deallocated on the second -m if it is bugous. The second -m will
exit on error at _gf_errno = GF_E_TWOMULT;.
Signed-off-by: Loic Dachary <loic-201408@dachary.org>
The 'm2' variable in gf_w64_clm_multiply_region_from_single_2() isn't
used except for calculations on 'm2' which are not used later in the code.
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for coverity issue from Ceph project:
CID 1193093 (#1 of 1): Structurally dead code (UNREACHABLE)
unreachable: This code cannot be reached: "return gf_w4_double_table_i...".
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Remove identical expression, reorganize code in gf_error_check()
to be identical handled trough all checks. Removed (raltmap && arg1 != 4)
check - this is dead code (arg1 is always 4 in this code path).
Fix for coverity issue from Ceph project:
CID 1193071 (#1 of 1): Same on both sides (CONSTANT_EXPRESSION_RESULT)
pointless_expression: The expression (arg1 == 4 && arg2 == 32) ||
(arg1 == 4 && arg2 == 32) does not accomplish anything because it
evaluates to either of its identical operands, arg1 == 4 && arg2 == 32.
Did you intend the operands to be different?
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Since there is no comment indicating fallthrough on purpose added a
break in switch value 5 and 6.
Fix for coverity issue from Ceph project:
CID 1193084 (#1 of 1): Missing break in switch (MISSING_BREAK)
unterminated_case: This case (value 5) is not terminated by a 'break'
statement.
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Since there is no comment indicating fallthrough on purpose added a
break in switch value 5 and 6.
Fix for coverity issue from Ceph project:
CID 1193082 (#1 of 1): Missing break in switch (MISSING_BREAK)
unterminated_case: This case (value 5) is not terminated by a 'break'
statement.
CID 1193083 (#1 of 1): Missing break in switch (MISSING_BREAK)
unterminated_case: This case (value 6) is not terminated by a 'break'
statement.
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>