shun-iwasawa 82a8f5
macro(simd_fail message)
shun-iwasawa 82a8f5
  if(REQUIRE_SIMD)
shun-iwasawa 82a8f5
    message(FATAL_ERROR "${message}.")
shun-iwasawa 82a8f5
  else()
shun-iwasawa 82a8f5
    message(WARNING "${message}.  Performance will suffer.")
shun-iwasawa 82a8f5
    set(WITH_SIMD 0 PARENT_SCOPE)
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
endmacro()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
# x86[-64] (NASM)
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CPU_TYPE STREQUAL "x86_64" OR CPU_TYPE STREQUAL "i386")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(CMAKE_ASM_NASM_FLAGS_DEBUG_INIT "-g")
shun-iwasawa 82a8f5
set(CMAKE_ASM_NASM_FLAGS_RELWITHDEBINFO_INIT "-g")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
# Allow the location of the NASM executable to be specified using the ASM_NASM
shun-iwasawa 82a8f5
# environment variable.  This should happen automatically, but unfortunately
shun-iwasawa 82a8f5
# enable_language(ASM_NASM) doesn't parse the ASM_NASM environment variable
shun-iwasawa 82a8f5
# until after CMAKE_ASM_NASM_COMPILER has been populated with the results of
shun-iwasawa 82a8f5
# searching for NASM or YASM in the PATH.
shun-iwasawa 82a8f5
if(NOT DEFINED CMAKE_ASM_NASM_COMPILER AND DEFINED ENV{ASM_NASM})
shun-iwasawa 82a8f5
  set(CMAKE_ASM_NASM_COMPILER $ENV{ASM_NASM})
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CPU_TYPE STREQUAL "x86_64")
shun-iwasawa 82a8f5
  if(CYGWIN)
shun-iwasawa 82a8f5
    set(CMAKE_ASM_NASM_OBJECT_FORMAT win64)
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
elseif(CPU_TYPE STREQUAL "i386")
shun-iwasawa 82a8f5
  if(BORLAND)
shun-iwasawa 82a8f5
    set(CMAKE_ASM_NASM_OBJECT_FORMAT obj)
shun-iwasawa 82a8f5
  elseif(CYGWIN)
shun-iwasawa 82a8f5
    set(CMAKE_ASM_NASM_OBJECT_FORMAT win32)
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(NOT REQUIRE_SIMD)
shun-iwasawa 82a8f5
  include(CheckLanguage)
shun-iwasawa 82a8f5
  check_language(ASM_NASM)
shun-iwasawa 82a8f5
  if(NOT CMAKE_ASM_NASM_COMPILER)
shun-iwasawa 82a8f5
    simd_fail("SIMD extensions disabled: could not find NASM compiler")
shun-iwasawa 82a8f5
    return()
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
enable_language(ASM_NASM)
shun-iwasawa 82a8f5
message(STATUS "CMAKE_ASM_NASM_COMPILER = ${CMAKE_ASM_NASM_COMPILER}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CMAKE_ASM_NASM_OBJECT_FORMAT MATCHES "macho*")
shun-iwasawa 82a8f5
  set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DMACHO")
shun-iwasawa 82a8f5
elseif(CMAKE_ASM_NASM_OBJECT_FORMAT MATCHES "elf*")
shun-iwasawa 82a8f5
  set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DELF")
shun-iwasawa 82a8f5
  set(CMAKE_ASM_NASM_DEBUG_FORMAT "dwarf2")
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
if(CPU_TYPE STREQUAL "x86_64")
shun-iwasawa 82a8f5
  if(WIN32 OR CYGWIN)
shun-iwasawa 82a8f5
    set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DWIN64")
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
  set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -D__x86_64__")
shun-iwasawa 82a8f5
elseif(CPU_TYPE STREQUAL "i386")
shun-iwasawa 82a8f5
  if(BORLAND)
shun-iwasawa 82a8f5
    set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DOBJ32")
shun-iwasawa 82a8f5
  elseif(WIN32 OR CYGWIN)
shun-iwasawa 82a8f5
    set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DWIN32")
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
message(STATUS "CMAKE_ASM_NASM_OBJECT_FORMAT = ${CMAKE_ASM_NASM_OBJECT_FORMAT}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(NOT CMAKE_ASM_NASM_OBJECT_FORMAT)
shun-iwasawa 82a8f5
  simd_fail("SIMD extensions disabled: could not determine NASM object format")
shun-iwasawa 82a8f5
  return()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
get_filename_component(CMAKE_ASM_NASM_COMPILER_TYPE
shun-iwasawa 82a8f5
  "${CMAKE_ASM_NASM_COMPILER}" NAME_WE)
shun-iwasawa 82a8f5
if(CMAKE_ASM_NASM_COMPILER_TYPE MATCHES "yasm")
shun-iwasawa 82a8f5
  foreach(var CMAKE_ASM_NASM_FLAGS_DEBUG CMAKE_ASM_NASM_FLAGS_RELWITHDEBINFO)
shun-iwasawa 82a8f5
    if(${var} STREQUAL "-g")
shun-iwasawa 82a8f5
      if(CMAKE_ASM_NASM_DEBUG_FORMAT)
shun-iwasawa 82a8f5
        set_property(CACHE ${var} PROPERTY VALUE "-g ${CMAKE_ASM_NASM_DEBUG_FORMAT}")
shun-iwasawa 82a8f5
      else()
shun-iwasawa 82a8f5
        set_property(CACHE ${var} PROPERTY VALUE "")
shun-iwasawa 82a8f5
      endif()
shun-iwasawa 82a8f5
    endif()
shun-iwasawa 82a8f5
  endforeach()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(NOT WIN32 AND (CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED))
shun-iwasawa 82a8f5
  set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DPIC")
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
shun-iwasawa 82a8f5
set(EFFECTIVE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} ${CMAKE_ASM_NASM_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
shun-iwasawa 82a8f5
message(STATUS "CMAKE_ASM_NASM_FLAGS = ${EFFECTIVE_ASM_NASM_FLAGS}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -I\"${CMAKE_CURRENT_SOURCE_DIR}/nasm/\" -I\"${CMAKE_CURRENT_SOURCE_DIR}/${CPU_TYPE}/\"")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(GREP grep)
shun-iwasawa 82a8f5
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
shun-iwasawa 82a8f5
  set(GREP ggrep)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
add_custom_target(jsimdcfg COMMAND
shun-iwasawa 82a8f5
  ${CMAKE_C_COMPILER} -E -I${CMAKE_BINARY_DIR} -I${CMAKE_CURRENT_BINARY_DIR}
shun-iwasawa 82a8f5
    -I${CMAKE_CURRENT_SOURCE_DIR}
shun-iwasawa 82a8f5
    ${CMAKE_CURRENT_SOURCE_DIR}/nasm/jsimdcfg.inc.h |
shun-iwasawa 82a8f5
  ${GREP} -E '^[\;%]|^\ %' | sed 's%_cpp_protection_%%' |
shun-iwasawa 82a8f5
  sed 's@% define@%define@g' >${CMAKE_CURRENT_SOURCE_DIR}/nasm/jsimdcfg.inc)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CPU_TYPE STREQUAL "x86_64")
shun-iwasawa 82a8f5
  set(SIMD_SOURCES x86_64/jsimdcpu.asm x86_64/jfdctflt-sse.asm
shun-iwasawa 82a8f5
    x86_64/jccolor-sse2.asm x86_64/jcgray-sse2.asm x86_64/jchuff-sse2.asm
shun-iwasawa 82a8f5
    x86_64/jcphuff-sse2.asm x86_64/jcsample-sse2.asm x86_64/jdcolor-sse2.asm
shun-iwasawa 82a8f5
    x86_64/jdmerge-sse2.asm x86_64/jdsample-sse2.asm x86_64/jfdctfst-sse2.asm
shun-iwasawa 82a8f5
    x86_64/jfdctint-sse2.asm x86_64/jidctflt-sse2.asm x86_64/jidctfst-sse2.asm
shun-iwasawa 82a8f5
    x86_64/jidctint-sse2.asm x86_64/jidctred-sse2.asm x86_64/jquantf-sse2.asm
shun-iwasawa 82a8f5
    x86_64/jquanti-sse2.asm
shun-iwasawa 82a8f5
    x86_64/jccolor-avx2.asm x86_64/jcgray-avx2.asm x86_64/jcsample-avx2.asm
shun-iwasawa 82a8f5
    x86_64/jdcolor-avx2.asm x86_64/jdmerge-avx2.asm x86_64/jdsample-avx2.asm
shun-iwasawa 82a8f5
    x86_64/jfdctint-avx2.asm x86_64/jidctint-avx2.asm x86_64/jquanti-avx2.asm)
shun-iwasawa 82a8f5
else()
shun-iwasawa 82a8f5
  set(SIMD_SOURCES i386/jsimdcpu.asm i386/jfdctflt-3dn.asm
shun-iwasawa 82a8f5
    i386/jidctflt-3dn.asm i386/jquant-3dn.asm
shun-iwasawa 82a8f5
    i386/jccolor-mmx.asm i386/jcgray-mmx.asm i386/jcsample-mmx.asm
shun-iwasawa 82a8f5
    i386/jdcolor-mmx.asm i386/jdmerge-mmx.asm i386/jdsample-mmx.asm
shun-iwasawa 82a8f5
    i386/jfdctfst-mmx.asm i386/jfdctint-mmx.asm i386/jidctfst-mmx.asm
shun-iwasawa 82a8f5
    i386/jidctint-mmx.asm i386/jidctred-mmx.asm i386/jquant-mmx.asm
shun-iwasawa 82a8f5
    i386/jfdctflt-sse.asm i386/jidctflt-sse.asm i386/jquant-sse.asm
shun-iwasawa 82a8f5
    i386/jccolor-sse2.asm i386/jcgray-sse2.asm i386/jchuff-sse2.asm
shun-iwasawa 82a8f5
    i386/jcphuff-sse2.asm i386/jcsample-sse2.asm i386/jdcolor-sse2.asm
shun-iwasawa 82a8f5
    i386/jdmerge-sse2.asm i386/jdsample-sse2.asm i386/jfdctfst-sse2.asm
shun-iwasawa 82a8f5
    i386/jfdctint-sse2.asm i386/jidctflt-sse2.asm i386/jidctfst-sse2.asm
shun-iwasawa 82a8f5
    i386/jidctint-sse2.asm i386/jidctred-sse2.asm i386/jquantf-sse2.asm
shun-iwasawa 82a8f5
    i386/jquanti-sse2.asm
shun-iwasawa 82a8f5
    i386/jccolor-avx2.asm i386/jcgray-avx2.asm i386/jcsample-avx2.asm
shun-iwasawa 82a8f5
    i386/jdcolor-avx2.asm i386/jdmerge-avx2.asm i386/jdsample-avx2.asm
shun-iwasawa 82a8f5
    i386/jfdctint-avx2.asm i386/jidctint-avx2.asm i386/jquanti-avx2.asm)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(MSVC_IDE)
shun-iwasawa 82a8f5
  set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}")
shun-iwasawa 82a8f5
  string(REGEX REPLACE " " ";" CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS}")
shun-iwasawa 82a8f5
elseif(XCODE)
shun-iwasawa 82a8f5
  set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}")
shun-iwasawa 82a8f5
  string(REGEX REPLACE " " ";" CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS}")
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
file(GLOB INC_FILES nasm/*.inc)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
foreach(file ${SIMD_SOURCES})
shun-iwasawa 82a8f5
  set(OBJECT_DEPENDS "")
shun-iwasawa 82a8f5
  if(${file} MATCHES jccolor)
shun-iwasawa 82a8f5
    string(REGEX REPLACE "jccolor" "jccolext" DEPFILE ${file})
shun-iwasawa 82a8f5
    set(OBJECT_DEPENDS ${OBJECT_DEPENDS}
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE})
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
  if(${file} MATCHES jcgray)
shun-iwasawa 82a8f5
    string(REGEX REPLACE "jcgray" "jcgryext" DEPFILE ${file})
shun-iwasawa 82a8f5
    set(OBJECT_DEPENDS ${OBJECT_DEPENDS}
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE})
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
  if(${file} MATCHES jdcolor)
shun-iwasawa 82a8f5
    string(REGEX REPLACE "jdcolor" "jdcolext" DEPFILE ${file})
shun-iwasawa 82a8f5
    set(OBJECT_DEPENDS ${OBJECT_DEPENDS}
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE})
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
  if(${file} MATCHES jdmerge)
shun-iwasawa 82a8f5
    string(REGEX REPLACE "jdmerge" "jdmrgext" DEPFILE ${file})
shun-iwasawa 82a8f5
    set(OBJECT_DEPENDS ${OBJECT_DEPENDS}
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE})
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
  set(OBJECT_DEPENDS ${OBJECT_DEPENDS} ${INC_FILES})
shun-iwasawa 82a8f5
  if(MSVC_IDE OR XCODE)
shun-iwasawa 82a8f5
    # The CMake Visual Studio generators do not work properly with the ASM_NASM
shun-iwasawa 82a8f5
    # language, so we have to go rogue here and use a custom command like we
shun-iwasawa 82a8f5
    # did in prior versions of libjpeg-turbo.  (This is why we can't have nice
shun-iwasawa 82a8f5
    # things.)
shun-iwasawa 82a8f5
    string(REGEX REPLACE "${CPU_TYPE}/" "" filename ${file})
shun-iwasawa 82a8f5
    set(SIMD_OBJ ${OBJDIR}/${filename}${CMAKE_C_OUTPUT_EXTENSION})
shun-iwasawa 82a8f5
    add_custom_command(OUTPUT ${SIMD_OBJ} DEPENDS ${file} ${OBJECT_DEPENDS}
shun-iwasawa 82a8f5
      COMMAND ${CMAKE_ASM_NASM_COMPILER} -f${CMAKE_ASM_NASM_OBJECT_FORMAT}
shun-iwasawa 82a8f5
        ${CMAKE_ASM_NASM_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${file}
shun-iwasawa 82a8f5
        -o${SIMD_OBJ})
shun-iwasawa 82a8f5
    set(SIMD_OBJS ${SIMD_OBJS} ${SIMD_OBJ})
shun-iwasawa 82a8f5
  else()
shun-iwasawa 82a8f5
    set_source_files_properties(${file} PROPERTIES OBJECT_DEPENDS
shun-iwasawa 82a8f5
      "${OBJECT_DEPENDS}")
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
endforeach()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(MSVC_IDE OR XCODE)
shun-iwasawa 82a8f5
  set(SIMD_OBJS ${SIMD_OBJS} PARENT_SCOPE)
shun-iwasawa 82a8f5
  add_library(simd OBJECT ${CPU_TYPE}/jsimd.c)
shun-iwasawa 82a8f5
  add_custom_target(simd-objs DEPENDS ${SIMD_OBJS})
shun-iwasawa 82a8f5
  add_dependencies(simd simd-objs)
shun-iwasawa 82a8f5
else()
shun-iwasawa 82a8f5
  add_library(simd OBJECT ${SIMD_SOURCES} ${CPU_TYPE}/jsimd.c)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
if(NOT WIN32 AND (CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED))
shun-iwasawa 82a8f5
  set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
# Arm (GAS)
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
elseif(CPU_TYPE STREQUAL "arm64" OR CPU_TYPE STREQUAL "arm")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
enable_language(ASM)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ASM_FLAGS}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
shun-iwasawa 82a8f5
set(EFFECTIVE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
shun-iwasawa 82a8f5
message(STATUS "CMAKE_ASM_FLAGS = ${EFFECTIVE_ASM_FLAGS}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
# Test whether we need gas-preprocessor.pl
shun-iwasawa 82a8f5
if(CPU_TYPE STREQUAL "arm")
shun-iwasawa 82a8f5
  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gastest.S "
shun-iwasawa 82a8f5
    .text
shun-iwasawa 82a8f5
    .fpu neon
shun-iwasawa 82a8f5
    .arch armv7a
shun-iwasawa 82a8f5
    .object_arch armv4
shun-iwasawa 82a8f5
    .arm
shun-iwasawa 82a8f5
    pld [r0]
shun-iwasawa 82a8f5
    vmovn.u16 d0, q0")
shun-iwasawa 82a8f5
else()
shun-iwasawa 82a8f5
  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gastest.S "
shun-iwasawa 82a8f5
    .text
shun-iwasawa 82a8f5
    MYVAR .req x0
shun-iwasawa 82a8f5
    movi v0.16b, #100
shun-iwasawa 82a8f5
    mov MYVAR, #100
shun-iwasawa 82a8f5
    .unreq MYVAR")
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
separate_arguments(CMAKE_ASM_FLAGS_SEP UNIX_COMMAND "${CMAKE_ASM_FLAGS}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
execute_process(COMMAND ${CMAKE_ASM_COMPILER} ${CMAKE_ASM_FLAGS_SEP}
shun-iwasawa 82a8f5
    -x assembler-with-cpp -c ${CMAKE_CURRENT_BINARY_DIR}/gastest.S
shun-iwasawa 82a8f5
  RESULT_VARIABLE RESULT OUTPUT_VARIABLE OUTPUT ERROR_VARIABLE ERROR)
shun-iwasawa 82a8f5
if(NOT RESULT EQUAL 0)
shun-iwasawa 82a8f5
  message(STATUS "GAS appears to be broken.  Trying gas-preprocessor.pl ...")
shun-iwasawa 82a8f5
  execute_process(COMMAND gas-preprocessor.pl ${CMAKE_ASM_COMPILER}
shun-iwasawa 82a8f5
      ${CMAKE_ASM_FLAGS_SEP} -x assembler-with-cpp -c
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_BINARY_DIR}/gastest.S
shun-iwasawa 82a8f5
    RESULT_VARIABLE RESULT OUTPUT_VARIABLE OUTPUT ERROR_VARIABLE ERROR)
shun-iwasawa 82a8f5
  if(NOT RESULT EQUAL 0)
shun-iwasawa 82a8f5
    simd_fail("SIMD extensions disabled: GAS is not working properly")
shun-iwasawa 82a8f5
    return()
shun-iwasawa 82a8f5
  else()
shun-iwasawa 82a8f5
    message(STATUS "Using gas-preprocessor.pl")
shun-iwasawa 82a8f5
    configure_file(gas-preprocessor.in gas-preprocessor @ONLY)
shun-iwasawa 82a8f5
    set(CMAKE_ASM_COMPILER ${CMAKE_CURRENT_BINARY_DIR}/gas-preprocessor)
shun-iwasawa 82a8f5
  endif()
shun-iwasawa 82a8f5
else()
shun-iwasawa 82a8f5
  message(STATUS "GAS is working properly")
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/gastest.S)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
add_library(simd OBJECT ${CPU_TYPE}/jsimd_neon.S ${CPU_TYPE}/jsimd.c)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)
shun-iwasawa 82a8f5
  set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
# MIPS (GAS)
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
elseif(CPU_TYPE STREQUAL "mips" OR CPU_TYPE STREQUAL "mipsel")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
enable_language(ASM)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
shun-iwasawa 82a8f5
set(EFFECTIVE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
shun-iwasawa 82a8f5
message(STATUS "CMAKE_ASM_FLAGS = ${EFFECTIVE_ASM_FLAGS}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(CMAKE_REQUIRED_FLAGS -mdspr2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
check_c_source_compiles("
shun-iwasawa 82a8f5
  #if !(defined(__mips__) && __mips_isa_rev >= 2)
shun-iwasawa 82a8f5
  #error MIPS DSPr2 is currently only available on MIPS32r2 platforms.
shun-iwasawa 82a8f5
  #endif
shun-iwasawa 82a8f5
  int main(void) {
shun-iwasawa 82a8f5
    int c = 0, a = 0, b = 0;
shun-iwasawa 82a8f5
    __asm__ __volatile__ (
shun-iwasawa 82a8f5
      \"precr.qb.ph %[c], %[a], %[b]\"
shun-iwasawa 82a8f5
      : [c] \"=r\" (c)
shun-iwasawa 82a8f5
      : [a] \"r\" (a), [b] \"r\" (b)
shun-iwasawa 82a8f5
    );
shun-iwasawa 82a8f5
    return c;
shun-iwasawa 82a8f5
  }" HAVE_DSPR2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
unset(CMAKE_REQUIRED_FLAGS)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(NOT HAVE_DSPR2)
shun-iwasawa 82a8f5
  simd_fail("SIMD extensions not available for this CPU")
shun-iwasawa 82a8f5
  return()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
add_library(simd OBJECT mips/jsimd_dspr2.S mips/jsimd.c)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)
shun-iwasawa 82a8f5
  set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
# Loongson (Intrinsics)
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
elseif(CPU_TYPE STREQUAL "loongson")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(SIMD_SOURCES loongson/jccolor-mmi.c loongson/jcsample-mmi.c
shun-iwasawa 82a8f5
  loongson/jdcolor-mmi.c loongson/jdsample-mmi.c loongson/jfdctint-mmi.c
shun-iwasawa 82a8f5
  loongson/jidctint-mmi.c loongson/jquanti-mmi.c)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CMAKE_COMPILER_IS_GNUCC)
shun-iwasawa 82a8f5
  foreach(file ${SIMD_SOURCES})
shun-iwasawa 82a8f5
    set_property(SOURCE ${file} APPEND_STRING PROPERTY COMPILE_FLAGS
shun-iwasawa 82a8f5
      " -fno-strict-aliasing")
shun-iwasawa 82a8f5
  endforeach()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
add_library(simd OBJECT ${SIMD_SOURCES} loongson/jsimd.c)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)
shun-iwasawa 82a8f5
  set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
# PowerPC (Intrinsics)
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
elseif(CPU_TYPE STREQUAL "powerpc")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(CMAKE_REQUIRED_FLAGS -maltivec)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
check_c_source_compiles("
shun-iwasawa 82a8f5
  #include <altivec.h></altivec.h>
shun-iwasawa 82a8f5
  int main(void) {
shun-iwasawa 82a8f5
    __vector int vi = { 0, 0, 0, 0 };
shun-iwasawa 82a8f5
    int i[4];
shun-iwasawa 82a8f5
    vec_st(vi, 0, i);
shun-iwasawa 82a8f5
    return i[0];
shun-iwasawa 82a8f5
  }" HAVE_ALTIVEC)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
unset(CMAKE_REQUIRED_FLAGS)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(NOT HAVE_ALTIVEC)
shun-iwasawa 82a8f5
  simd_fail("SIMD extensions not available for this CPU (PowerPC SPE)")
shun-iwasawa 82a8f5
  return()
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(SIMD_SOURCES powerpc/jccolor-altivec.c powerpc/jcgray-altivec.c
shun-iwasawa 82a8f5
  powerpc/jcsample-altivec.c powerpc/jdcolor-altivec.c
shun-iwasawa 82a8f5
  powerpc/jdmerge-altivec.c powerpc/jdsample-altivec.c
shun-iwasawa 82a8f5
  powerpc/jfdctfst-altivec.c powerpc/jfdctint-altivec.c
shun-iwasawa 82a8f5
  powerpc/jidctfst-altivec.c powerpc/jidctint-altivec.c
shun-iwasawa 82a8f5
  powerpc/jquanti-altivec.c)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set_source_files_properties(${SIMD_SOURCES} PROPERTIES
shun-iwasawa 82a8f5
  COMPILE_FLAGS -maltivec)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
add_library(simd OBJECT ${SIMD_SOURCES} powerpc/jsimd.c)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)
shun-iwasawa 82a8f5
  set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
# None
shun-iwasawa 82a8f5
###############################################################################
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
else()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
simd_fail("SIMD extensions not available for this CPU (${CMAKE_SYSTEM_PROCESSOR})")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
endif() # CPU_TYPE