]> granicus.if.org Git - libjpeg-turbo/commitdiff
Build: Detect whether compiler supports DSPr2
authorDRC <information@libjpeg-turbo.org>
Fri, 29 Jun 2018 17:45:57 +0000 (12:45 -0500)
committerDRC <information@libjpeg-turbo.org>
Fri, 29 Jun 2018 18:23:58 +0000 (13:23 -0500)
This is basically the same test that was performed in acinclude.m4 in
the old autotools-based build system.  It was not ported to the
CMake-based build system because I previously had no way of testing
a non-DSPr2 build environment.

Fixes #248

ChangeLog.md
simd/CMakeLists.txt

index e18a2826b7b6f231c9b5d05c11effc23508b48c6..03f28dabf95ee2583770a569f86cfa474e87926f 100644 (file)
@@ -44,6 +44,9 @@ subsampling (for instance, 4:2:0 or 4:4:0.)
 a 4:2:2 or 4:2:0 JPEG image using the merged (non-fancy) upsampling algorithms
 (that is, when setting `cinfo.do_fancy_upsampling` to `FALSE`.)
 
+7. The new CMake-based build system will now disable the MIPS DSPr2 SIMD
+extensions if it detects that the compiler does not support DSPr2 instructions.
+
 
 1.5.90 (2.0 beta1)
 ==================
index 2468b1b8901eb9340c7dea20f4124c8065bc235c..346994cbfde0a2bb9000c74265e67a6ec51c02ab 100755 (executable)
@@ -270,6 +270,29 @@ string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
 set(EFFECTIVE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
 message(STATUS "CMAKE_ASM_FLAGS = ${EFFECTIVE_ASM_FLAGS}")
 
+set(CMAKE_REQUIRED_FLAGS -mdspr2)
+
+check_c_source_compiles("
+  #if !(defined(__mips__) && __mips_isa_rev >= 2)
+  #error MIPS DSPr2 is currently only available on MIPS32r2 platforms.
+  #endif
+  int main(void) {
+    int c = 0, a = 0, b = 0;
+    __asm__ __volatile__ (
+      \"precr.qb.ph %[c], %[a], %[b]\"
+      : [c] \"=r\" (c)
+      : [a] \"r\" (a), [b] \"r\" (b)
+    );
+    return c;
+  }" HAVE_DSPR2)
+
+unset(CMAKE_REQUIRED_FLAGS)
+
+if(NOT HAVE_DSPR2)
+  simd_fail("SIMD extensions not available for this CPU")
+  return()
+endif()
+
 add_library(simd OBJECT ${CPU_TYPE}/jsimd_dspr2.S ${CPU_TYPE}/jsimd.c)
 
 if(CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)