<commit_before>include(AddFileDependencies)

add_definitions(-DCOMPILE_FOR_UNIT_TESTS) # -DVC_CHECK_ALIGNMENT)
if(Vc_COMPILER_IS_MSVC)
   AddCompilerFlag("/wd4267") # Disable warning "conversion from 'size_t' to 'int', possible loss of data"
   AddCompilerFlag("/wd4723") # Disable warning "potential divide by 0" (suppress doesn't work)
endif()

if(DEFINED Vc_INSIDE_ROOT)
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "")  # Reset the ROOT default executable destination
   set(Vc_TEST_TARGET_PREFIX "vc-")
else()
   set(Vc_TEST_TARGET_PREFIX "")
endif()

# don't warn about sanity checks:
AddCompilerFlag(-Wno-tautological-constant-out-of-range-compare)
AddCompilerFlag(-Wno-tautological-compare)

macro(vc_set_first_flag_of _result)
   set(${_result})
   foreach(_flag ${ARGN})
      AddCompilerFlag("${_flag}" CXX_FLAGS ${_result} CXX_RESULT _ok)
      if(_ok)
         break()
      endif()
   endforeach()
endmacro()

vc_set_first_flag_of(_sse2_flag "-xSSE2" "-msse2" "/arch:SSE2")
vc_set_first_flag_of(_sse4_1_flag "-xSSE4.1" "-msse4.1" "/arch:SSE2")
vc_set_first_flag_of(_avx_flag "-xAVX" "-mavx" "/arch:AVX")
vc_set_first_flag_of(_avx2_flag "-xCORE-AVX2" "-mavx2" "/arch:AVX2")
macro(vc_add_run_target _target)
   if("${_target}" MATCHES "_mic$")
      if(MIC_NATIVELOAD)
         get_target_property(_exe "${_target}" OUTPUT_NAME)
         add_custom_target(run_${_target}
            ${MIC_NATIVELOAD} "${_exe}"
            DEPENDS ${_target}
            COMMENT "Execute ${_target} test"
            VERBATIM
            )
      endif()
   else()
      add_custom_target(run_${_target}
         ${_target}
         DEPENDS ${_target}
         COMMENT "Execute ${_target} test"
         VERBATIM
         )
   endif()
endmacro()

macro(vc_set_test_target_properties _target _impl _compile_flags)
   target_link_libraries(${_target} Vc)
   set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
   set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
   add_target_property(${_target} COMPILE_FLAGS "${_compile_flags} ${_extra_flags}")
   add_target_property(${_target} LABELS "${_impl}")
   add_dependencies(build_tests ${_target})
   add_dependencies(${_impl} ${_target})
   add_test(${Vc_TEST_TARGET_PREFIX}${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}")
   set_property(TEST ${Vc_TEST_TARGET_PREFIX}${_target} PROPERTY LABELS "${_impl}")
   vc_add_run_target(${_target})
endmacro()

macro(vc_add_test _name)
   set(_extra_flags)
   set(name ${_name})
   set(_state 0)
   set(_targets "Scalar;SSE;AVX1;AVX2;MIC")
   foreach(_arg ${ARGN})
      if("${_arg}" STREQUAL "FLAGS")
         set(_state 0)
      elseif("${_arg}" STREQUAL "TARGETS")
         set(_targets)
         set(_state 1)
      elseif(_state EQUAL 0)
         set(_extra_flags "${_extra_flags} -D${_arg}")
         set(name "${name}_${_arg}")
      elseif(_state EQUAL 1)
         if("${_arg}" STREQUAL "AVX")
            list(APPEND _targets "AVX1")
         else()
            list(APPEND _targets "${_arg}")
         endif()
      endif()
   endforeach()
   string(REPLACE "=" "_" name "${name}")

   set(_run_targets)

   set(_target "${name}_scalar")
   list(FIND disabled_targets ${_target} _disabled)
   if(_disabled EQUAL -1 AND "${_targets}" MATCHES "Scalar")
      file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/scalar/*.tcc" "${CMAKE_SOURCE_DIR}/scalar/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
      add_file_dependencies(${_name}.cpp "${_extra_deps}")
      add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
      vc_set_test_target_properties(${_target} Scalar "-DVC_IMPL=Scalar")
      list(APPEND _run_targets "run_${_target}")
   endif()

   if(USE_SSE2 AND NOT Vc_SSE_INTRINSICS_BROKEN AND "${_targets}" MATCHES "SSE")
      set(DVC_IMPL "-DVC_IMPL=SSE")
      if(USE_XOP)
         set(DVC_IMPL "${DVC_IMPL}+XOP")
      endif()
      if(USE_FMA)
         set(DVC_IMPL "${DVC_IMPL}+FMA")
      elseif(USE_FMA4)
         set(DVC_IMPL "${DVC_IMPL}+FMA4")
      endif()
      set(_target "${name}_sse")
      list(FIND disabled_targets ${_target} _disabled)
      if(_disabled EQUAL -1)
         file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/sse/*.tcc" "${CMAKE_SOURCE_DIR}/sse/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
         add_file_dependencies(${_name}.cpp "${_extra_deps}")
         add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
         vc_set_test_target_properties(${_target} SSE "${DVC_IMPL} ${Vc_ARCHITECTURE_FLAGS}")
         list(APPEND _run_targets "run_${_target}")
      endif()
   endif()

   if(USE_AVX AND "${_targets}" MATCHES "AVX1")
      set(DVC_IMPL "-DVC_IMPL=AVX")
      if(USE_XOP)
         set(DVC_IMPL "${DVC_IMPL}+XOP")
      endif()
      if(USE_FMA)
         set(DVC_IMPL "${DVC_IMPL}+FMA")
      elseif(USE_FMA4)
         set(DVC_IMPL "${DVC_IMPL}+FMA4")
      endif()
      set(_target "${name}_avx")
      list(FIND disabled_targets ${_target} _disabled)
      if(_disabled EQUAL -1)
         file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/avx/*.tcc" "${CMAKE_SOURCE_DIR}/avx/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
         add_file_dependencies(${_name}.cpp "${_extra_deps}")
         add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
         vc_set_test_target_properties(${_target} AVX "${DVC_IMPL} ${Vc_ARCHITECTURE_FLAGS}")
         list(APPEND _run_targets "run_${_target}")
      endif()
   endif()

   if(USE_AVX2 AND "${_targets}" MATCHES "AVX2")
      set(DVC_IMPL "-DVC_IMPL=AVX2")
      set(_target "${name}_avx2")
      list(FIND disabled_targets ${_target} _disabled)
      if(_disabled EQUAL -1)
         file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/avx/*.tcc" "${CMAKE_SOURCE_DIR}/avx/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
         add_file_dependencies(${_name}.cpp "${_extra_deps}")
         add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
         vc_set_test_target_properties(${_target} AVX2 "${DVC_IMPL} ${Vc_ARCHITECTURE_FLAGS}")
         list(APPEND _run_targets "run_${_target}")
      endif()
   endif()

   if(MIC_NATIVE_FOUND AND "${_targets}" MATCHES "MIC")
      set(DVC_IMPL "-DVC_IMPL=MIC")
      set(_target "${name}_mic")
      list(FIND disabled_targets ${_target} _disabled)
      file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/mic/*.tcc" "${CMAKE_SOURCE_DIR}/mic/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
      add_file_dependencies(${_name}.cpp "${_extra_deps}")
      mic_add_executable(${_target}
         LINK_LIBRARIES Vc_MIC
         COMPILE_FLAGS "${DVC_IMPL} ${_extra_flags}"
         SOURCES ${_name}.cpp
         EXCLUDE_FROM_ALL
         )
      add_target_property(${_target} LABELS "MIC")
      if(_disabled EQUAL -1)
         add_dependencies(build_tests ${_target})
         add_dependencies(MIC ${_target})
         if(MIC_NATIVELOAD)
            get_target_property(_exe "${_target}" OUTPUT_NAME)
            add_test(NAME ${Vc_TEST_TARGET_PREFIX}${_target}
               COMMAND "${MIC_NATIVELOAD}" "${_exe}"
               )
            set_property(TEST ${Vc_TEST_TARGET_PREFIX}${_target} PROPERTY LABELS "MIC")
            vc_add_run_target(${_target})
            list(APPEND _run_targets "run_${_target}")
         endif()
      endif()
   endif()

   add_custom_target(run_${name}_all
      COMMENT "Execute all ${name} tests"
      VERBATIM
      )
   add_dependencies(run_${name}_all ${_run_targets})

endmacro(vc_add_test)

vc_add_test(types)
vc_add_test(subscript)
vc_add_test(type_traits)
vc_add_test(stlcontainer)
vc_add_test(scalaraccess)
vc_add_test(memory)
vc_add_test(arithmetics)
vc_add_test(implicit_type_conversion)
vc_add_test(load)
vc_add_test(store)
vc_add_test(gather)
vc_add_test(gather VC_USE_BSF_GATHERS TARGETS SSE AVX AVX2)
vc_add_test(gather VC_USE_POPCNT_BSF_GATHERS TARGETS SSE AVX AVX2)
vc_add_test(gather VC_USE_SET_GATHERS TARGETS SSE AVX AVX2)
vc_add_test(scatter)
vc_add_test(scatter VC_USE_BSF_SCATTERS TARGETS SSE AVX AVX2)
vc_add_test(scatter VC_USE_POPCNT_BSF_SCATTERS TARGETS SSE AVX AVX2)
vc_add_test(math)
vc_add_test(math VC_LOG_ILP TARGETS SSE AVX AVX2)
vc_add_test(math VC_LOG_ILP2 TARGETS SSE AVX AVX2)
vc_add_test(mask)
vc_add_test(utils)
vc_add_test(deinterleave)
vc_add_test(deinterleave VC_USE_MASKMOV_SCATTER TARGETS SSE AVX AVX2)<commit_msg>cmake: the run_*_all target needs to be conditional<commit_after>include(AddFileDependencies)

add_definitions(-DCOMPILE_FOR_UNIT_TESTS) # -DVC_CHECK_ALIGNMENT)
if(Vc_COMPILER_IS_MSVC)
   AddCompilerFlag("/wd4267") # Disable warning "conversion from 'size_t' to 'int', possible loss of data"
   AddCompilerFlag("/wd4723") # Disable warning "potential divide by 0" (suppress doesn't work)
endif()

if(DEFINED Vc_INSIDE_ROOT)
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "")  # Reset the ROOT default executable destination
   set(Vc_TEST_TARGET_PREFIX "vc-")
else()
   set(Vc_TEST_TARGET_PREFIX "")
endif()

# don't warn about sanity checks:
AddCompilerFlag(-Wno-tautological-constant-out-of-range-compare)
AddCompilerFlag(-Wno-tautological-compare)

macro(vc_set_first_flag_of _result)
   set(${_result})
   foreach(_flag ${ARGN})
      AddCompilerFlag("${_flag}" CXX_FLAGS ${_result} CXX_RESULT _ok)
      if(_ok)
         break()
      endif()
   endforeach()
endmacro()

vc_set_first_flag_of(_sse2_flag "-xSSE2" "-msse2" "/arch:SSE2")
vc_set_first_flag_of(_sse4_1_flag "-xSSE4.1" "-msse4.1" "/arch:SSE2")
vc_set_first_flag_of(_avx_flag "-xAVX" "-mavx" "/arch:AVX")
vc_set_first_flag_of(_avx2_flag "-xCORE-AVX2" "-mavx2" "/arch:AVX2")
macro(vc_add_run_target _target)
   if("${_target}" MATCHES "_mic$")
      if(MIC_NATIVELOAD)
         get_target_property(_exe "${_target}" OUTPUT_NAME)
         add_custom_target(run_${_target}
            ${MIC_NATIVELOAD} "${_exe}"
            DEPENDS ${_target}
            COMMENT "Execute ${_target} test"
            VERBATIM
            )
      endif()
   else()
      add_custom_target(run_${_target}
         ${_target}
         DEPENDS ${_target}
         COMMENT "Execute ${_target} test"
         VERBATIM
         )
   endif()
endmacro()

macro(vc_set_test_target_properties _target _impl _compile_flags)
   target_link_libraries(${_target} Vc)
   set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
   set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
   add_target_property(${_target} COMPILE_FLAGS "${_compile_flags} ${_extra_flags}")
   add_target_property(${_target} LABELS "${_impl}")
   add_dependencies(build_tests ${_target})
   add_dependencies(${_impl} ${_target})
   add_test(${Vc_TEST_TARGET_PREFIX}${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}")
   set_property(TEST ${Vc_TEST_TARGET_PREFIX}${_target} PROPERTY LABELS "${_impl}")
   vc_add_run_target(${_target})
endmacro()

macro(vc_add_test _name)
   set(_extra_flags)
   set(name ${_name})
   set(_state 0)
   set(_targets "Scalar;SSE;AVX1;AVX2;MIC")
   foreach(_arg ${ARGN})
      if("${_arg}" STREQUAL "FLAGS")
         set(_state 0)
      elseif("${_arg}" STREQUAL "TARGETS")
         set(_targets)
         set(_state 1)
      elseif(_state EQUAL 0)
         set(_extra_flags "${_extra_flags} -D${_arg}")
         set(name "${name}_${_arg}")
      elseif(_state EQUAL 1)
         if("${_arg}" STREQUAL "AVX")
            list(APPEND _targets "AVX1")
         else()
            list(APPEND _targets "${_arg}")
         endif()
      endif()
   endforeach()
   string(REPLACE "=" "_" name "${name}")

   set(_run_targets)

   set(_target "${name}_scalar")
   list(FIND disabled_targets ${_target} _disabled)
   if(_disabled EQUAL -1 AND "${_targets}" MATCHES "Scalar")
      file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/scalar/*.tcc" "${CMAKE_SOURCE_DIR}/scalar/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
      add_file_dependencies(${_name}.cpp "${_extra_deps}")
      add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
      vc_set_test_target_properties(${_target} Scalar "-DVC_IMPL=Scalar")
      list(APPEND _run_targets "run_${_target}")
   endif()

   if(USE_SSE2 AND NOT Vc_SSE_INTRINSICS_BROKEN AND "${_targets}" MATCHES "SSE")
      set(DVC_IMPL "-DVC_IMPL=SSE")
      if(USE_XOP)
         set(DVC_IMPL "${DVC_IMPL}+XOP")
      endif()
      if(USE_FMA)
         set(DVC_IMPL "${DVC_IMPL}+FMA")
      elseif(USE_FMA4)
         set(DVC_IMPL "${DVC_IMPL}+FMA4")
      endif()
      set(_target "${name}_sse")
      list(FIND disabled_targets ${_target} _disabled)
      if(_disabled EQUAL -1)
         file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/sse/*.tcc" "${CMAKE_SOURCE_DIR}/sse/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
         add_file_dependencies(${_name}.cpp "${_extra_deps}")
         add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
         vc_set_test_target_properties(${_target} SSE "${DVC_IMPL} ${Vc_ARCHITECTURE_FLAGS}")
         list(APPEND _run_targets "run_${_target}")
      endif()
   endif()

   if(USE_AVX AND "${_targets}" MATCHES "AVX1")
      set(DVC_IMPL "-DVC_IMPL=AVX")
      if(USE_XOP)
         set(DVC_IMPL "${DVC_IMPL}+XOP")
      endif()
      if(USE_FMA)
         set(DVC_IMPL "${DVC_IMPL}+FMA")
      elseif(USE_FMA4)
         set(DVC_IMPL "${DVC_IMPL}+FMA4")
      endif()
      set(_target "${name}_avx")
      list(FIND disabled_targets ${_target} _disabled)
      if(_disabled EQUAL -1)
         file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/avx/*.tcc" "${CMAKE_SOURCE_DIR}/avx/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
         add_file_dependencies(${_name}.cpp "${_extra_deps}")
         add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
         vc_set_test_target_properties(${_target} AVX "${DVC_IMPL} ${Vc_ARCHITECTURE_FLAGS}")
         list(APPEND _run_targets "run_${_target}")
      endif()
   endif()

   if(USE_AVX2 AND "${_targets}" MATCHES "AVX2")
      set(DVC_IMPL "-DVC_IMPL=AVX2")
      set(_target "${name}_avx2")
      list(FIND disabled_targets ${_target} _disabled)
      if(_disabled EQUAL -1)
         file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/avx/*.tcc" "${CMAKE_SOURCE_DIR}/avx/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
         add_file_dependencies(${_name}.cpp "${_extra_deps}")
         add_executable(${_target} EXCLUDE_FROM_ALL ${_name}.cpp)
         vc_set_test_target_properties(${_target} AVX2 "${DVC_IMPL} ${Vc_ARCHITECTURE_FLAGS}")
         list(APPEND _run_targets "run_${_target}")
      endif()
   endif()

   if(MIC_NATIVE_FOUND AND "${_targets}" MATCHES "MIC")
      set(DVC_IMPL "-DVC_IMPL=MIC")
      set(_target "${name}_mic")
      list(FIND disabled_targets ${_target} _disabled)
      file(GLOB _extra_deps "${CMAKE_SOURCE_DIR}/mic/*.tcc" "${CMAKE_SOURCE_DIR}/mic/*.h" "${CMAKE_SOURCE_DIR}/common/*.h")
      add_file_dependencies(${_name}.cpp "${_extra_deps}")
      mic_add_executable(${_target}
         LINK_LIBRARIES Vc_MIC
         COMPILE_FLAGS "${DVC_IMPL} ${_extra_flags}"
         SOURCES ${_name}.cpp
         EXCLUDE_FROM_ALL
         )
      add_target_property(${_target} LABELS "MIC")
      if(_disabled EQUAL -1)
         add_dependencies(build_tests ${_target})
         add_dependencies(MIC ${_target})
         if(MIC_NATIVELOAD)
            get_target_property(_exe "${_target}" OUTPUT_NAME)
            add_test(NAME ${Vc_TEST_TARGET_PREFIX}${_target}
               COMMAND "${MIC_NATIVELOAD}" "${_exe}"
               )
            set_property(TEST ${Vc_TEST_TARGET_PREFIX}${_target} PROPERTY LABELS "MIC")
            vc_add_run_target(${_target})
            list(APPEND _run_targets "run_${_target}")
         endif()
      endif()
   endif()

   if(_run_targets)
      add_custom_target(run_${name}_all
         COMMENT "Execute all ${name} tests"
         VERBATIM
         )
      add_dependencies(run_${name}_all ${_run_targets})
   endif()

endmacro(vc_add_test)

vc_add_test(types)
vc_add_test(subscript)
vc_add_test(type_traits)
vc_add_test(stlcontainer)
vc_add_test(scalaraccess)
vc_add_test(memory)
vc_add_test(arithmetics)
vc_add_test(implicit_type_conversion)
vc_add_test(load)
vc_add_test(store)
vc_add_test(gather)
vc_add_test(gather VC_USE_BSF_GATHERS TARGETS SSE AVX AVX2)
vc_add_test(gather VC_USE_POPCNT_BSF_GATHERS TARGETS SSE AVX AVX2)
vc_add_test(gather VC_USE_SET_GATHERS TARGETS SSE AVX AVX2)
vc_add_test(scatter)
vc_add_test(scatter VC_USE_BSF_SCATTERS TARGETS SSE AVX AVX2)
vc_add_test(scatter VC_USE_POPCNT_BSF_SCATTERS TARGETS SSE AVX AVX2)
vc_add_test(math)
vc_add_test(math VC_LOG_ILP TARGETS SSE AVX AVX2)
vc_add_test(math VC_LOG_ILP2 TARGETS SSE AVX AVX2)
vc_add_test(mask)
vc_add_test(utils)
vc_add_test(deinterleave)
vc_add_test(deinterleave VC_USE_MASKMOV_SCATTER TARGETS SSE AVX AVX2)
{'fraction_non_alphanumeric': 0.13652781122080423, 'fraction_numerical': 0.006982903924873585, 'mean_word_length': 3.9843984398439845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2601877', 'n_tokens_mistral': 6592, 'n_tokens_neox': 6301, 'n_words': 986}