diff --git a/cmake/cpu_features.cmake b/cmake/cpu_features.cmake index f1f6dfb9a9c..1fc3c2db804 100644 --- a/cmake/cpu_features.cmake +++ b/cmake/cpu_features.cmake @@ -16,7 +16,7 @@ option (ENABLE_SSE41 "Use SSE4.1 instructions on x86_64" 1) option (ENABLE_SSE42 "Use SSE4.2 instructions on x86_64" 1) option (ENABLE_PCLMULQDQ "Use pclmulqdq instructions on x86_64" 1) option (ENABLE_POPCNT "Use popcnt instructions on x86_64" 1) -option (ENABLE_AVX "Use AVX instructions on x86_64" 1) +option (ENABLE_AVX "Use AVX instructions on x86_64" 0) option (ENABLE_AVX2 "Use AVX2 instructions on x86_64" 0) option (ENABLE_AVX512 "Use AVX512 instructions on x86_64" 0) option (ENABLE_AVX512_VBMI "Use AVX512_VBMI instruction on x86_64 (depends on ENABLE_AVX512)" 0) diff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h index d888a181d7a..0d6ddfdf7c2 100644 --- a/src/Functions/FunctionsConversion.h +++ b/src/Functions/FunctionsConversion.h @@ -191,29 +191,27 @@ struct ConvertImpl vec_null_map_to = &col_null_map_to->getData(); } - if constexpr (std::is_same_v) + bool result_is_bool = isBool(result_type); + for (size_t i = 0; i < input_rows_count; ++i) { - if (isBool(result_type)) + if constexpr (std::is_same_v) { - for (size_t i = 0; i < input_rows_count; ++i) + if (result_is_bool) { vec_to[i] = vec_from[i] != FromFieldType(0); + continue; } - goto done; } - } - if constexpr (std::is_same_v != std::is_same_v) - { - throw Exception("Conversion between numeric types and UUID is not supported. Probably the passed UUID is unquoted", ErrorCodes::NOT_IMPLEMENTED); - } - else - { - if constexpr (IsDataTypeDecimal || IsDataTypeDecimal) + if constexpr (std::is_same_v != std::is_same_v) { - if constexpr (std::is_same_v) + throw Exception("Conversion between numeric types and UUID is not supported. Probably the passed UUID is unquoted", ErrorCodes::NOT_IMPLEMENTED); + } + else + { + if constexpr (IsDataTypeDecimal || IsDataTypeDecimal) { - for (size_t i = 0; i < input_rows_count; ++i) + if constexpr (std::is_same_v) { ToFieldType result; bool convert_result = false; @@ -233,10 +231,7 @@ struct ConvertImpl (*vec_null_map_to)[i] = true; } } - } - else - { - for (size_t i = 0; i < input_rows_count; ++i) + else { if constexpr (IsDataTypeDecimal && IsDataTypeDecimal) vec_to[i] = convertDecimals(vec_from[i], col_from->getScale(), col_to->getScale()); @@ -248,13 +243,10 @@ struct ConvertImpl throw Exception("Unsupported data type in conversion function", ErrorCodes::CANNOT_CONVERT_TYPE); } } - } - else - { - /// If From Data is Nan or Inf and we convert to integer type, throw exception - if constexpr (std::is_floating_point_v && !std::is_floating_point_v) + else { - for (size_t i = 0; i < input_rows_count; ++i) + /// If From Data is Nan or Inf and we convert to integer type, throw exception + if constexpr (std::is_floating_point_v && !std::is_floating_point_v) { if (!isFinite(vec_from[i])) { @@ -262,46 +254,15 @@ struct ConvertImpl { vec_to[i] = 0; (*vec_null_map_to)[i] = true; + continue; } else throw Exception("Unexpected inf or nan to integer conversion", ErrorCodes::CANNOT_CONVERT_TYPE); } - else - { - if constexpr (std::is_same_v - || std::is_same_v) - { - bool convert_result = accurate::convertNumeric(vec_from[i], vec_to[i]); - - if (!convert_result) - { - if (std::is_same_v) - { - vec_to[i] = 0; - (*vec_null_map_to)[i] = true; - } - else - { - throw Exception( - "Value in column " + named_from.column->getName() + " cannot be safely converted into type " - + result_type->getName(), - ErrorCodes::CANNOT_CONVERT_TYPE); - } - } - } - else - { - vec_to[i] = static_cast(vec_from[i]); - } - } } - goto done; - } - if constexpr (std::is_same_v - || std::is_same_v) - { - for (size_t i = 0; i < input_rows_count; ++i) + if constexpr (std::is_same_v + || std::is_same_v) { bool convert_result = accurate::convertNumeric(vec_from[i], vec_to[i]); @@ -321,38 +282,14 @@ struct ConvertImpl } } } - } - else - { - if constexpr (std::is_same_v && std::is_same_v) - { - /// Turns out that when ClickHouse is compiled with AVX1 or AVX2 instructions, Clang's autovectorizer produces - /// code for UInt64-to-Float23 conversion which is only ~50% as fast as scalar code. Interestingly, scalar code - /// is equally fast than code compiled for SSE4.2, so we might as well disable vectorization. This situation - /// may change with AVX512 which has a dediated instruction for that usecase (_mm512_cvtepi64_ps). -#if defined(__x86_64__) -# ifdef __clang__ -# pragma clang loop vectorize(disable) interleave(disable) -# endif -#endif - for (size_t i = 0; i < input_rows_count; ++i) - { - vec_to[i] = static_cast(vec_from[i]); - } - } else { - for (size_t i = 0; i < input_rows_count; ++i) - { - vec_to[i] = static_cast(vec_from[i]); - } + vec_to[i] = static_cast(vec_from[i]); } } } } -done: - if constexpr (std::is_same_v) return ColumnNullable::create(std::move(col_to), std::move(col_null_map_to)); else diff --git a/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.reference b/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.reference index e69de29bb2d..8984d35930a 100644 --- a/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.reference +++ b/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.reference @@ -0,0 +1,7 @@ +Instruction check fail. The CPU does not support SSSE3 instruction set. +Instruction check fail. The CPU does not support SSE4.1 instruction set. +Instruction check fail. The CPU does not support SSE4.2 instruction set. +Instruction check fail. The CPU does not support POPCNT instruction set. +: MADV_DONTNEED does not work (memset will be used instead) +: (This is the expected behaviour if you are running under QEMU) +1 diff --git a/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.sh b/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.sh index 9fb239e87b2..9b6e1e05f2d 100755 --- a/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.sh +++ b/tests/queries/0_stateless/01103_check_cpu_instructions_at_startup.sh @@ -2,18 +2,6 @@ # Tags: no-tsan, no-asan, no-ubsan, no-msan, no-debug, no-fasttest, no-cpu-aarch64 # Tag no-fasttest: avoid dependency on qemu -- invonvenient when running locally -# More than a decade after AVX was released, AVX is still not supported by QEMU, even if "-cpu help" pretends to. As a result, we cannot use -# QEMU to verify that a ClickHouse binary compiled for a SIMD level up to AVX runs on a system with a SIMD level up to AVX. The alternative -# is to disassemble the binary and grep for unwanted instructions (e.g. AVX512) which is just too fragile ... -# -# https://gitlab.com/qemu-project/qemu/-/issues/164 -# https://www.mail-archive.com/qemu-devel@nongnu.org/msg713932.html -# https://lore.kernel.org/all/CAObpvQmejWBh+RNz2vhk16-kcY_QveM_pSmM5ZeWqWv1d8AJzQ@mail.gmail.com/T/ - -exit 0 - -# keeping the original test because it is instructive and maybe QEMU will be fixed at some point ... - CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=../shell_config.sh . "$CURDIR"/../shell_config.sh