[PATCH] cpu.h: add defines for clang

lvqcl <[email protected]>
Newsgroups gmane.comp.audio.compression.flac.devel
Message-ID <op.yunadpoqcba0by@userme-pc>
Currently cpu.h lacks FLAC__SSE_TARGET and FLAC__SSEnn_SUPPORTED
macros for clang. I added them, but I cannot properly test them
as I can't get compiled flac.exe under Windows (don't know
how to setup clang under MSYS2).

If somebody has working clang, please test this patch.
Does it affect en/decoding speed?
Or at least, dows it affect disassembly of functions
such as FLAC__precompute_partition_info_sums_intrin_avx2()?

_______________________________________________
flac-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/flac-dev
clang_cpu_support.patch (application/octet-stream, 1.8 KB)
diff --git a/src/libFLAC/include/private/cpu.h b/src/libFLAC/include/private/cpu.h
index 7c65180..623efc5 100644
--- a/src/libFLAC/include/private/cpu.h
+++ b/src/libFLAC/include/private/cpu.h
@@ -88,8 +88,25 @@
     #define FLAC__AVX2_SUPPORTED 1
     #define FLAC__FMA_SUPPORTED 1
   #endif
-#elif defined __GNUC__
-  #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) /* since GCC 4.9 -msse.. compiler options aren't necessary */
+#elif defined __GNUC__ || defined __clang__
+  #if defined __clang__ && __has_attribute(__target__) /* clang */
+    #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x)))
+    #if __has_builtin(__builtin_ia32_maxps)
+      #define FLAC__SSE_SUPPORTED 1
+    #endif
+    #if __has_builtin(__builtin_ia32_pmuludq128)
+      #define FLAC__SSE2_SUPPORTED 1
+    #endif
+    #if __has_builtin(__builtin_ia32_pabsd128)
+      #define FLAC__SSSE3_SUPPORTED 1
+    #endif
+    #if __has_builtin(__builtin_ia32_pmuldq128)
+      #define FLAC__SSE4_1_SUPPORTED 1
+    #endif
+    #if __has_builtin(__builtin_ia32_pabsd256)
+      #define FLAC__AVX2_SUPPORTED 1
+    #endif
+  #elif !defined __clang__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) /* GCC 4.9+ */
     #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x)))
     #define FLAC__SSE_SUPPORTED 1
     #define FLAC__SSE2_SUPPORTED 1
@@ -100,7 +117,7 @@
     #define FLAC__AVX2_SUPPORTED 1
     #define FLAC__FMA_SUPPORTED 1
 #endif
-  #else /* for GCC older than 4.9 */
+  #else /* older GCC and clang */
     #define FLAC__SSE_TARGET(x)
     #ifdef __SSE__
       #define FLAC__SSE_SUPPORTED 1
@@ -123,7 +140,7 @@
     #ifdef __FMA__
       #define FLAC__FMA_SUPPORTED 1
     #endif
-  #endif /* GCC version */
+  #endif
 #endif /* compiler version */
 #endif /* intrinsics support */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.