From: Andrei Tatar Date: Mon, 17 Jul 2023 15:19:57 +0000 (+0200) Subject: Add compatibility with clang >= 16 X-Git-Tag: RELEASE-0.14.0~10 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=0e54e4dd238d75ed3e9f1c607ddccb9ffc0012af;p=unikraft%2Flibs%2Fintel-intrinsics.git Add compatibility with clang >= 16 Implementations based off headers in LLVM 16.0.0. Signed-off-by: Andrei Tatar Reviewed-by: Maria Sfiraiala Reviewed-by: Radu Nichita Approved-by: Razvan Deaconescu Tested-by: Unikraft CI GitHub-Closes: #3 --- diff --git a/include/avx512bf16intrin.h b/include/avx512bf16intrin.h index 0965373..eef0fc3 100644 --- a/include/avx512bf16intrin.h +++ b/include/avx512bf16intrin.h @@ -13,9 +13,15 @@ #ifndef __AVX512BF16INTRIN_H #define __AVX512BF16INTRIN_H +#if (__clang_major__ > 15) +typedef __bf16 __v32bf __attribute__((__vector_size__(64), __aligned__(64))); +typedef __bf16 __m512bh __attribute__((__vector_size__(64), __aligned__(64))); +typedef __bf16 __bfloat16; +#else typedef short __m512bh __attribute__((__vector_size__(64), __aligned__(64))); typedef short __m256bh __attribute__((__vector_size__(32), __aligned__(32))); typedef unsigned short __bfloat16; +#endif #define __DEFAULT_FN_ATTRS512 \ __attribute__((__always_inline__, __nodebug__, __target__("avx512bf16"), \ diff --git a/include/avx512vlbf16intrin.h b/include/avx512vlbf16intrin.h index 6a5a860..adc43c1 100644 --- a/include/avx512vlbf16intrin.h +++ b/include/avx512vlbf16intrin.h @@ -13,7 +13,9 @@ #ifndef __AVX512VLBF16INTRIN_H #define __AVX512VLBF16INTRIN_H +#if (__clang_major__ <= 15) typedef short __m128bh __attribute__((__vector_size__(16), __aligned__(16))); +#endif #define __DEFAULT_FN_ATTRS128 \ __attribute__((__always_inline__, __nodebug__, \ @@ -415,9 +417,15 @@ _mm256_maskz_dpbf16_ps(__mmask8 __U, __m256 __D, __m256bh __A, __m256bh __B) { /// and fraction field is truncated to 7 bits. static __inline__ __bfloat16 __DEFAULT_FN_ATTRS128 _mm_cvtness_sbh(float __A) { __v4sf __V = {__A, 0, 0, 0}; +#if (__clang_major__ > 15) + __v8bf __R = __builtin_ia32_cvtneps2bf16_128_mask( + (__v4sf)__V, (__v8bf)_mm_undefined_si128(), (__mmask8)-1); + return (__bf16)__R[0]; +#else __v8hi __R = __builtin_ia32_cvtneps2bf16_128_mask( (__v4sf)__V, (__v8hi)_mm_undefined_si128(), (__mmask8)-1); return __R[0]; +#endif } /// Convert Packed BF16 Data to Packed float Data. diff --git a/include/avxintrin.h b/include/avxintrin.h index 17fe636..2f2a159 100644 --- a/include/avxintrin.h +++ b/include/avxintrin.h @@ -39,6 +39,18 @@ typedef float __m256_u __attribute__ ((__vector_size__ (32), __aligned__(1))); typedef double __m256d_u __attribute__((__vector_size__(32), __aligned__(1))); typedef long long __m256i_u __attribute__((__vector_size__(32), __aligned__(1))); +#if (__clang_major__ > 15) +#ifdef __SSE2__ +/* Both _Float16 and __bf16 require SSE2 being enabled. */ +typedef _Float16 __v16hf __attribute__((__vector_size__(32), __aligned__(32))); +typedef _Float16 __m256h __attribute__((__vector_size__(32), __aligned__(32))); +typedef _Float16 __m256h_u __attribute__((__vector_size__(32), __aligned__(1))); + +typedef __bf16 __v16bf __attribute__((__vector_size__(32), __aligned__(32))); +typedef __bf16 __m256bh __attribute__((__vector_size__(32), __aligned__(32))); +#endif +#endif + /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("avx"), __min_vector_width__(256))) #define __DEFAULT_FN_ATTRS128 __attribute__((__always_inline__, __nodebug__, __target__("avx"), __min_vector_width__(128))) diff --git a/include/emmintrin.h b/include/emmintrin.h index c2a8d4a..c25ce30 100644 --- a/include/emmintrin.h +++ b/include/emmintrin.h @@ -37,6 +37,18 @@ typedef unsigned char __v16qu __attribute__((__vector_size__(16))); * appear in the interface though. */ typedef signed char __v16qs __attribute__((__vector_size__(16))); +#if (__clang_major__ > 15) +#ifdef __SSE2__ +/* Both _Float16 and __bf16 require SSE2 being enabled. */ +typedef _Float16 __v8hf __attribute__((__vector_size__(16), __aligned__(16))); +typedef _Float16 __m128h __attribute__((__vector_size__(16), __aligned__(16))); +typedef _Float16 __m128h_u __attribute__((__vector_size__(16), __aligned__(1))); + +typedef __bf16 __v8bf __attribute__((__vector_size__(16), __aligned__(16))); +typedef __bf16 __m128bh __attribute__((__vector_size__(16), __aligned__(16))); +#endif +#endif + /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse2"), __min_vector_width__(128))) #define __DEFAULT_FN_ATTRS_MMX __attribute__((__always_inline__, __nodebug__, __target__("mmx,sse2"), __min_vector_width__(64)))