Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/cuda_builtin_vars.h
/*===---- cuda_builtin_vars.h - CUDA built-in variables ---------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __CUDA_BUILTIN_VARS_H #define __CUDA_BUILTIN_VARS_H // The file implements built-in CUDA variables using __declspec(property). // https://msdn.microsoft.com/en-us/library/yhfk0thd.aspx // All read accesses of built-in variable fields get converted into calls to a // getter function which in turn would call appropriate builtin to fetch the // value. // // Example: // int x = threadIdx.x; // IR output: // %0 = call i32 @llvm.ptx.read.tid.x() #3 // PTX output: // mov.u32 %r2, %tid.x; #define __CUDA_DEVICE_BUILTIN(FIELD, INTRINSIC) \ __declspec(property(get = __fetch_builtin_##FIELD)) unsigned int FIELD; \ static inline __attribute__((always_inline)) \ __attribute__((device)) unsigned int __fetch_builtin_##FIELD(void) { \ return INTRINSIC; \ } #if __cplusplus >= 201103L #define __DELETE =delete #else #define __DELETE #endif // Make sure nobody can create instances of the special varible types. nvcc // also disallows taking address of special variables, so we disable address-of // operator as well. #define __CUDA_DISALLOW_BUILTINVAR_ACCESS(TypeName) \ __attribute__((device)) TypeName() __DELETE; \ __attribute__((device)) TypeName(const TypeName &) __DELETE; \ __attribute__((device)) void operator=(const TypeName &) const __DELETE; \ __attribute__((device)) TypeName *operator&() const __DELETE struct __cuda_builtin_threadIdx_t { __CUDA_DEVICE_BUILTIN(x,__builtin_ptx_read_tid_x()); __CUDA_DEVICE_BUILTIN(y,__builtin_ptx_read_tid_y()); __CUDA_DEVICE_BUILTIN(z,__builtin_ptx_read_tid_z()); private: __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_threadIdx_t); }; struct __cuda_builtin_blockIdx_t { __CUDA_DEVICE_BUILTIN(x,__builtin_ptx_read_ctaid_x()); __CUDA_DEVICE_BUILTIN(y,__builtin_ptx_read_ctaid_y()); __CUDA_DEVICE_BUILTIN(z,__builtin_ptx_read_ctaid_z()); private: __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_blockIdx_t); }; struct __cuda_builtin_blockDim_t { __CUDA_DEVICE_BUILTIN(x,__builtin_ptx_read_ntid_x()); __CUDA_DEVICE_BUILTIN(y,__builtin_ptx_read_ntid_y()); __CUDA_DEVICE_BUILTIN(z,__builtin_ptx_read_ntid_z()); private: __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_blockDim_t); }; struct __cuda_builtin_gridDim_t { __CUDA_DEVICE_BUILTIN(x,__builtin_ptx_read_nctaid_x()); __CUDA_DEVICE_BUILTIN(y,__builtin_ptx_read_nctaid_y()); __CUDA_DEVICE_BUILTIN(z,__builtin_ptx_read_nctaid_z()); private: __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_gridDim_t); }; #define __CUDA_BUILTIN_VAR \ extern const __attribute__((device)) __attribute__((weak)) __CUDA_BUILTIN_VAR __cuda_builtin_threadIdx_t threadIdx; __CUDA_BUILTIN_VAR __cuda_builtin_blockIdx_t blockIdx; __CUDA_BUILTIN_VAR __cuda_builtin_blockDim_t blockDim; __CUDA_BUILTIN_VAR __cuda_builtin_gridDim_t gridDim; // warpSize should translate to read of %WARP_SZ but there's currently no // builtin to do so. According to PTX v4.2 docs 'to date, all target // architectures have a WARP_SZ value of 32'. __attribute__((device)) const int warpSize = 32; #undef __CUDA_DEVICE_BUILTIN #undef __CUDA_BUILTIN_VAR #undef __CUDA_DISALLOW_BUILTINVAR_ACCESS #endif /* __CUDA_BUILTIN_VARS_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/fmaintrin.h
/*===---- fma4intrin.h - FMA4 intrinsics -----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <fmaintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __FMAINTRIN_H #define __FMAINTRIN_H #ifndef __FMA__ # error "FMA instruction set is not enabled" #else /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fmadd_ps(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfmaddps(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fmadd_pd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfmaddpd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fmadd_ss(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfmaddss(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fmadd_sd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfmaddsd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fmsub_ps(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfmsubps(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fmsub_pd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfmsubpd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fmsub_ss(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfmsubss(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fmsub_sd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfmsubsd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fnmadd_ps(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfnmaddps(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fnmadd_pd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfnmaddpd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fnmadd_ss(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfnmaddss(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fnmadd_sd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfnmaddsd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fnmsub_ps(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfnmsubps(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fnmsub_pd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfnmsubpd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fnmsub_ss(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfnmsubss(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fnmsub_sd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfnmsubsd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fmaddsub_ps(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfmaddsubps(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fmaddsub_pd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfmaddsubpd(__A, __B, __C); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_fmsubadd_ps(__m128 __A, __m128 __B, __m128 __C) { return (__m128)__builtin_ia32_vfmsubaddps(__A, __B, __C); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_fmsubadd_pd(__m128d __A, __m128d __B, __m128d __C) { return (__m128d)__builtin_ia32_vfmsubaddpd(__A, __B, __C); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_fmadd_ps(__m256 __A, __m256 __B, __m256 __C) { return (__m256)__builtin_ia32_vfmaddps256(__A, __B, __C); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_fmadd_pd(__m256d __A, __m256d __B, __m256d __C) { return (__m256d)__builtin_ia32_vfmaddpd256(__A, __B, __C); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_fmsub_ps(__m256 __A, __m256 __B, __m256 __C) { return (__m256)__builtin_ia32_vfmsubps256(__A, __B, __C); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_fmsub_pd(__m256d __A, __m256d __B, __m256d __C) { return (__m256d)__builtin_ia32_vfmsubpd256(__A, __B, __C); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_fnmadd_ps(__m256 __A, __m256 __B, __m256 __C) { return (__m256)__builtin_ia32_vfnmaddps256(__A, __B, __C); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_fnmadd_pd(__m256d __A, __m256d __B, __m256d __C) { return (__m256d)__builtin_ia32_vfnmaddpd256(__A, __B, __C); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_fnmsub_ps(__m256 __A, __m256 __B, __m256 __C) { return (__m256)__builtin_ia32_vfnmsubps256(__A, __B, __C); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_fnmsub_pd(__m256d __A, __m256d __B, __m256d __C) { return (__m256d)__builtin_ia32_vfnmsubpd256(__A, __B, __C); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_fmaddsub_ps(__m256 __A, __m256 __B, __m256 __C) { return (__m256)__builtin_ia32_vfmaddsubps256(__A, __B, __C); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_fmaddsub_pd(__m256d __A, __m256d __B, __m256d __C) { return (__m256d)__builtin_ia32_vfmaddsubpd256(__A, __B, __C); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_fmsubadd_ps(__m256 __A, __m256 __B, __m256 __C) { return (__m256)__builtin_ia32_vfmsubaddps256(__A, __B, __C); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_fmsubadd_pd(__m256d __A, __m256d __B, __m256d __C) { return (__m256d)__builtin_ia32_vfmsubaddpd256(__A, __B, __C); } #undef __DEFAULT_FN_ATTRS #endif /* __FMA__ */ #endif /* __FMAINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/__stddef_max_align_t.h
/*===---- __stddef_max_align_t.h - Definition of max_align_t for modules ---=== * * Copyright (c) 2014 Chandler Carruth * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __CLANG_MAX_ALIGN_T_DEFINED #define __CLANG_MAX_ALIGN_T_DEFINED #if defined(_MSC_VER) typedef double max_align_t; #elif defined(__APPLE__) typedef long double max_align_t; #else // Define 'max_align_t' to match the GCC definition. typedef struct { long long __clang_max_align_nonce1 __attribute__((__aligned__(__alignof__(long long)))); long double __clang_max_align_nonce2 __attribute__((__aligned__(__alignof__(long double)))); } max_align_t; #endif #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/rdseedintrin.h
/*===---- rdseedintrin.h - RDSEED intrinsics -------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __X86INTRIN_H #error "Never use <rdseedintrin.h> directly; include <x86intrin.h> instead." #endif #ifndef __RDSEEDINTRIN_H #define __RDSEEDINTRIN_H #ifdef __RDSEED__ /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ int __DEFAULT_FN_ATTRS _rdseed16_step(unsigned short *__p) { return __builtin_ia32_rdseed16_step(__p); } static __inline__ int __DEFAULT_FN_ATTRS _rdseed32_step(unsigned int *__p) { return __builtin_ia32_rdseed32_step(__p); } #ifdef __x86_64__ static __inline__ int __DEFAULT_FN_ATTRS _rdseed64_step(unsigned long long *__p) { return __builtin_ia32_rdseed64_step(__p); } #endif #undef __DEFAULT_FN_ATTRS #endif /* __RDSEED__ */ #endif /* __RDSEEDINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/stdnoreturn.h
/*===---- stdnoreturn.h - Standard header for noreturn macro ---------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __STDNORETURN_H #define __STDNORETURN_H #define noreturn _Noreturn #define __noreturn_is_defined 1 #endif /* __STDNORETURN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/altivec.h
/*===---- altivec.h - Standard header for type generic math ---------------===*\ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * \*===----------------------------------------------------------------------===*/ #ifndef __ALTIVEC_H #define __ALTIVEC_H #ifndef __ALTIVEC__ #error "AltiVec support not enabled" #endif /* constants for mapping CR6 bits to predicate result. */ #define __CR6_EQ 0 #define __CR6_EQ_REV 1 #define __CR6_LT 2 #define __CR6_LT_REV 3 #define __ATTRS_o_ai __attribute__((__overloadable__, __always_inline__)) static vector signed char __ATTRS_o_ai vec_perm(vector signed char __a, vector signed char __b, vector unsigned char __c); static vector unsigned char __ATTRS_o_ai vec_perm(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c); static vector bool char __ATTRS_o_ai vec_perm(vector bool char __a, vector bool char __b, vector unsigned char __c); static vector short __ATTRS_o_ai vec_perm(vector signed short __a, vector signed short __b, vector unsigned char __c); static vector unsigned short __ATTRS_o_ai vec_perm(vector unsigned short __a, vector unsigned short __b, vector unsigned char __c); static vector bool short __ATTRS_o_ai vec_perm(vector bool short __a, vector bool short __b, vector unsigned char __c); static vector pixel __ATTRS_o_ai vec_perm(vector pixel __a, vector pixel __b, vector unsigned char __c); static vector int __ATTRS_o_ai vec_perm(vector signed int __a, vector signed int __b, vector unsigned char __c); static vector unsigned int __ATTRS_o_ai vec_perm(vector unsigned int __a, vector unsigned int __b, vector unsigned char __c); static vector bool int __ATTRS_o_ai vec_perm(vector bool int __a, vector bool int __b, vector unsigned char __c); static vector float __ATTRS_o_ai vec_perm(vector float __a, vector float __b, vector unsigned char __c); #ifdef __VSX__ static vector long long __ATTRS_o_ai vec_perm(vector signed long long __a, vector signed long long __b, vector unsigned char __c); static vector unsigned long long __ATTRS_o_ai vec_perm(vector unsigned long long __a, vector unsigned long long __b, vector unsigned char __c); static vector bool long long __ATTRS_o_ai vec_perm(vector bool long long __a, vector bool long long __b, vector unsigned char __c); static vector double __ATTRS_o_ai vec_perm(vector double __a, vector double __b, vector unsigned char __c); #endif static vector unsigned char __ATTRS_o_ai vec_xor(vector unsigned char __a, vector unsigned char __b); /* vec_abs */ #define __builtin_altivec_abs_v16qi vec_abs #define __builtin_altivec_abs_v8hi vec_abs #define __builtin_altivec_abs_v4si vec_abs static vector signed char __ATTRS_o_ai vec_abs(vector signed char __a) { return __builtin_altivec_vmaxsb(__a, -__a); } static vector signed short __ATTRS_o_ai vec_abs(vector signed short __a) { return __builtin_altivec_vmaxsh(__a, -__a); } static vector signed int __ATTRS_o_ai vec_abs(vector signed int __a) { return __builtin_altivec_vmaxsw(__a, -__a); } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector signed long long __ATTRS_o_ai vec_abs(vector signed long long __a) { return __builtin_altivec_vmaxsd(__a, -__a); } #endif static vector float __ATTRS_o_ai vec_abs(vector float __a) { vector unsigned int __res = (vector unsigned int)__a & (vector unsigned int)(0x7FFFFFFF); return (vector float)__res; } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector double __ATTRS_o_ai vec_abs(vector double __a) { vector unsigned long long __res = { 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF }; __res &= (vector unsigned int)__a; return (vector double)__res; } #endif /* vec_abss */ #define __builtin_altivec_abss_v16qi vec_abss #define __builtin_altivec_abss_v8hi vec_abss #define __builtin_altivec_abss_v4si vec_abss static vector signed char __ATTRS_o_ai vec_abss(vector signed char __a) { return __builtin_altivec_vmaxsb( __a, __builtin_altivec_vsubsbs((vector signed char)(0), __a)); } static vector signed short __ATTRS_o_ai vec_abss(vector signed short __a) { return __builtin_altivec_vmaxsh( __a, __builtin_altivec_vsubshs((vector signed short)(0), __a)); } static vector signed int __ATTRS_o_ai vec_abss(vector signed int __a) { return __builtin_altivec_vmaxsw( __a, __builtin_altivec_vsubsws((vector signed int)(0), __a)); } /* vec_add */ static vector signed char __ATTRS_o_ai vec_add(vector signed char __a, vector signed char __b) { return __a + __b; } static vector signed char __ATTRS_o_ai vec_add(vector bool char __a, vector signed char __b) { return (vector signed char)__a + __b; } static vector signed char __ATTRS_o_ai vec_add(vector signed char __a, vector bool char __b) { return __a + (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_add(vector unsigned char __a, vector unsigned char __b) { return __a + __b; } static vector unsigned char __ATTRS_o_ai vec_add(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a + __b; } static vector unsigned char __ATTRS_o_ai vec_add(vector unsigned char __a, vector bool char __b) { return __a + (vector unsigned char)__b; } static vector short __ATTRS_o_ai vec_add(vector short __a, vector short __b) { return __a + __b; } static vector short __ATTRS_o_ai vec_add(vector bool short __a, vector short __b) { return (vector short)__a + __b; } static vector short __ATTRS_o_ai vec_add(vector short __a, vector bool short __b) { return __a + (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_add(vector unsigned short __a, vector unsigned short __b) { return __a + __b; } static vector unsigned short __ATTRS_o_ai vec_add(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a + __b; } static vector unsigned short __ATTRS_o_ai vec_add(vector unsigned short __a, vector bool short __b) { return __a + (vector unsigned short)__b; } static vector int __ATTRS_o_ai vec_add(vector int __a, vector int __b) { return __a + __b; } static vector int __ATTRS_o_ai vec_add(vector bool int __a, vector int __b) { return (vector int)__a + __b; } static vector int __ATTRS_o_ai vec_add(vector int __a, vector bool int __b) { return __a + (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_add(vector unsigned int __a, vector unsigned int __b) { return __a + __b; } static vector unsigned int __ATTRS_o_ai vec_add(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a + __b; } static vector unsigned int __ATTRS_o_ai vec_add(vector unsigned int __a, vector bool int __b) { return __a + (vector unsigned int)__b; } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector signed long long __ATTRS_o_ai vec_add(vector signed long long __a, vector signed long long __b) { return __a + __b; } static vector unsigned long long __ATTRS_o_ai vec_add(vector unsigned long long __a, vector unsigned long long __b) { return __a + __b; } static vector signed __int128 __ATTRS_o_ai vec_add(vector signed __int128 __a, vector signed __int128 __b) { return __a + __b; } static vector unsigned __int128 __ATTRS_o_ai vec_add(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __a + __b; } #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector float __ATTRS_o_ai vec_add(vector float __a, vector float __b) { return __a + __b; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_add(vector double __a, vector double __b) { return __a + __b; } #endif // __VSX__ /* vec_vaddubm */ #define __builtin_altivec_vaddubm vec_vaddubm static vector signed char __ATTRS_o_ai vec_vaddubm(vector signed char __a, vector signed char __b) { return __a + __b; } static vector signed char __ATTRS_o_ai vec_vaddubm(vector bool char __a, vector signed char __b) { return (vector signed char)__a + __b; } static vector signed char __ATTRS_o_ai vec_vaddubm(vector signed char __a, vector bool char __b) { return __a + (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_vaddubm(vector unsigned char __a, vector unsigned char __b) { return __a + __b; } static vector unsigned char __ATTRS_o_ai vec_vaddubm(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a + __b; } static vector unsigned char __ATTRS_o_ai vec_vaddubm(vector unsigned char __a, vector bool char __b) { return __a + (vector unsigned char)__b; } /* vec_vadduhm */ #define __builtin_altivec_vadduhm vec_vadduhm static vector short __ATTRS_o_ai vec_vadduhm(vector short __a, vector short __b) { return __a + __b; } static vector short __ATTRS_o_ai vec_vadduhm(vector bool short __a, vector short __b) { return (vector short)__a + __b; } static vector short __ATTRS_o_ai vec_vadduhm(vector short __a, vector bool short __b) { return __a + (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_vadduhm(vector unsigned short __a, vector unsigned short __b) { return __a + __b; } static vector unsigned short __ATTRS_o_ai vec_vadduhm(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a + __b; } static vector unsigned short __ATTRS_o_ai vec_vadduhm(vector unsigned short __a, vector bool short __b) { return __a + (vector unsigned short)__b; } /* vec_vadduwm */ #define __builtin_altivec_vadduwm vec_vadduwm static vector int __ATTRS_o_ai vec_vadduwm(vector int __a, vector int __b) { return __a + __b; } static vector int __ATTRS_o_ai vec_vadduwm(vector bool int __a, vector int __b) { return (vector int)__a + __b; } static vector int __ATTRS_o_ai vec_vadduwm(vector int __a, vector bool int __b) { return __a + (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_vadduwm(vector unsigned int __a, vector unsigned int __b) { return __a + __b; } static vector unsigned int __ATTRS_o_ai vec_vadduwm(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a + __b; } static vector unsigned int __ATTRS_o_ai vec_vadduwm(vector unsigned int __a, vector bool int __b) { return __a + (vector unsigned int)__b; } /* vec_vaddfp */ #define __builtin_altivec_vaddfp vec_vaddfp static vector float __attribute__((__always_inline__)) vec_vaddfp(vector float __a, vector float __b) { return __a + __b; } /* vec_addc */ static vector unsigned int __ATTRS_o_ai vec_addc(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vaddcuw(__a, __b); } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector signed __int128 __ATTRS_o_ai vec_addc(vector signed __int128 __a, vector signed __int128 __b) { return __builtin_altivec_vaddcuq(__a, __b); } static vector unsigned __int128 __ATTRS_o_ai vec_addc(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __builtin_altivec_vaddcuq(__a, __b); } #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) /* vec_vaddcuw */ static vector unsigned int __attribute__((__always_inline__)) vec_vaddcuw(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vaddcuw(__a, __b); } /* vec_adds */ static vector signed char __ATTRS_o_ai vec_adds(vector signed char __a, vector signed char __b) { return __builtin_altivec_vaddsbs(__a, __b); } static vector signed char __ATTRS_o_ai vec_adds(vector bool char __a, vector signed char __b) { return __builtin_altivec_vaddsbs((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_adds(vector signed char __a, vector bool char __b) { return __builtin_altivec_vaddsbs(__a, (vector signed char)__b); } static vector unsigned char __ATTRS_o_ai vec_adds(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vaddubs(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_adds(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vaddubs((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_adds(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vaddubs(__a, (vector unsigned char)__b); } static vector short __ATTRS_o_ai vec_adds(vector short __a, vector short __b) { return __builtin_altivec_vaddshs(__a, __b); } static vector short __ATTRS_o_ai vec_adds(vector bool short __a, vector short __b) { return __builtin_altivec_vaddshs((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_adds(vector short __a, vector bool short __b) { return __builtin_altivec_vaddshs(__a, (vector short)__b); } static vector unsigned short __ATTRS_o_ai vec_adds(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vadduhs(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_adds(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vadduhs((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_adds(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vadduhs(__a, (vector unsigned short)__b); } static vector int __ATTRS_o_ai vec_adds(vector int __a, vector int __b) { return __builtin_altivec_vaddsws(__a, __b); } static vector int __ATTRS_o_ai vec_adds(vector bool int __a, vector int __b) { return __builtin_altivec_vaddsws((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_adds(vector int __a, vector bool int __b) { return __builtin_altivec_vaddsws(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_adds(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vadduws(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_adds(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vadduws((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_adds(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vadduws(__a, (vector unsigned int)__b); } /* vec_vaddsbs */ static vector signed char __ATTRS_o_ai vec_vaddsbs(vector signed char __a, vector signed char __b) { return __builtin_altivec_vaddsbs(__a, __b); } static vector signed char __ATTRS_o_ai vec_vaddsbs(vector bool char __a, vector signed char __b) { return __builtin_altivec_vaddsbs((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_vaddsbs(vector signed char __a, vector bool char __b) { return __builtin_altivec_vaddsbs(__a, (vector signed char)__b); } /* vec_vaddubs */ static vector unsigned char __ATTRS_o_ai vec_vaddubs(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vaddubs(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vaddubs(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vaddubs((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vaddubs(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vaddubs(__a, (vector unsigned char)__b); } /* vec_vaddshs */ static vector short __ATTRS_o_ai vec_vaddshs(vector short __a, vector short __b) { return __builtin_altivec_vaddshs(__a, __b); } static vector short __ATTRS_o_ai vec_vaddshs(vector bool short __a, vector short __b) { return __builtin_altivec_vaddshs((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_vaddshs(vector short __a, vector bool short __b) { return __builtin_altivec_vaddshs(__a, (vector short)__b); } /* vec_vadduhs */ static vector unsigned short __ATTRS_o_ai vec_vadduhs(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vadduhs(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vadduhs(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vadduhs((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vadduhs(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vadduhs(__a, (vector unsigned short)__b); } /* vec_vaddsws */ static vector int __ATTRS_o_ai vec_vaddsws(vector int __a, vector int __b) { return __builtin_altivec_vaddsws(__a, __b); } static vector int __ATTRS_o_ai vec_vaddsws(vector bool int __a, vector int __b) { return __builtin_altivec_vaddsws((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_vaddsws(vector int __a, vector bool int __b) { return __builtin_altivec_vaddsws(__a, (vector int)__b); } /* vec_vadduws */ static vector unsigned int __ATTRS_o_ai vec_vadduws(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vadduws(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vadduws(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vadduws((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vadduws(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vadduws(__a, (vector unsigned int)__b); } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) /* vec_vadduqm */ static vector signed __int128 __ATTRS_o_ai vec_vadduqm(vector signed __int128 __a, vector signed __int128 __b) { return __a + __b; } static vector unsigned __int128 __ATTRS_o_ai vec_vadduqm(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __a + __b; } /* vec_vaddeuqm */ static vector signed __int128 __ATTRS_o_ai vec_vaddeuqm(vector signed __int128 __a, vector signed __int128 __b, vector signed __int128 __c) { return __builtin_altivec_vaddeuqm(__a, __b, __c); } static vector unsigned __int128 __ATTRS_o_ai vec_vaddeuqm(vector unsigned __int128 __a, vector unsigned __int128 __b, vector unsigned __int128 __c) { return __builtin_altivec_vaddeuqm(__a, __b, __c); } /* vec_vaddcuq */ static vector signed __int128 __ATTRS_o_ai vec_vaddcuq(vector signed __int128 __a, vector signed __int128 __b) { return __builtin_altivec_vaddcuq(__a, __b); } static vector unsigned __int128 __ATTRS_o_ai vec_vaddcuq(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __builtin_altivec_vaddcuq(__a, __b); } /* vec_vaddecuq */ static vector signed __int128 __ATTRS_o_ai vec_vaddecuq(vector signed __int128 __a, vector signed __int128 __b, vector signed __int128 __c) { return __builtin_altivec_vaddecuq(__a, __b, __c); } static vector unsigned __int128 __ATTRS_o_ai vec_vaddecuq(vector unsigned __int128 __a, vector unsigned __int128 __b, vector unsigned __int128 __c) { return __builtin_altivec_vaddecuq(__a, __b, __c); } #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) /* vec_and */ #define __builtin_altivec_vand vec_and static vector signed char __ATTRS_o_ai vec_and(vector signed char __a, vector signed char __b) { return __a & __b; } static vector signed char __ATTRS_o_ai vec_and(vector bool char __a, vector signed char __b) { return (vector signed char)__a & __b; } static vector signed char __ATTRS_o_ai vec_and(vector signed char __a, vector bool char __b) { return __a & (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_and(vector unsigned char __a, vector unsigned char __b) { return __a & __b; } static vector unsigned char __ATTRS_o_ai vec_and(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a & __b; } static vector unsigned char __ATTRS_o_ai vec_and(vector unsigned char __a, vector bool char __b) { return __a & (vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_and(vector bool char __a, vector bool char __b) { return __a & __b; } static vector short __ATTRS_o_ai vec_and(vector short __a, vector short __b) { return __a & __b; } static vector short __ATTRS_o_ai vec_and(vector bool short __a, vector short __b) { return (vector short)__a & __b; } static vector short __ATTRS_o_ai vec_and(vector short __a, vector bool short __b) { return __a & (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_and(vector unsigned short __a, vector unsigned short __b) { return __a & __b; } static vector unsigned short __ATTRS_o_ai vec_and(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a & __b; } static vector unsigned short __ATTRS_o_ai vec_and(vector unsigned short __a, vector bool short __b) { return __a & (vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_and(vector bool short __a, vector bool short __b) { return __a & __b; } static vector int __ATTRS_o_ai vec_and(vector int __a, vector int __b) { return __a & __b; } static vector int __ATTRS_o_ai vec_and(vector bool int __a, vector int __b) { return (vector int)__a & __b; } static vector int __ATTRS_o_ai vec_and(vector int __a, vector bool int __b) { return __a & (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_and(vector unsigned int __a, vector unsigned int __b) { return __a & __b; } static vector unsigned int __ATTRS_o_ai vec_and(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a & __b; } static vector unsigned int __ATTRS_o_ai vec_and(vector unsigned int __a, vector bool int __b) { return __a & (vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_and(vector bool int __a, vector bool int __b) { return __a & __b; } static vector float __ATTRS_o_ai vec_and(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_and(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_and(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a & (vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_and(vector bool long long __a, vector double __b) { vector unsigned long long __res = (vector unsigned long long)__a & (vector unsigned long long)__b; return (vector double)__res; } static vector double __ATTRS_o_ai vec_and(vector double __a, vector bool long long __b) { vector unsigned long long __res = (vector unsigned long long)__a & (vector unsigned long long)__b; return (vector double)__res; } static vector double __ATTRS_o_ai vec_and(vector double __a, vector double __b) { vector unsigned long long __res = (vector unsigned long long)__a & (vector unsigned long long)__b; return (vector double)__res; } static vector signed long long __ATTRS_o_ai vec_and(vector signed long long __a, vector signed long long __b) { return __a & __b; } static vector signed long long __ATTRS_o_ai vec_and(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a & __b; } static vector signed long long __ATTRS_o_ai vec_and(vector signed long long __a, vector bool long long __b) { return __a & (vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_and(vector unsigned long long __a, vector unsigned long long __b) { return __a & __b; } static vector unsigned long long __ATTRS_o_ai vec_and(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a & __b; } static vector unsigned long long __ATTRS_o_ai vec_and(vector unsigned long long __a, vector bool long long __b) { return __a & (vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_and(vector bool long long __a, vector bool long long __b) { return __a & __b; } #endif /* vec_vand */ static vector signed char __ATTRS_o_ai vec_vand(vector signed char __a, vector signed char __b) { return __a & __b; } static vector signed char __ATTRS_o_ai vec_vand(vector bool char __a, vector signed char __b) { return (vector signed char)__a & __b; } static vector signed char __ATTRS_o_ai vec_vand(vector signed char __a, vector bool char __b) { return __a & (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_vand(vector unsigned char __a, vector unsigned char __b) { return __a & __b; } static vector unsigned char __ATTRS_o_ai vec_vand(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a & __b; } static vector unsigned char __ATTRS_o_ai vec_vand(vector unsigned char __a, vector bool char __b) { return __a & (vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_vand(vector bool char __a, vector bool char __b) { return __a & __b; } static vector short __ATTRS_o_ai vec_vand(vector short __a, vector short __b) { return __a & __b; } static vector short __ATTRS_o_ai vec_vand(vector bool short __a, vector short __b) { return (vector short)__a & __b; } static vector short __ATTRS_o_ai vec_vand(vector short __a, vector bool short __b) { return __a & (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_vand(vector unsigned short __a, vector unsigned short __b) { return __a & __b; } static vector unsigned short __ATTRS_o_ai vec_vand(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a & __b; } static vector unsigned short __ATTRS_o_ai vec_vand(vector unsigned short __a, vector bool short __b) { return __a & (vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_vand(vector bool short __a, vector bool short __b) { return __a & __b; } static vector int __ATTRS_o_ai vec_vand(vector int __a, vector int __b) { return __a & __b; } static vector int __ATTRS_o_ai vec_vand(vector bool int __a, vector int __b) { return (vector int)__a & __b; } static vector int __ATTRS_o_ai vec_vand(vector int __a, vector bool int __b) { return __a & (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_vand(vector unsigned int __a, vector unsigned int __b) { return __a & __b; } static vector unsigned int __ATTRS_o_ai vec_vand(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a & __b; } static vector unsigned int __ATTRS_o_ai vec_vand(vector unsigned int __a, vector bool int __b) { return __a & (vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_vand(vector bool int __a, vector bool int __b) { return __a & __b; } static vector float __ATTRS_o_ai vec_vand(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vand(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vand(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a & (vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_vand(vector signed long long __a, vector signed long long __b) { return __a & __b; } static vector signed long long __ATTRS_o_ai vec_vand(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a & __b; } static vector signed long long __ATTRS_o_ai vec_vand(vector signed long long __a, vector bool long long __b) { return __a & (vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_vand(vector unsigned long long __a, vector unsigned long long __b) { return __a & __b; } static vector unsigned long long __ATTRS_o_ai vec_vand(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a & __b; } static vector unsigned long long __ATTRS_o_ai vec_vand(vector unsigned long long __a, vector bool long long __b) { return __a & (vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_vand(vector bool long long __a, vector bool long long __b) { return __a & __b; } #endif /* vec_andc */ #define __builtin_altivec_vandc vec_andc static vector signed char __ATTRS_o_ai vec_andc(vector signed char __a, vector signed char __b) { return __a & ~__b; } static vector signed char __ATTRS_o_ai vec_andc(vector bool char __a, vector signed char __b) { return (vector signed char)__a & ~__b; } static vector signed char __ATTRS_o_ai vec_andc(vector signed char __a, vector bool char __b) { return __a & ~(vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_andc(vector unsigned char __a, vector unsigned char __b) { return __a & ~__b; } static vector unsigned char __ATTRS_o_ai vec_andc(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a & ~__b; } static vector unsigned char __ATTRS_o_ai vec_andc(vector unsigned char __a, vector bool char __b) { return __a & ~(vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_andc(vector bool char __a, vector bool char __b) { return __a & ~__b; } static vector short __ATTRS_o_ai vec_andc(vector short __a, vector short __b) { return __a & ~__b; } static vector short __ATTRS_o_ai vec_andc(vector bool short __a, vector short __b) { return (vector short)__a & ~__b; } static vector short __ATTRS_o_ai vec_andc(vector short __a, vector bool short __b) { return __a & ~(vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_andc(vector unsigned short __a, vector unsigned short __b) { return __a & ~__b; } static vector unsigned short __ATTRS_o_ai vec_andc(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a & ~__b; } static vector unsigned short __ATTRS_o_ai vec_andc(vector unsigned short __a, vector bool short __b) { return __a & ~(vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_andc(vector bool short __a, vector bool short __b) { return __a & ~__b; } static vector int __ATTRS_o_ai vec_andc(vector int __a, vector int __b) { return __a & ~__b; } static vector int __ATTRS_o_ai vec_andc(vector bool int __a, vector int __b) { return (vector int)__a & ~__b; } static vector int __ATTRS_o_ai vec_andc(vector int __a, vector bool int __b) { return __a & ~(vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_andc(vector unsigned int __a, vector unsigned int __b) { return __a & ~__b; } static vector unsigned int __ATTRS_o_ai vec_andc(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a & ~__b; } static vector unsigned int __ATTRS_o_ai vec_andc(vector unsigned int __a, vector bool int __b) { return __a & ~(vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_andc(vector bool int __a, vector bool int __b) { return __a & ~__b; } static vector float __ATTRS_o_ai vec_andc(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & ~(vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_andc(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & ~(vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_andc(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a & ~(vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_andc(vector bool long long __a, vector double __b) { vector unsigned long long __res = (vector unsigned long long)__a & ~(vector unsigned long long)__b; return (vector double)__res; } static vector double __ATTRS_o_ai vec_andc(vector double __a, vector bool long long __b) { vector unsigned long long __res = (vector unsigned long long)__a & ~(vector unsigned long long)__b; return (vector double)__res; } static vector double __ATTRS_o_ai vec_andc(vector double __a, vector double __b) { vector unsigned long long __res = (vector unsigned long long)__a & ~(vector unsigned long long)__b; return (vector double)__res; } static vector signed long long __ATTRS_o_ai vec_andc(vector signed long long __a, vector signed long long __b) { return __a & ~__b; } static vector signed long long __ATTRS_o_ai vec_andc(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a & ~__b; } static vector signed long long __ATTRS_o_ai vec_andc(vector signed long long __a, vector bool long long __b) { return __a & ~(vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_andc(vector unsigned long long __a, vector unsigned long long __b) { return __a & ~__b; } static vector unsigned long long __ATTRS_o_ai vec_andc(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a & ~__b; } static vector unsigned long long __ATTRS_o_ai vec_andc(vector unsigned long long __a, vector bool long long __b) { return __a & ~(vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_andc(vector bool long long __a, vector bool long long __b) { return __a & ~__b; } #endif /* vec_vandc */ static vector signed char __ATTRS_o_ai vec_vandc(vector signed char __a, vector signed char __b) { return __a & ~__b; } static vector signed char __ATTRS_o_ai vec_vandc(vector bool char __a, vector signed char __b) { return (vector signed char)__a & ~__b; } static vector signed char __ATTRS_o_ai vec_vandc(vector signed char __a, vector bool char __b) { return __a & ~(vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_vandc(vector unsigned char __a, vector unsigned char __b) { return __a & ~__b; } static vector unsigned char __ATTRS_o_ai vec_vandc(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a & ~__b; } static vector unsigned char __ATTRS_o_ai vec_vandc(vector unsigned char __a, vector bool char __b) { return __a & ~(vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_vandc(vector bool char __a, vector bool char __b) { return __a & ~__b; } static vector short __ATTRS_o_ai vec_vandc(vector short __a, vector short __b) { return __a & ~__b; } static vector short __ATTRS_o_ai vec_vandc(vector bool short __a, vector short __b) { return (vector short)__a & ~__b; } static vector short __ATTRS_o_ai vec_vandc(vector short __a, vector bool short __b) { return __a & ~(vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_vandc(vector unsigned short __a, vector unsigned short __b) { return __a & ~__b; } static vector unsigned short __ATTRS_o_ai vec_vandc(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a & ~__b; } static vector unsigned short __ATTRS_o_ai vec_vandc(vector unsigned short __a, vector bool short __b) { return __a & ~(vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_vandc(vector bool short __a, vector bool short __b) { return __a & ~__b; } static vector int __ATTRS_o_ai vec_vandc(vector int __a, vector int __b) { return __a & ~__b; } static vector int __ATTRS_o_ai vec_vandc(vector bool int __a, vector int __b) { return (vector int)__a & ~__b; } static vector int __ATTRS_o_ai vec_vandc(vector int __a, vector bool int __b) { return __a & ~(vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_vandc(vector unsigned int __a, vector unsigned int __b) { return __a & ~__b; } static vector unsigned int __ATTRS_o_ai vec_vandc(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a & ~__b; } static vector unsigned int __ATTRS_o_ai vec_vandc(vector unsigned int __a, vector bool int __b) { return __a & ~(vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_vandc(vector bool int __a, vector bool int __b) { return __a & ~__b; } static vector float __ATTRS_o_ai vec_vandc(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & ~(vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vandc(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a & ~(vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vandc(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a & ~(vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_vandc(vector signed long long __a, vector signed long long __b) { return __a & ~__b; } static vector signed long long __ATTRS_o_ai vec_vandc(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a & ~__b; } static vector signed long long __ATTRS_o_ai vec_vandc(vector signed long long __a, vector bool long long __b) { return __a & ~(vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_vandc(vector unsigned long long __a, vector unsigned long long __b) { return __a & ~__b; } static vector unsigned long long __ATTRS_o_ai vec_vandc(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a & ~__b; } static vector unsigned long long __ATTRS_o_ai vec_vandc(vector unsigned long long __a, vector bool long long __b) { return __a & ~(vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_vandc(vector bool long long __a, vector bool long long __b) { return __a & ~__b; } #endif /* vec_avg */ static vector signed char __ATTRS_o_ai vec_avg(vector signed char __a, vector signed char __b) { return __builtin_altivec_vavgsb(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_avg(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vavgub(__a, __b); } static vector short __ATTRS_o_ai vec_avg(vector short __a, vector short __b) { return __builtin_altivec_vavgsh(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_avg(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vavguh(__a, __b); } static vector int __ATTRS_o_ai vec_avg(vector int __a, vector int __b) { return __builtin_altivec_vavgsw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_avg(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vavguw(__a, __b); } /* vec_vavgsb */ static vector signed char __attribute__((__always_inline__)) vec_vavgsb(vector signed char __a, vector signed char __b) { return __builtin_altivec_vavgsb(__a, __b); } /* vec_vavgub */ static vector unsigned char __attribute__((__always_inline__)) vec_vavgub(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vavgub(__a, __b); } /* vec_vavgsh */ static vector short __attribute__((__always_inline__)) vec_vavgsh(vector short __a, vector short __b) { return __builtin_altivec_vavgsh(__a, __b); } /* vec_vavguh */ static vector unsigned short __attribute__((__always_inline__)) vec_vavguh(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vavguh(__a, __b); } /* vec_vavgsw */ static vector int __attribute__((__always_inline__)) vec_vavgsw(vector int __a, vector int __b) { return __builtin_altivec_vavgsw(__a, __b); } /* vec_vavguw */ static vector unsigned int __attribute__((__always_inline__)) vec_vavguw(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vavguw(__a, __b); } /* vec_ceil */ static vector float __ATTRS_o_ai vec_ceil(vector float __a) { #ifdef __VSX__ return __builtin_vsx_xvrspip(__a); #else return __builtin_altivec_vrfip(__a); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_ceil(vector double __a) { return __builtin_vsx_xvrdpip(__a); } #endif /* vec_vrfip */ static vector float __attribute__((__always_inline__)) vec_vrfip(vector float __a) { return __builtin_altivec_vrfip(__a); } /* vec_cmpb */ static vector int __attribute__((__always_inline__)) vec_cmpb(vector float __a, vector float __b) { return __builtin_altivec_vcmpbfp(__a, __b); } /* vec_vcmpbfp */ static vector int __attribute__((__always_inline__)) vec_vcmpbfp(vector float __a, vector float __b) { return __builtin_altivec_vcmpbfp(__a, __b); } /* vec_cmpeq */ static vector bool char __ATTRS_o_ai vec_cmpeq(vector signed char __a, vector signed char __b) { return (vector bool char)__builtin_altivec_vcmpequb((vector char)__a, (vector char)__b); } static vector bool char __ATTRS_o_ai vec_cmpeq(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)__builtin_altivec_vcmpequb((vector char)__a, (vector char)__b); } static vector bool short __ATTRS_o_ai vec_cmpeq(vector short __a, vector short __b) { return (vector bool short)__builtin_altivec_vcmpequh(__a, __b); } static vector bool short __ATTRS_o_ai vec_cmpeq(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)__builtin_altivec_vcmpequh((vector short)__a, (vector short)__b); } static vector bool int __ATTRS_o_ai vec_cmpeq(vector int __a, vector int __b) { return (vector bool int)__builtin_altivec_vcmpequw(__a, __b); } static vector bool int __ATTRS_o_ai vec_cmpeq(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)__builtin_altivec_vcmpequw((vector int)__a, (vector int)__b); } #ifdef __POWER8_VECTOR__ static vector bool long long __ATTRS_o_ai vec_cmpeq(vector signed long long __a, vector signed long long __b) { return (vector bool long long)__builtin_altivec_vcmpequd(__a, __b); } static vector bool long long __ATTRS_o_ai vec_cmpeq(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)__builtin_altivec_vcmpequd( (vector long long)__a, (vector long long)__b); } #endif static vector bool int __ATTRS_o_ai vec_cmpeq(vector float __a, vector float __b) { #ifdef __VSX__ return (vector bool int)__builtin_vsx_xvcmpeqsp(__a, __b); #else return (vector bool int)__builtin_altivec_vcmpeqfp(__a, __b); #endif } #ifdef __VSX__ static vector bool long long __ATTRS_o_ai vec_cmpeq(vector double __a, vector double __b) { return (vector bool long long)__builtin_vsx_xvcmpeqdp(__a, __b); } #endif /* vec_cmpge */ static vector bool int __ATTRS_o_ai vec_cmpge(vector float __a, vector float __b) { #ifdef __VSX__ return (vector bool int)__builtin_vsx_xvcmpgesp(__a, __b); #else return (vector bool int)__builtin_altivec_vcmpgefp(__a, __b); #endif } #ifdef __VSX__ static vector bool long long __ATTRS_o_ai vec_cmpge(vector double __a, vector double __b) { return (vector bool long long)__builtin_vsx_xvcmpgedp(__a, __b); } #endif #ifdef __POWER8_VECTOR__ /* Forwrad declarations as the functions are used here */ static vector bool long long __ATTRS_o_ai vec_cmpgt(vector unsigned long long __a, vector unsigned long long __b); static vector bool long long __ATTRS_o_ai vec_cmpgt(vector signed long long __a, vector signed long long __b); static vector bool long long __ATTRS_o_ai vec_cmpge(vector signed long long __a, vector signed long long __b) { return ~(vec_cmpgt(__b, __a)); } static vector bool long long __ATTRS_o_ai vec_cmpge(vector unsigned long long __a, vector unsigned long long __b) { return ~(vec_cmpgt(__b, __a)); } #endif /* vec_vcmpgefp */ static vector bool int __attribute__((__always_inline__)) vec_vcmpgefp(vector float __a, vector float __b) { return (vector bool int)__builtin_altivec_vcmpgefp(__a, __b); } /* vec_cmpgt */ static vector bool char __ATTRS_o_ai vec_cmpgt(vector signed char __a, vector signed char __b) { return (vector bool char)__builtin_altivec_vcmpgtsb(__a, __b); } static vector bool char __ATTRS_o_ai vec_cmpgt(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)__builtin_altivec_vcmpgtub(__a, __b); } static vector bool short __ATTRS_o_ai vec_cmpgt(vector short __a, vector short __b) { return (vector bool short)__builtin_altivec_vcmpgtsh(__a, __b); } static vector bool short __ATTRS_o_ai vec_cmpgt(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)__builtin_altivec_vcmpgtuh(__a, __b); } static vector bool int __ATTRS_o_ai vec_cmpgt(vector int __a, vector int __b) { return (vector bool int)__builtin_altivec_vcmpgtsw(__a, __b); } static vector bool int __ATTRS_o_ai vec_cmpgt(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)__builtin_altivec_vcmpgtuw(__a, __b); } #ifdef __POWER8_VECTOR__ static vector bool long long __ATTRS_o_ai vec_cmpgt(vector signed long long __a, vector signed long long __b) { return (vector bool long long)__builtin_altivec_vcmpgtsd(__a, __b); } static vector bool long long __ATTRS_o_ai vec_cmpgt(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)__builtin_altivec_vcmpgtud(__a, __b); } #endif static vector bool int __ATTRS_o_ai vec_cmpgt(vector float __a, vector float __b) { #ifdef __VSX__ return (vector bool int)__builtin_vsx_xvcmpgtsp(__a, __b); #else return (vector bool int)__builtin_altivec_vcmpgtfp(__a, __b); #endif } #ifdef __VSX__ static vector bool long long __ATTRS_o_ai vec_cmpgt(vector double __a, vector double __b) { return (vector bool long long)__builtin_vsx_xvcmpgtdp(__a, __b); } #endif /* vec_vcmpgtsb */ static vector bool char __attribute__((__always_inline__)) vec_vcmpgtsb(vector signed char __a, vector signed char __b) { return (vector bool char)__builtin_altivec_vcmpgtsb(__a, __b); } /* vec_vcmpgtub */ static vector bool char __attribute__((__always_inline__)) vec_vcmpgtub(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)__builtin_altivec_vcmpgtub(__a, __b); } /* vec_vcmpgtsh */ static vector bool short __attribute__((__always_inline__)) vec_vcmpgtsh(vector short __a, vector short __b) { return (vector bool short)__builtin_altivec_vcmpgtsh(__a, __b); } /* vec_vcmpgtuh */ static vector bool short __attribute__((__always_inline__)) vec_vcmpgtuh(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)__builtin_altivec_vcmpgtuh(__a, __b); } /* vec_vcmpgtsw */ static vector bool int __attribute__((__always_inline__)) vec_vcmpgtsw(vector int __a, vector int __b) { return (vector bool int)__builtin_altivec_vcmpgtsw(__a, __b); } /* vec_vcmpgtuw */ static vector bool int __attribute__((__always_inline__)) vec_vcmpgtuw(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)__builtin_altivec_vcmpgtuw(__a, __b); } /* vec_vcmpgtfp */ static vector bool int __attribute__((__always_inline__)) vec_vcmpgtfp(vector float __a, vector float __b) { return (vector bool int)__builtin_altivec_vcmpgtfp(__a, __b); } /* vec_cmple */ static vector bool int __ATTRS_o_ai vec_cmple(vector float __a, vector float __b) { return vec_cmpge(__b, __a); } #ifdef __VSX__ static vector bool long long __ATTRS_o_ai vec_cmple(vector double __a, vector double __b) { return vec_cmpge(__b, __a); } #endif #ifdef __POWER8_VECTOR__ static vector bool long long __ATTRS_o_ai vec_cmple(vector signed long long __a, vector signed long long __b) { return vec_cmpge(__b, __a); } static vector bool long long __ATTRS_o_ai vec_cmple(vector unsigned long long __a, vector unsigned long long __b) { return vec_cmpge(__b, __a); } #endif /* vec_cmplt */ static vector bool char __ATTRS_o_ai vec_cmplt(vector signed char __a, vector signed char __b) { return vec_cmpgt(__b, __a); } static vector bool char __ATTRS_o_ai vec_cmplt(vector unsigned char __a, vector unsigned char __b) { return vec_cmpgt(__b, __a); } static vector bool short __ATTRS_o_ai vec_cmplt(vector short __a, vector short __b) { return vec_cmpgt(__b, __a); } static vector bool short __ATTRS_o_ai vec_cmplt(vector unsigned short __a, vector unsigned short __b) { return vec_cmpgt(__b, __a); } static vector bool int __ATTRS_o_ai vec_cmplt(vector int __a, vector int __b) { return vec_cmpgt(__b, __a); } static vector bool int __ATTRS_o_ai vec_cmplt(vector unsigned int __a, vector unsigned int __b) { return vec_cmpgt(__b, __a); } static vector bool int __ATTRS_o_ai vec_cmplt(vector float __a, vector float __b) { return vec_cmpgt(__b, __a); } #ifdef __VSX__ static vector bool long long __ATTRS_o_ai vec_cmplt(vector double __a, vector double __b) { return vec_cmpgt(__b, __a); } #endif #ifdef __POWER8_VECTOR__ static vector bool long long __ATTRS_o_ai vec_cmplt(vector signed long long __a, vector signed long long __b) { return vec_cmpgt(__b, __a); } static vector bool long long __ATTRS_o_ai vec_cmplt(vector unsigned long long __a, vector unsigned long long __b) { return vec_cmpgt(__b, __a); } /* vec_cntlz */ static vector signed char __ATTRS_o_ai vec_cntlz(vector signed char __a) { return __builtin_altivec_vclzb(__a); } static vector unsigned char __ATTRS_o_ai vec_cntlz(vector unsigned char __a) { return __builtin_altivec_vclzb(__a); } static vector signed short __ATTRS_o_ai vec_cntlz(vector signed short __a) { return __builtin_altivec_vclzh(__a); } static vector unsigned short __ATTRS_o_ai vec_cntlz(vector unsigned short __a) { return __builtin_altivec_vclzh(__a); } static vector signed int __ATTRS_o_ai vec_cntlz(vector signed int __a) { return __builtin_altivec_vclzw(__a); } static vector unsigned int __ATTRS_o_ai vec_cntlz(vector unsigned int __a) { return __builtin_altivec_vclzw(__a); } static vector signed long long __ATTRS_o_ai vec_cntlz(vector signed long long __a) { return __builtin_altivec_vclzd(__a); } static vector unsigned long long __ATTRS_o_ai vec_cntlz(vector unsigned long long __a) { return __builtin_altivec_vclzd(__a); } #endif /* vec_cpsgn */ #ifdef __VSX__ static vector float __ATTRS_o_ai vec_cpsgn(vector float __a, vector float __b) { return __builtin_vsx_xvcpsgnsp(__a, __b); } static vector double __ATTRS_o_ai vec_cpsgn(vector double __a, vector double __b) { return __builtin_vsx_xvcpsgndp(__a, __b); } #endif /* vec_ctf */ static vector float __ATTRS_o_ai vec_ctf(vector int __a, int __b) { return __builtin_altivec_vcfsx(__a, __b); } static vector float __ATTRS_o_ai vec_ctf(vector unsigned int __a, int __b) { return __builtin_altivec_vcfux((vector int)__a, __b); } /* vec_vcfsx */ static vector float __attribute__((__always_inline__)) vec_vcfsx(vector int __a, int __b) { return __builtin_altivec_vcfsx(__a, __b); } /* vec_vcfux */ static vector float __attribute__((__always_inline__)) vec_vcfux(vector unsigned int __a, int __b) { return __builtin_altivec_vcfux((vector int)__a, __b); } /* vec_cts */ static vector int __attribute__((__always_inline__)) vec_cts(vector float __a, int __b) { return __builtin_altivec_vctsxs(__a, __b); } /* vec_vctsxs */ static vector int __attribute__((__always_inline__)) vec_vctsxs(vector float __a, int __b) { return __builtin_altivec_vctsxs(__a, __b); } /* vec_ctu */ static vector unsigned int __attribute__((__always_inline__)) vec_ctu(vector float __a, int __b) { return __builtin_altivec_vctuxs(__a, __b); } /* vec_vctuxs */ static vector unsigned int __attribute__((__always_inline__)) vec_vctuxs(vector float __a, int __b) { return __builtin_altivec_vctuxs(__a, __b); } /* vec_div */ /* Integer vector divides (vectors are scalarized, elements divided and the vectors reassembled). */ static vector signed char __ATTRS_o_ai vec_div(vector signed char __a, vector signed char __b) { return __a / __b; } static vector unsigned char __ATTRS_o_ai vec_div(vector unsigned char __a, vector unsigned char __b) { return __a / __b; } static vector signed short __ATTRS_o_ai vec_div(vector signed short __a, vector signed short __b) { return __a / __b; } static vector unsigned short __ATTRS_o_ai vec_div(vector unsigned short __a, vector unsigned short __b) { return __a / __b; } static vector signed int __ATTRS_o_ai vec_div(vector signed int __a, vector signed int __b) { return __a / __b; } static vector unsigned int __ATTRS_o_ai vec_div(vector unsigned int __a, vector unsigned int __b) { return __a / __b; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_div(vector signed long long __a, vector signed long long __b) { return __a / __b; } static vector unsigned long long __ATTRS_o_ai vec_div(vector unsigned long long __a, vector unsigned long long __b) { return __a / __b; } static vector float __ATTRS_o_ai vec_div(vector float __a, vector float __b) { return __a / __b; } static vector double __ATTRS_o_ai vec_div(vector double __a, vector double __b) { return __a / __b; } #endif /* vec_dss */ static void __attribute__((__always_inline__)) vec_dss(int __a) { __builtin_altivec_dss(__a); } /* vec_dssall */ static void __attribute__((__always_inline__)) vec_dssall(void) { __builtin_altivec_dssall(); } /* vec_dst */ static void __attribute__((__always_inline__)) vec_dst(const void *__a, int __b, int __c) { __builtin_altivec_dst(__a, __b, __c); } /* vec_dstst */ static void __attribute__((__always_inline__)) vec_dstst(const void *__a, int __b, int __c) { __builtin_altivec_dstst(__a, __b, __c); } /* vec_dststt */ static void __attribute__((__always_inline__)) vec_dststt(const void *__a, int __b, int __c) { __builtin_altivec_dststt(__a, __b, __c); } /* vec_dstt */ static void __attribute__((__always_inline__)) vec_dstt(const void *__a, int __b, int __c) { __builtin_altivec_dstt(__a, __b, __c); } /* vec_eqv */ #ifdef __POWER8_VECTOR__ static vector signed char __ATTRS_o_ai vec_eqv(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed char __ATTRS_o_ai vec_eqv(vector bool char __a, vector signed char __b) { return (vector signed char)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed char __ATTRS_o_ai vec_eqv(vector signed char __a, vector bool char __b) { return (vector signed char)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned char __ATTRS_o_ai vec_eqv(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned char __ATTRS_o_ai vec_eqv(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned char __ATTRS_o_ai vec_eqv(vector unsigned char __a, vector bool char __b) { return (vector unsigned char)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed short __ATTRS_o_ai vec_eqv(vector signed short __a, vector signed short __b) { return (vector signed short)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed short __ATTRS_o_ai vec_eqv(vector bool short __a, vector signed short __b) { return (vector signed short)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed short __ATTRS_o_ai vec_eqv(vector signed short __a, vector bool short __b) { return (vector signed short)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned short __ATTRS_o_ai vec_eqv(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned short __ATTRS_o_ai vec_eqv(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned short __ATTRS_o_ai vec_eqv(vector unsigned short __a, vector bool short __b) { return (vector unsigned short)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed int __ATTRS_o_ai vec_eqv(vector signed int __a, vector signed int __b) { return (vector signed int)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed int __ATTRS_o_ai vec_eqv(vector bool int __a, vector signed int __b) { return (vector signed int)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed int __ATTRS_o_ai vec_eqv(vector signed int __a, vector bool int __b) { return (vector signed int)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned int __ATTRS_o_ai vec_eqv(vector unsigned int __a, vector unsigned int __b) { return __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned int __ATTRS_o_ai vec_eqv(vector bool int __a, vector unsigned int __b) { return __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned int __ATTRS_o_ai vec_eqv(vector unsigned int __a, vector bool int __b) { return __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed long long __ATTRS_o_ai vec_eqv(vector signed long long __a, vector signed long long __b) { return (vector signed long long) __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed long long __ATTRS_o_ai vec_eqv(vector bool long long __a, vector signed long long __b) { return (vector signed long long) __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector signed long long __ATTRS_o_ai vec_eqv(vector signed long long __a, vector bool long long __b) { return (vector signed long long) __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned long long __ATTRS_o_ai vec_eqv(vector unsigned long long __a, vector unsigned long long __b) { return (vector unsigned long long) __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned long long __ATTRS_o_ai vec_eqv(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long) __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector unsigned long long __ATTRS_o_ai vec_eqv(vector unsigned long long __a, vector bool long long __b) { return (vector unsigned long long) __builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector float __ATTRS_o_ai vec_eqv(vector float __a, vector float __b) { return (vector float)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector float __ATTRS_o_ai vec_eqv(vector bool int __a, vector float __b) { return (vector float)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector float __ATTRS_o_ai vec_eqv(vector float __a, vector bool int __b) { return (vector float)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector double __ATTRS_o_ai vec_eqv(vector double __a, vector double __b) { return (vector double)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector double __ATTRS_o_ai vec_eqv(vector bool long long __a, vector double __b) { return (vector double)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } static vector double __ATTRS_o_ai vec_eqv(vector double __a, vector bool long long __b) { return (vector double)__builtin_vsx_xxleqv((vector unsigned int)__a, (vector unsigned int)__b); } #endif /* vec_expte */ static vector float __attribute__((__always_inline__)) vec_expte(vector float __a) { return __builtin_altivec_vexptefp(__a); } /* vec_vexptefp */ static vector float __attribute__((__always_inline__)) vec_vexptefp(vector float __a) { return __builtin_altivec_vexptefp(__a); } /* vec_floor */ static vector float __ATTRS_o_ai vec_floor(vector float __a) { #ifdef __VSX__ return __builtin_vsx_xvrspim(__a); #else return __builtin_altivec_vrfim(__a); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_floor(vector double __a) { return __builtin_vsx_xvrdpim(__a); } #endif /* vec_vrfim */ static vector float __attribute__((__always_inline__)) vec_vrfim(vector float __a) { return __builtin_altivec_vrfim(__a); } /* vec_ld */ static vector signed char __ATTRS_o_ai vec_ld(int __a, const vector signed char *__b) { return (vector signed char)__builtin_altivec_lvx(__a, __b); } static vector signed char __ATTRS_o_ai vec_ld(int __a, const signed char *__b) { return (vector signed char)__builtin_altivec_lvx(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_ld(int __a, const vector unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvx(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_ld(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvx(__a, __b); } static vector bool char __ATTRS_o_ai vec_ld(int __a, const vector bool char *__b) { return (vector bool char)__builtin_altivec_lvx(__a, __b); } static vector short __ATTRS_o_ai vec_ld(int __a, const vector short *__b) { return (vector short)__builtin_altivec_lvx(__a, __b); } static vector short __ATTRS_o_ai vec_ld(int __a, const short *__b) { return (vector short)__builtin_altivec_lvx(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_ld(int __a, const vector unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvx(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_ld(int __a, const unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvx(__a, __b); } static vector bool short __ATTRS_o_ai vec_ld(int __a, const vector bool short *__b) { return (vector bool short)__builtin_altivec_lvx(__a, __b); } static vector pixel __ATTRS_o_ai vec_ld(int __a, const vector pixel *__b) { return (vector pixel)__builtin_altivec_lvx(__a, __b); } static vector int __ATTRS_o_ai vec_ld(int __a, const vector int *__b) { return (vector int)__builtin_altivec_lvx(__a, __b); } static vector int __ATTRS_o_ai vec_ld(int __a, const int *__b) { return (vector int)__builtin_altivec_lvx(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_ld(int __a, const vector unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvx(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_ld(int __a, const unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvx(__a, __b); } static vector bool int __ATTRS_o_ai vec_ld(int __a, const vector bool int *__b) { return (vector bool int)__builtin_altivec_lvx(__a, __b); } static vector float __ATTRS_o_ai vec_ld(int __a, const vector float *__b) { return (vector float)__builtin_altivec_lvx(__a, __b); } static vector float __ATTRS_o_ai vec_ld(int __a, const float *__b) { return (vector float)__builtin_altivec_lvx(__a, __b); } /* vec_lvx */ static vector signed char __ATTRS_o_ai vec_lvx(int __a, const vector signed char *__b) { return (vector signed char)__builtin_altivec_lvx(__a, __b); } static vector signed char __ATTRS_o_ai vec_lvx(int __a, const signed char *__b) { return (vector signed char)__builtin_altivec_lvx(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_lvx(int __a, const vector unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvx(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_lvx(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvx(__a, __b); } static vector bool char __ATTRS_o_ai vec_lvx(int __a, const vector bool char *__b) { return (vector bool char)__builtin_altivec_lvx(__a, __b); } static vector short __ATTRS_o_ai vec_lvx(int __a, const vector short *__b) { return (vector short)__builtin_altivec_lvx(__a, __b); } static vector short __ATTRS_o_ai vec_lvx(int __a, const short *__b) { return (vector short)__builtin_altivec_lvx(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_lvx(int __a, const vector unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvx(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_lvx(int __a, const unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvx(__a, __b); } static vector bool short __ATTRS_o_ai vec_lvx(int __a, const vector bool short *__b) { return (vector bool short)__builtin_altivec_lvx(__a, __b); } static vector pixel __ATTRS_o_ai vec_lvx(int __a, const vector pixel *__b) { return (vector pixel)__builtin_altivec_lvx(__a, __b); } static vector int __ATTRS_o_ai vec_lvx(int __a, const vector int *__b) { return (vector int)__builtin_altivec_lvx(__a, __b); } static vector int __ATTRS_o_ai vec_lvx(int __a, const int *__b) { return (vector int)__builtin_altivec_lvx(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_lvx(int __a, const vector unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvx(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_lvx(int __a, const unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvx(__a, __b); } static vector bool int __ATTRS_o_ai vec_lvx(int __a, const vector bool int *__b) { return (vector bool int)__builtin_altivec_lvx(__a, __b); } static vector float __ATTRS_o_ai vec_lvx(int __a, const vector float *__b) { return (vector float)__builtin_altivec_lvx(__a, __b); } static vector float __ATTRS_o_ai vec_lvx(int __a, const float *__b) { return (vector float)__builtin_altivec_lvx(__a, __b); } /* vec_lde */ static vector signed char __ATTRS_o_ai vec_lde(int __a, const signed char *__b) { return (vector signed char)__builtin_altivec_lvebx(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_lde(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvebx(__a, __b); } static vector short __ATTRS_o_ai vec_lde(int __a, const short *__b) { return (vector short)__builtin_altivec_lvehx(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_lde(int __a, const unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvehx(__a, __b); } static vector int __ATTRS_o_ai vec_lde(int __a, const int *__b) { return (vector int)__builtin_altivec_lvewx(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_lde(int __a, const unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvewx(__a, __b); } static vector float __ATTRS_o_ai vec_lde(int __a, const float *__b) { return (vector float)__builtin_altivec_lvewx(__a, __b); } /* vec_lvebx */ static vector signed char __ATTRS_o_ai vec_lvebx(int __a, const signed char *__b) { return (vector signed char)__builtin_altivec_lvebx(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_lvebx(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvebx(__a, __b); } /* vec_lvehx */ static vector short __ATTRS_o_ai vec_lvehx(int __a, const short *__b) { return (vector short)__builtin_altivec_lvehx(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_lvehx(int __a, const unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvehx(__a, __b); } /* vec_lvewx */ static vector int __ATTRS_o_ai vec_lvewx(int __a, const int *__b) { return (vector int)__builtin_altivec_lvewx(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_lvewx(int __a, const unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvewx(__a, __b); } static vector float __ATTRS_o_ai vec_lvewx(int __a, const float *__b) { return (vector float)__builtin_altivec_lvewx(__a, __b); } /* vec_ldl */ static vector signed char __ATTRS_o_ai vec_ldl(int __a, const vector signed char *__b) { return (vector signed char)__builtin_altivec_lvxl(__a, __b); } static vector signed char __ATTRS_o_ai vec_ldl(int __a, const signed char *__b) { return (vector signed char)__builtin_altivec_lvxl(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_ldl(int __a, const vector unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvxl(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_ldl(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvxl(__a, __b); } static vector bool char __ATTRS_o_ai vec_ldl(int __a, const vector bool char *__b) { return (vector bool char)__builtin_altivec_lvxl(__a, __b); } static vector short __ATTRS_o_ai vec_ldl(int __a, const vector short *__b) { return (vector short)__builtin_altivec_lvxl(__a, __b); } static vector short __ATTRS_o_ai vec_ldl(int __a, const short *__b) { return (vector short)__builtin_altivec_lvxl(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_ldl(int __a, const vector unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvxl(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_ldl(int __a, const unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvxl(__a, __b); } static vector bool short __ATTRS_o_ai vec_ldl(int __a, const vector bool short *__b) { return (vector bool short)__builtin_altivec_lvxl(__a, __b); } static vector pixel __ATTRS_o_ai vec_ldl(int __a, const vector pixel *__b) { return (vector pixel short)__builtin_altivec_lvxl(__a, __b); } static vector int __ATTRS_o_ai vec_ldl(int __a, const vector int *__b) { return (vector int)__builtin_altivec_lvxl(__a, __b); } static vector int __ATTRS_o_ai vec_ldl(int __a, const int *__b) { return (vector int)__builtin_altivec_lvxl(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_ldl(int __a, const vector unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvxl(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_ldl(int __a, const unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvxl(__a, __b); } static vector bool int __ATTRS_o_ai vec_ldl(int __a, const vector bool int *__b) { return (vector bool int)__builtin_altivec_lvxl(__a, __b); } static vector float __ATTRS_o_ai vec_ldl(int __a, const vector float *__b) { return (vector float)__builtin_altivec_lvxl(__a, __b); } static vector float __ATTRS_o_ai vec_ldl(int __a, const float *__b) { return (vector float)__builtin_altivec_lvxl(__a, __b); } /* vec_lvxl */ static vector signed char __ATTRS_o_ai vec_lvxl(int __a, const vector signed char *__b) { return (vector signed char)__builtin_altivec_lvxl(__a, __b); } static vector signed char __ATTRS_o_ai vec_lvxl(int __a, const signed char *__b) { return (vector signed char)__builtin_altivec_lvxl(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_lvxl(int __a, const vector unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvxl(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_lvxl(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvxl(__a, __b); } static vector bool char __ATTRS_o_ai vec_lvxl(int __a, const vector bool char *__b) { return (vector bool char)__builtin_altivec_lvxl(__a, __b); } static vector short __ATTRS_o_ai vec_lvxl(int __a, const vector short *__b) { return (vector short)__builtin_altivec_lvxl(__a, __b); } static vector short __ATTRS_o_ai vec_lvxl(int __a, const short *__b) { return (vector short)__builtin_altivec_lvxl(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_lvxl(int __a, const vector unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvxl(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_lvxl(int __a, const unsigned short *__b) { return (vector unsigned short)__builtin_altivec_lvxl(__a, __b); } static vector bool short __ATTRS_o_ai vec_lvxl(int __a, const vector bool short *__b) { return (vector bool short)__builtin_altivec_lvxl(__a, __b); } static vector pixel __ATTRS_o_ai vec_lvxl(int __a, const vector pixel *__b) { return (vector pixel)__builtin_altivec_lvxl(__a, __b); } static vector int __ATTRS_o_ai vec_lvxl(int __a, const vector int *__b) { return (vector int)__builtin_altivec_lvxl(__a, __b); } static vector int __ATTRS_o_ai vec_lvxl(int __a, const int *__b) { return (vector int)__builtin_altivec_lvxl(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_lvxl(int __a, const vector unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvxl(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_lvxl(int __a, const unsigned int *__b) { return (vector unsigned int)__builtin_altivec_lvxl(__a, __b); } static vector bool int __ATTRS_o_ai vec_lvxl(int __a, const vector bool int *__b) { return (vector bool int)__builtin_altivec_lvxl(__a, __b); } static vector float __ATTRS_o_ai vec_lvxl(int __a, const vector float *__b) { return (vector float)__builtin_altivec_lvxl(__a, __b); } static vector float __ATTRS_o_ai vec_lvxl(int __a, const float *__b) { return (vector float)__builtin_altivec_lvxl(__a, __b); } /* vec_loge */ static vector float __attribute__((__always_inline__)) vec_loge(vector float __a) { return __builtin_altivec_vlogefp(__a); } /* vec_vlogefp */ static vector float __attribute__((__always_inline__)) vec_vlogefp(vector float __a) { return __builtin_altivec_vlogefp(__a); } /* vec_lvsl */ #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsl(int __a, const signed char *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsl(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsl(int __a, const signed char *__b) { return (vector unsigned char)__builtin_altivec_lvsl(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsl(int __a, const unsigned char *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsl(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsl(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvsl(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsl(int __a, const short *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsl(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsl(int __a, const short *__b) { return (vector unsigned char)__builtin_altivec_lvsl(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsl(int __a, const unsigned short *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsl(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsl(int __a, const unsigned short *__b) { return (vector unsigned char)__builtin_altivec_lvsl(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsl(int __a, const int *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsl(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsl(int __a, const int *__b) { return (vector unsigned char)__builtin_altivec_lvsl(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsl(int __a, const unsigned int *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsl(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsl(int __a, const unsigned int *__b) { return (vector unsigned char)__builtin_altivec_lvsl(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsl(int __a, const float *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsl(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsl(int __a, const float *__b) { return (vector unsigned char)__builtin_altivec_lvsl(__a, __b); } #endif /* vec_lvsr */ #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsr(int __a, const signed char *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsr(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsr(int __a, const signed char *__b) { return (vector unsigned char)__builtin_altivec_lvsr(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsr(int __a, const unsigned char *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsr(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsr(int __a, const unsigned char *__b) { return (vector unsigned char)__builtin_altivec_lvsr(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsr(int __a, const short *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsr(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsr(int __a, const short *__b) { return (vector unsigned char)__builtin_altivec_lvsr(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsr(int __a, const unsigned short *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsr(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsr(int __a, const unsigned short *__b) { return (vector unsigned char)__builtin_altivec_lvsr(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsr(int __a, const int *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsr(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsr(int __a, const int *__b) { return (vector unsigned char)__builtin_altivec_lvsr(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsr(int __a, const unsigned int *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsr(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsr(int __a, const unsigned int *__b) { return (vector unsigned char)__builtin_altivec_lvsr(__a, __b); } #endif #ifdef __LITTLE_ENDIAN__ static vector unsigned char __ATTRS_o_ai __attribute__((__deprecated__("use assignment for unaligned little endian \ loads/stores"))) vec_lvsr(int __a, const float *__b) { vector unsigned char mask = (vector unsigned char)__builtin_altivec_lvsr(__a, __b); vector unsigned char reverse = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; return vec_perm(mask, mask, reverse); } #else static vector unsigned char __ATTRS_o_ai vec_lvsr(int __a, const float *__b) { return (vector unsigned char)__builtin_altivec_lvsr(__a, __b); } #endif /* vec_madd */ static vector float __ATTRS_o_ai vec_madd(vector float __a, vector float __b, vector float __c) { #ifdef __VSX__ return __builtin_vsx_xvmaddasp(__a, __b, __c); #else return __builtin_altivec_vmaddfp(__a, __b, __c); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_madd(vector double __a, vector double __b, vector double __c) { return __builtin_vsx_xvmaddadp(__a, __b, __c); } #endif /* vec_vmaddfp */ static vector float __attribute__((__always_inline__)) vec_vmaddfp(vector float __a, vector float __b, vector float __c) { return __builtin_altivec_vmaddfp(__a, __b, __c); } /* vec_madds */ static vector signed short __attribute__((__always_inline__)) vec_madds(vector signed short __a, vector signed short __b, vector signed short __c) { return __builtin_altivec_vmhaddshs(__a, __b, __c); } /* vec_vmhaddshs */ static vector signed short __attribute__((__always_inline__)) vec_vmhaddshs(vector signed short __a, vector signed short __b, vector signed short __c) { return __builtin_altivec_vmhaddshs(__a, __b, __c); } /* vec_msub */ #ifdef __VSX__ static vector float __ATTRS_o_ai vec_msub(vector float __a, vector float __b, vector float __c) { return __builtin_vsx_xvmsubasp(__a, __b, __c); } static vector double __ATTRS_o_ai vec_msub(vector double __a, vector double __b, vector double __c) { return __builtin_vsx_xvmsubadp(__a, __b, __c); } #endif /* vec_max */ static vector signed char __ATTRS_o_ai vec_max(vector signed char __a, vector signed char __b) { return __builtin_altivec_vmaxsb(__a, __b); } static vector signed char __ATTRS_o_ai vec_max(vector bool char __a, vector signed char __b) { return __builtin_altivec_vmaxsb((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_max(vector signed char __a, vector bool char __b) { return __builtin_altivec_vmaxsb(__a, (vector signed char)__b); } static vector unsigned char __ATTRS_o_ai vec_max(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vmaxub(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_max(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vmaxub((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_max(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vmaxub(__a, (vector unsigned char)__b); } static vector short __ATTRS_o_ai vec_max(vector short __a, vector short __b) { return __builtin_altivec_vmaxsh(__a, __b); } static vector short __ATTRS_o_ai vec_max(vector bool short __a, vector short __b) { return __builtin_altivec_vmaxsh((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_max(vector short __a, vector bool short __b) { return __builtin_altivec_vmaxsh(__a, (vector short)__b); } static vector unsigned short __ATTRS_o_ai vec_max(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vmaxuh(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_max(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vmaxuh((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_max(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vmaxuh(__a, (vector unsigned short)__b); } static vector int __ATTRS_o_ai vec_max(vector int __a, vector int __b) { return __builtin_altivec_vmaxsw(__a, __b); } static vector int __ATTRS_o_ai vec_max(vector bool int __a, vector int __b) { return __builtin_altivec_vmaxsw((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_max(vector int __a, vector bool int __b) { return __builtin_altivec_vmaxsw(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_max(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vmaxuw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_max(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vmaxuw((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_max(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vmaxuw(__a, (vector unsigned int)__b); } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_max(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vmaxsd(__a, __b); } static vector signed long long __ATTRS_o_ai vec_max(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vmaxsd((vector signed long long)__a, __b); } static vector signed long long __ATTRS_o_ai vec_max(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vmaxsd(__a, (vector signed long long)__b); } static vector unsigned long long __ATTRS_o_ai vec_max(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vmaxud(__a, __b); } static vector unsigned long long __ATTRS_o_ai vec_max(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vmaxud((vector unsigned long long)__a, __b); } static vector unsigned long long __ATTRS_o_ai vec_max(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vmaxud(__a, (vector unsigned long long)__b); } #endif static vector float __ATTRS_o_ai vec_max(vector float __a, vector float __b) { #ifdef __VSX__ return __builtin_vsx_xvmaxsp(__a, __b); #else return __builtin_altivec_vmaxfp(__a, __b); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_max(vector double __a, vector double __b) { return __builtin_vsx_xvmaxdp(__a, __b); } #endif /* vec_vmaxsb */ static vector signed char __ATTRS_o_ai vec_vmaxsb(vector signed char __a, vector signed char __b) { return __builtin_altivec_vmaxsb(__a, __b); } static vector signed char __ATTRS_o_ai vec_vmaxsb(vector bool char __a, vector signed char __b) { return __builtin_altivec_vmaxsb((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_vmaxsb(vector signed char __a, vector bool char __b) { return __builtin_altivec_vmaxsb(__a, (vector signed char)__b); } /* vec_vmaxub */ static vector unsigned char __ATTRS_o_ai vec_vmaxub(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vmaxub(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vmaxub(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vmaxub((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vmaxub(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vmaxub(__a, (vector unsigned char)__b); } /* vec_vmaxsh */ static vector short __ATTRS_o_ai vec_vmaxsh(vector short __a, vector short __b) { return __builtin_altivec_vmaxsh(__a, __b); } static vector short __ATTRS_o_ai vec_vmaxsh(vector bool short __a, vector short __b) { return __builtin_altivec_vmaxsh((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_vmaxsh(vector short __a, vector bool short __b) { return __builtin_altivec_vmaxsh(__a, (vector short)__b); } /* vec_vmaxuh */ static vector unsigned short __ATTRS_o_ai vec_vmaxuh(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vmaxuh(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vmaxuh(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vmaxuh((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vmaxuh(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vmaxuh(__a, (vector unsigned short)__b); } /* vec_vmaxsw */ static vector int __ATTRS_o_ai vec_vmaxsw(vector int __a, vector int __b) { return __builtin_altivec_vmaxsw(__a, __b); } static vector int __ATTRS_o_ai vec_vmaxsw(vector bool int __a, vector int __b) { return __builtin_altivec_vmaxsw((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_vmaxsw(vector int __a, vector bool int __b) { return __builtin_altivec_vmaxsw(__a, (vector int)__b); } /* vec_vmaxuw */ static vector unsigned int __ATTRS_o_ai vec_vmaxuw(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vmaxuw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vmaxuw(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vmaxuw((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vmaxuw(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vmaxuw(__a, (vector unsigned int)__b); } /* vec_vmaxfp */ static vector float __attribute__((__always_inline__)) vec_vmaxfp(vector float __a, vector float __b) { #ifdef __VSX__ return __builtin_vsx_xvmaxsp(__a, __b); #else return __builtin_altivec_vmaxfp(__a, __b); #endif } /* vec_mergeh */ static vector signed char __ATTRS_o_ai vec_mergeh(vector signed char __a, vector signed char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17)); } static vector unsigned char __ATTRS_o_ai vec_mergeh(vector unsigned char __a, vector unsigned char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17)); } static vector bool char __ATTRS_o_ai vec_mergeh(vector bool char __a, vector bool char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17)); } static vector short __ATTRS_o_ai vec_mergeh(vector short __a, vector short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } static vector unsigned short __ATTRS_o_ai vec_mergeh(vector unsigned short __a, vector unsigned short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } static vector bool short __ATTRS_o_ai vec_mergeh(vector bool short __a, vector bool short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } static vector pixel __ATTRS_o_ai vec_mergeh(vector pixel __a, vector pixel __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } static vector int __ATTRS_o_ai vec_mergeh(vector int __a, vector int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } static vector unsigned int __ATTRS_o_ai vec_mergeh(vector unsigned int __a, vector unsigned int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } static vector bool int __ATTRS_o_ai vec_mergeh(vector bool int __a, vector bool int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } static vector float __ATTRS_o_ai vec_mergeh(vector float __a, vector float __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_mergeh(vector signed long long __a, vector signed long long __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector signed long long __ATTRS_o_ai vec_mergeh(vector signed long long __a, vector bool long long __b) { return vec_perm(__a, (vector signed long long)__b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector signed long long __ATTRS_o_ai vec_mergeh(vector bool long long __a, vector signed long long __b) { return vec_perm((vector signed long long)__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector unsigned long long __ATTRS_o_ai vec_mergeh(vector unsigned long long __a, vector unsigned long long __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector unsigned long long __ATTRS_o_ai vec_mergeh(vector unsigned long long __a, vector bool long long __b) { return vec_perm(__a, (vector unsigned long long)__b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector unsigned long long __ATTRS_o_ai vec_mergeh(vector bool long long __a, vector unsigned long long __b) { return vec_perm((vector unsigned long long)__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector double __ATTRS_o_ai vec_mergeh(vector double __a, vector double __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector double __ATTRS_o_ai vec_mergeh(vector double __a, vector bool long long __b) { return vec_perm(__a, (vector double)__b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } static vector double __ATTRS_o_ai vec_mergeh(vector bool long long __a, vector double __b) { return vec_perm((vector double)__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)); } #endif /* vec_vmrghb */ #define __builtin_altivec_vmrghb vec_vmrghb static vector signed char __ATTRS_o_ai vec_vmrghb(vector signed char __a, vector signed char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17)); } static vector unsigned char __ATTRS_o_ai vec_vmrghb(vector unsigned char __a, vector unsigned char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17)); } static vector bool char __ATTRS_o_ai vec_vmrghb(vector bool char __a, vector bool char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17)); } /* vec_vmrghh */ #define __builtin_altivec_vmrghh vec_vmrghh static vector short __ATTRS_o_ai vec_vmrghh(vector short __a, vector short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } static vector unsigned short __ATTRS_o_ai vec_vmrghh(vector unsigned short __a, vector unsigned short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } static vector bool short __ATTRS_o_ai vec_vmrghh(vector bool short __a, vector bool short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } static vector pixel __ATTRS_o_ai vec_vmrghh(vector pixel __a, vector pixel __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x10, 0x11, 0x02, 0x03, 0x12, 0x13, 0x04, 0x05, 0x14, 0x15, 0x06, 0x07, 0x16, 0x17)); } /* vec_vmrghw */ #define __builtin_altivec_vmrghw vec_vmrghw static vector int __ATTRS_o_ai vec_vmrghw(vector int __a, vector int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } static vector unsigned int __ATTRS_o_ai vec_vmrghw(vector unsigned int __a, vector unsigned int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } static vector bool int __ATTRS_o_ai vec_vmrghw(vector bool int __a, vector bool int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } static vector float __ATTRS_o_ai vec_vmrghw(vector float __a, vector float __b) { return vec_perm(__a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17)); } /* vec_mergel */ static vector signed char __ATTRS_o_ai vec_mergel(vector signed char __a, vector signed char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F)); } static vector unsigned char __ATTRS_o_ai vec_mergel(vector unsigned char __a, vector unsigned char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F)); } static vector bool char __ATTRS_o_ai vec_mergel(vector bool char __a, vector bool char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F)); } static vector short __ATTRS_o_ai vec_mergel(vector short __a, vector short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } static vector unsigned short __ATTRS_o_ai vec_mergel(vector unsigned short __a, vector unsigned short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } static vector bool short __ATTRS_o_ai vec_mergel(vector bool short __a, vector bool short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } static vector pixel __ATTRS_o_ai vec_mergel(vector pixel __a, vector pixel __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } static vector int __ATTRS_o_ai vec_mergel(vector int __a, vector int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector unsigned int __ATTRS_o_ai vec_mergel(vector unsigned int __a, vector unsigned int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector bool int __ATTRS_o_ai vec_mergel(vector bool int __a, vector bool int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector float __ATTRS_o_ai vec_mergel(vector float __a, vector float __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_mergel(vector signed long long __a, vector signed long long __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector signed long long __ATTRS_o_ai vec_mergel(vector signed long long __a, vector bool long long __b) { return vec_perm(__a, (vector signed long long)__b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector signed long long __ATTRS_o_ai vec_mergel(vector bool long long __a, vector signed long long __b) { return vec_perm((vector signed long long)__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector unsigned long long __ATTRS_o_ai vec_mergel(vector unsigned long long __a, vector unsigned long long __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector unsigned long long __ATTRS_o_ai vec_mergel(vector unsigned long long __a, vector bool long long __b) { return vec_perm(__a, (vector unsigned long long)__b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector unsigned long long __ATTRS_o_ai vec_mergel(vector bool long long __a, vector unsigned long long __b) { return vec_perm((vector unsigned long long)__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector double __ATTRS_o_ai vec_mergel(vector double __a, vector double __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector double __ATTRS_o_ai vec_mergel(vector double __a, vector bool long long __b) { return vec_perm(__a, (vector double)__b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector double __ATTRS_o_ai vec_mergel(vector bool long long __a, vector double __b) { return vec_perm((vector double)__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x18, 0X19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)); } #endif /* vec_vmrglb */ #define __builtin_altivec_vmrglb vec_vmrglb static vector signed char __ATTRS_o_ai vec_vmrglb(vector signed char __a, vector signed char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F)); } static vector unsigned char __ATTRS_o_ai vec_vmrglb(vector unsigned char __a, vector unsigned char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F)); } static vector bool char __ATTRS_o_ai vec_vmrglb(vector bool char __a, vector bool char __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F)); } /* vec_vmrglh */ #define __builtin_altivec_vmrglh vec_vmrglh static vector short __ATTRS_o_ai vec_vmrglh(vector short __a, vector short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } static vector unsigned short __ATTRS_o_ai vec_vmrglh(vector unsigned short __a, vector unsigned short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } static vector bool short __ATTRS_o_ai vec_vmrglh(vector bool short __a, vector bool short __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } static vector pixel __ATTRS_o_ai vec_vmrglh(vector pixel __a, vector pixel __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x18, 0x19, 0x0A, 0x0B, 0x1A, 0x1B, 0x0C, 0x0D, 0x1C, 0x1D, 0x0E, 0x0F, 0x1E, 0x1F)); } /* vec_vmrglw */ #define __builtin_altivec_vmrglw vec_vmrglw static vector int __ATTRS_o_ai vec_vmrglw(vector int __a, vector int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector unsigned int __ATTRS_o_ai vec_vmrglw(vector unsigned int __a, vector unsigned int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector bool int __ATTRS_o_ai vec_vmrglw(vector bool int __a, vector bool int __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector float __ATTRS_o_ai vec_vmrglw(vector float __a, vector float __b) { return vec_perm(__a, __b, (vector unsigned char)(0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } #ifdef __POWER8_VECTOR__ /* vec_mergee */ static vector bool int __ATTRS_o_ai vec_mergee(vector bool int __a, vector bool int __b) { return vec_perm(__a, __b, (vector unsigned char) (0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B)); } static vector signed int __ATTRS_o_ai vec_mergee(vector signed int __a, vector signed int __b) { return vec_perm(__a, __b, (vector unsigned char) (0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B)); } static vector unsigned int __ATTRS_o_ai vec_mergee(vector unsigned int __a, vector unsigned int __b) { return vec_perm(__a, __b, (vector unsigned char) (0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, 0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B)); } /* vec_mergeo */ static vector bool int __ATTRS_o_ai vec_mergeo(vector bool int __a, vector bool int __b) { return vec_perm(__a, __b, (vector unsigned char) (0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector signed int __ATTRS_o_ai vec_mergeo(vector signed int __a, vector signed int __b) { return vec_perm(__a, __b, (vector unsigned char) (0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } static vector unsigned int __ATTRS_o_ai vec_mergeo(vector unsigned int __a, vector unsigned int __b) { return vec_perm(__a, __b, (vector unsigned char) (0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17, 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F)); } #endif /* vec_mfvscr */ static vector unsigned short __attribute__((__always_inline__)) vec_mfvscr(void) { return __builtin_altivec_mfvscr(); } /* vec_min */ static vector signed char __ATTRS_o_ai vec_min(vector signed char __a, vector signed char __b) { return __builtin_altivec_vminsb(__a, __b); } static vector signed char __ATTRS_o_ai vec_min(vector bool char __a, vector signed char __b) { return __builtin_altivec_vminsb((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_min(vector signed char __a, vector bool char __b) { return __builtin_altivec_vminsb(__a, (vector signed char)__b); } static vector unsigned char __ATTRS_o_ai vec_min(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vminub(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_min(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vminub((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_min(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vminub(__a, (vector unsigned char)__b); } static vector short __ATTRS_o_ai vec_min(vector short __a, vector short __b) { return __builtin_altivec_vminsh(__a, __b); } static vector short __ATTRS_o_ai vec_min(vector bool short __a, vector short __b) { return __builtin_altivec_vminsh((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_min(vector short __a, vector bool short __b) { return __builtin_altivec_vminsh(__a, (vector short)__b); } static vector unsigned short __ATTRS_o_ai vec_min(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vminuh(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_min(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vminuh((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_min(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vminuh(__a, (vector unsigned short)__b); } static vector int __ATTRS_o_ai vec_min(vector int __a, vector int __b) { return __builtin_altivec_vminsw(__a, __b); } static vector int __ATTRS_o_ai vec_min(vector bool int __a, vector int __b) { return __builtin_altivec_vminsw((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_min(vector int __a, vector bool int __b) { return __builtin_altivec_vminsw(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_min(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vminuw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_min(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vminuw((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_min(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vminuw(__a, (vector unsigned int)__b); } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_min(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vminsd(__a, __b); } static vector signed long long __ATTRS_o_ai vec_min(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vminsd((vector signed long long)__a, __b); } static vector signed long long __ATTRS_o_ai vec_min(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vminsd(__a, (vector signed long long)__b); } static vector unsigned long long __ATTRS_o_ai vec_min(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vminud(__a, __b); } static vector unsigned long long __ATTRS_o_ai vec_min(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vminud((vector unsigned long long)__a, __b); } static vector unsigned long long __ATTRS_o_ai vec_min(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vminud(__a, (vector unsigned long long)__b); } #endif static vector float __ATTRS_o_ai vec_min(vector float __a, vector float __b) { #ifdef __VSX__ return __builtin_vsx_xvminsp(__a, __b); #else return __builtin_altivec_vminfp(__a, __b); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_min(vector double __a, vector double __b) { return __builtin_vsx_xvmindp(__a, __b); } #endif /* vec_vminsb */ static vector signed char __ATTRS_o_ai vec_vminsb(vector signed char __a, vector signed char __b) { return __builtin_altivec_vminsb(__a, __b); } static vector signed char __ATTRS_o_ai vec_vminsb(vector bool char __a, vector signed char __b) { return __builtin_altivec_vminsb((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_vminsb(vector signed char __a, vector bool char __b) { return __builtin_altivec_vminsb(__a, (vector signed char)__b); } /* vec_vminub */ static vector unsigned char __ATTRS_o_ai vec_vminub(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vminub(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vminub(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vminub((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vminub(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vminub(__a, (vector unsigned char)__b); } /* vec_vminsh */ static vector short __ATTRS_o_ai vec_vminsh(vector short __a, vector short __b) { return __builtin_altivec_vminsh(__a, __b); } static vector short __ATTRS_o_ai vec_vminsh(vector bool short __a, vector short __b) { return __builtin_altivec_vminsh((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_vminsh(vector short __a, vector bool short __b) { return __builtin_altivec_vminsh(__a, (vector short)__b); } /* vec_vminuh */ static vector unsigned short __ATTRS_o_ai vec_vminuh(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vminuh(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vminuh(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vminuh((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vminuh(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vminuh(__a, (vector unsigned short)__b); } /* vec_vminsw */ static vector int __ATTRS_o_ai vec_vminsw(vector int __a, vector int __b) { return __builtin_altivec_vminsw(__a, __b); } static vector int __ATTRS_o_ai vec_vminsw(vector bool int __a, vector int __b) { return __builtin_altivec_vminsw((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_vminsw(vector int __a, vector bool int __b) { return __builtin_altivec_vminsw(__a, (vector int)__b); } /* vec_vminuw */ static vector unsigned int __ATTRS_o_ai vec_vminuw(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vminuw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vminuw(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vminuw((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vminuw(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vminuw(__a, (vector unsigned int)__b); } /* vec_vminfp */ static vector float __attribute__((__always_inline__)) vec_vminfp(vector float __a, vector float __b) { #ifdef __VSX__ return __builtin_vsx_xvminsp(__a, __b); #else return __builtin_altivec_vminfp(__a, __b); #endif } /* vec_mladd */ #define __builtin_altivec_vmladduhm vec_mladd static vector short __ATTRS_o_ai vec_mladd(vector short __a, vector short __b, vector short __c) { return __a * __b + __c; } static vector short __ATTRS_o_ai vec_mladd(vector short __a, vector unsigned short __b, vector unsigned short __c) { return __a * (vector short)__b + (vector short)__c; } static vector short __ATTRS_o_ai vec_mladd(vector unsigned short __a, vector short __b, vector short __c) { return (vector short)__a * __b + __c; } static vector unsigned short __ATTRS_o_ai vec_mladd(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __a * __b + __c; } /* vec_vmladduhm */ static vector short __ATTRS_o_ai vec_vmladduhm(vector short __a, vector short __b, vector short __c) { return __a * __b + __c; } static vector short __ATTRS_o_ai vec_vmladduhm(vector short __a, vector unsigned short __b, vector unsigned short __c) { return __a * (vector short)__b + (vector short)__c; } static vector short __ATTRS_o_ai vec_vmladduhm(vector unsigned short __a, vector short __b, vector short __c) { return (vector short)__a * __b + __c; } static vector unsigned short __ATTRS_o_ai vec_vmladduhm(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __a * __b + __c; } /* vec_mradds */ static vector short __attribute__((__always_inline__)) vec_mradds(vector short __a, vector short __b, vector short __c) { return __builtin_altivec_vmhraddshs(__a, __b, __c); } /* vec_vmhraddshs */ static vector short __attribute__((__always_inline__)) vec_vmhraddshs(vector short __a, vector short __b, vector short __c) { return __builtin_altivec_vmhraddshs(__a, __b, __c); } /* vec_msum */ static vector int __ATTRS_o_ai vec_msum(vector signed char __a, vector unsigned char __b, vector int __c) { return __builtin_altivec_vmsummbm(__a, __b, __c); } static vector unsigned int __ATTRS_o_ai vec_msum(vector unsigned char __a, vector unsigned char __b, vector unsigned int __c) { return __builtin_altivec_vmsumubm(__a, __b, __c); } static vector int __ATTRS_o_ai vec_msum(vector short __a, vector short __b, vector int __c) { return __builtin_altivec_vmsumshm(__a, __b, __c); } static vector unsigned int __ATTRS_o_ai vec_msum(vector unsigned short __a, vector unsigned short __b, vector unsigned int __c) { return __builtin_altivec_vmsumuhm(__a, __b, __c); } /* vec_vmsummbm */ static vector int __attribute__((__always_inline__)) vec_vmsummbm(vector signed char __a, vector unsigned char __b, vector int __c) { return __builtin_altivec_vmsummbm(__a, __b, __c); } /* vec_vmsumubm */ static vector unsigned int __attribute__((__always_inline__)) vec_vmsumubm(vector unsigned char __a, vector unsigned char __b, vector unsigned int __c) { return __builtin_altivec_vmsumubm(__a, __b, __c); } /* vec_vmsumshm */ static vector int __attribute__((__always_inline__)) vec_vmsumshm(vector short __a, vector short __b, vector int __c) { return __builtin_altivec_vmsumshm(__a, __b, __c); } /* vec_vmsumuhm */ static vector unsigned int __attribute__((__always_inline__)) vec_vmsumuhm(vector unsigned short __a, vector unsigned short __b, vector unsigned int __c) { return __builtin_altivec_vmsumuhm(__a, __b, __c); } /* vec_msums */ static vector int __ATTRS_o_ai vec_msums(vector short __a, vector short __b, vector int __c) { return __builtin_altivec_vmsumshs(__a, __b, __c); } static vector unsigned int __ATTRS_o_ai vec_msums(vector unsigned short __a, vector unsigned short __b, vector unsigned int __c) { return __builtin_altivec_vmsumuhs(__a, __b, __c); } /* vec_vmsumshs */ static vector int __attribute__((__always_inline__)) vec_vmsumshs(vector short __a, vector short __b, vector int __c) { return __builtin_altivec_vmsumshs(__a, __b, __c); } /* vec_vmsumuhs */ static vector unsigned int __attribute__((__always_inline__)) vec_vmsumuhs(vector unsigned short __a, vector unsigned short __b, vector unsigned int __c) { return __builtin_altivec_vmsumuhs(__a, __b, __c); } /* vec_mtvscr */ static void __ATTRS_o_ai vec_mtvscr(vector signed char __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector unsigned char __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector bool char __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector short __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector unsigned short __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector bool short __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector pixel __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector int __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector unsigned int __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector bool int __a) { __builtin_altivec_mtvscr((vector int)__a); } static void __ATTRS_o_ai vec_mtvscr(vector float __a) { __builtin_altivec_mtvscr((vector int)__a); } /* vec_mul */ /* Integer vector multiplication will involve multiplication of the odd/even elements separately, then truncating the results and moving to the result vector. */ static vector signed char __ATTRS_o_ai vec_mul(vector signed char __a, vector signed char __b) { return __a * __b; } static vector unsigned char __ATTRS_o_ai vec_mul(vector unsigned char __a, vector unsigned char __b) { return __a * __b; } static vector signed short __ATTRS_o_ai vec_mul(vector signed short __a, vector signed short __b) { return __a * __b; } static vector unsigned short __ATTRS_o_ai vec_mul(vector unsigned short __a, vector unsigned short __b) { return __a * __b; } static vector signed int __ATTRS_o_ai vec_mul(vector signed int __a, vector signed int __b) { return __a * __b; } static vector unsigned int __ATTRS_o_ai vec_mul(vector unsigned int __a, vector unsigned int __b) { return __a * __b; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_mul(vector signed long long __a, vector signed long long __b) { return __a * __b; } static vector unsigned long long __ATTRS_o_ai vec_mul(vector unsigned long long __a, vector unsigned long long __b) { return __a * __b; } #endif static vector float __ATTRS_o_ai vec_mul(vector float __a, vector float __b) { return __a * __b; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_mul(vector double __a, vector double __b) { return __a * __b; } #endif /* The vmulos* and vmules* instructions have a big endian bias, so we must reverse the meaning of "even" and "odd" for little endian. */ /* vec_mule */ static vector short __ATTRS_o_ai vec_mule(vector signed char __a, vector signed char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulosb(__a, __b); #else return __builtin_altivec_vmulesb(__a, __b); #endif } static vector unsigned short __ATTRS_o_ai vec_mule(vector unsigned char __a, vector unsigned char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmuloub(__a, __b); #else return __builtin_altivec_vmuleub(__a, __b); #endif } static vector int __ATTRS_o_ai vec_mule(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulosh(__a, __b); #else return __builtin_altivec_vmulesh(__a, __b); #endif } static vector unsigned int __ATTRS_o_ai vec_mule(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulouh(__a, __b); #else return __builtin_altivec_vmuleuh(__a, __b); #endif } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_mule(vector signed int __a, vector signed int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulosw(__a, __b); #else return __builtin_altivec_vmulesw(__a, __b); #endif } static vector unsigned long long __ATTRS_o_ai vec_mule(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulouw(__a, __b); #else return __builtin_altivec_vmuleuw(__a, __b); #endif } #endif /* vec_vmulesb */ static vector short __attribute__((__always_inline__)) vec_vmulesb(vector signed char __a, vector signed char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulosb(__a, __b); #else return __builtin_altivec_vmulesb(__a, __b); #endif } /* vec_vmuleub */ static vector unsigned short __attribute__((__always_inline__)) vec_vmuleub(vector unsigned char __a, vector unsigned char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmuloub(__a, __b); #else return __builtin_altivec_vmuleub(__a, __b); #endif } /* vec_vmulesh */ static vector int __attribute__((__always_inline__)) vec_vmulesh(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulosh(__a, __b); #else return __builtin_altivec_vmulesh(__a, __b); #endif } /* vec_vmuleuh */ static vector unsigned int __attribute__((__always_inline__)) vec_vmuleuh(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulouh(__a, __b); #else return __builtin_altivec_vmuleuh(__a, __b); #endif } /* vec_mulo */ static vector short __ATTRS_o_ai vec_mulo(vector signed char __a, vector signed char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulesb(__a, __b); #else return __builtin_altivec_vmulosb(__a, __b); #endif } static vector unsigned short __ATTRS_o_ai vec_mulo(vector unsigned char __a, vector unsigned char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmuleub(__a, __b); #else return __builtin_altivec_vmuloub(__a, __b); #endif } static vector int __ATTRS_o_ai vec_mulo(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulesh(__a, __b); #else return __builtin_altivec_vmulosh(__a, __b); #endif } static vector unsigned int __ATTRS_o_ai vec_mulo(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmuleuh(__a, __b); #else return __builtin_altivec_vmulouh(__a, __b); #endif } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_mulo(vector signed int __a, vector signed int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulesw(__a, __b); #else return __builtin_altivec_vmulosw(__a, __b); #endif } static vector unsigned long long __ATTRS_o_ai vec_mulo(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmuleuw(__a, __b); #else return __builtin_altivec_vmulouw(__a, __b); #endif } #endif /* vec_vmulosb */ static vector short __attribute__((__always_inline__)) vec_vmulosb(vector signed char __a, vector signed char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulesb(__a, __b); #else return __builtin_altivec_vmulosb(__a, __b); #endif } /* vec_vmuloub */ static vector unsigned short __attribute__((__always_inline__)) vec_vmuloub(vector unsigned char __a, vector unsigned char __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmuleub(__a, __b); #else return __builtin_altivec_vmuloub(__a, __b); #endif } /* vec_vmulosh */ static vector int __attribute__((__always_inline__)) vec_vmulosh(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmulesh(__a, __b); #else return __builtin_altivec_vmulosh(__a, __b); #endif } /* vec_vmulouh */ static vector unsigned int __attribute__((__always_inline__)) vec_vmulouh(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vmuleuh(__a, __b); #else return __builtin_altivec_vmulouh(__a, __b); #endif } /* vec_nand */ #ifdef __POWER8_VECTOR__ static vector signed char __ATTRS_o_ai vec_nand(vector signed char __a, vector signed char __b) { return ~(__a & __b); } static vector signed char __ATTRS_o_ai vec_nand(vector signed char __a, vector bool char __b) { return ~(__a & __b); } static vector signed char __ATTRS_o_ai vec_nand(vector bool char __a, vector signed char __b) { return ~(__a & __b); } static vector unsigned char __ATTRS_o_ai vec_nand(vector unsigned char __a, vector unsigned char __b) { return ~(__a & __b); } static vector unsigned char __ATTRS_o_ai vec_nand(vector unsigned char __a, vector bool char __b) { return ~(__a & __b); } static vector unsigned char __ATTRS_o_ai vec_nand(vector bool char __a, vector unsigned char __b) { return ~(__a & __b); } static vector signed short __ATTRS_o_ai vec_nand(vector signed short __a, vector signed short __b) { return ~(__a & __b); } static vector signed short __ATTRS_o_ai vec_nand(vector signed short __a, vector bool short __b) { return ~(__a & __b); } static vector signed short __ATTRS_o_ai vec_nand(vector bool short __a, vector signed short __b) { return ~(__a & __b); } static vector unsigned short __ATTRS_o_ai vec_nand(vector unsigned short __a, vector unsigned short __b) { return ~(__a & __b); } static vector unsigned short __ATTRS_o_ai vec_nand(vector unsigned short __a, vector bool short __b) { return ~(__a & __b); } static vector unsigned short __ATTRS_o_ai vec_nand(vector bool short __a, vector unsigned short __b) { return ~(__a & __b); } static vector signed int __ATTRS_o_ai vec_nand(vector signed int __a, vector signed int __b) { return ~(__a & __b); } static vector signed int __ATTRS_o_ai vec_nand(vector signed int __a, vector bool int __b) { return ~(__a & __b); } static vector signed int __ATTRS_o_ai vec_nand(vector bool int __a, vector signed int __b) { return ~(__a & __b); } static vector unsigned int __ATTRS_o_ai vec_nand(vector unsigned int __a, vector unsigned int __b) { return ~(__a & __b); } static vector unsigned int __ATTRS_o_ai vec_nand(vector unsigned int __a, vector bool int __b) { return ~(__a & __b); } static vector unsigned int __ATTRS_o_ai vec_nand(vector bool int __a, vector unsigned int __b) { return ~(__a & __b); } static vector signed long long __ATTRS_o_ai vec_nand(vector signed long long __a, vector signed long long __b) { return ~(__a & __b); } static vector signed long long __ATTRS_o_ai vec_nand(vector signed long long __a, vector bool long long __b) { return ~(__a & __b); } static vector signed long long __ATTRS_o_ai vec_nand(vector bool long long __a, vector signed long long __b) { return ~(__a & __b); } static vector unsigned long long __ATTRS_o_ai vec_nand(vector unsigned long long __a, vector unsigned long long __b) { return ~(__a & __b); } static vector unsigned long long __ATTRS_o_ai vec_nand(vector unsigned long long __a, vector bool long long __b) { return ~(__a & __b); } static vector unsigned long long __ATTRS_o_ai vec_nand(vector bool long long __a, vector unsigned long long __b) { return ~(__a & __b); } #endif /* vec_nmadd */ #ifdef __VSX__ static vector float __ATTRS_o_ai vec_nmadd(vector float __a, vector float __b, vector float __c) { return __builtin_vsx_xvnmaddasp(__a, __b, __c); } static vector double __ATTRS_o_ai vec_nmadd(vector double __a, vector double __b, vector double __c) { return __builtin_vsx_xvnmaddadp(__a, __b, __c); } #endif /* vec_nmsub */ static vector float __ATTRS_o_ai vec_nmsub(vector float __a, vector float __b, vector float __c) { #ifdef __VSX__ return __builtin_vsx_xvnmsubasp(__a, __b, __c); #else return __builtin_altivec_vnmsubfp(__a, __b, __c); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_nmsub(vector double __a, vector double __b, vector double __c) { return __builtin_vsx_xvnmsubadp(__a, __b, __c); } #endif /* vec_vnmsubfp */ static vector float __attribute__((__always_inline__)) vec_vnmsubfp(vector float __a, vector float __b, vector float __c) { return __builtin_altivec_vnmsubfp(__a, __b, __c); } /* vec_nor */ #define __builtin_altivec_vnor vec_nor static vector signed char __ATTRS_o_ai vec_nor(vector signed char __a, vector signed char __b) { return ~(__a | __b); } static vector unsigned char __ATTRS_o_ai vec_nor(vector unsigned char __a, vector unsigned char __b) { return ~(__a | __b); } static vector bool char __ATTRS_o_ai vec_nor(vector bool char __a, vector bool char __b) { return ~(__a | __b); } static vector short __ATTRS_o_ai vec_nor(vector short __a, vector short __b) { return ~(__a | __b); } static vector unsigned short __ATTRS_o_ai vec_nor(vector unsigned short __a, vector unsigned short __b) { return ~(__a | __b); } static vector bool short __ATTRS_o_ai vec_nor(vector bool short __a, vector bool short __b) { return ~(__a | __b); } static vector int __ATTRS_o_ai vec_nor(vector int __a, vector int __b) { return ~(__a | __b); } static vector unsigned int __ATTRS_o_ai vec_nor(vector unsigned int __a, vector unsigned int __b) { return ~(__a | __b); } static vector bool int __ATTRS_o_ai vec_nor(vector bool int __a, vector bool int __b) { return ~(__a | __b); } static vector float __ATTRS_o_ai vec_nor(vector float __a, vector float __b) { vector unsigned int __res = ~((vector unsigned int)__a | (vector unsigned int)__b); return (vector float)__res; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_nor(vector double __a, vector double __b) { vector unsigned long long __res = ~((vector unsigned long long)__a | (vector unsigned long long)__b); return (vector double)__res; } #endif /* vec_vnor */ static vector signed char __ATTRS_o_ai vec_vnor(vector signed char __a, vector signed char __b) { return ~(__a | __b); } static vector unsigned char __ATTRS_o_ai vec_vnor(vector unsigned char __a, vector unsigned char __b) { return ~(__a | __b); } static vector bool char __ATTRS_o_ai vec_vnor(vector bool char __a, vector bool char __b) { return ~(__a | __b); } static vector short __ATTRS_o_ai vec_vnor(vector short __a, vector short __b) { return ~(__a | __b); } static vector unsigned short __ATTRS_o_ai vec_vnor(vector unsigned short __a, vector unsigned short __b) { return ~(__a | __b); } static vector bool short __ATTRS_o_ai vec_vnor(vector bool short __a, vector bool short __b) { return ~(__a | __b); } static vector int __ATTRS_o_ai vec_vnor(vector int __a, vector int __b) { return ~(__a | __b); } static vector unsigned int __ATTRS_o_ai vec_vnor(vector unsigned int __a, vector unsigned int __b) { return ~(__a | __b); } static vector bool int __ATTRS_o_ai vec_vnor(vector bool int __a, vector bool int __b) { return ~(__a | __b); } static vector float __ATTRS_o_ai vec_vnor(vector float __a, vector float __b) { vector unsigned int __res = ~((vector unsigned int)__a | (vector unsigned int)__b); return (vector float)__res; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_nor(vector signed long long __a, vector signed long long __b) { return ~(__a | __b); } static vector unsigned long long __ATTRS_o_ai vec_nor(vector unsigned long long __a, vector unsigned long long __b) { return ~(__a | __b); } static vector bool long long __ATTRS_o_ai vec_nor(vector bool long long __a, vector bool long long __b) { return ~(__a | __b); } #endif /* vec_or */ #define __builtin_altivec_vor vec_or static vector signed char __ATTRS_o_ai vec_or(vector signed char __a, vector signed char __b) { return __a | __b; } static vector signed char __ATTRS_o_ai vec_or(vector bool char __a, vector signed char __b) { return (vector signed char)__a | __b; } static vector signed char __ATTRS_o_ai vec_or(vector signed char __a, vector bool char __b) { return __a | (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_or(vector unsigned char __a, vector unsigned char __b) { return __a | __b; } static vector unsigned char __ATTRS_o_ai vec_or(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a | __b; } static vector unsigned char __ATTRS_o_ai vec_or(vector unsigned char __a, vector bool char __b) { return __a | (vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_or(vector bool char __a, vector bool char __b) { return __a | __b; } static vector short __ATTRS_o_ai vec_or(vector short __a, vector short __b) { return __a | __b; } static vector short __ATTRS_o_ai vec_or(vector bool short __a, vector short __b) { return (vector short)__a | __b; } static vector short __ATTRS_o_ai vec_or(vector short __a, vector bool short __b) { return __a | (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_or(vector unsigned short __a, vector unsigned short __b) { return __a | __b; } static vector unsigned short __ATTRS_o_ai vec_or(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a | __b; } static vector unsigned short __ATTRS_o_ai vec_or(vector unsigned short __a, vector bool short __b) { return __a | (vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_or(vector bool short __a, vector bool short __b) { return __a | __b; } static vector int __ATTRS_o_ai vec_or(vector int __a, vector int __b) { return __a | __b; } static vector int __ATTRS_o_ai vec_or(vector bool int __a, vector int __b) { return (vector int)__a | __b; } static vector int __ATTRS_o_ai vec_or(vector int __a, vector bool int __b) { return __a | (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_or(vector unsigned int __a, vector unsigned int __b) { return __a | __b; } static vector unsigned int __ATTRS_o_ai vec_or(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a | __b; } static vector unsigned int __ATTRS_o_ai vec_or(vector unsigned int __a, vector bool int __b) { return __a | (vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_or(vector bool int __a, vector bool int __b) { return __a | __b; } static vector float __ATTRS_o_ai vec_or(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a | (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_or(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a | (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_or(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a | (vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_or(vector bool long long __a, vector double __b) { return (vector unsigned long long)__a | (vector unsigned long long)__b; } static vector double __ATTRS_o_ai vec_or(vector double __a, vector bool long long __b) { return (vector unsigned long long)__a | (vector unsigned long long)__b; } static vector double __ATTRS_o_ai vec_or(vector double __a, vector double __b) { vector unsigned long long __res = (vector unsigned long long)__a | (vector unsigned long long)__b; return (vector double)__res; } static vector signed long long __ATTRS_o_ai vec_or(vector signed long long __a, vector signed long long __b) { return __a | __b; } static vector signed long long __ATTRS_o_ai vec_or(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a | __b; } static vector signed long long __ATTRS_o_ai vec_or(vector signed long long __a, vector bool long long __b) { return __a | (vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_or(vector unsigned long long __a, vector unsigned long long __b) { return __a | __b; } static vector unsigned long long __ATTRS_o_ai vec_or(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a | __b; } static vector unsigned long long __ATTRS_o_ai vec_or(vector unsigned long long __a, vector bool long long __b) { return __a | (vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_or(vector bool long long __a, vector bool long long __b) { return __a | __b; } #endif #ifdef __POWER8_VECTOR__ static vector signed char __ATTRS_o_ai vec_orc(vector signed char __a, vector signed char __b) { return __a | ~__b; } static vector signed char __ATTRS_o_ai vec_orc(vector signed char __a, vector bool char __b) { return __a | ~__b; } static vector signed char __ATTRS_o_ai vec_orc(vector bool char __a, vector signed char __b) { return __a | ~__b; } static vector unsigned char __ATTRS_o_ai vec_orc(vector unsigned char __a, vector unsigned char __b) { return __a | ~__b; } static vector unsigned char __ATTRS_o_ai vec_orc(vector unsigned char __a, vector bool char __b) { return __a | ~__b; } static vector unsigned char __ATTRS_o_ai vec_orc(vector bool char __a, vector unsigned char __b) { return __a | ~__b; } static vector signed short __ATTRS_o_ai vec_orc(vector signed short __a, vector signed short __b) { return __a | ~__b; } static vector signed short __ATTRS_o_ai vec_orc(vector signed short __a, vector bool short __b) { return __a | ~__b; } static vector signed short __ATTRS_o_ai vec_orc(vector bool short __a, vector signed short __b) { return __a | ~__b; } static vector unsigned short __ATTRS_o_ai vec_orc(vector unsigned short __a, vector unsigned short __b) { return __a | ~__b; } static vector unsigned short __ATTRS_o_ai vec_orc(vector unsigned short __a, vector bool short __b) { return __a | ~__b; } static vector unsigned short __ATTRS_o_ai vec_orc(vector bool short __a, vector unsigned short __b) { return __a | ~__b; } static vector signed int __ATTRS_o_ai vec_orc(vector signed int __a, vector signed int __b) { return __a | ~__b; } static vector signed int __ATTRS_o_ai vec_orc(vector signed int __a, vector bool int __b) { return __a | ~__b; } static vector signed int __ATTRS_o_ai vec_orc(vector bool int __a, vector signed int __b) { return __a | ~__b; } static vector unsigned int __ATTRS_o_ai vec_orc(vector unsigned int __a, vector unsigned int __b) { return __a | ~__b; } static vector unsigned int __ATTRS_o_ai vec_orc(vector unsigned int __a, vector bool int __b) { return __a | ~__b; } static vector unsigned int __ATTRS_o_ai vec_orc(vector bool int __a, vector unsigned int __b) { return __a | ~__b; } static vector signed long long __ATTRS_o_ai vec_orc(vector signed long long __a, vector signed long long __b) { return __a | ~__b; } static vector signed long long __ATTRS_o_ai vec_orc(vector signed long long __a, vector bool long long __b) { return __a | ~__b; } static vector signed long long __ATTRS_o_ai vec_orc(vector bool long long __a, vector signed long long __b) { return __a | ~__b; } static vector unsigned long long __ATTRS_o_ai vec_orc(vector unsigned long long __a, vector unsigned long long __b) { return __a | ~__b; } static vector unsigned long long __ATTRS_o_ai vec_orc(vector unsigned long long __a, vector bool long long __b) { return __a | ~__b; } static vector unsigned long long __ATTRS_o_ai vec_orc(vector bool long long __a, vector unsigned long long __b) { return __a | ~__b; } #endif /* vec_vor */ static vector signed char __ATTRS_o_ai vec_vor(vector signed char __a, vector signed char __b) { return __a | __b; } static vector signed char __ATTRS_o_ai vec_vor(vector bool char __a, vector signed char __b) { return (vector signed char)__a | __b; } static vector signed char __ATTRS_o_ai vec_vor(vector signed char __a, vector bool char __b) { return __a | (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_vor(vector unsigned char __a, vector unsigned char __b) { return __a | __b; } static vector unsigned char __ATTRS_o_ai vec_vor(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a | __b; } static vector unsigned char __ATTRS_o_ai vec_vor(vector unsigned char __a, vector bool char __b) { return __a | (vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_vor(vector bool char __a, vector bool char __b) { return __a | __b; } static vector short __ATTRS_o_ai vec_vor(vector short __a, vector short __b) { return __a | __b; } static vector short __ATTRS_o_ai vec_vor(vector bool short __a, vector short __b) { return (vector short)__a | __b; } static vector short __ATTRS_o_ai vec_vor(vector short __a, vector bool short __b) { return __a | (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_vor(vector unsigned short __a, vector unsigned short __b) { return __a | __b; } static vector unsigned short __ATTRS_o_ai vec_vor(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a | __b; } static vector unsigned short __ATTRS_o_ai vec_vor(vector unsigned short __a, vector bool short __b) { return __a | (vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_vor(vector bool short __a, vector bool short __b) { return __a | __b; } static vector int __ATTRS_o_ai vec_vor(vector int __a, vector int __b) { return __a | __b; } static vector int __ATTRS_o_ai vec_vor(vector bool int __a, vector int __b) { return (vector int)__a | __b; } static vector int __ATTRS_o_ai vec_vor(vector int __a, vector bool int __b) { return __a | (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_vor(vector unsigned int __a, vector unsigned int __b) { return __a | __b; } static vector unsigned int __ATTRS_o_ai vec_vor(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a | __b; } static vector unsigned int __ATTRS_o_ai vec_vor(vector unsigned int __a, vector bool int __b) { return __a | (vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_vor(vector bool int __a, vector bool int __b) { return __a | __b; } static vector float __ATTRS_o_ai vec_vor(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a | (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vor(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a | (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vor(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a | (vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_vor(vector signed long long __a, vector signed long long __b) { return __a | __b; } static vector signed long long __ATTRS_o_ai vec_vor(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a | __b; } static vector signed long long __ATTRS_o_ai vec_vor(vector signed long long __a, vector bool long long __b) { return __a | (vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_vor(vector unsigned long long __a, vector unsigned long long __b) { return __a | __b; } static vector unsigned long long __ATTRS_o_ai vec_vor(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a | __b; } static vector unsigned long long __ATTRS_o_ai vec_vor(vector unsigned long long __a, vector bool long long __b) { return __a | (vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_vor(vector bool long long __a, vector bool long long __b) { return __a | __b; } #endif /* vec_pack */ /* The various vector pack instructions have a big-endian bias, so for little endian we must handle reversed element numbering. */ static vector signed char __ATTRS_o_ai vec_pack(vector signed short __a, vector signed short __b) { #ifdef __LITTLE_ENDIAN__ return (vector signed char)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E)); #else return (vector signed char)vec_perm( __a, __b, (vector unsigned char)(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F)); #endif } static vector unsigned char __ATTRS_o_ai vec_pack(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned char)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E)); #else return (vector unsigned char)vec_perm( __a, __b, (vector unsigned char)(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F)); #endif } static vector bool char __ATTRS_o_ai vec_pack(vector bool short __a, vector bool short __b) { #ifdef __LITTLE_ENDIAN__ return (vector bool char)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E)); #else return (vector bool char)vec_perm( __a, __b, (vector unsigned char)(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F)); #endif } static vector short __ATTRS_o_ai vec_pack(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ return (vector short)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x18, 0x19, 0x1C, 0x1D)); #else return (vector short)vec_perm( __a, __b, (vector unsigned char)(0x02, 0x03, 0x06, 0x07, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16, 0x17, 0x1A, 0x1B, 0x1E, 0x1F)); #endif } static vector unsigned short __ATTRS_o_ai vec_pack(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned short)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x18, 0x19, 0x1C, 0x1D)); #else return (vector unsigned short)vec_perm( __a, __b, (vector unsigned char)(0x02, 0x03, 0x06, 0x07, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16, 0x17, 0x1A, 0x1B, 0x1E, 0x1F)); #endif } static vector bool short __ATTRS_o_ai vec_pack(vector bool int __a, vector bool int __b) { #ifdef __LITTLE_ENDIAN__ return (vector bool short)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x18, 0x19, 0x1C, 0x1D)); #else return (vector bool short)vec_perm( __a, __b, (vector unsigned char)(0x02, 0x03, 0x06, 0x07, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16, 0x17, 0x1A, 0x1B, 0x1E, 0x1F)); #endif } #ifdef __VSX__ static vector signed int __ATTRS_o_ai vec_pack(vector signed long long __a, vector signed long long __b) { #ifdef __LITTLE_ENDIAN__ return (vector signed int)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B)); #else return (vector signed int)vec_perm( __a, __b, (vector unsigned char)(0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F)); #endif } static vector unsigned int __ATTRS_o_ai vec_pack(vector unsigned long long __a, vector unsigned long long __b) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned int)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B)); #else return (vector unsigned int)vec_perm( __a, __b, (vector unsigned char)(0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F)); #endif } static vector bool int __ATTRS_o_ai vec_pack(vector bool long long __a, vector bool long long __b) { #ifdef __LITTLE_ENDIAN__ return (vector bool int)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B)); #else return (vector bool int)vec_perm( __a, __b, (vector unsigned char)(0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F)); #endif } #endif /* vec_vpkuhum */ #define __builtin_altivec_vpkuhum vec_vpkuhum static vector signed char __ATTRS_o_ai vec_vpkuhum(vector signed short __a, vector signed short __b) { #ifdef __LITTLE_ENDIAN__ return (vector signed char)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E)); #else return (vector signed char)vec_perm( __a, __b, (vector unsigned char)(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F)); #endif } static vector unsigned char __ATTRS_o_ai vec_vpkuhum(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned char)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E)); #else return (vector unsigned char)vec_perm( __a, __b, (vector unsigned char)(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F)); #endif } static vector bool char __ATTRS_o_ai vec_vpkuhum(vector bool short __a, vector bool short __b) { #ifdef __LITTLE_ENDIAN__ return (vector bool char)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E)); #else return (vector bool char)vec_perm( __a, __b, (vector unsigned char)(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F)); #endif } /* vec_vpkuwum */ #define __builtin_altivec_vpkuwum vec_vpkuwum static vector short __ATTRS_o_ai vec_vpkuwum(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ return (vector short)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x18, 0x19, 0x1C, 0x1D)); #else return (vector short)vec_perm( __a, __b, (vector unsigned char)(0x02, 0x03, 0x06, 0x07, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16, 0x17, 0x1A, 0x1B, 0x1E, 0x1F)); #endif } static vector unsigned short __ATTRS_o_ai vec_vpkuwum(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned short)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x18, 0x19, 0x1C, 0x1D)); #else return (vector unsigned short)vec_perm( __a, __b, (vector unsigned char)(0x02, 0x03, 0x06, 0x07, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16, 0x17, 0x1A, 0x1B, 0x1E, 0x1F)); #endif } static vector bool short __ATTRS_o_ai vec_vpkuwum(vector bool int __a, vector bool int __b) { #ifdef __LITTLE_ENDIAN__ return (vector bool short)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x18, 0x19, 0x1C, 0x1D)); #else return (vector bool short)vec_perm( __a, __b, (vector unsigned char)(0x02, 0x03, 0x06, 0x07, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16, 0x17, 0x1A, 0x1B, 0x1E, 0x1F)); #endif } /* vec_vpkudum */ #ifdef __POWER8_VECTOR__ #define __builtin_altivec_vpkudum vec_vpkudum static vector int __ATTRS_o_ai vec_vpkudum(vector long long __a, vector long long __b) { #ifdef __LITTLE_ENDIAN__ return (vector int)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B)); #else return (vector int)vec_perm( __a, __b, (vector unsigned char)(0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F)); #endif } static vector unsigned int __ATTRS_o_ai vec_vpkudum(vector unsigned long long __a, vector unsigned long long __b) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned int)vec_perm( __a, __b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B)); #else return (vector unsigned int)vec_perm( __a, __b, (vector unsigned char)(0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F)); #endif } static vector bool int __ATTRS_o_ai vec_vpkudum(vector bool long long __a, vector bool long long __b) { #ifdef __LITTLE_ENDIAN__ return (vector bool int)vec_perm( (vector long long)__a, (vector long long)__b, (vector unsigned char)(0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B)); #else return (vector bool int)vec_perm( (vector long long)__a, (vector long long)__b, (vector unsigned char)(0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F)); #endif } #endif /* vec_packpx */ static vector pixel __attribute__((__always_inline__)) vec_packpx(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return (vector pixel)__builtin_altivec_vpkpx(__b, __a); #else return (vector pixel)__builtin_altivec_vpkpx(__a, __b); #endif } /* vec_vpkpx */ static vector pixel __attribute__((__always_inline__)) vec_vpkpx(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return (vector pixel)__builtin_altivec_vpkpx(__b, __a); #else return (vector pixel)__builtin_altivec_vpkpx(__a, __b); #endif } /* vec_packs */ static vector signed char __ATTRS_o_ai vec_packs(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkshss(__b, __a); #else return __builtin_altivec_vpkshss(__a, __b); #endif } static vector unsigned char __ATTRS_o_ai vec_packs(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuhus(__b, __a); #else return __builtin_altivec_vpkuhus(__a, __b); #endif } static vector signed short __ATTRS_o_ai vec_packs(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkswss(__b, __a); #else return __builtin_altivec_vpkswss(__a, __b); #endif } static vector unsigned short __ATTRS_o_ai vec_packs(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuwus(__b, __a); #else return __builtin_altivec_vpkuwus(__a, __b); #endif } #ifdef __POWER8_VECTOR__ static vector int __ATTRS_o_ai vec_packs(vector long long __a, vector long long __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpksdss(__b, __a); #else return __builtin_altivec_vpksdss(__a, __b); #endif } static vector unsigned int __ATTRS_o_ai vec_packs(vector unsigned long long __a, vector unsigned long long __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkudus(__b, __a); #else return __builtin_altivec_vpkudus(__a, __b); #endif } #endif /* vec_vpkshss */ static vector signed char __attribute__((__always_inline__)) vec_vpkshss(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkshss(__b, __a); #else return __builtin_altivec_vpkshss(__a, __b); #endif } /* vec_vpksdss */ #ifdef __POWER8_VECTOR__ static vector int __ATTRS_o_ai vec_vpksdss(vector long long __a, vector long long __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpksdss(__b, __a); #else return __builtin_altivec_vpksdss(__a, __b); #endif } #endif /* vec_vpkuhus */ static vector unsigned char __attribute__((__always_inline__)) vec_vpkuhus(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuhus(__b, __a); #else return __builtin_altivec_vpkuhus(__a, __b); #endif } /* vec_vpkudus */ #ifdef __POWER8_VECTOR__ static vector unsigned int __attribute__((__always_inline__)) vec_vpkudus(vector unsigned long long __a, vector unsigned long long __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkudus(__b, __a); #else return __builtin_altivec_vpkudus(__a, __b); #endif } #endif /* vec_vpkswss */ static vector signed short __attribute__((__always_inline__)) vec_vpkswss(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkswss(__b, __a); #else return __builtin_altivec_vpkswss(__a, __b); #endif } /* vec_vpkuwus */ static vector unsigned short __attribute__((__always_inline__)) vec_vpkuwus(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuwus(__b, __a); #else return __builtin_altivec_vpkuwus(__a, __b); #endif } /* vec_packsu */ static vector unsigned char __ATTRS_o_ai vec_packsu(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkshus(__b, __a); #else return __builtin_altivec_vpkshus(__a, __b); #endif } static vector unsigned char __ATTRS_o_ai vec_packsu(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuhus(__b, __a); #else return __builtin_altivec_vpkuhus(__a, __b); #endif } static vector unsigned short __ATTRS_o_ai vec_packsu(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkswus(__b, __a); #else return __builtin_altivec_vpkswus(__a, __b); #endif } static vector unsigned short __ATTRS_o_ai vec_packsu(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuwus(__b, __a); #else return __builtin_altivec_vpkuwus(__a, __b); #endif } #ifdef __POWER8_VECTOR__ static vector unsigned int __ATTRS_o_ai vec_packsu(vector long long __a, vector long long __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpksdus(__b, __a); #else return __builtin_altivec_vpksdus(__a, __b); #endif } static vector unsigned int __ATTRS_o_ai vec_packsu(vector unsigned long long __a, vector unsigned long long __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkudus(__b, __a); #else return __builtin_altivec_vpkudus(__a, __b); #endif } #endif /* vec_vpkshus */ static vector unsigned char __ATTRS_o_ai vec_vpkshus(vector short __a, vector short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkshus(__b, __a); #else return __builtin_altivec_vpkshus(__a, __b); #endif } static vector unsigned char __ATTRS_o_ai vec_vpkshus(vector unsigned short __a, vector unsigned short __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuhus(__b, __a); #else return __builtin_altivec_vpkuhus(__a, __b); #endif } /* vec_vpkswus */ static vector unsigned short __ATTRS_o_ai vec_vpkswus(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkswus(__b, __a); #else return __builtin_altivec_vpkswus(__a, __b); #endif } static vector unsigned short __ATTRS_o_ai vec_vpkswus(vector unsigned int __a, vector unsigned int __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpkuwus(__b, __a); #else return __builtin_altivec_vpkuwus(__a, __b); #endif } /* vec_vpksdus */ #ifdef __POWER8_VECTOR__ static vector unsigned int __ATTRS_o_ai vec_vpksdus(vector long long __a, vector long long __b) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vpksdus(__b, __a); #else return __builtin_altivec_vpksdus(__a, __b); #endif } #endif /* vec_perm */ // The vperm instruction is defined architecturally with a big-endian bias. // For little endian, we swap the input operands and invert the permute // control vector. Only the rightmost 5 bits matter, so we could use // a vector of all 31s instead of all 255s to perform the inversion. // However, when the PCV is not a constant, using 255 has an advantage // in that the vec_xor can be recognized as a vec_nor (and for P8 and // later, possibly a vec_nand). static vector signed char __ATTRS_o_ai vec_perm(vector signed char __a, vector signed char __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector signed char)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector signed char)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } static vector unsigned char __ATTRS_o_ai vec_perm(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector unsigned char)__builtin_altivec_vperm_4si( (vector int)__b, (vector int)__a, __d); #else return (vector unsigned char)__builtin_altivec_vperm_4si( (vector int)__a, (vector int)__b, __c); #endif } static vector bool char __ATTRS_o_ai vec_perm(vector bool char __a, vector bool char __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector bool char)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector bool char)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } static vector short __ATTRS_o_ai vec_perm(vector signed short __a, vector signed short __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector signed short)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector signed short)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } static vector unsigned short __ATTRS_o_ai vec_perm(vector unsigned short __a, vector unsigned short __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector unsigned short)__builtin_altivec_vperm_4si( (vector int)__b, (vector int)__a, __d); #else return (vector unsigned short)__builtin_altivec_vperm_4si( (vector int)__a, (vector int)__b, __c); #endif } static vector bool short __ATTRS_o_ai vec_perm(vector bool short __a, vector bool short __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector bool short)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector bool short)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } static vector pixel __ATTRS_o_ai vec_perm(vector pixel __a, vector pixel __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector pixel)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector pixel)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } static vector int __ATTRS_o_ai vec_perm(vector signed int __a, vector signed int __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector signed int)__builtin_altivec_vperm_4si(__b, __a, __d); #else return (vector signed int)__builtin_altivec_vperm_4si(__a, __b, __c); #endif } static vector unsigned int __ATTRS_o_ai vec_perm(vector unsigned int __a, vector unsigned int __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector unsigned int)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector unsigned int)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } static vector bool int __ATTRS_o_ai vec_perm(vector bool int __a, vector bool int __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector bool int)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector bool int)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } static vector float __ATTRS_o_ai vec_perm(vector float __a, vector float __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector float)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector float)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } #ifdef __VSX__ static vector long long __ATTRS_o_ai vec_perm(vector signed long long __a, vector signed long long __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector signed long long)__builtin_altivec_vperm_4si( (vector int)__b, (vector int)__a, __d); #else return (vector signed long long)__builtin_altivec_vperm_4si( (vector int)__a, (vector int)__b, __c); #endif } static vector unsigned long long __ATTRS_o_ai vec_perm(vector unsigned long long __a, vector unsigned long long __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector unsigned long long)__builtin_altivec_vperm_4si( (vector int)__b, (vector int)__a, __d); #else return (vector unsigned long long)__builtin_altivec_vperm_4si( (vector int)__a, (vector int)__b, __c); #endif } static vector bool long long __ATTRS_o_ai vec_perm(vector bool long long __a, vector bool long long __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector bool long long)__builtin_altivec_vperm_4si( (vector int)__b, (vector int)__a, __d); #else return (vector bool long long)__builtin_altivec_vperm_4si( (vector int)__a, (vector int)__b, __c); #endif } static vector double __ATTRS_o_ai vec_perm(vector double __a, vector double __b, vector unsigned char __c) { #ifdef __LITTLE_ENDIAN__ vector unsigned char __d = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; __d = vec_xor(__c, __d); return (vector double)__builtin_altivec_vperm_4si((vector int)__b, (vector int)__a, __d); #else return (vector double)__builtin_altivec_vperm_4si((vector int)__a, (vector int)__b, __c); #endif } #endif /* vec_vperm */ static vector signed char __ATTRS_o_ai vec_vperm(vector signed char __a, vector signed char __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector unsigned char __ATTRS_o_ai vec_vperm(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector bool char __ATTRS_o_ai vec_vperm(vector bool char __a, vector bool char __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector short __ATTRS_o_ai vec_vperm(vector short __a, vector short __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector unsigned short __ATTRS_o_ai vec_vperm(vector unsigned short __a, vector unsigned short __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector bool short __ATTRS_o_ai vec_vperm(vector bool short __a, vector bool short __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector pixel __ATTRS_o_ai vec_vperm(vector pixel __a, vector pixel __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector int __ATTRS_o_ai vec_vperm(vector int __a, vector int __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector unsigned int __ATTRS_o_ai vec_vperm(vector unsigned int __a, vector unsigned int __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector bool int __ATTRS_o_ai vec_vperm(vector bool int __a, vector bool int __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector float __ATTRS_o_ai vec_vperm(vector float __a, vector float __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } #ifdef __VSX__ static vector long long __ATTRS_o_ai vec_vperm(vector long long __a, vector long long __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector unsigned long long __ATTRS_o_ai vec_vperm(vector unsigned long long __a, vector unsigned long long __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } static vector double __ATTRS_o_ai vec_vperm(vector double __a, vector double __b, vector unsigned char __c) { return vec_perm(__a, __b, __c); } #endif /* vec_re */ static vector float __ATTRS_o_ai vec_re(vector float __a) { #ifdef __VSX__ return __builtin_vsx_xvresp(__a); #else return __builtin_altivec_vrefp(__a); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_re(vector double __a) { return __builtin_vsx_xvredp(__a); } #endif /* vec_vrefp */ static vector float __attribute__((__always_inline__)) vec_vrefp(vector float __a) { return __builtin_altivec_vrefp(__a); } /* vec_rl */ static vector signed char __ATTRS_o_ai vec_rl(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vrlb((vector char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_rl(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vrlb((vector char)__a, __b); } static vector short __ATTRS_o_ai vec_rl(vector short __a, vector unsigned short __b) { return __builtin_altivec_vrlh(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_rl(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vrlh((vector short)__a, __b); } static vector int __ATTRS_o_ai vec_rl(vector int __a, vector unsigned int __b) { return __builtin_altivec_vrlw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_rl(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vrlw((vector int)__a, __b); } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_rl(vector signed long long __a, vector unsigned long long __b) { return __builtin_altivec_vrld(__a, __b); } static vector unsigned long long __ATTRS_o_ai vec_rl(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vrld(__a, __b); } #endif /* vec_vrlb */ static vector signed char __ATTRS_o_ai vec_vrlb(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vrlb((vector char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vrlb(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vrlb((vector char)__a, __b); } /* vec_vrlh */ static vector short __ATTRS_o_ai vec_vrlh(vector short __a, vector unsigned short __b) { return __builtin_altivec_vrlh(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vrlh(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vrlh((vector short)__a, __b); } /* vec_vrlw */ static vector int __ATTRS_o_ai vec_vrlw(vector int __a, vector unsigned int __b) { return __builtin_altivec_vrlw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vrlw(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vrlw((vector int)__a, __b); } /* vec_round */ static vector float __ATTRS_o_ai vec_round(vector float __a) { #ifdef __VSX__ return __builtin_vsx_xvrspi(__a); #else return __builtin_altivec_vrfin(__a); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_round(vector double __a) { return __builtin_vsx_xvrdpi(__a); } /* vec_rint */ static vector float __ATTRS_o_ai vec_rint(vector float __a) { return __builtin_vsx_xvrspic(__a); } static vector double __ATTRS_o_ai vec_rint(vector double __a) { return __builtin_vsx_xvrdpic(__a); } /* vec_nearbyint */ static vector float __ATTRS_o_ai vec_nearbyint(vector float __a) { return __builtin_vsx_xvrspi(__a); } static vector double __ATTRS_o_ai vec_nearbyint(vector double __a) { return __builtin_vsx_xvrdpi(__a); } #endif /* vec_vrfin */ static vector float __attribute__((__always_inline__)) vec_vrfin(vector float __a) { return __builtin_altivec_vrfin(__a); } /* vec_sqrt */ #ifdef __VSX__ static vector float __ATTRS_o_ai vec_sqrt(vector float __a) { return __builtin_vsx_xvsqrtsp(__a); } static vector double __ATTRS_o_ai vec_sqrt(vector double __a) { return __builtin_vsx_xvsqrtdp(__a); } #endif /* vec_rsqrte */ static vector float __ATTRS_o_ai vec_rsqrte(vector float __a) { #ifdef __VSX__ return __builtin_vsx_xvrsqrtesp(__a); #else return __builtin_altivec_vrsqrtefp(__a); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_rsqrte(vector double __a) { return __builtin_vsx_xvrsqrtedp(__a); } #endif /* vec_vrsqrtefp */ static __vector float __attribute__((__always_inline__)) vec_vrsqrtefp(vector float __a) { return __builtin_altivec_vrsqrtefp(__a); } /* vec_sel */ #define __builtin_altivec_vsel_4si vec_sel static vector signed char __ATTRS_o_ai vec_sel(vector signed char __a, vector signed char __b, vector unsigned char __c) { return (__a & ~(vector signed char)__c) | (__b & (vector signed char)__c); } static vector signed char __ATTRS_o_ai vec_sel(vector signed char __a, vector signed char __b, vector bool char __c) { return (__a & ~(vector signed char)__c) | (__b & (vector signed char)__c); } static vector unsigned char __ATTRS_o_ai vec_sel(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return (__a & ~__c) | (__b & __c); } static vector unsigned char __ATTRS_o_ai vec_sel(vector unsigned char __a, vector unsigned char __b, vector bool char __c) { return (__a & ~(vector unsigned char)__c) | (__b & (vector unsigned char)__c); } static vector bool char __ATTRS_o_ai vec_sel(vector bool char __a, vector bool char __b, vector unsigned char __c) { return (__a & ~(vector bool char)__c) | (__b & (vector bool char)__c); } static vector bool char __ATTRS_o_ai vec_sel(vector bool char __a, vector bool char __b, vector bool char __c) { return (__a & ~__c) | (__b & __c); } static vector short __ATTRS_o_ai vec_sel(vector short __a, vector short __b, vector unsigned short __c) { return (__a & ~(vector short)__c) | (__b & (vector short)__c); } static vector short __ATTRS_o_ai vec_sel(vector short __a, vector short __b, vector bool short __c) { return (__a & ~(vector short)__c) | (__b & (vector short)__c); } static vector unsigned short __ATTRS_o_ai vec_sel(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return (__a & ~__c) | (__b & __c); } static vector unsigned short __ATTRS_o_ai vec_sel(vector unsigned short __a, vector unsigned short __b, vector bool short __c) { return (__a & ~(vector unsigned short)__c) | (__b & (vector unsigned short)__c); } static vector bool short __ATTRS_o_ai vec_sel(vector bool short __a, vector bool short __b, vector unsigned short __c) { return (__a & ~(vector bool short)__c) | (__b & (vector bool short)__c); } static vector bool short __ATTRS_o_ai vec_sel(vector bool short __a, vector bool short __b, vector bool short __c) { return (__a & ~__c) | (__b & __c); } static vector int __ATTRS_o_ai vec_sel(vector int __a, vector int __b, vector unsigned int __c) { return (__a & ~(vector int)__c) | (__b & (vector int)__c); } static vector int __ATTRS_o_ai vec_sel(vector int __a, vector int __b, vector bool int __c) { return (__a & ~(vector int)__c) | (__b & (vector int)__c); } static vector unsigned int __ATTRS_o_ai vec_sel(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return (__a & ~__c) | (__b & __c); } static vector unsigned int __ATTRS_o_ai vec_sel(vector unsigned int __a, vector unsigned int __b, vector bool int __c) { return (__a & ~(vector unsigned int)__c) | (__b & (vector unsigned int)__c); } static vector bool int __ATTRS_o_ai vec_sel(vector bool int __a, vector bool int __b, vector unsigned int __c) { return (__a & ~(vector bool int)__c) | (__b & (vector bool int)__c); } static vector bool int __ATTRS_o_ai vec_sel(vector bool int __a, vector bool int __b, vector bool int __c) { return (__a & ~__c) | (__b & __c); } static vector float __ATTRS_o_ai vec_sel(vector float __a, vector float __b, vector unsigned int __c) { vector int __res = ((vector int)__a & ~(vector int)__c) | ((vector int)__b & (vector int)__c); return (vector float)__res; } static vector float __ATTRS_o_ai vec_sel(vector float __a, vector float __b, vector bool int __c) { vector int __res = ((vector int)__a & ~(vector int)__c) | ((vector int)__b & (vector int)__c); return (vector float)__res; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_sel(vector double __a, vector double __b, vector bool long long __c) { vector long long __res = ((vector long long)__a & ~(vector long long)__c) | ((vector long long)__b & (vector long long)__c); return (vector double)__res; } static vector double __ATTRS_o_ai vec_sel(vector double __a, vector double __b, vector unsigned long long __c) { vector long long __res = ((vector long long)__a & ~(vector long long)__c) | ((vector long long)__b & (vector long long)__c); return (vector double)__res; } #endif /* vec_vsel */ static vector signed char __ATTRS_o_ai vec_vsel(vector signed char __a, vector signed char __b, vector unsigned char __c) { return (__a & ~(vector signed char)__c) | (__b & (vector signed char)__c); } static vector signed char __ATTRS_o_ai vec_vsel(vector signed char __a, vector signed char __b, vector bool char __c) { return (__a & ~(vector signed char)__c) | (__b & (vector signed char)__c); } static vector unsigned char __ATTRS_o_ai vec_vsel(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return (__a & ~__c) | (__b & __c); } static vector unsigned char __ATTRS_o_ai vec_vsel(vector unsigned char __a, vector unsigned char __b, vector bool char __c) { return (__a & ~(vector unsigned char)__c) | (__b & (vector unsigned char)__c); } static vector bool char __ATTRS_o_ai vec_vsel(vector bool char __a, vector bool char __b, vector unsigned char __c) { return (__a & ~(vector bool char)__c) | (__b & (vector bool char)__c); } static vector bool char __ATTRS_o_ai vec_vsel(vector bool char __a, vector bool char __b, vector bool char __c) { return (__a & ~__c) | (__b & __c); } static vector short __ATTRS_o_ai vec_vsel(vector short __a, vector short __b, vector unsigned short __c) { return (__a & ~(vector short)__c) | (__b & (vector short)__c); } static vector short __ATTRS_o_ai vec_vsel(vector short __a, vector short __b, vector bool short __c) { return (__a & ~(vector short)__c) | (__b & (vector short)__c); } static vector unsigned short __ATTRS_o_ai vec_vsel(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return (__a & ~__c) | (__b & __c); } static vector unsigned short __ATTRS_o_ai vec_vsel(vector unsigned short __a, vector unsigned short __b, vector bool short __c) { return (__a & ~(vector unsigned short)__c) | (__b & (vector unsigned short)__c); } static vector bool short __ATTRS_o_ai vec_vsel(vector bool short __a, vector bool short __b, vector unsigned short __c) { return (__a & ~(vector bool short)__c) | (__b & (vector bool short)__c); } static vector bool short __ATTRS_o_ai vec_vsel(vector bool short __a, vector bool short __b, vector bool short __c) { return (__a & ~__c) | (__b & __c); } static vector int __ATTRS_o_ai vec_vsel(vector int __a, vector int __b, vector unsigned int __c) { return (__a & ~(vector int)__c) | (__b & (vector int)__c); } static vector int __ATTRS_o_ai vec_vsel(vector int __a, vector int __b, vector bool int __c) { return (__a & ~(vector int)__c) | (__b & (vector int)__c); } static vector unsigned int __ATTRS_o_ai vec_vsel(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return (__a & ~__c) | (__b & __c); } static vector unsigned int __ATTRS_o_ai vec_vsel(vector unsigned int __a, vector unsigned int __b, vector bool int __c) { return (__a & ~(vector unsigned int)__c) | (__b & (vector unsigned int)__c); } static vector bool int __ATTRS_o_ai vec_vsel(vector bool int __a, vector bool int __b, vector unsigned int __c) { return (__a & ~(vector bool int)__c) | (__b & (vector bool int)__c); } static vector bool int __ATTRS_o_ai vec_vsel(vector bool int __a, vector bool int __b, vector bool int __c) { return (__a & ~__c) | (__b & __c); } static vector float __ATTRS_o_ai vec_vsel(vector float __a, vector float __b, vector unsigned int __c) { vector int __res = ((vector int)__a & ~(vector int)__c) | ((vector int)__b & (vector int)__c); return (vector float)__res; } static vector float __ATTRS_o_ai vec_vsel(vector float __a, vector float __b, vector bool int __c) { vector int __res = ((vector int)__a & ~(vector int)__c) | ((vector int)__b & (vector int)__c); return (vector float)__res; } /* vec_sl */ static vector signed char __ATTRS_o_ai vec_sl(vector signed char __a, vector unsigned char __b) { return __a << (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_sl(vector unsigned char __a, vector unsigned char __b) { return __a << __b; } static vector short __ATTRS_o_ai vec_sl(vector short __a, vector unsigned short __b) { return __a << (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_sl(vector unsigned short __a, vector unsigned short __b) { return __a << __b; } static vector int __ATTRS_o_ai vec_sl(vector int __a, vector unsigned int __b) { return __a << (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_sl(vector unsigned int __a, vector unsigned int __b) { return __a << __b; } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_sl(vector signed long long __a, vector unsigned long long __b) { return __a << (vector long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_sl(vector unsigned long long __a, vector unsigned long long __b) { return __a << __b; } #endif /* vec_vslb */ #define __builtin_altivec_vslb vec_vslb static vector signed char __ATTRS_o_ai vec_vslb(vector signed char __a, vector unsigned char __b) { return vec_sl(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vslb(vector unsigned char __a, vector unsigned char __b) { return vec_sl(__a, __b); } /* vec_vslh */ #define __builtin_altivec_vslh vec_vslh static vector short __ATTRS_o_ai vec_vslh(vector short __a, vector unsigned short __b) { return vec_sl(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vslh(vector unsigned short __a, vector unsigned short __b) { return vec_sl(__a, __b); } /* vec_vslw */ #define __builtin_altivec_vslw vec_vslw static vector int __ATTRS_o_ai vec_vslw(vector int __a, vector unsigned int __b) { return vec_sl(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vslw(vector unsigned int __a, vector unsigned int __b) { return vec_sl(__a, __b); } /* vec_sld */ #define __builtin_altivec_vsldoi_4si vec_sld static vector signed char __ATTRS_o_ai vec_sld(vector signed char __a, vector signed char __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector unsigned char __ATTRS_o_ai vec_sld(vector unsigned char __a, vector unsigned char __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector bool char __ATTRS_o_ai vec_sld(vector bool char __a, vector bool char __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector signed short __ATTRS_o_ai vec_sld(vector signed short __a, vector signed short __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector unsigned short __ATTRS_o_ai vec_sld(vector unsigned short __a, vector unsigned short __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector bool short __ATTRS_o_ai vec_sld(vector bool short __a, vector bool short __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector pixel __ATTRS_o_ai vec_sld(vector pixel __a, vector pixel __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector signed int __ATTRS_o_ai vec_sld(vector signed int __a, vector signed int __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector unsigned int __ATTRS_o_ai vec_sld(vector unsigned int __a, vector unsigned int __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector bool int __ATTRS_o_ai vec_sld(vector bool int __a, vector bool int __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector float __ATTRS_o_ai vec_sld(vector float __a, vector float __b, unsigned const int __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } /* vec_vsldoi */ static vector signed char __ATTRS_o_ai vec_vsldoi(vector signed char __a, vector signed char __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector unsigned char __ATTRS_o_ai vec_vsldoi(vector unsigned char __a, vector unsigned char __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector short __ATTRS_o_ai vec_vsldoi(vector short __a, vector short __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector unsigned short __ATTRS_o_ai vec_vsldoi(vector unsigned short __a, vector unsigned short __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector pixel __ATTRS_o_ai vec_vsldoi(vector pixel __a, vector pixel __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector int __ATTRS_o_ai vec_vsldoi(vector int __a, vector int __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector unsigned int __ATTRS_o_ai vec_vsldoi(vector unsigned int __a, vector unsigned int __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } static vector float __ATTRS_o_ai vec_vsldoi(vector float __a, vector float __b, unsigned char __c) { unsigned char __d = __c & 0x0F; #ifdef __LITTLE_ENDIAN__ return vec_perm( __b, __a, (vector unsigned char)(16 - __d, 17 - __d, 18 - __d, 19 - __d, 20 - __d, 21 - __d, 22 - __d, 23 - __d, 24 - __d, 25 - __d, 26 - __d, 27 - __d, 28 - __d, 29 - __d, 30 - __d, 31 - __d)); #else return vec_perm( __a, __b, (vector unsigned char)(__d, __d + 1, __d + 2, __d + 3, __d + 4, __d + 5, __d + 6, __d + 7, __d + 8, __d + 9, __d + 10, __d + 11, __d + 12, __d + 13, __d + 14, __d + 15)); #endif } /* vec_sll */ static vector signed char __ATTRS_o_ai vec_sll(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_sll(vector signed char __a, vector unsigned short __b) { return (vector signed char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_sll(vector signed char __a, vector unsigned int __b) { return (vector signed char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_sll(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_sll(vector unsigned char __a, vector unsigned short __b) { return (vector unsigned char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_sll(vector unsigned char __a, vector unsigned int __b) { return (vector unsigned char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_sll(vector bool char __a, vector unsigned char __b) { return (vector bool char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_sll(vector bool char __a, vector unsigned short __b) { return (vector bool char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_sll(vector bool char __a, vector unsigned int __b) { return (vector bool char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_sll(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_sll(vector short __a, vector unsigned short __b) { return (vector short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_sll(vector short __a, vector unsigned int __b) { return (vector short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_sll(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_sll(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_sll(vector unsigned short __a, vector unsigned int __b) { return (vector unsigned short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_sll(vector bool short __a, vector unsigned char __b) { return (vector bool short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_sll(vector bool short __a, vector unsigned short __b) { return (vector bool short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_sll(vector bool short __a, vector unsigned int __b) { return (vector bool short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_sll(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_sll(vector pixel __a, vector unsigned short __b) { return (vector pixel)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_sll(vector pixel __a, vector unsigned int __b) { return (vector pixel)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_sll(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vsl(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_sll(vector int __a, vector unsigned short __b) { return (vector int)__builtin_altivec_vsl(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_sll(vector int __a, vector unsigned int __b) { return (vector int)__builtin_altivec_vsl(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_sll(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_sll(vector unsigned int __a, vector unsigned short __b) { return (vector unsigned int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_sll(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_sll(vector bool int __a, vector unsigned char __b) { return (vector bool int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_sll(vector bool int __a, vector unsigned short __b) { return (vector bool int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_sll(vector bool int __a, vector unsigned int __b) { return (vector bool int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } /* vec_vsl */ static vector signed char __ATTRS_o_ai vec_vsl(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_vsl(vector signed char __a, vector unsigned short __b) { return (vector signed char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_vsl(vector signed char __a, vector unsigned int __b) { return (vector signed char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsl(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsl(vector unsigned char __a, vector unsigned short __b) { return (vector unsigned char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsl(vector unsigned char __a, vector unsigned int __b) { return (vector unsigned char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_vsl(vector bool char __a, vector unsigned char __b) { return (vector bool char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_vsl(vector bool char __a, vector unsigned short __b) { return (vector bool char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_vsl(vector bool char __a, vector unsigned int __b) { return (vector bool char)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsl(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsl(vector short __a, vector unsigned short __b) { return (vector short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsl(vector short __a, vector unsigned int __b) { return (vector short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsl(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsl(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsl(vector unsigned short __a, vector unsigned int __b) { return (vector unsigned short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_vsl(vector bool short __a, vector unsigned char __b) { return (vector bool short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_vsl(vector bool short __a, vector unsigned short __b) { return (vector bool short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_vsl(vector bool short __a, vector unsigned int __b) { return (vector bool short)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsl(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsl(vector pixel __a, vector unsigned short __b) { return (vector pixel)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsl(vector pixel __a, vector unsigned int __b) { return (vector pixel)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsl(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vsl(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsl(vector int __a, vector unsigned short __b) { return (vector int)__builtin_altivec_vsl(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsl(vector int __a, vector unsigned int __b) { return (vector int)__builtin_altivec_vsl(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsl(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsl(vector unsigned int __a, vector unsigned short __b) { return (vector unsigned int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsl(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_vsl(vector bool int __a, vector unsigned char __b) { return (vector bool int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_vsl(vector bool int __a, vector unsigned short __b) { return (vector bool int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_vsl(vector bool int __a, vector unsigned int __b) { return (vector bool int)__builtin_altivec_vsl((vector int)__a, (vector int)__b); } /* vec_slo */ static vector signed char __ATTRS_o_ai vec_slo(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_slo(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_slo(vector unsigned char __a, vector signed char __b) { return (vector unsigned char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_slo(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_slo(vector short __a, vector signed char __b) { return (vector short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_slo(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_slo(vector unsigned short __a, vector signed char __b) { return (vector unsigned short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_slo(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_slo(vector pixel __a, vector signed char __b) { return (vector pixel)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_slo(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_slo(vector int __a, vector signed char __b) { return (vector int)__builtin_altivec_vslo(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_slo(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vslo(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_slo(vector unsigned int __a, vector signed char __b) { return (vector unsigned int)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_slo(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_slo(vector float __a, vector signed char __b) { return (vector float)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_slo(vector float __a, vector unsigned char __b) { return (vector float)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } /* vec_vslo */ static vector signed char __ATTRS_o_ai vec_vslo(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_vslo(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vslo(vector unsigned char __a, vector signed char __b) { return (vector unsigned char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vslo(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vslo(vector short __a, vector signed char __b) { return (vector short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vslo(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vslo(vector unsigned short __a, vector signed char __b) { return (vector unsigned short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vslo(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vslo(vector pixel __a, vector signed char __b) { return (vector pixel)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vslo(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vslo(vector int __a, vector signed char __b) { return (vector int)__builtin_altivec_vslo(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vslo(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vslo(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vslo(vector unsigned int __a, vector signed char __b) { return (vector unsigned int)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vslo(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_vslo(vector float __a, vector signed char __b) { return (vector float)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_vslo(vector float __a, vector unsigned char __b) { return (vector float)__builtin_altivec_vslo((vector int)__a, (vector int)__b); } /* vec_splat */ static vector signed char __ATTRS_o_ai vec_splat(vector signed char __a, unsigned const int __b) { return vec_perm(__a, __a, (vector unsigned char)(__b & 0x0F)); } static vector unsigned char __ATTRS_o_ai vec_splat(vector unsigned char __a, unsigned const int __b) { return vec_perm(__a, __a, (vector unsigned char)(__b & 0x0F)); } static vector bool char __ATTRS_o_ai vec_splat(vector bool char __a, unsigned const int __b) { return vec_perm(__a, __a, (vector unsigned char)(__b & 0x0F)); } static vector signed short __ATTRS_o_ai vec_splat(vector signed short __a, unsigned const int __b) { unsigned char b0 = (__b & 0x07) * 2; unsigned char b1 = b0 + 1; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1)); } static vector unsigned short __ATTRS_o_ai vec_splat(vector unsigned short __a, unsigned const int __b) { unsigned char b0 = (__b & 0x07) * 2; unsigned char b1 = b0 + 1; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1)); } static vector bool short __ATTRS_o_ai vec_splat(vector bool short __a, unsigned const int __b) { unsigned char b0 = (__b & 0x07) * 2; unsigned char b1 = b0 + 1; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1)); } static vector pixel __ATTRS_o_ai vec_splat(vector pixel __a, unsigned const int __b) { unsigned char b0 = (__b & 0x07) * 2; unsigned char b1 = b0 + 1; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1, b0, b1)); } static vector signed int __ATTRS_o_ai vec_splat(vector signed int __a, unsigned const int __b) { unsigned char b0 = (__b & 0x03) * 4; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3)); } static vector unsigned int __ATTRS_o_ai vec_splat(vector unsigned int __a, unsigned const int __b) { unsigned char b0 = (__b & 0x03) * 4; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3)); } static vector bool int __ATTRS_o_ai vec_splat(vector bool int __a, unsigned const int __b) { unsigned char b0 = (__b & 0x03) * 4; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3)); } static vector float __ATTRS_o_ai vec_splat(vector float __a, unsigned const int __b) { unsigned char b0 = (__b & 0x03) * 4; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3, b0, b1, b2, b3)); } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_splat(vector double __a, unsigned const int __b) { unsigned char b0 = (__b & 0x01) * 8; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3, b4 = b0 + 4, b5 = b0 + 5, b6 = b0 + 6, b7 = b0 + 7; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b4, b5, b6, b7, b0, b1, b2, b3, b4, b5, b6, b7)); } static vector bool long long __ATTRS_o_ai vec_splat(vector bool long long __a, unsigned const int __b) { unsigned char b0 = (__b & 0x01) * 8; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3, b4 = b0 + 4, b5 = b0 + 5, b6 = b0 + 6, b7 = b0 + 7; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b4, b5, b6, b7, b0, b1, b2, b3, b4, b5, b6, b7)); } static vector signed long long __ATTRS_o_ai vec_splat(vector signed long long __a, unsigned const int __b) { unsigned char b0 = (__b & 0x01) * 8; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3, b4 = b0 + 4, b5 = b0 + 5, b6 = b0 + 6, b7 = b0 + 7; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b4, b5, b6, b7, b0, b1, b2, b3, b4, b5, b6, b7)); } static vector unsigned long long __ATTRS_o_ai vec_splat(vector unsigned long long __a, unsigned const int __b) { unsigned char b0 = (__b & 0x01) * 8; unsigned char b1 = b0 + 1, b2 = b0 + 2, b3 = b0 + 3, b4 = b0 + 4, b5 = b0 + 5, b6 = b0 + 6, b7 = b0 + 7; return vec_perm(__a, __a, (vector unsigned char)(b0, b1, b2, b3, b4, b5, b6, b7, b0, b1, b2, b3, b4, b5, b6, b7)); } #endif /* vec_vspltb */ #define __builtin_altivec_vspltb vec_vspltb static vector signed char __ATTRS_o_ai vec_vspltb(vector signed char __a, unsigned char __b) { return vec_perm(__a, __a, (vector unsigned char)(__b)); } static vector unsigned char __ATTRS_o_ai vec_vspltb(vector unsigned char __a, unsigned char __b) { return vec_perm(__a, __a, (vector unsigned char)(__b)); } static vector bool char __ATTRS_o_ai vec_vspltb(vector bool char __a, unsigned char __b) { return vec_perm(__a, __a, (vector unsigned char)(__b)); } /* vec_vsplth */ #define __builtin_altivec_vsplth vec_vsplth static vector short __ATTRS_o_ai vec_vsplth(vector short __a, unsigned char __b) { __b *= 2; unsigned char b1 = __b + 1; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1)); } static vector unsigned short __ATTRS_o_ai vec_vsplth(vector unsigned short __a, unsigned char __b) { __b *= 2; unsigned char b1 = __b + 1; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1)); } static vector bool short __ATTRS_o_ai vec_vsplth(vector bool short __a, unsigned char __b) { __b *= 2; unsigned char b1 = __b + 1; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1)); } static vector pixel __ATTRS_o_ai vec_vsplth(vector pixel __a, unsigned char __b) { __b *= 2; unsigned char b1 = __b + 1; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1, __b, b1)); } /* vec_vspltw */ #define __builtin_altivec_vspltw vec_vspltw static vector int __ATTRS_o_ai vec_vspltw(vector int __a, unsigned char __b) { __b *= 4; unsigned char b1 = __b + 1, b2 = __b + 2, b3 = __b + 3; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3)); } static vector unsigned int __ATTRS_o_ai vec_vspltw(vector unsigned int __a, unsigned char __b) { __b *= 4; unsigned char b1 = __b + 1, b2 = __b + 2, b3 = __b + 3; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3)); } static vector bool int __ATTRS_o_ai vec_vspltw(vector bool int __a, unsigned char __b) { __b *= 4; unsigned char b1 = __b + 1, b2 = __b + 2, b3 = __b + 3; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3)); } static vector float __ATTRS_o_ai vec_vspltw(vector float __a, unsigned char __b) { __b *= 4; unsigned char b1 = __b + 1, b2 = __b + 2, b3 = __b + 3; return vec_perm(__a, __a, (vector unsigned char)(__b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3, __b, b1, b2, b3)); } /* vec_splat_s8 */ #define __builtin_altivec_vspltisb vec_splat_s8 // FIXME: parameter should be treated as 5-bit signed literal static vector signed char __ATTRS_o_ai vec_splat_s8(signed char __a) { return (vector signed char)(__a); } /* vec_vspltisb */ // FIXME: parameter should be treated as 5-bit signed literal static vector signed char __ATTRS_o_ai vec_vspltisb(signed char __a) { return (vector signed char)(__a); } /* vec_splat_s16 */ #define __builtin_altivec_vspltish vec_splat_s16 // FIXME: parameter should be treated as 5-bit signed literal static vector short __ATTRS_o_ai vec_splat_s16(signed char __a) { return (vector short)(__a); } /* vec_vspltish */ // FIXME: parameter should be treated as 5-bit signed literal static vector short __ATTRS_o_ai vec_vspltish(signed char __a) { return (vector short)(__a); } /* vec_splat_s32 */ #define __builtin_altivec_vspltisw vec_splat_s32 // FIXME: parameter should be treated as 5-bit signed literal static vector int __ATTRS_o_ai vec_splat_s32(signed char __a) { return (vector int)(__a); } /* vec_vspltisw */ // FIXME: parameter should be treated as 5-bit signed literal static vector int __ATTRS_o_ai vec_vspltisw(signed char __a) { return (vector int)(__a); } /* vec_splat_u8 */ // FIXME: parameter should be treated as 5-bit signed literal static vector unsigned char __ATTRS_o_ai vec_splat_u8(unsigned char __a) { return (vector unsigned char)(__a); } /* vec_splat_u16 */ // FIXME: parameter should be treated as 5-bit signed literal static vector unsigned short __ATTRS_o_ai vec_splat_u16(signed char __a) { return (vector unsigned short)(__a); } /* vec_splat_u32 */ // FIXME: parameter should be treated as 5-bit signed literal static vector unsigned int __ATTRS_o_ai vec_splat_u32(signed char __a) { return (vector unsigned int)(__a); } /* vec_sr */ static vector signed char __ATTRS_o_ai vec_sr(vector signed char __a, vector unsigned char __b) { vector unsigned char __res = (vector unsigned char)__a >> __b; return (vector signed char)__res; } static vector unsigned char __ATTRS_o_ai vec_sr(vector unsigned char __a, vector unsigned char __b) { return __a >> __b; } static vector signed short __ATTRS_o_ai vec_sr(vector signed short __a, vector unsigned short __b) { vector unsigned short __res = (vector unsigned short)__a >> __b; return (vector signed short)__res; } static vector unsigned short __ATTRS_o_ai vec_sr(vector unsigned short __a, vector unsigned short __b) { return __a >> __b; } static vector signed int __ATTRS_o_ai vec_sr(vector signed int __a, vector unsigned int __b) { vector unsigned int __res = (vector unsigned int)__a >> __b; return (vector signed int)__res; } static vector unsigned int __ATTRS_o_ai vec_sr(vector unsigned int __a, vector unsigned int __b) { return __a >> __b; } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_sr(vector signed long long __a, vector unsigned long long __b) { vector unsigned long long __res = (vector unsigned long long)__a >> __b; return (vector signed long long)__res; } static vector unsigned long long __ATTRS_o_ai vec_sr(vector unsigned long long __a, vector unsigned long long __b) { return __a >> __b; } #endif /* vec_vsrb */ #define __builtin_altivec_vsrb vec_vsrb static vector signed char __ATTRS_o_ai vec_vsrb(vector signed char __a, vector unsigned char __b) { return __a >> (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_vsrb(vector unsigned char __a, vector unsigned char __b) { return __a >> __b; } /* vec_vsrh */ #define __builtin_altivec_vsrh vec_vsrh static vector short __ATTRS_o_ai vec_vsrh(vector short __a, vector unsigned short __b) { return __a >> (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_vsrh(vector unsigned short __a, vector unsigned short __b) { return __a >> __b; } /* vec_vsrw */ #define __builtin_altivec_vsrw vec_vsrw static vector int __ATTRS_o_ai vec_vsrw(vector int __a, vector unsigned int __b) { return __a >> (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_vsrw(vector unsigned int __a, vector unsigned int __b) { return __a >> __b; } /* vec_sra */ static vector signed char __ATTRS_o_ai vec_sra(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsrab((vector char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_sra(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsrab((vector char)__a, __b); } static vector short __ATTRS_o_ai vec_sra(vector short __a, vector unsigned short __b) { return __builtin_altivec_vsrah(__a, (vector unsigned short)__b); } static vector unsigned short __ATTRS_o_ai vec_sra(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vsrah((vector short)__a, __b); } static vector int __ATTRS_o_ai vec_sra(vector int __a, vector unsigned int __b) { return __builtin_altivec_vsraw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_sra(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vsraw((vector int)__a, __b); } #ifdef __POWER8_VECTOR__ static vector signed long long __ATTRS_o_ai vec_sra(vector signed long long __a, vector unsigned long long __b) { return __a >> __b; } static vector unsigned long long __ATTRS_o_ai vec_sra(vector unsigned long long __a, vector unsigned long long __b) { return (vector unsigned long long)((vector signed long long)__a >> __b); } #endif /* vec_vsrab */ static vector signed char __ATTRS_o_ai vec_vsrab(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsrab((vector char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vsrab(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsrab((vector char)__a, __b); } /* vec_vsrah */ static vector short __ATTRS_o_ai vec_vsrah(vector short __a, vector unsigned short __b) { return __builtin_altivec_vsrah(__a, (vector unsigned short)__b); } static vector unsigned short __ATTRS_o_ai vec_vsrah(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vsrah((vector short)__a, __b); } /* vec_vsraw */ static vector int __ATTRS_o_ai vec_vsraw(vector int __a, vector unsigned int __b) { return __builtin_altivec_vsraw(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vsraw(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vsraw((vector int)__a, __b); } /* vec_srl */ static vector signed char __ATTRS_o_ai vec_srl(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_srl(vector signed char __a, vector unsigned short __b) { return (vector signed char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_srl(vector signed char __a, vector unsigned int __b) { return (vector signed char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_srl(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_srl(vector unsigned char __a, vector unsigned short __b) { return (vector unsigned char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_srl(vector unsigned char __a, vector unsigned int __b) { return (vector unsigned char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_srl(vector bool char __a, vector unsigned char __b) { return (vector bool char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_srl(vector bool char __a, vector unsigned short __b) { return (vector bool char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_srl(vector bool char __a, vector unsigned int __b) { return (vector bool char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_srl(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_srl(vector short __a, vector unsigned short __b) { return (vector short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_srl(vector short __a, vector unsigned int __b) { return (vector short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_srl(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_srl(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_srl(vector unsigned short __a, vector unsigned int __b) { return (vector unsigned short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_srl(vector bool short __a, vector unsigned char __b) { return (vector bool short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_srl(vector bool short __a, vector unsigned short __b) { return (vector bool short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_srl(vector bool short __a, vector unsigned int __b) { return (vector bool short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_srl(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_srl(vector pixel __a, vector unsigned short __b) { return (vector pixel)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_srl(vector pixel __a, vector unsigned int __b) { return (vector pixel)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_srl(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vsr(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_srl(vector int __a, vector unsigned short __b) { return (vector int)__builtin_altivec_vsr(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_srl(vector int __a, vector unsigned int __b) { return (vector int)__builtin_altivec_vsr(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_srl(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_srl(vector unsigned int __a, vector unsigned short __b) { return (vector unsigned int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_srl(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_srl(vector bool int __a, vector unsigned char __b) { return (vector bool int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_srl(vector bool int __a, vector unsigned short __b) { return (vector bool int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_srl(vector bool int __a, vector unsigned int __b) { return (vector bool int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } /* vec_vsr */ static vector signed char __ATTRS_o_ai vec_vsr(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_vsr(vector signed char __a, vector unsigned short __b) { return (vector signed char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_vsr(vector signed char __a, vector unsigned int __b) { return (vector signed char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsr(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsr(vector unsigned char __a, vector unsigned short __b) { return (vector unsigned char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsr(vector unsigned char __a, vector unsigned int __b) { return (vector unsigned char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_vsr(vector bool char __a, vector unsigned char __b) { return (vector bool char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_vsr(vector bool char __a, vector unsigned short __b) { return (vector bool char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool char __ATTRS_o_ai vec_vsr(vector bool char __a, vector unsigned int __b) { return (vector bool char)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsr(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsr(vector short __a, vector unsigned short __b) { return (vector short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsr(vector short __a, vector unsigned int __b) { return (vector short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsr(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsr(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsr(vector unsigned short __a, vector unsigned int __b) { return (vector unsigned short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_vsr(vector bool short __a, vector unsigned char __b) { return (vector bool short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_vsr(vector bool short __a, vector unsigned short __b) { return (vector bool short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool short __ATTRS_o_ai vec_vsr(vector bool short __a, vector unsigned int __b) { return (vector bool short)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsr(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsr(vector pixel __a, vector unsigned short __b) { return (vector pixel)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsr(vector pixel __a, vector unsigned int __b) { return (vector pixel)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsr(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vsr(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsr(vector int __a, vector unsigned short __b) { return (vector int)__builtin_altivec_vsr(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsr(vector int __a, vector unsigned int __b) { return (vector int)__builtin_altivec_vsr(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsr(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsr(vector unsigned int __a, vector unsigned short __b) { return (vector unsigned int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsr(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_vsr(vector bool int __a, vector unsigned char __b) { return (vector bool int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_vsr(vector bool int __a, vector unsigned short __b) { return (vector bool int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } static vector bool int __ATTRS_o_ai vec_vsr(vector bool int __a, vector unsigned int __b) { return (vector bool int)__builtin_altivec_vsr((vector int)__a, (vector int)__b); } /* vec_sro */ static vector signed char __ATTRS_o_ai vec_sro(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_sro(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_sro(vector unsigned char __a, vector signed char __b) { return (vector unsigned char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_sro(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_sro(vector short __a, vector signed char __b) { return (vector short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_sro(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_sro(vector unsigned short __a, vector signed char __b) { return (vector unsigned short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_sro(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_sro(vector pixel __a, vector signed char __b) { return (vector pixel)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_sro(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_sro(vector int __a, vector signed char __b) { return (vector int)__builtin_altivec_vsro(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_sro(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vsro(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_sro(vector unsigned int __a, vector signed char __b) { return (vector unsigned int)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_sro(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_sro(vector float __a, vector signed char __b) { return (vector float)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_sro(vector float __a, vector unsigned char __b) { return (vector float)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } /* vec_vsro */ static vector signed char __ATTRS_o_ai vec_vsro(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector signed char __ATTRS_o_ai vec_vsro(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsro(vector unsigned char __a, vector signed char __b) { return (vector unsigned char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned char __ATTRS_o_ai vec_vsro(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsro(vector short __a, vector signed char __b) { return (vector short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector short __ATTRS_o_ai vec_vsro(vector short __a, vector unsigned char __b) { return (vector short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsro(vector unsigned short __a, vector signed char __b) { return (vector unsigned short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned short __ATTRS_o_ai vec_vsro(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsro(vector pixel __a, vector signed char __b) { return (vector pixel)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector pixel __ATTRS_o_ai vec_vsro(vector pixel __a, vector unsigned char __b) { return (vector pixel)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsro(vector int __a, vector signed char __b) { return (vector int)__builtin_altivec_vsro(__a, (vector int)__b); } static vector int __ATTRS_o_ai vec_vsro(vector int __a, vector unsigned char __b) { return (vector int)__builtin_altivec_vsro(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsro(vector unsigned int __a, vector signed char __b) { return (vector unsigned int)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_vsro(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_vsro(vector float __a, vector signed char __b) { return (vector float)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } static vector float __ATTRS_o_ai vec_vsro(vector float __a, vector unsigned char __b) { return (vector float)__builtin_altivec_vsro((vector int)__a, (vector int)__b); } /* vec_st */ static void __ATTRS_o_ai vec_st(vector signed char __a, int __b, vector signed char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector signed char __a, int __b, signed char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector unsigned char __a, int __b, vector unsigned char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector unsigned char __a, int __b, unsigned char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool char __a, int __b, signed char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool char __a, int __b, unsigned char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool char __a, int __b, vector bool char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector short __a, int __b, vector short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector short __a, int __b, short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector unsigned short __a, int __b, vector unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector unsigned short __a, int __b, unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool short __a, int __b, short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool short __a, int __b, unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool short __a, int __b, vector bool short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector pixel __a, int __b, short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector pixel __a, int __b, unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector pixel __a, int __b, vector pixel *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector int __a, int __b, vector int *__c) { __builtin_altivec_stvx(__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector int __a, int __b, int *__c) { __builtin_altivec_stvx(__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector unsigned int __a, int __b, vector unsigned int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector unsigned int __a, int __b, unsigned int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool int __a, int __b, int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool int __a, int __b, unsigned int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector bool int __a, int __b, vector bool int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector float __a, int __b, vector float *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_st(vector float __a, int __b, float *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } /* vec_stvx */ static void __ATTRS_o_ai vec_stvx(vector signed char __a, int __b, vector signed char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector signed char __a, int __b, signed char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector unsigned char __a, int __b, vector unsigned char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector unsigned char __a, int __b, unsigned char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool char __a, int __b, signed char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool char __a, int __b, unsigned char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool char __a, int __b, vector bool char *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector short __a, int __b, vector short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector short __a, int __b, short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector unsigned short __a, int __b, vector unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector unsigned short __a, int __b, unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool short __a, int __b, short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool short __a, int __b, unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool short __a, int __b, vector bool short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector pixel __a, int __b, short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector pixel __a, int __b, unsigned short *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector pixel __a, int __b, vector pixel *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector int __a, int __b, vector int *__c) { __builtin_altivec_stvx(__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector int __a, int __b, int *__c) { __builtin_altivec_stvx(__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector unsigned int __a, int __b, vector unsigned int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector unsigned int __a, int __b, unsigned int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool int __a, int __b, int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool int __a, int __b, unsigned int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector bool int __a, int __b, vector bool int *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector float __a, int __b, vector float *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvx(vector float __a, int __b, float *__c) { __builtin_altivec_stvx((vector int)__a, __b, __c); } /* vec_ste */ static void __ATTRS_o_ai vec_ste(vector signed char __a, int __b, signed char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector unsigned char __a, int __b, unsigned char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector bool char __a, int __b, signed char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector bool char __a, int __b, unsigned char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector short __a, int __b, short *__c) { __builtin_altivec_stvehx(__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector unsigned short __a, int __b, unsigned short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector bool short __a, int __b, short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector bool short __a, int __b, unsigned short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector pixel __a, int __b, short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector pixel __a, int __b, unsigned short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector int __a, int __b, int *__c) { __builtin_altivec_stvewx(__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector unsigned int __a, int __b, unsigned int *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector bool int __a, int __b, int *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector bool int __a, int __b, unsigned int *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_ste(vector float __a, int __b, float *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } /* vec_stvebx */ static void __ATTRS_o_ai vec_stvebx(vector signed char __a, int __b, signed char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } static void __ATTRS_o_ai vec_stvebx(vector unsigned char __a, int __b, unsigned char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } static void __ATTRS_o_ai vec_stvebx(vector bool char __a, int __b, signed char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } static void __ATTRS_o_ai vec_stvebx(vector bool char __a, int __b, unsigned char *__c) { __builtin_altivec_stvebx((vector char)__a, __b, __c); } /* vec_stvehx */ static void __ATTRS_o_ai vec_stvehx(vector short __a, int __b, short *__c) { __builtin_altivec_stvehx(__a, __b, __c); } static void __ATTRS_o_ai vec_stvehx(vector unsigned short __a, int __b, unsigned short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_stvehx(vector bool short __a, int __b, short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_stvehx(vector bool short __a, int __b, unsigned short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_stvehx(vector pixel __a, int __b, short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } static void __ATTRS_o_ai vec_stvehx(vector pixel __a, int __b, unsigned short *__c) { __builtin_altivec_stvehx((vector short)__a, __b, __c); } /* vec_stvewx */ static void __ATTRS_o_ai vec_stvewx(vector int __a, int __b, int *__c) { __builtin_altivec_stvewx(__a, __b, __c); } static void __ATTRS_o_ai vec_stvewx(vector unsigned int __a, int __b, unsigned int *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvewx(vector bool int __a, int __b, int *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvewx(vector bool int __a, int __b, unsigned int *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvewx(vector float __a, int __b, float *__c) { __builtin_altivec_stvewx((vector int)__a, __b, __c); } /* vec_stl */ static void __ATTRS_o_ai vec_stl(vector signed char __a, int __b, vector signed char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector signed char __a, int __b, signed char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector unsigned char __a, int __b, vector unsigned char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector unsigned char __a, int __b, unsigned char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool char __a, int __b, signed char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool char __a, int __b, unsigned char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool char __a, int __b, vector bool char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector short __a, int __b, vector short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector short __a, int __b, short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector unsigned short __a, int __b, vector unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector unsigned short __a, int __b, unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool short __a, int __b, short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool short __a, int __b, unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool short __a, int __b, vector bool short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector pixel __a, int __b, short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector pixel __a, int __b, unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector pixel __a, int __b, vector pixel *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector int __a, int __b, vector int *__c) { __builtin_altivec_stvxl(__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector int __a, int __b, int *__c) { __builtin_altivec_stvxl(__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector unsigned int __a, int __b, vector unsigned int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector unsigned int __a, int __b, unsigned int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool int __a, int __b, int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool int __a, int __b, unsigned int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector bool int __a, int __b, vector bool int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector float __a, int __b, vector float *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stl(vector float __a, int __b, float *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } /* vec_stvxl */ static void __ATTRS_o_ai vec_stvxl(vector signed char __a, int __b, vector signed char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector signed char __a, int __b, signed char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector unsigned char __a, int __b, vector unsigned char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector unsigned char __a, int __b, unsigned char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool char __a, int __b, signed char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool char __a, int __b, unsigned char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool char __a, int __b, vector bool char *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector short __a, int __b, vector short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector short __a, int __b, short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector unsigned short __a, int __b, vector unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector unsigned short __a, int __b, unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool short __a, int __b, short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool short __a, int __b, unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool short __a, int __b, vector bool short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector pixel __a, int __b, short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector pixel __a, int __b, unsigned short *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector pixel __a, int __b, vector pixel *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector int __a, int __b, vector int *__c) { __builtin_altivec_stvxl(__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector int __a, int __b, int *__c) { __builtin_altivec_stvxl(__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector unsigned int __a, int __b, vector unsigned int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector unsigned int __a, int __b, unsigned int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool int __a, int __b, int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool int __a, int __b, unsigned int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector bool int __a, int __b, vector bool int *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector float __a, int __b, vector float *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_stvxl(vector float __a, int __b, float *__c) { __builtin_altivec_stvxl((vector int)__a, __b, __c); } /* vec_sub */ static vector signed char __ATTRS_o_ai vec_sub(vector signed char __a, vector signed char __b) { return __a - __b; } static vector signed char __ATTRS_o_ai vec_sub(vector bool char __a, vector signed char __b) { return (vector signed char)__a - __b; } static vector signed char __ATTRS_o_ai vec_sub(vector signed char __a, vector bool char __b) { return __a - (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_sub(vector unsigned char __a, vector unsigned char __b) { return __a - __b; } static vector unsigned char __ATTRS_o_ai vec_sub(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a - __b; } static vector unsigned char __ATTRS_o_ai vec_sub(vector unsigned char __a, vector bool char __b) { return __a - (vector unsigned char)__b; } static vector short __ATTRS_o_ai vec_sub(vector short __a, vector short __b) { return __a - __b; } static vector short __ATTRS_o_ai vec_sub(vector bool short __a, vector short __b) { return (vector short)__a - __b; } static vector short __ATTRS_o_ai vec_sub(vector short __a, vector bool short __b) { return __a - (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_sub(vector unsigned short __a, vector unsigned short __b) { return __a - __b; } static vector unsigned short __ATTRS_o_ai vec_sub(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a - __b; } static vector unsigned short __ATTRS_o_ai vec_sub(vector unsigned short __a, vector bool short __b) { return __a - (vector unsigned short)__b; } static vector int __ATTRS_o_ai vec_sub(vector int __a, vector int __b) { return __a - __b; } static vector int __ATTRS_o_ai vec_sub(vector bool int __a, vector int __b) { return (vector int)__a - __b; } static vector int __ATTRS_o_ai vec_sub(vector int __a, vector bool int __b) { return __a - (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_sub(vector unsigned int __a, vector unsigned int __b) { return __a - __b; } static vector unsigned int __ATTRS_o_ai vec_sub(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a - __b; } static vector unsigned int __ATTRS_o_ai vec_sub(vector unsigned int __a, vector bool int __b) { return __a - (vector unsigned int)__b; } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector signed __int128 __ATTRS_o_ai vec_sub(vector signed __int128 __a, vector signed __int128 __b) { return __a - __b; } static vector unsigned __int128 __ATTRS_o_ai vec_sub(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __a - __b; } #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector float __ATTRS_o_ai vec_sub(vector float __a, vector float __b) { return __a - __b; } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_sub(vector double __a, vector double __b) { return __a - __b; } #endif /* vec_vsububm */ #define __builtin_altivec_vsububm vec_vsububm static vector signed char __ATTRS_o_ai vec_vsububm(vector signed char __a, vector signed char __b) { return __a - __b; } static vector signed char __ATTRS_o_ai vec_vsububm(vector bool char __a, vector signed char __b) { return (vector signed char)__a - __b; } static vector signed char __ATTRS_o_ai vec_vsububm(vector signed char __a, vector bool char __b) { return __a - (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_vsububm(vector unsigned char __a, vector unsigned char __b) { return __a - __b; } static vector unsigned char __ATTRS_o_ai vec_vsububm(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a - __b; } static vector unsigned char __ATTRS_o_ai vec_vsububm(vector unsigned char __a, vector bool char __b) { return __a - (vector unsigned char)__b; } /* vec_vsubuhm */ #define __builtin_altivec_vsubuhm vec_vsubuhm static vector short __ATTRS_o_ai vec_vsubuhm(vector short __a, vector short __b) { return __a - __b; } static vector short __ATTRS_o_ai vec_vsubuhm(vector bool short __a, vector short __b) { return (vector short)__a - __b; } static vector short __ATTRS_o_ai vec_vsubuhm(vector short __a, vector bool short __b) { return __a - (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_vsubuhm(vector unsigned short __a, vector unsigned short __b) { return __a - __b; } static vector unsigned short __ATTRS_o_ai vec_vsubuhm(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a - __b; } static vector unsigned short __ATTRS_o_ai vec_vsubuhm(vector unsigned short __a, vector bool short __b) { return __a - (vector unsigned short)__b; } /* vec_vsubuwm */ #define __builtin_altivec_vsubuwm vec_vsubuwm static vector int __ATTRS_o_ai vec_vsubuwm(vector int __a, vector int __b) { return __a - __b; } static vector int __ATTRS_o_ai vec_vsubuwm(vector bool int __a, vector int __b) { return (vector int)__a - __b; } static vector int __ATTRS_o_ai vec_vsubuwm(vector int __a, vector bool int __b) { return __a - (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_vsubuwm(vector unsigned int __a, vector unsigned int __b) { return __a - __b; } static vector unsigned int __ATTRS_o_ai vec_vsubuwm(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a - __b; } static vector unsigned int __ATTRS_o_ai vec_vsubuwm(vector unsigned int __a, vector bool int __b) { return __a - (vector unsigned int)__b; } /* vec_vsubfp */ #define __builtin_altivec_vsubfp vec_vsubfp static vector float __attribute__((__always_inline__)) vec_vsubfp(vector float __a, vector float __b) { return __a - __b; } /* vec_subc */ static vector unsigned int __ATTRS_o_ai vec_subc(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vsubcuw(__a, __b); } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) static vector unsigned __int128 __ATTRS_o_ai vec_subc(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __builtin_altivec_vsubcuq(__a, __b); } static vector signed __int128 __ATTRS_o_ai vec_subc(vector signed __int128 __a, vector signed __int128 __b) { return __builtin_altivec_vsubcuq(__a, __b); } #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) /* vec_vsubcuw */ static vector unsigned int __attribute__((__always_inline__)) vec_vsubcuw(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vsubcuw(__a, __b); } /* vec_subs */ static vector signed char __ATTRS_o_ai vec_subs(vector signed char __a, vector signed char __b) { return __builtin_altivec_vsubsbs(__a, __b); } static vector signed char __ATTRS_o_ai vec_subs(vector bool char __a, vector signed char __b) { return __builtin_altivec_vsubsbs((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_subs(vector signed char __a, vector bool char __b) { return __builtin_altivec_vsubsbs(__a, (vector signed char)__b); } static vector unsigned char __ATTRS_o_ai vec_subs(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vsububs(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_subs(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vsububs((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_subs(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vsububs(__a, (vector unsigned char)__b); } static vector short __ATTRS_o_ai vec_subs(vector short __a, vector short __b) { return __builtin_altivec_vsubshs(__a, __b); } static vector short __ATTRS_o_ai vec_subs(vector bool short __a, vector short __b) { return __builtin_altivec_vsubshs((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_subs(vector short __a, vector bool short __b) { return __builtin_altivec_vsubshs(__a, (vector short)__b); } static vector unsigned short __ATTRS_o_ai vec_subs(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vsubuhs(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_subs(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vsubuhs((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_subs(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vsubuhs(__a, (vector unsigned short)__b); } static vector int __ATTRS_o_ai vec_subs(vector int __a, vector int __b) { return __builtin_altivec_vsubsws(__a, __b); } static vector int __ATTRS_o_ai vec_subs(vector bool int __a, vector int __b) { return __builtin_altivec_vsubsws((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_subs(vector int __a, vector bool int __b) { return __builtin_altivec_vsubsws(__a, (vector int)__b); } static vector unsigned int __ATTRS_o_ai vec_subs(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vsubuws(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_subs(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vsubuws((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_subs(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vsubuws(__a, (vector unsigned int)__b); } /* vec_vsubsbs */ static vector signed char __ATTRS_o_ai vec_vsubsbs(vector signed char __a, vector signed char __b) { return __builtin_altivec_vsubsbs(__a, __b); } static vector signed char __ATTRS_o_ai vec_vsubsbs(vector bool char __a, vector signed char __b) { return __builtin_altivec_vsubsbs((vector signed char)__a, __b); } static vector signed char __ATTRS_o_ai vec_vsubsbs(vector signed char __a, vector bool char __b) { return __builtin_altivec_vsubsbs(__a, (vector signed char)__b); } /* vec_vsububs */ static vector unsigned char __ATTRS_o_ai vec_vsububs(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vsububs(__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vsububs(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vsububs((vector unsigned char)__a, __b); } static vector unsigned char __ATTRS_o_ai vec_vsububs(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vsububs(__a, (vector unsigned char)__b); } /* vec_vsubshs */ static vector short __ATTRS_o_ai vec_vsubshs(vector short __a, vector short __b) { return __builtin_altivec_vsubshs(__a, __b); } static vector short __ATTRS_o_ai vec_vsubshs(vector bool short __a, vector short __b) { return __builtin_altivec_vsubshs((vector short)__a, __b); } static vector short __ATTRS_o_ai vec_vsubshs(vector short __a, vector bool short __b) { return __builtin_altivec_vsubshs(__a, (vector short)__b); } /* vec_vsubuhs */ static vector unsigned short __ATTRS_o_ai vec_vsubuhs(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vsubuhs(__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vsubuhs(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vsubuhs((vector unsigned short)__a, __b); } static vector unsigned short __ATTRS_o_ai vec_vsubuhs(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vsubuhs(__a, (vector unsigned short)__b); } /* vec_vsubsws */ static vector int __ATTRS_o_ai vec_vsubsws(vector int __a, vector int __b) { return __builtin_altivec_vsubsws(__a, __b); } static vector int __ATTRS_o_ai vec_vsubsws(vector bool int __a, vector int __b) { return __builtin_altivec_vsubsws((vector int)__a, __b); } static vector int __ATTRS_o_ai vec_vsubsws(vector int __a, vector bool int __b) { return __builtin_altivec_vsubsws(__a, (vector int)__b); } /* vec_vsubuws */ static vector unsigned int __ATTRS_o_ai vec_vsubuws(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vsubuws(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vsubuws(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vsubuws((vector unsigned int)__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vsubuws(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vsubuws(__a, (vector unsigned int)__b); } #if defined(__POWER8_VECTOR__) && defined(__powerpc64__) /* vec_vsubuqm */ static vector signed __int128 __ATTRS_o_ai vec_vsubuqm(vector signed __int128 __a, vector signed __int128 __b) { return __a - __b; } static vector unsigned __int128 __ATTRS_o_ai vec_vsubuqm(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __a - __b; } /* vec_vsubeuqm */ static vector signed __int128 __ATTRS_o_ai vec_vsubeuqm(vector signed __int128 __a, vector signed __int128 __b, vector signed __int128 __c) { return __builtin_altivec_vsubeuqm(__a, __b, __c); } static vector unsigned __int128 __ATTRS_o_ai vec_vsubeuqm(vector unsigned __int128 __a, vector unsigned __int128 __b, vector unsigned __int128 __c) { return __builtin_altivec_vsubeuqm(__a, __b, __c); } /* vec_vsubcuq */ static vector signed __int128 __ATTRS_o_ai vec_vsubcuq(vector signed __int128 __a, vector signed __int128 __b) { return __builtin_altivec_vsubcuq(__a, __b); } static vector unsigned __int128 __ATTRS_o_ai vec_vsubcuq(vector unsigned __int128 __a, vector unsigned __int128 __b) { return __builtin_altivec_vsubcuq(__a, __b); } /* vec_vsubecuq */ static vector signed __int128 __ATTRS_o_ai vec_vsubecuq(vector signed __int128 __a, vector signed __int128 __b, vector signed __int128 __c) { return __builtin_altivec_vsubecuq(__a, __b, __c); } static vector unsigned __int128 __ATTRS_o_ai vec_vsubecuq(vector unsigned __int128 __a, vector unsigned __int128 __b, vector unsigned __int128 __c) { return __builtin_altivec_vsubecuq(__a, __b, __c); } #endif // defined(__POWER8_VECTOR__) && defined(__powerpc64__) /* vec_sum4s */ static vector int __ATTRS_o_ai vec_sum4s(vector signed char __a, vector int __b) { return __builtin_altivec_vsum4sbs(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_sum4s(vector unsigned char __a, vector unsigned int __b) { return __builtin_altivec_vsum4ubs(__a, __b); } static vector int __ATTRS_o_ai vec_sum4s(vector signed short __a, vector int __b) { return __builtin_altivec_vsum4shs(__a, __b); } /* vec_vsum4sbs */ static vector int __attribute__((__always_inline__)) vec_vsum4sbs(vector signed char __a, vector int __b) { return __builtin_altivec_vsum4sbs(__a, __b); } /* vec_vsum4ubs */ static vector unsigned int __attribute__((__always_inline__)) vec_vsum4ubs(vector unsigned char __a, vector unsigned int __b) { return __builtin_altivec_vsum4ubs(__a, __b); } /* vec_vsum4shs */ static vector int __attribute__((__always_inline__)) vec_vsum4shs(vector signed short __a, vector int __b) { return __builtin_altivec_vsum4shs(__a, __b); } /* vec_sum2s */ /* The vsum2sws instruction has a big-endian bias, so that the second input vector and the result always reference big-endian elements 1 and 3 (little-endian element 0 and 2). For ease of porting the programmer wants elements 1 and 3 in both cases, so for little endian we must perform some permutes. */ static vector signed int __attribute__((__always_inline__)) vec_sum2s(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ vector int __c = (vector signed int)vec_perm( __b, __b, (vector unsigned char)(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)); __c = __builtin_altivec_vsum2sws(__a, __c); return (vector signed int)vec_perm( __c, __c, (vector unsigned char)(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)); #else return __builtin_altivec_vsum2sws(__a, __b); #endif } /* vec_vsum2sws */ static vector signed int __attribute__((__always_inline__)) vec_vsum2sws(vector int __a, vector int __b) { #ifdef __LITTLE_ENDIAN__ vector int __c = (vector signed int)vec_perm( __b, __b, (vector unsigned char)(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)); __c = __builtin_altivec_vsum2sws(__a, __c); return (vector signed int)vec_perm( __c, __c, (vector unsigned char)(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)); #else return __builtin_altivec_vsum2sws(__a, __b); #endif } /* vec_sums */ /* The vsumsws instruction has a big-endian bias, so that the second input vector and the result always reference big-endian element 3 (little-endian element 0). For ease of porting the programmer wants element 3 in both cases, so for little endian we must perform some permutes. */ static vector signed int __attribute__((__always_inline__)) vec_sums(vector signed int __a, vector signed int __b) { #ifdef __LITTLE_ENDIAN__ __b = (vector signed int)vec_splat(__b, 3); __b = __builtin_altivec_vsumsws(__a, __b); return (vector signed int)(0, 0, 0, __b[0]); #else return __builtin_altivec_vsumsws(__a, __b); #endif } /* vec_vsumsws */ static vector signed int __attribute__((__always_inline__)) vec_vsumsws(vector signed int __a, vector signed int __b) { #ifdef __LITTLE_ENDIAN__ __b = (vector signed int)vec_splat(__b, 3); __b = __builtin_altivec_vsumsws(__a, __b); return (vector signed int)(0, 0, 0, __b[0]); #else return __builtin_altivec_vsumsws(__a, __b); #endif } /* vec_trunc */ static vector float __ATTRS_o_ai vec_trunc(vector float __a) { #ifdef __VSX__ return __builtin_vsx_xvrspiz(__a); #else return __builtin_altivec_vrfiz(__a); #endif } #ifdef __VSX__ static vector double __ATTRS_o_ai vec_trunc(vector double __a) { return __builtin_vsx_xvrdpiz(__a); } #endif /* vec_vrfiz */ static vector float __attribute__((__always_inline__)) vec_vrfiz(vector float __a) { return __builtin_altivec_vrfiz(__a); } /* vec_unpackh */ /* The vector unpack instructions all have a big-endian bias, so for little endian we must reverse the meanings of "high" and "low." */ static vector short __ATTRS_o_ai vec_unpackh(vector signed char __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupklsb((vector char)__a); #else return __builtin_altivec_vupkhsb((vector char)__a); #endif } static vector bool short __ATTRS_o_ai vec_unpackh(vector bool char __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool short)__builtin_altivec_vupklsb((vector char)__a); #else return (vector bool short)__builtin_altivec_vupkhsb((vector char)__a); #endif } static vector int __ATTRS_o_ai vec_unpackh(vector short __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupklsh(__a); #else return __builtin_altivec_vupkhsh(__a); #endif } static vector bool int __ATTRS_o_ai vec_unpackh(vector bool short __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool int)__builtin_altivec_vupklsh((vector short)__a); #else return (vector bool int)__builtin_altivec_vupkhsh((vector short)__a); #endif } static vector unsigned int __ATTRS_o_ai vec_unpackh(vector pixel __a) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned int)__builtin_altivec_vupklpx((vector short)__a); #else return (vector unsigned int)__builtin_altivec_vupkhpx((vector short)__a); #endif } #ifdef __POWER8_VECTOR__ static vector long long __ATTRS_o_ai vec_unpackh(vector int __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupklsw(__a); #else return __builtin_altivec_vupkhsw(__a); #endif } static vector bool long long __ATTRS_o_ai vec_unpackh(vector bool int __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool long long)__builtin_altivec_vupklsw((vector int)__a); #else return (vector bool long long)__builtin_altivec_vupkhsw((vector int)__a); #endif } #endif /* vec_vupkhsb */ static vector short __ATTRS_o_ai vec_vupkhsb(vector signed char __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupklsb((vector char)__a); #else return __builtin_altivec_vupkhsb((vector char)__a); #endif } static vector bool short __ATTRS_o_ai vec_vupkhsb(vector bool char __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool short)__builtin_altivec_vupklsb((vector char)__a); #else return (vector bool short)__builtin_altivec_vupkhsb((vector char)__a); #endif } /* vec_vupkhsh */ static vector int __ATTRS_o_ai vec_vupkhsh(vector short __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupklsh(__a); #else return __builtin_altivec_vupkhsh(__a); #endif } static vector bool int __ATTRS_o_ai vec_vupkhsh(vector bool short __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool int)__builtin_altivec_vupklsh((vector short)__a); #else return (vector bool int)__builtin_altivec_vupkhsh((vector short)__a); #endif } static vector unsigned int __ATTRS_o_ai vec_vupkhsh(vector pixel __a) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned int)__builtin_altivec_vupklpx((vector short)__a); #else return (vector unsigned int)__builtin_altivec_vupkhpx((vector short)__a); #endif } /* vec_vupkhsw */ #ifdef __POWER8_VECTOR__ static vector long long __ATTRS_o_ai vec_vupkhsw(vector int __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupklsw(__a); #else return __builtin_altivec_vupkhsw(__a); #endif } static vector bool long long __ATTRS_o_ai vec_vupkhsw(vector bool int __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool long long)__builtin_altivec_vupklsw((vector int)__a); #else return (vector bool long long)__builtin_altivec_vupkhsw((vector int)__a); #endif } #endif /* vec_unpackl */ static vector short __ATTRS_o_ai vec_unpackl(vector signed char __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupkhsb((vector char)__a); #else return __builtin_altivec_vupklsb((vector char)__a); #endif } static vector bool short __ATTRS_o_ai vec_unpackl(vector bool char __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool short)__builtin_altivec_vupkhsb((vector char)__a); #else return (vector bool short)__builtin_altivec_vupklsb((vector char)__a); #endif } static vector int __ATTRS_o_ai vec_unpackl(vector short __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupkhsh(__a); #else return __builtin_altivec_vupklsh(__a); #endif } static vector bool int __ATTRS_o_ai vec_unpackl(vector bool short __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool int)__builtin_altivec_vupkhsh((vector short)__a); #else return (vector bool int)__builtin_altivec_vupklsh((vector short)__a); #endif } static vector unsigned int __ATTRS_o_ai vec_unpackl(vector pixel __a) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned int)__builtin_altivec_vupkhpx((vector short)__a); #else return (vector unsigned int)__builtin_altivec_vupklpx((vector short)__a); #endif } #ifdef __POWER8_VECTOR__ static vector long long __ATTRS_o_ai vec_unpackl(vector int __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupkhsw(__a); #else return __builtin_altivec_vupklsw(__a); #endif } static vector bool long long __ATTRS_o_ai vec_unpackl(vector bool int __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool long long)__builtin_altivec_vupkhsw((vector int)__a); #else return (vector bool long long)__builtin_altivec_vupklsw((vector int)__a); #endif } #endif /* vec_vupklsb */ static vector short __ATTRS_o_ai vec_vupklsb(vector signed char __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupkhsb((vector char)__a); #else return __builtin_altivec_vupklsb((vector char)__a); #endif } static vector bool short __ATTRS_o_ai vec_vupklsb(vector bool char __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool short)__builtin_altivec_vupkhsb((vector char)__a); #else return (vector bool short)__builtin_altivec_vupklsb((vector char)__a); #endif } /* vec_vupklsh */ static vector int __ATTRS_o_ai vec_vupklsh(vector short __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupkhsh(__a); #else return __builtin_altivec_vupklsh(__a); #endif } static vector bool int __ATTRS_o_ai vec_vupklsh(vector bool short __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool int)__builtin_altivec_vupkhsh((vector short)__a); #else return (vector bool int)__builtin_altivec_vupklsh((vector short)__a); #endif } static vector unsigned int __ATTRS_o_ai vec_vupklsh(vector pixel __a) { #ifdef __LITTLE_ENDIAN__ return (vector unsigned int)__builtin_altivec_vupkhpx((vector short)__a); #else return (vector unsigned int)__builtin_altivec_vupklpx((vector short)__a); #endif } /* vec_vupklsw */ #ifdef __POWER8_VECTOR__ static vector long long __ATTRS_o_ai vec_vupklsw(vector int __a) { #ifdef __LITTLE_ENDIAN__ return __builtin_altivec_vupkhsw(__a); #else return __builtin_altivec_vupklsw(__a); #endif } static vector bool long long __ATTRS_o_ai vec_vupklsw(vector bool int __a) { #ifdef __LITTLE_ENDIAN__ return (vector bool long long)__builtin_altivec_vupkhsw((vector int)__a); #else return (vector bool long long)__builtin_altivec_vupklsw((vector int)__a); #endif } #endif /* vec_vsx_ld */ #ifdef __VSX__ static vector signed int __ATTRS_o_ai vec_vsx_ld(int __a, const vector signed int *__b) { return (vector signed int)__builtin_vsx_lxvw4x(__a, __b); } static vector unsigned int __ATTRS_o_ai vec_vsx_ld(int __a, const vector unsigned int *__b) { return (vector unsigned int)__builtin_vsx_lxvw4x(__a, __b); } static vector float __ATTRS_o_ai vec_vsx_ld(int __a, const vector float *__b) { return (vector float)__builtin_vsx_lxvw4x(__a, __b); } static vector signed long long __ATTRS_o_ai vec_vsx_ld(int __a, const vector signed long long *__b) { return (vector signed long long)__builtin_vsx_lxvd2x(__a, __b); } static vector unsigned long long __ATTRS_o_ai vec_vsx_ld(int __a, const vector unsigned long long *__b) { return (vector unsigned long long)__builtin_vsx_lxvd2x(__a, __b); } static vector double __ATTRS_o_ai vec_vsx_ld(int __a, const vector double *__b) { return (vector double)__builtin_vsx_lxvd2x(__a, __b); } #endif /* vec_vsx_st */ #ifdef __VSX__ static void __ATTRS_o_ai vec_vsx_st(vector signed int __a, int __b, vector signed int *__c) { __builtin_vsx_stxvw4x((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_vsx_st(vector unsigned int __a, int __b, vector unsigned int *__c) { __builtin_vsx_stxvw4x((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_vsx_st(vector float __a, int __b, vector float *__c) { __builtin_vsx_stxvw4x((vector int)__a, __b, __c); } static void __ATTRS_o_ai vec_vsx_st(vector signed long long __a, int __b, vector signed long long *__c) { __builtin_vsx_stxvd2x((vector double)__a, __b, __c); } static void __ATTRS_o_ai vec_vsx_st(vector unsigned long long __a, int __b, vector unsigned long long *__c) { __builtin_vsx_stxvd2x((vector double)__a, __b, __c); } static void __ATTRS_o_ai vec_vsx_st(vector double __a, int __b, vector double *__c) { __builtin_vsx_stxvd2x((vector double)__a, __b, __c); } #endif /* vec_xor */ #define __builtin_altivec_vxor vec_xor static vector signed char __ATTRS_o_ai vec_xor(vector signed char __a, vector signed char __b) { return __a ^ __b; } static vector signed char __ATTRS_o_ai vec_xor(vector bool char __a, vector signed char __b) { return (vector signed char)__a ^ __b; } static vector signed char __ATTRS_o_ai vec_xor(vector signed char __a, vector bool char __b) { return __a ^ (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_xor(vector unsigned char __a, vector unsigned char __b) { return __a ^ __b; } static vector unsigned char __ATTRS_o_ai vec_xor(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a ^ __b; } static vector unsigned char __ATTRS_o_ai vec_xor(vector unsigned char __a, vector bool char __b) { return __a ^ (vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_xor(vector bool char __a, vector bool char __b) { return __a ^ __b; } static vector short __ATTRS_o_ai vec_xor(vector short __a, vector short __b) { return __a ^ __b; } static vector short __ATTRS_o_ai vec_xor(vector bool short __a, vector short __b) { return (vector short)__a ^ __b; } static vector short __ATTRS_o_ai vec_xor(vector short __a, vector bool short __b) { return __a ^ (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_xor(vector unsigned short __a, vector unsigned short __b) { return __a ^ __b; } static vector unsigned short __ATTRS_o_ai vec_xor(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a ^ __b; } static vector unsigned short __ATTRS_o_ai vec_xor(vector unsigned short __a, vector bool short __b) { return __a ^ (vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_xor(vector bool short __a, vector bool short __b) { return __a ^ __b; } static vector int __ATTRS_o_ai vec_xor(vector int __a, vector int __b) { return __a ^ __b; } static vector int __ATTRS_o_ai vec_xor(vector bool int __a, vector int __b) { return (vector int)__a ^ __b; } static vector int __ATTRS_o_ai vec_xor(vector int __a, vector bool int __b) { return __a ^ (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_xor(vector unsigned int __a, vector unsigned int __b) { return __a ^ __b; } static vector unsigned int __ATTRS_o_ai vec_xor(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a ^ __b; } static vector unsigned int __ATTRS_o_ai vec_xor(vector unsigned int __a, vector bool int __b) { return __a ^ (vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_xor(vector bool int __a, vector bool int __b) { return __a ^ __b; } static vector float __ATTRS_o_ai vec_xor(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a ^ (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_xor(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a ^ (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_xor(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a ^ (vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_xor(vector signed long long __a, vector signed long long __b) { return __a ^ __b; } static vector signed long long __ATTRS_o_ai vec_xor(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a ^ __b; } static vector signed long long __ATTRS_o_ai vec_xor(vector signed long long __a, vector bool long long __b) { return __a ^ (vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_xor(vector unsigned long long __a, vector unsigned long long __b) { return __a ^ __b; } static vector unsigned long long __ATTRS_o_ai vec_xor(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a ^ __b; } static vector unsigned long long __ATTRS_o_ai vec_xor(vector unsigned long long __a, vector bool long long __b) { return __a ^ (vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_xor(vector bool long long __a, vector bool long long __b) { return __a ^ __b; } static vector double __ATTRS_o_ai vec_xor(vector double __a, vector double __b) { return (vector double)((vector unsigned long long)__a ^ (vector unsigned long long)__b); } static vector double __ATTRS_o_ai vec_xor(vector double __a, vector bool long long __b) { return (vector double)((vector unsigned long long)__a ^ (vector unsigned long long) __b); } static vector double __ATTRS_o_ai vec_xor(vector bool long long __a, vector double __b) { return (vector double)((vector unsigned long long)__a ^ (vector unsigned long long)__b); } #endif /* vec_vxor */ static vector signed char __ATTRS_o_ai vec_vxor(vector signed char __a, vector signed char __b) { return __a ^ __b; } static vector signed char __ATTRS_o_ai vec_vxor(vector bool char __a, vector signed char __b) { return (vector signed char)__a ^ __b; } static vector signed char __ATTRS_o_ai vec_vxor(vector signed char __a, vector bool char __b) { return __a ^ (vector signed char)__b; } static vector unsigned char __ATTRS_o_ai vec_vxor(vector unsigned char __a, vector unsigned char __b) { return __a ^ __b; } static vector unsigned char __ATTRS_o_ai vec_vxor(vector bool char __a, vector unsigned char __b) { return (vector unsigned char)__a ^ __b; } static vector unsigned char __ATTRS_o_ai vec_vxor(vector unsigned char __a, vector bool char __b) { return __a ^ (vector unsigned char)__b; } static vector bool char __ATTRS_o_ai vec_vxor(vector bool char __a, vector bool char __b) { return __a ^ __b; } static vector short __ATTRS_o_ai vec_vxor(vector short __a, vector short __b) { return __a ^ __b; } static vector short __ATTRS_o_ai vec_vxor(vector bool short __a, vector short __b) { return (vector short)__a ^ __b; } static vector short __ATTRS_o_ai vec_vxor(vector short __a, vector bool short __b) { return __a ^ (vector short)__b; } static vector unsigned short __ATTRS_o_ai vec_vxor(vector unsigned short __a, vector unsigned short __b) { return __a ^ __b; } static vector unsigned short __ATTRS_o_ai vec_vxor(vector bool short __a, vector unsigned short __b) { return (vector unsigned short)__a ^ __b; } static vector unsigned short __ATTRS_o_ai vec_vxor(vector unsigned short __a, vector bool short __b) { return __a ^ (vector unsigned short)__b; } static vector bool short __ATTRS_o_ai vec_vxor(vector bool short __a, vector bool short __b) { return __a ^ __b; } static vector int __ATTRS_o_ai vec_vxor(vector int __a, vector int __b) { return __a ^ __b; } static vector int __ATTRS_o_ai vec_vxor(vector bool int __a, vector int __b) { return (vector int)__a ^ __b; } static vector int __ATTRS_o_ai vec_vxor(vector int __a, vector bool int __b) { return __a ^ (vector int)__b; } static vector unsigned int __ATTRS_o_ai vec_vxor(vector unsigned int __a, vector unsigned int __b) { return __a ^ __b; } static vector unsigned int __ATTRS_o_ai vec_vxor(vector bool int __a, vector unsigned int __b) { return (vector unsigned int)__a ^ __b; } static vector unsigned int __ATTRS_o_ai vec_vxor(vector unsigned int __a, vector bool int __b) { return __a ^ (vector unsigned int)__b; } static vector bool int __ATTRS_o_ai vec_vxor(vector bool int __a, vector bool int __b) { return __a ^ __b; } static vector float __ATTRS_o_ai vec_vxor(vector float __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a ^ (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vxor(vector bool int __a, vector float __b) { vector unsigned int __res = (vector unsigned int)__a ^ (vector unsigned int)__b; return (vector float)__res; } static vector float __ATTRS_o_ai vec_vxor(vector float __a, vector bool int __b) { vector unsigned int __res = (vector unsigned int)__a ^ (vector unsigned int)__b; return (vector float)__res; } #ifdef __VSX__ static vector signed long long __ATTRS_o_ai vec_vxor(vector signed long long __a, vector signed long long __b) { return __a ^ __b; } static vector signed long long __ATTRS_o_ai vec_vxor(vector bool long long __a, vector signed long long __b) { return (vector signed long long)__a ^ __b; } static vector signed long long __ATTRS_o_ai vec_vxor(vector signed long long __a, vector bool long long __b) { return __a ^ (vector signed long long)__b; } static vector unsigned long long __ATTRS_o_ai vec_vxor(vector unsigned long long __a, vector unsigned long long __b) { return __a ^ __b; } static vector unsigned long long __ATTRS_o_ai vec_vxor(vector bool long long __a, vector unsigned long long __b) { return (vector unsigned long long)__a ^ __b; } static vector unsigned long long __ATTRS_o_ai vec_vxor(vector unsigned long long __a, vector bool long long __b) { return __a ^ (vector unsigned long long)__b; } static vector bool long long __ATTRS_o_ai vec_vxor(vector bool long long __a, vector bool long long __b) { return __a ^ __b; } #endif /* ------------------------ extensions for CBEA ----------------------------- */ /* vec_extract */ static signed char __ATTRS_o_ai vec_extract(vector signed char __a, int __b) { return __a[__b]; } static unsigned char __ATTRS_o_ai vec_extract(vector unsigned char __a, int __b) { return __a[__b]; } static short __ATTRS_o_ai vec_extract(vector short __a, int __b) { return __a[__b]; } static unsigned short __ATTRS_o_ai vec_extract(vector unsigned short __a, int __b) { return __a[__b]; } static int __ATTRS_o_ai vec_extract(vector int __a, int __b) { return __a[__b]; } static unsigned int __ATTRS_o_ai vec_extract(vector unsigned int __a, int __b) { return __a[__b]; } static float __ATTRS_o_ai vec_extract(vector float __a, int __b) { return __a[__b]; } /* vec_insert */ static vector signed char __ATTRS_o_ai vec_insert(signed char __a, vector signed char __b, int __c) { __b[__c] = __a; return __b; } static vector unsigned char __ATTRS_o_ai vec_insert(unsigned char __a, vector unsigned char __b, int __c) { __b[__c] = __a; return __b; } static vector short __ATTRS_o_ai vec_insert(short __a, vector short __b, int __c) { __b[__c] = __a; return __b; } static vector unsigned short __ATTRS_o_ai vec_insert(unsigned short __a, vector unsigned short __b, int __c) { __b[__c] = __a; return __b; } static vector int __ATTRS_o_ai vec_insert(int __a, vector int __b, int __c) { __b[__c] = __a; return __b; } static vector unsigned int __ATTRS_o_ai vec_insert(unsigned int __a, vector unsigned int __b, int __c) { __b[__c] = __a; return __b; } static vector float __ATTRS_o_ai vec_insert(float __a, vector float __b, int __c) { __b[__c] = __a; return __b; } /* vec_lvlx */ static vector signed char __ATTRS_o_ai vec_lvlx(int __a, const signed char *__b) { return vec_perm(vec_ld(__a, __b), (vector signed char)(0), vec_lvsl(__a, __b)); } static vector signed char __ATTRS_o_ai vec_lvlx(int __a, const vector signed char *__b) { return vec_perm(vec_ld(__a, __b), (vector signed char)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned char __ATTRS_o_ai vec_lvlx(int __a, const unsigned char *__b) { return vec_perm(vec_ld(__a, __b), (vector unsigned char)(0), vec_lvsl(__a, __b)); } static vector unsigned char __ATTRS_o_ai vec_lvlx(int __a, const vector unsigned char *__b) { return vec_perm(vec_ld(__a, __b), (vector unsigned char)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool char __ATTRS_o_ai vec_lvlx(int __a, const vector bool char *__b) { return vec_perm(vec_ld(__a, __b), (vector bool char)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector short __ATTRS_o_ai vec_lvlx(int __a, const short *__b) { return vec_perm(vec_ld(__a, __b), (vector short)(0), vec_lvsl(__a, __b)); } static vector short __ATTRS_o_ai vec_lvlx(int __a, const vector short *__b) { return vec_perm(vec_ld(__a, __b), (vector short)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned short __ATTRS_o_ai vec_lvlx(int __a, const unsigned short *__b) { return vec_perm(vec_ld(__a, __b), (vector unsigned short)(0), vec_lvsl(__a, __b)); } static vector unsigned short __ATTRS_o_ai vec_lvlx(int __a, const vector unsigned short *__b) { return vec_perm(vec_ld(__a, __b), (vector unsigned short)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool short __ATTRS_o_ai vec_lvlx(int __a, const vector bool short *__b) { return vec_perm(vec_ld(__a, __b), (vector bool short)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector pixel __ATTRS_o_ai vec_lvlx(int __a, const vector pixel *__b) { return vec_perm(vec_ld(__a, __b), (vector pixel)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector int __ATTRS_o_ai vec_lvlx(int __a, const int *__b) { return vec_perm(vec_ld(__a, __b), (vector int)(0), vec_lvsl(__a, __b)); } static vector int __ATTRS_o_ai vec_lvlx(int __a, const vector int *__b) { return vec_perm(vec_ld(__a, __b), (vector int)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned int __ATTRS_o_ai vec_lvlx(int __a, const unsigned int *__b) { return vec_perm(vec_ld(__a, __b), (vector unsigned int)(0), vec_lvsl(__a, __b)); } static vector unsigned int __ATTRS_o_ai vec_lvlx(int __a, const vector unsigned int *__b) { return vec_perm(vec_ld(__a, __b), (vector unsigned int)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool int __ATTRS_o_ai vec_lvlx(int __a, const vector bool int *__b) { return vec_perm(vec_ld(__a, __b), (vector bool int)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector float __ATTRS_o_ai vec_lvlx(int __a, const float *__b) { return vec_perm(vec_ld(__a, __b), (vector float)(0), vec_lvsl(__a, __b)); } static vector float __ATTRS_o_ai vec_lvlx(int __a, const vector float *__b) { return vec_perm(vec_ld(__a, __b), (vector float)(0), vec_lvsl(__a, (unsigned char *)__b)); } /* vec_lvlxl */ static vector signed char __ATTRS_o_ai vec_lvlxl(int __a, const signed char *__b) { return vec_perm(vec_ldl(__a, __b), (vector signed char)(0), vec_lvsl(__a, __b)); } static vector signed char __ATTRS_o_ai vec_lvlxl(int __a, const vector signed char *__b) { return vec_perm(vec_ldl(__a, __b), (vector signed char)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned char __ATTRS_o_ai vec_lvlxl(int __a, const unsigned char *__b) { return vec_perm(vec_ldl(__a, __b), (vector unsigned char)(0), vec_lvsl(__a, __b)); } static vector unsigned char __ATTRS_o_ai vec_lvlxl(int __a, const vector unsigned char *__b) { return vec_perm(vec_ldl(__a, __b), (vector unsigned char)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool char __ATTRS_o_ai vec_lvlxl(int __a, const vector bool char *__b) { return vec_perm(vec_ldl(__a, __b), (vector bool char)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector short __ATTRS_o_ai vec_lvlxl(int __a, const short *__b) { return vec_perm(vec_ldl(__a, __b), (vector short)(0), vec_lvsl(__a, __b)); } static vector short __ATTRS_o_ai vec_lvlxl(int __a, const vector short *__b) { return vec_perm(vec_ldl(__a, __b), (vector short)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned short __ATTRS_o_ai vec_lvlxl(int __a, const unsigned short *__b) { return vec_perm(vec_ldl(__a, __b), (vector unsigned short)(0), vec_lvsl(__a, __b)); } static vector unsigned short __ATTRS_o_ai vec_lvlxl(int __a, const vector unsigned short *__b) { return vec_perm(vec_ldl(__a, __b), (vector unsigned short)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool short __ATTRS_o_ai vec_lvlxl(int __a, const vector bool short *__b) { return vec_perm(vec_ldl(__a, __b), (vector bool short)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector pixel __ATTRS_o_ai vec_lvlxl(int __a, const vector pixel *__b) { return vec_perm(vec_ldl(__a, __b), (vector pixel)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector int __ATTRS_o_ai vec_lvlxl(int __a, const int *__b) { return vec_perm(vec_ldl(__a, __b), (vector int)(0), vec_lvsl(__a, __b)); } static vector int __ATTRS_o_ai vec_lvlxl(int __a, const vector int *__b) { return vec_perm(vec_ldl(__a, __b), (vector int)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned int __ATTRS_o_ai vec_lvlxl(int __a, const unsigned int *__b) { return vec_perm(vec_ldl(__a, __b), (vector unsigned int)(0), vec_lvsl(__a, __b)); } static vector unsigned int __ATTRS_o_ai vec_lvlxl(int __a, const vector unsigned int *__b) { return vec_perm(vec_ldl(__a, __b), (vector unsigned int)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool int __ATTRS_o_ai vec_lvlxl(int __a, const vector bool int *__b) { return vec_perm(vec_ldl(__a, __b), (vector bool int)(0), vec_lvsl(__a, (unsigned char *)__b)); } static vector float __ATTRS_o_ai vec_lvlxl(int __a, const float *__b) { return vec_perm(vec_ldl(__a, __b), (vector float)(0), vec_lvsl(__a, __b)); } static vector float __ATTRS_o_ai vec_lvlxl(int __a, vector float *__b) { return vec_perm(vec_ldl(__a, __b), (vector float)(0), vec_lvsl(__a, (unsigned char *)__b)); } /* vec_lvrx */ static vector signed char __ATTRS_o_ai vec_lvrx(int __a, const signed char *__b) { return vec_perm((vector signed char)(0), vec_ld(__a, __b), vec_lvsl(__a, __b)); } static vector signed char __ATTRS_o_ai vec_lvrx(int __a, const vector signed char *__b) { return vec_perm((vector signed char)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned char __ATTRS_o_ai vec_lvrx(int __a, const unsigned char *__b) { return vec_perm((vector unsigned char)(0), vec_ld(__a, __b), vec_lvsl(__a, __b)); } static vector unsigned char __ATTRS_o_ai vec_lvrx(int __a, const vector unsigned char *__b) { return vec_perm((vector unsigned char)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool char __ATTRS_o_ai vec_lvrx(int __a, const vector bool char *__b) { return vec_perm((vector bool char)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector short __ATTRS_o_ai vec_lvrx(int __a, const short *__b) { return vec_perm((vector short)(0), vec_ld(__a, __b), vec_lvsl(__a, __b)); } static vector short __ATTRS_o_ai vec_lvrx(int __a, const vector short *__b) { return vec_perm((vector short)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned short __ATTRS_o_ai vec_lvrx(int __a, const unsigned short *__b) { return vec_perm((vector unsigned short)(0), vec_ld(__a, __b), vec_lvsl(__a, __b)); } static vector unsigned short __ATTRS_o_ai vec_lvrx(int __a, const vector unsigned short *__b) { return vec_perm((vector unsigned short)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool short __ATTRS_o_ai vec_lvrx(int __a, const vector bool short *__b) { return vec_perm((vector bool short)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector pixel __ATTRS_o_ai vec_lvrx(int __a, const vector pixel *__b) { return vec_perm((vector pixel)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector int __ATTRS_o_ai vec_lvrx(int __a, const int *__b) { return vec_perm((vector int)(0), vec_ld(__a, __b), vec_lvsl(__a, __b)); } static vector int __ATTRS_o_ai vec_lvrx(int __a, const vector int *__b) { return vec_perm((vector int)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned int __ATTRS_o_ai vec_lvrx(int __a, const unsigned int *__b) { return vec_perm((vector unsigned int)(0), vec_ld(__a, __b), vec_lvsl(__a, __b)); } static vector unsigned int __ATTRS_o_ai vec_lvrx(int __a, const vector unsigned int *__b) { return vec_perm((vector unsigned int)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool int __ATTRS_o_ai vec_lvrx(int __a, const vector bool int *__b) { return vec_perm((vector bool int)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector float __ATTRS_o_ai vec_lvrx(int __a, const float *__b) { return vec_perm((vector float)(0), vec_ld(__a, __b), vec_lvsl(__a, __b)); } static vector float __ATTRS_o_ai vec_lvrx(int __a, const vector float *__b) { return vec_perm((vector float)(0), vec_ld(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } /* vec_lvrxl */ static vector signed char __ATTRS_o_ai vec_lvrxl(int __a, const signed char *__b) { return vec_perm((vector signed char)(0), vec_ldl(__a, __b), vec_lvsl(__a, __b)); } static vector signed char __ATTRS_o_ai vec_lvrxl(int __a, const vector signed char *__b) { return vec_perm((vector signed char)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned char __ATTRS_o_ai vec_lvrxl(int __a, const unsigned char *__b) { return vec_perm((vector unsigned char)(0), vec_ldl(__a, __b), vec_lvsl(__a, __b)); } static vector unsigned char __ATTRS_o_ai vec_lvrxl(int __a, const vector unsigned char *__b) { return vec_perm((vector unsigned char)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool char __ATTRS_o_ai vec_lvrxl(int __a, const vector bool char *__b) { return vec_perm((vector bool char)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector short __ATTRS_o_ai vec_lvrxl(int __a, const short *__b) { return vec_perm((vector short)(0), vec_ldl(__a, __b), vec_lvsl(__a, __b)); } static vector short __ATTRS_o_ai vec_lvrxl(int __a, const vector short *__b) { return vec_perm((vector short)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned short __ATTRS_o_ai vec_lvrxl(int __a, const unsigned short *__b) { return vec_perm((vector unsigned short)(0), vec_ldl(__a, __b), vec_lvsl(__a, __b)); } static vector unsigned short __ATTRS_o_ai vec_lvrxl(int __a, const vector unsigned short *__b) { return vec_perm((vector unsigned short)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool short __ATTRS_o_ai vec_lvrxl(int __a, const vector bool short *__b) { return vec_perm((vector bool short)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector pixel __ATTRS_o_ai vec_lvrxl(int __a, const vector pixel *__b) { return vec_perm((vector pixel)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector int __ATTRS_o_ai vec_lvrxl(int __a, const int *__b) { return vec_perm((vector int)(0), vec_ldl(__a, __b), vec_lvsl(__a, __b)); } static vector int __ATTRS_o_ai vec_lvrxl(int __a, const vector int *__b) { return vec_perm((vector int)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector unsigned int __ATTRS_o_ai vec_lvrxl(int __a, const unsigned int *__b) { return vec_perm((vector unsigned int)(0), vec_ldl(__a, __b), vec_lvsl(__a, __b)); } static vector unsigned int __ATTRS_o_ai vec_lvrxl(int __a, const vector unsigned int *__b) { return vec_perm((vector unsigned int)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector bool int __ATTRS_o_ai vec_lvrxl(int __a, const vector bool int *__b) { return vec_perm((vector bool int)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } static vector float __ATTRS_o_ai vec_lvrxl(int __a, const float *__b) { return vec_perm((vector float)(0), vec_ldl(__a, __b), vec_lvsl(__a, __b)); } static vector float __ATTRS_o_ai vec_lvrxl(int __a, const vector float *__b) { return vec_perm((vector float)(0), vec_ldl(__a, __b), vec_lvsl(__a, (unsigned char *)__b)); } /* vec_stvlx */ static void __ATTRS_o_ai vec_stvlx(vector signed char __a, int __b, signed char *__c) { return vec_st(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector signed char __a, int __b, vector signed char *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector unsigned char __a, int __b, unsigned char *__c) { return vec_st(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector unsigned char __a, int __b, vector unsigned char *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector bool char __a, int __b, vector bool char *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector short __a, int __b, short *__c) { return vec_st(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector short __a, int __b, vector short *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector unsigned short __a, int __b, unsigned short *__c) { return vec_st(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector unsigned short __a, int __b, vector unsigned short *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector bool short __a, int __b, vector bool short *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector pixel __a, int __b, vector pixel *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector int __a, int __b, int *__c) { return vec_st(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector int __a, int __b, vector int *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector unsigned int __a, int __b, unsigned int *__c) { return vec_st(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector unsigned int __a, int __b, vector unsigned int *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector bool int __a, int __b, vector bool int *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlx(vector float __a, int __b, vector float *__c) { return vec_st( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } /* vec_stvlxl */ static void __ATTRS_o_ai vec_stvlxl(vector signed char __a, int __b, signed char *__c) { return vec_stl(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector signed char __a, int __b, vector signed char *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector unsigned char __a, int __b, unsigned char *__c) { return vec_stl(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector unsigned char __a, int __b, vector unsigned char *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector bool char __a, int __b, vector bool char *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector short __a, int __b, short *__c) { return vec_stl(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector short __a, int __b, vector short *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector unsigned short __a, int __b, unsigned short *__c) { return vec_stl(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector unsigned short __a, int __b, vector unsigned short *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector bool short __a, int __b, vector bool short *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector pixel __a, int __b, vector pixel *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector int __a, int __b, int *__c) { return vec_stl(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector int __a, int __b, vector int *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector unsigned int __a, int __b, unsigned int *__c) { return vec_stl(vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector unsigned int __a, int __b, vector unsigned int *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector bool int __a, int __b, vector bool int *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvlxl(vector float __a, int __b, vector float *__c) { return vec_stl( vec_perm(vec_lvrx(__b, __c), __a, vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } /* vec_stvrx */ static void __ATTRS_o_ai vec_stvrx(vector signed char __a, int __b, signed char *__c) { return vec_st(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector signed char __a, int __b, vector signed char *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector unsigned char __a, int __b, unsigned char *__c) { return vec_st(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector unsigned char __a, int __b, vector unsigned char *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector bool char __a, int __b, vector bool char *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector short __a, int __b, short *__c) { return vec_st(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector short __a, int __b, vector short *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector unsigned short __a, int __b, unsigned short *__c) { return vec_st(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector unsigned short __a, int __b, vector unsigned short *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector bool short __a, int __b, vector bool short *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector pixel __a, int __b, vector pixel *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector int __a, int __b, int *__c) { return vec_st(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector int __a, int __b, vector int *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector unsigned int __a, int __b, unsigned int *__c) { return vec_st(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector unsigned int __a, int __b, vector unsigned int *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector bool int __a, int __b, vector bool int *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrx(vector float __a, int __b, vector float *__c) { return vec_st( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } /* vec_stvrxl */ static void __ATTRS_o_ai vec_stvrxl(vector signed char __a, int __b, signed char *__c) { return vec_stl(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector signed char __a, int __b, vector signed char *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector unsigned char __a, int __b, unsigned char *__c) { return vec_stl(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector unsigned char __a, int __b, vector unsigned char *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector bool char __a, int __b, vector bool char *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector short __a, int __b, short *__c) { return vec_stl(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector short __a, int __b, vector short *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector unsigned short __a, int __b, unsigned short *__c) { return vec_stl(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector unsigned short __a, int __b, vector unsigned short *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector bool short __a, int __b, vector bool short *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector pixel __a, int __b, vector pixel *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector int __a, int __b, int *__c) { return vec_stl(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector int __a, int __b, vector int *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector unsigned int __a, int __b, unsigned int *__c) { return vec_stl(vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, __c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector unsigned int __a, int __b, vector unsigned int *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector bool int __a, int __b, vector bool int *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } static void __ATTRS_o_ai vec_stvrxl(vector float __a, int __b, vector float *__c) { return vec_stl( vec_perm(__a, vec_lvlx(__b, __c), vec_lvsr(__b, (unsigned char *)__c)), __b, __c); } /* vec_promote */ static vector signed char __ATTRS_o_ai vec_promote(signed char __a, int __b) { vector signed char __res = (vector signed char)(0); __res[__b] = __a; return __res; } static vector unsigned char __ATTRS_o_ai vec_promote(unsigned char __a, int __b) { vector unsigned char __res = (vector unsigned char)(0); __res[__b] = __a; return __res; } static vector short __ATTRS_o_ai vec_promote(short __a, int __b) { vector short __res = (vector short)(0); __res[__b] = __a; return __res; } static vector unsigned short __ATTRS_o_ai vec_promote(unsigned short __a, int __b) { vector unsigned short __res = (vector unsigned short)(0); __res[__b] = __a; return __res; } static vector int __ATTRS_o_ai vec_promote(int __a, int __b) { vector int __res = (vector int)(0); __res[__b] = __a; return __res; } static vector unsigned int __ATTRS_o_ai vec_promote(unsigned int __a, int __b) { vector unsigned int __res = (vector unsigned int)(0); __res[__b] = __a; return __res; } static vector float __ATTRS_o_ai vec_promote(float __a, int __b) { vector float __res = (vector float)(0); __res[__b] = __a; return __res; } /* vec_splats */ static vector signed char __ATTRS_o_ai vec_splats(signed char __a) { return (vector signed char)(__a); } static vector unsigned char __ATTRS_o_ai vec_splats(unsigned char __a) { return (vector unsigned char)(__a); } static vector short __ATTRS_o_ai vec_splats(short __a) { return (vector short)(__a); } static vector unsigned short __ATTRS_o_ai vec_splats(unsigned short __a) { return (vector unsigned short)(__a); } static vector int __ATTRS_o_ai vec_splats(int __a) { return (vector int)(__a); } static vector unsigned int __ATTRS_o_ai vec_splats(unsigned int __a) { return (vector unsigned int)(__a); } static vector float __ATTRS_o_ai vec_splats(float __a) { return (vector float)(__a); } /* ----------------------------- predicates --------------------------------- */ /* vec_all_eq */ static int __ATTRS_o_ai vec_all_eq(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_eq(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_eq(vector short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_eq(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, __a, (vector short)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_eq(vector pixel __a, vector pixel __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_eq(vector int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_eq(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT, __a, (vector int)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT, (vector int)__a, (vector int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_all_eq(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_eq(vector long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT, __a, (vector long long)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT, (vector long long)__a, (vector long long)__b); } static int __ATTRS_o_ai vec_all_eq(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT, (vector long long)__a, (vector long long)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool long long __a, vector long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT, (vector long long)__a, (vector long long)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT, (vector long long)__a, (vector long long)__b); } static int __ATTRS_o_ai vec_all_eq(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT, (vector long long)__a, (vector long long)__b); } #endif static int __ATTRS_o_ai vec_all_eq(vector float __a, vector float __b) { return __builtin_altivec_vcmpeqfp_p(__CR6_LT, __a, __b); } /* vec_all_ge */ static int __ATTRS_o_ai vec_all_ge(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ, (vector signed char)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, (vector unsigned char)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, __b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_all_ge(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ, (vector short)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, (vector unsigned short)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, __b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_all_ge(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ, (vector int)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, (vector unsigned int)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, (vector unsigned int)__b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, __b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, (vector unsigned int)__b, (vector unsigned int)__a); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_all_ge(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ, (vector signed long long)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, __b, __a); } static int __ATTRS_o_ai vec_all_ge(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, (vector unsigned long long)__b, __a); } static int __ATTRS_o_ai vec_all_ge(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, (vector unsigned long long)__b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, __b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_all_ge(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, (vector unsigned long long)__b, (vector unsigned long long)__a); } #endif static int __ATTRS_o_ai vec_all_ge(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_LT, __a, __b); } /* vec_all_gt */ static int __ATTRS_o_ai vec_all_gt(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT, __a, (vector signed char)__b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, __a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, (vector unsigned char)__a, __b); } static int __ATTRS_o_ai vec_all_gt(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_all_gt(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT, __a, (vector short)__b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, __a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, (vector unsigned short)__a, __b); } static int __ATTRS_o_ai vec_all_gt(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_all_gt(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT, __a, (vector int)__b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, __a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, (vector unsigned int)__a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, (vector unsigned int)__a, __b); } static int __ATTRS_o_ai vec_all_gt(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, (vector unsigned int)__a, (vector unsigned int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_all_gt(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT, __a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, __a, __b); } static int __ATTRS_o_ai vec_all_gt(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, __a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, (vector unsigned long long)__a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_all_gt(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, (vector unsigned long long)__a, __b); } static int __ATTRS_o_ai vec_all_gt(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, (vector unsigned long long)__a, (vector unsigned long long)__b); } #endif static int __ATTRS_o_ai vec_all_gt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_LT, __a, __b); } /* vec_all_in */ static int __attribute__((__always_inline__)) vec_all_in(vector float __a, vector float __b) { return __builtin_altivec_vcmpbfp_p(__CR6_EQ, __a, __b); } /* vec_all_le */ static int __ATTRS_o_ai vec_all_le(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ, __a, (vector signed char)__b); } static int __ATTRS_o_ai vec_all_le(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, __a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_all_le(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_all_le(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, (vector unsigned char)__a, __b); } static int __ATTRS_o_ai vec_all_le(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_all_le(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ, __a, (vector short)__b); } static int __ATTRS_o_ai vec_all_le(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, __a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_all_le(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_all_le(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, (vector unsigned short)__a, __b); } static int __ATTRS_o_ai vec_all_le(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_all_le(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ, __a, (vector int)__b); } static int __ATTRS_o_ai vec_all_le(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, __a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_all_le(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, (vector unsigned int)__a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_all_le(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, (vector unsigned int)__a, __b); } static int __ATTRS_o_ai vec_all_le(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ, (vector unsigned int)__a, (vector unsigned int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_all_le(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_le(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ, __a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_all_le(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, __a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_all_le(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, (vector unsigned long long)__a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_all_le(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, (vector unsigned long long)__a, __b); } static int __ATTRS_o_ai vec_all_le(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ, (vector unsigned long long)__a, (vector unsigned long long)__b); } #endif static int __ATTRS_o_ai vec_all_le(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_LT, __b, __a); } /* vec_all_lt */ static int __ATTRS_o_ai vec_all_lt(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT, (vector signed char)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, (vector unsigned char)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, __b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_all_lt(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT, (vector short)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, (vector unsigned short)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, __b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_all_lt(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT, (vector int)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, (vector unsigned int)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, (vector unsigned int)__b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, __b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT, (vector unsigned int)__b, (vector unsigned int)__a); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_all_lt(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, __b, __a); } static int __ATTRS_o_ai vec_all_lt(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT, (vector signed long long)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, (vector unsigned long long)__b, __a); } static int __ATTRS_o_ai vec_all_lt(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, (vector unsigned long long)__b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, __b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_all_lt(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT, (vector unsigned long long)__b, (vector unsigned long long)__a); } #endif static int __ATTRS_o_ai vec_all_lt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_LT, __b, __a); } /* vec_all_nan */ static int __attribute__((__always_inline__)) vec_all_nan(vector float __a) { return __builtin_altivec_vcmpeqfp_p(__CR6_EQ, __a, __a); } /* vec_all_ne */ static int __ATTRS_o_ai vec_all_ne(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_ne(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_all_ne(vector short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_ne(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, __a, (vector short)__b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_ne(vector pixel __a, vector pixel __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_all_ne(vector int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_ne(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ, __a, (vector int)__b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ, (vector int)__a, (vector int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_all_ne(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ, __a, __b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ, (vector long long)__a, (vector long long)__b); } static int __ATTRS_o_ai vec_all_ne(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ, __a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_all_ne(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_all_ne(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ, (vector signed long long)__a, (vector signed long long)__b); } #endif static int __ATTRS_o_ai vec_all_ne(vector float __a, vector float __b) { return __builtin_altivec_vcmpeqfp_p(__CR6_EQ, __a, __b); } /* vec_all_nge */ static int __attribute__((__always_inline__)) vec_all_nge(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_EQ, __a, __b); } /* vec_all_ngt */ static int __attribute__((__always_inline__)) vec_all_ngt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_EQ, __a, __b); } /* vec_all_nle */ static int __attribute__((__always_inline__)) vec_all_nle(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_EQ, __b, __a); } /* vec_all_nlt */ static int __attribute__((__always_inline__)) vec_all_nlt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_EQ, __b, __a); } /* vec_all_numeric */ static int __attribute__((__always_inline__)) vec_all_numeric(vector float __a) { return __builtin_altivec_vcmpeqfp_p(__CR6_LT, __a, __a); } /* vec_any_eq */ static int __ATTRS_o_ai vec_any_eq(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_eq(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_EQ_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_eq(vector short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_eq(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, __a, (vector short)__b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_eq(vector pixel __a, vector pixel __b) { return __builtin_altivec_vcmpequh_p(__CR6_EQ_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_eq(vector int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_eq(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ_REV, __a, (vector int)__b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_EQ_REV, (vector int)__a, (vector int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_any_eq(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ_REV, (vector long long)__a, (vector long long)__b); } static int __ATTRS_o_ai vec_any_eq(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_EQ_REV, __a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_eq(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_EQ_REV, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_EQ_REV, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_EQ_REV, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_eq(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_EQ_REV, (vector signed long long)__a, (vector signed long long)__b); } #endif static int __ATTRS_o_ai vec_any_eq(vector float __a, vector float __b) { return __builtin_altivec_vcmpeqfp_p(__CR6_EQ_REV, __a, __b); } /* vec_any_ge */ static int __ATTRS_o_ai vec_any_ge(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT_REV, (vector signed char)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, (vector unsigned char)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, __b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_any_ge(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT_REV, (vector short)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, (vector unsigned short)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, __b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_any_ge(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT_REV, (vector int)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, (vector unsigned int)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, (vector unsigned int)__b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, __b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, (vector unsigned int)__b, (vector unsigned int)__a); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_any_ge(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, __b, __a); } static int __ATTRS_o_ai vec_any_ge(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT_REV, (vector signed long long)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, (vector unsigned long long)__b, __a); } static int __ATTRS_o_ai vec_any_ge(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, (vector unsigned long long)__b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, __b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_any_ge(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, (vector unsigned long long)__b, (vector unsigned long long)__a); } #endif static int __ATTRS_o_ai vec_any_ge(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_EQ_REV, __a, __b); } /* vec_any_gt */ static int __ATTRS_o_ai vec_any_gt(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ_REV, __a, (vector signed char)__b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, __a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, (vector unsigned char)__a, __b); } static int __ATTRS_o_ai vec_any_gt(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_any_gt(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ_REV, __a, (vector short)__b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, __a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, (vector unsigned short)__a, __b); } static int __ATTRS_o_ai vec_any_gt(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_any_gt(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ_REV, __a, (vector int)__b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, __a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, (vector unsigned int)__a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, (vector unsigned int)__a, __b); } static int __ATTRS_o_ai vec_any_gt(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, (vector unsigned int)__a, (vector unsigned int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_any_gt(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, __a, __b); } static int __ATTRS_o_ai vec_any_gt(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ_REV, __a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_gt(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, __a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, (vector unsigned long long)__a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_any_gt(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, (vector unsigned long long)__a, __b); } static int __ATTRS_o_ai vec_any_gt(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, (vector unsigned long long)__a, (vector unsigned long long)__b); } #endif static int __ATTRS_o_ai vec_any_gt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_EQ_REV, __a, __b); } /* vec_any_le */ static int __ATTRS_o_ai vec_any_le(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_LT_REV, __a, (vector signed char)__b); } static int __ATTRS_o_ai vec_any_le(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, __a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_any_le(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_any_le(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, (vector unsigned char)__a, __b); } static int __ATTRS_o_ai vec_any_le(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_LT_REV, (vector unsigned char)__a, (vector unsigned char)__b); } static int __ATTRS_o_ai vec_any_le(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_LT_REV, __a, (vector short)__b); } static int __ATTRS_o_ai vec_any_le(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, __a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_any_le(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_any_le(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, (vector unsigned short)__a, __b); } static int __ATTRS_o_ai vec_any_le(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_LT_REV, (vector unsigned short)__a, (vector unsigned short)__b); } static int __ATTRS_o_ai vec_any_le(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_LT_REV, __a, (vector int)__b); } static int __ATTRS_o_ai vec_any_le(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, __a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_any_le(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, (vector unsigned int)__a, (vector unsigned int)__b); } static int __ATTRS_o_ai vec_any_le(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, (vector unsigned int)__a, __b); } static int __ATTRS_o_ai vec_any_le(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_LT_REV, (vector unsigned int)__a, (vector unsigned int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_any_le(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_le(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_LT_REV, __a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_le(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, __a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_any_le(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, (vector unsigned long long)__a, (vector unsigned long long)__b); } static int __ATTRS_o_ai vec_any_le(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, (vector unsigned long long)__a, __b); } static int __ATTRS_o_ai vec_any_le(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_LT_REV, (vector unsigned long long)__a, (vector unsigned long long)__b); } #endif static int __ATTRS_o_ai vec_any_le(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_EQ_REV, __b, __a); } /* vec_any_lt */ static int __ATTRS_o_ai vec_any_lt(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpgtsb_p(__CR6_EQ_REV, (vector signed char)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, (vector unsigned char)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, __b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpgtub_p(__CR6_EQ_REV, (vector unsigned char)__b, (vector unsigned char)__a); } static int __ATTRS_o_ai vec_any_lt(vector short __a, vector short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpgtsh_p(__CR6_EQ_REV, (vector short)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, (vector unsigned short)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, __b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpgtuh_p(__CR6_EQ_REV, (vector unsigned short)__b, (vector unsigned short)__a); } static int __ATTRS_o_ai vec_any_lt(vector int __a, vector int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpgtsw_p(__CR6_EQ_REV, (vector int)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, (vector unsigned int)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, (vector unsigned int)__b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, __b, (vector unsigned int)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpgtuw_p(__CR6_EQ_REV, (vector unsigned int)__b, (vector unsigned int)__a); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_any_lt(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, __b, __a); } static int __ATTRS_o_ai vec_any_lt(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtsd_p(__CR6_EQ_REV, (vector signed long long)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, (vector unsigned long long)__b, __a); } static int __ATTRS_o_ai vec_any_lt(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, (vector unsigned long long)__b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, __b, (vector unsigned long long)__a); } static int __ATTRS_o_ai vec_any_lt(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpgtud_p(__CR6_EQ_REV, (vector unsigned long long)__b, (vector unsigned long long)__a); } #endif static int __ATTRS_o_ai vec_any_lt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_EQ_REV, __b, __a); } /* vec_any_nan */ static int __attribute__((__always_inline__)) vec_any_nan(vector float __a) { return __builtin_altivec_vcmpeqfp_p(__CR6_LT_REV, __a, __a); } /* vec_any_ne */ static int __ATTRS_o_ai vec_any_ne(vector signed char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_ne(vector signed char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool char __a, vector signed char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool char __a, vector unsigned char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool char __a, vector bool char __b) { return __builtin_altivec_vcmpequb_p(__CR6_LT_REV, (vector char)__a, (vector char)__b); } static int __ATTRS_o_ai vec_any_ne(vector short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_ne(vector short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, __a, (vector short)__b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool short __a, vector short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool short __a, vector unsigned short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool short __a, vector bool short __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_ne(vector pixel __a, vector pixel __b) { return __builtin_altivec_vcmpequh_p(__CR6_LT_REV, (vector short)__a, (vector short)__b); } static int __ATTRS_o_ai vec_any_ne(vector int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_ne(vector int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT_REV, __a, (vector int)__b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool int __a, vector int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool int __a, vector unsigned int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT_REV, (vector int)__a, (vector int)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool int __a, vector bool int __b) { return __builtin_altivec_vcmpequw_p(__CR6_LT_REV, (vector int)__a, (vector int)__b); } #ifdef __POWER8_VECTOR__ static int __ATTRS_o_ai vec_any_ne(vector signed long long __a, vector signed long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT_REV, __a, __b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT_REV, (vector long long)__a, (vector long long)__b); } static int __ATTRS_o_ai vec_any_ne(vector signed long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p(__CR6_LT_REV, __a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_ne(vector unsigned long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_LT_REV, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool long long __a, vector signed long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_LT_REV, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool long long __a, vector unsigned long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_LT_REV, (vector signed long long)__a, (vector signed long long)__b); } static int __ATTRS_o_ai vec_any_ne(vector bool long long __a, vector bool long long __b) { return __builtin_altivec_vcmpequd_p( __CR6_LT_REV, (vector signed long long)__a, (vector signed long long)__b); } #endif static int __ATTRS_o_ai vec_any_ne(vector float __a, vector float __b) { return __builtin_altivec_vcmpeqfp_p(__CR6_LT_REV, __a, __b); } /* vec_any_nge */ static int __attribute__((__always_inline__)) vec_any_nge(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_LT_REV, __a, __b); } /* vec_any_ngt */ static int __attribute__((__always_inline__)) vec_any_ngt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_LT_REV, __a, __b); } /* vec_any_nle */ static int __attribute__((__always_inline__)) vec_any_nle(vector float __a, vector float __b) { return __builtin_altivec_vcmpgefp_p(__CR6_LT_REV, __b, __a); } /* vec_any_nlt */ static int __attribute__((__always_inline__)) vec_any_nlt(vector float __a, vector float __b) { return __builtin_altivec_vcmpgtfp_p(__CR6_LT_REV, __b, __a); } /* vec_any_numeric */ static int __attribute__((__always_inline__)) vec_any_numeric(vector float __a) { return __builtin_altivec_vcmpeqfp_p(__CR6_EQ_REV, __a, __a); } /* vec_any_out */ static int __attribute__((__always_inline__)) vec_any_out(vector float __a, vector float __b) { return __builtin_altivec_vcmpbfp_p(__CR6_EQ_REV, __a, __b); } /* Power 8 Crypto functions Note: We diverge from the current GCC implementation with regard to cryptography and related functions as follows: - Only the SHA and AES instructions and builtins are disabled by -mno-crypto - The remaining ones are only available on Power8 and up so require -mpower8-vector The justification for this is that export requirements require that Category:Vector.Crypto is optional (i.e. compliant hardware may not provide support). As a result, we need to be able to turn off support for those. The remaining ones (currently controlled by -mcrypto for GCC) still need to be provided on compliant hardware even if Vector.Crypto is not provided. FIXME: the naming convention for the builtins will be adjusted due to the inconsistency (__builtin_crypto_ prefix on builtins that cannot be removed with -mno-crypto). This is under development. */ #ifdef __CRYPTO__ static vector unsigned long long __attribute__((__always_inline__)) __builtin_crypto_vsbox(vector unsigned long long __a) { return __builtin_altivec_crypto_vsbox(__a); } static vector unsigned long long __attribute__((__always_inline__)) __builtin_crypto_vcipher(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_crypto_vcipher(__a, __b); } static vector unsigned long long __attribute__((__always_inline__)) __builtin_crypto_vcipherlast(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_crypto_vcipherlast(__a, __b); } static vector unsigned long long __attribute__((__always_inline__)) __builtin_crypto_vncipher(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_crypto_vncipher(__a, __b); } static vector unsigned long long __attribute__((__always_inline__)) __builtin_crypto_vncipherlast(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_crypto_vncipherlast(__a, __b); } #define __builtin_crypto_vshasigmad __builtin_altivec_crypto_vshasigmad #define __builtin_crypto_vshasigmaw __builtin_altivec_crypto_vshasigmaw #endif #ifdef __POWER8_VECTOR__ static vector unsigned char __ATTRS_o_ai __builtin_crypto_vpermxor(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_altivec_crypto_vpermxor(__a, __b, __c); } static vector unsigned short __ATTRS_o_ai __builtin_crypto_vpermxor(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return (vector unsigned short)__builtin_altivec_crypto_vpermxor( (vector unsigned char)__a, (vector unsigned char)__b, (vector unsigned char)__c); } static vector unsigned int __ATTRS_o_ai __builtin_crypto_vpermxor( vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return (vector unsigned int)__builtin_altivec_crypto_vpermxor( (vector unsigned char)__a, (vector unsigned char)__b, (vector unsigned char)__c); } static vector unsigned long long __ATTRS_o_ai __builtin_crypto_vpermxor( vector unsigned long long __a, vector unsigned long long __b, vector unsigned long long __c) { return (vector unsigned long long)__builtin_altivec_crypto_vpermxor( (vector unsigned char)__a, (vector unsigned char)__b, (vector unsigned char)__c); } static vector unsigned char __ATTRS_o_ai __builtin_crypto_vpmsumb(vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_crypto_vpmsumb(__a, __b); } static vector unsigned short __ATTRS_o_ai __builtin_crypto_vpmsumb(vector unsigned short __a, vector unsigned short __b) { return __builtin_altivec_crypto_vpmsumh(__a, __b); } static vector unsigned int __ATTRS_o_ai __builtin_crypto_vpmsumb(vector unsigned int __a, vector unsigned int __b) { return __builtin_altivec_crypto_vpmsumw(__a, __b); } static vector unsigned long long __ATTRS_o_ai __builtin_crypto_vpmsumb( vector unsigned long long __a, vector unsigned long long __b) { return __builtin_altivec_crypto_vpmsumd(__a, __b); } static vector signed char __ATTRS_o_ai vec_vgbbd (vector signed char __a) { return __builtin_altivec_vgbbd((vector unsigned char) __a); } static vector unsigned char __ATTRS_o_ai vec_vgbbd (vector unsigned char __a) { return __builtin_altivec_vgbbd(__a); } static vector long long __ATTRS_o_ai vec_vbpermq (vector signed char __a, vector signed char __b) { return __builtin_altivec_vbpermq((vector unsigned char) __a, (vector unsigned char) __b); } static vector long long __ATTRS_o_ai vec_vbpermq (vector unsigned char __a, vector unsigned char __b) { return __builtin_altivec_vbpermq(__a, __b); } #endif #undef __ATTRS_o_ai #endif /* __ALTIVEC_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/Intrin.h
/* ===-------- Intrin.h ---------------------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ /* Only include this if we're compiling for the windows platform. */ #ifndef _MSC_VER #include_next <Intrin.h> #else #ifndef __INTRIN_H #define __INTRIN_H /* First include the standard intrinsics. */ #if defined(__i386__) || defined(__x86_64__) #include <x86intrin.h> #endif /* For the definition of jmp_buf. */ #if __STDC_HOSTED__ #include <setjmp.h> #endif /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) #ifdef __cplusplus extern "C" { #endif #if defined(__MMX__) /* And the random ones that aren't in those files. */ __m64 _m_from_float(float); __m64 _m_from_int(int _l); void _m_prefetch(void *); float _m_to_float(__m64); int _m_to_int(__m64 _M); #endif /* Other assorted instruction intrinsics. */ void __addfsbyte(unsigned long, unsigned char); void __addfsdword(unsigned long, unsigned long); void __addfsword(unsigned long, unsigned short); void __code_seg(const char *); static __inline__ void __cpuid(int[4], int); static __inline__ void __cpuidex(int[4], int, int); void __debugbreak(void); __int64 __emul(int, int); unsigned __int64 __emulu(unsigned int, unsigned int); void __cdecl __fastfail(unsigned int); unsigned int __getcallerseflags(void); static __inline__ void __halt(void); unsigned char __inbyte(unsigned short); void __inbytestring(unsigned short, unsigned char *, unsigned long); void __incfsbyte(unsigned long); void __incfsdword(unsigned long); void __incfsword(unsigned long); unsigned long __indword(unsigned short); void __indwordstring(unsigned short, unsigned long *, unsigned long); void __int2c(void); void __invlpg(void *); unsigned short __inword(unsigned short); void __inwordstring(unsigned short, unsigned short *, unsigned long); void __lidt(void *); unsigned __int64 __ll_lshift(unsigned __int64, int); __int64 __ll_rshift(__int64, int); void __llwpcb(void *); unsigned char __lwpins32(unsigned int, unsigned int, unsigned int); void __lwpval32(unsigned int, unsigned int, unsigned int); unsigned int __lzcnt(unsigned int); unsigned short __lzcnt16(unsigned short); static __inline__ void __movsb(unsigned char *, unsigned char const *, size_t); static __inline__ void __movsd(unsigned long *, unsigned long const *, size_t); static __inline__ void __movsw(unsigned short *, unsigned short const *, size_t); void __nop(void); void __nvreg_restore_fence(void); void __nvreg_save_fence(void); void __outbyte(unsigned short, unsigned char); void __outbytestring(unsigned short, unsigned char *, unsigned long); void __outdword(unsigned short, unsigned long); void __outdwordstring(unsigned short, unsigned long *, unsigned long); void __outword(unsigned short, unsigned short); void __outwordstring(unsigned short, unsigned short *, unsigned long); static __inline__ unsigned int __popcnt(unsigned int); static __inline__ unsigned short __popcnt16(unsigned short); unsigned long __readcr0(void); unsigned long __readcr2(void); static __inline__ unsigned long __readcr3(void); unsigned long __readcr4(void); unsigned long __readcr8(void); unsigned int __readdr(unsigned int); #ifdef __i386__ static __inline__ unsigned char __readfsbyte(unsigned long); static __inline__ unsigned long __readfsdword(unsigned long); static __inline__ unsigned __int64 __readfsqword(unsigned long); static __inline__ unsigned short __readfsword(unsigned long); #endif static __inline__ unsigned __int64 __readmsr(unsigned long); unsigned __int64 __readpmc(unsigned long); unsigned long __segmentlimit(unsigned long); void __sidt(void *); void *__slwpcb(void); static __inline__ void __stosb(unsigned char *, unsigned char, size_t); static __inline__ void __stosd(unsigned long *, unsigned long, size_t); static __inline__ void __stosw(unsigned short *, unsigned short, size_t); void __svm_clgi(void); void __svm_invlpga(void *, int); void __svm_skinit(int); void __svm_stgi(void); void __svm_vmload(size_t); void __svm_vmrun(size_t); void __svm_vmsave(size_t); void __ud2(void); unsigned __int64 __ull_rshift(unsigned __int64, int); void __vmx_off(void); void __vmx_vmptrst(unsigned __int64 *); void __wbinvd(void); void __writecr0(unsigned int); static __inline__ void __writecr3(unsigned int); void __writecr4(unsigned int); void __writecr8(unsigned int); void __writedr(unsigned int, unsigned int); void __writefsbyte(unsigned long, unsigned char); void __writefsdword(unsigned long, unsigned long); void __writefsqword(unsigned long, unsigned __int64); void __writefsword(unsigned long, unsigned short); void __writemsr(unsigned long, unsigned __int64); static __inline__ void *_AddressOfReturnAddress(void); static __inline__ unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask); static __inline__ unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask); static __inline__ unsigned char _bittest(long const *, long); static __inline__ unsigned char _bittestandcomplement(long *, long); static __inline__ unsigned char _bittestandreset(long *, long); static __inline__ unsigned char _bittestandset(long *, long); unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); unsigned long __cdecl _byteswap_ulong(unsigned long); unsigned short __cdecl _byteswap_ushort(unsigned short); void __cdecl _disable(void); void __cdecl _enable(void); long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value); static __inline__ long _InterlockedAnd(long volatile *_Value, long _Mask); static __inline__ short _InterlockedAnd16(short volatile *_Value, short _Mask); static __inline__ char _InterlockedAnd8(char volatile *_Value, char _Mask); unsigned char _interlockedbittestandreset(long volatile *, long); static __inline__ unsigned char _interlockedbittestandset(long volatile *, long); static __inline__ long __cdecl _InterlockedCompareExchange(long volatile *_Destination, long _Exchange, long _Comparand); long _InterlockedCompareExchange_HLEAcquire(long volatile *, long, long); long _InterlockedCompareExchange_HLERelease(long volatile *, long, long); static __inline__ short _InterlockedCompareExchange16(short volatile *_Destination, short _Exchange, short _Comparand); static __inline__ __int64 _InterlockedCompareExchange64(__int64 volatile *_Destination, __int64 _Exchange, __int64 _Comparand); __int64 _InterlockedcompareExchange64_HLEAcquire(__int64 volatile *, __int64, __int64); __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64, __int64); static __inline__ char _InterlockedCompareExchange8(char volatile *_Destination, char _Exchange, char _Comparand); void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *, void *); void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *, void *); static __inline__ long __cdecl _InterlockedDecrement(long volatile *_Addend); static __inline__ short _InterlockedDecrement16(short volatile *_Addend); long _InterlockedExchange(long volatile *_Target, long _Value); static __inline__ short _InterlockedExchange16(short volatile *_Target, short _Value); static __inline__ char _InterlockedExchange8(char volatile *_Target, char _Value); static __inline__ long __cdecl _InterlockedExchangeAdd(long volatile *_Addend, long _Value); long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long); long _InterlockedExchangeAdd_HLERelease(long volatile *, long); static __inline__ short _InterlockedExchangeAdd16(short volatile *_Addend, short _Value); __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64); __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64); static __inline__ char _InterlockedExchangeAdd8(char volatile *_Addend, char _Value); static __inline__ long __cdecl _InterlockedIncrement(long volatile *_Addend); static __inline__ short _InterlockedIncrement16(short volatile *_Addend); static __inline__ long _InterlockedOr(long volatile *_Value, long _Mask); static __inline__ short _InterlockedOr16(short volatile *_Value, short _Mask); static __inline__ char _InterlockedOr8(char volatile *_Value, char _Mask); static __inline__ long _InterlockedXor(long volatile *_Value, long _Mask); static __inline__ short _InterlockedXor16(short volatile *_Value, short _Mask); static __inline__ char _InterlockedXor8(char volatile *_Value, char _Mask); void __cdecl _invpcid(unsigned int, void *); static __inline__ unsigned long __cdecl _lrotl(unsigned long, int); static __inline__ unsigned long __cdecl _lrotr(unsigned long, int); static __inline__ static __inline__ void _ReadBarrier(void); static __inline__ void _ReadWriteBarrier(void); static __inline__ void *_ReturnAddress(void); unsigned int _rorx_u32(unsigned int, const unsigned int); static __inline__ unsigned int __cdecl _rotl(unsigned int _Value, int _Shift); static __inline__ unsigned short _rotl16(unsigned short _Value, unsigned char _Shift); static __inline__ unsigned __int64 __cdecl _rotl64(unsigned __int64 _Value, int _Shift); static __inline__ unsigned char _rotl8(unsigned char _Value, unsigned char _Shift); static __inline__ unsigned int __cdecl _rotr(unsigned int _Value, int _Shift); static __inline__ unsigned short _rotr16(unsigned short _Value, unsigned char _Shift); static __inline__ unsigned __int64 __cdecl _rotr64(unsigned __int64 _Value, int _Shift); static __inline__ unsigned char _rotr8(unsigned char _Value, unsigned char _Shift); int _sarx_i32(int, unsigned int); #if __STDC_HOSTED__ int __cdecl _setjmp(jmp_buf); #endif unsigned int _shlx_u32(unsigned int, unsigned int); unsigned int _shrx_u32(unsigned int, unsigned int); void _Store_HLERelease(long volatile *, long); void _Store64_HLERelease(__int64 volatile *, __int64); void _StorePointer_HLERelease(void *volatile *, void *); static __inline__ void _WriteBarrier(void); unsigned __int32 xbegin(void); void _xend(void); static __inline__ #define _XCR_XFEATURE_ENABLED_MASK 0 unsigned __int64 __cdecl _xgetbv(unsigned int); void __cdecl _xrstor(void const *, unsigned __int64); void __cdecl _xsave(void *, unsigned __int64); void __cdecl _xsaveopt(void *, unsigned __int64); void __cdecl _xsetbv(unsigned int, unsigned __int64); /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */ #ifdef __x86_64__ void __addgsbyte(unsigned long, unsigned char); void __addgsdword(unsigned long, unsigned long); void __addgsqword(unsigned long, unsigned __int64); void __addgsword(unsigned long, unsigned short); static __inline__ void __faststorefence(void); void __incgsbyte(unsigned long); void __incgsdword(unsigned long); void __incgsqword(unsigned long); void __incgsword(unsigned long); unsigned char __lwpins64(unsigned __int64, unsigned int, unsigned int); void __lwpval64(unsigned __int64, unsigned int, unsigned int); unsigned __int64 __lzcnt64(unsigned __int64); static __inline__ void __movsq(unsigned long long *, unsigned long long const *, size_t); __int64 __mulh(__int64, __int64); static __inline__ unsigned __int64 __popcnt64(unsigned __int64); static __inline__ unsigned char __readgsbyte(unsigned long); static __inline__ unsigned long __readgsdword(unsigned long); static __inline__ unsigned __int64 __readgsqword(unsigned long); unsigned short __readgsword(unsigned long); unsigned __int64 __shiftleft128(unsigned __int64 _LowPart, unsigned __int64 _HighPart, unsigned char _Shift); unsigned __int64 __shiftright128(unsigned __int64 _LowPart, unsigned __int64 _HighPart, unsigned char _Shift); static __inline__ void __stosq(unsigned __int64 *, unsigned __int64, size_t); unsigned char __vmx_on(unsigned __int64 *); unsigned char __vmx_vmclear(unsigned __int64 *); unsigned char __vmx_vmlaunch(void); unsigned char __vmx_vmptrld(unsigned __int64 *); unsigned char __vmx_vmread(size_t, size_t *); unsigned char __vmx_vmresume(void); unsigned char __vmx_vmwrite(size_t, size_t); void __writegsbyte(unsigned long, unsigned char); void __writegsdword(unsigned long, unsigned long); void __writegsqword(unsigned long, unsigned __int64); void __writegsword(unsigned long, unsigned short); static __inline__ unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask); static __inline__ unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask); static __inline__ unsigned char _bittest64(__int64 const *, __int64); static __inline__ unsigned char _bittestandcomplement64(__int64 *, __int64); static __inline__ unsigned char _bittestandreset64(__int64 *, __int64); static __inline__ unsigned char _bittestandset64(__int64 *, __int64); unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64); long _InterlockedAnd_np(long volatile *_Value, long _Mask); short _InterlockedAnd16_np(short volatile *_Value, short _Mask); __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask); char _InterlockedAnd8_np(char volatile *_Value, char _Mask); unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64); static __inline__ unsigned char _interlockedbittestandset64(__int64 volatile *, __int64); long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange, long _Comparand); unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination, __int64 _ExchangeHigh, __int64 _ExchangeLow, __int64 *_CompareandResult); unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination, __int64 _ExchangeHigh, __int64 _ExchangeLow, __int64 *_ComparandResult); short _InterlockedCompareExchange16_np(short volatile *_Destination, short _Exchange, short _Comparand); __int64 _InterlockedCompareExchange64_HLEAcquire(__int64 volatile *, __int64, __int64); __int64 _InterlockedCompareExchange64_HLERelease(__int64 volatile *, __int64, __int64); __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination, __int64 _Exchange, __int64 _Comparand); void *_InterlockedCompareExchangePointer(void *volatile *_Destination, void *_Exchange, void *_Comparand); void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination, void *_Exchange, void *_Comparand); static __inline__ __int64 _InterlockedDecrement64(__int64 volatile *_Addend); static __inline__ __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value); static __inline__ __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value); void *_InterlockedExchangePointer(void *volatile *_Target, void *_Value); static __inline__ __int64 _InterlockedIncrement64(__int64 volatile *_Addend); long _InterlockedOr_np(long volatile *_Value, long _Mask); short _InterlockedOr16_np(short volatile *_Value, short _Mask); static __inline__ __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask); __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask); char _InterlockedOr8_np(char volatile *_Value, char _Mask); long _InterlockedXor_np(long volatile *_Value, long _Mask); short _InterlockedXor16_np(short volatile *_Value, short _Mask); static __inline__ __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask); __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask); char _InterlockedXor8_np(char volatile *_Value, char _Mask); static __inline__ __int64 _mul128(__int64 _Multiplier, __int64 _Multiplicand, __int64 *_HighProduct); unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int); __int64 _sarx_i64(__int64, unsigned int); #if __STDC_HOSTED__ int __cdecl _setjmpex(jmp_buf); #endif unsigned __int64 _shlx_u64(unsigned __int64, unsigned int); unsigned __int64 _shrx_u64(unsigned __int64, unsigned int); /* * Multiply two 64-bit integers and obtain a 64-bit result. * The low-half is returned directly and the high half is in an out parameter. */ static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS _umul128(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand, unsigned __int64 *_HighProduct) { unsigned __int128 _FullProduct = (unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand; *_HighProduct = _FullProduct >> 64; return _FullProduct; } static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS __umulh(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand) { unsigned __int128 _FullProduct = (unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand; return _FullProduct >> 64; } void __cdecl _xrstor64(void const *, unsigned __int64); void __cdecl _xsave64(void *, unsigned __int64); void __cdecl _xsaveopt64(void *, unsigned __int64); #endif /* __x86_64__ */ /*----------------------------------------------------------------------------*\ |* Bit Twiddling \*----------------------------------------------------------------------------*/ static __inline__ unsigned char __DEFAULT_FN_ATTRS _rotl8(unsigned char _Value, unsigned char _Shift) { _Shift &= 0x7; return _Shift ? (_Value << _Shift) | (_Value >> (8 - _Shift)) : _Value; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _rotr8(unsigned char _Value, unsigned char _Shift) { _Shift &= 0x7; return _Shift ? (_Value >> _Shift) | (_Value << (8 - _Shift)) : _Value; } static __inline__ unsigned short __DEFAULT_FN_ATTRS _rotl16(unsigned short _Value, unsigned char _Shift) { _Shift &= 0xf; return _Shift ? (_Value << _Shift) | (_Value >> (16 - _Shift)) : _Value; } static __inline__ unsigned short __DEFAULT_FN_ATTRS _rotr16(unsigned short _Value, unsigned char _Shift) { _Shift &= 0xf; return _Shift ? (_Value >> _Shift) | (_Value << (16 - _Shift)) : _Value; } static __inline__ unsigned int __DEFAULT_FN_ATTRS _rotl(unsigned int _Value, int _Shift) { _Shift &= 0x1f; return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value; } static __inline__ unsigned int __DEFAULT_FN_ATTRS _rotr(unsigned int _Value, int _Shift) { _Shift &= 0x1f; return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value; } static __inline__ unsigned long __DEFAULT_FN_ATTRS _lrotl(unsigned long _Value, int _Shift) { _Shift &= 0x1f; return _Shift ? (_Value << _Shift) | (_Value >> (32 - _Shift)) : _Value; } static __inline__ unsigned long __DEFAULT_FN_ATTRS _lrotr(unsigned long _Value, int _Shift) { _Shift &= 0x1f; return _Shift ? (_Value >> _Shift) | (_Value << (32 - _Shift)) : _Value; } static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS _rotl64(unsigned __int64 _Value, int _Shift) { _Shift &= 0x3f; return _Shift ? (_Value << _Shift) | (_Value >> (64 - _Shift)) : _Value; } static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS _rotr64(unsigned __int64 _Value, int _Shift) { _Shift &= 0x3f; return _Shift ? (_Value >> _Shift) | (_Value << (64 - _Shift)) : _Value; } /*----------------------------------------------------------------------------*\ |* Bit Counting and Testing \*----------------------------------------------------------------------------*/ static __inline__ unsigned char __DEFAULT_FN_ATTRS _BitScanForward(unsigned long *_Index, unsigned long _Mask) { if (!_Mask) return 0; *_Index = __builtin_ctzl(_Mask); return 1; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _BitScanReverse(unsigned long *_Index, unsigned long _Mask) { if (!_Mask) return 0; *_Index = 31 - __builtin_clzl(_Mask); return 1; } static __inline__ unsigned short __DEFAULT_FN_ATTRS __popcnt16(unsigned short _Value) { return __builtin_popcount((int)_Value); } static __inline__ unsigned int __DEFAULT_FN_ATTRS __popcnt(unsigned int _Value) { return __builtin_popcount(_Value); } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittest(long const *_BitBase, long _BitPos) { return (*_BitBase >> _BitPos) & 1; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittestandcomplement(long *_BitBase, long _BitPos) { unsigned char _Res = (*_BitBase >> _BitPos) & 1; *_BitBase = *_BitBase ^ (1 << _BitPos); return _Res; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittestandreset(long *_BitBase, long _BitPos) { unsigned char _Res = (*_BitBase >> _BitPos) & 1; *_BitBase = *_BitBase & ~(1 << _BitPos); return _Res; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittestandset(long *_BitBase, long _BitPos) { unsigned char _Res = (*_BitBase >> _BitPos) & 1; *_BitBase = *_BitBase | (1 << _BitPos); return _Res; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _interlockedbittestandset(long volatile *_BitBase, long _BitPos) { long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST); return (_PrevVal >> _BitPos) & 1; } #ifdef __x86_64__ static __inline__ unsigned char __DEFAULT_FN_ATTRS _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) { if (!_Mask) return 0; *_Index = __builtin_ctzll(_Mask); return 1; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask) { if (!_Mask) return 0; *_Index = 63 - __builtin_clzll(_Mask); return 1; } static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS __popcnt64(unsigned __int64 _Value) { return __builtin_popcountll(_Value); } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittest64(__int64 const *_BitBase, __int64 _BitPos) { return (*_BitBase >> _BitPos) & 1; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittestandcomplement64(__int64 *_BitBase, __int64 _BitPos) { unsigned char _Res = (*_BitBase >> _BitPos) & 1; *_BitBase = *_BitBase ^ (1ll << _BitPos); return _Res; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittestandreset64(__int64 *_BitBase, __int64 _BitPos) { unsigned char _Res = (*_BitBase >> _BitPos) & 1; *_BitBase = *_BitBase & ~(1ll << _BitPos); return _Res; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _bittestandset64(__int64 *_BitBase, __int64 _BitPos) { unsigned char _Res = (*_BitBase >> _BitPos) & 1; *_BitBase = *_BitBase | (1ll << _BitPos); return _Res; } static __inline__ unsigned char __DEFAULT_FN_ATTRS _interlockedbittestandset64(__int64 volatile *_BitBase, __int64 _BitPos) { long long _PrevVal = __atomic_fetch_or(_BitBase, 1ll << _BitPos, __ATOMIC_SEQ_CST); return (_PrevVal >> _BitPos) & 1; } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Exchange Add \*----------------------------------------------------------------------------*/ static __inline__ char __DEFAULT_FN_ATTRS _InterlockedExchangeAdd8(char volatile *_Addend, char _Value) { return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST); } static __inline__ short __DEFAULT_FN_ATTRS _InterlockedExchangeAdd16(short volatile *_Addend, short _Value) { return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST); } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) { return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST); } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Exchange Sub \*----------------------------------------------------------------------------*/ static __inline__ char __DEFAULT_FN_ATTRS _InterlockedExchangeSub8(char volatile *_Subend, char _Value) { return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); } static __inline__ short __DEFAULT_FN_ATTRS _InterlockedExchangeSub16(short volatile *_Subend, short _Value) { return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); } static __inline__ long __DEFAULT_FN_ATTRS _InterlockedExchangeSub(long volatile *_Subend, long _Value) { return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value) { return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST); } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Increment \*----------------------------------------------------------------------------*/ static __inline__ short __DEFAULT_FN_ATTRS _InterlockedIncrement16(short volatile *_Value) { return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST); } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedIncrement64(__int64 volatile *_Value) { return __atomic_add_fetch(_Value, 1, __ATOMIC_SEQ_CST); } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Decrement \*----------------------------------------------------------------------------*/ static __inline__ short __DEFAULT_FN_ATTRS _InterlockedDecrement16(short volatile *_Value) { return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST); } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedDecrement64(__int64 volatile *_Value) { return __atomic_sub_fetch(_Value, 1, __ATOMIC_SEQ_CST); } #endif /*----------------------------------------------------------------------------*\ |* Interlocked And \*----------------------------------------------------------------------------*/ static __inline__ char __DEFAULT_FN_ATTRS _InterlockedAnd8(char volatile *_Value, char _Mask) { return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } static __inline__ short __DEFAULT_FN_ATTRS _InterlockedAnd16(short volatile *_Value, short _Mask) { return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } static __inline__ long __DEFAULT_FN_ATTRS _InterlockedAnd(long volatile *_Value, long _Mask) { return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask) { return __atomic_and_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Or \*----------------------------------------------------------------------------*/ static __inline__ char __DEFAULT_FN_ATTRS _InterlockedOr8(char volatile *_Value, char _Mask) { return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } static __inline__ short __DEFAULT_FN_ATTRS _InterlockedOr16(short volatile *_Value, short _Mask) { return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } static __inline__ long __DEFAULT_FN_ATTRS _InterlockedOr(long volatile *_Value, long _Mask) { return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask) { return __atomic_or_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Xor \*----------------------------------------------------------------------------*/ static __inline__ char __DEFAULT_FN_ATTRS _InterlockedXor8(char volatile *_Value, char _Mask) { return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } static __inline__ short __DEFAULT_FN_ATTRS _InterlockedXor16(short volatile *_Value, short _Mask) { return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } static __inline__ long __DEFAULT_FN_ATTRS _InterlockedXor(long volatile *_Value, long _Mask) { return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask) { return __atomic_xor_fetch(_Value, _Mask, __ATOMIC_SEQ_CST); } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Exchange \*----------------------------------------------------------------------------*/ static __inline__ char __DEFAULT_FN_ATTRS _InterlockedExchange8(char volatile *_Target, char _Value) { __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST); return _Value; } static __inline__ short __DEFAULT_FN_ATTRS _InterlockedExchange16(short volatile *_Target, short _Value) { __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST); return _Value; } #ifdef __x86_64__ static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value) { __atomic_exchange(_Target, &_Value, &_Value, __ATOMIC_SEQ_CST); return _Value; } #endif /*----------------------------------------------------------------------------*\ |* Interlocked Compare Exchange \*----------------------------------------------------------------------------*/ static __inline__ char __DEFAULT_FN_ATTRS _InterlockedCompareExchange8(char volatile *_Destination, char _Exchange, char _Comparand) { __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return _Comparand; } static __inline__ short __DEFAULT_FN_ATTRS _InterlockedCompareExchange16(short volatile *_Destination, short _Exchange, short _Comparand) { __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return _Comparand; } static __inline__ __int64 __DEFAULT_FN_ATTRS _InterlockedCompareExchange64(__int64 volatile *_Destination, __int64 _Exchange, __int64 _Comparand) { __atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return _Comparand; } /*----------------------------------------------------------------------------*\ |* Barriers \*----------------------------------------------------------------------------*/ #if defined(__i386__) || defined(__x86_64__) static __inline__ void __DEFAULT_FN_ATTRS __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) _ReadWriteBarrier(void) { __asm__ volatile ("" : : : "memory"); } static __inline__ void __DEFAULT_FN_ATTRS __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) _ReadBarrier(void) { __asm__ volatile ("" : : : "memory"); } static __inline__ void __DEFAULT_FN_ATTRS __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead"))) _WriteBarrier(void) { __asm__ volatile ("" : : : "memory"); } #endif #ifdef __x86_64__ static __inline__ void __DEFAULT_FN_ATTRS __faststorefence(void) { __asm__ volatile("lock orq $0, (%%rsp)" : : : "memory"); } #endif /*----------------------------------------------------------------------------*\ |* readfs, readgs |* (Pointers in address space #256 and #257 are relative to the GS and FS |* segment registers, respectively.) \*----------------------------------------------------------------------------*/ #define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \ ((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \ (__offset)) #ifdef __i386__ static __inline__ unsigned char __DEFAULT_FN_ATTRS __readfsbyte(unsigned long __offset) { return *__ptr_to_addr_space(257, unsigned char, __offset); } static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS __readfsqword(unsigned long __offset) { return *__ptr_to_addr_space(257, unsigned __int64, __offset); } static __inline__ unsigned short __DEFAULT_FN_ATTRS __readfsword(unsigned long __offset) { return *__ptr_to_addr_space(257, unsigned short, __offset); } #endif #ifdef __x86_64__ static __inline__ unsigned char __DEFAULT_FN_ATTRS __readgsbyte(unsigned long __offset) { return *__ptr_to_addr_space(256, unsigned char, __offset); } static __inline__ unsigned long __DEFAULT_FN_ATTRS __readgsdword(unsigned long __offset) { return *__ptr_to_addr_space(256, unsigned long, __offset); } static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS __readgsqword(unsigned long __offset) { return *__ptr_to_addr_space(256, unsigned __int64, __offset); } static __inline__ unsigned short __DEFAULT_FN_ATTRS __readgsword(unsigned long __offset) { return *__ptr_to_addr_space(256, unsigned short, __offset); } #endif #undef __ptr_to_addr_space /*----------------------------------------------------------------------------*\ |* movs, stos \*----------------------------------------------------------------------------*/ #if defined(__i386__) || defined(__x86_64__) static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) { __asm__("rep movsb" : : "D"(__dst), "S"(__src), "c"(__n) : "%edi", "%esi", "%ecx"); } static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) { __asm__("rep movsl" : : "D"(__dst), "S"(__src), "c"(__n) : "%edi", "%esi", "%ecx"); } static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) { __asm__("rep movsh" : : "D"(__dst), "S"(__src), "c"(__n) : "%edi", "%esi", "%ecx"); } static __inline__ void __DEFAULT_FN_ATTRS __stosb(unsigned char *__dst, unsigned char __x, size_t __n) { __asm__("rep stosb" : : "D"(__dst), "a"(__x), "c"(__n) : "%edi", "%ecx"); } static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst, unsigned long __x, size_t __n) { __asm__("rep stosl" : : "D"(__dst), "a"(__x), "c"(__n) : "%edi", "%ecx"); } static __inline__ void __DEFAULT_FN_ATTRS __stosw(unsigned short *__dst, unsigned short __x, size_t __n) { __asm__("rep stosh" : : "D"(__dst), "a"(__x), "c"(__n) : "%edi", "%ecx"); } #endif #ifdef __x86_64__ static __inline__ void __DEFAULT_FN_ATTRS __movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) { __asm__("rep movsq" : : "D"(__dst), "S"(__src), "c"(__n) : "%edi", "%esi", "%ecx"); } static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) { __asm__("rep stosq" : : "D"(__dst), "a"(__x), "c"(__n) : "%edi", "%ecx"); } #endif /*----------------------------------------------------------------------------*\ |* Misc \*----------------------------------------------------------------------------*/ static __inline__ void * __DEFAULT_FN_ATTRS _AddressOfReturnAddress(void) { return (void*)((char*)__builtin_frame_address(0) + sizeof(void*)); } static __inline__ void * __DEFAULT_FN_ATTRS _ReturnAddress(void) { return __builtin_return_address(0); } #if defined(__i386__) || defined(__x86_64__) static __inline__ void __DEFAULT_FN_ATTRS __cpuid(int __info[4], int __level) { __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3]) : "a"(__level)); } static __inline__ void __DEFAULT_FN_ATTRS __cpuidex(int __info[4], int __level, int __ecx) { __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3]) : "a"(__level), "c"(__ecx)); } static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS _xgetbv(unsigned int __xcr_no) { unsigned int __eax, __edx; __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no)); return ((unsigned __int64)__edx << 32) | __eax; } static __inline__ void __DEFAULT_FN_ATTRS __halt(void) { __asm__ volatile ("hlt"); } #endif /*----------------------------------------------------------------------------*\ |* Privileged intrinsics \*----------------------------------------------------------------------------*/ #if defined(__i386__) || defined(__x86_64__) static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS __readmsr(unsigned long __register) { // Loads the contents of a 64-bit model specific register (MSR) specified in // the ECX register into registers EDX:EAX. The EDX register is loaded with // the high-order 32 bits of the MSR and the EAX register is loaded with the // low-order 32 bits. If less than 64 bits are implemented in the MSR being // read, the values returned to EDX:EAX in unimplemented bit locations are // undefined. unsigned long __edx; unsigned long __eax; __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register)); return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax; } static __inline__ unsigned long __DEFAULT_FN_ATTRS __readcr3(void) { unsigned long __cr3_val; __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory"); return __cr3_val; } static __inline__ void __DEFAULT_FN_ATTRS __writecr3(unsigned int __cr3_val) { __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory"); } #endif #ifdef __cplusplus } #endif #undef __DEFAULT_FN_ATTRS #endif /* __INTRIN_H */ #endif /* _MSC_VER */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/xtestintrin.h
/*===---- xtestintrin.h - XTEST intrinsic ---------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <xtestintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __XTESTINTRIN_H #define __XTESTINTRIN_H /* xtest returns non-zero if the instruction is executed within an RTM or active * HLE region. */ /* FIXME: This can be an either or for RTM/HLE. Deal with this when HLE is * supported. */ static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rtm"))) _xtest(void) { return __builtin_ia32_xtest(); } #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/inttypes.h
/*===---- inttypes.h - Standard header for integer printf macros ----------===*\ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * \*===----------------------------------------------------------------------===*/ #ifndef __CLANG_INTTYPES_H #define __CLANG_INTTYPES_H #include_next <inttypes.h> #if defined(_MSC_VER) && _MSC_VER < 1900 /* MSVC headers define int32_t as int, but PRIx32 as "lx" instead of "x". * This triggers format warnings, so fix it up here. */ #undef PRId32 #undef PRIdLEAST32 #undef PRIdFAST32 #undef PRIi32 #undef PRIiLEAST32 #undef PRIiFAST32 #undef PRIo32 #undef PRIoLEAST32 #undef PRIoFAST32 #undef PRIu32 #undef PRIuLEAST32 #undef PRIuFAST32 #undef PRIx32 #undef PRIxLEAST32 #undef PRIxFAST32 #undef PRIX32 #undef PRIXLEAST32 #undef PRIXFAST32 #undef SCNd32 #undef SCNdLEAST32 #undef SCNdFAST32 #undef SCNi32 #undef SCNiLEAST32 #undef SCNiFAST32 #undef SCNo32 #undef SCNoLEAST32 #undef SCNoFAST32 #undef SCNu32 #undef SCNuLEAST32 #undef SCNuFAST32 #undef SCNx32 #undef SCNxLEAST32 #undef SCNxFAST32 #define PRId32 "d" #define PRIdLEAST32 "d" #define PRIdFAST32 "d" #define PRIi32 "i" #define PRIiLEAST32 "i" #define PRIiFAST32 "i" #define PRIo32 "o" #define PRIoLEAST32 "o" #define PRIoFAST32 "o" #define PRIu32 "u" #define PRIuLEAST32 "u" #define PRIuFAST32 "u" #define PRIx32 "x" #define PRIxLEAST32 "x" #define PRIxFAST32 "x" #define PRIX32 "X" #define PRIXLEAST32 "X" #define PRIXFAST32 "X" #define SCNd32 "d" #define SCNdLEAST32 "d" #define SCNdFAST32 "d" #define SCNi32 "i" #define SCNiLEAST32 "i" #define SCNiFAST32 "i" #define SCNo32 "o" #define SCNoLEAST32 "o" #define SCNoFAST32 "o" #define SCNu32 "u" #define SCNuLEAST32 "u" #define SCNuFAST32 "u" #define SCNx32 "x" #define SCNxLEAST32 "x" #define SCNxFAST32 "x" #endif #endif /* __CLANG_INTTYPES_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avx512dqintrin.h
/*===---- avx512dqintrin.h - AVX512DQ intrinsics ---------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avx512dqintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVX512DQINTRIN_H #define __AVX512DQINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mullo_epi64 (__m512i __A, __m512i __B) { return (__m512i) ((__v8di) __A * (__v8di) __B); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mask_mullo_epi64 (__m512i __W, __mmask8 __U, __m512i __A, __m512i __B) { return (__m512i) __builtin_ia32_pmullq512_mask ((__v8di) __A, (__v8di) __B, (__v8di) __W, (__mmask8) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_maskz_mullo_epi64 (__mmask8 __U, __m512i __A, __m512i __B) { return (__m512i) __builtin_ia32_pmullq512_mask ((__v8di) __A, (__v8di) __B, (__v8di) _mm512_setzero_si512 (), (__mmask8) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_xor_pd (__m512d __A, __m512d __B) { return (__m512d) ((__v8di) __A ^ (__v8di) __B); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_mask_xor_pd (__m512d __W, __mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_xorpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) __W, (__mmask8) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_maskz_xor_pd (__mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_xorpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) _mm512_setzero_pd (), (__mmask8) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_xor_ps (__m512 __A, __m512 __B) { return (__m512) ((__v16si) __A ^ (__v16si) __B); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_mask_xor_ps (__m512 __W, __mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_xorps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) __W, (__mmask16) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_maskz_xor_ps (__mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_xorps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) _mm512_setzero_ps (), (__mmask16) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_or_pd (__m512d __A, __m512d __B) { return (__m512d) ((__v8di) __A | (__v8di) __B); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_mask_or_pd (__m512d __W, __mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_orpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) __W, (__mmask8) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_maskz_or_pd (__mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_orpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) _mm512_setzero_pd (), (__mmask8) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_or_ps (__m512 __A, __m512 __B) { return (__m512) ((__v16si) __A | (__v16si) __B); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_mask_or_ps (__m512 __W, __mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_orps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) __W, (__mmask16) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_maskz_or_ps (__mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_orps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) _mm512_setzero_ps (), (__mmask16) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_and_pd (__m512d __A, __m512d __B) { return (__m512d) ((__v8di) __A & (__v8di) __B); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_mask_and_pd (__m512d __W, __mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_andpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) __W, (__mmask8) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_maskz_and_pd (__mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_andpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) _mm512_setzero_pd (), (__mmask8) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_and_ps (__m512 __A, __m512 __B) { return (__m512) ((__v16si) __A & (__v16si) __B); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_mask_and_ps (__m512 __W, __mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_andps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) __W, (__mmask16) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_maskz_and_ps (__mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_andps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) _mm512_setzero_ps (), (__mmask16) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_andnot_pd (__m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_andnpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) _mm512_setzero_pd (), (__mmask8) -1); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_mask_andnot_pd (__m512d __W, __mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_andnpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) __W, (__mmask8) __U); } static __inline__ __m512d __DEFAULT_FN_ATTRS _mm512_maskz_andnot_pd (__mmask8 __U, __m512d __A, __m512d __B) { return (__m512d) __builtin_ia32_andnpd512_mask ((__v8df) __A, (__v8df) __B, (__v8df) _mm512_setzero_pd (), (__mmask8) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_andnot_ps (__m512 __A, __m512 __B) { return (__m512) __builtin_ia32_andnps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) _mm512_setzero_ps (), (__mmask16) -1); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_mask_andnot_ps (__m512 __W, __mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_andnps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) __W, (__mmask16) __U); } static __inline__ __m512 __DEFAULT_FN_ATTRS _mm512_maskz_andnot_ps (__mmask16 __U, __m512 __A, __m512 __B) { return (__m512) __builtin_ia32_andnps512_mask ((__v16sf) __A, (__v16sf) __B, (__v16sf) _mm512_setzero_ps (), (__mmask16) __U); } #undef __DEFAULT_FN_ATTRS #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/__wmmintrin_pclmul.h
/*===---- __wmmintrin_pclmul.h - AES intrinsics ----------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef _WMMINTRIN_PCLMUL_H #define _WMMINTRIN_PCLMUL_H #if !defined (__PCLMUL__) # error "PCLMUL instruction is not enabled" #else #define _mm_clmulepi64_si128(__X, __Y, __I) \ ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(__X), \ (__v2di)(__m128i)(__Y), (char)(__I))) #endif #endif /* _WMMINTRIN_PCLMUL_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/immintrin.h
/*===---- immintrin.h - Intel intrinsics -----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #define __IMMINTRIN_H #ifdef __MMX__ #include <mmintrin.h> #endif #ifdef __SSE__ #include <xmmintrin.h> #endif #ifdef __SSE2__ #include <emmintrin.h> #endif #ifdef __SSE3__ #include <pmmintrin.h> #endif #ifdef __SSSE3__ #include <tmmintrin.h> #endif #if defined (__SSE4_2__) || defined (__SSE4_1__) #include <smmintrin.h> #endif #if defined (__AES__) || defined (__PCLMUL__) #include <wmmintrin.h> #endif #ifdef __AVX__ #include <avxintrin.h> #endif #ifdef __AVX2__ #include <avx2intrin.h> #endif #ifdef __BMI__ #include <bmiintrin.h> #endif #ifdef __BMI2__ #include <bmi2intrin.h> #endif #ifdef __LZCNT__ #include <lzcntintrin.h> #endif #ifdef __FMA__ #include <fmaintrin.h> #endif #ifdef __AVX512F__ #include <avx512fintrin.h> #endif #ifdef __AVX512VL__ #include <avx512vlintrin.h> #endif #ifdef __AVX512BW__ #include <avx512bwintrin.h> #endif #ifdef __AVX512CD__ #include <avx512cdintrin.h> #endif #ifdef __AVX512DQ__ #include <avx512dqintrin.h> #endif #if defined (__AVX512VL__) && defined (__AVX512BW__) #include <avx512vlbwintrin.h> #endif #if defined (__AVX512VL__) && defined (__AVX512DQ__) #include <avx512vldqintrin.h> #endif #ifdef __AVX512ER__ #include <avx512erintrin.h> #endif #ifdef __RDRND__ static __inline__ int __attribute__((__always_inline__, __nodebug__)) _rdrand16_step(unsigned short *__p) { return __builtin_ia32_rdrand16_step(__p); } static __inline__ int __attribute__((__always_inline__, __nodebug__)) _rdrand32_step(unsigned int *__p) { return __builtin_ia32_rdrand32_step(__p); } #ifdef __x86_64__ static __inline__ int __attribute__((__always_inline__, __nodebug__)) _rdrand64_step(unsigned long long *__p) { return __builtin_ia32_rdrand64_step(__p); } #endif #endif /* __RDRND__ */ #ifdef __FSGSBASE__ #ifdef __x86_64__ static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) _readfsbase_u32(void) { return __builtin_ia32_rdfsbase32(); } static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__)) _readfsbase_u64(void) { return __builtin_ia32_rdfsbase64(); } static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) _readgsbase_u32(void) { return __builtin_ia32_rdgsbase32(); } static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__)) _readgsbase_u64(void) { return __builtin_ia32_rdgsbase64(); } static __inline__ void __attribute__((__always_inline__, __nodebug__)) _writefsbase_u32(unsigned int __V) { return __builtin_ia32_wrfsbase32(__V); } static __inline__ void __attribute__((__always_inline__, __nodebug__)) _writefsbase_u64(unsigned long long __V) { return __builtin_ia32_wrfsbase64(__V); } static __inline__ void __attribute__((__always_inline__, __nodebug__)) _writegsbase_u32(unsigned int __V) { return __builtin_ia32_wrgsbase32(__V); } static __inline__ void __attribute__((__always_inline__, __nodebug__)) _writegsbase_u64(unsigned long long __V) { return __builtin_ia32_wrgsbase64(__V); } #endif #endif /* __FSGSBASE__ */ #ifdef __RTM__ #include <rtmintrin.h> #endif #ifdef __RTM__ #include <xtestintrin.h> #endif #ifdef __SHA__ #include <shaintrin.h> #endif #include <fxsrintrin.h> /* Some intrinsics inside adxintrin.h are available only on processors with ADX, * whereas others are also available at all times. */ #include <adxintrin.h> #endif /* __IMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/mmintrin.h
/*===---- mmintrin.h - MMX intrinsics --------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __MMINTRIN_H #define __MMINTRIN_H #ifndef __MMX__ #error "MMX instruction set not enabled" #else typedef long long __m64 __attribute__((__vector_size__(8))); typedef int __v2si __attribute__((__vector_size__(8))); typedef short __v4hi __attribute__((__vector_size__(8))); typedef char __v8qi __attribute__((__vector_size__(8))); /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ void __DEFAULT_FN_ATTRS _mm_empty(void) { __builtin_ia32_emms(); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvtsi32_si64(int __i) { return (__m64)__builtin_ia32_vec_init_v2si(__i, 0); } static __inline__ int __DEFAULT_FN_ATTRS _mm_cvtsi64_si32(__m64 __m) { return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvtsi64_m64(long long __i) { return (__m64)__i; } static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvtm64_si64(__m64 __m) { return (long long)__m; } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_packs_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_packs_pi32(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_packs_pu16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_unpackhi_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_punpckhbw((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_unpackhi_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_punpckhwd((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_unpackhi_pi32(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_punpckhdq((__v2si)__m1, (__v2si)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_unpacklo_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_punpcklbw((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_unpacklo_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_punpcklwd((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_unpacklo_pi32(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_punpckldq((__v2si)__m1, (__v2si)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_add_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_add_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_add_pi32(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_adds_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_paddsb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_adds_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_paddsw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_adds_pu8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_paddusb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_adds_pu16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_paddusw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sub_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_psubb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sub_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_psubw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sub_pi32(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_psubd((__v2si)__m1, (__v2si)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_subs_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_psubsb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_subs_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_psubsw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_subs_pu8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_psubusb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_subs_pu16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_psubusw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_madd_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pmaddwd((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_mulhi_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pmulhw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_mullo_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pmullw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sll_pi16(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_psllw((__v4hi)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_slli_pi16(__m64 __m, int __count) { return (__m64)__builtin_ia32_psllwi((__v4hi)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sll_pi32(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_pslld((__v2si)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_slli_pi32(__m64 __m, int __count) { return (__m64)__builtin_ia32_pslldi((__v2si)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sll_si64(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_psllq(__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_slli_si64(__m64 __m, int __count) { return (__m64)__builtin_ia32_psllqi(__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sra_pi16(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_psraw((__v4hi)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srai_pi16(__m64 __m, int __count) { return (__m64)__builtin_ia32_psrawi((__v4hi)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sra_pi32(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_psrad((__v2si)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srai_pi32(__m64 __m, int __count) { return (__m64)__builtin_ia32_psradi((__v2si)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srl_pi16(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_psrlw((__v4hi)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srli_pi16(__m64 __m, int __count) { return (__m64)__builtin_ia32_psrlwi((__v4hi)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srl_pi32(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_psrld((__v2si)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srli_pi32(__m64 __m, int __count) { return (__m64)__builtin_ia32_psrldi((__v2si)__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srl_si64(__m64 __m, __m64 __count) { return (__m64)__builtin_ia32_psrlq(__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_srli_si64(__m64 __m, int __count) { return (__m64)__builtin_ia32_psrlqi(__m, __count); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_and_si64(__m64 __m1, __m64 __m2) { return __builtin_ia32_pand(__m1, __m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_andnot_si64(__m64 __m1, __m64 __m2) { return __builtin_ia32_pandn(__m1, __m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_or_si64(__m64 __m1, __m64 __m2) { return __builtin_ia32_por(__m1, __m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_xor_si64(__m64 __m1, __m64 __m2) { return __builtin_ia32_pxor(__m1, __m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cmpeq_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pcmpeqb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cmpeq_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pcmpeqw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cmpeq_pi32(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pcmpeqd((__v2si)__m1, (__v2si)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cmpgt_pi8(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pcmpgtb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cmpgt_pi16(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pcmpgtw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cmpgt_pi32(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pcmpgtd((__v2si)__m1, (__v2si)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_setzero_si64(void) { return (__m64){ 0LL }; } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_set_pi32(int __i1, int __i0) { return (__m64)__builtin_ia32_vec_init_v2si(__i0, __i1); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_set_pi16(short __s3, short __s2, short __s1, short __s0) { return (__m64)__builtin_ia32_vec_init_v4hi(__s0, __s1, __s2, __s3); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_set_pi8(char __b7, char __b6, char __b5, char __b4, char __b3, char __b2, char __b1, char __b0) { return (__m64)__builtin_ia32_vec_init_v8qi(__b0, __b1, __b2, __b3, __b4, __b5, __b6, __b7); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_set1_pi32(int __i) { return _mm_set_pi32(__i, __i); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_set1_pi16(short __w) { return _mm_set_pi16(__w, __w, __w, __w); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_set1_pi8(char __b) { return _mm_set_pi8(__b, __b, __b, __b, __b, __b, __b, __b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_setr_pi32(int __i0, int __i1) { return _mm_set_pi32(__i1, __i0); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_setr_pi16(short __w0, short __w1, short __w2, short __w3) { return _mm_set_pi16(__w3, __w2, __w1, __w0); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_setr_pi8(char __b0, char __b1, char __b2, char __b3, char __b4, char __b5, char __b6, char __b7) { return _mm_set_pi8(__b7, __b6, __b5, __b4, __b3, __b2, __b1, __b0); } #undef __DEFAULT_FN_ATTRS /* Aliases for compatibility. */ #define _m_empty _mm_empty #define _m_from_int _mm_cvtsi32_si64 #define _m_to_int _mm_cvtsi64_si32 #define _m_packsswb _mm_packs_pi16 #define _m_packssdw _mm_packs_pi32 #define _m_packuswb _mm_packs_pu16 #define _m_punpckhbw _mm_unpackhi_pi8 #define _m_punpckhwd _mm_unpackhi_pi16 #define _m_punpckhdq _mm_unpackhi_pi32 #define _m_punpcklbw _mm_unpacklo_pi8 #define _m_punpcklwd _mm_unpacklo_pi16 #define _m_punpckldq _mm_unpacklo_pi32 #define _m_paddb _mm_add_pi8 #define _m_paddw _mm_add_pi16 #define _m_paddd _mm_add_pi32 #define _m_paddsb _mm_adds_pi8 #define _m_paddsw _mm_adds_pi16 #define _m_paddusb _mm_adds_pu8 #define _m_paddusw _mm_adds_pu16 #define _m_psubb _mm_sub_pi8 #define _m_psubw _mm_sub_pi16 #define _m_psubd _mm_sub_pi32 #define _m_psubsb _mm_subs_pi8 #define _m_psubsw _mm_subs_pi16 #define _m_psubusb _mm_subs_pu8 #define _m_psubusw _mm_subs_pu16 #define _m_pmaddwd _mm_madd_pi16 #define _m_pmulhw _mm_mulhi_pi16 #define _m_pmullw _mm_mullo_pi16 #define _m_psllw _mm_sll_pi16 #define _m_psllwi _mm_slli_pi16 #define _m_pslld _mm_sll_pi32 #define _m_pslldi _mm_slli_pi32 #define _m_psllq _mm_sll_si64 #define _m_psllqi _mm_slli_si64 #define _m_psraw _mm_sra_pi16 #define _m_psrawi _mm_srai_pi16 #define _m_psrad _mm_sra_pi32 #define _m_psradi _mm_srai_pi32 #define _m_psrlw _mm_srl_pi16 #define _m_psrlwi _mm_srli_pi16 #define _m_psrld _mm_srl_pi32 #define _m_psrldi _mm_srli_pi32 #define _m_psrlq _mm_srl_si64 #define _m_psrlqi _mm_srli_si64 #define _m_pand _mm_and_si64 #define _m_pandn _mm_andnot_si64 #define _m_por _mm_or_si64 #define _m_pxor _mm_xor_si64 #define _m_pcmpeqb _mm_cmpeq_pi8 #define _m_pcmpeqw _mm_cmpeq_pi16 #define _m_pcmpeqd _mm_cmpeq_pi32 #define _m_pcmpgtb _mm_cmpgt_pi8 #define _m_pcmpgtw _mm_cmpgt_pi16 #define _m_pcmpgtd _mm_cmpgt_pi32 #endif /* __MMX__ */ #endif /* __MMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/mm_malloc.h
/*===---- mm_malloc.h - Allocating and Freeing Aligned Memory Blocks -------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __MM_MALLOC_H #define __MM_MALLOC_H #include <stdlib.h> #ifdef _WIN32 #include <malloc.h> #else #ifndef __cplusplus extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size); #else // Some systems (e.g. those with GNU libc) declare posix_memalign with an // exception specifier. Via an "egregious workaround" in // Sema::CheckEquivalentExceptionSpec, Clang accepts the following as a valid // redeclaration of glibc's declaration. extern "C" int posix_memalign(void **__memptr, size_t __alignment, size_t __size); #endif #endif #if !(defined(_WIN32) && defined(_mm_malloc)) static __inline__ void *__attribute__((__always_inline__, __nodebug__, __malloc__)) _mm_malloc(size_t __size, size_t __align) { if (__align == 1) { return malloc(__size); } if (!(__align & (__align - 1)) && __align < sizeof(void *)) __align = sizeof(void *); void *__mallocedMemory; #if defined(__MINGW32__) __mallocedMemory = __mingw_aligned_malloc(__size, __align); #elif defined(_WIN32) __mallocedMemory = _aligned_malloc(__size, __align); #else if (posix_memalign(&__mallocedMemory, __align, __size)) return 0; #endif return __mallocedMemory; } static __inline__ void __attribute__((__always_inline__, __nodebug__)) _mm_free(void *__p) { free(__p); } #endif #endif /* __MM_MALLOC_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/nmmintrin.h
/*===---- nmmintrin.h - SSE4 intrinsics ------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef _NMMINTRIN_H #define _NMMINTRIN_H #ifndef __SSE4_2__ #error "SSE4.2 instruction set not enabled" #else /* To match expectations of gcc we put the sse4.2 definitions into smmintrin.h, just include it now then. */ #include <smmintrin.h> #endif /* __SSE4_2__ */ #endif /* _NMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/s390intrin.h
/*===---- s390intrin.h - SystemZ intrinsics --------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __S390INTRIN_H #define __S390INTRIN_H #ifndef __s390__ #error "<s390intrin.h> is for s390 only" #endif #ifdef __HTM__ #include <htmintrin.h> #endif #ifdef __VEC__ #include <vecintrin.h> #endif #endif /* __S390INTRIN_H*/
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/float.h
/*===---- float.h - Characteristics of floating point types ----------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __FLOAT_H #define __FLOAT_H /* If we're on MinGW, fall back to the system's float.h, which might have * additional definitions provided for Windows. * For more details see http://msdn.microsoft.com/en-us/library/y0ybw9fy.aspx */ #if (defined(__MINGW32__) || defined(_MSC_VER)) && __STDC_HOSTED__ && \ __has_include_next(<float.h>) # include_next <float.h> /* Undefine anything that we'll be redefining below. */ # undef FLT_EVAL_METHOD # undef FLT_ROUNDS # undef FLT_RADIX # undef FLT_MANT_DIG # undef DBL_MANT_DIG # undef LDBL_MANT_DIG # undef DECIMAL_DIG # undef FLT_DIG # undef DBL_DIG # undef LDBL_DIG # undef FLT_MIN_EXP # undef DBL_MIN_EXP # undef LDBL_MIN_EXP # undef FLT_MIN_10_EXP # undef DBL_MIN_10_EXP # undef LDBL_MIN_10_EXP # undef FLT_MAX_EXP # undef DBL_MAX_EXP # undef LDBL_MAX_EXP # undef FLT_MAX_10_EXP # undef DBL_MAX_10_EXP # undef LDBL_MAX_10_EXP # undef FLT_MAX # undef DBL_MAX # undef LDBL_MAX # undef FLT_EPSILON # undef DBL_EPSILON # undef LDBL_EPSILON # undef FLT_MIN # undef DBL_MIN # undef LDBL_MIN # if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__) # undef FLT_TRUE_MIN # undef DBL_TRUE_MIN # undef LDBL_TRUE_MIN # endif #endif /* Characteristics of floating point types, C99 5.2.4.2.2 */ #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ #define FLT_ROUNDS (__builtin_flt_rounds()) #define FLT_RADIX __FLT_RADIX__ #define FLT_MANT_DIG __FLT_MANT_DIG__ #define DBL_MANT_DIG __DBL_MANT_DIG__ #define LDBL_MANT_DIG __LDBL_MANT_DIG__ #define DECIMAL_DIG __DECIMAL_DIG__ #define FLT_DIG __FLT_DIG__ #define DBL_DIG __DBL_DIG__ #define LDBL_DIG __LDBL_DIG__ #define FLT_MIN_EXP __FLT_MIN_EXP__ #define DBL_MIN_EXP __DBL_MIN_EXP__ #define LDBL_MIN_EXP __LDBL_MIN_EXP__ #define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ #define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ #define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ #define FLT_MAX_EXP __FLT_MAX_EXP__ #define DBL_MAX_EXP __DBL_MAX_EXP__ #define LDBL_MAX_EXP __LDBL_MAX_EXP__ #define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ #define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ #define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ #define FLT_MAX __FLT_MAX__ #define DBL_MAX __DBL_MAX__ #define LDBL_MAX __LDBL_MAX__ #define FLT_EPSILON __FLT_EPSILON__ #define DBL_EPSILON __DBL_EPSILON__ #define LDBL_EPSILON __LDBL_EPSILON__ #define FLT_MIN __FLT_MIN__ #define DBL_MIN __DBL_MIN__ #define LDBL_MIN __LDBL_MIN__ #if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__) # define FLT_TRUE_MIN __FLT_DENORM_MIN__ # define DBL_TRUE_MIN __DBL_DENORM_MIN__ # define LDBL_TRUE_MIN __LDBL_DENORM_MIN__ #endif #endif /* __FLOAT_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/iso646.h
/*===---- iso646.h - Standard header for alternate spellings of operators---=== * * Copyright (c) 2008 Eli Friedman * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __ISO646_H #define __ISO646_H #ifndef __cplusplus #define and && #define and_eq &= #define bitand & #define bitor | #define compl ~ #define not ! #define not_eq != #define or || #define or_eq |= #define xor ^ #define xor_eq ^= #endif #endif /* __ISO646_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/adxintrin.h
/*===---- adxintrin.h - ADX intrinsics -------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <adxintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __ADXINTRIN_H #define __ADXINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) /* Intrinsics that are available only if __ADX__ defined */ #ifdef __ADX__ static __inline unsigned char __DEFAULT_FN_ATTRS _addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y, unsigned int *__p) { return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p); } #ifdef __x86_64__ static __inline unsigned char __DEFAULT_FN_ATTRS _addcarryx_u64(unsigned char __cf, unsigned long long __x, unsigned long long __y, unsigned long long *__p) { return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p); } #endif #endif /* Intrinsics that are also available if __ADX__ undefined */ static __inline unsigned char __DEFAULT_FN_ATTRS _addcarry_u32(unsigned char __cf, unsigned int __x, unsigned int __y, unsigned int *__p) { return __builtin_ia32_addcarry_u32(__cf, __x, __y, __p); } #ifdef __x86_64__ static __inline unsigned char __DEFAULT_FN_ATTRS _addcarry_u64(unsigned char __cf, unsigned long long __x, unsigned long long __y, unsigned long long *__p) { return __builtin_ia32_addcarry_u64(__cf, __x, __y, __p); } #endif static __inline unsigned char __DEFAULT_FN_ATTRS _subborrow_u32(unsigned char __cf, unsigned int __x, unsigned int __y, unsigned int *__p) { return __builtin_ia32_subborrow_u32(__cf, __x, __y, __p); } #ifdef __x86_64__ static __inline unsigned char __DEFAULT_FN_ATTRS _subborrow_u64(unsigned char __cf, unsigned long long __x, unsigned long long __y, unsigned long long *__p) { return __builtin_ia32_subborrow_u64(__cf, __x, __y, __p); } #endif #undef __DEFAULT_FN_ATTRS #endif /* __ADXINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/wmmintrin.h
/*===---- wmmintrin.h - AES intrinsics ------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef _WMMINTRIN_H #define _WMMINTRIN_H #include <emmintrin.h> #if !defined (__AES__) && !defined (__PCLMUL__) # error "AES/PCLMUL instructions not enabled" #else #ifdef __AES__ #include <__wmmintrin_aes.h> #endif /* __AES__ */ #ifdef __PCLMUL__ #include <__wmmintrin_pclmul.h> #endif /* __PCLMUL__ */ #endif /* __AES__ || __PCLMUL__ */ #endif /* _WMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/stdalign.h
/*===---- stdalign.h - Standard header for alignment ------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __STDALIGN_H #define __STDALIGN_H #ifndef __cplusplus #define alignas _Alignas #define alignof _Alignof #endif #define __alignas_is_defined 1 #define __alignof_is_defined 1 #endif /* __STDALIGN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/rtmintrin.h
/*===---- rtmintrin.h - RTM intrinsics -------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <rtmintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __RTMINTRIN_H #define __RTMINTRIN_H #define _XBEGIN_STARTED (~0u) #define _XABORT_EXPLICIT (1 << 0) #define _XABORT_RETRY (1 << 1) #define _XABORT_CONFLICT (1 << 2) #define _XABORT_CAPACITY (1 << 3) #define _XABORT_DEBUG (1 << 4) #define _XABORT_NESTED (1 << 5) #define _XABORT_CODE(x) (((x) >> 24) & 0xFF) /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ unsigned int __DEFAULT_FN_ATTRS _xbegin(void) { return __builtin_ia32_xbegin(); } static __inline__ void __DEFAULT_FN_ATTRS _xend(void) { __builtin_ia32_xend(); } #define _xabort(imm) __builtin_ia32_xabort((imm)) #undef __DEFAULT_FN_ATTRS #endif /* __RTMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/bmiintrin.h
/*===---- bmiintrin.h - BMI intrinsics -------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H #error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead." #endif #ifndef __BMI__ # error "BMI instruction set not enabled" #endif /* __BMI__ */ #ifndef __BMIINTRIN_H #define __BMIINTRIN_H #define _tzcnt_u16(a) (__tzcnt_u16((a))) #define _andn_u32(a, b) (__andn_u32((a), (b))) /* _bextr_u32 != __bextr_u32 */ #define _blsi_u32(a) (__blsi_u32((a))) #define _blsmsk_u32(a) (__blsmsk_u32((a))) #define _blsr_u32(a) (__blsr_u32((a))) #define _tzcnt_u32(a) (__tzcnt_u32((a))) /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ unsigned short __DEFAULT_FN_ATTRS __tzcnt_u16(unsigned short __X) { return __X ? __builtin_ctzs(__X) : 16; } static __inline__ unsigned int __DEFAULT_FN_ATTRS __andn_u32(unsigned int __X, unsigned int __Y) { return ~__X & __Y; } /* AMD-specified, double-leading-underscore version of BEXTR */ static __inline__ unsigned int __DEFAULT_FN_ATTRS __bextr_u32(unsigned int __X, unsigned int __Y) { return __builtin_ia32_bextr_u32(__X, __Y); } /* Intel-specified, single-leading-underscore version of BEXTR */ static __inline__ unsigned int __DEFAULT_FN_ATTRS _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z) { return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); } static __inline__ unsigned int __DEFAULT_FN_ATTRS __blsi_u32(unsigned int __X) { return __X & -__X; } static __inline__ unsigned int __DEFAULT_FN_ATTRS __blsmsk_u32(unsigned int __X) { return __X ^ (__X - 1); } static __inline__ unsigned int __DEFAULT_FN_ATTRS __blsr_u32(unsigned int __X) { return __X & (__X - 1); } static __inline__ unsigned int __DEFAULT_FN_ATTRS __tzcnt_u32(unsigned int __X) { return __X ? __builtin_ctz(__X) : 32; } #ifdef __x86_64__ #define _andn_u64(a, b) (__andn_u64((a), (b))) /* _bextr_u64 != __bextr_u64 */ #define _blsi_u64(a) (__blsi_u64((a))) #define _blsmsk_u64(a) (__blsmsk_u64((a))) #define _blsr_u64(a) (__blsr_u64((a))) #define _tzcnt_u64(a) (__tzcnt_u64((a))) static __inline__ unsigned long long __DEFAULT_FN_ATTRS __andn_u64 (unsigned long long __X, unsigned long long __Y) { return ~__X & __Y; } /* AMD-specified, double-leading-underscore version of BEXTR */ static __inline__ unsigned long long __DEFAULT_FN_ATTRS __bextr_u64(unsigned long long __X, unsigned long long __Y) { return __builtin_ia32_bextr_u64(__X, __Y); } /* Intel-specified, single-leading-underscore version of BEXTR */ static __inline__ unsigned long long __DEFAULT_FN_ATTRS _bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z) { return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); } static __inline__ unsigned long long __DEFAULT_FN_ATTRS __blsi_u64(unsigned long long __X) { return __X & -__X; } static __inline__ unsigned long long __DEFAULT_FN_ATTRS __blsmsk_u64(unsigned long long __X) { return __X ^ (__X - 1); } static __inline__ unsigned long long __DEFAULT_FN_ATTRS __blsr_u64(unsigned long long __X) { return __X & (__X - 1); } static __inline__ unsigned long long __DEFAULT_FN_ATTRS __tzcnt_u64(unsigned long long __X) { return __X ? __builtin_ctzll(__X) : 64; } #endif /* __x86_64__ */ #undef __DEFAULT_FN_ATTRS #endif /* __BMIINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avx2intrin.h
/*===---- avx2intrin.h - AVX2 intrinsics -----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avx2intrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVX2INTRIN_H #define __AVX2INTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) /* SSE4 Multiple Packed Sums of Absolute Difference. */ #define _mm256_mpsadbw_epu8(X, Y, M) __builtin_ia32_mpsadbw256((X), (Y), (M)) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_abs_epi8(__m256i __a) { return (__m256i)__builtin_ia32_pabsb256((__v32qi)__a); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_abs_epi16(__m256i __a) { return (__m256i)__builtin_ia32_pabsw256((__v16hi)__a); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_abs_epi32(__m256i __a) { return (__m256i)__builtin_ia32_pabsd256((__v8si)__a); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_packs_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_packsswb256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_packs_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_packssdw256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_packus_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_packuswb256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_packus_epi32(__m256i __V1, __m256i __V2) { return (__m256i) __builtin_ia32_packusdw256((__v8si)__V1, (__v8si)__V2); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_add_epi8(__m256i __a, __m256i __b) { return (__m256i)((__v32qi)__a + (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_add_epi16(__m256i __a, __m256i __b) { return (__m256i)((__v16hi)__a + (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_add_epi32(__m256i __a, __m256i __b) { return (__m256i)((__v8si)__a + (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_add_epi64(__m256i __a, __m256i __b) { return __a + __b; } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_adds_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_paddsb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_adds_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_paddsw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_adds_epu8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_paddusb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_adds_epu16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_paddusw256((__v16hi)__a, (__v16hi)__b); } #define _mm256_alignr_epi8(a, b, n) __extension__ ({ \ __m256i __a = (a); \ __m256i __b = (b); \ (__m256i)__builtin_ia32_palignr256((__v32qi)__a, (__v32qi)__b, (n)); }) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_and_si256(__m256i __a, __m256i __b) { return __a & __b; } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_andnot_si256(__m256i __a, __m256i __b) { return ~__a & __b; } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_avg_epu8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pavgb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_avg_epu16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pavgw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_blendv_epi8(__m256i __V1, __m256i __V2, __m256i __M) { return (__m256i)__builtin_ia32_pblendvb256((__v32qi)__V1, (__v32qi)__V2, (__v32qi)__M); } #define _mm256_blend_epi16(V1, V2, M) __extension__ ({ \ __m256i __V1 = (V1); \ __m256i __V2 = (V2); \ (__m256i)__builtin_shufflevector((__v16hi)__V1, (__v16hi)__V2, \ (((M) & 0x01) ? 16 : 0), \ (((M) & 0x02) ? 17 : 1), \ (((M) & 0x04) ? 18 : 2), \ (((M) & 0x08) ? 19 : 3), \ (((M) & 0x10) ? 20 : 4), \ (((M) & 0x20) ? 21 : 5), \ (((M) & 0x40) ? 22 : 6), \ (((M) & 0x80) ? 23 : 7), \ (((M) & 0x01) ? 24 : 8), \ (((M) & 0x02) ? 25 : 9), \ (((M) & 0x04) ? 26 : 10), \ (((M) & 0x08) ? 27 : 11), \ (((M) & 0x10) ? 28 : 12), \ (((M) & 0x20) ? 29 : 13), \ (((M) & 0x40) ? 30 : 14), \ (((M) & 0x80) ? 31 : 15)); }) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpeq_epi8(__m256i __a, __m256i __b) { return (__m256i)((__v32qi)__a == (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpeq_epi16(__m256i __a, __m256i __b) { return (__m256i)((__v16hi)__a == (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpeq_epi32(__m256i __a, __m256i __b) { return (__m256i)((__v8si)__a == (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpeq_epi64(__m256i __a, __m256i __b) { return (__m256i)(__a == __b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpgt_epi8(__m256i __a, __m256i __b) { return (__m256i)((__v32qi)__a > (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpgt_epi16(__m256i __a, __m256i __b) { return (__m256i)((__v16hi)__a > (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpgt_epi32(__m256i __a, __m256i __b) { return (__m256i)((__v8si)__a > (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cmpgt_epi64(__m256i __a, __m256i __b) { return (__m256i)(__a > __b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_hadd_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_phaddw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_hadd_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_phaddd256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_hadds_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_phaddsw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_hsub_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_phsubw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_hsub_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_phsubd256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_hsubs_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_phsubsw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maddubs_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaddubsw256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_madd_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaddwd256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_max_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaxsb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_max_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaxsw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_max_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaxsd256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_max_epu8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaxub256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_max_epu16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaxuw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_max_epu32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmaxud256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_min_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pminsb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_min_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pminsw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_min_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pminsd256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_min_epu8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pminub256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_min_epu16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pminuw256 ((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_min_epu32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pminud256((__v8si)__a, (__v8si)__b); } static __inline__ int __DEFAULT_FN_ATTRS _mm256_movemask_epi8(__m256i __a) { return __builtin_ia32_pmovmskb256((__v32qi)__a); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepi8_epi16(__m128i __V) { return (__m256i)__builtin_ia32_pmovsxbw256((__v16qi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepi8_epi32(__m128i __V) { return (__m256i)__builtin_ia32_pmovsxbd256((__v16qi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepi8_epi64(__m128i __V) { return (__m256i)__builtin_ia32_pmovsxbq256((__v16qi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepi16_epi32(__m128i __V) { return (__m256i)__builtin_ia32_pmovsxwd256((__v8hi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepi16_epi64(__m128i __V) { return (__m256i)__builtin_ia32_pmovsxwq256((__v8hi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepi32_epi64(__m128i __V) { return (__m256i)__builtin_ia32_pmovsxdq256((__v4si)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepu8_epi16(__m128i __V) { return (__m256i)__builtin_ia32_pmovzxbw256((__v16qi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepu8_epi32(__m128i __V) { return (__m256i)__builtin_ia32_pmovzxbd256((__v16qi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepu8_epi64(__m128i __V) { return (__m256i)__builtin_ia32_pmovzxbq256((__v16qi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepu16_epi32(__m128i __V) { return (__m256i)__builtin_ia32_pmovzxwd256((__v8hi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepu16_epi64(__m128i __V) { return (__m256i)__builtin_ia32_pmovzxwq256((__v8hi)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_cvtepu32_epi64(__m128i __V) { return (__m256i)__builtin_ia32_pmovzxdq256((__v4si)__V); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mul_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmuldq256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mulhrs_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmulhrsw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mulhi_epu16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmulhuw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mulhi_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pmulhw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mullo_epi16(__m256i __a, __m256i __b) { return (__m256i)((__v16hi)__a * (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mullo_epi32 (__m256i __a, __m256i __b) { return (__m256i)((__v8si)__a * (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mul_epu32(__m256i __a, __m256i __b) { return __builtin_ia32_pmuludq256((__v8si)__a, (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_or_si256(__m256i __a, __m256i __b) { return __a | __b; } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sad_epu8(__m256i __a, __m256i __b) { return __builtin_ia32_psadbw256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_shuffle_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_pshufb256((__v32qi)__a, (__v32qi)__b); } #define _mm256_shuffle_epi32(a, imm) __extension__ ({ \ __m256i __a = (a); \ (__m256i)__builtin_shufflevector((__v8si)__a, (__v8si)_mm256_set1_epi32(0), \ (imm) & 0x3, ((imm) & 0xc) >> 2, \ ((imm) & 0x30) >> 4, ((imm) & 0xc0) >> 6, \ 4 + (((imm) & 0x03) >> 0), \ 4 + (((imm) & 0x0c) >> 2), \ 4 + (((imm) & 0x30) >> 4), \ 4 + (((imm) & 0xc0) >> 6)); }) #define _mm256_shufflehi_epi16(a, imm) __extension__ ({ \ __m256i __a = (a); \ (__m256i)__builtin_shufflevector((__v16hi)__a, (__v16hi)_mm256_set1_epi16(0), \ 0, 1, 2, 3, \ 4 + (((imm) & 0x03) >> 0), \ 4 + (((imm) & 0x0c) >> 2), \ 4 + (((imm) & 0x30) >> 4), \ 4 + (((imm) & 0xc0) >> 6), \ 8, 9, 10, 11, \ 12 + (((imm) & 0x03) >> 0), \ 12 + (((imm) & 0x0c) >> 2), \ 12 + (((imm) & 0x30) >> 4), \ 12 + (((imm) & 0xc0) >> 6)); }) #define _mm256_shufflelo_epi16(a, imm) __extension__ ({ \ __m256i __a = (a); \ (__m256i)__builtin_shufflevector((__v16hi)__a, (__v16hi)_mm256_set1_epi16(0), \ (imm) & 0x3,((imm) & 0xc) >> 2, \ ((imm) & 0x30) >> 4, ((imm) & 0xc0) >> 6, \ 4, 5, 6, 7, \ 8 + (((imm) & 0x03) >> 0), \ 8 + (((imm) & 0x0c) >> 2), \ 8 + (((imm) & 0x30) >> 4), \ 8 + (((imm) & 0xc0) >> 6), \ 12, 13, 14, 15); }) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sign_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_psignb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sign_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_psignw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sign_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_psignd256((__v8si)__a, (__v8si)__b); } #define _mm256_slli_si256(a, count) __extension__ ({ \ __m256i __a = (a); \ (__m256i)__builtin_ia32_pslldqi256(__a, (count)*8); }) #define _mm256_bslli_epi128(a, count) _mm256_slli_si256((a), (count)) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_slli_epi16(__m256i __a, int __count) { return (__m256i)__builtin_ia32_psllwi256((__v16hi)__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sll_epi16(__m256i __a, __m128i __count) { return (__m256i)__builtin_ia32_psllw256((__v16hi)__a, (__v8hi)__count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_slli_epi32(__m256i __a, int __count) { return (__m256i)__builtin_ia32_pslldi256((__v8si)__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sll_epi32(__m256i __a, __m128i __count) { return (__m256i)__builtin_ia32_pslld256((__v8si)__a, (__v4si)__count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_slli_epi64(__m256i __a, int __count) { return __builtin_ia32_psllqi256(__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sll_epi64(__m256i __a, __m128i __count) { return __builtin_ia32_psllq256(__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srai_epi16(__m256i __a, int __count) { return (__m256i)__builtin_ia32_psrawi256((__v16hi)__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sra_epi16(__m256i __a, __m128i __count) { return (__m256i)__builtin_ia32_psraw256((__v16hi)__a, (__v8hi)__count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srai_epi32(__m256i __a, int __count) { return (__m256i)__builtin_ia32_psradi256((__v8si)__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sra_epi32(__m256i __a, __m128i __count) { return (__m256i)__builtin_ia32_psrad256((__v8si)__a, (__v4si)__count); } #define _mm256_srli_si256(a, count) __extension__ ({ \ __m256i __a = (a); \ (__m256i)__builtin_ia32_psrldqi256(__a, (count)*8); }) #define _mm256_bsrli_epi128(a, count) _mm256_srli_si256((a), (count)) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srli_epi16(__m256i __a, int __count) { return (__m256i)__builtin_ia32_psrlwi256((__v16hi)__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srl_epi16(__m256i __a, __m128i __count) { return (__m256i)__builtin_ia32_psrlw256((__v16hi)__a, (__v8hi)__count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srli_epi32(__m256i __a, int __count) { return (__m256i)__builtin_ia32_psrldi256((__v8si)__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srl_epi32(__m256i __a, __m128i __count) { return (__m256i)__builtin_ia32_psrld256((__v8si)__a, (__v4si)__count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srli_epi64(__m256i __a, int __count) { return __builtin_ia32_psrlqi256(__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srl_epi64(__m256i __a, __m128i __count) { return __builtin_ia32_psrlq256(__a, __count); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sub_epi8(__m256i __a, __m256i __b) { return (__m256i)((__v32qi)__a - (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sub_epi16(__m256i __a, __m256i __b) { return (__m256i)((__v16hi)__a - (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sub_epi32(__m256i __a, __m256i __b) { return (__m256i)((__v8si)__a - (__v8si)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sub_epi64(__m256i __a, __m256i __b) { return __a - __b; } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_subs_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_psubsb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_subs_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_psubsw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_subs_epu8(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_psubusb256((__v32qi)__a, (__v32qi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_subs_epu16(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_psubusw256((__v16hi)__a, (__v16hi)__b); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpackhi_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector((__v32qi)__a, (__v32qi)__b, 8, 32+8, 9, 32+9, 10, 32+10, 11, 32+11, 12, 32+12, 13, 32+13, 14, 32+14, 15, 32+15, 24, 32+24, 25, 32+25, 26, 32+26, 27, 32+27, 28, 32+28, 29, 32+29, 30, 32+30, 31, 32+31); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpackhi_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector((__v16hi)__a, (__v16hi)__b, 4, 16+4, 5, 16+5, 6, 16+6, 7, 16+7, 12, 16+12, 13, 16+13, 14, 16+14, 15, 16+15); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpackhi_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector((__v8si)__a, (__v8si)__b, 2, 8+2, 3, 8+3, 6, 8+6, 7, 8+7); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpackhi_epi64(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector(__a, __b, 1, 4+1, 3, 4+3); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpacklo_epi8(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector((__v32qi)__a, (__v32qi)__b, 0, 32+0, 1, 32+1, 2, 32+2, 3, 32+3, 4, 32+4, 5, 32+5, 6, 32+6, 7, 32+7, 16, 32+16, 17, 32+17, 18, 32+18, 19, 32+19, 20, 32+20, 21, 32+21, 22, 32+22, 23, 32+23); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpacklo_epi16(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector((__v16hi)__a, (__v16hi)__b, 0, 16+0, 1, 16+1, 2, 16+2, 3, 16+3, 8, 16+8, 9, 16+9, 10, 16+10, 11, 16+11); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpacklo_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector((__v8si)__a, (__v8si)__b, 0, 8+0, 1, 8+1, 4, 8+4, 5, 8+5); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_unpacklo_epi64(__m256i __a, __m256i __b) { return (__m256i)__builtin_shufflevector(__a, __b, 0, 4+0, 2, 4+2); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_xor_si256(__m256i __a, __m256i __b) { return __a ^ __b; } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_stream_load_si256(__m256i *__V) { return (__m256i)__builtin_ia32_movntdqa256((__v4di *)__V); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_broadcastss_ps(__m128 __X) { return (__m128)__builtin_ia32_vbroadcastss_ps((__v4sf)__X); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_broadcastsd_pd(__m128d __a) { return __builtin_shufflevector(__a, __a, 0, 0); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_broadcastss_ps(__m128 __X) { return (__m256)__builtin_ia32_vbroadcastss_ps256((__v4sf)__X); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_broadcastsd_pd(__m128d __X) { return (__m256d)__builtin_ia32_vbroadcastsd_pd256((__v2df)__X); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_broadcastsi128_si256(__m128i __X) { return (__m256i)__builtin_shufflevector(__X, __X, 0, 1, 0, 1); } #define _mm_blend_epi32(V1, V2, M) __extension__ ({ \ __m128i __V1 = (V1); \ __m128i __V2 = (V2); \ (__m128i)__builtin_shufflevector((__v4si)__V1, (__v4si)__V2, \ (((M) & 0x01) ? 4 : 0), \ (((M) & 0x02) ? 5 : 1), \ (((M) & 0x04) ? 6 : 2), \ (((M) & 0x08) ? 7 : 3)); }) #define _mm256_blend_epi32(V1, V2, M) __extension__ ({ \ __m256i __V1 = (V1); \ __m256i __V2 = (V2); \ (__m256i)__builtin_shufflevector((__v8si)__V1, (__v8si)__V2, \ (((M) & 0x01) ? 8 : 0), \ (((M) & 0x02) ? 9 : 1), \ (((M) & 0x04) ? 10 : 2), \ (((M) & 0x08) ? 11 : 3), \ (((M) & 0x10) ? 12 : 4), \ (((M) & 0x20) ? 13 : 5), \ (((M) & 0x40) ? 14 : 6), \ (((M) & 0x80) ? 15 : 7)); }) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_broadcastb_epi8(__m128i __X) { return (__m256i)__builtin_ia32_pbroadcastb256((__v16qi)__X); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_broadcastw_epi16(__m128i __X) { return (__m256i)__builtin_ia32_pbroadcastw256((__v8hi)__X); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_broadcastd_epi32(__m128i __X) { return (__m256i)__builtin_ia32_pbroadcastd256((__v4si)__X); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_broadcastq_epi64(__m128i __X) { return (__m256i)__builtin_ia32_pbroadcastq256(__X); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_broadcastb_epi8(__m128i __X) { return (__m128i)__builtin_ia32_pbroadcastb128((__v16qi)__X); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_broadcastw_epi16(__m128i __X) { return (__m128i)__builtin_ia32_pbroadcastw128((__v8hi)__X); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_broadcastd_epi32(__m128i __X) { return (__m128i)__builtin_ia32_pbroadcastd128((__v4si)__X); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_broadcastq_epi64(__m128i __X) { return (__m128i)__builtin_ia32_pbroadcastq128(__X); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_permutevar8x32_epi32(__m256i __a, __m256i __b) { return (__m256i)__builtin_ia32_permvarsi256((__v8si)__a, (__v8si)__b); } #define _mm256_permute4x64_pd(V, M) __extension__ ({ \ __m256d __V = (V); \ (__m256d)__builtin_shufflevector((__v4df)__V, (__v4df) _mm256_setzero_pd(), \ (M) & 0x3, ((M) & 0xc) >> 2, \ ((M) & 0x30) >> 4, ((M) & 0xc0) >> 6); }) static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_permutevar8x32_ps(__m256 __a, __m256 __b) { return (__m256)__builtin_ia32_permvarsf256((__v8sf)__a, (__v8sf)__b); } #define _mm256_permute4x64_epi64(V, M) __extension__ ({ \ __m256i __V = (V); \ (__m256i)__builtin_shufflevector((__v4di)__V, (__v4di) _mm256_setzero_si256(), \ (M) & 0x3, ((M) & 0xc) >> 2, \ ((M) & 0x30) >> 4, ((M) & 0xc0) >> 6); }) #define _mm256_permute2x128_si256(V1, V2, M) __extension__ ({ \ __m256i __V1 = (V1); \ __m256i __V2 = (V2); \ (__m256i)__builtin_ia32_permti256(__V1, __V2, (M)); }) #define _mm256_extracti128_si256(V, M) __extension__ ({ \ (__m128i)__builtin_shufflevector( \ (__v4di)(V), \ (__v4di)(_mm256_setzero_si256()), \ (((M) & 1) ? 2 : 0), \ (((M) & 1) ? 3 : 1) );}) #define _mm256_inserti128_si256(V1, V2, M) __extension__ ({ \ (__m256i)__builtin_shufflevector( \ (__v4di)(V1), \ (__v4di)_mm256_castsi128_si256((__m128i)(V2)), \ (((M) & 1) ? 0 : 4), \ (((M) & 1) ? 1 : 5), \ (((M) & 1) ? 4 : 2), \ (((M) & 1) ? 5 : 3) );}) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskload_epi32(int const *__X, __m256i __M) { return (__m256i)__builtin_ia32_maskloadd256((const __v8si *)__X, (__v8si)__M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskload_epi64(long long const *__X, __m256i __M) { return (__m256i)__builtin_ia32_maskloadq256((const __v4di *)__X, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskload_epi32(int const *__X, __m128i __M) { return (__m128i)__builtin_ia32_maskloadd((const __v4si *)__X, (__v4si)__M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskload_epi64(long long const *__X, __m128i __M) { return (__m128i)__builtin_ia32_maskloadq((const __v2di *)__X, (__v2di)__M); } static __inline__ void __DEFAULT_FN_ATTRS _mm256_maskstore_epi32(int *__X, __m256i __M, __m256i __Y) { __builtin_ia32_maskstored256((__v8si *)__X, (__v8si)__M, (__v8si)__Y); } static __inline__ void __DEFAULT_FN_ATTRS _mm256_maskstore_epi64(long long *__X, __m256i __M, __m256i __Y) { __builtin_ia32_maskstoreq256((__v4di *)__X, __M, __Y); } static __inline__ void __DEFAULT_FN_ATTRS _mm_maskstore_epi32(int *__X, __m128i __M, __m128i __Y) { __builtin_ia32_maskstored((__v4si *)__X, (__v4si)__M, (__v4si)__Y); } static __inline__ void __DEFAULT_FN_ATTRS _mm_maskstore_epi64(long long *__X, __m128i __M, __m128i __Y) { __builtin_ia32_maskstoreq(( __v2di *)__X, __M, __Y); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sllv_epi32(__m256i __X, __m256i __Y) { return (__m256i)__builtin_ia32_psllv8si((__v8si)__X, (__v8si)__Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sllv_epi32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_psllv4si((__v4si)__X, (__v4si)__Y); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_sllv_epi64(__m256i __X, __m256i __Y) { return (__m256i)__builtin_ia32_psllv4di(__X, __Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sllv_epi64(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_psllv2di(__X, __Y); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srav_epi32(__m256i __X, __m256i __Y) { return (__m256i)__builtin_ia32_psrav8si((__v8si)__X, (__v8si)__Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srav_epi32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_psrav4si((__v4si)__X, (__v4si)__Y); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srlv_epi32(__m256i __X, __m256i __Y) { return (__m256i)__builtin_ia32_psrlv8si((__v8si)__X, (__v8si)__Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srlv_epi32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_psrlv4si((__v4si)__X, (__v4si)__Y); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_srlv_epi64(__m256i __X, __m256i __Y) { return (__m256i)__builtin_ia32_psrlv4di(__X, __Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srlv_epi64(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_psrlv2di(__X, __Y); } #define _mm_mask_i32gather_pd(a, m, i, mask, s) __extension__ ({ \ __m128d __a = (a); \ double const *__m = (m); \ __m128i __i = (i); \ __m128d __mask = (mask); \ (__m128d)__builtin_ia32_gatherd_pd((__v2df)__a, (const __v2df *)__m, \ (__v4si)__i, (__v2df)__mask, (s)); }) #define _mm256_mask_i32gather_pd(a, m, i, mask, s) __extension__ ({ \ __m256d __a = (a); \ double const *__m = (m); \ __m128i __i = (i); \ __m256d __mask = (mask); \ (__m256d)__builtin_ia32_gatherd_pd256((__v4df)__a, (const __v4df *)__m, \ (__v4si)__i, (__v4df)__mask, (s)); }) #define _mm_mask_i64gather_pd(a, m, i, mask, s) __extension__ ({ \ __m128d __a = (a); \ double const *__m = (m); \ __m128i __i = (i); \ __m128d __mask = (mask); \ (__m128d)__builtin_ia32_gatherq_pd((__v2df)__a, (const __v2df *)__m, \ (__v2di)__i, (__v2df)__mask, (s)); }) #define _mm256_mask_i64gather_pd(a, m, i, mask, s) __extension__ ({ \ __m256d __a = (a); \ double const *__m = (m); \ __m256i __i = (i); \ __m256d __mask = (mask); \ (__m256d)__builtin_ia32_gatherq_pd256((__v4df)__a, (const __v4df *)__m, \ (__v4di)__i, (__v4df)__mask, (s)); }) #define _mm_mask_i32gather_ps(a, m, i, mask, s) __extension__ ({ \ __m128 __a = (a); \ float const *__m = (m); \ __m128i __i = (i); \ __m128 __mask = (mask); \ (__m128)__builtin_ia32_gatherd_ps((__v4sf)__a, (const __v4sf *)__m, \ (__v4si)__i, (__v4sf)__mask, (s)); }) #define _mm256_mask_i32gather_ps(a, m, i, mask, s) __extension__ ({ \ __m256 __a = (a); \ float const *__m = (m); \ __m256i __i = (i); \ __m256 __mask = (mask); \ (__m256)__builtin_ia32_gatherd_ps256((__v8sf)__a, (const __v8sf *)__m, \ (__v8si)__i, (__v8sf)__mask, (s)); }) #define _mm_mask_i64gather_ps(a, m, i, mask, s) __extension__ ({ \ __m128 __a = (a); \ float const *__m = (m); \ __m128i __i = (i); \ __m128 __mask = (mask); \ (__m128)__builtin_ia32_gatherq_ps((__v4sf)__a, (const __v4sf *)__m, \ (__v2di)__i, (__v4sf)__mask, (s)); }) #define _mm256_mask_i64gather_ps(a, m, i, mask, s) __extension__ ({ \ __m128 __a = (a); \ float const *__m = (m); \ __m256i __i = (i); \ __m128 __mask = (mask); \ (__m128)__builtin_ia32_gatherq_ps256((__v4sf)__a, (const __v4sf *)__m, \ (__v4di)__i, (__v4sf)__mask, (s)); }) #define _mm_mask_i32gather_epi32(a, m, i, mask, s) __extension__ ({ \ __m128i __a = (a); \ int const *__m = (m); \ __m128i __i = (i); \ __m128i __mask = (mask); \ (__m128i)__builtin_ia32_gatherd_d((__v4si)__a, (const __v4si *)__m, \ (__v4si)__i, (__v4si)__mask, (s)); }) #define _mm256_mask_i32gather_epi32(a, m, i, mask, s) __extension__ ({ \ __m256i __a = (a); \ int const *__m = (m); \ __m256i __i = (i); \ __m256i __mask = (mask); \ (__m256i)__builtin_ia32_gatherd_d256((__v8si)__a, (const __v8si *)__m, \ (__v8si)__i, (__v8si)__mask, (s)); }) #define _mm_mask_i64gather_epi32(a, m, i, mask, s) __extension__ ({ \ __m128i __a = (a); \ int const *__m = (m); \ __m128i __i = (i); \ __m128i __mask = (mask); \ (__m128i)__builtin_ia32_gatherq_d((__v4si)__a, (const __v4si *)__m, \ (__v2di)__i, (__v4si)__mask, (s)); }) #define _mm256_mask_i64gather_epi32(a, m, i, mask, s) __extension__ ({ \ __m128i __a = (a); \ int const *__m = (m); \ __m256i __i = (i); \ __m128i __mask = (mask); \ (__m128i)__builtin_ia32_gatherq_d256((__v4si)__a, (const __v4si *)__m, \ (__v4di)__i, (__v4si)__mask, (s)); }) #define _mm_mask_i32gather_epi64(a, m, i, mask, s) __extension__ ({ \ __m128i __a = (a); \ long long const *__m = (m); \ __m128i __i = (i); \ __m128i __mask = (mask); \ (__m128i)__builtin_ia32_gatherd_q((__v2di)__a, (const __v2di *)__m, \ (__v4si)__i, (__v2di)__mask, (s)); }) #define _mm256_mask_i32gather_epi64(a, m, i, mask, s) __extension__ ({ \ __m256i __a = (a); \ long long const *__m = (m); \ __m128i __i = (i); \ __m256i __mask = (mask); \ (__m256i)__builtin_ia32_gatherd_q256((__v4di)__a, (const __v4di *)__m, \ (__v4si)__i, (__v4di)__mask, (s)); }) #define _mm_mask_i64gather_epi64(a, m, i, mask, s) __extension__ ({ \ __m128i __a = (a); \ long long const *__m = (m); \ __m128i __i = (i); \ __m128i __mask = (mask); \ (__m128i)__builtin_ia32_gatherq_q((__v2di)__a, (const __v2di *)__m, \ (__v2di)__i, (__v2di)__mask, (s)); }) #define _mm256_mask_i64gather_epi64(a, m, i, mask, s) __extension__ ({ \ __m256i __a = (a); \ long long const *__m = (m); \ __m256i __i = (i); \ __m256i __mask = (mask); \ (__m256i)__builtin_ia32_gatherq_q256((__v4di)__a, (const __v4di *)__m, \ (__v4di)__i, (__v4di)__mask, (s)); }) #define _mm_i32gather_pd(m, i, s) __extension__ ({ \ double const *__m = (m); \ __m128i __i = (i); \ (__m128d)__builtin_ia32_gatherd_pd((__v2df)_mm_setzero_pd(), \ (const __v2df *)__m, (__v4si)__i, \ (__v2df)_mm_set1_pd((double)(long long int)-1), (s)); }) #define _mm256_i32gather_pd(m, i, s) __extension__ ({ \ double const *__m = (m); \ __m128i __i = (i); \ (__m256d)__builtin_ia32_gatherd_pd256((__v4df)_mm256_setzero_pd(), \ (const __v4df *)__m, (__v4si)__i, \ (__v4df)_mm256_set1_pd((double)(long long int)-1), (s)); }) #define _mm_i64gather_pd(m, i, s) __extension__ ({ \ double const *__m = (m); \ __m128i __i = (i); \ (__m128d)__builtin_ia32_gatherq_pd((__v2df)_mm_setzero_pd(), \ (const __v2df *)__m, (__v2di)__i, \ (__v2df)_mm_set1_pd((double)(long long int)-1), (s)); }) #define _mm256_i64gather_pd(m, i, s) __extension__ ({ \ double const *__m = (m); \ __m256i __i = (i); \ (__m256d)__builtin_ia32_gatherq_pd256((__v4df)_mm256_setzero_pd(), \ (const __v4df *)__m, (__v4di)__i, \ (__v4df)_mm256_set1_pd((double)(long long int)-1), (s)); }) #define _mm_i32gather_ps(m, i, s) __extension__ ({ \ float const *__m = (m); \ __m128i __i = (i); \ (__m128)__builtin_ia32_gatherd_ps((__v4sf)_mm_setzero_ps(), \ (const __v4sf *)__m, (__v4si)__i, \ (__v4sf)_mm_set1_ps((float)(int)-1), (s)); }) #define _mm256_i32gather_ps(m, i, s) __extension__ ({ \ float const *__m = (m); \ __m256i __i = (i); \ (__m256)__builtin_ia32_gatherd_ps256((__v8sf)_mm256_setzero_ps(), \ (const __v8sf *)__m, (__v8si)__i, \ (__v8sf)_mm256_set1_ps((float)(int)-1), (s)); }) #define _mm_i64gather_ps(m, i, s) __extension__ ({ \ float const *__m = (m); \ __m128i __i = (i); \ (__m128)__builtin_ia32_gatherq_ps((__v4sf)_mm_setzero_ps(), \ (const __v4sf *)__m, (__v2di)__i, \ (__v4sf)_mm_set1_ps((float)(int)-1), (s)); }) #define _mm256_i64gather_ps(m, i, s) __extension__ ({ \ float const *__m = (m); \ __m256i __i = (i); \ (__m128)__builtin_ia32_gatherq_ps256((__v4sf)_mm_setzero_ps(), \ (const __v4sf *)__m, (__v4di)__i, \ (__v4sf)_mm_set1_ps((float)(int)-1), (s)); }) #define _mm_i32gather_epi32(m, i, s) __extension__ ({ \ int const *__m = (m); \ __m128i __i = (i); \ (__m128i)__builtin_ia32_gatherd_d((__v4si)_mm_setzero_si128(), \ (const __v4si *)__m, (__v4si)__i, \ (__v4si)_mm_set1_epi32(-1), (s)); }) #define _mm256_i32gather_epi32(m, i, s) __extension__ ({ \ int const *__m = (m); \ __m256i __i = (i); \ (__m256i)__builtin_ia32_gatherd_d256((__v8si)_mm256_setzero_si256(), \ (const __v8si *)__m, (__v8si)__i, \ (__v8si)_mm256_set1_epi32(-1), (s)); }) #define _mm_i64gather_epi32(m, i, s) __extension__ ({ \ int const *__m = (m); \ __m128i __i = (i); \ (__m128i)__builtin_ia32_gatherq_d((__v4si)_mm_setzero_si128(), \ (const __v4si *)__m, (__v2di)__i, \ (__v4si)_mm_set1_epi32(-1), (s)); }) #define _mm256_i64gather_epi32(m, i, s) __extension__ ({ \ int const *__m = (m); \ __m256i __i = (i); \ (__m128i)__builtin_ia32_gatherq_d256((__v4si)_mm_setzero_si128(), \ (const __v4si *)__m, (__v4di)__i, \ (__v4si)_mm_set1_epi32(-1), (s)); }) #define _mm_i32gather_epi64(m, i, s) __extension__ ({ \ long long const *__m = (m); \ __m128i __i = (i); \ (__m128i)__builtin_ia32_gatherd_q((__v2di)_mm_setzero_si128(), \ (const __v2di *)__m, (__v4si)__i, \ (__v2di)_mm_set1_epi64x(-1), (s)); }) #define _mm256_i32gather_epi64(m, i, s) __extension__ ({ \ long long const *__m = (m); \ __m128i __i = (i); \ (__m256i)__builtin_ia32_gatherd_q256((__v4di)_mm256_setzero_si256(), \ (const __v4di *)__m, (__v4si)__i, \ (__v4di)_mm256_set1_epi64x(-1), (s)); }) #define _mm_i64gather_epi64(m, i, s) __extension__ ({ \ long long const *__m = (m); \ __m128i __i = (i); \ (__m128i)__builtin_ia32_gatherq_q((__v2di)_mm_setzero_si128(), \ (const __v2di *)__m, (__v2di)__i, \ (__v2di)_mm_set1_epi64x(-1), (s)); }) #define _mm256_i64gather_epi64(m, i, s) __extension__ ({ \ long long const *__m = (m); \ __m256i __i = (i); \ (__m256i)__builtin_ia32_gatherq_q256((__v4di)_mm256_setzero_si256(), \ (const __v4di *)__m, (__v4di)__i, \ (__v4di)_mm256_set1_epi64x(-1), (s)); }) #undef __DEFAULT_FN_ATTRS #endif /* __AVX2INTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/stdbool.h
/*===---- stdbool.h - Standard header for booleans -------------------------=== * * Copyright (c) 2008 Eli Friedman * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __STDBOOL_H #define __STDBOOL_H /* Don't define bool, true, and false in C++, except as a GNU extension. */ #ifndef __cplusplus #define bool _Bool #define true 1 #define false 0 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* Define _Bool, bool, false, true as a GNU extension. */ #define _Bool bool #define bool bool #define false false #define true true #endif #define __bool_true_false_are_defined 1 #endif /* __STDBOOL_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/xmmintrin.h
/*===---- xmmintrin.h - SSE intrinsics -------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __XMMINTRIN_H #define __XMMINTRIN_H #ifndef __SSE__ #error "SSE instruction set not enabled" #else #include <mmintrin.h> typedef int __v4si __attribute__((__vector_size__(16))); typedef float __v4sf __attribute__((__vector_size__(16))); typedef float __m128 __attribute__((__vector_size__(16))); /* This header should only be included in a hosted environment as it depends on * a standard library to provide allocation routines. */ #if __STDC_HOSTED__ #include <mm_malloc.h> #endif /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_add_ss(__m128 __a, __m128 __b) { __a[0] += __b[0]; return __a; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_add_ps(__m128 __a, __m128 __b) { return __a + __b; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_sub_ss(__m128 __a, __m128 __b) { __a[0] -= __b[0]; return __a; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_sub_ps(__m128 __a, __m128 __b) { return __a - __b; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mul_ss(__m128 __a, __m128 __b) { __a[0] *= __b[0]; return __a; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mul_ps(__m128 __a, __m128 __b) { return __a * __b; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_div_ss(__m128 __a, __m128 __b) { __a[0] /= __b[0]; return __a; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_div_ps(__m128 __a, __m128 __b) { return __a / __b; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_sqrt_ss(__m128 __a) { __m128 __c = __builtin_ia32_sqrtss(__a); return (__m128) { __c[0], __a[1], __a[2], __a[3] }; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_sqrt_ps(__m128 __a) { return __builtin_ia32_sqrtps(__a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_rcp_ss(__m128 __a) { __m128 __c = __builtin_ia32_rcpss(__a); return (__m128) { __c[0], __a[1], __a[2], __a[3] }; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_rcp_ps(__m128 __a) { return __builtin_ia32_rcpps(__a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_rsqrt_ss(__m128 __a) { __m128 __c = __builtin_ia32_rsqrtss(__a); return (__m128) { __c[0], __a[1], __a[2], __a[3] }; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_rsqrt_ps(__m128 __a) { return __builtin_ia32_rsqrtps(__a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_min_ss(__m128 __a, __m128 __b) { return __builtin_ia32_minss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_min_ps(__m128 __a, __m128 __b) { return __builtin_ia32_minps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_max_ss(__m128 __a, __m128 __b) { return __builtin_ia32_maxss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_max_ps(__m128 __a, __m128 __b) { return __builtin_ia32_maxps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_and_ps(__m128 __a, __m128 __b) { return (__m128)((__v4si)__a & (__v4si)__b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_andnot_ps(__m128 __a, __m128 __b) { return (__m128)(~(__v4si)__a & (__v4si)__b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_or_ps(__m128 __a, __m128 __b) { return (__m128)((__v4si)__a | (__v4si)__b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_xor_ps(__m128 __a, __m128 __b) { return (__m128)((__v4si)__a ^ (__v4si)__b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpeq_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpeqss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpeq_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpeqps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmplt_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpltss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmplt_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpltps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmple_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpless(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmple_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpleps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpgt_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_shufflevector(__a, __builtin_ia32_cmpltss(__b, __a), 4, 1, 2, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpgt_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpltps(__b, __a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpge_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_shufflevector(__a, __builtin_ia32_cmpless(__b, __a), 4, 1, 2, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpge_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpleps(__b, __a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpneq_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpneqss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpneq_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpneqps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpnlt_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpnltss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpnlt_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpnltps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpnle_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpnless(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpnle_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpnleps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpngt_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_shufflevector(__a, __builtin_ia32_cmpnltss(__b, __a), 4, 1, 2, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpngt_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpnltps(__b, __a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpnge_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_shufflevector(__a, __builtin_ia32_cmpnless(__b, __a), 4, 1, 2, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpnge_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpnleps(__b, __a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpord_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpordss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpord_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpordps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpunord_ss(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpunordss(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cmpunord_ps(__m128 __a, __m128 __b) { return (__m128)__builtin_ia32_cmpunordps(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comieq_ss(__m128 __a, __m128 __b) { return __builtin_ia32_comieq(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comilt_ss(__m128 __a, __m128 __b) { return __builtin_ia32_comilt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comile_ss(__m128 __a, __m128 __b) { return __builtin_ia32_comile(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comigt_ss(__m128 __a, __m128 __b) { return __builtin_ia32_comigt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comige_ss(__m128 __a, __m128 __b) { return __builtin_ia32_comige(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comineq_ss(__m128 __a, __m128 __b) { return __builtin_ia32_comineq(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomieq_ss(__m128 __a, __m128 __b) { return __builtin_ia32_ucomieq(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomilt_ss(__m128 __a, __m128 __b) { return __builtin_ia32_ucomilt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomile_ss(__m128 __a, __m128 __b) { return __builtin_ia32_ucomile(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomigt_ss(__m128 __a, __m128 __b) { return __builtin_ia32_ucomigt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomige_ss(__m128 __a, __m128 __b) { return __builtin_ia32_ucomige(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomineq_ss(__m128 __a, __m128 __b) { return __builtin_ia32_ucomineq(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_cvtss_si32(__m128 __a) { return __builtin_ia32_cvtss2si(__a); } static __inline__ int __DEFAULT_FN_ATTRS _mm_cvt_ss2si(__m128 __a) { return _mm_cvtss_si32(__a); } #ifdef __x86_64__ static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvtss_si64(__m128 __a) { return __builtin_ia32_cvtss2si64(__a); } #endif static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvtps_pi32(__m128 __a) { return (__m64)__builtin_ia32_cvtps2pi(__a); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvt_ps2pi(__m128 __a) { return _mm_cvtps_pi32(__a); } static __inline__ int __DEFAULT_FN_ATTRS _mm_cvttss_si32(__m128 __a) { return __a[0]; } static __inline__ int __DEFAULT_FN_ATTRS _mm_cvtt_ss2si(__m128 __a) { return _mm_cvttss_si32(__a); } static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvttss_si64(__m128 __a) { return __a[0]; } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvttps_pi32(__m128 __a) { return (__m64)__builtin_ia32_cvttps2pi(__a); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvtt_ps2pi(__m128 __a) { return _mm_cvttps_pi32(__a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtsi32_ss(__m128 __a, int __b) { __a[0] = __b; return __a; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvt_si2ss(__m128 __a, int __b) { return _mm_cvtsi32_ss(__a, __b); } #ifdef __x86_64__ static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtsi64_ss(__m128 __a, long long __b) { __a[0] = __b; return __a; } #endif static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtpi32_ps(__m128 __a, __m64 __b) { return __builtin_ia32_cvtpi2ps(__a, (__v2si)__b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvt_pi2ps(__m128 __a, __m64 __b) { return _mm_cvtpi32_ps(__a, __b); } static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtss_f32(__m128 __a) { return __a[0]; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_loadh_pi(__m128 __a, const __m64 *__p) { typedef float __mm_loadh_pi_v2f32 __attribute__((__vector_size__(8))); struct __mm_loadh_pi_struct { __mm_loadh_pi_v2f32 __u; } __attribute__((__packed__, __may_alias__)); __mm_loadh_pi_v2f32 __b = ((struct __mm_loadh_pi_struct*)__p)->__u; __m128 __bb = __builtin_shufflevector(__b, __b, 0, 1, 0, 1); return __builtin_shufflevector(__a, __bb, 0, 1, 4, 5); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_loadl_pi(__m128 __a, const __m64 *__p) { typedef float __mm_loadl_pi_v2f32 __attribute__((__vector_size__(8))); struct __mm_loadl_pi_struct { __mm_loadl_pi_v2f32 __u; } __attribute__((__packed__, __may_alias__)); __mm_loadl_pi_v2f32 __b = ((struct __mm_loadl_pi_struct*)__p)->__u; __m128 __bb = __builtin_shufflevector(__b, __b, 0, 1, 0, 1); return __builtin_shufflevector(__a, __bb, 4, 5, 2, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_load_ss(const float *__p) { struct __mm_load_ss_struct { float __u; } __attribute__((__packed__, __may_alias__)); float __u = ((struct __mm_load_ss_struct*)__p)->__u; return (__m128){ __u, 0, 0, 0 }; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_load1_ps(const float *__p) { struct __mm_load1_ps_struct { float __u; } __attribute__((__packed__, __may_alias__)); float __u = ((struct __mm_load1_ps_struct*)__p)->__u; return (__m128){ __u, __u, __u, __u }; } #define _mm_load_ps1(p) _mm_load1_ps(p) static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_load_ps(const float *__p) { return *(__m128*)__p; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_loadu_ps(const float *__p) { struct __loadu_ps { __m128 __v; } __attribute__((__packed__, __may_alias__)); return ((struct __loadu_ps*)__p)->__v; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_loadr_ps(const float *__p) { __m128 __a = _mm_load_ps(__p); return __builtin_shufflevector(__a, __a, 3, 2, 1, 0); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_set_ss(float __w) { return (__m128){ __w, 0, 0, 0 }; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_set1_ps(float __w) { return (__m128){ __w, __w, __w, __w }; } /* Microsoft specific. */ static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_set_ps1(float __w) { return _mm_set1_ps(__w); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_set_ps(float __z, float __y, float __x, float __w) { return (__m128){ __w, __x, __y, __z }; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_setr_ps(float __z, float __y, float __x, float __w) { return (__m128){ __z, __y, __x, __w }; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_setzero_ps(void) { return (__m128){ 0, 0, 0, 0 }; } static __inline__ void __DEFAULT_FN_ATTRS _mm_storeh_pi(__m64 *__p, __m128 __a) { __builtin_ia32_storehps((__v2si *)__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_storel_pi(__m64 *__p, __m128 __a) { __builtin_ia32_storelps((__v2si *)__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_store_ss(float *__p, __m128 __a) { struct __mm_store_ss_struct { float __u; } __attribute__((__packed__, __may_alias__)); ((struct __mm_store_ss_struct*)__p)->__u = __a[0]; } static __inline__ void __DEFAULT_FN_ATTRS _mm_storeu_ps(float *__p, __m128 __a) { __builtin_ia32_storeups(__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_store1_ps(float *__p, __m128 __a) { __a = __builtin_shufflevector(__a, __a, 0, 0, 0, 0); _mm_storeu_ps(__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_store_ps1(float *__p, __m128 __a) { return _mm_store1_ps(__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_store_ps(float *__p, __m128 __a) { *(__m128 *)__p = __a; } static __inline__ void __DEFAULT_FN_ATTRS _mm_storer_ps(float *__p, __m128 __a) { __a = __builtin_shufflevector(__a, __a, 3, 2, 1, 0); _mm_store_ps(__p, __a); } #define _MM_HINT_T0 3 #define _MM_HINT_T1 2 #define _MM_HINT_T2 1 #define _MM_HINT_NTA 0 #ifndef _MSC_VER /* FIXME: We have to #define this because "sel" must be a constant integer, and Sema doesn't do any form of constant propagation yet. */ #define _mm_prefetch(a, sel) (__builtin_prefetch((void *)(a), 0, (sel))) #endif static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_pi(__m64 *__p, __m64 __a) { __builtin_ia32_movntq(__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_ps(float *__p, __m128 __a) { __builtin_ia32_movntps(__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_sfence(void) { __builtin_ia32_sfence(); } static __inline__ int __DEFAULT_FN_ATTRS _mm_extract_pi16(__m64 __a, int __n) { __v4hi __b = (__v4hi)__a; return (unsigned short)__b[__n & 3]; } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_insert_pi16(__m64 __a, int __d, int __n) { __v4hi __b = (__v4hi)__a; __b[__n & 3] = __d; return (__m64)__b; } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_max_pi16(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_pmaxsw((__v4hi)__a, (__v4hi)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_max_pu8(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_pmaxub((__v8qi)__a, (__v8qi)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_min_pi16(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_pminsw((__v4hi)__a, (__v4hi)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_min_pu8(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_pminub((__v8qi)__a, (__v8qi)__b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_movemask_pi8(__m64 __a) { return __builtin_ia32_pmovmskb((__v8qi)__a); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_mulhi_pu16(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_pmulhuw((__v4hi)__a, (__v4hi)__b); } #define _mm_shuffle_pi16(a, n) __extension__ ({ \ __m64 __a = (a); \ (__m64)__builtin_ia32_pshufw((__v4hi)__a, (n)); }) static __inline__ void __DEFAULT_FN_ATTRS _mm_maskmove_si64(__m64 __d, __m64 __n, char *__p) { __builtin_ia32_maskmovq((__v8qi)__d, (__v8qi)__n, __p); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_avg_pu8(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_pavgb((__v8qi)__a, (__v8qi)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_avg_pu16(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_pavgw((__v4hi)__a, (__v4hi)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sad_pu8(__m64 __a, __m64 __b) { return (__m64)__builtin_ia32_psadbw((__v8qi)__a, (__v8qi)__b); } static __inline__ unsigned int __DEFAULT_FN_ATTRS _mm_getcsr(void) { return __builtin_ia32_stmxcsr(); } static __inline__ void __DEFAULT_FN_ATTRS _mm_setcsr(unsigned int __i) { __builtin_ia32_ldmxcsr(__i); } #define _mm_shuffle_ps(a, b, mask) __extension__ ({ \ __m128 __a = (a); \ __m128 __b = (b); \ (__m128)__builtin_shufflevector((__v4sf)__a, (__v4sf)__b, \ (mask) & 0x3, ((mask) & 0xc) >> 2, \ (((mask) & 0x30) >> 4) + 4, \ (((mask) & 0xc0) >> 6) + 4); }) static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_unpackhi_ps(__m128 __a, __m128 __b) { return __builtin_shufflevector(__a, __b, 2, 6, 3, 7); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_unpacklo_ps(__m128 __a, __m128 __b) { return __builtin_shufflevector(__a, __b, 0, 4, 1, 5); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_move_ss(__m128 __a, __m128 __b) { return __builtin_shufflevector(__a, __b, 4, 1, 2, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_movehl_ps(__m128 __a, __m128 __b) { return __builtin_shufflevector(__a, __b, 6, 7, 2, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_movelh_ps(__m128 __a, __m128 __b) { return __builtin_shufflevector(__a, __b, 0, 1, 4, 5); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtpi16_ps(__m64 __a) { __m64 __b, __c; __m128 __r; __b = _mm_setzero_si64(); __b = _mm_cmpgt_pi16(__b, __a); __c = _mm_unpackhi_pi16(__a, __b); __r = _mm_setzero_ps(); __r = _mm_cvtpi32_ps(__r, __c); __r = _mm_movelh_ps(__r, __r); __c = _mm_unpacklo_pi16(__a, __b); __r = _mm_cvtpi32_ps(__r, __c); return __r; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtpu16_ps(__m64 __a) { __m64 __b, __c; __m128 __r; __b = _mm_setzero_si64(); __c = _mm_unpackhi_pi16(__a, __b); __r = _mm_setzero_ps(); __r = _mm_cvtpi32_ps(__r, __c); __r = _mm_movelh_ps(__r, __r); __c = _mm_unpacklo_pi16(__a, __b); __r = _mm_cvtpi32_ps(__r, __c); return __r; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtpi8_ps(__m64 __a) { __m64 __b; __b = _mm_setzero_si64(); __b = _mm_cmpgt_pi8(__b, __a); __b = _mm_unpacklo_pi8(__a, __b); return _mm_cvtpi16_ps(__b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtpu8_ps(__m64 __a) { __m64 __b; __b = _mm_setzero_si64(); __b = _mm_unpacklo_pi8(__a, __b); return _mm_cvtpi16_ps(__b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtpi32x2_ps(__m64 __a, __m64 __b) { __m128 __c; __c = _mm_setzero_ps(); __c = _mm_cvtpi32_ps(__c, __b); __c = _mm_movelh_ps(__c, __c); return _mm_cvtpi32_ps(__c, __a); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvtps_pi16(__m128 __a) { __m64 __b, __c; __b = _mm_cvtps_pi32(__a); __a = _mm_movehl_ps(__a, __a); __c = _mm_cvtps_pi32(__a); return _mm_packs_pi32(__b, __c); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvtps_pi8(__m128 __a) { __m64 __b, __c; __b = _mm_cvtps_pi16(__a); __c = _mm_setzero_si64(); return _mm_packs_pi16(__b, __c); } static __inline__ int __DEFAULT_FN_ATTRS _mm_movemask_ps(__m128 __a) { return __builtin_ia32_movmskps(__a); } #define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w)) #define _MM_EXCEPT_INVALID (0x0001) #define _MM_EXCEPT_DENORM (0x0002) #define _MM_EXCEPT_DIV_ZERO (0x0004) #define _MM_EXCEPT_OVERFLOW (0x0008) #define _MM_EXCEPT_UNDERFLOW (0x0010) #define _MM_EXCEPT_INEXACT (0x0020) #define _MM_EXCEPT_MASK (0x003f) #define _MM_MASK_INVALID (0x0080) #define _MM_MASK_DENORM (0x0100) #define _MM_MASK_DIV_ZERO (0x0200) #define _MM_MASK_OVERFLOW (0x0400) #define _MM_MASK_UNDERFLOW (0x0800) #define _MM_MASK_INEXACT (0x1000) #define _MM_MASK_MASK (0x1f80) #define _MM_ROUND_NEAREST (0x0000) #define _MM_ROUND_DOWN (0x2000) #define _MM_ROUND_UP (0x4000) #define _MM_ROUND_TOWARD_ZERO (0x6000) #define _MM_ROUND_MASK (0x6000) #define _MM_FLUSH_ZERO_MASK (0x8000) #define _MM_FLUSH_ZERO_ON (0x8000) #define _MM_FLUSH_ZERO_OFF (0x0000) #define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK) #define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK) #define _MM_GET_FLUSH_ZERO_MODE() (_mm_getcsr() & _MM_FLUSH_ZERO_MASK) #define _MM_GET_ROUNDING_MODE() (_mm_getcsr() & _MM_ROUND_MASK) #define _MM_SET_EXCEPTION_MASK(x) (_mm_setcsr((_mm_getcsr() & ~_MM_MASK_MASK) | (x))) #define _MM_SET_EXCEPTION_STATE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_EXCEPT_MASK) | (x))) #define _MM_SET_FLUSH_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_FLUSH_ZERO_MASK) | (x))) #define _MM_SET_ROUNDING_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_ROUND_MASK) | (x))) #define _MM_TRANSPOSE4_PS(row0, row1, row2, row3) \ do { \ __m128 tmp3, tmp2, tmp1, tmp0; \ tmp0 = _mm_unpacklo_ps((row0), (row1)); \ tmp2 = _mm_unpacklo_ps((row2), (row3)); \ tmp1 = _mm_unpackhi_ps((row0), (row1)); \ tmp3 = _mm_unpackhi_ps((row2), (row3)); \ (row0) = _mm_movelh_ps(tmp0, tmp2); \ (row1) = _mm_movehl_ps(tmp2, tmp0); \ (row2) = _mm_movelh_ps(tmp1, tmp3); \ (row3) = _mm_movehl_ps(tmp3, tmp1); \ } while (0) /* Aliases for compatibility. */ #define _m_pextrw _mm_extract_pi16 #define _m_pinsrw _mm_insert_pi16 #define _m_pmaxsw _mm_max_pi16 #define _m_pmaxub _mm_max_pu8 #define _m_pminsw _mm_min_pi16 #define _m_pminub _mm_min_pu8 #define _m_pmovmskb _mm_movemask_pi8 #define _m_pmulhuw _mm_mulhi_pu16 #define _m_pshufw _mm_shuffle_pi16 #define _m_maskmovq _mm_maskmove_si64 #define _m_pavgb _mm_avg_pu8 #define _m_pavgw _mm_avg_pu16 #define _m_psadbw _mm_sad_pu8 #define _m_ _mm_ #define _m_ _mm_ #undef __DEFAULT_FN_ATTRS /* Ugly hack for backwards-compatibility (compatible with gcc) */ #if defined(__SSE2__) && !__has_feature(modules) #include <emmintrin.h> #endif #endif /* __SSE__ */ #endif /* __XMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/varargs.h
/*===---- varargs.h - Variable argument handling -------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __VARARGS_H #define __VARARGS_H #error "Please use <stdarg.h> instead of <varargs.h>" #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/vecintrin.h
/*===---- vecintrin.h - Vector intrinsics ----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if defined(__s390x__) && defined(__VEC__) #define __ATTRS_ai __attribute__((__always_inline__)) #define __ATTRS_o __attribute__((__overloadable__)) #define __ATTRS_o_ai __attribute__((__overloadable__, __always_inline__)) #define __constant(PARM) \ __attribute__((__enable_if__ ((PARM) == (PARM), \ "argument must be a constant integer"))) #define __constant_range(PARM, LOW, HIGH) \ __attribute__((__enable_if__ ((PARM) >= (LOW) && (PARM) <= (HIGH), \ "argument must be a constant integer from " #LOW " to " #HIGH))) #define __constant_pow2_range(PARM, LOW, HIGH) \ __attribute__((__enable_if__ ((PARM) >= (LOW) && (PARM) <= (HIGH) && \ ((PARM) & ((PARM) - 1)) == 0, \ "argument must be a constant power of 2 from " #LOW " to " #HIGH))) /*-- __lcbb -----------------------------------------------------------------*/ extern __ATTRS_o unsigned int __lcbb(const void *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); #define __lcbb(X, Y) ((__typeof__((__lcbb)((X), (Y)))) \ __builtin_s390_lcbb((X), __builtin_constant_p((Y))? \ ((Y) == 64 ? 0 : \ (Y) == 128 ? 1 : \ (Y) == 256 ? 2 : \ (Y) == 512 ? 3 : \ (Y) == 1024 ? 4 : \ (Y) == 2048 ? 5 : \ (Y) == 4096 ? 6 : 0) : 0)) /*-- vec_extract ------------------------------------------------------------*/ static inline __ATTRS_o_ai signed char vec_extract(vector signed char __vec, int __index) { return __vec[__index & 15]; } static inline __ATTRS_o_ai unsigned char vec_extract(vector bool char __vec, int __index) { return __vec[__index & 15]; } static inline __ATTRS_o_ai unsigned char vec_extract(vector unsigned char __vec, int __index) { return __vec[__index & 15]; } static inline __ATTRS_o_ai signed short vec_extract(vector signed short __vec, int __index) { return __vec[__index & 7]; } static inline __ATTRS_o_ai unsigned short vec_extract(vector bool short __vec, int __index) { return __vec[__index & 7]; } static inline __ATTRS_o_ai unsigned short vec_extract(vector unsigned short __vec, int __index) { return __vec[__index & 7]; } static inline __ATTRS_o_ai signed int vec_extract(vector signed int __vec, int __index) { return __vec[__index & 3]; } static inline __ATTRS_o_ai unsigned int vec_extract(vector bool int __vec, int __index) { return __vec[__index & 3]; } static inline __ATTRS_o_ai unsigned int vec_extract(vector unsigned int __vec, int __index) { return __vec[__index & 3]; } static inline __ATTRS_o_ai signed long long vec_extract(vector signed long long __vec, int __index) { return __vec[__index & 1]; } static inline __ATTRS_o_ai unsigned long long vec_extract(vector bool long long __vec, int __index) { return __vec[__index & 1]; } static inline __ATTRS_o_ai unsigned long long vec_extract(vector unsigned long long __vec, int __index) { return __vec[__index & 1]; } static inline __ATTRS_o_ai double vec_extract(vector double __vec, int __index) { return __vec[__index & 1]; } /*-- vec_insert -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_insert(signed char __scalar, vector signed char __vec, int __index) { __vec[__index & 15] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned char vec_insert(unsigned char __scalar, vector bool char __vec, int __index) { vector unsigned char __newvec = (vector unsigned char)__vec; __newvec[__index & 15] = (unsigned char)__scalar; return __newvec; } static inline __ATTRS_o_ai vector unsigned char vec_insert(unsigned char __scalar, vector unsigned char __vec, int __index) { __vec[__index & 15] = __scalar; return __vec; } static inline __ATTRS_o_ai vector signed short vec_insert(signed short __scalar, vector signed short __vec, int __index) { __vec[__index & 7] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned short vec_insert(unsigned short __scalar, vector bool short __vec, int __index) { vector unsigned short __newvec = (vector unsigned short)__vec; __newvec[__index & 7] = (unsigned short)__scalar; return __newvec; } static inline __ATTRS_o_ai vector unsigned short vec_insert(unsigned short __scalar, vector unsigned short __vec, int __index) { __vec[__index & 7] = __scalar; return __vec; } static inline __ATTRS_o_ai vector signed int vec_insert(signed int __scalar, vector signed int __vec, int __index) { __vec[__index & 3] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned int vec_insert(unsigned int __scalar, vector bool int __vec, int __index) { vector unsigned int __newvec = (vector unsigned int)__vec; __newvec[__index & 3] = __scalar; return __newvec; } static inline __ATTRS_o_ai vector unsigned int vec_insert(unsigned int __scalar, vector unsigned int __vec, int __index) { __vec[__index & 3] = __scalar; return __vec; } static inline __ATTRS_o_ai vector signed long long vec_insert(signed long long __scalar, vector signed long long __vec, int __index) { __vec[__index & 1] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned long long vec_insert(unsigned long long __scalar, vector bool long long __vec, int __index) { vector unsigned long long __newvec = (vector unsigned long long)__vec; __newvec[__index & 1] = __scalar; return __newvec; } static inline __ATTRS_o_ai vector unsigned long long vec_insert(unsigned long long __scalar, vector unsigned long long __vec, int __index) { __vec[__index & 1] = __scalar; return __vec; } static inline __ATTRS_o_ai vector double vec_insert(double __scalar, vector double __vec, int __index) { __vec[__index & 1] = __scalar; return __vec; } /*-- vec_promote ------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_promote(signed char __scalar, int __index) { const vector signed char __zero = (vector signed char)0; vector signed char __vec = __builtin_shufflevector(__zero, __zero, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1); __vec[__index & 15] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned char vec_promote(unsigned char __scalar, int __index) { const vector unsigned char __zero = (vector unsigned char)0; vector unsigned char __vec = __builtin_shufflevector(__zero, __zero, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1); __vec[__index & 15] = __scalar; return __vec; } static inline __ATTRS_o_ai vector signed short vec_promote(signed short __scalar, int __index) { const vector signed short __zero = (vector signed short)0; vector signed short __vec = __builtin_shufflevector(__zero, __zero, -1, -1, -1, -1, -1, -1, -1, -1); __vec[__index & 7] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned short vec_promote(unsigned short __scalar, int __index) { const vector unsigned short __zero = (vector unsigned short)0; vector unsigned short __vec = __builtin_shufflevector(__zero, __zero, -1, -1, -1, -1, -1, -1, -1, -1); __vec[__index & 7] = __scalar; return __vec; } static inline __ATTRS_o_ai vector signed int vec_promote(signed int __scalar, int __index) { const vector signed int __zero = (vector signed int)0; vector signed int __vec = __builtin_shufflevector(__zero, __zero, -1, -1, -1, -1); __vec[__index & 3] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned int vec_promote(unsigned int __scalar, int __index) { const vector unsigned int __zero = (vector unsigned int)0; vector unsigned int __vec = __builtin_shufflevector(__zero, __zero, -1, -1, -1, -1); __vec[__index & 3] = __scalar; return __vec; } static inline __ATTRS_o_ai vector signed long long vec_promote(signed long long __scalar, int __index) { const vector signed long long __zero = (vector signed long long)0; vector signed long long __vec = __builtin_shufflevector(__zero, __zero, -1, -1); __vec[__index & 1] = __scalar; return __vec; } static inline __ATTRS_o_ai vector unsigned long long vec_promote(unsigned long long __scalar, int __index) { const vector unsigned long long __zero = (vector unsigned long long)0; vector unsigned long long __vec = __builtin_shufflevector(__zero, __zero, -1, -1); __vec[__index & 1] = __scalar; return __vec; } static inline __ATTRS_o_ai vector double vec_promote(double __scalar, int __index) { const vector double __zero = (vector double)0; vector double __vec = __builtin_shufflevector(__zero, __zero, -1, -1); __vec[__index & 1] = __scalar; return __vec; } /*-- vec_insert_and_zero ----------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_insert_and_zero(const signed char *__ptr) { vector signed char __vec = (vector signed char)0; __vec[7] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector unsigned char vec_insert_and_zero(const unsigned char *__ptr) { vector unsigned char __vec = (vector unsigned char)0; __vec[7] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector signed short vec_insert_and_zero(const signed short *__ptr) { vector signed short __vec = (vector signed short)0; __vec[3] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector unsigned short vec_insert_and_zero(const unsigned short *__ptr) { vector unsigned short __vec = (vector unsigned short)0; __vec[3] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector signed int vec_insert_and_zero(const signed int *__ptr) { vector signed int __vec = (vector signed int)0; __vec[1] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector unsigned int vec_insert_and_zero(const unsigned int *__ptr) { vector unsigned int __vec = (vector unsigned int)0; __vec[1] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector signed long long vec_insert_and_zero(const signed long long *__ptr) { vector signed long long __vec = (vector signed long long)0; __vec[0] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector unsigned long long vec_insert_and_zero(const unsigned long long *__ptr) { vector unsigned long long __vec = (vector unsigned long long)0; __vec[0] = *__ptr; return __vec; } static inline __ATTRS_o_ai vector double vec_insert_and_zero(const double *__ptr) { vector double __vec = (vector double)0; __vec[0] = *__ptr; return __vec; } /*-- vec_perm ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_perm(vector signed char __a, vector signed char __b, vector unsigned char __c) { return (vector signed char)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector unsigned char vec_perm(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return (vector unsigned char)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector bool char vec_perm(vector bool char __a, vector bool char __b, vector unsigned char __c) { return (vector bool char)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector signed short vec_perm(vector signed short __a, vector signed short __b, vector unsigned char __c) { return (vector signed short)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector unsigned short vec_perm(vector unsigned short __a, vector unsigned short __b, vector unsigned char __c) { return (vector unsigned short)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector bool short vec_perm(vector bool short __a, vector bool short __b, vector unsigned char __c) { return (vector bool short)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector signed int vec_perm(vector signed int __a, vector signed int __b, vector unsigned char __c) { return (vector signed int)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector unsigned int vec_perm(vector unsigned int __a, vector unsigned int __b, vector unsigned char __c) { return (vector unsigned int)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector bool int vec_perm(vector bool int __a, vector bool int __b, vector unsigned char __c) { return (vector bool int)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector signed long long vec_perm(vector signed long long __a, vector signed long long __b, vector unsigned char __c) { return (vector signed long long)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector unsigned long long vec_perm(vector unsigned long long __a, vector unsigned long long __b, vector unsigned char __c) { return (vector unsigned long long)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector bool long long vec_perm(vector bool long long __a, vector bool long long __b, vector unsigned char __c) { return (vector bool long long)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } static inline __ATTRS_o_ai vector double vec_perm(vector double __a, vector double __b, vector unsigned char __c) { return (vector double)__builtin_s390_vperm( (vector unsigned char)__a, (vector unsigned char)__b, __c); } /*-- vec_permi --------------------------------------------------------------*/ extern __ATTRS_o vector signed long long vec_permi(vector signed long long __a, vector signed long long __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector unsigned long long vec_permi(vector unsigned long long __a, vector unsigned long long __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector bool long long vec_permi(vector bool long long __a, vector bool long long __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector double vec_permi(vector double __a, vector double __b, int __c) __constant_range(__c, 0, 3); #define vec_permi(X, Y, Z) ((__typeof__((vec_permi)((X), (Y), (Z)))) \ __builtin_s390_vpdi((vector unsigned long long)(X), \ (vector unsigned long long)(Y), \ (((Z) & 2) << 1) | ((Z) & 1))) /*-- vec_sel ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_sel(vector signed char __a, vector signed char __b, vector unsigned char __c) { return ((vector signed char)__c & __b) | (~(vector signed char)__c & __a); } static inline __ATTRS_o_ai vector signed char vec_sel(vector signed char __a, vector signed char __b, vector bool char __c) { return ((vector signed char)__c & __b) | (~(vector signed char)__c & __a); } static inline __ATTRS_o_ai vector bool char vec_sel(vector bool char __a, vector bool char __b, vector unsigned char __c) { return ((vector bool char)__c & __b) | (~(vector bool char)__c & __a); } static inline __ATTRS_o_ai vector bool char vec_sel(vector bool char __a, vector bool char __b, vector bool char __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned char vec_sel(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned char vec_sel(vector unsigned char __a, vector unsigned char __b, vector bool char __c) { return ((vector unsigned char)__c & __b) | (~(vector unsigned char)__c & __a); } static inline __ATTRS_o_ai vector signed short vec_sel(vector signed short __a, vector signed short __b, vector unsigned short __c) { return ((vector signed short)__c & __b) | (~(vector signed short)__c & __a); } static inline __ATTRS_o_ai vector signed short vec_sel(vector signed short __a, vector signed short __b, vector bool short __c) { return ((vector signed short)__c & __b) | (~(vector signed short)__c & __a); } static inline __ATTRS_o_ai vector bool short vec_sel(vector bool short __a, vector bool short __b, vector unsigned short __c) { return ((vector bool short)__c & __b) | (~(vector bool short)__c & __a); } static inline __ATTRS_o_ai vector bool short vec_sel(vector bool short __a, vector bool short __b, vector bool short __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned short vec_sel(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned short vec_sel(vector unsigned short __a, vector unsigned short __b, vector bool short __c) { return (((vector unsigned short)__c & __b) | (~(vector unsigned short)__c & __a)); } static inline __ATTRS_o_ai vector signed int vec_sel(vector signed int __a, vector signed int __b, vector unsigned int __c) { return ((vector signed int)__c & __b) | (~(vector signed int)__c & __a); } static inline __ATTRS_o_ai vector signed int vec_sel(vector signed int __a, vector signed int __b, vector bool int __c) { return ((vector signed int)__c & __b) | (~(vector signed int)__c & __a); } static inline __ATTRS_o_ai vector bool int vec_sel(vector bool int __a, vector bool int __b, vector unsigned int __c) { return ((vector bool int)__c & __b) | (~(vector bool int)__c & __a); } static inline __ATTRS_o_ai vector bool int vec_sel(vector bool int __a, vector bool int __b, vector bool int __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned int vec_sel(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned int vec_sel(vector unsigned int __a, vector unsigned int __b, vector bool int __c) { return ((vector unsigned int)__c & __b) | (~(vector unsigned int)__c & __a); } static inline __ATTRS_o_ai vector signed long long vec_sel(vector signed long long __a, vector signed long long __b, vector unsigned long long __c) { return (((vector signed long long)__c & __b) | (~(vector signed long long)__c & __a)); } static inline __ATTRS_o_ai vector signed long long vec_sel(vector signed long long __a, vector signed long long __b, vector bool long long __c) { return (((vector signed long long)__c & __b) | (~(vector signed long long)__c & __a)); } static inline __ATTRS_o_ai vector bool long long vec_sel(vector bool long long __a, vector bool long long __b, vector unsigned long long __c) { return (((vector bool long long)__c & __b) | (~(vector bool long long)__c & __a)); } static inline __ATTRS_o_ai vector bool long long vec_sel(vector bool long long __a, vector bool long long __b, vector bool long long __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned long long vec_sel(vector unsigned long long __a, vector unsigned long long __b, vector unsigned long long __c) { return (__c & __b) | (~__c & __a); } static inline __ATTRS_o_ai vector unsigned long long vec_sel(vector unsigned long long __a, vector unsigned long long __b, vector bool long long __c) { return (((vector unsigned long long)__c & __b) | (~(vector unsigned long long)__c & __a)); } static inline __ATTRS_o_ai vector double vec_sel(vector double __a, vector double __b, vector unsigned long long __c) { return (vector double)((__c & (vector unsigned long long)__b) | (~__c & (vector unsigned long long)__a)); } static inline __ATTRS_o_ai vector double vec_sel(vector double __a, vector double __b, vector bool long long __c) { vector unsigned long long __ac = (vector unsigned long long)__a; vector unsigned long long __bc = (vector unsigned long long)__b; vector unsigned long long __cc = (vector unsigned long long)__c; return (vector double)((__cc & __bc) | (~__cc & __ac)); } /*-- vec_gather_element -----------------------------------------------------*/ static inline __ATTRS_o_ai vector signed int vec_gather_element(vector signed int __vec, vector unsigned int __offset, const signed int *__ptr, int __index) __constant_range(__index, 0, 3) { __vec[__index] = *(const signed int *)( (__INTPTR_TYPE__)__ptr + (__INTPTR_TYPE__)__offset[__index]); return __vec; } static inline __ATTRS_o_ai vector bool int vec_gather_element(vector bool int __vec, vector unsigned int __offset, const unsigned int *__ptr, int __index) __constant_range(__index, 0, 3) { __vec[__index] = *(const unsigned int *)( (__INTPTR_TYPE__)__ptr + (__INTPTR_TYPE__)__offset[__index]); return __vec; } static inline __ATTRS_o_ai vector unsigned int vec_gather_element(vector unsigned int __vec, vector unsigned int __offset, const unsigned int *__ptr, int __index) __constant_range(__index, 0, 3) { __vec[__index] = *(const unsigned int *)( (__INTPTR_TYPE__)__ptr + (__INTPTR_TYPE__)__offset[__index]); return __vec; } static inline __ATTRS_o_ai vector signed long long vec_gather_element(vector signed long long __vec, vector unsigned long long __offset, const signed long long *__ptr, int __index) __constant_range(__index, 0, 1) { __vec[__index] = *(const signed long long *)( (__INTPTR_TYPE__)__ptr + (__INTPTR_TYPE__)__offset[__index]); return __vec; } static inline __ATTRS_o_ai vector bool long long vec_gather_element(vector bool long long __vec, vector unsigned long long __offset, const unsigned long long *__ptr, int __index) __constant_range(__index, 0, 1) { __vec[__index] = *(const unsigned long long *)( (__INTPTR_TYPE__)__ptr + (__INTPTR_TYPE__)__offset[__index]); return __vec; } static inline __ATTRS_o_ai vector unsigned long long vec_gather_element(vector unsigned long long __vec, vector unsigned long long __offset, const unsigned long long *__ptr, int __index) __constant_range(__index, 0, 1) { __vec[__index] = *(const unsigned long long *)( (__INTPTR_TYPE__)__ptr + (__INTPTR_TYPE__)__offset[__index]); return __vec; } static inline __ATTRS_o_ai vector double vec_gather_element(vector double __vec, vector unsigned long long __offset, const double *__ptr, int __index) __constant_range(__index, 0, 1) { __vec[__index] = *(const double *)( (__INTPTR_TYPE__)__ptr + (__INTPTR_TYPE__)__offset[__index]); return __vec; } /*-- vec_scatter_element ----------------------------------------------------*/ static inline __ATTRS_o_ai void vec_scatter_element(vector signed int __vec, vector unsigned int __offset, signed int *__ptr, int __index) __constant_range(__index, 0, 3) { *(signed int *)((__INTPTR_TYPE__)__ptr + __offset[__index]) = __vec[__index]; } static inline __ATTRS_o_ai void vec_scatter_element(vector bool int __vec, vector unsigned int __offset, unsigned int *__ptr, int __index) __constant_range(__index, 0, 3) { *(unsigned int *)((__INTPTR_TYPE__)__ptr + __offset[__index]) = __vec[__index]; } static inline __ATTRS_o_ai void vec_scatter_element(vector unsigned int __vec, vector unsigned int __offset, unsigned int *__ptr, int __index) __constant_range(__index, 0, 3) { *(unsigned int *)((__INTPTR_TYPE__)__ptr + __offset[__index]) = __vec[__index]; } static inline __ATTRS_o_ai void vec_scatter_element(vector signed long long __vec, vector unsigned long long __offset, signed long long *__ptr, int __index) __constant_range(__index, 0, 1) { *(signed long long *)((__INTPTR_TYPE__)__ptr + __offset[__index]) = __vec[__index]; } static inline __ATTRS_o_ai void vec_scatter_element(vector bool long long __vec, vector unsigned long long __offset, unsigned long long *__ptr, int __index) __constant_range(__index, 0, 1) { *(unsigned long long *)((__INTPTR_TYPE__)__ptr + __offset[__index]) = __vec[__index]; } static inline __ATTRS_o_ai void vec_scatter_element(vector unsigned long long __vec, vector unsigned long long __offset, unsigned long long *__ptr, int __index) __constant_range(__index, 0, 1) { *(unsigned long long *)((__INTPTR_TYPE__)__ptr + __offset[__index]) = __vec[__index]; } static inline __ATTRS_o_ai void vec_scatter_element(vector double __vec, vector unsigned long long __offset, double *__ptr, int __index) __constant_range(__index, 0, 1) { *(double *)((__INTPTR_TYPE__)__ptr + __offset[__index]) = __vec[__index]; } /*-- vec_xld2 ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_xld2(long __offset, const signed char *__ptr) { return *(const vector signed char *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector unsigned char vec_xld2(long __offset, const unsigned char *__ptr) { return *(const vector unsigned char *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector signed short vec_xld2(long __offset, const signed short *__ptr) { return *(const vector signed short *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector unsigned short vec_xld2(long __offset, const unsigned short *__ptr) { return *(const vector unsigned short *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector signed int vec_xld2(long __offset, const signed int *__ptr) { return *(const vector signed int *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector unsigned int vec_xld2(long __offset, const unsigned int *__ptr) { return *(const vector unsigned int *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector signed long long vec_xld2(long __offset, const signed long long *__ptr) { return *(const vector signed long long *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector unsigned long long vec_xld2(long __offset, const unsigned long long *__ptr) { return *(const vector unsigned long long *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector double vec_xld2(long __offset, const double *__ptr) { return *(const vector double *)((__INTPTR_TYPE__)__ptr + __offset); } /*-- vec_xlw4 ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_xlw4(long __offset, const signed char *__ptr) { return *(const vector signed char *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector unsigned char vec_xlw4(long __offset, const unsigned char *__ptr) { return *(const vector unsigned char *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector signed short vec_xlw4(long __offset, const signed short *__ptr) { return *(const vector signed short *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector unsigned short vec_xlw4(long __offset, const unsigned short *__ptr) { return *(const vector unsigned short *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector signed int vec_xlw4(long __offset, const signed int *__ptr) { return *(const vector signed int *)((__INTPTR_TYPE__)__ptr + __offset); } static inline __ATTRS_o_ai vector unsigned int vec_xlw4(long __offset, const unsigned int *__ptr) { return *(const vector unsigned int *)((__INTPTR_TYPE__)__ptr + __offset); } /*-- vec_xstd2 --------------------------------------------------------------*/ static inline __ATTRS_o_ai void vec_xstd2(vector signed char __vec, long __offset, signed char *__ptr) { *(vector signed char *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector unsigned char __vec, long __offset, unsigned char *__ptr) { *(vector unsigned char *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector signed short __vec, long __offset, signed short *__ptr) { *(vector signed short *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector unsigned short __vec, long __offset, unsigned short *__ptr) { *(vector unsigned short *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector signed int __vec, long __offset, signed int *__ptr) { *(vector signed int *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector unsigned int __vec, long __offset, unsigned int *__ptr) { *(vector unsigned int *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector signed long long __vec, long __offset, signed long long *__ptr) { *(vector signed long long *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector unsigned long long __vec, long __offset, unsigned long long *__ptr) { *(vector unsigned long long *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstd2(vector double __vec, long __offset, double *__ptr) { *(vector double *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } /*-- vec_xstw4 --------------------------------------------------------------*/ static inline __ATTRS_o_ai void vec_xstw4(vector signed char __vec, long __offset, signed char *__ptr) { *(vector signed char *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstw4(vector unsigned char __vec, long __offset, unsigned char *__ptr) { *(vector unsigned char *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstw4(vector signed short __vec, long __offset, signed short *__ptr) { *(vector signed short *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstw4(vector unsigned short __vec, long __offset, unsigned short *__ptr) { *(vector unsigned short *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstw4(vector signed int __vec, long __offset, signed int *__ptr) { *(vector signed int *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } static inline __ATTRS_o_ai void vec_xstw4(vector unsigned int __vec, long __offset, unsigned int *__ptr) { *(vector unsigned int *)((__INTPTR_TYPE__)__ptr + __offset) = __vec; } /*-- vec_load_bndry ---------------------------------------------------------*/ extern __ATTRS_o vector signed char vec_load_bndry(const signed char *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector unsigned char vec_load_bndry(const unsigned char *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector signed short vec_load_bndry(const signed short *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector unsigned short vec_load_bndry(const unsigned short *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector signed int vec_load_bndry(const signed int *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector unsigned int vec_load_bndry(const unsigned int *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector signed long long vec_load_bndry(const signed long long *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector unsigned long long vec_load_bndry(const unsigned long long *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); extern __ATTRS_o vector double vec_load_bndry(const double *__ptr, unsigned short __len) __constant_pow2_range(__len, 64, 4096); #define vec_load_bndry(X, Y) ((__typeof__((vec_load_bndry)((X), (Y)))) \ __builtin_s390_vlbb((X), ((Y) == 64 ? 0 : \ (Y) == 128 ? 1 : \ (Y) == 256 ? 2 : \ (Y) == 512 ? 3 : \ (Y) == 1024 ? 4 : \ (Y) == 2048 ? 5 : \ (Y) == 4096 ? 6 : -1))) /*-- vec_load_len -----------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_load_len(const signed char *__ptr, unsigned int __len) { return (vector signed char)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector unsigned char vec_load_len(const unsigned char *__ptr, unsigned int __len) { return (vector unsigned char)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector signed short vec_load_len(const signed short *__ptr, unsigned int __len) { return (vector signed short)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector unsigned short vec_load_len(const unsigned short *__ptr, unsigned int __len) { return (vector unsigned short)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector signed int vec_load_len(const signed int *__ptr, unsigned int __len) { return (vector signed int)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector unsigned int vec_load_len(const unsigned int *__ptr, unsigned int __len) { return (vector unsigned int)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector signed long long vec_load_len(const signed long long *__ptr, unsigned int __len) { return (vector signed long long)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector unsigned long long vec_load_len(const unsigned long long *__ptr, unsigned int __len) { return (vector unsigned long long)__builtin_s390_vll(__len, __ptr); } static inline __ATTRS_o_ai vector double vec_load_len(const double *__ptr, unsigned int __len) { return (vector double)__builtin_s390_vll(__len, __ptr); } /*-- vec_store_len ----------------------------------------------------------*/ static inline __ATTRS_o_ai void vec_store_len(vector signed char __vec, signed char *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector unsigned char __vec, unsigned char *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector signed short __vec, signed short *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector unsigned short __vec, unsigned short *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector signed int __vec, signed int *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector unsigned int __vec, unsigned int *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector signed long long __vec, signed long long *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector unsigned long long __vec, unsigned long long *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } static inline __ATTRS_o_ai void vec_store_len(vector double __vec, double *__ptr, unsigned int __len) { __builtin_s390_vstl((vector signed char)__vec, __len, __ptr); } /*-- vec_load_pair ----------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed long long vec_load_pair(signed long long __a, signed long long __b) { return (vector signed long long)(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_load_pair(unsigned long long __a, unsigned long long __b) { return (vector unsigned long long)(__a, __b); } /*-- vec_genmask ------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_genmask(unsigned short __mask) __constant(__mask) { return (vector unsigned char)( __mask & 0x8000 ? 0xff : 0, __mask & 0x4000 ? 0xff : 0, __mask & 0x2000 ? 0xff : 0, __mask & 0x1000 ? 0xff : 0, __mask & 0x0800 ? 0xff : 0, __mask & 0x0400 ? 0xff : 0, __mask & 0x0200 ? 0xff : 0, __mask & 0x0100 ? 0xff : 0, __mask & 0x0080 ? 0xff : 0, __mask & 0x0040 ? 0xff : 0, __mask & 0x0020 ? 0xff : 0, __mask & 0x0010 ? 0xff : 0, __mask & 0x0008 ? 0xff : 0, __mask & 0x0004 ? 0xff : 0, __mask & 0x0002 ? 0xff : 0, __mask & 0x0001 ? 0xff : 0); } /*-- vec_genmasks_* ---------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_genmasks_8(unsigned char __first, unsigned char __last) __constant(__first) __constant(__last) { unsigned char __bit1 = __first & 7; unsigned char __bit2 = __last & 7; unsigned char __mask1 = (unsigned char)(1U << (7 - __bit1) << 1) - 1; unsigned char __mask2 = (unsigned char)(1U << (7 - __bit2)) - 1; unsigned char __value = (__bit1 <= __bit2 ? __mask1 & ~__mask2 : __mask1 | ~__mask2); return (vector unsigned char)__value; } static inline __ATTRS_o_ai vector unsigned short vec_genmasks_16(unsigned char __first, unsigned char __last) __constant(__first) __constant(__last) { unsigned char __bit1 = __first & 15; unsigned char __bit2 = __last & 15; unsigned short __mask1 = (unsigned short)(1U << (15 - __bit1) << 1) - 1; unsigned short __mask2 = (unsigned short)(1U << (15 - __bit2)) - 1; unsigned short __value = (__bit1 <= __bit2 ? __mask1 & ~__mask2 : __mask1 | ~__mask2); return (vector unsigned short)__value; } static inline __ATTRS_o_ai vector unsigned int vec_genmasks_32(unsigned char __first, unsigned char __last) __constant(__first) __constant(__last) { unsigned char __bit1 = __first & 31; unsigned char __bit2 = __last & 31; unsigned int __mask1 = (1U << (31 - __bit1) << 1) - 1; unsigned int __mask2 = (1U << (31 - __bit2)) - 1; unsigned int __value = (__bit1 <= __bit2 ? __mask1 & ~__mask2 : __mask1 | ~__mask2); return (vector unsigned int)__value; } static inline __ATTRS_o_ai vector unsigned long long vec_genmasks_64(unsigned char __first, unsigned char __last) __constant(__first) __constant(__last) { unsigned char __bit1 = __first & 63; unsigned char __bit2 = __last & 63; unsigned long long __mask1 = (1ULL << (63 - __bit1) << 1) - 1; unsigned long long __mask2 = (1ULL << (63 - __bit2)) - 1; unsigned long long __value = (__bit1 <= __bit2 ? __mask1 & ~__mask2 : __mask1 | ~__mask2); return (vector unsigned long long)__value; } /*-- vec_splat --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_splat(vector signed char __vec, int __index) __constant_range(__index, 0, 15) { return (vector signed char)__vec[__index]; } static inline __ATTRS_o_ai vector bool char vec_splat(vector bool char __vec, int __index) __constant_range(__index, 0, 15) { return (vector bool char)(vector unsigned char)__vec[__index]; } static inline __ATTRS_o_ai vector unsigned char vec_splat(vector unsigned char __vec, int __index) __constant_range(__index, 0, 15) { return (vector unsigned char)__vec[__index]; } static inline __ATTRS_o_ai vector signed short vec_splat(vector signed short __vec, int __index) __constant_range(__index, 0, 7) { return (vector signed short)__vec[__index]; } static inline __ATTRS_o_ai vector bool short vec_splat(vector bool short __vec, int __index) __constant_range(__index, 0, 7) { return (vector bool short)(vector unsigned short)__vec[__index]; } static inline __ATTRS_o_ai vector unsigned short vec_splat(vector unsigned short __vec, int __index) __constant_range(__index, 0, 7) { return (vector unsigned short)__vec[__index]; } static inline __ATTRS_o_ai vector signed int vec_splat(vector signed int __vec, int __index) __constant_range(__index, 0, 3) { return (vector signed int)__vec[__index]; } static inline __ATTRS_o_ai vector bool int vec_splat(vector bool int __vec, int __index) __constant_range(__index, 0, 3) { return (vector bool int)(vector unsigned int)__vec[__index]; } static inline __ATTRS_o_ai vector unsigned int vec_splat(vector unsigned int __vec, int __index) __constant_range(__index, 0, 3) { return (vector unsigned int)__vec[__index]; } static inline __ATTRS_o_ai vector signed long long vec_splat(vector signed long long __vec, int __index) __constant_range(__index, 0, 1) { return (vector signed long long)__vec[__index]; } static inline __ATTRS_o_ai vector bool long long vec_splat(vector bool long long __vec, int __index) __constant_range(__index, 0, 1) { return (vector bool long long)(vector unsigned long long)__vec[__index]; } static inline __ATTRS_o_ai vector unsigned long long vec_splat(vector unsigned long long __vec, int __index) __constant_range(__index, 0, 1) { return (vector unsigned long long)__vec[__index]; } static inline __ATTRS_o_ai vector double vec_splat(vector double __vec, int __index) __constant_range(__index, 0, 1) { return (vector double)__vec[__index]; } /*-- vec_splat_s* -----------------------------------------------------------*/ static inline __ATTRS_ai vector signed char vec_splat_s8(signed char __scalar) __constant(__scalar) { return (vector signed char)__scalar; } static inline __ATTRS_ai vector signed short vec_splat_s16(signed short __scalar) __constant(__scalar) { return (vector signed short)__scalar; } static inline __ATTRS_ai vector signed int vec_splat_s32(signed short __scalar) __constant(__scalar) { return (vector signed int)(signed int)__scalar; } static inline __ATTRS_ai vector signed long long vec_splat_s64(signed short __scalar) __constant(__scalar) { return (vector signed long long)(signed long)__scalar; } /*-- vec_splat_u* -----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_splat_u8(unsigned char __scalar) __constant(__scalar) { return (vector unsigned char)__scalar; } static inline __ATTRS_ai vector unsigned short vec_splat_u16(unsigned short __scalar) __constant(__scalar) { return (vector unsigned short)__scalar; } static inline __ATTRS_ai vector unsigned int vec_splat_u32(signed short __scalar) __constant(__scalar) { return (vector unsigned int)(signed int)__scalar; } static inline __ATTRS_ai vector unsigned long long vec_splat_u64(signed short __scalar) __constant(__scalar) { return (vector unsigned long long)(signed long long)__scalar; } /*-- vec_splats -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_splats(signed char __scalar) { return (vector signed char)__scalar; } static inline __ATTRS_o_ai vector unsigned char vec_splats(unsigned char __scalar) { return (vector unsigned char)__scalar; } static inline __ATTRS_o_ai vector signed short vec_splats(signed short __scalar) { return (vector signed short)__scalar; } static inline __ATTRS_o_ai vector unsigned short vec_splats(unsigned short __scalar) { return (vector unsigned short)__scalar; } static inline __ATTRS_o_ai vector signed int vec_splats(signed int __scalar) { return (vector signed int)__scalar; } static inline __ATTRS_o_ai vector unsigned int vec_splats(unsigned int __scalar) { return (vector unsigned int)__scalar; } static inline __ATTRS_o_ai vector signed long long vec_splats(signed long long __scalar) { return (vector signed long long)__scalar; } static inline __ATTRS_o_ai vector unsigned long long vec_splats(unsigned long long __scalar) { return (vector unsigned long long)__scalar; } static inline __ATTRS_o_ai vector double vec_splats(double __scalar) { return (vector double)__scalar; } /*-- vec_extend_s64 ---------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed long long vec_extend_s64(vector signed char __a) { return (vector signed long long)(__a[7], __a[15]); } static inline __ATTRS_o_ai vector signed long long vec_extend_s64(vector signed short __a) { return (vector signed long long)(__a[3], __a[7]); } static inline __ATTRS_o_ai vector signed long long vec_extend_s64(vector signed int __a) { return (vector signed long long)(__a[1], __a[3]); } /*-- vec_mergeh -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_mergeh(vector signed char __a, vector signed char __b) { return (vector signed char)( __a[0], __b[0], __a[1], __b[1], __a[2], __b[2], __a[3], __b[3], __a[4], __b[4], __a[5], __b[5], __a[6], __b[6], __a[7], __b[7]); } static inline __ATTRS_o_ai vector bool char vec_mergeh(vector bool char __a, vector bool char __b) { return (vector bool char)( __a[0], __b[0], __a[1], __b[1], __a[2], __b[2], __a[3], __b[3], __a[4], __b[4], __a[5], __b[5], __a[6], __b[6], __a[7], __b[7]); } static inline __ATTRS_o_ai vector unsigned char vec_mergeh(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)( __a[0], __b[0], __a[1], __b[1], __a[2], __b[2], __a[3], __b[3], __a[4], __b[4], __a[5], __b[5], __a[6], __b[6], __a[7], __b[7]); } static inline __ATTRS_o_ai vector signed short vec_mergeh(vector signed short __a, vector signed short __b) { return (vector signed short)( __a[0], __b[0], __a[1], __b[1], __a[2], __b[2], __a[3], __b[3]); } static inline __ATTRS_o_ai vector bool short vec_mergeh(vector bool short __a, vector bool short __b) { return (vector bool short)( __a[0], __b[0], __a[1], __b[1], __a[2], __b[2], __a[3], __b[3]); } static inline __ATTRS_o_ai vector unsigned short vec_mergeh(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)( __a[0], __b[0], __a[1], __b[1], __a[2], __b[2], __a[3], __b[3]); } static inline __ATTRS_o_ai vector signed int vec_mergeh(vector signed int __a, vector signed int __b) { return (vector signed int)(__a[0], __b[0], __a[1], __b[1]); } static inline __ATTRS_o_ai vector bool int vec_mergeh(vector bool int __a, vector bool int __b) { return (vector bool int)(__a[0], __b[0], __a[1], __b[1]); } static inline __ATTRS_o_ai vector unsigned int vec_mergeh(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)(__a[0], __b[0], __a[1], __b[1]); } static inline __ATTRS_o_ai vector signed long long vec_mergeh(vector signed long long __a, vector signed long long __b) { return (vector signed long long)(__a[0], __b[0]); } static inline __ATTRS_o_ai vector bool long long vec_mergeh(vector bool long long __a, vector bool long long __b) { return (vector bool long long)(__a[0], __b[0]); } static inline __ATTRS_o_ai vector unsigned long long vec_mergeh(vector unsigned long long __a, vector unsigned long long __b) { return (vector unsigned long long)(__a[0], __b[0]); } static inline __ATTRS_o_ai vector double vec_mergeh(vector double __a, vector double __b) { return (vector double)(__a[0], __b[0]); } /*-- vec_mergel -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_mergel(vector signed char __a, vector signed char __b) { return (vector signed char)( __a[8], __b[8], __a[9], __b[9], __a[10], __b[10], __a[11], __b[11], __a[12], __b[12], __a[13], __b[13], __a[14], __b[14], __a[15], __b[15]); } static inline __ATTRS_o_ai vector bool char vec_mergel(vector bool char __a, vector bool char __b) { return (vector bool char)( __a[8], __b[8], __a[9], __b[9], __a[10], __b[10], __a[11], __b[11], __a[12], __b[12], __a[13], __b[13], __a[14], __b[14], __a[15], __b[15]); } static inline __ATTRS_o_ai vector unsigned char vec_mergel(vector unsigned char __a, vector unsigned char __b) { return (vector unsigned char)( __a[8], __b[8], __a[9], __b[9], __a[10], __b[10], __a[11], __b[11], __a[12], __b[12], __a[13], __b[13], __a[14], __b[14], __a[15], __b[15]); } static inline __ATTRS_o_ai vector signed short vec_mergel(vector signed short __a, vector signed short __b) { return (vector signed short)( __a[4], __b[4], __a[5], __b[5], __a[6], __b[6], __a[7], __b[7]); } static inline __ATTRS_o_ai vector bool short vec_mergel(vector bool short __a, vector bool short __b) { return (vector bool short)( __a[4], __b[4], __a[5], __b[5], __a[6], __b[6], __a[7], __b[7]); } static inline __ATTRS_o_ai vector unsigned short vec_mergel(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)( __a[4], __b[4], __a[5], __b[5], __a[6], __b[6], __a[7], __b[7]); } static inline __ATTRS_o_ai vector signed int vec_mergel(vector signed int __a, vector signed int __b) { return (vector signed int)(__a[2], __b[2], __a[3], __b[3]); } static inline __ATTRS_o_ai vector bool int vec_mergel(vector bool int __a, vector bool int __b) { return (vector bool int)(__a[2], __b[2], __a[3], __b[3]); } static inline __ATTRS_o_ai vector unsigned int vec_mergel(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)(__a[2], __b[2], __a[3], __b[3]); } static inline __ATTRS_o_ai vector signed long long vec_mergel(vector signed long long __a, vector signed long long __b) { return (vector signed long long)(__a[1], __b[1]); } static inline __ATTRS_o_ai vector bool long long vec_mergel(vector bool long long __a, vector bool long long __b) { return (vector bool long long)(__a[1], __b[1]); } static inline __ATTRS_o_ai vector unsigned long long vec_mergel(vector unsigned long long __a, vector unsigned long long __b) { return (vector unsigned long long)(__a[1], __b[1]); } static inline __ATTRS_o_ai vector double vec_mergel(vector double __a, vector double __b) { return (vector double)(__a[1], __b[1]); } /*-- vec_pack ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_pack(vector signed short __a, vector signed short __b) { vector signed char __ac = (vector signed char)__a; vector signed char __bc = (vector signed char)__b; return (vector signed char)( __ac[1], __ac[3], __ac[5], __ac[7], __ac[9], __ac[11], __ac[13], __ac[15], __bc[1], __bc[3], __bc[5], __bc[7], __bc[9], __bc[11], __bc[13], __bc[15]); } static inline __ATTRS_o_ai vector bool char vec_pack(vector bool short __a, vector bool short __b) { vector bool char __ac = (vector bool char)__a; vector bool char __bc = (vector bool char)__b; return (vector bool char)( __ac[1], __ac[3], __ac[5], __ac[7], __ac[9], __ac[11], __ac[13], __ac[15], __bc[1], __bc[3], __bc[5], __bc[7], __bc[9], __bc[11], __bc[13], __bc[15]); } static inline __ATTRS_o_ai vector unsigned char vec_pack(vector unsigned short __a, vector unsigned short __b) { vector unsigned char __ac = (vector unsigned char)__a; vector unsigned char __bc = (vector unsigned char)__b; return (vector unsigned char)( __ac[1], __ac[3], __ac[5], __ac[7], __ac[9], __ac[11], __ac[13], __ac[15], __bc[1], __bc[3], __bc[5], __bc[7], __bc[9], __bc[11], __bc[13], __bc[15]); } static inline __ATTRS_o_ai vector signed short vec_pack(vector signed int __a, vector signed int __b) { vector signed short __ac = (vector signed short)__a; vector signed short __bc = (vector signed short)__b; return (vector signed short)( __ac[1], __ac[3], __ac[5], __ac[7], __bc[1], __bc[3], __bc[5], __bc[7]); } static inline __ATTRS_o_ai vector bool short vec_pack(vector bool int __a, vector bool int __b) { vector bool short __ac = (vector bool short)__a; vector bool short __bc = (vector bool short)__b; return (vector bool short)( __ac[1], __ac[3], __ac[5], __ac[7], __bc[1], __bc[3], __bc[5], __bc[7]); } static inline __ATTRS_o_ai vector unsigned short vec_pack(vector unsigned int __a, vector unsigned int __b) { vector unsigned short __ac = (vector unsigned short)__a; vector unsigned short __bc = (vector unsigned short)__b; return (vector unsigned short)( __ac[1], __ac[3], __ac[5], __ac[7], __bc[1], __bc[3], __bc[5], __bc[7]); } static inline __ATTRS_o_ai vector signed int vec_pack(vector signed long long __a, vector signed long long __b) { vector signed int __ac = (vector signed int)__a; vector signed int __bc = (vector signed int)__b; return (vector signed int)(__ac[1], __ac[3], __bc[1], __bc[3]); } static inline __ATTRS_o_ai vector bool int vec_pack(vector bool long long __a, vector bool long long __b) { vector bool int __ac = (vector bool int)__a; vector bool int __bc = (vector bool int)__b; return (vector bool int)(__ac[1], __ac[3], __bc[1], __bc[3]); } static inline __ATTRS_o_ai vector unsigned int vec_pack(vector unsigned long long __a, vector unsigned long long __b) { vector unsigned int __ac = (vector unsigned int)__a; vector unsigned int __bc = (vector unsigned int)__b; return (vector unsigned int)(__ac[1], __ac[3], __bc[1], __bc[3]); } /*-- vec_packs --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_packs(vector signed short __a, vector signed short __b) { return __builtin_s390_vpksh(__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_packs(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vpklsh(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_packs(vector signed int __a, vector signed int __b) { return __builtin_s390_vpksf(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_packs(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vpklsf(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_packs(vector signed long long __a, vector signed long long __b) { return __builtin_s390_vpksg(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_packs(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vpklsg(__a, __b); } /*-- vec_packs_cc -----------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_packs_cc(vector signed short __a, vector signed short __b, int *__cc) { return __builtin_s390_vpkshs(__a, __b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_packs_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vpklshs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed short vec_packs_cc(vector signed int __a, vector signed int __b, int *__cc) { return __builtin_s390_vpksfs(__a, __b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_packs_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vpklsfs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed int vec_packs_cc(vector signed long long __a, vector signed long long __b, int *__cc) { return __builtin_s390_vpksgs(__a, __b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_packs_cc(vector unsigned long long __a, vector unsigned long long __b, int *__cc) { return __builtin_s390_vpklsgs(__a, __b, __cc); } /*-- vec_packsu -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_packsu(vector signed short __a, vector signed short __b) { const vector signed short __zero = (vector signed short)0; return __builtin_s390_vpklsh( (vector unsigned short)(__a >= __zero) & (vector unsigned short)__a, (vector unsigned short)(__b >= __zero) & (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned char vec_packsu(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vpklsh(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_packsu(vector signed int __a, vector signed int __b) { const vector signed int __zero = (vector signed int)0; return __builtin_s390_vpklsf( (vector unsigned int)(__a >= __zero) & (vector unsigned int)__a, (vector unsigned int)(__b >= __zero) & (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned short vec_packsu(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vpklsf(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_packsu(vector signed long long __a, vector signed long long __b) { const vector signed long long __zero = (vector signed long long)0; return __builtin_s390_vpklsg( (vector unsigned long long)(__a >= __zero) & (vector unsigned long long)__a, (vector unsigned long long)(__b >= __zero) & (vector unsigned long long)__b); } static inline __ATTRS_o_ai vector unsigned int vec_packsu(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vpklsg(__a, __b); } /*-- vec_packsu_cc ----------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_packsu_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vpklshs(__a, __b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_packsu_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vpklsfs(__a, __b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_packsu_cc(vector unsigned long long __a, vector unsigned long long __b, int *__cc) { return __builtin_s390_vpklsgs(__a, __b, __cc); } /*-- vec_unpackh ------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed short vec_unpackh(vector signed char __a) { return __builtin_s390_vuphb(__a); } static inline __ATTRS_o_ai vector bool short vec_unpackh(vector bool char __a) { return (vector bool short)__builtin_s390_vuphb((vector signed char)__a); } static inline __ATTRS_o_ai vector unsigned short vec_unpackh(vector unsigned char __a) { return __builtin_s390_vuplhb(__a); } static inline __ATTRS_o_ai vector signed int vec_unpackh(vector signed short __a) { return __builtin_s390_vuphh(__a); } static inline __ATTRS_o_ai vector bool int vec_unpackh(vector bool short __a) { return (vector bool int)__builtin_s390_vuphh((vector signed short)__a); } static inline __ATTRS_o_ai vector unsigned int vec_unpackh(vector unsigned short __a) { return __builtin_s390_vuplhh(__a); } static inline __ATTRS_o_ai vector signed long long vec_unpackh(vector signed int __a) { return __builtin_s390_vuphf(__a); } static inline __ATTRS_o_ai vector bool long long vec_unpackh(vector bool int __a) { return (vector bool long long)__builtin_s390_vuphf((vector signed int)__a); } static inline __ATTRS_o_ai vector unsigned long long vec_unpackh(vector unsigned int __a) { return __builtin_s390_vuplhf(__a); } /*-- vec_unpackl ------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed short vec_unpackl(vector signed char __a) { return __builtin_s390_vuplb(__a); } static inline __ATTRS_o_ai vector bool short vec_unpackl(vector bool char __a) { return (vector bool short)__builtin_s390_vuplb((vector signed char)__a); } static inline __ATTRS_o_ai vector unsigned short vec_unpackl(vector unsigned char __a) { return __builtin_s390_vupllb(__a); } static inline __ATTRS_o_ai vector signed int vec_unpackl(vector signed short __a) { return __builtin_s390_vuplhw(__a); } static inline __ATTRS_o_ai vector bool int vec_unpackl(vector bool short __a) { return (vector bool int)__builtin_s390_vuplhw((vector signed short)__a); } static inline __ATTRS_o_ai vector unsigned int vec_unpackl(vector unsigned short __a) { return __builtin_s390_vupllh(__a); } static inline __ATTRS_o_ai vector signed long long vec_unpackl(vector signed int __a) { return __builtin_s390_vuplf(__a); } static inline __ATTRS_o_ai vector bool long long vec_unpackl(vector bool int __a) { return (vector bool long long)__builtin_s390_vuplf((vector signed int)__a); } static inline __ATTRS_o_ai vector unsigned long long vec_unpackl(vector unsigned int __a) { return __builtin_s390_vupllf(__a); } /*-- vec_cmpeq --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmpeq(vector bool char __a, vector bool char __b) { return (vector bool char)(__a == __b); } static inline __ATTRS_o_ai vector bool char vec_cmpeq(vector signed char __a, vector signed char __b) { return (vector bool char)(__a == __b); } static inline __ATTRS_o_ai vector bool char vec_cmpeq(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)(__a == __b); } static inline __ATTRS_o_ai vector bool short vec_cmpeq(vector bool short __a, vector bool short __b) { return (vector bool short)(__a == __b); } static inline __ATTRS_o_ai vector bool short vec_cmpeq(vector signed short __a, vector signed short __b) { return (vector bool short)(__a == __b); } static inline __ATTRS_o_ai vector bool short vec_cmpeq(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)(__a == __b); } static inline __ATTRS_o_ai vector bool int vec_cmpeq(vector bool int __a, vector bool int __b) { return (vector bool int)(__a == __b); } static inline __ATTRS_o_ai vector bool int vec_cmpeq(vector signed int __a, vector signed int __b) { return (vector bool int)(__a == __b); } static inline __ATTRS_o_ai vector bool int vec_cmpeq(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)(__a == __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpeq(vector bool long long __a, vector bool long long __b) { return (vector bool long long)(__a == __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpeq(vector signed long long __a, vector signed long long __b) { return (vector bool long long)(__a == __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpeq(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)(__a == __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpeq(vector double __a, vector double __b) { return (vector bool long long)(__a == __b); } /*-- vec_cmpge --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmpge(vector signed char __a, vector signed char __b) { return (vector bool char)(__a >= __b); } static inline __ATTRS_o_ai vector bool char vec_cmpge(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)(__a >= __b); } static inline __ATTRS_o_ai vector bool short vec_cmpge(vector signed short __a, vector signed short __b) { return (vector bool short)(__a >= __b); } static inline __ATTRS_o_ai vector bool short vec_cmpge(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)(__a >= __b); } static inline __ATTRS_o_ai vector bool int vec_cmpge(vector signed int __a, vector signed int __b) { return (vector bool int)(__a >= __b); } static inline __ATTRS_o_ai vector bool int vec_cmpge(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)(__a >= __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpge(vector signed long long __a, vector signed long long __b) { return (vector bool long long)(__a >= __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpge(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)(__a >= __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpge(vector double __a, vector double __b) { return (vector bool long long)(__a >= __b); } /*-- vec_cmpgt --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmpgt(vector signed char __a, vector signed char __b) { return (vector bool char)(__a > __b); } static inline __ATTRS_o_ai vector bool char vec_cmpgt(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)(__a > __b); } static inline __ATTRS_o_ai vector bool short vec_cmpgt(vector signed short __a, vector signed short __b) { return (vector bool short)(__a > __b); } static inline __ATTRS_o_ai vector bool short vec_cmpgt(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)(__a > __b); } static inline __ATTRS_o_ai vector bool int vec_cmpgt(vector signed int __a, vector signed int __b) { return (vector bool int)(__a > __b); } static inline __ATTRS_o_ai vector bool int vec_cmpgt(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)(__a > __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpgt(vector signed long long __a, vector signed long long __b) { return (vector bool long long)(__a > __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpgt(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)(__a > __b); } static inline __ATTRS_o_ai vector bool long long vec_cmpgt(vector double __a, vector double __b) { return (vector bool long long)(__a > __b); } /*-- vec_cmple --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmple(vector signed char __a, vector signed char __b) { return (vector bool char)(__a <= __b); } static inline __ATTRS_o_ai vector bool char vec_cmple(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)(__a <= __b); } static inline __ATTRS_o_ai vector bool short vec_cmple(vector signed short __a, vector signed short __b) { return (vector bool short)(__a <= __b); } static inline __ATTRS_o_ai vector bool short vec_cmple(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)(__a <= __b); } static inline __ATTRS_o_ai vector bool int vec_cmple(vector signed int __a, vector signed int __b) { return (vector bool int)(__a <= __b); } static inline __ATTRS_o_ai vector bool int vec_cmple(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)(__a <= __b); } static inline __ATTRS_o_ai vector bool long long vec_cmple(vector signed long long __a, vector signed long long __b) { return (vector bool long long)(__a <= __b); } static inline __ATTRS_o_ai vector bool long long vec_cmple(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)(__a <= __b); } static inline __ATTRS_o_ai vector bool long long vec_cmple(vector double __a, vector double __b) { return (vector bool long long)(__a <= __b); } /*-- vec_cmplt --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmplt(vector signed char __a, vector signed char __b) { return (vector bool char)(__a < __b); } static inline __ATTRS_o_ai vector bool char vec_cmplt(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)(__a < __b); } static inline __ATTRS_o_ai vector bool short vec_cmplt(vector signed short __a, vector signed short __b) { return (vector bool short)(__a < __b); } static inline __ATTRS_o_ai vector bool short vec_cmplt(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)(__a < __b); } static inline __ATTRS_o_ai vector bool int vec_cmplt(vector signed int __a, vector signed int __b) { return (vector bool int)(__a < __b); } static inline __ATTRS_o_ai vector bool int vec_cmplt(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)(__a < __b); } static inline __ATTRS_o_ai vector bool long long vec_cmplt(vector signed long long __a, vector signed long long __b) { return (vector bool long long)(__a < __b); } static inline __ATTRS_o_ai vector bool long long vec_cmplt(vector unsigned long long __a, vector unsigned long long __b) { return (vector bool long long)(__a < __b); } static inline __ATTRS_o_ai vector bool long long vec_cmplt(vector double __a, vector double __b) { return (vector bool long long)(__a < __b); } /*-- vec_all_eq -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_all_eq(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs(__a, (vector signed char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs(__a, (vector signed short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs(__a, (vector signed int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs(__a, (vector signed long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_eq(vector double __a, vector double __b) { int __cc; __builtin_s390_vfcedbs(__a, __b, &__cc); return __cc == 0; } /*-- vec_all_ne -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_all_ne(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs(__a, (vector signed char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs(__a, (vector signed short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs(__a, (vector signed int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs(__a, (vector signed long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ne(vector double __a, vector double __b) { int __cc; __builtin_s390_vfcedbs(__a, __b, &__cc); return __cc == 3; } /*-- vec_all_ge -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_all_ge(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, (vector signed char)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, (vector unsigned char)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, (vector unsigned char)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, (vector signed short)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, (vector unsigned short)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, (vector unsigned short)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, (vector signed int)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, (vector unsigned int)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, (vector unsigned int)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, (vector signed long long)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, __a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, (vector unsigned long long)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, (vector unsigned long long)__a, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_ge(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__a, __b, &__cc); return __cc == 0; } /*-- vec_all_gt -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_all_gt(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs(__a, (vector signed char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs(__a, (vector unsigned char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, (vector unsigned char)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs(__a, (vector signed short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs(__a, (vector unsigned short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, (vector unsigned short)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs(__a, (vector signed int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs(__a, (vector unsigned int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, (vector unsigned int)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs(__a, (vector signed long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs(__a, (vector unsigned long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, __b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, (vector unsigned long long)__b, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_gt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__a, __b, &__cc); return __cc == 0; } /*-- vec_all_le -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_all_le(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs(__a, (vector signed char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs(__a, (vector unsigned char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, (vector unsigned char)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs(__a, (vector signed short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs(__a, (vector unsigned short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, (vector unsigned short)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs(__a, (vector signed int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs(__a, (vector unsigned int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, (vector unsigned int)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs(__a, (vector signed long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs(__a, (vector unsigned long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, __b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, (vector unsigned long long)__b, &__cc); return __cc == 3; } static inline __ATTRS_o_ai int vec_all_le(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__b, __a, &__cc); return __cc == 0; } /*-- vec_all_lt -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_all_lt(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, (vector signed char)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, (vector unsigned char)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, (vector unsigned char)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, (vector signed short)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, (vector unsigned short)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, (vector unsigned short)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, (vector signed int)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, (vector unsigned int)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, (vector unsigned int)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, (vector signed long long)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, __a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, (vector unsigned long long)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, (vector unsigned long long)__a, &__cc); return __cc == 0; } static inline __ATTRS_o_ai int vec_all_lt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__b, __a, &__cc); return __cc == 0; } /*-- vec_all_nge ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_all_nge(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__a, __b, &__cc); return __cc == 3; } /*-- vec_all_ngt ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_all_ngt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__a, __b, &__cc); return __cc == 3; } /*-- vec_all_nle ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_all_nle(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__b, __a, &__cc); return __cc == 3; } /*-- vec_all_nlt ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_all_nlt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__b, __a, &__cc); return __cc == 3; } /*-- vec_all_nan ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_all_nan(vector double __a) { int __cc; __builtin_s390_vftcidb(__a, 15, &__cc); return __cc == 0; } /*-- vec_all_numeric --------------------------------------------------------*/ static inline __ATTRS_ai int vec_all_numeric(vector double __a) { int __cc; __builtin_s390_vftcidb(__a, 15, &__cc); return __cc == 3; } /*-- vec_any_eq -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_any_eq(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs(__a, (vector signed char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs(__a, (vector signed short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs(__a, (vector signed int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs(__a, (vector signed long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_eq(vector double __a, vector double __b) { int __cc; __builtin_s390_vfcedbs(__a, __b, &__cc); return __cc <= 1; } /*-- vec_any_ne -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_any_ne(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs(__a, (vector signed char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vceqbs((vector signed char)__a, (vector signed char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs(__a, (vector signed short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vceqhs((vector signed short)__a, (vector signed short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs(__a, (vector signed int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vceqfs((vector signed int)__a, (vector signed int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs(__a, (vector signed long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vceqgs((vector signed long long)__a, (vector signed long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ne(vector double __a, vector double __b) { int __cc; __builtin_s390_vfcedbs(__a, __b, &__cc); return __cc != 0; } /*-- vec_any_ge -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_any_ge(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, (vector signed char)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, (vector unsigned char)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, (vector unsigned char)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, (vector signed short)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, (vector unsigned short)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, (vector unsigned short)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, (vector signed int)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, (vector unsigned int)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, (vector unsigned int)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, (vector signed long long)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, __a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, (vector unsigned long long)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, (vector unsigned long long)__a, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_ge(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__a, __b, &__cc); return __cc <= 1; } /*-- vec_any_gt -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_any_gt(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs(__a, (vector signed char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs(__a, (vector unsigned char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, (vector unsigned char)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs(__a, (vector signed short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs(__a, (vector unsigned short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, (vector unsigned short)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs(__a, (vector signed int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs(__a, (vector unsigned int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, (vector unsigned int)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs(__a, (vector signed long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs(__a, (vector unsigned long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, __b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, (vector unsigned long long)__b, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_gt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__a, __b, &__cc); return __cc <= 1; } /*-- vec_any_le -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_any_le(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs(__a, (vector signed char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs(__a, (vector unsigned char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__a, (vector unsigned char)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs(__a, (vector signed short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs(__a, (vector unsigned short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__a, (vector unsigned short)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs(__a, (vector signed int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs(__a, (vector unsigned int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__a, (vector unsigned int)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs(__a, (vector signed long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs(__a, (vector unsigned long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, __b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__a, (vector unsigned long long)__b, &__cc); return __cc != 0; } static inline __ATTRS_o_ai int vec_any_le(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__b, __a, &__cc); return __cc <= 1; } /*-- vec_any_lt -------------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_any_lt(vector signed char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector signed char __a, vector bool char __b) { int __cc; __builtin_s390_vchbs((vector signed char)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool char __a, vector signed char __b) { int __cc; __builtin_s390_vchbs(__b, (vector signed char)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool char __a, vector unsigned char __b) { int __cc; __builtin_s390_vchlbs(__b, (vector unsigned char)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool char __a, vector bool char __b) { int __cc; __builtin_s390_vchlbs((vector unsigned char)__b, (vector unsigned char)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector signed short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector signed short __a, vector bool short __b) { int __cc; __builtin_s390_vchhs((vector signed short)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool short __a, vector signed short __b) { int __cc; __builtin_s390_vchhs(__b, (vector signed short)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool short __a, vector unsigned short __b) { int __cc; __builtin_s390_vchlhs(__b, (vector unsigned short)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool short __a, vector bool short __b) { int __cc; __builtin_s390_vchlhs((vector unsigned short)__b, (vector unsigned short)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector signed int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector signed int __a, vector bool int __b) { int __cc; __builtin_s390_vchfs((vector signed int)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool int __a, vector signed int __b) { int __cc; __builtin_s390_vchfs(__b, (vector signed int)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool int __a, vector unsigned int __b) { int __cc; __builtin_s390_vchlfs(__b, (vector unsigned int)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool int __a, vector bool int __b) { int __cc; __builtin_s390_vchlfs((vector unsigned int)__b, (vector unsigned int)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector signed long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector signed long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchgs((vector signed long long)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool long long __a, vector signed long long __b) { int __cc; __builtin_s390_vchgs(__b, (vector signed long long)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector unsigned long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, __a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool long long __a, vector unsigned long long __b) { int __cc; __builtin_s390_vchlgs(__b, (vector unsigned long long)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector bool long long __a, vector bool long long __b) { int __cc; __builtin_s390_vchlgs((vector unsigned long long)__b, (vector unsigned long long)__a, &__cc); return __cc <= 1; } static inline __ATTRS_o_ai int vec_any_lt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__b, __a, &__cc); return __cc <= 1; } /*-- vec_any_nge ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_any_nge(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__a, __b, &__cc); return __cc != 0; } /*-- vec_any_ngt ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_any_ngt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__a, __b, &__cc); return __cc != 0; } /*-- vec_any_nle ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_any_nle(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchedbs(__b, __a, &__cc); return __cc != 0; } /*-- vec_any_nlt ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_any_nlt(vector double __a, vector double __b) { int __cc; __builtin_s390_vfchdbs(__b, __a, &__cc); return __cc != 0; } /*-- vec_any_nan ------------------------------------------------------------*/ static inline __ATTRS_ai int vec_any_nan(vector double __a) { int __cc; __builtin_s390_vftcidb(__a, 15, &__cc); return __cc != 3; } /*-- vec_any_numeric --------------------------------------------------------*/ static inline __ATTRS_ai int vec_any_numeric(vector double __a) { int __cc; __builtin_s390_vftcidb(__a, 15, &__cc); return __cc != 0; } /*-- vec_andc ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_andc(vector bool char __a, vector bool char __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed char vec_andc(vector signed char __a, vector signed char __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed char vec_andc(vector bool char __a, vector signed char __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed char vec_andc(vector signed char __a, vector bool char __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned char vec_andc(vector unsigned char __a, vector unsigned char __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned char vec_andc(vector bool char __a, vector unsigned char __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned char vec_andc(vector unsigned char __a, vector bool char __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector bool short vec_andc(vector bool short __a, vector bool short __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed short vec_andc(vector signed short __a, vector signed short __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed short vec_andc(vector bool short __a, vector signed short __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed short vec_andc(vector signed short __a, vector bool short __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned short vec_andc(vector unsigned short __a, vector unsigned short __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned short vec_andc(vector bool short __a, vector unsigned short __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned short vec_andc(vector unsigned short __a, vector bool short __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector bool int vec_andc(vector bool int __a, vector bool int __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed int vec_andc(vector signed int __a, vector signed int __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed int vec_andc(vector bool int __a, vector signed int __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed int vec_andc(vector signed int __a, vector bool int __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned int vec_andc(vector unsigned int __a, vector unsigned int __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned int vec_andc(vector bool int __a, vector unsigned int __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned int vec_andc(vector unsigned int __a, vector bool int __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector bool long long vec_andc(vector bool long long __a, vector bool long long __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed long long vec_andc(vector signed long long __a, vector signed long long __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed long long vec_andc(vector bool long long __a, vector signed long long __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector signed long long vec_andc(vector signed long long __a, vector bool long long __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned long long vec_andc(vector unsigned long long __a, vector unsigned long long __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned long long vec_andc(vector bool long long __a, vector unsigned long long __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector unsigned long long vec_andc(vector unsigned long long __a, vector bool long long __b) { return __a & ~__b; } static inline __ATTRS_o_ai vector double vec_andc(vector double __a, vector double __b) { return (vector double)((vector unsigned long long)__a & ~(vector unsigned long long)__b); } static inline __ATTRS_o_ai vector double vec_andc(vector bool long long __a, vector double __b) { return (vector double)((vector unsigned long long)__a & ~(vector unsigned long long)__b); } static inline __ATTRS_o_ai vector double vec_andc(vector double __a, vector bool long long __b) { return (vector double)((vector unsigned long long)__a & ~(vector unsigned long long)__b); } /*-- vec_nor ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_nor(vector bool char __a, vector bool char __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed char vec_nor(vector signed char __a, vector signed char __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed char vec_nor(vector bool char __a, vector signed char __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed char vec_nor(vector signed char __a, vector bool char __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned char vec_nor(vector unsigned char __a, vector unsigned char __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned char vec_nor(vector bool char __a, vector unsigned char __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned char vec_nor(vector unsigned char __a, vector bool char __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector bool short vec_nor(vector bool short __a, vector bool short __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed short vec_nor(vector signed short __a, vector signed short __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed short vec_nor(vector bool short __a, vector signed short __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed short vec_nor(vector signed short __a, vector bool short __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned short vec_nor(vector unsigned short __a, vector unsigned short __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned short vec_nor(vector bool short __a, vector unsigned short __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned short vec_nor(vector unsigned short __a, vector bool short __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector bool int vec_nor(vector bool int __a, vector bool int __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed int vec_nor(vector signed int __a, vector signed int __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed int vec_nor(vector bool int __a, vector signed int __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed int vec_nor(vector signed int __a, vector bool int __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned int vec_nor(vector unsigned int __a, vector unsigned int __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned int vec_nor(vector bool int __a, vector unsigned int __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned int vec_nor(vector unsigned int __a, vector bool int __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector bool long long vec_nor(vector bool long long __a, vector bool long long __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed long long vec_nor(vector signed long long __a, vector signed long long __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed long long vec_nor(vector bool long long __a, vector signed long long __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector signed long long vec_nor(vector signed long long __a, vector bool long long __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned long long vec_nor(vector unsigned long long __a, vector unsigned long long __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned long long vec_nor(vector bool long long __a, vector unsigned long long __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector unsigned long long vec_nor(vector unsigned long long __a, vector bool long long __b) { return ~(__a | __b); } static inline __ATTRS_o_ai vector double vec_nor(vector double __a, vector double __b) { return (vector double)~((vector unsigned long long)__a | (vector unsigned long long)__b); } static inline __ATTRS_o_ai vector double vec_nor(vector bool long long __a, vector double __b) { return (vector double)~((vector unsigned long long)__a | (vector unsigned long long)__b); } static inline __ATTRS_o_ai vector double vec_nor(vector double __a, vector bool long long __b) { return (vector double)~((vector unsigned long long)__a | (vector unsigned long long)__b); } /*-- vec_cntlz --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cntlz(vector signed char __a) { return __builtin_s390_vclzb((vector unsigned char)__a); } static inline __ATTRS_o_ai vector unsigned char vec_cntlz(vector unsigned char __a) { return __builtin_s390_vclzb(__a); } static inline __ATTRS_o_ai vector unsigned short vec_cntlz(vector signed short __a) { return __builtin_s390_vclzh((vector unsigned short)__a); } static inline __ATTRS_o_ai vector unsigned short vec_cntlz(vector unsigned short __a) { return __builtin_s390_vclzh(__a); } static inline __ATTRS_o_ai vector unsigned int vec_cntlz(vector signed int __a) { return __builtin_s390_vclzf((vector unsigned int)__a); } static inline __ATTRS_o_ai vector unsigned int vec_cntlz(vector unsigned int __a) { return __builtin_s390_vclzf(__a); } static inline __ATTRS_o_ai vector unsigned long long vec_cntlz(vector signed long long __a) { return __builtin_s390_vclzg((vector unsigned long long)__a); } static inline __ATTRS_o_ai vector unsigned long long vec_cntlz(vector unsigned long long __a) { return __builtin_s390_vclzg(__a); } /*-- vec_cnttz --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cnttz(vector signed char __a) { return __builtin_s390_vctzb((vector unsigned char)__a); } static inline __ATTRS_o_ai vector unsigned char vec_cnttz(vector unsigned char __a) { return __builtin_s390_vctzb(__a); } static inline __ATTRS_o_ai vector unsigned short vec_cnttz(vector signed short __a) { return __builtin_s390_vctzh((vector unsigned short)__a); } static inline __ATTRS_o_ai vector unsigned short vec_cnttz(vector unsigned short __a) { return __builtin_s390_vctzh(__a); } static inline __ATTRS_o_ai vector unsigned int vec_cnttz(vector signed int __a) { return __builtin_s390_vctzf((vector unsigned int)__a); } static inline __ATTRS_o_ai vector unsigned int vec_cnttz(vector unsigned int __a) { return __builtin_s390_vctzf(__a); } static inline __ATTRS_o_ai vector unsigned long long vec_cnttz(vector signed long long __a) { return __builtin_s390_vctzg((vector unsigned long long)__a); } static inline __ATTRS_o_ai vector unsigned long long vec_cnttz(vector unsigned long long __a) { return __builtin_s390_vctzg(__a); } /*-- vec_popcnt -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_popcnt(vector signed char __a) { return __builtin_s390_vpopctb((vector unsigned char)__a); } static inline __ATTRS_o_ai vector unsigned char vec_popcnt(vector unsigned char __a) { return __builtin_s390_vpopctb(__a); } static inline __ATTRS_o_ai vector unsigned short vec_popcnt(vector signed short __a) { return __builtin_s390_vpopcth((vector unsigned short)__a); } static inline __ATTRS_o_ai vector unsigned short vec_popcnt(vector unsigned short __a) { return __builtin_s390_vpopcth(__a); } static inline __ATTRS_o_ai vector unsigned int vec_popcnt(vector signed int __a) { return __builtin_s390_vpopctf((vector unsigned int)__a); } static inline __ATTRS_o_ai vector unsigned int vec_popcnt(vector unsigned int __a) { return __builtin_s390_vpopctf(__a); } static inline __ATTRS_o_ai vector unsigned long long vec_popcnt(vector signed long long __a) { return __builtin_s390_vpopctg((vector unsigned long long)__a); } static inline __ATTRS_o_ai vector unsigned long long vec_popcnt(vector unsigned long long __a) { return __builtin_s390_vpopctg(__a); } /*-- vec_rl -----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_rl(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_s390_verllvb( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_rl(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_verllvb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_rl(vector signed short __a, vector unsigned short __b) { return (vector signed short)__builtin_s390_verllvh( (vector unsigned short)__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_rl(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_verllvh(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_rl(vector signed int __a, vector unsigned int __b) { return (vector signed int)__builtin_s390_verllvf( (vector unsigned int)__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_rl(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_verllvf(__a, __b); } static inline __ATTRS_o_ai vector signed long long vec_rl(vector signed long long __a, vector unsigned long long __b) { return (vector signed long long)__builtin_s390_verllvg( (vector unsigned long long)__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_rl(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_verllvg(__a, __b); } /*-- vec_rli ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_rli(vector signed char __a, unsigned long __b) { return (vector signed char)__builtin_s390_verllb( (vector unsigned char)__a, (int)__b); } static inline __ATTRS_o_ai vector unsigned char vec_rli(vector unsigned char __a, unsigned long __b) { return __builtin_s390_verllb(__a, (int)__b); } static inline __ATTRS_o_ai vector signed short vec_rli(vector signed short __a, unsigned long __b) { return (vector signed short)__builtin_s390_verllh( (vector unsigned short)__a, (int)__b); } static inline __ATTRS_o_ai vector unsigned short vec_rli(vector unsigned short __a, unsigned long __b) { return __builtin_s390_verllh(__a, (int)__b); } static inline __ATTRS_o_ai vector signed int vec_rli(vector signed int __a, unsigned long __b) { return (vector signed int)__builtin_s390_verllf( (vector unsigned int)__a, (int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_rli(vector unsigned int __a, unsigned long __b) { return __builtin_s390_verllf(__a, (int)__b); } static inline __ATTRS_o_ai vector signed long long vec_rli(vector signed long long __a, unsigned long __b) { return (vector signed long long)__builtin_s390_verllg( (vector unsigned long long)__a, (int)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_rli(vector unsigned long long __a, unsigned long __b) { return __builtin_s390_verllg(__a, (int)__b); } /*-- vec_rl_mask ------------------------------------------------------------*/ extern __ATTRS_o vector signed char vec_rl_mask(vector signed char __a, vector unsigned char __b, unsigned char __c) __constant(__c); extern __ATTRS_o vector unsigned char vec_rl_mask(vector unsigned char __a, vector unsigned char __b, unsigned char __c) __constant(__c); extern __ATTRS_o vector signed short vec_rl_mask(vector signed short __a, vector unsigned short __b, unsigned char __c) __constant(__c); extern __ATTRS_o vector unsigned short vec_rl_mask(vector unsigned short __a, vector unsigned short __b, unsigned char __c) __constant(__c); extern __ATTRS_o vector signed int vec_rl_mask(vector signed int __a, vector unsigned int __b, unsigned char __c) __constant(__c); extern __ATTRS_o vector unsigned int vec_rl_mask(vector unsigned int __a, vector unsigned int __b, unsigned char __c) __constant(__c); extern __ATTRS_o vector signed long long vec_rl_mask(vector signed long long __a, vector unsigned long long __b, unsigned char __c) __constant(__c); extern __ATTRS_o vector unsigned long long vec_rl_mask(vector unsigned long long __a, vector unsigned long long __b, unsigned char __c) __constant(__c); #define vec_rl_mask(X, Y, Z) ((__typeof__((vec_rl_mask)((X), (Y), (Z)))) \ __extension__ ({ \ vector unsigned char __res; \ vector unsigned char __x = (vector unsigned char)(X); \ vector unsigned char __y = (vector unsigned char)(Y); \ switch (sizeof ((X)[0])) { \ case 1: __res = (vector unsigned char) __builtin_s390_verimb( \ (vector unsigned char)__x, (vector unsigned char)__x, \ (vector unsigned char)__y, (Z)); break; \ case 2: __res = (vector unsigned char) __builtin_s390_verimh( \ (vector unsigned short)__x, (vector unsigned short)__x, \ (vector unsigned short)__y, (Z)); break; \ case 4: __res = (vector unsigned char) __builtin_s390_verimf( \ (vector unsigned int)__x, (vector unsigned int)__x, \ (vector unsigned int)__y, (Z)); break; \ default: __res = (vector unsigned char) __builtin_s390_verimg( \ (vector unsigned long long)__x, (vector unsigned long long)__x, \ (vector unsigned long long)__y, (Z)); break; \ } __res; })) /*-- vec_sll ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_sll(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed char vec_sll(vector signed char __a, vector unsigned short __b) { return (vector signed char)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed char vec_sll(vector signed char __a, vector unsigned int __b) { return (vector signed char)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool char vec_sll(vector bool char __a, vector unsigned char __b) { return (vector bool char)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool char vec_sll(vector bool char __a, vector unsigned short __b) { return (vector bool char)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool char vec_sll(vector bool char __a, vector unsigned int __b) { return (vector bool char)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_sll(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vsl(__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_sll(vector unsigned char __a, vector unsigned short __b) { return __builtin_s390_vsl(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_sll(vector unsigned char __a, vector unsigned int __b) { return __builtin_s390_vsl(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_sll(vector signed short __a, vector unsigned char __b) { return (vector signed short)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed short vec_sll(vector signed short __a, vector unsigned short __b) { return (vector signed short)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_sll(vector signed short __a, vector unsigned int __b) { return (vector signed short)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool short vec_sll(vector bool short __a, vector unsigned char __b) { return (vector bool short)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool short vec_sll(vector bool short __a, vector unsigned short __b) { return (vector bool short)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool short vec_sll(vector bool short __a, vector unsigned int __b) { return (vector bool short)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_sll(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_sll(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_sll(vector unsigned short __a, vector unsigned int __b) { return (vector unsigned short)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_sll(vector signed int __a, vector unsigned char __b) { return (vector signed int)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed int vec_sll(vector signed int __a, vector unsigned short __b) { return (vector signed int)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_sll(vector signed int __a, vector unsigned int __b) { return (vector signed int)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool int vec_sll(vector bool int __a, vector unsigned char __b) { return (vector bool int)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool int vec_sll(vector bool int __a, vector unsigned short __b) { return (vector bool int)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool int vec_sll(vector bool int __a, vector unsigned int __b) { return (vector bool int)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_sll(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_sll(vector unsigned int __a, vector unsigned short __b) { return (vector unsigned int)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_sll(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_sll(vector signed long long __a, vector unsigned char __b) { return (vector signed long long)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed long long vec_sll(vector signed long long __a, vector unsigned short __b) { return (vector signed long long)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_sll(vector signed long long __a, vector unsigned int __b) { return (vector signed long long)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool long long vec_sll(vector bool long long __a, vector unsigned char __b) { return (vector bool long long)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool long long vec_sll(vector bool long long __a, vector unsigned short __b) { return (vector bool long long)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool long long vec_sll(vector bool long long __a, vector unsigned int __b) { return (vector bool long long)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_sll(vector unsigned long long __a, vector unsigned char __b) { return (vector unsigned long long)__builtin_s390_vsl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_sll(vector unsigned long long __a, vector unsigned short __b) { return (vector unsigned long long)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_sll(vector unsigned long long __a, vector unsigned int __b) { return (vector unsigned long long)__builtin_s390_vsl( (vector unsigned char)__a, (vector unsigned char)__b); } /*-- vec_slb ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_slb(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed char vec_slb(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_s390_vslb( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_slb(vector unsigned char __a, vector signed char __b) { return __builtin_s390_vslb(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_slb(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vslb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_slb(vector signed short __a, vector signed short __b) { return (vector signed short)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_slb(vector signed short __a, vector unsigned short __b) { return (vector signed short)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_slb(vector unsigned short __a, vector signed short __b) { return (vector unsigned short)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_slb(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_slb(vector signed int __a, vector signed int __b) { return (vector signed int)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_slb(vector signed int __a, vector unsigned int __b) { return (vector signed int)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_slb(vector unsigned int __a, vector signed int __b) { return (vector unsigned int)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_slb(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_slb(vector signed long long __a, vector signed long long __b) { return (vector signed long long)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_slb(vector signed long long __a, vector unsigned long long __b) { return (vector signed long long)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_slb(vector unsigned long long __a, vector signed long long __b) { return (vector unsigned long long)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_slb(vector unsigned long long __a, vector unsigned long long __b) { return (vector unsigned long long)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector double vec_slb(vector double __a, vector signed long long __b) { return (vector double)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector double vec_slb(vector double __a, vector unsigned long long __b) { return (vector double)__builtin_s390_vslb( (vector unsigned char)__a, (vector unsigned char)__b); } /*-- vec_sld ----------------------------------------------------------------*/ extern __ATTRS_o vector signed char vec_sld(vector signed char __a, vector signed char __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector unsigned char vec_sld(vector unsigned char __a, vector unsigned char __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector signed short vec_sld(vector signed short __a, vector signed short __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector unsigned short vec_sld(vector unsigned short __a, vector unsigned short __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector signed int vec_sld(vector signed int __a, vector signed int __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector unsigned int vec_sld(vector unsigned int __a, vector unsigned int __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector signed long long vec_sld(vector signed long long __a, vector signed long long __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector unsigned long long vec_sld(vector unsigned long long __a, vector unsigned long long __b, int __c) __constant_range(__c, 0, 15); extern __ATTRS_o vector double vec_sld(vector double __a, vector double __b, int __c) __constant_range(__c, 0, 15); #define vec_sld(X, Y, Z) ((__typeof__((vec_sld)((X), (Y), (Z)))) \ __builtin_s390_vsldb((vector unsigned char)(X), \ (vector unsigned char)(Y), (Z))) /*-- vec_sldw ---------------------------------------------------------------*/ extern __ATTRS_o vector signed char vec_sldw(vector signed char __a, vector signed char __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector unsigned char vec_sldw(vector unsigned char __a, vector unsigned char __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector signed short vec_sldw(vector signed short __a, vector signed short __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector unsigned short vec_sldw(vector unsigned short __a, vector unsigned short __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector signed int vec_sldw(vector signed int __a, vector signed int __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector unsigned int vec_sldw(vector unsigned int __a, vector unsigned int __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector signed long long vec_sldw(vector signed long long __a, vector signed long long __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector unsigned long long vec_sldw(vector unsigned long long __a, vector unsigned long long __b, int __c) __constant_range(__c, 0, 3); extern __ATTRS_o vector double vec_sldw(vector double __a, vector double __b, int __c) __constant_range(__c, 0, 3); #define vec_sldw(X, Y, Z) ((__typeof__((vec_sldw)((X), (Y), (Z)))) \ __builtin_s390_vsldb((vector unsigned char)(X), \ (vector unsigned char)(Y), (Z) * 4)) /*-- vec_sral ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_sral(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed char vec_sral(vector signed char __a, vector unsigned short __b) { return (vector signed char)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed char vec_sral(vector signed char __a, vector unsigned int __b) { return (vector signed char)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool char vec_sral(vector bool char __a, vector unsigned char __b) { return (vector bool char)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool char vec_sral(vector bool char __a, vector unsigned short __b) { return (vector bool char)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool char vec_sral(vector bool char __a, vector unsigned int __b) { return (vector bool char)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_sral(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vsra(__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_sral(vector unsigned char __a, vector unsigned short __b) { return __builtin_s390_vsra(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_sral(vector unsigned char __a, vector unsigned int __b) { return __builtin_s390_vsra(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_sral(vector signed short __a, vector unsigned char __b) { return (vector signed short)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed short vec_sral(vector signed short __a, vector unsigned short __b) { return (vector signed short)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_sral(vector signed short __a, vector unsigned int __b) { return (vector signed short)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool short vec_sral(vector bool short __a, vector unsigned char __b) { return (vector bool short)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool short vec_sral(vector bool short __a, vector unsigned short __b) { return (vector bool short)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool short vec_sral(vector bool short __a, vector unsigned int __b) { return (vector bool short)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_sral(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_sral(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_sral(vector unsigned short __a, vector unsigned int __b) { return (vector unsigned short)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_sral(vector signed int __a, vector unsigned char __b) { return (vector signed int)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed int vec_sral(vector signed int __a, vector unsigned short __b) { return (vector signed int)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_sral(vector signed int __a, vector unsigned int __b) { return (vector signed int)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool int vec_sral(vector bool int __a, vector unsigned char __b) { return (vector bool int)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool int vec_sral(vector bool int __a, vector unsigned short __b) { return (vector bool int)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool int vec_sral(vector bool int __a, vector unsigned int __b) { return (vector bool int)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_sral(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_sral(vector unsigned int __a, vector unsigned short __b) { return (vector unsigned int)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_sral(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_sral(vector signed long long __a, vector unsigned char __b) { return (vector signed long long)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed long long vec_sral(vector signed long long __a, vector unsigned short __b) { return (vector signed long long)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_sral(vector signed long long __a, vector unsigned int __b) { return (vector signed long long)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool long long vec_sral(vector bool long long __a, vector unsigned char __b) { return (vector bool long long)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool long long vec_sral(vector bool long long __a, vector unsigned short __b) { return (vector bool long long)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool long long vec_sral(vector bool long long __a, vector unsigned int __b) { return (vector bool long long)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_sral(vector unsigned long long __a, vector unsigned char __b) { return (vector unsigned long long)__builtin_s390_vsra( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_sral(vector unsigned long long __a, vector unsigned short __b) { return (vector unsigned long long)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_sral(vector unsigned long long __a, vector unsigned int __b) { return (vector unsigned long long)__builtin_s390_vsra( (vector unsigned char)__a, (vector unsigned char)__b); } /*-- vec_srab ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_srab(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed char vec_srab(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_s390_vsrab( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_srab(vector unsigned char __a, vector signed char __b) { return __builtin_s390_vsrab(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_srab(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vsrab(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_srab(vector signed short __a, vector signed short __b) { return (vector signed short)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_srab(vector signed short __a, vector unsigned short __b) { return (vector signed short)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_srab(vector unsigned short __a, vector signed short __b) { return (vector unsigned short)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_srab(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_srab(vector signed int __a, vector signed int __b) { return (vector signed int)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_srab(vector signed int __a, vector unsigned int __b) { return (vector signed int)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_srab(vector unsigned int __a, vector signed int __b) { return (vector unsigned int)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_srab(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_srab(vector signed long long __a, vector signed long long __b) { return (vector signed long long)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_srab(vector signed long long __a, vector unsigned long long __b) { return (vector signed long long)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_srab(vector unsigned long long __a, vector signed long long __b) { return (vector unsigned long long)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_srab(vector unsigned long long __a, vector unsigned long long __b) { return (vector unsigned long long)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector double vec_srab(vector double __a, vector signed long long __b) { return (vector double)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector double vec_srab(vector double __a, vector unsigned long long __b) { return (vector double)__builtin_s390_vsrab( (vector unsigned char)__a, (vector unsigned char)__b); } /*-- vec_srl ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_srl(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed char vec_srl(vector signed char __a, vector unsigned short __b) { return (vector signed char)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed char vec_srl(vector signed char __a, vector unsigned int __b) { return (vector signed char)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool char vec_srl(vector bool char __a, vector unsigned char __b) { return (vector bool char)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool char vec_srl(vector bool char __a, vector unsigned short __b) { return (vector bool char)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool char vec_srl(vector bool char __a, vector unsigned int __b) { return (vector bool char)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_srl(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vsrl(__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_srl(vector unsigned char __a, vector unsigned short __b) { return __builtin_s390_vsrl(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_srl(vector unsigned char __a, vector unsigned int __b) { return __builtin_s390_vsrl(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_srl(vector signed short __a, vector unsigned char __b) { return (vector signed short)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed short vec_srl(vector signed short __a, vector unsigned short __b) { return (vector signed short)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_srl(vector signed short __a, vector unsigned int __b) { return (vector signed short)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool short vec_srl(vector bool short __a, vector unsigned char __b) { return (vector bool short)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool short vec_srl(vector bool short __a, vector unsigned short __b) { return (vector bool short)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool short vec_srl(vector bool short __a, vector unsigned int __b) { return (vector bool short)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_srl(vector unsigned short __a, vector unsigned char __b) { return (vector unsigned short)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_srl(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_srl(vector unsigned short __a, vector unsigned int __b) { return (vector unsigned short)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_srl(vector signed int __a, vector unsigned char __b) { return (vector signed int)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed int vec_srl(vector signed int __a, vector unsigned short __b) { return (vector signed int)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_srl(vector signed int __a, vector unsigned int __b) { return (vector signed int)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool int vec_srl(vector bool int __a, vector unsigned char __b) { return (vector bool int)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool int vec_srl(vector bool int __a, vector unsigned short __b) { return (vector bool int)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool int vec_srl(vector bool int __a, vector unsigned int __b) { return (vector bool int)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_srl(vector unsigned int __a, vector unsigned char __b) { return (vector unsigned int)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_srl(vector unsigned int __a, vector unsigned short __b) { return (vector unsigned int)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_srl(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_srl(vector signed long long __a, vector unsigned char __b) { return (vector signed long long)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector signed long long vec_srl(vector signed long long __a, vector unsigned short __b) { return (vector signed long long)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_srl(vector signed long long __a, vector unsigned int __b) { return (vector signed long long)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool long long vec_srl(vector bool long long __a, vector unsigned char __b) { return (vector bool long long)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector bool long long vec_srl(vector bool long long __a, vector unsigned short __b) { return (vector bool long long)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector bool long long vec_srl(vector bool long long __a, vector unsigned int __b) { return (vector bool long long)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_srl(vector unsigned long long __a, vector unsigned char __b) { return (vector unsigned long long)__builtin_s390_vsrl( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_srl(vector unsigned long long __a, vector unsigned short __b) { return (vector unsigned long long)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_srl(vector unsigned long long __a, vector unsigned int __b) { return (vector unsigned long long)__builtin_s390_vsrl( (vector unsigned char)__a, (vector unsigned char)__b); } /*-- vec_srb ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_srb(vector signed char __a, vector signed char __b) { return (vector signed char)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed char vec_srb(vector signed char __a, vector unsigned char __b) { return (vector signed char)__builtin_s390_vsrlb( (vector unsigned char)__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_srb(vector unsigned char __a, vector signed char __b) { return __builtin_s390_vsrlb(__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_srb(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vsrlb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_srb(vector signed short __a, vector signed short __b) { return (vector signed short)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed short vec_srb(vector signed short __a, vector unsigned short __b) { return (vector signed short)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_srb(vector unsigned short __a, vector signed short __b) { return (vector unsigned short)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned short vec_srb(vector unsigned short __a, vector unsigned short __b) { return (vector unsigned short)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_srb(vector signed int __a, vector signed int __b) { return (vector signed int)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed int vec_srb(vector signed int __a, vector unsigned int __b) { return (vector signed int)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_srb(vector unsigned int __a, vector signed int __b) { return (vector unsigned int)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned int vec_srb(vector unsigned int __a, vector unsigned int __b) { return (vector unsigned int)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_srb(vector signed long long __a, vector signed long long __b) { return (vector signed long long)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector signed long long vec_srb(vector signed long long __a, vector unsigned long long __b) { return (vector signed long long)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_srb(vector unsigned long long __a, vector signed long long __b) { return (vector unsigned long long)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned long long vec_srb(vector unsigned long long __a, vector unsigned long long __b) { return (vector unsigned long long)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector double vec_srb(vector double __a, vector signed long long __b) { return (vector double)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector double vec_srb(vector double __a, vector unsigned long long __b) { return (vector double)__builtin_s390_vsrlb( (vector unsigned char)__a, (vector unsigned char)__b); } /*-- vec_abs ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_abs(vector signed char __a) { return vec_sel(__a, -__a, vec_cmplt(__a, (vector signed char)0)); } static inline __ATTRS_o_ai vector signed short vec_abs(vector signed short __a) { return vec_sel(__a, -__a, vec_cmplt(__a, (vector signed short)0)); } static inline __ATTRS_o_ai vector signed int vec_abs(vector signed int __a) { return vec_sel(__a, -__a, vec_cmplt(__a, (vector signed int)0)); } static inline __ATTRS_o_ai vector signed long long vec_abs(vector signed long long __a) { return vec_sel(__a, -__a, vec_cmplt(__a, (vector signed long long)0)); } static inline __ATTRS_o_ai vector double vec_abs(vector double __a) { return __builtin_s390_vflpdb(__a); } /*-- vec_nabs ---------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_nabs(vector double __a) { return __builtin_s390_vflndb(__a); } /*-- vec_max ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_max(vector signed char __a, vector signed char __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed char vec_max(vector signed char __a, vector bool char __b) { vector signed char __bc = (vector signed char)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed char vec_max(vector bool char __a, vector signed char __b) { vector signed char __ac = (vector signed char)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned char vec_max(vector unsigned char __a, vector unsigned char __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned char vec_max(vector unsigned char __a, vector bool char __b) { vector unsigned char __bc = (vector unsigned char)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned char vec_max(vector bool char __a, vector unsigned char __b) { vector unsigned char __ac = (vector unsigned char)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector signed short vec_max(vector signed short __a, vector signed short __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed short vec_max(vector signed short __a, vector bool short __b) { vector signed short __bc = (vector signed short)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed short vec_max(vector bool short __a, vector signed short __b) { vector signed short __ac = (vector signed short)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned short vec_max(vector unsigned short __a, vector unsigned short __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned short vec_max(vector unsigned short __a, vector bool short __b) { vector unsigned short __bc = (vector unsigned short)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned short vec_max(vector bool short __a, vector unsigned short __b) { vector unsigned short __ac = (vector unsigned short)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector signed int vec_max(vector signed int __a, vector signed int __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed int vec_max(vector signed int __a, vector bool int __b) { vector signed int __bc = (vector signed int)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed int vec_max(vector bool int __a, vector signed int __b) { vector signed int __ac = (vector signed int)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned int vec_max(vector unsigned int __a, vector unsigned int __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned int vec_max(vector unsigned int __a, vector bool int __b) { vector unsigned int __bc = (vector unsigned int)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned int vec_max(vector bool int __a, vector unsigned int __b) { vector unsigned int __ac = (vector unsigned int)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector signed long long vec_max(vector signed long long __a, vector signed long long __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed long long vec_max(vector signed long long __a, vector bool long long __b) { vector signed long long __bc = (vector signed long long)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed long long vec_max(vector bool long long __a, vector signed long long __b) { vector signed long long __ac = (vector signed long long)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned long long vec_max(vector unsigned long long __a, vector unsigned long long __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned long long vec_max(vector unsigned long long __a, vector bool long long __b) { vector unsigned long long __bc = (vector unsigned long long)__b; return vec_sel(__bc, __a, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned long long vec_max(vector bool long long __a, vector unsigned long long __b) { vector unsigned long long __ac = (vector unsigned long long)__a; return vec_sel(__b, __ac, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector double vec_max(vector double __a, vector double __b) { return vec_sel(__b, __a, vec_cmpgt(__a, __b)); } /*-- vec_min ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_min(vector signed char __a, vector signed char __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed char vec_min(vector signed char __a, vector bool char __b) { vector signed char __bc = (vector signed char)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed char vec_min(vector bool char __a, vector signed char __b) { vector signed char __ac = (vector signed char)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned char vec_min(vector unsigned char __a, vector unsigned char __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned char vec_min(vector unsigned char __a, vector bool char __b) { vector unsigned char __bc = (vector unsigned char)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned char vec_min(vector bool char __a, vector unsigned char __b) { vector unsigned char __ac = (vector unsigned char)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector signed short vec_min(vector signed short __a, vector signed short __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed short vec_min(vector signed short __a, vector bool short __b) { vector signed short __bc = (vector signed short)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed short vec_min(vector bool short __a, vector signed short __b) { vector signed short __ac = (vector signed short)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned short vec_min(vector unsigned short __a, vector unsigned short __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned short vec_min(vector unsigned short __a, vector bool short __b) { vector unsigned short __bc = (vector unsigned short)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned short vec_min(vector bool short __a, vector unsigned short __b) { vector unsigned short __ac = (vector unsigned short)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector signed int vec_min(vector signed int __a, vector signed int __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed int vec_min(vector signed int __a, vector bool int __b) { vector signed int __bc = (vector signed int)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed int vec_min(vector bool int __a, vector signed int __b) { vector signed int __ac = (vector signed int)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned int vec_min(vector unsigned int __a, vector unsigned int __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned int vec_min(vector unsigned int __a, vector bool int __b) { vector unsigned int __bc = (vector unsigned int)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned int vec_min(vector bool int __a, vector unsigned int __b) { vector unsigned int __ac = (vector unsigned int)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector signed long long vec_min(vector signed long long __a, vector signed long long __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector signed long long vec_min(vector signed long long __a, vector bool long long __b) { vector signed long long __bc = (vector signed long long)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector signed long long vec_min(vector bool long long __a, vector signed long long __b) { vector signed long long __ac = (vector signed long long)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector unsigned long long vec_min(vector unsigned long long __a, vector unsigned long long __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } static inline __ATTRS_o_ai vector unsigned long long vec_min(vector unsigned long long __a, vector bool long long __b) { vector unsigned long long __bc = (vector unsigned long long)__b; return vec_sel(__a, __bc, vec_cmpgt(__a, __bc)); } static inline __ATTRS_o_ai vector unsigned long long vec_min(vector bool long long __a, vector unsigned long long __b) { vector unsigned long long __ac = (vector unsigned long long)__a; return vec_sel(__ac, __b, vec_cmpgt(__ac, __b)); } static inline __ATTRS_o_ai vector double vec_min(vector double __a, vector double __b) { return vec_sel(__a, __b, vec_cmpgt(__a, __b)); } /*-- vec_add_u128 -----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_add_u128(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vaq(__a, __b); } /*-- vec_addc ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_addc(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vaccb(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_addc(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vacch(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_addc(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vaccf(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_addc(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vaccg(__a, __b); } /*-- vec_addc_u128 ----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_addc_u128(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vaccq(__a, __b); } /*-- vec_adde_u128 ----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_adde_u128(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vacq(__a, __b, __c); } /*-- vec_addec_u128 ---------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_addec_u128(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vacccq(__a, __b, __c); } /*-- vec_avg ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_avg(vector signed char __a, vector signed char __b) { return __builtin_s390_vavgb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_avg(vector signed short __a, vector signed short __b) { return __builtin_s390_vavgh(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_avg(vector signed int __a, vector signed int __b) { return __builtin_s390_vavgf(__a, __b); } static inline __ATTRS_o_ai vector signed long long vec_avg(vector signed long long __a, vector signed long long __b) { return __builtin_s390_vavgg(__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_avg(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vavglb(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_avg(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vavglh(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_avg(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vavglf(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_avg(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vavglg(__a, __b); } /*-- vec_checksum -----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned int vec_checksum(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vcksm(__a, __b); } /*-- vec_gfmsum -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned short vec_gfmsum(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vgfmb(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_gfmsum(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vgfmh(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_gfmsum(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vgfmf(__a, __b); } /*-- vec_gfmsum_128 ---------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_gfmsum_128(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vgfmg(__a, __b); } /*-- vec_gfmsum_accum -------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned short vec_gfmsum_accum(vector unsigned char __a, vector unsigned char __b, vector unsigned short __c) { return __builtin_s390_vgfmab(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned int vec_gfmsum_accum(vector unsigned short __a, vector unsigned short __b, vector unsigned int __c) { return __builtin_s390_vgfmah(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned long long vec_gfmsum_accum(vector unsigned int __a, vector unsigned int __b, vector unsigned long long __c) { return __builtin_s390_vgfmaf(__a, __b, __c); } /*-- vec_gfmsum_accum_128 ---------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_gfmsum_accum_128(vector unsigned long long __a, vector unsigned long long __b, vector unsigned char __c) { return __builtin_s390_vgfmag(__a, __b, __c); } /*-- vec_mladd --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_mladd(vector signed char __a, vector signed char __b, vector signed char __c) { return __a * __b + __c; } static inline __ATTRS_o_ai vector signed char vec_mladd(vector unsigned char __a, vector signed char __b, vector signed char __c) { return (vector signed char)__a * __b + __c; } static inline __ATTRS_o_ai vector signed char vec_mladd(vector signed char __a, vector unsigned char __b, vector unsigned char __c) { return __a * (vector signed char)__b + (vector signed char)__c; } static inline __ATTRS_o_ai vector unsigned char vec_mladd(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __a * __b + __c; } static inline __ATTRS_o_ai vector signed short vec_mladd(vector signed short __a, vector signed short __b, vector signed short __c) { return __a * __b + __c; } static inline __ATTRS_o_ai vector signed short vec_mladd(vector unsigned short __a, vector signed short __b, vector signed short __c) { return (vector signed short)__a * __b + __c; } static inline __ATTRS_o_ai vector signed short vec_mladd(vector signed short __a, vector unsigned short __b, vector unsigned short __c) { return __a * (vector signed short)__b + (vector signed short)__c; } static inline __ATTRS_o_ai vector unsigned short vec_mladd(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __a * __b + __c; } static inline __ATTRS_o_ai vector signed int vec_mladd(vector signed int __a, vector signed int __b, vector signed int __c) { return __a * __b + __c; } static inline __ATTRS_o_ai vector signed int vec_mladd(vector unsigned int __a, vector signed int __b, vector signed int __c) { return (vector signed int)__a * __b + __c; } static inline __ATTRS_o_ai vector signed int vec_mladd(vector signed int __a, vector unsigned int __b, vector unsigned int __c) { return __a * (vector signed int)__b + (vector signed int)__c; } static inline __ATTRS_o_ai vector unsigned int vec_mladd(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return __a * __b + __c; } /*-- vec_mhadd --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_mhadd(vector signed char __a, vector signed char __b, vector signed char __c) { return __builtin_s390_vmahb(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned char vec_mhadd(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vmalhb(__a, __b, __c); } static inline __ATTRS_o_ai vector signed short vec_mhadd(vector signed short __a, vector signed short __b, vector signed short __c) { return __builtin_s390_vmahh(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned short vec_mhadd(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __builtin_s390_vmalhh(__a, __b, __c); } static inline __ATTRS_o_ai vector signed int vec_mhadd(vector signed int __a, vector signed int __b, vector signed int __c) { return __builtin_s390_vmahf(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned int vec_mhadd(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return __builtin_s390_vmalhf(__a, __b, __c); } /*-- vec_meadd --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed short vec_meadd(vector signed char __a, vector signed char __b, vector signed short __c) { return __builtin_s390_vmaeb(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned short vec_meadd(vector unsigned char __a, vector unsigned char __b, vector unsigned short __c) { return __builtin_s390_vmaleb(__a, __b, __c); } static inline __ATTRS_o_ai vector signed int vec_meadd(vector signed short __a, vector signed short __b, vector signed int __c) { return __builtin_s390_vmaeh(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned int vec_meadd(vector unsigned short __a, vector unsigned short __b, vector unsigned int __c) { return __builtin_s390_vmaleh(__a, __b, __c); } static inline __ATTRS_o_ai vector signed long long vec_meadd(vector signed int __a, vector signed int __b, vector signed long long __c) { return __builtin_s390_vmaef(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned long long vec_meadd(vector unsigned int __a, vector unsigned int __b, vector unsigned long long __c) { return __builtin_s390_vmalef(__a, __b, __c); } /*-- vec_moadd --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed short vec_moadd(vector signed char __a, vector signed char __b, vector signed short __c) { return __builtin_s390_vmaob(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned short vec_moadd(vector unsigned char __a, vector unsigned char __b, vector unsigned short __c) { return __builtin_s390_vmalob(__a, __b, __c); } static inline __ATTRS_o_ai vector signed int vec_moadd(vector signed short __a, vector signed short __b, vector signed int __c) { return __builtin_s390_vmaoh(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned int vec_moadd(vector unsigned short __a, vector unsigned short __b, vector unsigned int __c) { return __builtin_s390_vmaloh(__a, __b, __c); } static inline __ATTRS_o_ai vector signed long long vec_moadd(vector signed int __a, vector signed int __b, vector signed long long __c) { return __builtin_s390_vmaof(__a, __b, __c); } static inline __ATTRS_o_ai vector unsigned long long vec_moadd(vector unsigned int __a, vector unsigned int __b, vector unsigned long long __c) { return __builtin_s390_vmalof(__a, __b, __c); } /*-- vec_mulh ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_mulh(vector signed char __a, vector signed char __b) { return __builtin_s390_vmhb(__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_mulh(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vmlhb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_mulh(vector signed short __a, vector signed short __b) { return __builtin_s390_vmhh(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_mulh(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vmlhh(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_mulh(vector signed int __a, vector signed int __b) { return __builtin_s390_vmhf(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_mulh(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vmlhf(__a, __b); } /*-- vec_mule ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed short vec_mule(vector signed char __a, vector signed char __b) { return __builtin_s390_vmeb(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_mule(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vmleb(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_mule(vector signed short __a, vector signed short __b) { return __builtin_s390_vmeh(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_mule(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vmleh(__a, __b); } static inline __ATTRS_o_ai vector signed long long vec_mule(vector signed int __a, vector signed int __b) { return __builtin_s390_vmef(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_mule(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vmlef(__a, __b); } /*-- vec_mulo ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed short vec_mulo(vector signed char __a, vector signed char __b) { return __builtin_s390_vmob(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_mulo(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vmlob(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_mulo(vector signed short __a, vector signed short __b) { return __builtin_s390_vmoh(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_mulo(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vmloh(__a, __b); } static inline __ATTRS_o_ai vector signed long long vec_mulo(vector signed int __a, vector signed int __b) { return __builtin_s390_vmof(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_mulo(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vmlof(__a, __b); } /*-- vec_sub_u128 -----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_sub_u128(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vsq(__a, __b); } /*-- vec_subc ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_subc(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vscbib(__a, __b); } static inline __ATTRS_o_ai vector unsigned short vec_subc(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vscbih(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_subc(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vscbif(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_subc(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vscbig(__a, __b); } /*-- vec_subc_u128 ----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_subc_u128(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vscbiq(__a, __b); } /*-- vec_sube_u128 ----------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_sube_u128(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vsbiq(__a, __b, __c); } /*-- vec_subec_u128 ---------------------------------------------------------*/ static inline __ATTRS_ai vector unsigned char vec_subec_u128(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vsbcbiq(__a, __b, __c); } /*-- vec_sum2 ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned long long vec_sum2(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vsumgh(__a, __b); } static inline __ATTRS_o_ai vector unsigned long long vec_sum2(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vsumgf(__a, __b); } /*-- vec_sum_u128 -----------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_sum_u128(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vsumqf(__a, __b); } static inline __ATTRS_o_ai vector unsigned char vec_sum_u128(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vsumqg(__a, __b); } /*-- vec_sum4 ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned int vec_sum4(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vsumb(__a, __b); } static inline __ATTRS_o_ai vector unsigned int vec_sum4(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vsumh(__a, __b); } /*-- vec_test_mask ----------------------------------------------------------*/ static inline __ATTRS_o_ai int vec_test_mask(vector signed char __a, vector unsigned char __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai int vec_test_mask(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vtm(__a, __b); } static inline __ATTRS_o_ai int vec_test_mask(vector signed short __a, vector unsigned short __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai int vec_test_mask(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai int vec_test_mask(vector signed int __a, vector unsigned int __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai int vec_test_mask(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai int vec_test_mask(vector signed long long __a, vector unsigned long long __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai int vec_test_mask(vector unsigned long long __a, vector unsigned long long __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai int vec_test_mask(vector double __a, vector unsigned long long __b) { return __builtin_s390_vtm((vector unsigned char)__a, (vector unsigned char)__b); } /*-- vec_madd ---------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_madd(vector double __a, vector double __b, vector double __c) { return __builtin_s390_vfmadb(__a, __b, __c); } /*-- vec_msub ---------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_msub(vector double __a, vector double __b, vector double __c) { return __builtin_s390_vfmsdb(__a, __b, __c); } /*-- vec_sqrt ---------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_sqrt(vector double __a) { return __builtin_s390_vfsqdb(__a); } /*-- vec_ld2f ---------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_ld2f(const float *__ptr) { typedef float __v2f32 __attribute__((__vector_size__(8))); return __builtin_convertvector(*(const __v2f32 *)__ptr, vector double); } /*-- vec_st2f ---------------------------------------------------------------*/ static inline __ATTRS_ai void vec_st2f(vector double __a, float *__ptr) { typedef float __v2f32 __attribute__((__vector_size__(8))); *(__v2f32 *)__ptr = __builtin_convertvector(__a, __v2f32); } /*-- vec_ctd ----------------------------------------------------------------*/ static inline __ATTRS_o_ai vector double vec_ctd(vector signed long long __a, int __b) __constant_range(__b, 0, 31) { vector double __conv = __builtin_convertvector(__a, vector double); __conv *= (vector double)(vector unsigned long long)((0x3ffULL - __b) << 52); return __conv; } static inline __ATTRS_o_ai vector double vec_ctd(vector unsigned long long __a, int __b) __constant_range(__b, 0, 31) { vector double __conv = __builtin_convertvector(__a, vector double); __conv *= (vector double)(vector unsigned long long)((0x3ffULL - __b) << 52); return __conv; } /*-- vec_ctsl ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed long long vec_ctsl(vector double __a, int __b) __constant_range(__b, 0, 31) { __a *= (vector double)(vector unsigned long long)((0x3ffULL + __b) << 52); return __builtin_convertvector(__a, vector signed long long); } /*-- vec_ctul ---------------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned long long vec_ctul(vector double __a, int __b) __constant_range(__b, 0, 31) { __a *= (vector double)(vector unsigned long long)((0x3ffULL + __b) << 52); return __builtin_convertvector(__a, vector unsigned long long); } /*-- vec_roundp -------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_roundp(vector double __a) { return __builtin_s390_vfidb(__a, 4, 6); } /*-- vec_ceil ---------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_ceil(vector double __a) { // On this platform, vec_ceil never triggers the IEEE-inexact exception. return __builtin_s390_vfidb(__a, 4, 6); } /*-- vec_roundm -------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_roundm(vector double __a) { return __builtin_s390_vfidb(__a, 4, 7); } /*-- vec_floor --------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_floor(vector double __a) { // On this platform, vec_floor never triggers the IEEE-inexact exception. return __builtin_s390_vfidb(__a, 4, 7); } /*-- vec_roundz -------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_roundz(vector double __a) { return __builtin_s390_vfidb(__a, 4, 5); } /*-- vec_trunc --------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_trunc(vector double __a) { // On this platform, vec_trunc never triggers the IEEE-inexact exception. return __builtin_s390_vfidb(__a, 4, 5); } /*-- vec_roundc -------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_roundc(vector double __a) { return __builtin_s390_vfidb(__a, 4, 0); } /*-- vec_round --------------------------------------------------------------*/ static inline __ATTRS_ai vector double vec_round(vector double __a) { return __builtin_s390_vfidb(__a, 4, 4); } /*-- vec_fp_test_data_class -------------------------------------------------*/ #define vec_fp_test_data_class(X, Y, Z) \ ((vector bool long long)__builtin_s390_vftcidb((X), (Y), (Z))) /*-- vec_cp_until_zero ------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cp_until_zero(vector signed char __a) { return (vector signed char)__builtin_s390_vistrb((vector unsigned char)__a); } static inline __ATTRS_o_ai vector bool char vec_cp_until_zero(vector bool char __a) { return (vector bool char)__builtin_s390_vistrb((vector unsigned char)__a); } static inline __ATTRS_o_ai vector unsigned char vec_cp_until_zero(vector unsigned char __a) { return __builtin_s390_vistrb(__a); } static inline __ATTRS_o_ai vector signed short vec_cp_until_zero(vector signed short __a) { return (vector signed short)__builtin_s390_vistrh((vector unsigned short)__a); } static inline __ATTRS_o_ai vector bool short vec_cp_until_zero(vector bool short __a) { return (vector bool short)__builtin_s390_vistrh((vector unsigned short)__a); } static inline __ATTRS_o_ai vector unsigned short vec_cp_until_zero(vector unsigned short __a) { return __builtin_s390_vistrh(__a); } static inline __ATTRS_o_ai vector signed int vec_cp_until_zero(vector signed int __a) { return (vector signed int)__builtin_s390_vistrf((vector unsigned int)__a); } static inline __ATTRS_o_ai vector bool int vec_cp_until_zero(vector bool int __a) { return (vector bool int)__builtin_s390_vistrf((vector unsigned int)__a); } static inline __ATTRS_o_ai vector unsigned int vec_cp_until_zero(vector unsigned int __a) { return __builtin_s390_vistrf(__a); } /*-- vec_cp_until_zero_cc ---------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cp_until_zero_cc(vector signed char __a, int *__cc) { return (vector signed char) __builtin_s390_vistrbs((vector unsigned char)__a, __cc); } static inline __ATTRS_o_ai vector bool char vec_cp_until_zero_cc(vector bool char __a, int *__cc) { return (vector bool char) __builtin_s390_vistrbs((vector unsigned char)__a, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cp_until_zero_cc(vector unsigned char __a, int *__cc) { return __builtin_s390_vistrbs(__a, __cc); } static inline __ATTRS_o_ai vector signed short vec_cp_until_zero_cc(vector signed short __a, int *__cc) { return (vector signed short) __builtin_s390_vistrhs((vector unsigned short)__a, __cc); } static inline __ATTRS_o_ai vector bool short vec_cp_until_zero_cc(vector bool short __a, int *__cc) { return (vector bool short) __builtin_s390_vistrhs((vector unsigned short)__a, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cp_until_zero_cc(vector unsigned short __a, int *__cc) { return __builtin_s390_vistrhs(__a, __cc); } static inline __ATTRS_o_ai vector signed int vec_cp_until_zero_cc(vector signed int __a, int *__cc) { return (vector signed int) __builtin_s390_vistrfs((vector unsigned int)__a, __cc); } static inline __ATTRS_o_ai vector bool int vec_cp_until_zero_cc(vector bool int __a, int *__cc) { return (vector bool int)__builtin_s390_vistrfs((vector unsigned int)__a, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cp_until_zero_cc(vector unsigned int __a, int *__cc) { return __builtin_s390_vistrfs(__a, __cc); } /*-- vec_cmpeq_idx ----------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpeq_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfeeb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfeeb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfeeb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_cmpeq_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfeeh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfeeh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfeeh(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_cmpeq_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfeef((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfeef((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfeef(__a, __b); } /*-- vec_cmpeq_idx_cc -------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpeq_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfeebs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfeebs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfeebs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed short vec_cmpeq_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfeehs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfeehs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfeehs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed int vec_cmpeq_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfeefs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfeefs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfeefs(__a, __b, __cc); } /*-- vec_cmpeq_or_0_idx -----------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpeq_or_0_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfeezb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_or_0_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfeezb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_or_0_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfeezb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_cmpeq_or_0_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfeezh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_or_0_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfeezh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_or_0_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfeezh(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_cmpeq_or_0_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfeezf((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_or_0_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfeezf((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_or_0_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfeezf(__a, __b); } /*-- vec_cmpeq_or_0_idx_cc --------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpeq_or_0_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfeezbs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_or_0_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfeezbs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpeq_or_0_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfeezbs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed short vec_cmpeq_or_0_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfeezhs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_or_0_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfeezhs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpeq_or_0_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfeezhs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed int vec_cmpeq_or_0_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfeezfs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_or_0_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfeezfs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpeq_or_0_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfeezfs(__a, __b, __cc); } /*-- vec_cmpne_idx ----------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpne_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfeneb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfeneb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfeneb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_cmpne_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfeneh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfeneh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfeneh(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_cmpne_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfenef((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfenef((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfenef(__a, __b); } /*-- vec_cmpne_idx_cc -------------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpne_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfenebs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfenebs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfenebs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed short vec_cmpne_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfenehs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfenehs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfenehs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed int vec_cmpne_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfenefs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfenefs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfenefs(__a, __b, __cc); } /*-- vec_cmpne_or_0_idx -----------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpne_or_0_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfenezb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_or_0_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfenezb((vector unsigned char)__a, (vector unsigned char)__b); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_or_0_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfenezb(__a, __b); } static inline __ATTRS_o_ai vector signed short vec_cmpne_or_0_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfenezh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_or_0_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfenezh((vector unsigned short)__a, (vector unsigned short)__b); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_or_0_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfenezh(__a, __b); } static inline __ATTRS_o_ai vector signed int vec_cmpne_or_0_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfenezf((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_or_0_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfenezf((vector unsigned int)__a, (vector unsigned int)__b); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_or_0_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfenezf(__a, __b); } /*-- vec_cmpne_or_0_idx_cc --------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_cmpne_or_0_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfenezbs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_or_0_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfenezbs((vector unsigned char)__a, (vector unsigned char)__b, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_cmpne_or_0_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfenezbs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed short vec_cmpne_or_0_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfenezhs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_or_0_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfenezhs((vector unsigned short)__a, (vector unsigned short)__b, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpne_or_0_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfenezhs(__a, __b, __cc); } static inline __ATTRS_o_ai vector signed int vec_cmpne_or_0_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfenezfs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_or_0_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfenezfs((vector unsigned int)__a, (vector unsigned int)__b, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpne_or_0_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfenezfs(__a, __b, __cc); } /*-- vec_cmprg --------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmprg(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return (vector bool char)__builtin_s390_vstrcb(__a, __b, __c, 4); } static inline __ATTRS_o_ai vector bool short vec_cmprg(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return (vector bool short)__builtin_s390_vstrch(__a, __b, __c, 4); } static inline __ATTRS_o_ai vector bool int vec_cmprg(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return (vector bool int)__builtin_s390_vstrcf(__a, __b, __c, 4); } /*-- vec_cmprg_cc -----------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmprg_cc(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c, int *__cc) { return (vector bool char)__builtin_s390_vstrcbs(__a, __b, __c, 4, __cc); } static inline __ATTRS_o_ai vector bool short vec_cmprg_cc(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c, int *__cc) { return (vector bool short)__builtin_s390_vstrchs(__a, __b, __c, 4, __cc); } static inline __ATTRS_o_ai vector bool int vec_cmprg_cc(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c, int *__cc) { return (vector bool int)__builtin_s390_vstrcfs(__a, __b, __c, 4, __cc); } /*-- vec_cmprg_idx ----------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmprg_idx(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vstrcb(__a, __b, __c, 0); } static inline __ATTRS_o_ai vector unsigned short vec_cmprg_idx(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __builtin_s390_vstrch(__a, __b, __c, 0); } static inline __ATTRS_o_ai vector unsigned int vec_cmprg_idx(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return __builtin_s390_vstrcf(__a, __b, __c, 0); } /*-- vec_cmprg_idx_cc -------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmprg_idx_cc(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c, int *__cc) { return __builtin_s390_vstrcbs(__a, __b, __c, 0, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmprg_idx_cc(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c, int *__cc) { return __builtin_s390_vstrchs(__a, __b, __c, 0, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmprg_idx_cc(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c, int *__cc) { return __builtin_s390_vstrcfs(__a, __b, __c, 0, __cc); } /*-- vec_cmprg_or_0_idx -----------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmprg_or_0_idx(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vstrczb(__a, __b, __c, 0); } static inline __ATTRS_o_ai vector unsigned short vec_cmprg_or_0_idx(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __builtin_s390_vstrczh(__a, __b, __c, 0); } static inline __ATTRS_o_ai vector unsigned int vec_cmprg_or_0_idx(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return __builtin_s390_vstrczf(__a, __b, __c, 0); } /*-- vec_cmprg_or_0_idx_cc --------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmprg_or_0_idx_cc(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c, int *__cc) { return __builtin_s390_vstrczbs(__a, __b, __c, 0, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmprg_or_0_idx_cc(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c, int *__cc) { return __builtin_s390_vstrczhs(__a, __b, __c, 0, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmprg_or_0_idx_cc(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c, int *__cc) { return __builtin_s390_vstrczfs(__a, __b, __c, 0, __cc); } /*-- vec_cmpnrg -------------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmpnrg(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return (vector bool char)__builtin_s390_vstrcb(__a, __b, __c, 12); } static inline __ATTRS_o_ai vector bool short vec_cmpnrg(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return (vector bool short)__builtin_s390_vstrch(__a, __b, __c, 12); } static inline __ATTRS_o_ai vector bool int vec_cmpnrg(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return (vector bool int)__builtin_s390_vstrcf(__a, __b, __c, 12); } /*-- vec_cmpnrg_cc ----------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_cmpnrg_cc(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c, int *__cc) { return (vector bool char)__builtin_s390_vstrcbs(__a, __b, __c, 12, __cc); } static inline __ATTRS_o_ai vector bool short vec_cmpnrg_cc(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c, int *__cc) { return (vector bool short)__builtin_s390_vstrchs(__a, __b, __c, 12, __cc); } static inline __ATTRS_o_ai vector bool int vec_cmpnrg_cc(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c, int *__cc) { return (vector bool int)__builtin_s390_vstrcfs(__a, __b, __c, 12, __cc); } /*-- vec_cmpnrg_idx ---------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmpnrg_idx(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vstrcb(__a, __b, __c, 8); } static inline __ATTRS_o_ai vector unsigned short vec_cmpnrg_idx(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __builtin_s390_vstrch(__a, __b, __c, 8); } static inline __ATTRS_o_ai vector unsigned int vec_cmpnrg_idx(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return __builtin_s390_vstrcf(__a, __b, __c, 8); } /*-- vec_cmpnrg_idx_cc ------------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmpnrg_idx_cc(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c, int *__cc) { return __builtin_s390_vstrcbs(__a, __b, __c, 8, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpnrg_idx_cc(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c, int *__cc) { return __builtin_s390_vstrchs(__a, __b, __c, 8, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpnrg_idx_cc(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c, int *__cc) { return __builtin_s390_vstrcfs(__a, __b, __c, 8, __cc); } /*-- vec_cmpnrg_or_0_idx ----------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmpnrg_or_0_idx(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c) { return __builtin_s390_vstrczb(__a, __b, __c, 8); } static inline __ATTRS_o_ai vector unsigned short vec_cmpnrg_or_0_idx(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c) { return __builtin_s390_vstrczh(__a, __b, __c, 8); } static inline __ATTRS_o_ai vector unsigned int vec_cmpnrg_or_0_idx(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c) { return __builtin_s390_vstrczf(__a, __b, __c, 8); } /*-- vec_cmpnrg_or_0_idx_cc -------------------------------------------------*/ static inline __ATTRS_o_ai vector unsigned char vec_cmpnrg_or_0_idx_cc(vector unsigned char __a, vector unsigned char __b, vector unsigned char __c, int *__cc) { return __builtin_s390_vstrczbs(__a, __b, __c, 8, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_cmpnrg_or_0_idx_cc(vector unsigned short __a, vector unsigned short __b, vector unsigned short __c, int *__cc) { return __builtin_s390_vstrczhs(__a, __b, __c, 8, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_cmpnrg_or_0_idx_cc(vector unsigned int __a, vector unsigned int __b, vector unsigned int __c, int *__cc) { return __builtin_s390_vstrczfs(__a, __b, __c, 8, __cc); } /*-- vec_find_any_eq --------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_find_any_eq(vector signed char __a, vector signed char __b) { return (vector bool char) __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 4); } static inline __ATTRS_o_ai vector bool char vec_find_any_eq(vector bool char __a, vector bool char __b) { return (vector bool char) __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 4); } static inline __ATTRS_o_ai vector bool char vec_find_any_eq(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)__builtin_s390_vfaeb(__a, __b, 4); } static inline __ATTRS_o_ai vector bool short vec_find_any_eq(vector signed short __a, vector signed short __b) { return (vector bool short) __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 4); } static inline __ATTRS_o_ai vector bool short vec_find_any_eq(vector bool short __a, vector bool short __b) { return (vector bool short) __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 4); } static inline __ATTRS_o_ai vector bool short vec_find_any_eq(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)__builtin_s390_vfaeh(__a, __b, 4); } static inline __ATTRS_o_ai vector bool int vec_find_any_eq(vector signed int __a, vector signed int __b) { return (vector bool int) __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 4); } static inline __ATTRS_o_ai vector bool int vec_find_any_eq(vector bool int __a, vector bool int __b) { return (vector bool int) __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 4); } static inline __ATTRS_o_ai vector bool int vec_find_any_eq(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)__builtin_s390_vfaef(__a, __b, 4); } /*-- vec_find_any_eq_cc -----------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_find_any_eq_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector bool char) __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 4, __cc); } static inline __ATTRS_o_ai vector bool char vec_find_any_eq_cc(vector bool char __a, vector bool char __b, int *__cc) { return (vector bool char) __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 4, __cc); } static inline __ATTRS_o_ai vector bool char vec_find_any_eq_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return (vector bool char)__builtin_s390_vfaebs(__a, __b, 4, __cc); } static inline __ATTRS_o_ai vector bool short vec_find_any_eq_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector bool short) __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 4, __cc); } static inline __ATTRS_o_ai vector bool short vec_find_any_eq_cc(vector bool short __a, vector bool short __b, int *__cc) { return (vector bool short) __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 4, __cc); } static inline __ATTRS_o_ai vector bool short vec_find_any_eq_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return (vector bool short)__builtin_s390_vfaehs(__a, __b, 4, __cc); } static inline __ATTRS_o_ai vector bool int vec_find_any_eq_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector bool int) __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 4, __cc); } static inline __ATTRS_o_ai vector bool int vec_find_any_eq_cc(vector bool int __a, vector bool int __b, int *__cc) { return (vector bool int) __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 4, __cc); } static inline __ATTRS_o_ai vector bool int vec_find_any_eq_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return (vector bool int)__builtin_s390_vfaefs(__a, __b, 4, __cc); } /*-- vec_find_any_eq_idx ----------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_eq_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 0); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 0); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfaeb(__a, __b, 0); } static inline __ATTRS_o_ai vector signed short vec_find_any_eq_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 0); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 0); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfaeh(__a, __b, 0); } static inline __ATTRS_o_ai vector signed int vec_find_any_eq_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 0); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 0); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfaef(__a, __b, 0); } /*-- vec_find_any_eq_idx_cc -------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_eq_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfaebs(__a, __b, 0, __cc); } static inline __ATTRS_o_ai vector signed short vec_find_any_eq_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfaehs(__a, __b, 0, __cc); } static inline __ATTRS_o_ai vector signed int vec_find_any_eq_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfaefs(__a, __b, 0, __cc); } /*-- vec_find_any_eq_or_0_idx -----------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_eq_or_0_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfaezb((vector unsigned char)__a, (vector unsigned char)__b, 0); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_or_0_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfaezb((vector unsigned char)__a, (vector unsigned char)__b, 0); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_or_0_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfaezb(__a, __b, 0); } static inline __ATTRS_o_ai vector signed short vec_find_any_eq_or_0_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfaezh((vector unsigned short)__a, (vector unsigned short)__b, 0); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_or_0_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfaezh((vector unsigned short)__a, (vector unsigned short)__b, 0); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_or_0_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfaezh(__a, __b, 0); } static inline __ATTRS_o_ai vector signed int vec_find_any_eq_or_0_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfaezf((vector unsigned int)__a, (vector unsigned int)__b, 0); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_or_0_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfaezf((vector unsigned int)__a, (vector unsigned int)__b, 0); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_or_0_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfaezf(__a, __b, 0); } /*-- vec_find_any_eq_or_0_idx_cc --------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_eq_or_0_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfaezbs((vector unsigned char)__a, (vector unsigned char)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_or_0_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfaezbs((vector unsigned char)__a, (vector unsigned char)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_eq_or_0_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfaezbs(__a, __b, 0, __cc); } static inline __ATTRS_o_ai vector signed short vec_find_any_eq_or_0_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfaezhs((vector unsigned short)__a, (vector unsigned short)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_or_0_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfaezhs((vector unsigned short)__a, (vector unsigned short)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_eq_or_0_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfaezhs(__a, __b, 0, __cc); } static inline __ATTRS_o_ai vector signed int vec_find_any_eq_or_0_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfaezfs((vector unsigned int)__a, (vector unsigned int)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_or_0_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfaezfs((vector unsigned int)__a, (vector unsigned int)__b, 0, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_eq_or_0_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfaezfs(__a, __b, 0, __cc); } /*-- vec_find_any_ne --------------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_find_any_ne(vector signed char __a, vector signed char __b) { return (vector bool char) __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 12); } static inline __ATTRS_o_ai vector bool char vec_find_any_ne(vector bool char __a, vector bool char __b) { return (vector bool char) __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 12); } static inline __ATTRS_o_ai vector bool char vec_find_any_ne(vector unsigned char __a, vector unsigned char __b) { return (vector bool char)__builtin_s390_vfaeb(__a, __b, 12); } static inline __ATTRS_o_ai vector bool short vec_find_any_ne(vector signed short __a, vector signed short __b) { return (vector bool short) __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 12); } static inline __ATTRS_o_ai vector bool short vec_find_any_ne(vector bool short __a, vector bool short __b) { return (vector bool short) __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 12); } static inline __ATTRS_o_ai vector bool short vec_find_any_ne(vector unsigned short __a, vector unsigned short __b) { return (vector bool short)__builtin_s390_vfaeh(__a, __b, 12); } static inline __ATTRS_o_ai vector bool int vec_find_any_ne(vector signed int __a, vector signed int __b) { return (vector bool int) __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 12); } static inline __ATTRS_o_ai vector bool int vec_find_any_ne(vector bool int __a, vector bool int __b) { return (vector bool int) __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 12); } static inline __ATTRS_o_ai vector bool int vec_find_any_ne(vector unsigned int __a, vector unsigned int __b) { return (vector bool int)__builtin_s390_vfaef(__a, __b, 12); } /*-- vec_find_any_ne_cc -----------------------------------------------------*/ static inline __ATTRS_o_ai vector bool char vec_find_any_ne_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector bool char) __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 12, __cc); } static inline __ATTRS_o_ai vector bool char vec_find_any_ne_cc(vector bool char __a, vector bool char __b, int *__cc) { return (vector bool char) __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 12, __cc); } static inline __ATTRS_o_ai vector bool char vec_find_any_ne_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return (vector bool char)__builtin_s390_vfaebs(__a, __b, 12, __cc); } static inline __ATTRS_o_ai vector bool short vec_find_any_ne_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector bool short) __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 12, __cc); } static inline __ATTRS_o_ai vector bool short vec_find_any_ne_cc(vector bool short __a, vector bool short __b, int *__cc) { return (vector bool short) __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 12, __cc); } static inline __ATTRS_o_ai vector bool short vec_find_any_ne_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return (vector bool short)__builtin_s390_vfaehs(__a, __b, 12, __cc); } static inline __ATTRS_o_ai vector bool int vec_find_any_ne_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector bool int) __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 12, __cc); } static inline __ATTRS_o_ai vector bool int vec_find_any_ne_cc(vector bool int __a, vector bool int __b, int *__cc) { return (vector bool int) __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 12, __cc); } static inline __ATTRS_o_ai vector bool int vec_find_any_ne_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return (vector bool int)__builtin_s390_vfaefs(__a, __b, 12, __cc); } /*-- vec_find_any_ne_idx ----------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_ne_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 8); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfaeb((vector unsigned char)__a, (vector unsigned char)__b, 8); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfaeb(__a, __b, 8); } static inline __ATTRS_o_ai vector signed short vec_find_any_ne_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 8); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfaeh((vector unsigned short)__a, (vector unsigned short)__b, 8); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfaeh(__a, __b, 8); } static inline __ATTRS_o_ai vector signed int vec_find_any_ne_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 8); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfaef((vector unsigned int)__a, (vector unsigned int)__b, 8); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfaef(__a, __b, 8); } /*-- vec_find_any_ne_idx_cc -------------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_ne_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfaebs((vector unsigned char)__a, (vector unsigned char)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfaebs(__a, __b, 8, __cc); } static inline __ATTRS_o_ai vector signed short vec_find_any_ne_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfaehs((vector unsigned short)__a, (vector unsigned short)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfaehs(__a, __b, 8, __cc); } static inline __ATTRS_o_ai vector signed int vec_find_any_ne_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfaefs((vector unsigned int)__a, (vector unsigned int)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfaefs(__a, __b, 8, __cc); } /*-- vec_find_any_ne_or_0_idx -----------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_ne_or_0_idx(vector signed char __a, vector signed char __b) { return (vector signed char) __builtin_s390_vfaezb((vector unsigned char)__a, (vector unsigned char)__b, 8); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_or_0_idx(vector bool char __a, vector bool char __b) { return __builtin_s390_vfaezb((vector unsigned char)__a, (vector unsigned char)__b, 8); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_or_0_idx(vector unsigned char __a, vector unsigned char __b) { return __builtin_s390_vfaezb(__a, __b, 8); } static inline __ATTRS_o_ai vector signed short vec_find_any_ne_or_0_idx(vector signed short __a, vector signed short __b) { return (vector signed short) __builtin_s390_vfaezh((vector unsigned short)__a, (vector unsigned short)__b, 8); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_or_0_idx(vector bool short __a, vector bool short __b) { return __builtin_s390_vfaezh((vector unsigned short)__a, (vector unsigned short)__b, 8); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_or_0_idx(vector unsigned short __a, vector unsigned short __b) { return __builtin_s390_vfaezh(__a, __b, 8); } static inline __ATTRS_o_ai vector signed int vec_find_any_ne_or_0_idx(vector signed int __a, vector signed int __b) { return (vector signed int) __builtin_s390_vfaezf((vector unsigned int)__a, (vector unsigned int)__b, 8); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_or_0_idx(vector bool int __a, vector bool int __b) { return __builtin_s390_vfaezf((vector unsigned int)__a, (vector unsigned int)__b, 8); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_or_0_idx(vector unsigned int __a, vector unsigned int __b) { return __builtin_s390_vfaezf(__a, __b, 8); } /*-- vec_find_any_ne_or_0_idx_cc --------------------------------------------*/ static inline __ATTRS_o_ai vector signed char vec_find_any_ne_or_0_idx_cc(vector signed char __a, vector signed char __b, int *__cc) { return (vector signed char) __builtin_s390_vfaezbs((vector unsigned char)__a, (vector unsigned char)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_or_0_idx_cc(vector bool char __a, vector bool char __b, int *__cc) { return __builtin_s390_vfaezbs((vector unsigned char)__a, (vector unsigned char)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned char vec_find_any_ne_or_0_idx_cc(vector unsigned char __a, vector unsigned char __b, int *__cc) { return __builtin_s390_vfaezbs(__a, __b, 8, __cc); } static inline __ATTRS_o_ai vector signed short vec_find_any_ne_or_0_idx_cc(vector signed short __a, vector signed short __b, int *__cc) { return (vector signed short) __builtin_s390_vfaezhs((vector unsigned short)__a, (vector unsigned short)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_or_0_idx_cc(vector bool short __a, vector bool short __b, int *__cc) { return __builtin_s390_vfaezhs((vector unsigned short)__a, (vector unsigned short)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned short vec_find_any_ne_or_0_idx_cc(vector unsigned short __a, vector unsigned short __b, int *__cc) { return __builtin_s390_vfaezhs(__a, __b, 8, __cc); } static inline __ATTRS_o_ai vector signed int vec_find_any_ne_or_0_idx_cc(vector signed int __a, vector signed int __b, int *__cc) { return (vector signed int) __builtin_s390_vfaezfs((vector unsigned int)__a, (vector unsigned int)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_or_0_idx_cc(vector bool int __a, vector bool int __b, int *__cc) { return __builtin_s390_vfaezfs((vector unsigned int)__a, (vector unsigned int)__b, 8, __cc); } static inline __ATTRS_o_ai vector unsigned int vec_find_any_ne_or_0_idx_cc(vector unsigned int __a, vector unsigned int __b, int *__cc) { return __builtin_s390_vfaezfs(__a, __b, 8, __cc); } #undef __constant_pow2_range #undef __constant_range #undef __constant #undef __ATTRS_o #undef __ATTRS_o_ai #undef __ATTRS_ai #else #error "Use -fzvector to enable vector extensions" #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/stdint.h
/*===---- stdint.h - Standard header for sized integer types --------------===*\ * * Copyright (c) 2009 Chris Lattner * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * \*===----------------------------------------------------------------------===*/ #ifndef __CLANG_STDINT_H #define __CLANG_STDINT_H /* If we're hosted, fall back to the system's stdint.h, which might have * additional definitions. */ #if __STDC_HOSTED__ && __has_include_next(<stdint.h>) // C99 7.18.3 Limits of other integer types // // Footnote 219, 220: C++ implementations should define these macros only when // __STDC_LIMIT_MACROS is defined before <stdint.h> is included. // // Footnote 222: C++ implementations should define these macros only when // __STDC_CONSTANT_MACROS is defined before <stdint.h> is included. // // C++11 [cstdint.syn]p2: // // The macros defined by <cstdint> are provided unconditionally. In particular, // the symbols __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS (mentioned in // footnotes 219, 220, and 222 in the C standard) play no role in C++. // // C11 removed the problematic footnotes. // // Work around this inconsistency by always defining those macros in C++ mode, // so that a C library implementation which follows the C99 standard can be // used in C++. # ifdef __cplusplus # if !defined(__STDC_LIMIT_MACROS) # define __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS_DEFINED_BY_CLANG # endif # if !defined(__STDC_CONSTANT_MACROS) # define __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG # endif # endif # include_next <stdint.h> # ifdef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG # undef __STDC_LIMIT_MACROS # undef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG # endif # ifdef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG # undef __STDC_CONSTANT_MACROS # undef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG # endif #else /* C99 7.18.1.1 Exact-width integer types. * C99 7.18.1.2 Minimum-width integer types. * C99 7.18.1.3 Fastest minimum-width integer types. * * The standard requires that exact-width type be defined for 8-, 16-, 32-, and * 64-bit types if they are implemented. Other exact width types are optional. * This implementation defines an exact-width types for every integer width * that is represented in the standard integer types. * * The standard also requires minimum-width types be defined for 8-, 16-, 32-, * and 64-bit widths regardless of whether there are corresponding exact-width * types. * * To accommodate targets that are missing types that are exactly 8, 16, 32, or * 64 bits wide, this implementation takes an approach of cascading * redefintions, redefining __int_leastN_t to successively smaller exact-width * types. It is therefore important that the types are defined in order of * descending widths. * * We currently assume that the minimum-width types and the fastest * minimum-width types are the same. This is allowed by the standard, but is * suboptimal. * * In violation of the standard, some targets do not implement a type that is * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit). * To accommodate these targets, a required minimum-width type is only * defined if there exists an exact-width type of equal or greater width. */ #ifdef __INT64_TYPE__ # ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/ typedef __INT64_TYPE__ int64_t; # endif /* __int8_t_defined */ typedef __UINT64_TYPE__ uint64_t; # define __int_least64_t int64_t # define __uint_least64_t uint64_t # define __int_least32_t int64_t # define __uint_least32_t uint64_t # define __int_least16_t int64_t # define __uint_least16_t uint64_t # define __int_least8_t int64_t # define __uint_least8_t uint64_t #endif /* __INT64_TYPE__ */ #ifdef __int_least64_t typedef __int_least64_t int_least64_t; typedef __uint_least64_t uint_least64_t; typedef __int_least64_t int_fast64_t; typedef __uint_least64_t uint_fast64_t; #endif /* __int_least64_t */ #ifdef __INT56_TYPE__ typedef __INT56_TYPE__ int56_t; typedef __UINT56_TYPE__ uint56_t; typedef int56_t int_least56_t; typedef uint56_t uint_least56_t; typedef int56_t int_fast56_t; typedef uint56_t uint_fast56_t; # define __int_least32_t int56_t # define __uint_least32_t uint56_t # define __int_least16_t int56_t # define __uint_least16_t uint56_t # define __int_least8_t int56_t # define __uint_least8_t uint56_t #endif /* __INT56_TYPE__ */ #ifdef __INT48_TYPE__ typedef __INT48_TYPE__ int48_t; typedef __UINT48_TYPE__ uint48_t; typedef int48_t int_least48_t; typedef uint48_t uint_least48_t; typedef int48_t int_fast48_t; typedef uint48_t uint_fast48_t; # define __int_least32_t int48_t # define __uint_least32_t uint48_t # define __int_least16_t int48_t # define __uint_least16_t uint48_t # define __int_least8_t int48_t # define __uint_least8_t uint48_t #endif /* __INT48_TYPE__ */ #ifdef __INT40_TYPE__ typedef __INT40_TYPE__ int40_t; typedef __UINT40_TYPE__ uint40_t; typedef int40_t int_least40_t; typedef uint40_t uint_least40_t; typedef int40_t int_fast40_t; typedef uint40_t uint_fast40_t; # define __int_least32_t int40_t # define __uint_least32_t uint40_t # define __int_least16_t int40_t # define __uint_least16_t uint40_t # define __int_least8_t int40_t # define __uint_least8_t uint40_t #endif /* __INT40_TYPE__ */ #ifdef __INT32_TYPE__ # ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/ typedef __INT32_TYPE__ int32_t; # endif /* __int8_t_defined */ # ifndef __uint32_t_defined /* more glibc compatibility */ # define __uint32_t_defined typedef __UINT32_TYPE__ uint32_t; # endif /* __uint32_t_defined */ # define __int_least32_t int32_t # define __uint_least32_t uint32_t # define __int_least16_t int32_t # define __uint_least16_t uint32_t # define __int_least8_t int32_t # define __uint_least8_t uint32_t #endif /* __INT32_TYPE__ */ #ifdef __int_least32_t typedef __int_least32_t int_least32_t; typedef __uint_least32_t uint_least32_t; typedef __int_least32_t int_fast32_t; typedef __uint_least32_t uint_fast32_t; #endif /* __int_least32_t */ #ifdef __INT24_TYPE__ typedef __INT24_TYPE__ int24_t; typedef __UINT24_TYPE__ uint24_t; typedef int24_t int_least24_t; typedef uint24_t uint_least24_t; typedef int24_t int_fast24_t; typedef uint24_t uint_fast24_t; # define __int_least16_t int24_t # define __uint_least16_t uint24_t # define __int_least8_t int24_t # define __uint_least8_t uint24_t #endif /* __INT24_TYPE__ */ #ifdef __INT16_TYPE__ #ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/ typedef __INT16_TYPE__ int16_t; #endif /* __int8_t_defined */ typedef __UINT16_TYPE__ uint16_t; # define __int_least16_t int16_t # define __uint_least16_t uint16_t # define __int_least8_t int16_t # define __uint_least8_t uint16_t #endif /* __INT16_TYPE__ */ #ifdef __int_least16_t typedef __int_least16_t int_least16_t; typedef __uint_least16_t uint_least16_t; typedef __int_least16_t int_fast16_t; typedef __uint_least16_t uint_fast16_t; #endif /* __int_least16_t */ #ifdef __INT8_TYPE__ #ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/ typedef __INT8_TYPE__ int8_t; #endif /* __int8_t_defined */ typedef __UINT8_TYPE__ uint8_t; # define __int_least8_t int8_t # define __uint_least8_t uint8_t #endif /* __INT8_TYPE__ */ #ifdef __int_least8_t typedef __int_least8_t int_least8_t; typedef __uint_least8_t uint_least8_t; typedef __int_least8_t int_fast8_t; typedef __uint_least8_t uint_fast8_t; #endif /* __int_least8_t */ /* prevent glibc sys/types.h from defining conflicting types */ #ifndef __int8_t_defined # define __int8_t_defined #endif /* __int8_t_defined */ /* C99 7.18.1.4 Integer types capable of holding object pointers. */ #define __stdint_join3(a,b,c) a ## b ## c #define __intn_t(n) __stdint_join3( int, n, _t) #define __uintn_t(n) __stdint_join3(uint, n, _t) #ifndef _INTPTR_T #ifndef __intptr_t_defined typedef __intn_t(__INTPTR_WIDTH__) intptr_t; #define __intptr_t_defined #define _INTPTR_T #endif #endif #ifndef _UINTPTR_T typedef __uintn_t(__INTPTR_WIDTH__) uintptr_t; #define _UINTPTR_T #endif /* C99 7.18.1.5 Greatest-width integer types. */ typedef __INTMAX_TYPE__ intmax_t; typedef __UINTMAX_TYPE__ uintmax_t; /* C99 7.18.4 Macros for minimum-width integer constants. * * The standard requires that integer constant macros be defined for all the * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width * types are required, the corresponding integer constant macros are defined * here. This implementation also defines minimum-width types for every other * integer width that the target implements, so corresponding macros are * defined below, too. * * These macros are defined using the same successive-shrinking approach as * the type definitions above. It is likewise important that macros are defined * in order of decending width. * * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). */ #define __int_c_join(a, b) a ## b #define __int_c(v, suffix) __int_c_join(v, suffix) #define __uint_c(v, suffix) __int_c_join(v##U, suffix) #ifdef __INT64_TYPE__ # ifdef __INT64_C_SUFFIX__ # define __int64_c_suffix __INT64_C_SUFFIX__ # define __int32_c_suffix __INT64_C_SUFFIX__ # define __int16_c_suffix __INT64_C_SUFFIX__ # define __int8_c_suffix __INT64_C_SUFFIX__ # else # undef __int64_c_suffix # undef __int32_c_suffix # undef __int16_c_suffix # undef __int8_c_suffix # endif /* __INT64_C_SUFFIX__ */ #endif /* __INT64_TYPE__ */ #ifdef __int_least64_t # ifdef __int64_c_suffix # define INT64_C(v) __int_c(v, __int64_c_suffix) # define UINT64_C(v) __uint_c(v, __int64_c_suffix) # else # define INT64_C(v) v # define UINT64_C(v) v ## U # endif /* __int64_c_suffix */ #endif /* __int_least64_t */ #ifdef __INT56_TYPE__ # ifdef __INT56_C_SUFFIX__ # define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__) # define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__) # define __int32_c_suffix __INT56_C_SUFFIX__ # define __int16_c_suffix __INT56_C_SUFFIX__ # define __int8_c_suffix __INT56_C_SUFFIX__ # else # define INT56_C(v) v # define UINT56_C(v) v ## U # undef __int32_c_suffix # undef __int16_c_suffix # undef __int8_c_suffix # endif /* __INT56_C_SUFFIX__ */ #endif /* __INT56_TYPE__ */ #ifdef __INT48_TYPE__ # ifdef __INT48_C_SUFFIX__ # define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__) # define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__) # define __int32_c_suffix __INT48_C_SUFFIX__ # define __int16_c_suffix __INT48_C_SUFFIX__ # define __int8_c_suffix __INT48_C_SUFFIX__ # else # define INT48_C(v) v # define UINT48_C(v) v ## U # undef __int32_c_suffix # undef __int16_c_suffix # undef __int8_c_suffix # endif /* __INT48_C_SUFFIX__ */ #endif /* __INT48_TYPE__ */ #ifdef __INT40_TYPE__ # ifdef __INT40_C_SUFFIX__ # define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__) # define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__) # define __int32_c_suffix __INT40_C_SUFFIX__ # define __int16_c_suffix __INT40_C_SUFFIX__ # define __int8_c_suffix __INT40_C_SUFFIX__ # else # define INT40_C(v) v # define UINT40_C(v) v ## U # undef __int32_c_suffix # undef __int16_c_suffix # undef __int8_c_suffix # endif /* __INT40_C_SUFFIX__ */ #endif /* __INT40_TYPE__ */ #ifdef __INT32_TYPE__ # ifdef __INT32_C_SUFFIX__ # define __int32_c_suffix __INT32_C_SUFFIX__ # define __int16_c_suffix __INT32_C_SUFFIX__ # define __int8_c_suffix __INT32_C_SUFFIX__ #else # undef __int32_c_suffix # undef __int16_c_suffix # undef __int8_c_suffix # endif /* __INT32_C_SUFFIX__ */ #endif /* __INT32_TYPE__ */ #ifdef __int_least32_t # ifdef __int32_c_suffix # define INT32_C(v) __int_c(v, __int32_c_suffix) # define UINT32_C(v) __uint_c(v, __int32_c_suffix) # else # define INT32_C(v) v # define UINT32_C(v) v ## U # endif /* __int32_c_suffix */ #endif /* __int_least32_t */ #ifdef __INT24_TYPE__ # ifdef __INT24_C_SUFFIX__ # define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__) # define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__) # define __int16_c_suffix __INT24_C_SUFFIX__ # define __int8_c_suffix __INT24_C_SUFFIX__ # else # define INT24_C(v) v # define UINT24_C(v) v ## U # undef __int16_c_suffix # undef __int8_c_suffix # endif /* __INT24_C_SUFFIX__ */ #endif /* __INT24_TYPE__ */ #ifdef __INT16_TYPE__ # ifdef __INT16_C_SUFFIX__ # define __int16_c_suffix __INT16_C_SUFFIX__ # define __int8_c_suffix __INT16_C_SUFFIX__ #else # undef __int16_c_suffix # undef __int8_c_suffix # endif /* __INT16_C_SUFFIX__ */ #endif /* __INT16_TYPE__ */ #ifdef __int_least16_t # ifdef __int16_c_suffix # define INT16_C(v) __int_c(v, __int16_c_suffix) # define UINT16_C(v) __uint_c(v, __int16_c_suffix) # else # define INT16_C(v) v # define UINT16_C(v) v ## U # endif /* __int16_c_suffix */ #endif /* __int_least16_t */ #ifdef __INT8_TYPE__ # ifdef __INT8_C_SUFFIX__ # define __int8_c_suffix __INT8_C_SUFFIX__ #else # undef __int8_c_suffix # endif /* __INT8_C_SUFFIX__ */ #endif /* __INT8_TYPE__ */ #ifdef __int_least8_t # ifdef __int8_c_suffix # define INT8_C(v) __int_c(v, __int8_c_suffix) # define UINT8_C(v) __uint_c(v, __int8_c_suffix) # else # define INT8_C(v) v # define UINT8_C(v) v ## U # endif /* __int8_c_suffix */ #endif /* __int_least8_t */ /* C99 7.18.2.1 Limits of exact-width integer types. * C99 7.18.2.2 Limits of minimum-width integer types. * C99 7.18.2.3 Limits of fastest minimum-width integer types. * * The presence of limit macros are completely optional in C99. This * implementation defines limits for all of the types (exact- and * minimum-width) that it defines above, using the limits of the minimum-width * type for any types that do not have exact-width representations. * * As in the type definitions, this section takes an approach of * successive-shrinking to determine which limits to use for the standard (8, * 16, 32, 64) bit widths when they don't have exact representations. It is * therefore important that the defintions be kept in order of decending * widths. * * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). */ #ifdef __INT64_TYPE__ # define INT64_MAX INT64_C( 9223372036854775807) # define INT64_MIN (-INT64_C( 9223372036854775807)-1) # define UINT64_MAX UINT64_C(18446744073709551615) # define __INT_LEAST64_MIN INT64_MIN # define __INT_LEAST64_MAX INT64_MAX # define __UINT_LEAST64_MAX UINT64_MAX # define __INT_LEAST32_MIN INT64_MIN # define __INT_LEAST32_MAX INT64_MAX # define __UINT_LEAST32_MAX UINT64_MAX # define __INT_LEAST16_MIN INT64_MIN # define __INT_LEAST16_MAX INT64_MAX # define __UINT_LEAST16_MAX UINT64_MAX # define __INT_LEAST8_MIN INT64_MIN # define __INT_LEAST8_MAX INT64_MAX # define __UINT_LEAST8_MAX UINT64_MAX #endif /* __INT64_TYPE__ */ #ifdef __INT_LEAST64_MIN # define INT_LEAST64_MIN __INT_LEAST64_MIN # define INT_LEAST64_MAX __INT_LEAST64_MAX # define UINT_LEAST64_MAX __UINT_LEAST64_MAX # define INT_FAST64_MIN __INT_LEAST64_MIN # define INT_FAST64_MAX __INT_LEAST64_MAX # define UINT_FAST64_MAX __UINT_LEAST64_MAX #endif /* __INT_LEAST64_MIN */ #ifdef __INT56_TYPE__ # define INT56_MAX INT56_C(36028797018963967) # define INT56_MIN (-INT56_C(36028797018963967)-1) # define UINT56_MAX UINT56_C(72057594037927935) # define INT_LEAST56_MIN INT56_MIN # define INT_LEAST56_MAX INT56_MAX # define UINT_LEAST56_MAX UINT56_MAX # define INT_FAST56_MIN INT56_MIN # define INT_FAST56_MAX INT56_MAX # define UINT_FAST56_MAX UINT56_MAX # define __INT_LEAST32_MIN INT56_MIN # define __INT_LEAST32_MAX INT56_MAX # define __UINT_LEAST32_MAX UINT56_MAX # define __INT_LEAST16_MIN INT56_MIN # define __INT_LEAST16_MAX INT56_MAX # define __UINT_LEAST16_MAX UINT56_MAX # define __INT_LEAST8_MIN INT56_MIN # define __INT_LEAST8_MAX INT56_MAX # define __UINT_LEAST8_MAX UINT56_MAX #endif /* __INT56_TYPE__ */ #ifdef __INT48_TYPE__ # define INT48_MAX INT48_C(140737488355327) # define INT48_MIN (-INT48_C(140737488355327)-1) # define UINT48_MAX UINT48_C(281474976710655) # define INT_LEAST48_MIN INT48_MIN # define INT_LEAST48_MAX INT48_MAX # define UINT_LEAST48_MAX UINT48_MAX # define INT_FAST48_MIN INT48_MIN # define INT_FAST48_MAX INT48_MAX # define UINT_FAST48_MAX UINT48_MAX # define __INT_LEAST32_MIN INT48_MIN # define __INT_LEAST32_MAX INT48_MAX # define __UINT_LEAST32_MAX UINT48_MAX # define __INT_LEAST16_MIN INT48_MIN # define __INT_LEAST16_MAX INT48_MAX # define __UINT_LEAST16_MAX UINT48_MAX # define __INT_LEAST8_MIN INT48_MIN # define __INT_LEAST8_MAX INT48_MAX # define __UINT_LEAST8_MAX UINT48_MAX #endif /* __INT48_TYPE__ */ #ifdef __INT40_TYPE__ # define INT40_MAX INT40_C(549755813887) # define INT40_MIN (-INT40_C(549755813887)-1) # define UINT40_MAX UINT40_C(1099511627775) # define INT_LEAST40_MIN INT40_MIN # define INT_LEAST40_MAX INT40_MAX # define UINT_LEAST40_MAX UINT40_MAX # define INT_FAST40_MIN INT40_MIN # define INT_FAST40_MAX INT40_MAX # define UINT_FAST40_MAX UINT40_MAX # define __INT_LEAST32_MIN INT40_MIN # define __INT_LEAST32_MAX INT40_MAX # define __UINT_LEAST32_MAX UINT40_MAX # define __INT_LEAST16_MIN INT40_MIN # define __INT_LEAST16_MAX INT40_MAX # define __UINT_LEAST16_MAX UINT40_MAX # define __INT_LEAST8_MIN INT40_MIN # define __INT_LEAST8_MAX INT40_MAX # define __UINT_LEAST8_MAX UINT40_MAX #endif /* __INT40_TYPE__ */ #ifdef __INT32_TYPE__ # define INT32_MAX INT32_C(2147483647) # define INT32_MIN (-INT32_C(2147483647)-1) # define UINT32_MAX UINT32_C(4294967295) # define __INT_LEAST32_MIN INT32_MIN # define __INT_LEAST32_MAX INT32_MAX # define __UINT_LEAST32_MAX UINT32_MAX # define __INT_LEAST16_MIN INT32_MIN # define __INT_LEAST16_MAX INT32_MAX # define __UINT_LEAST16_MAX UINT32_MAX # define __INT_LEAST8_MIN INT32_MIN # define __INT_LEAST8_MAX INT32_MAX # define __UINT_LEAST8_MAX UINT32_MAX #endif /* __INT32_TYPE__ */ #ifdef __INT_LEAST32_MIN # define INT_LEAST32_MIN __INT_LEAST32_MIN # define INT_LEAST32_MAX __INT_LEAST32_MAX # define UINT_LEAST32_MAX __UINT_LEAST32_MAX # define INT_FAST32_MIN __INT_LEAST32_MIN # define INT_FAST32_MAX __INT_LEAST32_MAX # define UINT_FAST32_MAX __UINT_LEAST32_MAX #endif /* __INT_LEAST32_MIN */ #ifdef __INT24_TYPE__ # define INT24_MAX INT24_C(8388607) # define INT24_MIN (-INT24_C(8388607)-1) # define UINT24_MAX UINT24_C(16777215) # define INT_LEAST24_MIN INT24_MIN # define INT_LEAST24_MAX INT24_MAX # define UINT_LEAST24_MAX UINT24_MAX # define INT_FAST24_MIN INT24_MIN # define INT_FAST24_MAX INT24_MAX # define UINT_FAST24_MAX UINT24_MAX # define __INT_LEAST16_MIN INT24_MIN # define __INT_LEAST16_MAX INT24_MAX # define __UINT_LEAST16_MAX UINT24_MAX # define __INT_LEAST8_MIN INT24_MIN # define __INT_LEAST8_MAX INT24_MAX # define __UINT_LEAST8_MAX UINT24_MAX #endif /* __INT24_TYPE__ */ #ifdef __INT16_TYPE__ #define INT16_MAX INT16_C(32767) #define INT16_MIN (-INT16_C(32767)-1) #define UINT16_MAX UINT16_C(65535) # define __INT_LEAST16_MIN INT16_MIN # define __INT_LEAST16_MAX INT16_MAX # define __UINT_LEAST16_MAX UINT16_MAX # define __INT_LEAST8_MIN INT16_MIN # define __INT_LEAST8_MAX INT16_MAX # define __UINT_LEAST8_MAX UINT16_MAX #endif /* __INT16_TYPE__ */ #ifdef __INT_LEAST16_MIN # define INT_LEAST16_MIN __INT_LEAST16_MIN # define INT_LEAST16_MAX __INT_LEAST16_MAX # define UINT_LEAST16_MAX __UINT_LEAST16_MAX # define INT_FAST16_MIN __INT_LEAST16_MIN # define INT_FAST16_MAX __INT_LEAST16_MAX # define UINT_FAST16_MAX __UINT_LEAST16_MAX #endif /* __INT_LEAST16_MIN */ #ifdef __INT8_TYPE__ # define INT8_MAX INT8_C(127) # define INT8_MIN (-INT8_C(127)-1) # define UINT8_MAX UINT8_C(255) # define __INT_LEAST8_MIN INT8_MIN # define __INT_LEAST8_MAX INT8_MAX # define __UINT_LEAST8_MAX UINT8_MAX #endif /* __INT8_TYPE__ */ #ifdef __INT_LEAST8_MIN # define INT_LEAST8_MIN __INT_LEAST8_MIN # define INT_LEAST8_MAX __INT_LEAST8_MAX # define UINT_LEAST8_MAX __UINT_LEAST8_MAX # define INT_FAST8_MIN __INT_LEAST8_MIN # define INT_FAST8_MAX __INT_LEAST8_MAX # define UINT_FAST8_MAX __UINT_LEAST8_MAX #endif /* __INT_LEAST8_MIN */ /* Some utility macros */ #define __INTN_MIN(n) __stdint_join3( INT, n, _MIN) #define __INTN_MAX(n) __stdint_join3( INT, n, _MAX) #define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX) #define __INTN_C(n, v) __stdint_join3( INT, n, _C(v)) #define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v)) /* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */ /* C99 7.18.3 Limits of other integer types. */ #define INTPTR_MIN __INTN_MIN(__INTPTR_WIDTH__) #define INTPTR_MAX __INTN_MAX(__INTPTR_WIDTH__) #define UINTPTR_MAX __UINTN_MAX(__INTPTR_WIDTH__) #define PTRDIFF_MIN __INTN_MIN(__PTRDIFF_WIDTH__) #define PTRDIFF_MAX __INTN_MAX(__PTRDIFF_WIDTH__) #define SIZE_MAX __UINTN_MAX(__SIZE_WIDTH__) /* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__ * is enabled. */ #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 #define RSIZE_MAX (SIZE_MAX >> 1) #endif /* C99 7.18.2.5 Limits of greatest-width integer types. */ #define INTMAX_MIN __INTN_MIN(__INTMAX_WIDTH__) #define INTMAX_MAX __INTN_MAX(__INTMAX_WIDTH__) #define UINTMAX_MAX __UINTN_MAX(__INTMAX_WIDTH__) /* C99 7.18.3 Limits of other integer types. */ #define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__) #define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__) #ifdef __WINT_UNSIGNED__ # define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0) # define WINT_MAX __UINTN_MAX(__WINT_WIDTH__) #else # define WINT_MIN __INTN_MIN(__WINT_WIDTH__) # define WINT_MAX __INTN_MAX(__WINT_WIDTH__) #endif #ifndef WCHAR_MAX # define WCHAR_MAX __WCHAR_MAX__ #endif #ifndef WCHAR_MIN # if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__) # define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__) # else # define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0) # endif #endif /* 7.18.4.2 Macros for greatest-width integer constants. */ #define INTMAX_C(v) __INTN_C(__INTMAX_WIDTH__, v) #define UINTMAX_C(v) __UINTN_C(__INTMAX_WIDTH__, v) #endif /* __STDC_HOSTED__ */ #endif /* __CLANG_STDINT_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avx512cdintrin.h
/*===------------- avx512cdintrin.h - AVX512CD intrinsics ------------------=== * * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avx512cdintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVX512CDINTRIN_H #define __AVX512CDINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("avx512cd"))) static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_conflict_epi64 (__m512i __A) { return (__m512i) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A, (__v8di) _mm512_setzero_si512 (), (__mmask8) -1); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mask_conflict_epi64 (__m512i __W, __mmask8 __U, __m512i __A) { return (__m512i) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A, (__v8di) __W, (__mmask8) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_maskz_conflict_epi64 (__mmask8 __U, __m512i __A) { return (__m512i) __builtin_ia32_vpconflictdi_512_mask ((__v8di) __A, (__v8di) _mm512_setzero_si512 (), (__mmask8) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_conflict_epi32 (__m512i __A) { return (__m512i) __builtin_ia32_vpconflictsi_512_mask ((__v16si) __A, (__v16si) _mm512_setzero_si512 (), (__mmask16) -1); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mask_conflict_epi32 (__m512i __W, __mmask16 __U, __m512i __A) { return (__m512i) __builtin_ia32_vpconflictsi_512_mask ((__v16si) __A, (__v16si) __W, (__mmask16) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_maskz_conflict_epi32 (__mmask16 __U, __m512i __A) { return (__m512i) __builtin_ia32_vpconflictsi_512_mask ((__v16si) __A, (__v16si) _mm512_setzero_si512 (), (__mmask16) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_lzcnt_epi32 (__m512i __A) { return (__m512i) __builtin_ia32_vplzcntd_512_mask ((__v16si) __A, (__v16si) _mm512_setzero_si512 (), (__mmask16) -1); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mask_lzcnt_epi32 (__m512i __W, __mmask16 __U, __m512i __A) { return (__m512i) __builtin_ia32_vplzcntd_512_mask ((__v16si) __A, (__v16si) __W, (__mmask16) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_maskz_lzcnt_epi32 (__mmask16 __U, __m512i __A) { return (__m512i) __builtin_ia32_vplzcntd_512_mask ((__v16si) __A, (__v16si) _mm512_setzero_si512 (), (__mmask16) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_lzcnt_epi64 (__m512i __A) { return (__m512i) __builtin_ia32_vplzcntq_512_mask ((__v8di) __A, (__v8di) _mm512_setzero_si512 (), (__mmask8) -1); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mask_lzcnt_epi64 (__m512i __W, __mmask8 __U, __m512i __A) { return (__m512i) __builtin_ia32_vplzcntq_512_mask ((__v8di) __A, (__v8di) __W, (__mmask8) __U); } static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_maskz_lzcnt_epi64 (__mmask8 __U, __m512i __A) { return (__m512i) __builtin_ia32_vplzcntq_512_mask ((__v8di) __A, (__v8di) _mm512_setzero_si512 (), (__mmask8) __U); } #undef __DEFAULT_FN_ATTRS #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/pmmintrin.h
/*===---- pmmintrin.h - SSE3 intrinsics ------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __PMMINTRIN_H #define __PMMINTRIN_H #ifndef __SSE3__ #error "SSE3 instruction set not enabled" #else #include <emmintrin.h> /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_lddqu_si128(__m128i const *__p) { return (__m128i)__builtin_ia32_lddqu((char const *)__p); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_addsub_ps(__m128 __a, __m128 __b) { return __builtin_ia32_addsubps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_hadd_ps(__m128 __a, __m128 __b) { return __builtin_ia32_haddps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_hsub_ps(__m128 __a, __m128 __b) { return __builtin_ia32_hsubps(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_movehdup_ps(__m128 __a) { return __builtin_shufflevector(__a, __a, 1, 1, 3, 3); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_moveldup_ps(__m128 __a) { return __builtin_shufflevector(__a, __a, 0, 0, 2, 2); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_addsub_pd(__m128d __a, __m128d __b) { return __builtin_ia32_addsubpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_hadd_pd(__m128d __a, __m128d __b) { return __builtin_ia32_haddpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_hsub_pd(__m128d __a, __m128d __b) { return __builtin_ia32_hsubpd(__a, __b); } #define _mm_loaddup_pd(dp) _mm_load1_pd(dp) static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_movedup_pd(__m128d __a) { return __builtin_shufflevector(__a, __a, 0, 0); } #define _MM_DENORMALS_ZERO_ON (0x0040) #define _MM_DENORMALS_ZERO_OFF (0x0000) #define _MM_DENORMALS_ZERO_MASK (0x0040) #define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK) #define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_DENORMALS_ZERO_MASK) | (x))) static __inline__ void __DEFAULT_FN_ATTRS _mm_monitor(void const *__p, unsigned __extensions, unsigned __hints) { __builtin_ia32_monitor((void *)__p, __extensions, __hints); } static __inline__ void __DEFAULT_FN_ATTRS _mm_mwait(unsigned __extensions, unsigned __hints) { __builtin_ia32_mwait(__extensions, __hints); } #undef __DEFAULT_FN_ATTRS #endif /* __SSE3__ */ #endif /* __PMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/unwind.h
/*===---- unwind.h - Stack unwinding ----------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __CLANG_UNWIND_H #define __CLANG_UNWIND_H #if defined(__APPLE__) && __has_include_next(<unwind.h>) /* Darwin (from 11.x on) provide an unwind.h. If that's available, * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE, * so define that around the include.*/ # ifndef _GNU_SOURCE # define _SHOULD_UNDEFINE_GNU_SOURCE # define _GNU_SOURCE # endif // libunwind's unwind.h reflects the current visibility. However, Mozilla // builds with -fvisibility=hidden and relies on gcc's unwind.h to reset the // visibility to default and export its contents. gcc also allows users to // override its override by #defining HIDE_EXPORTS (but note, this only obeys // the user's -fvisibility setting; it doesn't hide any exports on its own). We // imitate gcc's header here: # ifdef HIDE_EXPORTS # include_next <unwind.h> # else # pragma GCC visibility push(default) # include_next <unwind.h> # pragma GCC visibility pop # endif # ifdef _SHOULD_UNDEFINE_GNU_SOURCE # undef _GNU_SOURCE # undef _SHOULD_UNDEFINE_GNU_SOURCE # endif #else #include <stdint.h> #ifdef __cplusplus extern "C" { #endif /* It is a bit strange for a header to play with the visibility of the symbols it declares, but this matches gcc's behavior and some programs depend on it */ #ifndef HIDE_EXPORTS #pragma GCC visibility push(default) #endif typedef uintptr_t _Unwind_Word; typedef intptr_t _Unwind_Sword; typedef uintptr_t _Unwind_Ptr; typedef uintptr_t _Unwind_Internal_Ptr; typedef uint64_t _Unwind_Exception_Class; typedef intptr_t _sleb128_t; typedef uintptr_t _uleb128_t; struct _Unwind_Context; struct _Unwind_Exception; typedef enum { _URC_NO_REASON = 0, _URC_FOREIGN_EXCEPTION_CAUGHT = 1, _URC_FATAL_PHASE2_ERROR = 2, _URC_FATAL_PHASE1_ERROR = 3, _URC_NORMAL_STOP = 4, _URC_END_OF_STACK = 5, _URC_HANDLER_FOUND = 6, _URC_INSTALL_CONTEXT = 7, _URC_CONTINUE_UNWIND = 8 } _Unwind_Reason_Code; typedef enum { _UA_SEARCH_PHASE = 1, _UA_CLEANUP_PHASE = 2, _UA_HANDLER_FRAME = 4, _UA_FORCE_UNWIND = 8, _UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */ } _Unwind_Action; typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code, struct _Unwind_Exception *); struct _Unwind_Exception { _Unwind_Exception_Class exception_class; _Unwind_Exception_Cleanup_Fn exception_cleanup; _Unwind_Word private_1; _Unwind_Word private_2; /* The Itanium ABI requires that _Unwind_Exception objects are "double-word * aligned". GCC has interpreted this to mean "use the maximum useful * alignment for the target"; so do we. */ } __attribute__((__aligned__)); typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *, struct _Unwind_Context *, void *); typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)( int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *, struct _Unwind_Context *); typedef _Unwind_Personality_Fn __personality_routine; typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *, void *); #if defined(__arm__) && !defined(__APPLE__) typedef enum { _UVRSC_CORE = 0, /* integer register */ _UVRSC_VFP = 1, /* vfp */ _UVRSC_WMMXD = 3, /* Intel WMMX data register */ _UVRSC_WMMXC = 4 /* Intel WMMX control register */ } _Unwind_VRS_RegClass; typedef enum { _UVRSD_UINT32 = 0, _UVRSD_VFPX = 1, _UVRSD_UINT64 = 3, _UVRSD_FLOAT = 4, _UVRSD_DOUBLE = 5 } _Unwind_VRS_DataRepresentation; typedef enum { _UVRSR_OK = 0, _UVRSR_NOT_IMPLEMENTED = 1, _UVRSR_FAILED = 2 } _Unwind_VRS_Result; _Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context, _Unwind_VRS_RegClass __regclass, uint32_t __regno, _Unwind_VRS_DataRepresentation __representation, void *__valuep); _Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context, _Unwind_VRS_RegClass __regclass, uint32_t __regno, _Unwind_VRS_DataRepresentation __representation, void *__valuep); static __inline__ _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) { _Unwind_Word __value; _Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value); return __value; } static __inline__ void _Unwind_SetGR(struct _Unwind_Context *__context, int __index, _Unwind_Word __value) { _Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value); } static __inline__ _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) { _Unwind_Word __ip = _Unwind_GetGR(__context, 15); return __ip & ~(_Unwind_Word)(0x1); /* Remove thumb mode bit. */ } static __inline__ void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) { _Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1; _Unwind_SetGR(__context, 15, __value | __thumb_mode_bit); } #else _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int); void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word); _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *); void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word); #endif _Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *); _Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *); _Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *); void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *); _Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *); /* DWARF EH functions; currently not available on Darwin/ARM */ #if !defined(__APPLE__) || !defined(__arm__) _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *); _Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception *, _Unwind_Stop_Fn, void *); void _Unwind_DeleteException(struct _Unwind_Exception *); void _Unwind_Resume(struct _Unwind_Exception *); _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(struct _Unwind_Exception *); #endif _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *); /* setjmp(3)/longjmp(3) stuff */ typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t; void _Unwind_SjLj_Register(_Unwind_FunctionContext_t); void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t); _Unwind_Reason_Code _Unwind_SjLj_RaiseException(struct _Unwind_Exception *); _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(struct _Unwind_Exception *, _Unwind_Stop_Fn, void *); void _Unwind_SjLj_Resume(struct _Unwind_Exception *); _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception *); void *_Unwind_FindEnclosingFunction(void *); #ifdef __APPLE__ _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *) __attribute__((__unavailable__)); _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *) __attribute__((__unavailable__)); /* Darwin-specific functions */ void __register_frame(const void *); void __deregister_frame(const void *); struct dwarf_eh_bases { uintptr_t tbase; uintptr_t dbase; uintptr_t func; }; void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *); void __register_frame_info_bases(const void *, void *, void *, void *) __attribute__((__unavailable__)); void __register_frame_info(const void *, void *) __attribute__((__unavailable__)); void __register_frame_info_table_bases(const void *, void*, void *, void *) __attribute__((__unavailable__)); void __register_frame_info_table(const void *, void *) __attribute__((__unavailable__)); void __register_frame_table(const void *) __attribute__((__unavailable__)); void __deregister_frame_info(const void *) __attribute__((__unavailable__)); void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__)); #else _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *); _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *); #endif #ifndef HIDE_EXPORTS #pragma GCC visibility pop #endif #ifdef __cplusplus } #endif #endif #endif /* __CLANG_UNWIND_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/CMakeLists.txt
set(files adxintrin.h altivec.h ammintrin.h arm_acle.h avx2intrin.h avx512bwintrin.h avx512cdintrin.h avx512erintrin.h avx512fintrin.h avx512vlbwintrin.h avx512vlintrin.h avx512dqintrin.h avx512vldqintrin.h avxintrin.h bmi2intrin.h bmiintrin.h cpuid.h cuda_builtin_vars.h emmintrin.h f16cintrin.h float.h fma4intrin.h fmaintrin.h fxsrintrin.h htmintrin.h htmxlintrin.h ia32intrin.h immintrin.h Intrin.h inttypes.h iso646.h limits.h lzcntintrin.h mm3dnow.h mmintrin.h mm_malloc.h module.modulemap nmmintrin.h pmmintrin.h popcntintrin.h prfchwintrin.h rdseedintrin.h rtmintrin.h s390intrin.h shaintrin.h smmintrin.h stdalign.h stdarg.h stdatomic.h stdbool.h stddef.h __stddef_max_align_t.h stdint.h stdnoreturn.h tbmintrin.h tgmath.h tmmintrin.h unwind.h vadefs.h varargs.h vecintrin.h __wmmintrin_aes.h wmmintrin.h __wmmintrin_pclmul.h x86intrin.h xmmintrin.h xopintrin.h xtestintrin.h ) set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include) # Generate arm_neon.h clang_tablegen(arm_neon.h -gen-arm-neon SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_neon.td) set(out_files) foreach( f ${files} ) set( src ${CMAKE_CURRENT_SOURCE_DIR}/${f} ) set( dst ${output_dir}/${f} ) add_custom_command(OUTPUT ${dst} DEPENDS ${src} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} COMMENT "Copying clang's ${f}...") list(APPEND out_files ${dst}) endforeach( f ) add_custom_command(OUTPUT ${output_dir}/arm_neon.h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h ${output_dir}/arm_neon.h COMMENT "Copying clang's arm_neon.h...") list(APPEND out_files ${output_dir}/arm_neon.h) add_custom_target(clang-headers ALL DEPENDS ${out_files}) set_target_properties(clang-headers PROPERTIES FOLDER "Misc") install( FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/htmintrin.h
/*===---- htmintrin.h - Standard header for PowerPC HTM ---------------===*\ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * \*===----------------------------------------------------------------------===*/ #ifndef __HTMINTRIN_H #define __HTMINTRIN_H #ifndef __HTM__ #error "HTM instruction set not enabled" #endif #ifdef __powerpc__ #include <stdint.h> typedef uint64_t texasr_t; typedef uint32_t texasru_t; typedef uint32_t texasrl_t; typedef uintptr_t tfiar_t; typedef uintptr_t tfhar_t; #define _HTM_STATE(CR0) ((CR0 >> 1) & 0x3) #define _HTM_NONTRANSACTIONAL 0x0 #define _HTM_SUSPENDED 0x1 #define _HTM_TRANSACTIONAL 0x2 #define _TEXASR_EXTRACT_BITS(TEXASR,BITNUM,SIZE) \ (((TEXASR) >> (63-(BITNUM))) & ((1<<(SIZE))-1)) #define _TEXASRU_EXTRACT_BITS(TEXASR,BITNUM,SIZE) \ (((TEXASR) >> (31-(BITNUM))) & ((1<<(SIZE))-1)) #define _TEXASR_FAILURE_CODE(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 7, 8) #define _TEXASRU_FAILURE_CODE(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 7, 8) #define _TEXASR_FAILURE_PERSISTENT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 7, 1) #define _TEXASRU_FAILURE_PERSISTENT(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 7, 1) #define _TEXASR_DISALLOWED(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 8, 1) #define _TEXASRU_DISALLOWED(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 8, 1) #define _TEXASR_NESTING_OVERFLOW(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 9, 1) #define _TEXASRU_NESTING_OVERFLOW(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 9, 1) #define _TEXASR_FOOTPRINT_OVERFLOW(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 10, 1) #define _TEXASRU_FOOTPRINT_OVERFLOW(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 10, 1) #define _TEXASR_SELF_INDUCED_CONFLICT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 11, 1) #define _TEXASRU_SELF_INDUCED_CONFLICT(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 11, 1) #define _TEXASR_NON_TRANSACTIONAL_CONFLICT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 12, 1) #define _TEXASRU_NON_TRANSACTIONAL_CONFLICT(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 12, 1) #define _TEXASR_TRANSACTION_CONFLICT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 13, 1) #define _TEXASRU_TRANSACTION_CONFLICT(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 13, 1) #define _TEXASR_TRANSLATION_INVALIDATION_CONFLICT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 14, 1) #define _TEXASRU_TRANSLATION_INVALIDATION_CONFLICT(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 14, 1) #define _TEXASR_IMPLEMENTAION_SPECIFIC(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 15, 1) #define _TEXASRU_IMPLEMENTAION_SPECIFIC(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 15, 1) #define _TEXASR_INSTRUCTION_FETCH_CONFLICT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 16, 1) #define _TEXASRU_INSTRUCTION_FETCH_CONFLICT(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 16, 1) #define _TEXASR_ABORT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 31, 1) #define _TEXASRU_ABORT(TEXASRU) \ _TEXASRU_EXTRACT_BITS(TEXASRU, 31, 1) #define _TEXASR_SUSPENDED(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 32, 1) #define _TEXASR_PRIVILEGE(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 35, 2) #define _TEXASR_FAILURE_SUMMARY(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 36, 1) #define _TEXASR_TFIAR_EXACT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 37, 1) #define _TEXASR_ROT(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 38, 1) #define _TEXASR_TRANSACTION_LEVEL(TEXASR) \ _TEXASR_EXTRACT_BITS(TEXASR, 63, 12) #endif /* __powerpc */ #ifdef __s390__ /* Condition codes generated by tbegin */ #define _HTM_TBEGIN_STARTED 0 #define _HTM_TBEGIN_INDETERMINATE 1 #define _HTM_TBEGIN_TRANSIENT 2 #define _HTM_TBEGIN_PERSISTENT 3 /* The abort codes below this threshold are reserved for machine use. */ #define _HTM_FIRST_USER_ABORT_CODE 256 /* The transaction diagnostic block is it is defined in the Principles of Operation chapter 5-91. */ struct __htm_tdb { unsigned char format; /* 0 */ unsigned char flags; unsigned char reserved1[4]; unsigned short nesting_depth; unsigned long long abort_code; /* 8 */ unsigned long long conflict_token; /* 16 */ unsigned long long atia; /* 24 */ unsigned char eaid; /* 32 */ unsigned char dxc; unsigned char reserved2[2]; unsigned int program_int_id; unsigned long long exception_id; /* 40 */ unsigned long long bea; /* 48 */ unsigned char reserved3[72]; /* 56 */ unsigned long long gprs[16]; /* 128 */ } __attribute__((__packed__, __aligned__ (8))); /* Helper intrinsics to retry tbegin in case of transient failure. */ static __inline int __attribute__((__always_inline__, __nodebug__)) __builtin_tbegin_retry_null (int retry) { int cc, i = 0; while ((cc = __builtin_tbegin(0)) == _HTM_TBEGIN_TRANSIENT && i++ < retry) __builtin_tx_assist(i); return cc; } static __inline int __attribute__((__always_inline__, __nodebug__)) __builtin_tbegin_retry_tdb (void *tdb, int retry) { int cc, i = 0; while ((cc = __builtin_tbegin(tdb)) == _HTM_TBEGIN_TRANSIENT && i++ < retry) __builtin_tx_assist(i); return cc; } #define __builtin_tbegin_retry(tdb, retry) \ (__builtin_constant_p(tdb == 0) && tdb == 0 ? \ __builtin_tbegin_retry_null(retry) : \ __builtin_tbegin_retry_tdb(tdb, retry)) static __inline int __attribute__((__always_inline__, __nodebug__)) __builtin_tbegin_retry_nofloat_null (int retry) { int cc, i = 0; while ((cc = __builtin_tbegin_nofloat(0)) == _HTM_TBEGIN_TRANSIENT && i++ < retry) __builtin_tx_assist(i); return cc; } static __inline int __attribute__((__always_inline__, __nodebug__)) __builtin_tbegin_retry_nofloat_tdb (void *tdb, int retry) { int cc, i = 0; while ((cc = __builtin_tbegin_nofloat(tdb)) == _HTM_TBEGIN_TRANSIENT && i++ < retry) __builtin_tx_assist(i); return cc; } #define __builtin_tbegin_retry_nofloat(tdb, retry) \ (__builtin_constant_p(tdb == 0) && tdb == 0 ? \ __builtin_tbegin_retry_nofloat_null(retry) : \ __builtin_tbegin_retry_nofloat_tdb(tdb, retry)) #endif /* __s390__ */ #endif /* __HTMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/htmxlintrin.h
/*===---- htmxlintrin.h - XL compiler HTM execution intrinsics-------------===*\ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * \*===----------------------------------------------------------------------===*/ #ifndef __HTMXLINTRIN_H #define __HTMXLINTRIN_H #ifndef __HTM__ #error "HTM instruction set not enabled" #endif #include <htmintrin.h> #ifdef __powerpc__ #ifdef __cplusplus extern "C" { #endif #define _TEXASR_PTR(TM_BUF) \ ((texasr_t *)((TM_BUF)+0)) #define _TEXASRU_PTR(TM_BUF) \ ((texasru_t *)((TM_BUF)+0)) #define _TEXASRL_PTR(TM_BUF) \ ((texasrl_t *)((TM_BUF)+4)) #define _TFIAR_PTR(TM_BUF) \ ((tfiar_t *)((TM_BUF)+8)) typedef char TM_buff_type[16]; /* This macro can be used to determine whether a transaction was successfully started from the __TM_begin() and __TM_simple_begin() intrinsic functions below. */ #define _HTM_TBEGIN_STARTED 1 extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_simple_begin (void) { if (__builtin_expect (__builtin_tbegin (0), 1)) return _HTM_TBEGIN_STARTED; return 0; } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_begin (void* const TM_buff) { *_TEXASRL_PTR (TM_buff) = 0; if (__builtin_expect (__builtin_tbegin (0), 1)) return _HTM_TBEGIN_STARTED; #ifdef __powerpc64__ *_TEXASR_PTR (TM_buff) = __builtin_get_texasr (); #else *_TEXASRU_PTR (TM_buff) = __builtin_get_texasru (); *_TEXASRL_PTR (TM_buff) = __builtin_get_texasr (); #endif *_TFIAR_PTR (TM_buff) = __builtin_get_tfiar (); return 0; } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_end (void) { if (__builtin_expect (__builtin_tend (0), 1)) return 1; return 0; } extern __inline void __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_abort (void) { __builtin_tabort (0); } extern __inline void __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_named_abort (unsigned char const code) { __builtin_tabort (code); } extern __inline void __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_resume (void) { __builtin_tresume (); } extern __inline void __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_suspend (void) { __builtin_tsuspend (); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_is_user_abort (void* const TM_buff) { texasru_t texasru = *_TEXASRU_PTR (TM_buff); return _TEXASRU_ABORT (texasru); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_is_named_user_abort (void* const TM_buff, unsigned char *code) { texasru_t texasru = *_TEXASRU_PTR (TM_buff); *code = _TEXASRU_FAILURE_CODE (texasru); return _TEXASRU_ABORT (texasru); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_is_illegal (void* const TM_buff) { texasru_t texasru = *_TEXASRU_PTR (TM_buff); return _TEXASRU_DISALLOWED (texasru); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_is_footprint_exceeded (void* const TM_buff) { texasru_t texasru = *_TEXASRU_PTR (TM_buff); return _TEXASRU_FOOTPRINT_OVERFLOW (texasru); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_nesting_depth (void* const TM_buff) { texasrl_t texasrl; if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL) { texasrl = *_TEXASRL_PTR (TM_buff); if (!_TEXASR_FAILURE_SUMMARY (texasrl)) texasrl = 0; } else texasrl = (texasrl_t) __builtin_get_texasr (); return _TEXASR_TRANSACTION_LEVEL (texasrl); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_is_nested_too_deep(void* const TM_buff) { texasru_t texasru = *_TEXASRU_PTR (TM_buff); return _TEXASRU_NESTING_OVERFLOW (texasru); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_is_conflict(void* const TM_buff) { texasru_t texasru = *_TEXASRU_PTR (TM_buff); /* Return TEXASR bits 11 (Self-Induced Conflict) through 14 (Translation Invalidation Conflict). */ return (_TEXASRU_EXTRACT_BITS (texasru, 14, 4)) ? 1 : 0; } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_is_failure_persistent(void* const TM_buff) { texasru_t texasru = *_TEXASRU_PTR (TM_buff); return _TEXASRU_FAILURE_PERSISTENT (texasru); } extern __inline long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_failure_address(void* const TM_buff) { return *_TFIAR_PTR (TM_buff); } extern __inline long long __attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) __TM_failure_code(void* const TM_buff) { return *_TEXASR_PTR (TM_buff); } #ifdef __cplusplus } #endif #endif /* __powerpc__ */ #ifdef __s390__ #include <stdint.h> /* These intrinsics are being made available for compatibility with the IBM XL compiler. For documentation please see the "z/OS XL C/C++ Programming Guide" publically available on the web. */ static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_simple_begin () { return __builtin_tbegin_nofloat (0); } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_begin (void* const tdb) { return __builtin_tbegin_nofloat (tdb); } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_end () { return __builtin_tend (); } static __inline void __attribute__((__always_inline__)) __TM_abort () { return __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE); } static __inline void __attribute__((__always_inline__, __nodebug__)) __TM_named_abort (unsigned char const code) { return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE + code); } static __inline void __attribute__((__always_inline__, __nodebug__)) __TM_non_transactional_store (void* const addr, long long const value) { __builtin_non_tx_store ((uint64_t*)addr, (uint64_t)value); } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_nesting_depth (void* const tdb_ptr) { int depth = __builtin_tx_nesting_depth (); struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; if (depth != 0) return depth; if (tdb->format != 1) return 0; return tdb->nesting_depth; } /* Transaction failure diagnostics */ static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_is_user_abort (void* const tdb_ptr) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; if (tdb->format != 1) return 0; return !!(tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE); } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_is_named_user_abort (void* const tdb_ptr, unsigned char* code) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; if (tdb->format != 1) return 0; if (tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE) { *code = tdb->abort_code - _HTM_FIRST_USER_ABORT_CODE; return 1; } return 0; } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_is_illegal (void* const tdb_ptr) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; return (tdb->format == 1 && (tdb->abort_code == 4 /* unfiltered program interruption */ || tdb->abort_code == 11 /* restricted instruction */)); } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_is_footprint_exceeded (void* const tdb_ptr) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; return (tdb->format == 1 && (tdb->abort_code == 7 /* fetch overflow */ || tdb->abort_code == 8 /* store overflow */)); } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_is_nested_too_deep (void* const tdb_ptr) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; return tdb->format == 1 && tdb->abort_code == 13; /* depth exceeded */ } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_is_conflict (void* const tdb_ptr) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; return (tdb->format == 1 && (tdb->abort_code == 9 /* fetch conflict */ || tdb->abort_code == 10 /* store conflict */)); } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_is_failure_persistent (long const result) { return result == _HTM_TBEGIN_PERSISTENT; } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_failure_address (void* const tdb_ptr) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; return tdb->atia; } static __inline long __attribute__((__always_inline__, __nodebug__)) __TM_failure_code (void* const tdb_ptr) { struct __htm_tdb *tdb = (struct __htm_tdb*)tdb_ptr; return tdb->abort_code; } #endif /* __s390__ */ #endif /* __HTMXLINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/mm3dnow.h
/*===---- mm3dnow.h - 3DNow! intrinsics ------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef _MM3DNOW_H_INCLUDED #define _MM3DNOW_H_INCLUDED #include <mmintrin.h> #include <prfchwintrin.h> typedef float __v2sf __attribute__((__vector_size__(8))); /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ void __DEFAULT_FN_ATTRS _m_femms() { __builtin_ia32_femms(); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pavgusb(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pavgusb((__v8qi)__m1, (__v8qi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pf2id(__m64 __m) { return (__m64)__builtin_ia32_pf2id((__v2sf)__m); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfacc(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfacc((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfadd(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfadd((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfcmpeq(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfcmpeq((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfcmpge(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfcmpge((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfcmpgt(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfcmpgt((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfmax(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfmax((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfmin(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfmin((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfmul(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfmul((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfrcp(__m64 __m) { return (__m64)__builtin_ia32_pfrcp((__v2sf)__m); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfrcpit1(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfrcpit1((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfrcpit2(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfrcpit2((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfrsqrt(__m64 __m) { return (__m64)__builtin_ia32_pfrsqrt((__v2sf)__m); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfrsqrtit1(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfrsqit1((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfsub(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfsub((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfsubr(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfsubr((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pi2fd(__m64 __m) { return (__m64)__builtin_ia32_pi2fd((__v2si)__m); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pmulhrw(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pmulhrw((__v4hi)__m1, (__v4hi)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pf2iw(__m64 __m) { return (__m64)__builtin_ia32_pf2iw((__v2sf)__m); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfnacc(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfnacc((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pfpnacc(__m64 __m1, __m64 __m2) { return (__m64)__builtin_ia32_pfpnacc((__v2sf)__m1, (__v2sf)__m2); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pi2fw(__m64 __m) { return (__m64)__builtin_ia32_pi2fw((__v2si)__m); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pswapdsf(__m64 __m) { return (__m64)__builtin_ia32_pswapdsf((__v2sf)__m); } static __inline__ __m64 __DEFAULT_FN_ATTRS _m_pswapdsi(__m64 __m) { return (__m64)__builtin_ia32_pswapdsi((__v2si)__m); } #undef __DEFAULT_FN_ATTRS #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avxintrin.h
/*===---- avxintrin.h - AVX intrinsics -------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avxintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVXINTRIN_H #define __AVXINTRIN_H typedef double __v4df __attribute__ ((__vector_size__ (32))); typedef float __v8sf __attribute__ ((__vector_size__ (32))); typedef long long __v4di __attribute__ ((__vector_size__ (32))); typedef int __v8si __attribute__ ((__vector_size__ (32))); typedef short __v16hi __attribute__ ((__vector_size__ (32))); typedef char __v32qi __attribute__ ((__vector_size__ (32))); typedef float __m256 __attribute__ ((__vector_size__ (32))); typedef double __m256d __attribute__((__vector_size__(32))); typedef long long __m256i __attribute__((__vector_size__(32))); /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) /* Arithmetic */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_add_pd(__m256d __a, __m256d __b) { return __a+__b; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_add_ps(__m256 __a, __m256 __b) { return __a+__b; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_sub_pd(__m256d __a, __m256d __b) { return __a-__b; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_sub_ps(__m256 __a, __m256 __b) { return __a-__b; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_addsub_pd(__m256d __a, __m256d __b) { return (__m256d)__builtin_ia32_addsubpd256((__v4df)__a, (__v4df)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_addsub_ps(__m256 __a, __m256 __b) { return (__m256)__builtin_ia32_addsubps256((__v8sf)__a, (__v8sf)__b); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_div_pd(__m256d __a, __m256d __b) { return __a / __b; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_div_ps(__m256 __a, __m256 __b) { return __a / __b; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_max_pd(__m256d __a, __m256d __b) { return (__m256d)__builtin_ia32_maxpd256((__v4df)__a, (__v4df)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_max_ps(__m256 __a, __m256 __b) { return (__m256)__builtin_ia32_maxps256((__v8sf)__a, (__v8sf)__b); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_min_pd(__m256d __a, __m256d __b) { return (__m256d)__builtin_ia32_minpd256((__v4df)__a, (__v4df)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_min_ps(__m256 __a, __m256 __b) { return (__m256)__builtin_ia32_minps256((__v8sf)__a, (__v8sf)__b); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_mul_pd(__m256d __a, __m256d __b) { return __a * __b; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_mul_ps(__m256 __a, __m256 __b) { return __a * __b; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_sqrt_pd(__m256d __a) { return (__m256d)__builtin_ia32_sqrtpd256((__v4df)__a); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_sqrt_ps(__m256 __a) { return (__m256)__builtin_ia32_sqrtps256((__v8sf)__a); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_rsqrt_ps(__m256 __a) { return (__m256)__builtin_ia32_rsqrtps256((__v8sf)__a); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_rcp_ps(__m256 __a) { return (__m256)__builtin_ia32_rcpps256((__v8sf)__a); } #define _mm256_round_pd(V, M) __extension__ ({ \ __m256d __V = (V); \ (__m256d)__builtin_ia32_roundpd256((__v4df)__V, (M)); }) #define _mm256_round_ps(V, M) __extension__ ({ \ __m256 __V = (V); \ (__m256)__builtin_ia32_roundps256((__v8sf)__V, (M)); }) #define _mm256_ceil_pd(V) _mm256_round_pd((V), _MM_FROUND_CEIL) #define _mm256_floor_pd(V) _mm256_round_pd((V), _MM_FROUND_FLOOR) #define _mm256_ceil_ps(V) _mm256_round_ps((V), _MM_FROUND_CEIL) #define _mm256_floor_ps(V) _mm256_round_ps((V), _MM_FROUND_FLOOR) /* Logical */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_and_pd(__m256d __a, __m256d __b) { return (__m256d)((__v4di)__a & (__v4di)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_and_ps(__m256 __a, __m256 __b) { return (__m256)((__v8si)__a & (__v8si)__b); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_andnot_pd(__m256d __a, __m256d __b) { return (__m256d)(~(__v4di)__a & (__v4di)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_andnot_ps(__m256 __a, __m256 __b) { return (__m256)(~(__v8si)__a & (__v8si)__b); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_or_pd(__m256d __a, __m256d __b) { return (__m256d)((__v4di)__a | (__v4di)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_or_ps(__m256 __a, __m256 __b) { return (__m256)((__v8si)__a | (__v8si)__b); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_xor_pd(__m256d __a, __m256d __b) { return (__m256d)((__v4di)__a ^ (__v4di)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_xor_ps(__m256 __a, __m256 __b) { return (__m256)((__v8si)__a ^ (__v8si)__b); } /* Horizontal arithmetic */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_hadd_pd(__m256d __a, __m256d __b) { return (__m256d)__builtin_ia32_haddpd256((__v4df)__a, (__v4df)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_hadd_ps(__m256 __a, __m256 __b) { return (__m256)__builtin_ia32_haddps256((__v8sf)__a, (__v8sf)__b); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_hsub_pd(__m256d __a, __m256d __b) { return (__m256d)__builtin_ia32_hsubpd256((__v4df)__a, (__v4df)__b); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_hsub_ps(__m256 __a, __m256 __b) { return (__m256)__builtin_ia32_hsubps256((__v8sf)__a, (__v8sf)__b); } /* Vector permutations */ static __inline __m128d __DEFAULT_FN_ATTRS _mm_permutevar_pd(__m128d __a, __m128i __c) { return (__m128d)__builtin_ia32_vpermilvarpd((__v2df)__a, (__v2di)__c); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_permutevar_pd(__m256d __a, __m256i __c) { return (__m256d)__builtin_ia32_vpermilvarpd256((__v4df)__a, (__v4di)__c); } static __inline __m128 __DEFAULT_FN_ATTRS _mm_permutevar_ps(__m128 __a, __m128i __c) { return (__m128)__builtin_ia32_vpermilvarps((__v4sf)__a, (__v4si)__c); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_permutevar_ps(__m256 __a, __m256i __c) { return (__m256)__builtin_ia32_vpermilvarps256((__v8sf)__a, (__v8si)__c); } #define _mm_permute_pd(A, C) __extension__ ({ \ __m128d __A = (A); \ (__m128d)__builtin_shufflevector((__v2df)__A, (__v2df) _mm_setzero_pd(), \ (C) & 0x1, ((C) & 0x2) >> 1); }) #define _mm256_permute_pd(A, C) __extension__ ({ \ __m256d __A = (A); \ (__m256d)__builtin_shufflevector((__v4df)__A, (__v4df) _mm256_setzero_pd(), \ (C) & 0x1, ((C) & 0x2) >> 1, \ 2 + (((C) & 0x4) >> 2), \ 2 + (((C) & 0x8) >> 3)); }) #define _mm_permute_ps(A, C) __extension__ ({ \ __m128 __A = (A); \ (__m128)__builtin_shufflevector((__v4sf)__A, (__v4sf) _mm_setzero_ps(), \ (C) & 0x3, ((C) & 0xc) >> 2, \ ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6); }) #define _mm256_permute_ps(A, C) __extension__ ({ \ __m256 __A = (A); \ (__m256)__builtin_shufflevector((__v8sf)__A, (__v8sf) _mm256_setzero_ps(), \ (C) & 0x3, ((C) & 0xc) >> 2, \ ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6, \ 4 + (((C) & 0x03) >> 0), \ 4 + (((C) & 0x0c) >> 2), \ 4 + (((C) & 0x30) >> 4), \ 4 + (((C) & 0xc0) >> 6)); }) #define _mm256_permute2f128_pd(V1, V2, M) __extension__ ({ \ __m256d __V1 = (V1); \ __m256d __V2 = (V2); \ (__m256d)__builtin_ia32_vperm2f128_pd256((__v4df)__V1, (__v4df)__V2, (M)); }) #define _mm256_permute2f128_ps(V1, V2, M) __extension__ ({ \ __m256 __V1 = (V1); \ __m256 __V2 = (V2); \ (__m256)__builtin_ia32_vperm2f128_ps256((__v8sf)__V1, (__v8sf)__V2, (M)); }) #define _mm256_permute2f128_si256(V1, V2, M) __extension__ ({ \ __m256i __V1 = (V1); \ __m256i __V2 = (V2); \ (__m256i)__builtin_ia32_vperm2f128_si256((__v8si)__V1, (__v8si)__V2, (M)); }) /* Vector Blend */ #define _mm256_blend_pd(V1, V2, M) __extension__ ({ \ __m256d __V1 = (V1); \ __m256d __V2 = (V2); \ (__m256d)__builtin_shufflevector((__v4df)__V1, (__v4df)__V2, \ (((M) & 0x01) ? 4 : 0), \ (((M) & 0x02) ? 5 : 1), \ (((M) & 0x04) ? 6 : 2), \ (((M) & 0x08) ? 7 : 3)); }) #define _mm256_blend_ps(V1, V2, M) __extension__ ({ \ __m256 __V1 = (V1); \ __m256 __V2 = (V2); \ (__m256)__builtin_shufflevector((__v8sf)__V1, (__v8sf)__V2, \ (((M) & 0x01) ? 8 : 0), \ (((M) & 0x02) ? 9 : 1), \ (((M) & 0x04) ? 10 : 2), \ (((M) & 0x08) ? 11 : 3), \ (((M) & 0x10) ? 12 : 4), \ (((M) & 0x20) ? 13 : 5), \ (((M) & 0x40) ? 14 : 6), \ (((M) & 0x80) ? 15 : 7)); }) static __inline __m256d __DEFAULT_FN_ATTRS _mm256_blendv_pd(__m256d __a, __m256d __b, __m256d __c) { return (__m256d)__builtin_ia32_blendvpd256( (__v4df)__a, (__v4df)__b, (__v4df)__c); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c) { return (__m256)__builtin_ia32_blendvps256( (__v8sf)__a, (__v8sf)__b, (__v8sf)__c); } /* Vector Dot Product */ #define _mm256_dp_ps(V1, V2, M) __extension__ ({ \ __m256 __V1 = (V1); \ __m256 __V2 = (V2); \ (__m256)__builtin_ia32_dpps256((__v8sf)__V1, (__v8sf)__V2, (M)); }) /* Vector shuffle */ #define _mm256_shuffle_ps(a, b, mask) __extension__ ({ \ __m256 __a = (a); \ __m256 __b = (b); \ (__m256)__builtin_shufflevector((__v8sf)__a, (__v8sf)__b, \ (mask) & 0x3, ((mask) & 0xc) >> 2, \ (((mask) & 0x30) >> 4) + 8, (((mask) & 0xc0) >> 6) + 8, \ ((mask) & 0x3) + 4, (((mask) & 0xc) >> 2) + 4, \ (((mask) & 0x30) >> 4) + 12, (((mask) & 0xc0) >> 6) + 12); }) #define _mm256_shuffle_pd(a, b, mask) __extension__ ({ \ __m256d __a = (a); \ __m256d __b = (b); \ (__m256d)__builtin_shufflevector((__v4df)__a, (__v4df)__b, \ (mask) & 0x1, \ (((mask) & 0x2) >> 1) + 4, \ (((mask) & 0x4) >> 2) + 2, \ (((mask) & 0x8) >> 3) + 6); }) /* Compare */ #define _CMP_EQ_OQ 0x00 /* Equal (ordered, non-signaling) */ #define _CMP_LT_OS 0x01 /* Less-than (ordered, signaling) */ #define _CMP_LE_OS 0x02 /* Less-than-or-equal (ordered, signaling) */ #define _CMP_UNORD_Q 0x03 /* Unordered (non-signaling) */ #define _CMP_NEQ_UQ 0x04 /* Not-equal (unordered, non-signaling) */ #define _CMP_NLT_US 0x05 /* Not-less-than (unordered, signaling) */ #define _CMP_NLE_US 0x06 /* Not-less-than-or-equal (unordered, signaling) */ #define _CMP_ORD_Q 0x07 /* Ordered (nonsignaling) */ #define _CMP_EQ_UQ 0x08 /* Equal (unordered, non-signaling) */ #define _CMP_NGE_US 0x09 /* Not-greater-than-or-equal (unord, signaling) */ #define _CMP_NGT_US 0x0a /* Not-greater-than (unordered, signaling) */ #define _CMP_FALSE_OQ 0x0b /* False (ordered, non-signaling) */ #define _CMP_NEQ_OQ 0x0c /* Not-equal (ordered, non-signaling) */ #define _CMP_GE_OS 0x0d /* Greater-than-or-equal (ordered, signaling) */ #define _CMP_GT_OS 0x0e /* Greater-than (ordered, signaling) */ #define _CMP_TRUE_UQ 0x0f /* True (unordered, non-signaling) */ #define _CMP_EQ_OS 0x10 /* Equal (ordered, signaling) */ #define _CMP_LT_OQ 0x11 /* Less-than (ordered, non-signaling) */ #define _CMP_LE_OQ 0x12 /* Less-than-or-equal (ordered, non-signaling) */ #define _CMP_UNORD_S 0x13 /* Unordered (signaling) */ #define _CMP_NEQ_US 0x14 /* Not-equal (unordered, signaling) */ #define _CMP_NLT_UQ 0x15 /* Not-less-than (unordered, non-signaling) */ #define _CMP_NLE_UQ 0x16 /* Not-less-than-or-equal (unord, non-signaling) */ #define _CMP_ORD_S 0x17 /* Ordered (signaling) */ #define _CMP_EQ_US 0x18 /* Equal (unordered, signaling) */ #define _CMP_NGE_UQ 0x19 /* Not-greater-than-or-equal (unord, non-sign) */ #define _CMP_NGT_UQ 0x1a /* Not-greater-than (unordered, non-signaling) */ #define _CMP_FALSE_OS 0x1b /* False (ordered, signaling) */ #define _CMP_NEQ_OS 0x1c /* Not-equal (ordered, signaling) */ #define _CMP_GE_OQ 0x1d /* Greater-than-or-equal (ordered, non-signaling) */ #define _CMP_GT_OQ 0x1e /* Greater-than (ordered, non-signaling) */ #define _CMP_TRUE_US 0x1f /* True (unordered, signaling) */ #define _mm_cmp_pd(a, b, c) __extension__ ({ \ __m128d __a = (a); \ __m128d __b = (b); \ (__m128d)__builtin_ia32_cmppd((__v2df)__a, (__v2df)__b, (c)); }) #define _mm_cmp_ps(a, b, c) __extension__ ({ \ __m128 __a = (a); \ __m128 __b = (b); \ (__m128)__builtin_ia32_cmpps((__v4sf)__a, (__v4sf)__b, (c)); }) #define _mm256_cmp_pd(a, b, c) __extension__ ({ \ __m256d __a = (a); \ __m256d __b = (b); \ (__m256d)__builtin_ia32_cmppd256((__v4df)__a, (__v4df)__b, (c)); }) #define _mm256_cmp_ps(a, b, c) __extension__ ({ \ __m256 __a = (a); \ __m256 __b = (b); \ (__m256)__builtin_ia32_cmpps256((__v8sf)__a, (__v8sf)__b, (c)); }) #define _mm_cmp_sd(a, b, c) __extension__ ({ \ __m128d __a = (a); \ __m128d __b = (b); \ (__m128d)__builtin_ia32_cmpsd((__v2df)__a, (__v2df)__b, (c)); }) #define _mm_cmp_ss(a, b, c) __extension__ ({ \ __m128 __a = (a); \ __m128 __b = (b); \ (__m128)__builtin_ia32_cmpss((__v4sf)__a, (__v4sf)__b, (c)); }) static __inline int __DEFAULT_FN_ATTRS _mm256_extract_epi32(__m256i __a, const int __imm) { __v8si __b = (__v8si)__a; return __b[__imm & 7]; } static __inline int __DEFAULT_FN_ATTRS _mm256_extract_epi16(__m256i __a, const int __imm) { __v16hi __b = (__v16hi)__a; return __b[__imm & 15]; } static __inline int __DEFAULT_FN_ATTRS _mm256_extract_epi8(__m256i __a, const int __imm) { __v32qi __b = (__v32qi)__a; return __b[__imm & 31]; } #ifdef __x86_64__ static __inline long long __DEFAULT_FN_ATTRS _mm256_extract_epi64(__m256i __a, const int __imm) { __v4di __b = (__v4di)__a; return __b[__imm & 3]; } #endif static __inline __m256i __DEFAULT_FN_ATTRS _mm256_insert_epi32(__m256i __a, int __b, int const __imm) { __v8si __c = (__v8si)__a; __c[__imm & 7] = __b; return (__m256i)__c; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_insert_epi16(__m256i __a, int __b, int const __imm) { __v16hi __c = (__v16hi)__a; __c[__imm & 15] = __b; return (__m256i)__c; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_insert_epi8(__m256i __a, int __b, int const __imm) { __v32qi __c = (__v32qi)__a; __c[__imm & 31] = __b; return (__m256i)__c; } #ifdef __x86_64__ static __inline __m256i __DEFAULT_FN_ATTRS _mm256_insert_epi64(__m256i __a, long long __b, int const __imm) { __v4di __c = (__v4di)__a; __c[__imm & 3] = __b; return (__m256i)__c; } #endif /* Conversion */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_cvtepi32_pd(__m128i __a) { return (__m256d)__builtin_ia32_cvtdq2pd256((__v4si) __a); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_cvtepi32_ps(__m256i __a) { return (__m256)__builtin_ia32_cvtdq2ps256((__v8si) __a); } static __inline __m128 __DEFAULT_FN_ATTRS _mm256_cvtpd_ps(__m256d __a) { return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a); } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_cvtps_epi32(__m256 __a) { return (__m256i)__builtin_ia32_cvtps2dq256((__v8sf) __a); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_cvtps_pd(__m128 __a) { return (__m256d)__builtin_ia32_cvtps2pd256((__v4sf) __a); } static __inline __m128i __DEFAULT_FN_ATTRS _mm256_cvttpd_epi32(__m256d __a) { return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a); } static __inline __m128i __DEFAULT_FN_ATTRS _mm256_cvtpd_epi32(__m256d __a) { return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a); } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_cvttps_epi32(__m256 __a) { return (__m256i)__builtin_ia32_cvttps2dq256((__v8sf) __a); } /* Vector replicate */ static __inline __m256 __DEFAULT_FN_ATTRS _mm256_movehdup_ps(__m256 __a) { return __builtin_shufflevector(__a, __a, 1, 1, 3, 3, 5, 5, 7, 7); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_moveldup_ps(__m256 __a) { return __builtin_shufflevector(__a, __a, 0, 0, 2, 2, 4, 4, 6, 6); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_movedup_pd(__m256d __a) { return __builtin_shufflevector(__a, __a, 0, 0, 2, 2); } /* Unpack and Interleave */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_unpackhi_pd(__m256d __a, __m256d __b) { return __builtin_shufflevector(__a, __b, 1, 5, 1+2, 5+2); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_unpacklo_pd(__m256d __a, __m256d __b) { return __builtin_shufflevector(__a, __b, 0, 4, 0+2, 4+2); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_unpackhi_ps(__m256 __a, __m256 __b) { return __builtin_shufflevector(__a, __b, 2, 10, 2+1, 10+1, 6, 14, 6+1, 14+1); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_unpacklo_ps(__m256 __a, __m256 __b) { return __builtin_shufflevector(__a, __b, 0, 8, 0+1, 8+1, 4, 12, 4+1, 12+1); } /* Bit Test */ static __inline int __DEFAULT_FN_ATTRS _mm_testz_pd(__m128d __a, __m128d __b) { return __builtin_ia32_vtestzpd((__v2df)__a, (__v2df)__b); } static __inline int __DEFAULT_FN_ATTRS _mm_testc_pd(__m128d __a, __m128d __b) { return __builtin_ia32_vtestcpd((__v2df)__a, (__v2df)__b); } static __inline int __DEFAULT_FN_ATTRS _mm_testnzc_pd(__m128d __a, __m128d __b) { return __builtin_ia32_vtestnzcpd((__v2df)__a, (__v2df)__b); } static __inline int __DEFAULT_FN_ATTRS _mm_testz_ps(__m128 __a, __m128 __b) { return __builtin_ia32_vtestzps((__v4sf)__a, (__v4sf)__b); } static __inline int __DEFAULT_FN_ATTRS _mm_testc_ps(__m128 __a, __m128 __b) { return __builtin_ia32_vtestcps((__v4sf)__a, (__v4sf)__b); } static __inline int __DEFAULT_FN_ATTRS _mm_testnzc_ps(__m128 __a, __m128 __b) { return __builtin_ia32_vtestnzcps((__v4sf)__a, (__v4sf)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testz_pd(__m256d __a, __m256d __b) { return __builtin_ia32_vtestzpd256((__v4df)__a, (__v4df)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testc_pd(__m256d __a, __m256d __b) { return __builtin_ia32_vtestcpd256((__v4df)__a, (__v4df)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testnzc_pd(__m256d __a, __m256d __b) { return __builtin_ia32_vtestnzcpd256((__v4df)__a, (__v4df)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testz_ps(__m256 __a, __m256 __b) { return __builtin_ia32_vtestzps256((__v8sf)__a, (__v8sf)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testc_ps(__m256 __a, __m256 __b) { return __builtin_ia32_vtestcps256((__v8sf)__a, (__v8sf)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testnzc_ps(__m256 __a, __m256 __b) { return __builtin_ia32_vtestnzcps256((__v8sf)__a, (__v8sf)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testz_si256(__m256i __a, __m256i __b) { return __builtin_ia32_ptestz256((__v4di)__a, (__v4di)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testc_si256(__m256i __a, __m256i __b) { return __builtin_ia32_ptestc256((__v4di)__a, (__v4di)__b); } static __inline int __DEFAULT_FN_ATTRS _mm256_testnzc_si256(__m256i __a, __m256i __b) { return __builtin_ia32_ptestnzc256((__v4di)__a, (__v4di)__b); } /* Vector extract sign mask */ static __inline int __DEFAULT_FN_ATTRS _mm256_movemask_pd(__m256d __a) { return __builtin_ia32_movmskpd256((__v4df)__a); } static __inline int __DEFAULT_FN_ATTRS _mm256_movemask_ps(__m256 __a) { return __builtin_ia32_movmskps256((__v8sf)__a); } /* Vector __zero */ static __inline void __DEFAULT_FN_ATTRS _mm256_zeroall(void) { __builtin_ia32_vzeroall(); } static __inline void __DEFAULT_FN_ATTRS _mm256_zeroupper(void) { __builtin_ia32_vzeroupper(); } /* Vector load with broadcast */ static __inline __m128 __DEFAULT_FN_ATTRS _mm_broadcast_ss(float const *__a) { float __f = *__a; return (__m128)(__v4sf){ __f, __f, __f, __f }; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_broadcast_sd(double const *__a) { double __d = *__a; return (__m256d)(__v4df){ __d, __d, __d, __d }; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_broadcast_ss(float const *__a) { float __f = *__a; return (__m256)(__v8sf){ __f, __f, __f, __f, __f, __f, __f, __f }; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_broadcast_pd(__m128d const *__a) { return (__m256d)__builtin_ia32_vbroadcastf128_pd256(__a); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_broadcast_ps(__m128 const *__a) { return (__m256)__builtin_ia32_vbroadcastf128_ps256(__a); } /* SIMD load ops */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_load_pd(double const *__p) { return *(__m256d *)__p; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_load_ps(float const *__p) { return *(__m256 *)__p; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_loadu_pd(double const *__p) { struct __loadu_pd { __m256d __v; } __attribute__((__packed__, __may_alias__)); return ((struct __loadu_pd*)__p)->__v; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_loadu_ps(float const *__p) { struct __loadu_ps { __m256 __v; } __attribute__((__packed__, __may_alias__)); return ((struct __loadu_ps*)__p)->__v; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_load_si256(__m256i const *__p) { return *__p; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_loadu_si256(__m256i const *__p) { struct __loadu_si256 { __m256i __v; } __attribute__((__packed__, __may_alias__)); return ((struct __loadu_si256*)__p)->__v; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_lddqu_si256(__m256i const *__p) { return (__m256i)__builtin_ia32_lddqu256((char const *)__p); } /* SIMD store ops */ static __inline void __DEFAULT_FN_ATTRS _mm256_store_pd(double *__p, __m256d __a) { *(__m256d *)__p = __a; } static __inline void __DEFAULT_FN_ATTRS _mm256_store_ps(float *__p, __m256 __a) { *(__m256 *)__p = __a; } static __inline void __DEFAULT_FN_ATTRS _mm256_storeu_pd(double *__p, __m256d __a) { __builtin_ia32_storeupd256(__p, (__v4df)__a); } static __inline void __DEFAULT_FN_ATTRS _mm256_storeu_ps(float *__p, __m256 __a) { __builtin_ia32_storeups256(__p, (__v8sf)__a); } static __inline void __DEFAULT_FN_ATTRS _mm256_store_si256(__m256i *__p, __m256i __a) { *__p = __a; } static __inline void __DEFAULT_FN_ATTRS _mm256_storeu_si256(__m256i *__p, __m256i __a) { __builtin_ia32_storedqu256((char *)__p, (__v32qi)__a); } /* Conditional load ops */ static __inline __m128d __DEFAULT_FN_ATTRS _mm_maskload_pd(double const *__p, __m128d __m) { return (__m128d)__builtin_ia32_maskloadpd((const __v2df *)__p, (__v2df)__m); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_maskload_pd(double const *__p, __m256d __m) { return (__m256d)__builtin_ia32_maskloadpd256((const __v4df *)__p, (__v4df)__m); } static __inline __m128 __DEFAULT_FN_ATTRS _mm_maskload_ps(float const *__p, __m128 __m) { return (__m128)__builtin_ia32_maskloadps((const __v4sf *)__p, (__v4sf)__m); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_maskload_ps(float const *__p, __m256 __m) { return (__m256)__builtin_ia32_maskloadps256((const __v8sf *)__p, (__v8sf)__m); } /* Conditional store ops */ static __inline void __DEFAULT_FN_ATTRS _mm256_maskstore_ps(float *__p, __m256 __m, __m256 __a) { __builtin_ia32_maskstoreps256((__v8sf *)__p, (__v8sf)__m, (__v8sf)__a); } static __inline void __DEFAULT_FN_ATTRS _mm_maskstore_pd(double *__p, __m128d __m, __m128d __a) { __builtin_ia32_maskstorepd((__v2df *)__p, (__v2df)__m, (__v2df)__a); } static __inline void __DEFAULT_FN_ATTRS _mm256_maskstore_pd(double *__p, __m256d __m, __m256d __a) { __builtin_ia32_maskstorepd256((__v4df *)__p, (__v4df)__m, (__v4df)__a); } static __inline void __DEFAULT_FN_ATTRS _mm_maskstore_ps(float *__p, __m128 __m, __m128 __a) { __builtin_ia32_maskstoreps((__v4sf *)__p, (__v4sf)__m, (__v4sf)__a); } /* Cacheability support ops */ static __inline void __DEFAULT_FN_ATTRS _mm256_stream_si256(__m256i *__a, __m256i __b) { __builtin_ia32_movntdq256((__v4di *)__a, (__v4di)__b); } static __inline void __DEFAULT_FN_ATTRS _mm256_stream_pd(double *__a, __m256d __b) { __builtin_ia32_movntpd256(__a, (__v4df)__b); } static __inline void __DEFAULT_FN_ATTRS _mm256_stream_ps(float *__p, __m256 __a) { __builtin_ia32_movntps256(__p, (__v8sf)__a); } /* Create vectors */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_set_pd(double __a, double __b, double __c, double __d) { return (__m256d){ __d, __c, __b, __a }; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_set_ps(float __a, float __b, float __c, float __d, float __e, float __f, float __g, float __h) { return (__m256){ __h, __g, __f, __e, __d, __c, __b, __a }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set_epi32(int __i0, int __i1, int __i2, int __i3, int __i4, int __i5, int __i6, int __i7) { return (__m256i)(__v8si){ __i7, __i6, __i5, __i4, __i3, __i2, __i1, __i0 }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set_epi16(short __w15, short __w14, short __w13, short __w12, short __w11, short __w10, short __w09, short __w08, short __w07, short __w06, short __w05, short __w04, short __w03, short __w02, short __w01, short __w00) { return (__m256i)(__v16hi){ __w00, __w01, __w02, __w03, __w04, __w05, __w06, __w07, __w08, __w09, __w10, __w11, __w12, __w13, __w14, __w15 }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set_epi8(char __b31, char __b30, char __b29, char __b28, char __b27, char __b26, char __b25, char __b24, char __b23, char __b22, char __b21, char __b20, char __b19, char __b18, char __b17, char __b16, char __b15, char __b14, char __b13, char __b12, char __b11, char __b10, char __b09, char __b08, char __b07, char __b06, char __b05, char __b04, char __b03, char __b02, char __b01, char __b00) { return (__m256i)(__v32qi){ __b00, __b01, __b02, __b03, __b04, __b05, __b06, __b07, __b08, __b09, __b10, __b11, __b12, __b13, __b14, __b15, __b16, __b17, __b18, __b19, __b20, __b21, __b22, __b23, __b24, __b25, __b26, __b27, __b28, __b29, __b30, __b31 }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set_epi64x(long long __a, long long __b, long long __c, long long __d) { return (__m256i)(__v4di){ __d, __c, __b, __a }; } /* Create vectors with elements in reverse order */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_setr_pd(double __a, double __b, double __c, double __d) { return (__m256d){ __a, __b, __c, __d }; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_setr_ps(float __a, float __b, float __c, float __d, float __e, float __f, float __g, float __h) { return (__m256){ __a, __b, __c, __d, __e, __f, __g, __h }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_setr_epi32(int __i0, int __i1, int __i2, int __i3, int __i4, int __i5, int __i6, int __i7) { return (__m256i)(__v8si){ __i0, __i1, __i2, __i3, __i4, __i5, __i6, __i7 }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_setr_epi16(short __w15, short __w14, short __w13, short __w12, short __w11, short __w10, short __w09, short __w08, short __w07, short __w06, short __w05, short __w04, short __w03, short __w02, short __w01, short __w00) { return (__m256i)(__v16hi){ __w15, __w14, __w13, __w12, __w11, __w10, __w09, __w08, __w07, __w06, __w05, __w04, __w03, __w02, __w01, __w00 }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_setr_epi8(char __b31, char __b30, char __b29, char __b28, char __b27, char __b26, char __b25, char __b24, char __b23, char __b22, char __b21, char __b20, char __b19, char __b18, char __b17, char __b16, char __b15, char __b14, char __b13, char __b12, char __b11, char __b10, char __b09, char __b08, char __b07, char __b06, char __b05, char __b04, char __b03, char __b02, char __b01, char __b00) { return (__m256i)(__v32qi){ __b31, __b30, __b29, __b28, __b27, __b26, __b25, __b24, __b23, __b22, __b21, __b20, __b19, __b18, __b17, __b16, __b15, __b14, __b13, __b12, __b11, __b10, __b09, __b08, __b07, __b06, __b05, __b04, __b03, __b02, __b01, __b00 }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_setr_epi64x(long long __a, long long __b, long long __c, long long __d) { return (__m256i)(__v4di){ __a, __b, __c, __d }; } /* Create vectors with repeated elements */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_set1_pd(double __w) { return (__m256d){ __w, __w, __w, __w }; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_set1_ps(float __w) { return (__m256){ __w, __w, __w, __w, __w, __w, __w, __w }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set1_epi32(int __i) { return (__m256i)(__v8si){ __i, __i, __i, __i, __i, __i, __i, __i }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set1_epi16(short __w) { return (__m256i)(__v16hi){ __w, __w, __w, __w, __w, __w, __w, __w, __w, __w, __w, __w, __w, __w, __w, __w }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set1_epi8(char __b) { return (__m256i)(__v32qi){ __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set1_epi64x(long long __q) { return (__m256i)(__v4di){ __q, __q, __q, __q }; } /* Create __zeroed vectors */ static __inline __m256d __DEFAULT_FN_ATTRS _mm256_setzero_pd(void) { return (__m256d){ 0, 0, 0, 0 }; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_setzero_ps(void) { return (__m256){ 0, 0, 0, 0, 0, 0, 0, 0 }; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_setzero_si256(void) { return (__m256i){ 0LL, 0LL, 0LL, 0LL }; } /* Cast between vector types */ static __inline __m256 __DEFAULT_FN_ATTRS _mm256_castpd_ps(__m256d __a) { return (__m256)__a; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_castpd_si256(__m256d __a) { return (__m256i)__a; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_castps_pd(__m256 __a) { return (__m256d)__a; } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_castps_si256(__m256 __a) { return (__m256i)__a; } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_castsi256_ps(__m256i __a) { return (__m256)__a; } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_castsi256_pd(__m256i __a) { return (__m256d)__a; } static __inline __m128d __DEFAULT_FN_ATTRS _mm256_castpd256_pd128(__m256d __a) { return __builtin_shufflevector(__a, __a, 0, 1); } static __inline __m128 __DEFAULT_FN_ATTRS _mm256_castps256_ps128(__m256 __a) { return __builtin_shufflevector(__a, __a, 0, 1, 2, 3); } static __inline __m128i __DEFAULT_FN_ATTRS _mm256_castsi256_si128(__m256i __a) { return __builtin_shufflevector(__a, __a, 0, 1); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_castpd128_pd256(__m128d __a) { return __builtin_shufflevector(__a, __a, 0, 1, -1, -1); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_castps128_ps256(__m128 __a) { return __builtin_shufflevector(__a, __a, 0, 1, 2, 3, -1, -1, -1, -1); } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_castsi128_si256(__m128i __a) { return __builtin_shufflevector(__a, __a, 0, 1, -1, -1); } /* Vector insert. We use macros rather than inlines because we only want to accept invocations where the immediate M is a constant expression. */ #define _mm256_insertf128_ps(V1, V2, M) __extension__ ({ \ (__m256)__builtin_shufflevector( \ (__v8sf)(V1), \ (__v8sf)_mm256_castps128_ps256((__m128)(V2)), \ (((M) & 1) ? 0 : 8), \ (((M) & 1) ? 1 : 9), \ (((M) & 1) ? 2 : 10), \ (((M) & 1) ? 3 : 11), \ (((M) & 1) ? 8 : 4), \ (((M) & 1) ? 9 : 5), \ (((M) & 1) ? 10 : 6), \ (((M) & 1) ? 11 : 7) );}) #define _mm256_insertf128_pd(V1, V2, M) __extension__ ({ \ (__m256d)__builtin_shufflevector( \ (__v4df)(V1), \ (__v4df)_mm256_castpd128_pd256((__m128d)(V2)), \ (((M) & 1) ? 0 : 4), \ (((M) & 1) ? 1 : 5), \ (((M) & 1) ? 4 : 2), \ (((M) & 1) ? 5 : 3) );}) #define _mm256_insertf128_si256(V1, V2, M) __extension__ ({ \ (__m256i)__builtin_shufflevector( \ (__v4di)(V1), \ (__v4di)_mm256_castsi128_si256((__m128i)(V2)), \ (((M) & 1) ? 0 : 4), \ (((M) & 1) ? 1 : 5), \ (((M) & 1) ? 4 : 2), \ (((M) & 1) ? 5 : 3) );}) /* Vector extract. We use macros rather than inlines because we only want to accept invocations where the immediate M is a constant expression. */ #define _mm256_extractf128_ps(V, M) __extension__ ({ \ (__m128)__builtin_shufflevector( \ (__v8sf)(V), \ (__v8sf)(_mm256_setzero_ps()), \ (((M) & 1) ? 4 : 0), \ (((M) & 1) ? 5 : 1), \ (((M) & 1) ? 6 : 2), \ (((M) & 1) ? 7 : 3) );}) #define _mm256_extractf128_pd(V, M) __extension__ ({ \ (__m128d)__builtin_shufflevector( \ (__v4df)(V), \ (__v4df)(_mm256_setzero_pd()), \ (((M) & 1) ? 2 : 0), \ (((M) & 1) ? 3 : 1) );}) #define _mm256_extractf128_si256(V, M) __extension__ ({ \ (__m128i)__builtin_shufflevector( \ (__v4di)(V), \ (__v4di)(_mm256_setzero_si256()), \ (((M) & 1) ? 2 : 0), \ (((M) & 1) ? 3 : 1) );}) /* SIMD load ops (unaligned) */ static __inline __m256 __DEFAULT_FN_ATTRS _mm256_loadu2_m128(float const *__addr_hi, float const *__addr_lo) { struct __loadu_ps { __m128 __v; } __attribute__((__packed__, __may_alias__)); __m256 __v256 = _mm256_castps128_ps256(((struct __loadu_ps*)__addr_lo)->__v); return _mm256_insertf128_ps(__v256, ((struct __loadu_ps*)__addr_hi)->__v, 1); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_loadu2_m128d(double const *__addr_hi, double const *__addr_lo) { struct __loadu_pd { __m128d __v; } __attribute__((__packed__, __may_alias__)); __m256d __v256 = _mm256_castpd128_pd256(((struct __loadu_pd*)__addr_lo)->__v); return _mm256_insertf128_pd(__v256, ((struct __loadu_pd*)__addr_hi)->__v, 1); } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_loadu2_m128i(__m128i const *__addr_hi, __m128i const *__addr_lo) { struct __loadu_si128 { __m128i __v; } __attribute__((__packed__, __may_alias__)); __m256i __v256 = _mm256_castsi128_si256( ((struct __loadu_si128*)__addr_lo)->__v); return _mm256_insertf128_si256(__v256, ((struct __loadu_si128*)__addr_hi)->__v, 1); } /* SIMD store ops (unaligned) */ static __inline void __DEFAULT_FN_ATTRS _mm256_storeu2_m128(float *__addr_hi, float *__addr_lo, __m256 __a) { __m128 __v128; __v128 = _mm256_castps256_ps128(__a); __builtin_ia32_storeups(__addr_lo, __v128); __v128 = _mm256_extractf128_ps(__a, 1); __builtin_ia32_storeups(__addr_hi, __v128); } static __inline void __DEFAULT_FN_ATTRS _mm256_storeu2_m128d(double *__addr_hi, double *__addr_lo, __m256d __a) { __m128d __v128; __v128 = _mm256_castpd256_pd128(__a); __builtin_ia32_storeupd(__addr_lo, __v128); __v128 = _mm256_extractf128_pd(__a, 1); __builtin_ia32_storeupd(__addr_hi, __v128); } static __inline void __DEFAULT_FN_ATTRS _mm256_storeu2_m128i(__m128i *__addr_hi, __m128i *__addr_lo, __m256i __a) { __m128i __v128; __v128 = _mm256_castsi256_si128(__a); __builtin_ia32_storedqu((char *)__addr_lo, (__v16qi)__v128); __v128 = _mm256_extractf128_si256(__a, 1); __builtin_ia32_storedqu((char *)__addr_hi, (__v16qi)__v128); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_set_m128 (__m128 __hi, __m128 __lo) { return (__m256) __builtin_shufflevector(__lo, __hi, 0, 1, 2, 3, 4, 5, 6, 7); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_set_m128d (__m128d __hi, __m128d __lo) { return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo); } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_set_m128i (__m128i __hi, __m128i __lo) { return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_setr_m128 (__m128 __lo, __m128 __hi) { return _mm256_set_m128(__hi, __lo); } static __inline __m256d __DEFAULT_FN_ATTRS _mm256_setr_m128d (__m128d __lo, __m128d __hi) { return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo); } static __inline __m256i __DEFAULT_FN_ATTRS _mm256_setr_m128i (__m128i __lo, __m128i __hi) { return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo); } #undef __DEFAULT_FN_ATTRS #endif /* __AVXINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/ammintrin.h
/*===---- ammintrin.h - SSE4a intrinsics -----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __AMMINTRIN_H #define __AMMINTRIN_H #ifndef __SSE4A__ #error "SSE4A instruction set not enabled" #else #include <pmmintrin.h> /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit /// integer vector operand at the index idx and of the length len. /// /// \headerfile <x86intrin.h> /// /// \code /// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx); /// \endcode /// /// \code /// This intrinsic corresponds to the \c EXTRQ instruction. /// \endcode /// /// \param x /// The value from which bits are extracted. /// \param len /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0] /// are zero, the length is interpreted as 64. /// \param idx /// Bits [5:0] specify the index of the least significant bit; the other /// bits are ignored. If the sum of the index and length is greater than /// 64, the result is undefined. If the length and index are both zero, /// bits [63:0] of parameter x are extracted. If the length is zero /// but the index is non-zero, the result is undefined. /// \returns A 128-bit integer vector whose lower 64 bits contain the bits /// extracted from the source operand. #define _mm_extracti_si64(x, len, idx) \ ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \ (char)(len), (char)(idx))) /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit /// integer vector operand at the index and of the length specified by __y. /// /// \headerfile <x86intrin.h> /// /// \code /// This intrinsic corresponds to the \c EXTRQ instruction. /// \endcode /// /// \param __x /// The value from which bits are extracted. /// \param __y /// Specifies the index of the least significant bit at [13:8] /// and the length at [5:0]; all other bits are ignored. /// If bits [5:0] are zero, the length is interpreted as 64. /// If the sum of the index and length is greater than 64, the result is /// undefined. If the length and index are both zero, bits [63:0] of /// parameter __x are extracted. If the length is zero but the index is /// non-zero, the result is undefined. /// \returns A 128-bit vector whose lower 64 bits contain the bits extracted /// from the source operand. static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_extract_si64(__m128i __x, __m128i __y) { return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y); } /// \brief Inserts bits of a specified length from the source integer vector /// y into the lower 64 bits of the destination integer vector x at the /// index idx and of the length len. /// /// \headerfile <x86intrin.h> /// /// \code /// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len, /// const int idx); /// \endcode /// /// \code /// This intrinsic corresponds to the \c INSERTQ instruction. /// \endcode /// /// \param x /// The destination operand where bits will be inserted. The inserted bits /// are defined by the length len and by the index idx specifying the least /// significant bit. /// \param y /// The source operand containing the bits to be extracted. The extracted /// bits are the least significant bits of operand y of length len. /// \param len /// Bits [5:0] specify the length; the other bits are ignored. If bits [5:0] /// are zero, the length is interpreted as 64. /// \param idx /// Bits [5:0] specify the index of the least significant bit; the other /// bits are ignored. If the sum of the index and length is greater than /// 64, the result is undefined. If the length and index are both zero, /// bits [63:0] of parameter y are inserted into parameter x. If the /// length is zero but the index is non-zero, the result is undefined. /// \returns A 128-bit integer vector containing the original lower 64-bits /// of destination operand x with the specified bitfields replaced by the /// lower bits of source operand y. The upper 64 bits of the return value /// are undefined. #define _mm_inserti_si64(x, y, len, idx) \ ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \ (__v2di)(__m128i)(y), \ (char)(len), (char)(idx))) /// \brief Inserts bits of a specified length from the source integer vector /// __y into the lower 64 bits of the destination integer vector __x at /// the index and of the length specified by __y. /// /// \headerfile <x86intrin.h> /// /// \code /// This intrinsic corresponds to the \c INSERTQ instruction. /// \endcode /// /// \param __x /// The destination operand where bits will be inserted. The inserted bits /// are defined by the length and by the index of the least significant bit /// specified by operand __y. /// \param __y /// The source operand containing the bits to be extracted. The extracted /// bits are the least significant bits of operand __y with length specified /// by bits [69:64]. These are inserted into the destination at the index /// specified by bits [77:72]; all other bits are ignored. /// If bits [69:64] are zero, the length is interpreted as 64. /// If the sum of the index and length is greater than 64, the result is /// undefined. If the length and index are both zero, bits [63:0] of /// parameter __y are inserted into parameter __x. If the length /// is zero but the index is non-zero, the result is undefined. /// \returns A 128-bit integer vector containing the original lower 64-bits /// of destination operand __x with the specified bitfields replaced by the /// lower bits of source operand __y. The upper 64 bits of the return value /// are undefined. static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_insert_si64(__m128i __x, __m128i __y) { return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y); } /// \brief Stores a 64-bit double-precision value in a 64-bit memory location. /// To minimize caching, the data is flagged as non-temporal (unlikely to be /// used again soon). /// /// \headerfile <x86intrin.h> /// /// \code /// This intrinsic corresponds to the \c MOVNTSD instruction. /// \endcode /// /// \param __p /// The 64-bit memory location used to store the register value. /// \param __a /// The 64-bit double-precision floating-point register value to /// be stored. static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_sd(double *__p, __m128d __a) { __builtin_ia32_movntsd(__p, (__v2df)__a); } /// \brief Stores a 32-bit single-precision floating-point value in a 32-bit /// memory location. To minimize caching, the data is flagged as /// non-temporal (unlikely to be used again soon). /// /// \headerfile <x86intrin.h> /// /// \code /// This intrinsic corresponds to the \c MOVNTSS instruction. /// \endcode /// /// \param __p /// The 32-bit memory location used to store the register value. /// \param __a /// The 32-bit single-precision floating-point register value to /// be stored. static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_ss(float *__p, __m128 __a) { __builtin_ia32_movntss(__p, (__v4sf)__a); } #undef __DEFAULT_FN_ATTRS #endif /* __SSE4A__ */ #endif /* __AMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/module.modulemap
module _Builtin_intrinsics [system] [extern_c] { explicit module altivec { requires altivec header "altivec.h" } explicit module arm { requires arm explicit module acle { header "arm_acle.h" export * } explicit module neon { requires neon header "arm_neon.h" export * } } explicit module intel { requires x86 export * header "immintrin.h" header "x86intrin.h" explicit module mm_malloc { header "mm_malloc.h" export * // note: for <stdlib.h> dependency } explicit module cpuid { requires x86 header "cpuid.h" } explicit module mmx { requires mmx header "mmintrin.h" } explicit module f16c { requires f16c header "f16cintrin.h" } explicit module sse { requires sse export mmx export sse2 // note: for hackish <emmintrin.h> dependency header "xmmintrin.h" } explicit module sse2 { requires sse2 export sse header "emmintrin.h" } explicit module sse3 { requires sse3 export sse2 header "pmmintrin.h" } explicit module ssse3 { requires ssse3 export sse3 header "tmmintrin.h" } explicit module sse4_1 { requires sse41 export ssse3 header "smmintrin.h" } explicit module sse4_2 { requires sse42 export sse4_1 header "nmmintrin.h" } explicit module sse4a { requires sse4a export sse3 header "ammintrin.h" } explicit module avx { requires avx export sse4_2 header "avxintrin.h" } explicit module avx2 { requires avx2 export avx header "avx2intrin.h" } explicit module avx512f { requires avx512f export avx2 header "avx512fintrin.h" } explicit module avx512er { requires avx512er header "avx512erintrin.h" } explicit module bmi { requires bmi header "bmiintrin.h" } explicit module bmi2 { requires bmi2 header "bmi2intrin.h" } explicit module fma { requires fma header "fmaintrin.h" } explicit module fma4 { requires fma4 export sse3 header "fma4intrin.h" } explicit module lzcnt { requires lzcnt header "lzcntintrin.h" } explicit module popcnt { requires popcnt header "popcntintrin.h" } explicit module mm3dnow { requires mm3dnow header "mm3dnow.h" } explicit module xop { requires xop export fma4 header "xopintrin.h" } explicit module aes_pclmul { requires aes, pclmul header "wmmintrin.h" export aes export pclmul } explicit module aes { requires aes header "__wmmintrin_aes.h" } explicit module pclmul { requires pclmul header "__wmmintrin_pclmul.h" } } explicit module systemz { requires systemz export * header "s390intrin.h" explicit module htm { requires htm header "htmintrin.h" header "htmxlintrin.h" } explicit module zvector { requires zvector, vx header "vecintrin.h" } } } module _Builtin_stddef_max_align_t [system] [extern_c] { header "__stddef_max_align_t.h" }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avx512vlintrin.h
/*===---- avx512vlintrin.h - AVX512VL intrinsics ---------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avx512vlintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVX512VLINTRIN_H #define __AVX512VLINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) /* Integer compare */ static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpeq_epi32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpeqd128_mask((__v4si)__a, (__v4si)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epi32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpeqd128_mask((__v4si)__a, (__v4si)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpeq_epu32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 0, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epu32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 0, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpeq_epi32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpeqd256_mask((__v8si)__a, (__v8si)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epi32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpeqd256_mask((__v8si)__a, (__v8si)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpeq_epu32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 0, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epu32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 0, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpeq_epi64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpeqq128_mask((__v2di)__a, (__v2di)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epi64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpeqq128_mask((__v2di)__a, (__v2di)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpeq_epu64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 0, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epu64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 0, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpeq_epi64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpeqq256_mask((__v4di)__a, (__v4di)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epi64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpeqq256_mask((__v4di)__a, (__v4di)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpeq_epu64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 0, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epu64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 0, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpge_epi32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epi32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpge_epu32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epu32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpge_epi32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epi32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpge_epu32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epu32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpge_epi64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epi64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpge_epu64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epu64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpge_epi64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epi64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpge_epu64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epu64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpgt_epi32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpgtd128_mask((__v4si)__a, (__v4si)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epi32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpgtd128_mask((__v4si)__a, (__v4si)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpgt_epu32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 6, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epu32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 6, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpgt_epi32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpgtd256_mask((__v8si)__a, (__v8si)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epi32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpgtd256_mask((__v8si)__a, (__v8si)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpgt_epu32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 6, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epu32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 6, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpgt_epi64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpgtq128_mask((__v2di)__a, (__v2di)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epi64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpgtq128_mask((__v2di)__a, (__v2di)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpgt_epu64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 6, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epu64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 6, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpgt_epi64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpgtq256_mask((__v4di)__a, (__v4di)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epi64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_pcmpgtq256_mask((__v4di)__a, (__v4di)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpgt_epu64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 6, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epu64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 6, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmple_epi32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmple_epi32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmple_epu32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmple_epu32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmple_epi32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epi32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmple_epu32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epu32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmple_epi64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmple_epi64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmple_epu64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmple_epu64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmple_epi64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epi64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmple_epu64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epu64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmplt_epi32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epi32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmplt_epu32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epu32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmplt_epi32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epi32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmplt_epu32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epu32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmplt_epi64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epi64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmplt_epu64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epu64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmplt_epi64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epi64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmplt_epu64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epu64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpneq_epi32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epi32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)__a, (__v4si)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpneq_epu32_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epu32_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)__a, (__v4si)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpneq_epi32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epi32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)__a, (__v8si)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpneq_epu32_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epu32_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)__a, (__v8si)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpneq_epi64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epi64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)__a, (__v2di)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpneq_epu64_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epu64_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)__a, (__v2di)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpneq_epi64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epi64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)__a, (__v4di)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_cmpneq_epu64_mask(__m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epu64_mask(__mmask8 __u, __m256i __a, __m256i __b) { return (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)__a, (__v4di)__b, 4, __u); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_add_epi32 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_add_epi32 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_add_epi64 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_add_epi64 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_sub_epi32 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_sub_epi32 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_sub_epi64 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_sub_epi64 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_add_epi32 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_add_epi32 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_add_epi64 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_add_epi64 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_sub_epi32 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_sub_epi32 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_sub_epi64 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_sub_epi64 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_mul_epi32 (__m256i __W, __mmask8 __M, __m256i __X, __m256i __Y) { return (__m256i) __builtin_ia32_pmuldq256_mask ((__v8si) __X, (__v8si) __Y, (__v4di) __W, __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_mul_epi32 (__mmask8 __M, __m256i __X, __m256i __Y) { return (__m256i) __builtin_ia32_pmuldq256_mask ((__v8si) __X, (__v8si) __Y, (__v4di) _mm256_setzero_si256 (), __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_mul_epi32 (__m128i __W, __mmask8 __M, __m128i __X, __m128i __Y) { return (__m128i) __builtin_ia32_pmuldq128_mask ((__v4si) __X, (__v4si) __Y, (__v2di) __W, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_mul_epi32 (__mmask8 __M, __m128i __X, __m128i __Y) { return (__m128i) __builtin_ia32_pmuldq128_mask ((__v4si) __X, (__v4si) __Y, (__v2di) _mm_setzero_si128 (), __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_mul_epu32 (__m256i __W, __mmask8 __M, __m256i __X, __m256i __Y) { return (__m256i) __builtin_ia32_pmuludq256_mask ((__v8si) __X, (__v8si) __Y, (__v4di) __W, __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_mul_epu32 (__mmask8 __M, __m256i __X, __m256i __Y) { return (__m256i) __builtin_ia32_pmuludq256_mask ((__v8si) __X, (__v8si) __Y, (__v4di) _mm256_setzero_si256 (), __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_mul_epu32 (__m128i __W, __mmask8 __M, __m128i __X, __m128i __Y) { return (__m128i) __builtin_ia32_pmuludq128_mask ((__v4si) __X, (__v4si) __Y, (__v2di) __W, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_mul_epu32 (__mmask8 __M, __m128i __X, __m128i __Y) { return (__m128i) __builtin_ia32_pmuludq128_mask ((__v4si) __X, (__v4si) __Y, (__v2di) _mm_setzero_si128 (), __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_mullo_epi32 (__mmask8 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmulld256_mask ((__v8si) __A, (__v8si) __B, (__v8si) _mm256_setzero_si256 (), __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_mullo_epi32 (__m256i __W, __mmask8 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmulld256_mask ((__v8si) __A, (__v8si) __B, (__v8si) __W, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_mullo_epi32 (__mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmulld128_mask ((__v4si) __A, (__v4si) __B, (__v4si) _mm_setzero_si128 (), __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_mullo_epi32 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmulld128_mask ((__v4si) __A, (__v4si) __B, (__v4si) __W, __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_and_epi32 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_and_epi32 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_and_epi32 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_and_epi32 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_andnot_epi32 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandnd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_andnot_epi32 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandnd256_mask ((__v8si) __A, (__v8si) __B, (__v8si) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_andnot_epi32 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandnd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_andnot_epi32 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandnd128_mask ((__v4si) __A, (__v4si) __B, (__v4si) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_or_epi32 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pord256_mask ((__v8si) __A, (__v8si) __B, (__v8si) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_or_epi32 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pord256_mask ((__v8si) __A, (__v8si) __B, (__v8si) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_or_epi32 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pord128_mask ((__v4si) __A, (__v4si) __B, (__v4si) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_or_epi32 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pord128_mask ((__v4si) __A, (__v4si) __B, (__v4si) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_xor_epi32 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pxord256_mask ((__v8si) __A, (__v8si) __B, (__v8si) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_xor_epi32 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pxord256_mask ((__v8si) __A, (__v8si) __B, (__v8si) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_xor_epi32 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pxord128_mask ((__v4si) __A, (__v4si) __B, (__v4si) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_xor_epi32 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pxord128_mask ((__v4si) __A, (__v4si) __B, (__v4si) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_and_epi64 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) __W, __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_and_epi64 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) _mm256_setzero_pd (), __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_and_epi64 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) __W, __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_and_epi64 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) _mm_setzero_pd (), __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_andnot_epi64 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandnq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) __W, __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_andnot_epi64 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pandnq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) _mm256_setzero_pd (), __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_andnot_epi64 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandnq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) __W, __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_andnot_epi64 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pandnq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) _mm_setzero_pd (), __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_or_epi64 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_porq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_or_epi64 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_porq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_or_epi64 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_porq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_or_epi64 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_porq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_xor_epi64 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pxorq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_xor_epi64 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pxorq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_xor_epi64 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pxorq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_xor_epi64 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pxorq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) _mm_setzero_si128 (), (__mmask8) __U); } #define _mm_cmp_epi32_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)(__m128i)(a), \ (__v4si)(__m128i)(b), \ (p), (__mmask8)-1); }) #define _mm_mask_cmp_epi32_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpd128_mask((__v4si)(__m128i)(a), \ (__v4si)(__m128i)(b), \ (p), (__mmask8)(m)); }) #define _mm_cmp_epu32_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)(__m128i)(a), \ (__v4si)(__m128i)(b), \ (p), (__mmask8)-1); }) #define _mm_mask_cmp_epu32_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpd128_mask((__v4si)(__m128i)(a), \ (__v4si)(__m128i)(b), \ (p), (__mmask8)(m)); }) #define _mm256_cmp_epi32_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)(__m256i)(a), \ (__v8si)(__m256i)(b), \ (p), (__mmask8)-1); }) #define _mm256_mask_cmp_epi32_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpd256_mask((__v8si)(__m256i)(a), \ (__v8si)(__m256i)(b), \ (p), (__mmask8)(m)); }) #define _mm256_cmp_epu32_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)(__m256i)(a), \ (__v8si)(__m256i)(b), \ (p), (__mmask8)-1); }) #define _mm256_mask_cmp_epu32_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpd256_mask((__v8si)(__m256i)(a), \ (__v8si)(__m256i)(b), \ (p), (__mmask8)(m)); }) #define _mm_cmp_epi64_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)(__m128i)(a), \ (__v2di)(__m128i)(b), \ (p), (__mmask8)-1); }) #define _mm_mask_cmp_epi64_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpq128_mask((__v2di)(__m128i)(a), \ (__v2di)(__m128i)(b), \ (p), (__mmask8)(m)); }) #define _mm_cmp_epu64_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)(__m128i)(a), \ (__v2di)(__m128i)(b), \ (p), (__mmask8)-1); }) #define _mm_mask_cmp_epu64_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpq128_mask((__v2di)(__m128i)(a), \ (__v2di)(__m128i)(b), \ (p), (__mmask8)(m)); }) #define _mm256_cmp_epi64_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)(__m256i)(a), \ (__v4di)(__m256i)(b), \ (p), (__mmask8)-1); }) #define _mm256_mask_cmp_epi64_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpq256_mask((__v4di)(__m256i)(a), \ (__v4di)(__m256i)(b), \ (p), (__mmask8)(m)); }) #define _mm256_cmp_epu64_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)(__m256i)(a), \ (__v4di)(__m256i)(b), \ (p), (__mmask8)-1); }) #define _mm256_mask_cmp_epu64_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpq256_mask((__v4di)(__m256i)(a), \ (__v4di)(__m256i)(b), \ (p), (__mmask8)(m)); }) #define _mm256_cmp_ps_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpps256_mask((__v8sf)(__m256)(a), \ (__v8sf)(__m256)(b), \ (p), (__mmask8)-1); }) #define _mm256_mask_cmp_ps_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpps256_mask((__v8sf)(__m256)(a), \ (__v8sf)(__m256)(b), \ (p), (__mmask8)(m)); }) #define _mm256_cmp_pd_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmppd256_mask((__v4df)(__m256)(a), \ (__v4df)(__m256)(b), \ (p), (__mmask8)-1); }) #define _mm256_mask_cmp_pd_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmppd256_mask((__v4df)(__m256)(a), \ (__v4df)(__m256)(b), \ (p), (__mmask8)(m)); }) #define _mm128_cmp_ps_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpps128_mask((__v4sf)(__m128)(a), \ (__v4sf)(__m128)(b), \ (p), (__mmask8)-1); }) #define _mm128_mask_cmp_ps_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpps128_mask((__v4sf)(__m128)(a), \ (__v4sf)(__m128)(b), \ (p), (__mmask8)(m)); }) #define _mm128_cmp_pd_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmppd128_mask((__v2df)(__m128)(a), \ (__v2df)(__m128)(b), \ (p), (__mmask8)-1); }) #define _mm128_mask_cmp_pd_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmppd128_mask((__v2df)(__m128)(a), \ (__v2df)(__m128)(b), \ (p), (__mmask8)(m)); }) static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_fmadd_pd(__m128d __A, __mmask8 __U, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask3_fmadd_pd(__m128d __A, __m128d __B, __m128d __C, __mmask8 __U) { return (__m128d) __builtin_ia32_vfmaddpd128_mask3 ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_fmadd_pd(__mmask8 __U, __m128d __A, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddpd128_maskz ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_fmsub_pd(__m128d __A, __mmask8 __U, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddpd128_mask ((__v2df) __A, (__v2df) __B, -(__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_fmsub_pd(__mmask8 __U, __m128d __A, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddpd128_maskz ((__v2df) __A, (__v2df) __B, -(__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask3_fnmadd_pd(__m128d __A, __m128d __B, __m128d __C, __mmask8 __U) { return (__m128d) __builtin_ia32_vfmaddpd128_mask3 (-(__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_fnmadd_pd(__mmask8 __U, __m128d __A, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddpd128_maskz (-(__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_fnmsub_pd(__mmask8 __U, __m128d __A, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddpd128_maskz (-(__v2df) __A, (__v2df) __B, -(__v2df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_fmadd_pd(__m256d __A, __mmask8 __U, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask3_fmadd_pd(__m256d __A, __m256d __B, __m256d __C, __mmask8 __U) { return (__m256d) __builtin_ia32_vfmaddpd256_mask3 ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_fmadd_pd(__mmask8 __U, __m256d __A, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddpd256_maskz ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_fmsub_pd(__m256d __A, __mmask8 __U, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddpd256_mask ((__v4df) __A, (__v4df) __B, -(__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_fmsub_pd(__mmask8 __U, __m256d __A, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddpd256_maskz ((__v4df) __A, (__v4df) __B, -(__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask3_fnmadd_pd(__m256d __A, __m256d __B, __m256d __C, __mmask8 __U) { return (__m256d) __builtin_ia32_vfmaddpd256_mask3 (-(__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_fnmadd_pd(__mmask8 __U, __m256d __A, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddpd256_maskz (-(__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_fnmsub_pd(__mmask8 __U, __m256d __A, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddpd256_maskz (-(__v4df) __A, (__v4df) __B, -(__v4df) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_fmadd_ps(__m128 __A, __mmask8 __U, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask3_fmadd_ps(__m128 __A, __m128 __B, __m128 __C, __mmask8 __U) { return (__m128) __builtin_ia32_vfmaddps128_mask3 ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_fmadd_ps(__mmask8 __U, __m128 __A, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddps128_maskz ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_fmsub_ps(__m128 __A, __mmask8 __U, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddps128_mask ((__v4sf) __A, (__v4sf) __B, -(__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_fmsub_ps(__mmask8 __U, __m128 __A, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddps128_maskz ((__v4sf) __A, (__v4sf) __B, -(__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask3_fnmadd_ps(__m128 __A, __m128 __B, __m128 __C, __mmask8 __U) { return (__m128) __builtin_ia32_vfmaddps128_mask3 (-(__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_fnmadd_ps(__mmask8 __U, __m128 __A, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddps128_maskz (-(__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_fnmsub_ps(__mmask8 __U, __m128 __A, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddps128_maskz (-(__v4sf) __A, (__v4sf) __B, -(__v4sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_fmadd_ps(__m256 __A, __mmask8 __U, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask3_fmadd_ps(__m256 __A, __m256 __B, __m256 __C, __mmask8 __U) { return (__m256) __builtin_ia32_vfmaddps256_mask3 ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_fmadd_ps(__mmask8 __U, __m256 __A, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddps256_maskz ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_fmsub_ps(__m256 __A, __mmask8 __U, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddps256_mask ((__v8sf) __A, (__v8sf) __B, -(__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_fmsub_ps(__mmask8 __U, __m256 __A, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddps256_maskz ((__v8sf) __A, (__v8sf) __B, -(__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask3_fnmadd_ps(__m256 __A, __m256 __B, __m256 __C, __mmask8 __U) { return (__m256) __builtin_ia32_vfmaddps256_mask3 (-(__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_fnmadd_ps(__mmask8 __U, __m256 __A, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddps256_maskz (-(__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_fnmsub_ps(__mmask8 __U, __m256 __A, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddps256_maskz (-(__v8sf) __A, (__v8sf) __B, -(__v8sf) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_fmaddsub_pd(__m128d __A, __mmask8 __U, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddsubpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask3_fmaddsub_pd(__m128d __A, __m128d __B, __m128d __C, __mmask8 __U) { return (__m128d) __builtin_ia32_vfmaddsubpd128_mask3 ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_fmaddsub_pd(__mmask8 __U, __m128d __A, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddsubpd128_maskz ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_fmsubadd_pd(__m128d __A, __mmask8 __U, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddsubpd128_mask ((__v2df) __A, (__v2df) __B, -(__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_fmsubadd_pd(__mmask8 __U, __m128d __A, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfmaddsubpd128_maskz ((__v2df) __A, (__v2df) __B, -(__v2df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_fmaddsub_pd(__m256d __A, __mmask8 __U, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddsubpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask3_fmaddsub_pd(__m256d __A, __m256d __B, __m256d __C, __mmask8 __U) { return (__m256d) __builtin_ia32_vfmaddsubpd256_mask3 ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_fmaddsub_pd(__mmask8 __U, __m256d __A, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddsubpd256_maskz ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_fmsubadd_pd(__m256d __A, __mmask8 __U, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddsubpd256_mask ((__v4df) __A, (__v4df) __B, -(__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_fmsubadd_pd(__mmask8 __U, __m256d __A, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfmaddsubpd256_maskz ((__v4df) __A, (__v4df) __B, -(__v4df) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_fmaddsub_ps(__m128 __A, __mmask8 __U, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddsubps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask3_fmaddsub_ps(__m128 __A, __m128 __B, __m128 __C, __mmask8 __U) { return (__m128) __builtin_ia32_vfmaddsubps128_mask3 ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_fmaddsub_ps(__mmask8 __U, __m128 __A, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddsubps128_maskz ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_fmsubadd_ps(__m128 __A, __mmask8 __U, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddsubps128_mask ((__v4sf) __A, (__v4sf) __B, -(__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_fmsubadd_ps(__mmask8 __U, __m128 __A, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfmaddsubps128_maskz ((__v4sf) __A, (__v4sf) __B, -(__v4sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_fmaddsub_ps(__m256 __A, __mmask8 __U, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddsubps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask3_fmaddsub_ps(__m256 __A, __m256 __B, __m256 __C, __mmask8 __U) { return (__m256) __builtin_ia32_vfmaddsubps256_mask3 ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_fmaddsub_ps(__mmask8 __U, __m256 __A, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddsubps256_maskz ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_fmsubadd_ps(__m256 __A, __mmask8 __U, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddsubps256_mask ((__v8sf) __A, (__v8sf) __B, -(__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_fmsubadd_ps(__mmask8 __U, __m256 __A, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfmaddsubps256_maskz ((__v8sf) __A, (__v8sf) __B, -(__v8sf) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask3_fmsub_pd(__m128d __A, __m128d __B, __m128d __C, __mmask8 __U) { return (__m128d) __builtin_ia32_vfmsubpd128_mask3 ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask3_fmsub_pd(__m256d __A, __m256d __B, __m256d __C, __mmask8 __U) { return (__m256d) __builtin_ia32_vfmsubpd256_mask3 ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask3_fmsub_ps(__m128 __A, __m128 __B, __m128 __C, __mmask8 __U) { return (__m128) __builtin_ia32_vfmsubps128_mask3 ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask3_fmsub_ps(__m256 __A, __m256 __B, __m256 __C, __mmask8 __U) { return (__m256) __builtin_ia32_vfmsubps256_mask3 ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask3_fmsubadd_pd(__m128d __A, __m128d __B, __m128d __C, __mmask8 __U) { return (__m128d) __builtin_ia32_vfmsubaddpd128_mask3 ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask3_fmsubadd_pd(__m256d __A, __m256d __B, __m256d __C, __mmask8 __U) { return (__m256d) __builtin_ia32_vfmsubaddpd256_mask3 ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask3_fmsubadd_ps(__m128 __A, __m128 __B, __m128 __C, __mmask8 __U) { return (__m128) __builtin_ia32_vfmsubaddps128_mask3 ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask3_fmsubadd_ps(__m256 __A, __m256 __B, __m256 __C, __mmask8 __U) { return (__m256) __builtin_ia32_vfmsubaddps256_mask3 ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_fnmadd_pd(__m128d __A, __mmask8 __U, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfnmaddpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_fnmadd_pd(__m256d __A, __mmask8 __U, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfnmaddpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_fnmadd_ps(__m128 __A, __mmask8 __U, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfnmaddps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_fnmadd_ps(__m256 __A, __mmask8 __U, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfnmaddps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_fnmsub_pd(__m128d __A, __mmask8 __U, __m128d __B, __m128d __C) { return (__m128d) __builtin_ia32_vfnmsubpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask3_fnmsub_pd(__m128d __A, __m128d __B, __m128d __C, __mmask8 __U) { return (__m128d) __builtin_ia32_vfnmsubpd128_mask3 ((__v2df) __A, (__v2df) __B, (__v2df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_fnmsub_pd(__m256d __A, __mmask8 __U, __m256d __B, __m256d __C) { return (__m256d) __builtin_ia32_vfnmsubpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask3_fnmsub_pd(__m256d __A, __m256d __B, __m256d __C, __mmask8 __U) { return (__m256d) __builtin_ia32_vfnmsubpd256_mask3 ((__v4df) __A, (__v4df) __B, (__v4df) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_fnmsub_ps(__m128 __A, __mmask8 __U, __m128 __B, __m128 __C) { return (__m128) __builtin_ia32_vfnmsubps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask3_fnmsub_ps(__m128 __A, __m128 __B, __m128 __C, __mmask8 __U) { return (__m128) __builtin_ia32_vfnmsubps128_mask3 ((__v4sf) __A, (__v4sf) __B, (__v4sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_fnmsub_ps(__m256 __A, __mmask8 __U, __m256 __B, __m256 __C) { return (__m256) __builtin_ia32_vfnmsubps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask3_fnmsub_ps(__m256 __A, __m256 __B, __m256 __C, __mmask8 __U) { return (__m256) __builtin_ia32_vfnmsubps256_mask3 ((__v8sf) __A, (__v8sf) __B, (__v8sf) __C, (__mmask8) __U); } #undef __DEFAULT_FN_ATTRS #endif /* __AVX512VLINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/__wmmintrin_aes.h
/*===---- __wmmintrin_aes.h - AES intrinsics -------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef _WMMINTRIN_AES_H #define _WMMINTRIN_AES_H #include <emmintrin.h> #if !defined (__AES__) # error "AES instructions not enabled" #else /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_aesenc_si128(__m128i __V, __m128i __R) { return (__m128i)__builtin_ia32_aesenc128(__V, __R); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_aesenclast_si128(__m128i __V, __m128i __R) { return (__m128i)__builtin_ia32_aesenclast128(__V, __R); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_aesdec_si128(__m128i __V, __m128i __R) { return (__m128i)__builtin_ia32_aesdec128(__V, __R); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_aesdeclast_si128(__m128i __V, __m128i __R) { return (__m128i)__builtin_ia32_aesdeclast128(__V, __R); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_aesimc_si128(__m128i __V) { return (__m128i)__builtin_ia32_aesimc128(__V); } #define _mm_aeskeygenassist_si128(C, R) \ __builtin_ia32_aeskeygenassist128((C), (R)) #undef __DEFAULT_FN_ATTRS #endif #endif /* _WMMINTRIN_AES_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/bmi2intrin.h
/*===---- bmi2intrin.h - BMI2 intrinsics -----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H #error "Never use <bmi2intrin.h> directly; include <x86intrin.h> instead." #endif #ifndef __BMI2__ # error "BMI2 instruction set not enabled" #endif /* __BMI2__ */ #ifndef __BMI2INTRIN_H #define __BMI2INTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ unsigned int __DEFAULT_FN_ATTRS _bzhi_u32(unsigned int __X, unsigned int __Y) { return __builtin_ia32_bzhi_si(__X, __Y); } static __inline__ unsigned int __DEFAULT_FN_ATTRS _pdep_u32(unsigned int __X, unsigned int __Y) { return __builtin_ia32_pdep_si(__X, __Y); } static __inline__ unsigned int __DEFAULT_FN_ATTRS _pext_u32(unsigned int __X, unsigned int __Y) { return __builtin_ia32_pext_si(__X, __Y); } #ifdef __x86_64__ static __inline__ unsigned long long __DEFAULT_FN_ATTRS _bzhi_u64(unsigned long long __X, unsigned long long __Y) { return __builtin_ia32_bzhi_di(__X, __Y); } static __inline__ unsigned long long __DEFAULT_FN_ATTRS _pdep_u64(unsigned long long __X, unsigned long long __Y) { return __builtin_ia32_pdep_di(__X, __Y); } static __inline__ unsigned long long __DEFAULT_FN_ATTRS _pext_u64(unsigned long long __X, unsigned long long __Y) { return __builtin_ia32_pext_di(__X, __Y); } static __inline__ unsigned long long __DEFAULT_FN_ATTRS _mulx_u64 (unsigned long long __X, unsigned long long __Y, unsigned long long *__P) { unsigned __int128 __res = (unsigned __int128) __X * __Y; *__P = (unsigned long long) (__res >> 64); return (unsigned long long) __res; } #else /* !__x86_64__ */ static __inline__ unsigned int __DEFAULT_FN_ATTRS _mulx_u32 (unsigned int __X, unsigned int __Y, unsigned int *__P) { unsigned long long __res = (unsigned long long) __X * __Y; *__P = (unsigned int) (__res >> 32); return (unsigned int) __res; } #endif /* !__x86_64__ */ #undef __DEFAULT_FN_ATTRS #endif /* __BMI2INTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/limits.h
/*===---- limits.h - Standard header for integer sizes --------------------===*\ * * Copyright (c) 2009 Chris Lattner * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * \*===----------------------------------------------------------------------===*/ #ifndef __CLANG_LIMITS_H #define __CLANG_LIMITS_H /* The system's limits.h may, in turn, try to #include_next GCC's limits.h. Avert this #include_next madness. */ #if defined __GNUC__ && !defined _GCC_LIMITS_H_ #define _GCC_LIMITS_H_ #endif /* System headers include a number of constants from POSIX in <limits.h>. Include it if we're hosted. */ #if __STDC_HOSTED__ && __has_include_next(<limits.h>) #include_next <limits.h> #endif /* Many system headers try to "help us out" by defining these. No really, we know how big each datatype is. */ #undef SCHAR_MIN #undef SCHAR_MAX #undef UCHAR_MAX #undef SHRT_MIN #undef SHRT_MAX #undef USHRT_MAX #undef INT_MIN #undef INT_MAX #undef UINT_MAX #undef LONG_MIN #undef LONG_MAX #undef ULONG_MAX #undef CHAR_BIT #undef CHAR_MIN #undef CHAR_MAX /* C90/99 5.2.4.2.1 */ #define SCHAR_MAX __SCHAR_MAX__ #define SHRT_MAX __SHRT_MAX__ #define INT_MAX __INT_MAX__ #define LONG_MAX __LONG_MAX__ #define SCHAR_MIN (-__SCHAR_MAX__-1) #define SHRT_MIN (-__SHRT_MAX__ -1) #define INT_MIN (-__INT_MAX__ -1) #define LONG_MIN (-__LONG_MAX__ -1L) #define UCHAR_MAX (__SCHAR_MAX__*2 +1) #define USHRT_MAX (__SHRT_MAX__ *2 +1) #define UINT_MAX (__INT_MAX__ *2U +1U) #define ULONG_MAX (__LONG_MAX__ *2UL+1UL) #ifndef MB_LEN_MAX #define MB_LEN_MAX 1 #endif #define CHAR_BIT __CHAR_BIT__ #ifdef __CHAR_UNSIGNED__ /* -funsigned-char */ #define CHAR_MIN 0 #define CHAR_MAX UCHAR_MAX #else #define CHAR_MIN SCHAR_MIN #define CHAR_MAX __SCHAR_MAX__ #endif /* C99 5.2.4.2.1: Added long long. C++11 18.3.3.2: same contents as the Standard C Library header <limits.h>. */ #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L #undef LLONG_MIN #undef LLONG_MAX #undef ULLONG_MAX #define LLONG_MAX __LONG_LONG_MAX__ #define LLONG_MIN (-__LONG_LONG_MAX__-1LL) #define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL) #endif /* LONG_LONG_MIN/LONG_LONG_MAX/ULONG_LONG_MAX are a GNU extension. It's too bad that we don't have something like #pragma poison that could be used to deprecate a macro - the code should just use LLONG_MAX and friends. */ #if defined(__GNU_LIBRARY__) ? defined(__USE_GNU) : !defined(__STRICT_ANSI__) #undef LONG_LONG_MIN #undef LONG_LONG_MAX #undef ULONG_LONG_MAX #define LONG_LONG_MAX __LONG_LONG_MAX__ #define LONG_LONG_MIN (-__LONG_LONG_MAX__-1LL) #define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL) #endif #endif /* __CLANG_LIMITS_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/stdarg.h
/*===---- stdarg.h - Variable argument handling ----------------------------=== * * Copyright (c) 2008 Eli Friedman * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __STDARG_H #define __STDARG_H #ifndef _VA_LIST typedef __builtin_va_list va_list; #define _VA_LIST #endif #define va_start(ap, param) __builtin_va_start(ap, param) #define va_end(ap) __builtin_va_end(ap) #define va_arg(ap, type) __builtin_va_arg(ap, type) /* GCC always defines __va_copy, but does not define va_copy unless in c99 mode * or -ansi is not specified, since it was not part of C90. */ #define __va_copy(d,s) __builtin_va_copy(d,s) #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L || !defined(__STRICT_ANSI__) #define va_copy(dest, src) __builtin_va_copy(dest, src) #endif /* Hack required to make standard headers work, at least on Ubuntu */ #ifndef __GNUC_VA_LIST #define __GNUC_VA_LIST 1 #endif typedef __builtin_va_list __gnuc_va_list; #endif /* __STDARG_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/stdatomic.h
/*===---- stdatomic.h - Standard header for atomic types and operations -----=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __CLANG_STDATOMIC_H #define __CLANG_STDATOMIC_H /* If we're hosted, fall back to the system's stdatomic.h. FreeBSD, for * example, already has a Clang-compatible stdatomic.h header. */ #if __STDC_HOSTED__ && __has_include_next(<stdatomic.h>) # include_next <stdatomic.h> #else #include <stddef.h> #include <stdint.h> #ifdef __cplusplus extern "C" { #endif /* 7.17.1 Introduction */ #define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE #define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE #define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE #define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE #define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE #define ATOMIC_SHORT_T_LOCK_FREE __GCC_ATOMIC_SHORT_T_LOCK_FREE #define ATOMIC_INT_T_LOCK_FREE __GCC_ATOMIC_INT_T_LOCK_FREE #define ATOMIC_LONG_T_LOCK_FREE __GCC_ATOMIC_LONG_T_LOCK_FREE #define ATOMIC_LLONG_T_LOCK_FREE __GCC_ATOMIC_LLONG_T_LOCK_FREE #define ATOMIC_POINTER_T_LOCK_FREE __GCC_ATOMIC_POINTER_T_LOCK_FREE /* 7.17.2 Initialization */ #define ATOMIC_VAR_INIT(value) (value) #define atomic_init __c11_atomic_init /* 7.17.3 Order and consistency */ typedef enum memory_order { memory_order_relaxed = __ATOMIC_RELAXED, memory_order_consume = __ATOMIC_CONSUME, memory_order_acquire = __ATOMIC_ACQUIRE, memory_order_release = __ATOMIC_RELEASE, memory_order_acq_rel = __ATOMIC_ACQ_REL, memory_order_seq_cst = __ATOMIC_SEQ_CST } memory_order; #define kill_dependency(y) (y) /* 7.17.4 Fences */ /* These should be provided by the libc implementation. */ void atomic_thread_fence(memory_order); void atomic_signal_fence(memory_order); #define atomic_thread_fence(order) __c11_atomic_thread_fence(order) #define atomic_signal_fence(order) __c11_atomic_signal_fence(order) /* 7.17.5 Lock-free property */ #define atomic_is_lock_free(obj) __c11_atomic_is_lock_free(sizeof(*(obj))) /* 7.17.6 Atomic integer types */ #ifdef __cplusplus typedef _Atomic(bool) atomic_bool; #else typedef _Atomic(_Bool) atomic_bool; #endif typedef _Atomic(char) atomic_char; typedef _Atomic(signed char) atomic_schar; typedef _Atomic(unsigned char) atomic_uchar; typedef _Atomic(short) atomic_short; typedef _Atomic(unsigned short) atomic_ushort; typedef _Atomic(int) atomic_int; typedef _Atomic(unsigned int) atomic_uint; typedef _Atomic(long) atomic_long; typedef _Atomic(unsigned long) atomic_ulong; typedef _Atomic(long long) atomic_llong; typedef _Atomic(unsigned long long) atomic_ullong; typedef _Atomic(uint_least16_t) atomic_char16_t; typedef _Atomic(uint_least32_t) atomic_char32_t; typedef _Atomic(wchar_t) atomic_wchar_t; typedef _Atomic(int_least8_t) atomic_int_least8_t; typedef _Atomic(uint_least8_t) atomic_uint_least8_t; typedef _Atomic(int_least16_t) atomic_int_least16_t; typedef _Atomic(uint_least16_t) atomic_uint_least16_t; typedef _Atomic(int_least32_t) atomic_int_least32_t; typedef _Atomic(uint_least32_t) atomic_uint_least32_t; typedef _Atomic(int_least64_t) atomic_int_least64_t; typedef _Atomic(uint_least64_t) atomic_uint_least64_t; typedef _Atomic(int_fast8_t) atomic_int_fast8_t; typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; typedef _Atomic(int_fast16_t) atomic_int_fast16_t; typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; typedef _Atomic(int_fast32_t) atomic_int_fast32_t; typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; typedef _Atomic(int_fast64_t) atomic_int_fast64_t; typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; typedef _Atomic(intptr_t) atomic_intptr_t; typedef _Atomic(uintptr_t) atomic_uintptr_t; typedef _Atomic(size_t) atomic_size_t; typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; typedef _Atomic(intmax_t) atomic_intmax_t; typedef _Atomic(uintmax_t) atomic_uintmax_t; /* 7.17.7 Operations on atomic types */ #define atomic_store(object, desired) __c11_atomic_store(object, desired, __ATOMIC_SEQ_CST) #define atomic_store_explicit __c11_atomic_store #define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST) #define atomic_load_explicit __c11_atomic_load #define atomic_exchange(object, desired) __c11_atomic_exchange(object, desired, __ATOMIC_SEQ_CST) #define atomic_exchange_explicit __c11_atomic_exchange #define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) #define atomic_compare_exchange_strong_explicit __c11_atomic_compare_exchange_strong #define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) #define atomic_compare_exchange_weak_explicit __c11_atomic_compare_exchange_weak #define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST) #define atomic_fetch_add_explicit __c11_atomic_fetch_add #define atomic_fetch_sub(object, operand) __c11_atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST) #define atomic_fetch_sub_explicit __c11_atomic_fetch_sub #define atomic_fetch_or(object, operand) __c11_atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST) #define atomic_fetch_or_explicit __c11_atomic_fetch_or #define atomic_fetch_xor(object, operand) __c11_atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST) #define atomic_fetch_xor_explicit __c11_atomic_fetch_xor #define atomic_fetch_and(object, operand) __c11_atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST) #define atomic_fetch_and_explicit __c11_atomic_fetch_and /* 7.17.8 Atomic flag type and operations */ typedef struct atomic_flag { atomic_bool _Value; } atomic_flag; #define ATOMIC_FLAG_INIT { 0 } /* These should be provided by the libc implementation. */ #ifdef __cplusplus bool atomic_flag_test_and_set(volatile atomic_flag *); bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order); #else _Bool atomic_flag_test_and_set(volatile atomic_flag *); _Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order); #endif void atomic_flag_clear(volatile atomic_flag *); void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order); #define atomic_flag_test_and_set(object) __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST) #define atomic_flag_test_and_set_explicit(object, order) __c11_atomic_exchange(&(object)->_Value, 1, order) #define atomic_flag_clear(object) __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST) #define atomic_flag_clear_explicit(object, order) __c11_atomic_store(&(object)->_Value, 0, order) #ifdef __cplusplus } #endif #endif /* __STDC_HOSTED__ */ #endif /* __CLANG_STDATOMIC_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/popcntintrin.h
/*===---- popcntintrin.h - POPCNT intrinsics -------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __POPCNT__ #error "POPCNT instruction set not enabled" #endif #ifndef _POPCNTINTRIN_H #define _POPCNTINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ int __DEFAULT_FN_ATTRS _mm_popcnt_u32(unsigned int __A) { return __builtin_popcount(__A); } #ifdef __x86_64__ static __inline__ long long __DEFAULT_FN_ATTRS _mm_popcnt_u64(unsigned long long __A) { return __builtin_popcountll(__A); } #endif /* __x86_64__ */ #undef __DEFAULT_FN_ATTRS #endif /* _POPCNTINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avx512vldqintrin.h
/*===---- avx512vldqintrin.h - AVX512VL and AVX512DQ intrinsics ---------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avx512vldqintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVX512VLDQINTRIN_H #define __AVX512VLDQINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mullo_epi64 (__m256i __A, __m256i __B) { return (__m256i) ((__v4di) __A * (__v4di) __B); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_mullo_epi64 (__m256i __W, __mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmullq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_mullo_epi64 (__mmask8 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmullq256_mask ((__v4di) __A, (__v4di) __B, (__v4di) _mm256_setzero_si256 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mullo_epi64 (__m128i __A, __m128i __B) { return (__m128i) ((__v2di) __A * (__v2di) __B); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_mullo_epi64 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmullq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_mullo_epi64 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmullq128_mask ((__v2di) __A, (__v2di) __B, (__v2di) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_andnot_pd (__m256d __W, __mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_andnpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __W, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_andnot_pd (__mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_andnpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) _mm256_setzero_pd (), (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_andnot_pd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_andnpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __W, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_andnot_pd (__mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_andnpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) _mm_setzero_pd (), (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_andnot_ps (__m256 __W, __mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_andnps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __W, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_andnot_ps (__mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_andnps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) _mm256_setzero_ps (), (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_andnot_ps (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_andnps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __W, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_andnot_ps (__mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_andnps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) _mm_setzero_ps (), (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_and_pd (__m256d __W, __mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_andpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __W, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_and_pd (__mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_andpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) _mm256_setzero_pd (), (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_and_pd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_andpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __W, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_and_pd (__mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_andpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) _mm_setzero_pd (), (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_and_ps (__m256 __W, __mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_andps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __W, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_and_ps (__mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_andps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) _mm256_setzero_ps (), (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_and_ps (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_andps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __W, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_and_ps (__mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_andps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) _mm_setzero_ps (), (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_xor_pd (__m256d __W, __mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_xorpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __W, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_xor_pd (__mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_xorpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) _mm256_setzero_pd (), (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_xor_pd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_xorpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __W, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_xor_pd (__mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_xorpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) _mm_setzero_pd (), (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_xor_ps (__m256 __W, __mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_xorps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __W, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_xor_ps (__mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_xorps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) _mm256_setzero_ps (), (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_xor_ps (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_xorps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __W, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_xor_ps (__mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_xorps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) _mm_setzero_ps (), (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_mask_or_pd (__m256d __W, __mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_orpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) __W, (__mmask8) __U); } static __inline__ __m256d __DEFAULT_FN_ATTRS _mm256_maskz_or_pd (__mmask8 __U, __m256d __A, __m256d __B) { return (__m256d) __builtin_ia32_orpd256_mask ((__v4df) __A, (__v4df) __B, (__v4df) _mm256_setzero_pd (), (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mask_or_pd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_orpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) __W, (__mmask8) __U); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_maskz_or_pd (__mmask8 __U, __m128d __A, __m128d __B) { return (__m128d) __builtin_ia32_orpd128_mask ((__v2df) __A, (__v2df) __B, (__v2df) _mm_setzero_pd (), (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_mask_or_ps (__m256 __W, __mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_orps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) __W, (__mmask8) __U); } static __inline__ __m256 __DEFAULT_FN_ATTRS _mm256_maskz_or_ps (__mmask8 __U, __m256 __A, __m256 __B) { return (__m256) __builtin_ia32_orps256_mask ((__v8sf) __A, (__v8sf) __B, (__v8sf) _mm256_setzero_ps (), (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_mask_or_ps (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_orps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) __W, (__mmask8) __U); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_maskz_or_ps (__mmask8 __U, __m128 __A, __m128 __B) { return (__m128) __builtin_ia32_orps128_mask ((__v4sf) __A, (__v4sf) __B, (__v4sf) _mm_setzero_ps (), (__mmask8) __U); } #undef __DEFAULT_FN_ATTRS #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/lzcntintrin.h
/*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H #error "Never use <lzcntintrin.h> directly; include <x86intrin.h> instead." #endif #ifndef __LZCNT__ # error "LZCNT instruction is not enabled" #endif /* __LZCNT__ */ #ifndef __LZCNTINTRIN_H #define __LZCNTINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ unsigned short __DEFAULT_FN_ATTRS __lzcnt16(unsigned short __X) { return __X ? __builtin_clzs(__X) : 16; } static __inline__ unsigned int __DEFAULT_FN_ATTRS __lzcnt32(unsigned int __X) { return __X ? __builtin_clz(__X) : 32; } static __inline__ unsigned int __DEFAULT_FN_ATTRS _lzcnt_u32(unsigned int __X) { return __X ? __builtin_clz(__X) : 32; } #ifdef __x86_64__ static __inline__ unsigned long long __DEFAULT_FN_ATTRS __lzcnt64(unsigned long long __X) { return __X ? __builtin_clzll(__X) : 64; } static __inline__ unsigned long long __DEFAULT_FN_ATTRS _lzcnt_u64(unsigned long long __X) { return __X ? __builtin_clzll(__X) : 64; } #endif #undef __DEFAULT_FN_ATTRS #endif /* __LZCNTINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/cpuid.h
/*===---- cpuid.h - X86 cpu model detection --------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if !(__x86_64__ || __i386__) #error this header is for x86 only #endif /* Responses identification request with %eax 0 */ /* AMD: "AuthenticAMD" */ #define signature_AMD_ebx 0x68747541 #define signature_AMD_edx 0x69746e65 #define signature_AMD_ecx 0x444d4163 /* CENTAUR: "CentaurHauls" */ #define signature_CENTAUR_ebx 0x746e6543 #define signature_CENTAUR_edx 0x48727561 #define signature_CENTAUR_ecx 0x736c7561 /* CYRIX: "CyrixInstead" */ #define signature_CYRIX_ebx 0x69727943 #define signature_CYRIX_edx 0x736e4978 #define signature_CYRIX_ecx 0x64616574 /* INTEL: "GenuineIntel" */ #define signature_INTEL_ebx 0x756e6547 #define signature_INTEL_edx 0x49656e69 #define signature_INTEL_ecx 0x6c65746e /* TM1: "TransmetaCPU" */ #define signature_TM1_ebx 0x6e617254 #define signature_TM1_edx 0x74656d73 #define signature_TM1_ecx 0x55504361 /* TM2: "GenuineTMx86" */ #define signature_TM2_ebx 0x756e6547 #define signature_TM2_edx 0x54656e69 #define signature_TM2_ecx 0x3638784d /* NSC: "Geode by NSC" */ #define signature_NSC_ebx 0x646f6547 #define signature_NSC_edx 0x43534e20 #define signature_NSC_ecx 0x79622065 /* NEXGEN: "NexGenDriven" */ #define signature_NEXGEN_ebx 0x4778654e #define signature_NEXGEN_edx 0x72446e65 #define signature_NEXGEN_ecx 0x6e657669 /* RISE: "RiseRiseRise" */ #define signature_RISE_ebx 0x65736952 #define signature_RISE_edx 0x65736952 #define signature_RISE_ecx 0x65736952 /* SIS: "SiS SiS SiS " */ #define signature_SIS_ebx 0x20536953 #define signature_SIS_edx 0x20536953 #define signature_SIS_ecx 0x20536953 /* UMC: "UMC UMC UMC " */ #define signature_UMC_ebx 0x20434d55 #define signature_UMC_edx 0x20434d55 #define signature_UMC_ecx 0x20434d55 /* VIA: "VIA VIA VIA " */ #define signature_VIA_ebx 0x20414956 #define signature_VIA_edx 0x20414956 #define signature_VIA_ecx 0x20414956 /* VORTEX: "Vortex86 SoC" */ #define signature_VORTEX_ebx 0x74726f56 #define signature_VORTEX_edx 0x36387865 #define signature_VORTEX_ecx 0x436f5320 /* Features in %ecx for level 1 */ #define bit_SSE3 0x00000001 #define bit_PCLMULQDQ 0x00000002 #define bit_DTES64 0x00000004 #define bit_MONITOR 0x00000008 #define bit_DSCPL 0x00000010 #define bit_VMX 0x00000020 #define bit_SMX 0x00000040 #define bit_EIST 0x00000080 #define bit_TM2 0x00000100 #define bit_SSSE3 0x00000200 #define bit_CNXTID 0x00000400 #define bit_FMA 0x00001000 #define bit_CMPXCHG16B 0x00002000 #define bit_xTPR 0x00004000 #define bit_PDCM 0x00008000 #define bit_PCID 0x00020000 #define bit_DCA 0x00040000 #define bit_SSE41 0x00080000 #define bit_SSE42 0x00100000 #define bit_x2APIC 0x00200000 #define bit_MOVBE 0x00400000 #define bit_POPCNT 0x00800000 #define bit_TSCDeadline 0x01000000 #define bit_AESNI 0x02000000 #define bit_XSAVE 0x04000000 #define bit_OSXSAVE 0x08000000 #define bit_AVX 0x10000000 #define bit_RDRND 0x40000000 /* Features in %edx for level 1 */ #define bit_FPU 0x00000001 #define bit_VME 0x00000002 #define bit_DE 0x00000004 #define bit_PSE 0x00000008 #define bit_TSC 0x00000010 #define bit_MSR 0x00000020 #define bit_PAE 0x00000040 #define bit_MCE 0x00000080 #define bit_CX8 0x00000100 #define bit_APIC 0x00000200 #define bit_SEP 0x00000800 #define bit_MTRR 0x00001000 #define bit_PGE 0x00002000 #define bit_MCA 0x00004000 #define bit_CMOV 0x00008000 #define bit_PAT 0x00010000 #define bit_PSE36 0x00020000 #define bit_PSN 0x00040000 #define bit_CLFSH 0x00080000 #define bit_DS 0x00200000 #define bit_ACPI 0x00400000 #define bit_MMX 0x00800000 #define bit_FXSR 0x01000000 #define bit_FXSAVE bit_FXSR /* for gcc compat */ #define bit_SSE 0x02000000 #define bit_SSE2 0x04000000 #define bit_SS 0x08000000 #define bit_HTT 0x10000000 #define bit_TM 0x20000000 #define bit_PBE 0x80000000 /* Features in %ebx for level 7 sub-leaf 0 */ #define bit_FSGSBASE 0x00000001 #define bit_SMEP 0x00000080 #define bit_ENH_MOVSB 0x00000200 #if __i386__ #define __cpuid(__level, __eax, __ebx, __ecx, __edx) \ __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \ : "0"(__level)) #define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \ __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \ : "0"(__level), "2"(__count)) #else /* x86-64 uses %rbx as the base register, so preserve it. */ #define __cpuid(__level, __eax, __ebx, __ecx, __edx) \ __asm(" xchgq %%rbx,%q1\n" \ " cpuid\n" \ " xchgq %%rbx,%q1" \ : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \ : "0"(__level)) #define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \ __asm(" xchgq %%rbx,%q1\n" \ " cpuid\n" \ " xchgq %%rbx,%q1" \ : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \ : "0"(__level), "2"(__count)) #endif static __inline int __get_cpuid (unsigned int __level, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx) { __cpuid(__level, *__eax, *__ebx, *__ecx, *__edx); return 1; } static __inline int __get_cpuid_max (unsigned int __level, unsigned int *__sig) { unsigned int __eax, __ebx, __ecx, __edx; #if __i386__ int __cpuid_supported; __asm(" pushfl\n" " popl %%eax\n" " movl %%eax,%%ecx\n" " xorl $0x00200000,%%eax\n" " pushl %%eax\n" " popfl\n" " pushfl\n" " popl %%eax\n" " movl $0,%0\n" " cmpl %%eax,%%ecx\n" " je 1f\n" " movl $1,%0\n" "1:" : "=r" (__cpuid_supported) : : "eax", "ecx"); if (!__cpuid_supported) return 0; #endif __cpuid(__level, __eax, __ebx, __ecx, __edx); if (__sig) *__sig = __ebx; return __eax; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/prfchwintrin.h
/*===---- prfchwintrin.h - PREFETCHW intrinsic -----------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if !defined(__X86INTRIN_H) && !defined(_MM3DNOW_H_INCLUDED) #error "Never use <prfchwintrin.h> directly; include <x86intrin.h> or <mm3dnow.h> instead." #endif #ifndef __PRFCHWINTRIN_H #define __PRFCHWINTRIN_H #if defined(__PRFCHW__) || defined(__3dNOW__) static __inline__ void __attribute__((__always_inline__, __nodebug__)) _m_prefetchw(void *__P) { __builtin_prefetch (__P, 1, 3 /* _MM_HINT_T0 */); } #endif #endif /* __PRFCHWINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/smmintrin.h
/*===---- smmintrin.h - SSE4 intrinsics ------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef _SMMINTRIN_H #define _SMMINTRIN_H #ifndef __SSE4_1__ #error "SSE4.1 instruction set not enabled" #else #include <tmmintrin.h> /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) /* SSE4 Rounding macros. */ #define _MM_FROUND_TO_NEAREST_INT 0x00 #define _MM_FROUND_TO_NEG_INF 0x01 #define _MM_FROUND_TO_POS_INF 0x02 #define _MM_FROUND_TO_ZERO 0x03 #define _MM_FROUND_CUR_DIRECTION 0x04 #define _MM_FROUND_RAISE_EXC 0x00 #define _MM_FROUND_NO_EXC 0x08 #define _MM_FROUND_NINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEAREST_INT) #define _MM_FROUND_FLOOR (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEG_INF) #define _MM_FROUND_CEIL (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_POS_INF) #define _MM_FROUND_TRUNC (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_ZERO) #define _MM_FROUND_RINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION) #define _MM_FROUND_NEARBYINT (_MM_FROUND_NO_EXC | _MM_FROUND_CUR_DIRECTION) #define _mm_ceil_ps(X) _mm_round_ps((X), _MM_FROUND_CEIL) #define _mm_ceil_pd(X) _mm_round_pd((X), _MM_FROUND_CEIL) #define _mm_ceil_ss(X, Y) _mm_round_ss((X), (Y), _MM_FROUND_CEIL) #define _mm_ceil_sd(X, Y) _mm_round_sd((X), (Y), _MM_FROUND_CEIL) #define _mm_floor_ps(X) _mm_round_ps((X), _MM_FROUND_FLOOR) #define _mm_floor_pd(X) _mm_round_pd((X), _MM_FROUND_FLOOR) #define _mm_floor_ss(X, Y) _mm_round_ss((X), (Y), _MM_FROUND_FLOOR) #define _mm_floor_sd(X, Y) _mm_round_sd((X), (Y), _MM_FROUND_FLOOR) #define _mm_round_ps(X, M) __extension__ ({ \ __m128 __X = (X); \ (__m128) __builtin_ia32_roundps((__v4sf)__X, (M)); }) #define _mm_round_ss(X, Y, M) __extension__ ({ \ __m128 __X = (X); \ __m128 __Y = (Y); \ (__m128) __builtin_ia32_roundss((__v4sf)__X, (__v4sf)__Y, (M)); }) #define _mm_round_pd(X, M) __extension__ ({ \ __m128d __X = (X); \ (__m128d) __builtin_ia32_roundpd((__v2df)__X, (M)); }) #define _mm_round_sd(X, Y, M) __extension__ ({ \ __m128d __X = (X); \ __m128d __Y = (Y); \ (__m128d) __builtin_ia32_roundsd((__v2df)__X, (__v2df)__Y, (M)); }) /* SSE4 Packed Blending Intrinsics. */ #define _mm_blend_pd(V1, V2, M) __extension__ ({ \ __m128d __V1 = (V1); \ __m128d __V2 = (V2); \ (__m128d)__builtin_shufflevector((__v2df)__V1, (__v2df)__V2, \ (((M) & 0x01) ? 2 : 0), \ (((M) & 0x02) ? 3 : 1)); }) #define _mm_blend_ps(V1, V2, M) __extension__ ({ \ __m128 __V1 = (V1); \ __m128 __V2 = (V2); \ (__m128)__builtin_shufflevector((__v4sf)__V1, (__v4sf)__V2, \ (((M) & 0x01) ? 4 : 0), \ (((M) & 0x02) ? 5 : 1), \ (((M) & 0x04) ? 6 : 2), \ (((M) & 0x08) ? 7 : 3)); }) static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_blendv_pd (__m128d __V1, __m128d __V2, __m128d __M) { return (__m128d) __builtin_ia32_blendvpd ((__v2df)__V1, (__v2df)__V2, (__v2df)__M); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_blendv_ps (__m128 __V1, __m128 __V2, __m128 __M) { return (__m128) __builtin_ia32_blendvps ((__v4sf)__V1, (__v4sf)__V2, (__v4sf)__M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_blendv_epi8 (__m128i __V1, __m128i __V2, __m128i __M) { return (__m128i) __builtin_ia32_pblendvb128 ((__v16qi)__V1, (__v16qi)__V2, (__v16qi)__M); } #define _mm_blend_epi16(V1, V2, M) __extension__ ({ \ __m128i __V1 = (V1); \ __m128i __V2 = (V2); \ (__m128i)__builtin_shufflevector((__v8hi)__V1, (__v8hi)__V2, \ (((M) & 0x01) ? 8 : 0), \ (((M) & 0x02) ? 9 : 1), \ (((M) & 0x04) ? 10 : 2), \ (((M) & 0x08) ? 11 : 3), \ (((M) & 0x10) ? 12 : 4), \ (((M) & 0x20) ? 13 : 5), \ (((M) & 0x40) ? 14 : 6), \ (((M) & 0x80) ? 15 : 7)); }) /* SSE4 Dword Multiply Instructions. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mullo_epi32 (__m128i __V1, __m128i __V2) { return (__m128i) ((__v4si)__V1 * (__v4si)__V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mul_epi32 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pmuldq128 ((__v4si)__V1, (__v4si)__V2); } /* SSE4 Floating Point Dot Product Instructions. */ #define _mm_dp_ps(X, Y, M) __extension__ ({ \ __m128 __X = (X); \ __m128 __Y = (Y); \ (__m128) __builtin_ia32_dpps((__v4sf)__X, (__v4sf)__Y, (M)); }) #define _mm_dp_pd(X, Y, M) __extension__ ({\ __m128d __X = (X); \ __m128d __Y = (Y); \ (__m128d) __builtin_ia32_dppd((__v2df)__X, (__v2df)__Y, (M)); }) /* SSE4 Streaming Load Hint Instruction. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_stream_load_si128 (__m128i *__V) { return (__m128i) __builtin_ia32_movntdqa ((__v2di *) __V); } /* SSE4 Packed Integer Min/Max Instructions. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epi8 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pminsb128 ((__v16qi) __V1, (__v16qi) __V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epi8 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pmaxsb128 ((__v16qi) __V1, (__v16qi) __V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epu16 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pminuw128 ((__v8hi) __V1, (__v8hi) __V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epu16 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pmaxuw128 ((__v8hi) __V1, (__v8hi) __V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epi32 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pminsd128 ((__v4si) __V1, (__v4si) __V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epi32 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pmaxsd128 ((__v4si) __V1, (__v4si) __V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epu32 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pminud128((__v4si) __V1, (__v4si) __V2); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epu32 (__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_pmaxud128((__v4si) __V1, (__v4si) __V2); } /* SSE4 Insertion and Extraction from XMM Register Instructions. */ #define _mm_insert_ps(X, Y, N) __builtin_ia32_insertps128((X), (Y), (N)) #define _mm_extract_ps(X, N) (__extension__ \ ({ union { int __i; float __f; } __t; \ __v4sf __a = (__v4sf)(X); \ __t.__f = __a[(N) & 3]; \ __t.__i;})) /* Miscellaneous insert and extract macros. */ /* Extract a single-precision float from X at index N into D. */ #define _MM_EXTRACT_FLOAT(D, X, N) (__extension__ ({ __v4sf __a = (__v4sf)(X); \ (D) = __a[N]; })) /* Or together 2 sets of indexes (X and Y) with the zeroing bits (Z) to create an index suitable for _mm_insert_ps. */ #define _MM_MK_INSERTPS_NDX(X, Y, Z) (((X) << 6) | ((Y) << 4) | (Z)) /* Extract a float from X at index N into the first index of the return. */ #define _MM_PICK_OUT_PS(X, N) _mm_insert_ps (_mm_setzero_ps(), (X), \ _MM_MK_INSERTPS_NDX((N), 0, 0x0e)) /* Insert int into packed integer array at index. */ #define _mm_insert_epi8(X, I, N) (__extension__ ({ __v16qi __a = (__v16qi)(X); \ __a[(N) & 15] = (I); \ __a;})) #define _mm_insert_epi32(X, I, N) (__extension__ ({ __v4si __a = (__v4si)(X); \ __a[(N) & 3] = (I); \ __a;})) #ifdef __x86_64__ #define _mm_insert_epi64(X, I, N) (__extension__ ({ __v2di __a = (__v2di)(X); \ __a[(N) & 1] = (I); \ __a;})) #endif /* __x86_64__ */ /* Extract int from packed integer array at index. This returns the element * as a zero extended value, so it is unsigned. */ #define _mm_extract_epi8(X, N) (__extension__ ({ __v16qi __a = (__v16qi)(X); \ (int)(unsigned char) \ __a[(N) & 15];})) #define _mm_extract_epi32(X, N) (__extension__ ({ __v4si __a = (__v4si)(X); \ __a[(N) & 3];})) #ifdef __x86_64__ #define _mm_extract_epi64(X, N) (__extension__ ({ __v2di __a = (__v2di)(X); \ __a[(N) & 1];})) #endif /* __x86_64 */ /* SSE4 128-bit Packed Integer Comparisons. */ static __inline__ int __DEFAULT_FN_ATTRS _mm_testz_si128(__m128i __M, __m128i __V) { return __builtin_ia32_ptestz128((__v2di)__M, (__v2di)__V); } static __inline__ int __DEFAULT_FN_ATTRS _mm_testc_si128(__m128i __M, __m128i __V) { return __builtin_ia32_ptestc128((__v2di)__M, (__v2di)__V); } static __inline__ int __DEFAULT_FN_ATTRS _mm_testnzc_si128(__m128i __M, __m128i __V) { return __builtin_ia32_ptestnzc128((__v2di)__M, (__v2di)__V); } #define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_cmpeq_epi32((V), (V))) #define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128((M), (V)) #define _mm_test_all_zeros(M, V) _mm_testz_si128 ((M), (V)) /* SSE4 64-bit Packed Integer Comparisons. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpeq_epi64(__m128i __V1, __m128i __V2) { return (__m128i)((__v2di)__V1 == (__v2di)__V2); } /* SSE4 Packed Integer Sign-Extension. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi8_epi16(__m128i __V) { return (__m128i) __builtin_ia32_pmovsxbw128((__v16qi) __V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi8_epi32(__m128i __V) { return (__m128i) __builtin_ia32_pmovsxbd128((__v16qi) __V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi8_epi64(__m128i __V) { return (__m128i) __builtin_ia32_pmovsxbq128((__v16qi) __V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi16_epi32(__m128i __V) { return (__m128i) __builtin_ia32_pmovsxwd128((__v8hi) __V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi16_epi64(__m128i __V) { return (__m128i) __builtin_ia32_pmovsxwq128((__v8hi)__V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi32_epi64(__m128i __V) { return (__m128i) __builtin_ia32_pmovsxdq128((__v4si)__V); } /* SSE4 Packed Integer Zero-Extension. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu8_epi16(__m128i __V) { return (__m128i) __builtin_ia32_pmovzxbw128((__v16qi) __V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu8_epi32(__m128i __V) { return (__m128i) __builtin_ia32_pmovzxbd128((__v16qi)__V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu8_epi64(__m128i __V) { return (__m128i) __builtin_ia32_pmovzxbq128((__v16qi)__V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu16_epi32(__m128i __V) { return (__m128i) __builtin_ia32_pmovzxwd128((__v8hi)__V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu16_epi64(__m128i __V) { return (__m128i) __builtin_ia32_pmovzxwq128((__v8hi)__V); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu32_epi64(__m128i __V) { return (__m128i) __builtin_ia32_pmovzxdq128((__v4si)__V); } /* SSE4 Pack with Unsigned Saturation. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_packus_epi32(__m128i __V1, __m128i __V2) { return (__m128i) __builtin_ia32_packusdw128((__v4si)__V1, (__v4si)__V2); } /* SSE4 Multiple Packed Sums of Absolute Difference. */ #define _mm_mpsadbw_epu8(X, Y, M) __extension__ ({ \ __m128i __X = (X); \ __m128i __Y = (Y); \ (__m128i) __builtin_ia32_mpsadbw128((__v16qi)__X, (__v16qi)__Y, (M)); }) static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_minpos_epu16(__m128i __V) { return (__m128i) __builtin_ia32_phminposuw128((__v8hi)__V); } /* These definitions are normally in nmmintrin.h, but gcc puts them in here so we'll do the same. */ #ifdef __SSE4_2__ /* These specify the type of data that we're comparing. */ #define _SIDD_UBYTE_OPS 0x00 #define _SIDD_UWORD_OPS 0x01 #define _SIDD_SBYTE_OPS 0x02 #define _SIDD_SWORD_OPS 0x03 /* These specify the type of comparison operation. */ #define _SIDD_CMP_EQUAL_ANY 0x00 #define _SIDD_CMP_RANGES 0x04 #define _SIDD_CMP_EQUAL_EACH 0x08 #define _SIDD_CMP_EQUAL_ORDERED 0x0c /* These macros specify the polarity of the operation. */ #define _SIDD_POSITIVE_POLARITY 0x00 #define _SIDD_NEGATIVE_POLARITY 0x10 #define _SIDD_MASKED_POSITIVE_POLARITY 0x20 #define _SIDD_MASKED_NEGATIVE_POLARITY 0x30 /* These macros are used in _mm_cmpXstri() to specify the return. */ #define _SIDD_LEAST_SIGNIFICANT 0x00 #define _SIDD_MOST_SIGNIFICANT 0x40 /* These macros are used in _mm_cmpXstri() to specify the return. */ #define _SIDD_BIT_MASK 0x00 #define _SIDD_UNIT_MASK 0x40 /* SSE4.2 Packed Comparison Intrinsics. */ #define _mm_cmpistrm(A, B, M) __builtin_ia32_pcmpistrm128((A), (B), (M)) #define _mm_cmpistri(A, B, M) __builtin_ia32_pcmpistri128((A), (B), (M)) #define _mm_cmpestrm(A, LA, B, LB, M) \ __builtin_ia32_pcmpestrm128((A), (LA), (B), (LB), (M)) #define _mm_cmpestri(A, LA, B, LB, M) \ __builtin_ia32_pcmpestri128((A), (LA), (B), (LB), (M)) /* SSE4.2 Packed Comparison Intrinsics and EFlag Reading. */ #define _mm_cmpistra(A, B, M) \ __builtin_ia32_pcmpistria128((A), (B), (M)) #define _mm_cmpistrc(A, B, M) \ __builtin_ia32_pcmpistric128((A), (B), (M)) #define _mm_cmpistro(A, B, M) \ __builtin_ia32_pcmpistrio128((A), (B), (M)) #define _mm_cmpistrs(A, B, M) \ __builtin_ia32_pcmpistris128((A), (B), (M)) #define _mm_cmpistrz(A, B, M) \ __builtin_ia32_pcmpistriz128((A), (B), (M)) #define _mm_cmpestra(A, LA, B, LB, M) \ __builtin_ia32_pcmpestria128((A), (LA), (B), (LB), (M)) #define _mm_cmpestrc(A, LA, B, LB, M) \ __builtin_ia32_pcmpestric128((A), (LA), (B), (LB), (M)) #define _mm_cmpestro(A, LA, B, LB, M) \ __builtin_ia32_pcmpestrio128((A), (LA), (B), (LB), (M)) #define _mm_cmpestrs(A, LA, B, LB, M) \ __builtin_ia32_pcmpestris128((A), (LA), (B), (LB), (M)) #define _mm_cmpestrz(A, LA, B, LB, M) \ __builtin_ia32_pcmpestriz128((A), (LA), (B), (LB), (M)) /* SSE4.2 Compare Packed Data -- Greater Than. */ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpgt_epi64(__m128i __V1, __m128i __V2) { return (__m128i)((__v2di)__V1 > (__v2di)__V2); } /* SSE4.2 Accumulate CRC32. */ static __inline__ unsigned int __DEFAULT_FN_ATTRS _mm_crc32_u8(unsigned int __C, unsigned char __D) { return __builtin_ia32_crc32qi(__C, __D); } static __inline__ unsigned int __DEFAULT_FN_ATTRS _mm_crc32_u16(unsigned int __C, unsigned short __D) { return __builtin_ia32_crc32hi(__C, __D); } static __inline__ unsigned int __DEFAULT_FN_ATTRS _mm_crc32_u32(unsigned int __C, unsigned int __D) { return __builtin_ia32_crc32si(__C, __D); } #ifdef __x86_64__ static __inline__ unsigned long long __DEFAULT_FN_ATTRS _mm_crc32_u64(unsigned long long __C, unsigned long long __D) { return __builtin_ia32_crc32di(__C, __D); } #endif /* __x86_64__ */ #undef __DEFAULT_FN_ATTRS #ifdef __POPCNT__ #include <popcntintrin.h> #endif #endif /* __SSE4_2__ */ #endif /* __SSE4_1__ */ #endif /* _SMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/shaintrin.h
/*===---- shaintrin.h - SHA intrinsics -------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <shaintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __SHAINTRIN_H #define __SHAINTRIN_H #if !defined (__SHA__) # error "SHA instructions not enabled" #endif /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) #define _mm_sha1rnds4_epu32(V1, V2, M) __extension__ ({ \ __builtin_ia32_sha1rnds4((V1), (V2), (M)); }) static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha1nexte_epu32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_sha1nexte((__v4si)__X, (__v4si)__Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha1msg1_epu32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_sha1msg1((__v4si)__X, (__v4si)__Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha1msg2_epu32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_sha1msg2((__v4si)__X, (__v4si)__Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha256rnds2_epu32(__m128i __X, __m128i __Y, __m128i __Z) { return (__m128i)__builtin_ia32_sha256rnds2((__v4si)__X, (__v4si)__Y, (__v4si)__Z); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha256msg1_epu32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_sha256msg1((__v4si)__X, (__v4si)__Y); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha256msg2_epu32(__m128i __X, __m128i __Y) { return (__m128i)__builtin_ia32_sha256msg2((__v4si)__X, (__v4si)__Y); } #undef __DEFAULT_FN_ATTRS #endif /* __SHAINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/emmintrin.h
/*===---- emmintrin.h - SSE2 intrinsics ------------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __EMMINTRIN_H #define __EMMINTRIN_H #ifndef __SSE2__ #error "SSE2 instruction set not enabled" #else #include <xmmintrin.h> typedef double __m128d __attribute__((__vector_size__(16))); typedef long long __m128i __attribute__((__vector_size__(16))); /* Type defines. */ typedef double __v2df __attribute__ ((__vector_size__ (16))); typedef long long __v2di __attribute__ ((__vector_size__ (16))); typedef short __v8hi __attribute__((__vector_size__(16))); typedef char __v16qi __attribute__((__vector_size__(16))); /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_add_sd(__m128d __a, __m128d __b) { __a[0] += __b[0]; return __a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_add_pd(__m128d __a, __m128d __b) { return __a + __b; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_sub_sd(__m128d __a, __m128d __b) { __a[0] -= __b[0]; return __a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_sub_pd(__m128d __a, __m128d __b) { return __a - __b; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mul_sd(__m128d __a, __m128d __b) { __a[0] *= __b[0]; return __a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_mul_pd(__m128d __a, __m128d __b) { return __a * __b; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_div_sd(__m128d __a, __m128d __b) { __a[0] /= __b[0]; return __a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_div_pd(__m128d __a, __m128d __b) { return __a / __b; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_sqrt_sd(__m128d __a, __m128d __b) { __m128d __c = __builtin_ia32_sqrtsd(__b); return (__m128d) { __c[0], __a[1] }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_sqrt_pd(__m128d __a) { return __builtin_ia32_sqrtpd(__a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_min_sd(__m128d __a, __m128d __b) { return __builtin_ia32_minsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_min_pd(__m128d __a, __m128d __b) { return __builtin_ia32_minpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_max_sd(__m128d __a, __m128d __b) { return __builtin_ia32_maxsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_max_pd(__m128d __a, __m128d __b) { return __builtin_ia32_maxpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_and_pd(__m128d __a, __m128d __b) { return (__m128d)((__v4si)__a & (__v4si)__b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_andnot_pd(__m128d __a, __m128d __b) { return (__m128d)(~(__v4si)__a & (__v4si)__b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_or_pd(__m128d __a, __m128d __b) { return (__m128d)((__v4si)__a | (__v4si)__b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_xor_pd(__m128d __a, __m128d __b) { return (__m128d)((__v4si)__a ^ (__v4si)__b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpeq_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpeqpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmplt_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpltpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmple_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmplepd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpgt_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpltpd(__b, __a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpge_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmplepd(__b, __a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpord_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpordpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpunord_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpunordpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpneq_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpneqpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnlt_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpnltpd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnle_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpnlepd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpngt_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpnltpd(__b, __a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnge_pd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpnlepd(__b, __a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpeq_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpeqsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmplt_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpltsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmple_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmplesd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpgt_sd(__m128d __a, __m128d __b) { __m128d __c = __builtin_ia32_cmpltsd(__b, __a); return (__m128d) { __c[0], __a[1] }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpge_sd(__m128d __a, __m128d __b) { __m128d __c = __builtin_ia32_cmplesd(__b, __a); return (__m128d) { __c[0], __a[1] }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpord_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpordsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpunord_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpunordsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpneq_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpneqsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnlt_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpnltsd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnle_sd(__m128d __a, __m128d __b) { return (__m128d)__builtin_ia32_cmpnlesd(__a, __b); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpngt_sd(__m128d __a, __m128d __b) { __m128d __c = __builtin_ia32_cmpnltsd(__b, __a); return (__m128d) { __c[0], __a[1] }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cmpnge_sd(__m128d __a, __m128d __b) { __m128d __c = __builtin_ia32_cmpnlesd(__b, __a); return (__m128d) { __c[0], __a[1] }; } static __inline__ int __DEFAULT_FN_ATTRS _mm_comieq_sd(__m128d __a, __m128d __b) { return __builtin_ia32_comisdeq(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comilt_sd(__m128d __a, __m128d __b) { return __builtin_ia32_comisdlt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comile_sd(__m128d __a, __m128d __b) { return __builtin_ia32_comisdle(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comigt_sd(__m128d __a, __m128d __b) { return __builtin_ia32_comisdgt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comige_sd(__m128d __a, __m128d __b) { return __builtin_ia32_comisdge(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_comineq_sd(__m128d __a, __m128d __b) { return __builtin_ia32_comisdneq(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomieq_sd(__m128d __a, __m128d __b) { return __builtin_ia32_ucomisdeq(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomilt_sd(__m128d __a, __m128d __b) { return __builtin_ia32_ucomisdlt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomile_sd(__m128d __a, __m128d __b) { return __builtin_ia32_ucomisdle(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomigt_sd(__m128d __a, __m128d __b) { return __builtin_ia32_ucomisdgt(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomige_sd(__m128d __a, __m128d __b) { return __builtin_ia32_ucomisdge(__a, __b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_ucomineq_sd(__m128d __a, __m128d __b) { return __builtin_ia32_ucomisdneq(__a, __b); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtpd_ps(__m128d __a) { return __builtin_ia32_cvtpd2ps(__a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtps_pd(__m128 __a) { return __builtin_ia32_cvtps2pd(__a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtepi32_pd(__m128i __a) { return __builtin_ia32_cvtdq2pd((__v4si)__a); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtpd_epi32(__m128d __a) { return __builtin_ia32_cvtpd2dq(__a); } static __inline__ int __DEFAULT_FN_ATTRS _mm_cvtsd_si32(__m128d __a) { return __builtin_ia32_cvtsd2si(__a); } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtsd_ss(__m128 __a, __m128d __b) { __a[0] = __b[0]; return __a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtsi32_sd(__m128d __a, int __b) { __a[0] = __b; return __a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtss_sd(__m128d __a, __m128 __b) { __a[0] = __b[0]; return __a; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvttpd_epi32(__m128d __a) { return (__m128i)__builtin_ia32_cvttpd2dq(__a); } static __inline__ int __DEFAULT_FN_ATTRS _mm_cvttsd_si32(__m128d __a) { return __a[0]; } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvtpd_pi32(__m128d __a) { return (__m64)__builtin_ia32_cvtpd2pi(__a); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_cvttpd_pi32(__m128d __a) { return (__m64)__builtin_ia32_cvttpd2pi(__a); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtpi32_pd(__m64 __a) { return __builtin_ia32_cvtpi2pd((__v2si)__a); } static __inline__ double __DEFAULT_FN_ATTRS _mm_cvtsd_f64(__m128d __a) { return __a[0]; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_load_pd(double const *__dp) { return *(__m128d*)__dp; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_load1_pd(double const *__dp) { struct __mm_load1_pd_struct { double __u; } __attribute__((__packed__, __may_alias__)); double __u = ((struct __mm_load1_pd_struct*)__dp)->__u; return (__m128d){ __u, __u }; } #define _mm_load_pd1(dp) _mm_load1_pd(dp) static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_loadr_pd(double const *__dp) { __m128d __u = *(__m128d*)__dp; return __builtin_shufflevector(__u, __u, 1, 0); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_loadu_pd(double const *__dp) { struct __loadu_pd { __m128d __v; } __attribute__((__packed__, __may_alias__)); return ((struct __loadu_pd*)__dp)->__v; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_load_sd(double const *__dp) { struct __mm_load_sd_struct { double __u; } __attribute__((__packed__, __may_alias__)); double __u = ((struct __mm_load_sd_struct*)__dp)->__u; return (__m128d){ __u, 0 }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_loadh_pd(__m128d __a, double const *__dp) { struct __mm_loadh_pd_struct { double __u; } __attribute__((__packed__, __may_alias__)); double __u = ((struct __mm_loadh_pd_struct*)__dp)->__u; return (__m128d){ __a[0], __u }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_loadl_pd(__m128d __a, double const *__dp) { struct __mm_loadl_pd_struct { double __u; } __attribute__((__packed__, __may_alias__)); double __u = ((struct __mm_loadl_pd_struct*)__dp)->__u; return (__m128d){ __u, __a[1] }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_set_sd(double __w) { return (__m128d){ __w, 0 }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_set1_pd(double __w) { return (__m128d){ __w, __w }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_set_pd(double __w, double __x) { return (__m128d){ __x, __w }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_setr_pd(double __w, double __x) { return (__m128d){ __w, __x }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_setzero_pd(void) { return (__m128d){ 0, 0 }; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_move_sd(__m128d __a, __m128d __b) { return (__m128d){ __b[0], __a[1] }; } static __inline__ void __DEFAULT_FN_ATTRS _mm_store_sd(double *__dp, __m128d __a) { struct __mm_store_sd_struct { double __u; } __attribute__((__packed__, __may_alias__)); ((struct __mm_store_sd_struct*)__dp)->__u = __a[0]; } static __inline__ void __DEFAULT_FN_ATTRS _mm_store1_pd(double *__dp, __m128d __a) { struct __mm_store1_pd_struct { double __u[2]; } __attribute__((__packed__, __may_alias__)); ((struct __mm_store1_pd_struct*)__dp)->__u[0] = __a[0]; ((struct __mm_store1_pd_struct*)__dp)->__u[1] = __a[0]; } static __inline__ void __DEFAULT_FN_ATTRS _mm_store_pd(double *__dp, __m128d __a) { *(__m128d *)__dp = __a; } static __inline__ void __DEFAULT_FN_ATTRS _mm_storeu_pd(double *__dp, __m128d __a) { __builtin_ia32_storeupd(__dp, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_storer_pd(double *__dp, __m128d __a) { __a = __builtin_shufflevector(__a, __a, 1, 0); *(__m128d *)__dp = __a; } static __inline__ void __DEFAULT_FN_ATTRS _mm_storeh_pd(double *__dp, __m128d __a) { struct __mm_storeh_pd_struct { double __u; } __attribute__((__packed__, __may_alias__)); ((struct __mm_storeh_pd_struct*)__dp)->__u = __a[1]; } static __inline__ void __DEFAULT_FN_ATTRS _mm_storel_pd(double *__dp, __m128d __a) { struct __mm_storeh_pd_struct { double __u; } __attribute__((__packed__, __may_alias__)); ((struct __mm_storeh_pd_struct*)__dp)->__u = __a[0]; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_add_epi8(__m128i __a, __m128i __b) { return (__m128i)((__v16qi)__a + (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_add_epi16(__m128i __a, __m128i __b) { return (__m128i)((__v8hi)__a + (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_add_epi32(__m128i __a, __m128i __b) { return (__m128i)((__v4si)__a + (__v4si)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_add_si64(__m64 __a, __m64 __b) { return __a + __b; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_add_epi64(__m128i __a, __m128i __b) { return __a + __b; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_adds_epi8(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_paddsb128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_adds_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_paddsw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_adds_epu8(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_paddusb128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_adds_epu16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_paddusw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_avg_epu8(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pavgb128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_avg_epu16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pavgw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_madd_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pmaddwd128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pmaxsw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epu8(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pmaxub128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pminsw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epu8(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pminub128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mulhi_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pmulhw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mulhi_epu16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_pmulhuw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mullo_epi16(__m128i __a, __m128i __b) { return (__m128i)((__v8hi)__a * (__v8hi)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_mul_su32(__m64 __a, __m64 __b) { return __builtin_ia32_pmuludq((__v2si)__a, (__v2si)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mul_epu32(__m128i __a, __m128i __b) { return __builtin_ia32_pmuludq128((__v4si)__a, (__v4si)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sad_epu8(__m128i __a, __m128i __b) { return __builtin_ia32_psadbw128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sub_epi8(__m128i __a, __m128i __b) { return (__m128i)((__v16qi)__a - (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sub_epi16(__m128i __a, __m128i __b) { return (__m128i)((__v8hi)__a - (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sub_epi32(__m128i __a, __m128i __b) { return (__m128i)((__v4si)__a - (__v4si)__b); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_sub_si64(__m64 __a, __m64 __b) { return __a - __b; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sub_epi64(__m128i __a, __m128i __b) { return __a - __b; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_subs_epi8(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_psubsb128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_subs_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_psubsw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_subs_epu8(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_psubusb128((__v16qi)__a, (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_subs_epu16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_psubusw128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_and_si128(__m128i __a, __m128i __b) { return __a & __b; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_andnot_si128(__m128i __a, __m128i __b) { return ~__a & __b; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_or_si128(__m128i __a, __m128i __b) { return __a | __b; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_xor_si128(__m128i __a, __m128i __b) { return __a ^ __b; } #define _mm_slli_si128(a, imm) __extension__ ({ \ (__m128i)__builtin_shufflevector((__v16qi)_mm_setzero_si128(), \ (__v16qi)(__m128i)(a), \ ((imm)&0xF0) ? 0 : 16 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 17 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 18 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 19 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 20 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 21 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 22 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 23 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 24 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 25 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 26 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 27 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 28 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 29 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 30 - ((imm)&0xF), \ ((imm)&0xF0) ? 0 : 31 - ((imm)&0xF)); }) #define _mm_bslli_si128(a, imm) \ _mm_slli_si128((a), (imm)) static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_slli_epi16(__m128i __a, int __count) { return (__m128i)__builtin_ia32_psllwi128((__v8hi)__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sll_epi16(__m128i __a, __m128i __count) { return (__m128i)__builtin_ia32_psllw128((__v8hi)__a, (__v8hi)__count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_slli_epi32(__m128i __a, int __count) { return (__m128i)__builtin_ia32_pslldi128((__v4si)__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sll_epi32(__m128i __a, __m128i __count) { return (__m128i)__builtin_ia32_pslld128((__v4si)__a, (__v4si)__count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_slli_epi64(__m128i __a, int __count) { return __builtin_ia32_psllqi128(__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sll_epi64(__m128i __a, __m128i __count) { return __builtin_ia32_psllq128(__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srai_epi16(__m128i __a, int __count) { return (__m128i)__builtin_ia32_psrawi128((__v8hi)__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sra_epi16(__m128i __a, __m128i __count) { return (__m128i)__builtin_ia32_psraw128((__v8hi)__a, (__v8hi)__count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srai_epi32(__m128i __a, int __count) { return (__m128i)__builtin_ia32_psradi128((__v4si)__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sra_epi32(__m128i __a, __m128i __count) { return (__m128i)__builtin_ia32_psrad128((__v4si)__a, (__v4si)__count); } #define _mm_srli_si128(a, imm) __extension__ ({ \ (__m128i)__builtin_shufflevector((__v16qi)(__m128i)(a), \ (__v16qi)_mm_setzero_si128(), \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 0, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 1, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 2, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 3, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 4, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 5, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 6, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 7, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 8, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 9, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 10, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 11, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 12, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 13, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 14, \ ((imm)&0xF0) ? 16 : ((imm)&0xF) + 15); }) #define _mm_bsrli_si128(a, imm) \ _mm_srli_si128((a), (imm)) static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srli_epi16(__m128i __a, int __count) { return (__m128i)__builtin_ia32_psrlwi128((__v8hi)__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srl_epi16(__m128i __a, __m128i __count) { return (__m128i)__builtin_ia32_psrlw128((__v8hi)__a, (__v8hi)__count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srli_epi32(__m128i __a, int __count) { return (__m128i)__builtin_ia32_psrldi128((__v4si)__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srl_epi32(__m128i __a, __m128i __count) { return (__m128i)__builtin_ia32_psrld128((__v4si)__a, (__v4si)__count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srli_epi64(__m128i __a, int __count) { return __builtin_ia32_psrlqi128(__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_srl_epi64(__m128i __a, __m128i __count) { return __builtin_ia32_psrlq128(__a, __count); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpeq_epi8(__m128i __a, __m128i __b) { return (__m128i)((__v16qi)__a == (__v16qi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpeq_epi16(__m128i __a, __m128i __b) { return (__m128i)((__v8hi)__a == (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpeq_epi32(__m128i __a, __m128i __b) { return (__m128i)((__v4si)__a == (__v4si)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpgt_epi8(__m128i __a, __m128i __b) { /* This function always performs a signed comparison, but __v16qi is a char which may be signed or unsigned. */ typedef signed char __v16qs __attribute__((__vector_size__(16))); return (__m128i)((__v16qs)__a > (__v16qs)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpgt_epi16(__m128i __a, __m128i __b) { return (__m128i)((__v8hi)__a > (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpgt_epi32(__m128i __a, __m128i __b) { return (__m128i)((__v4si)__a > (__v4si)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmplt_epi8(__m128i __a, __m128i __b) { return _mm_cmpgt_epi8(__b, __a); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmplt_epi16(__m128i __a, __m128i __b) { return _mm_cmpgt_epi16(__b, __a); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmplt_epi32(__m128i __a, __m128i __b) { return _mm_cmpgt_epi32(__b, __a); } #ifdef __x86_64__ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_cvtsi64_sd(__m128d __a, long long __b) { __a[0] = __b; return __a; } static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvtsd_si64(__m128d __a) { return __builtin_ia32_cvtsd2si64(__a); } static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvttsd_si64(__m128d __a) { return __a[0]; } #endif static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_cvtepi32_ps(__m128i __a) { return __builtin_ia32_cvtdq2ps((__v4si)__a); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtps_epi32(__m128 __a) { return (__m128i)__builtin_ia32_cvtps2dq(__a); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvttps_epi32(__m128 __a) { return (__m128i)__builtin_ia32_cvttps2dq(__a); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtsi32_si128(int __a) { return (__m128i)(__v4si){ __a, 0, 0, 0 }; } #ifdef __x86_64__ static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtsi64_si128(long long __a) { return (__m128i){ __a, 0 }; } #endif static __inline__ int __DEFAULT_FN_ATTRS _mm_cvtsi128_si32(__m128i __a) { __v4si __b = (__v4si)__a; return __b[0]; } #ifdef __x86_64__ static __inline__ long long __DEFAULT_FN_ATTRS _mm_cvtsi128_si64(__m128i __a) { return __a[0]; } #endif static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_load_si128(__m128i const *__p) { return *__p; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_loadu_si128(__m128i const *__p) { struct __loadu_si128 { __m128i __v; } __attribute__((__packed__, __may_alias__)); return ((struct __loadu_si128*)__p)->__v; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_loadl_epi64(__m128i const *__p) { struct __mm_loadl_epi64_struct { long long __u; } __attribute__((__packed__, __may_alias__)); return (__m128i) { ((struct __mm_loadl_epi64_struct*)__p)->__u, 0}; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set_epi64x(long long q1, long long q0) { return (__m128i){ q0, q1 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set_epi64(__m64 q1, __m64 q0) { return (__m128i){ (long long)q0, (long long)q1 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set_epi32(int i3, int i2, int i1, int i0) { return (__m128i)(__v4si){ i0, i1, i2, i3}; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set_epi16(short w7, short w6, short w5, short w4, short w3, short w2, short w1, short w0) { return (__m128i)(__v8hi){ w0, w1, w2, w3, w4, w5, w6, w7 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set_epi8(char b15, char b14, char b13, char b12, char b11, char b10, char b9, char b8, char b7, char b6, char b5, char b4, char b3, char b2, char b1, char b0) { return (__m128i)(__v16qi){ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set1_epi64x(long long __q) { return (__m128i){ __q, __q }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set1_epi64(__m64 __q) { return (__m128i){ (long long)__q, (long long)__q }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set1_epi32(int __i) { return (__m128i)(__v4si){ __i, __i, __i, __i }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set1_epi16(short __w) { return (__m128i)(__v8hi){ __w, __w, __w, __w, __w, __w, __w, __w }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_set1_epi8(char __b) { return (__m128i)(__v16qi){ __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_setr_epi64(__m64 q0, __m64 q1) { return (__m128i){ (long long)q0, (long long)q1 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_setr_epi32(int i0, int i1, int i2, int i3) { return (__m128i)(__v4si){ i0, i1, i2, i3}; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_setr_epi16(short w0, short w1, short w2, short w3, short w4, short w5, short w6, short w7) { return (__m128i)(__v8hi){ w0, w1, w2, w3, w4, w5, w6, w7 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_setr_epi8(char b0, char b1, char b2, char b3, char b4, char b5, char b6, char b7, char b8, char b9, char b10, char b11, char b12, char b13, char b14, char b15) { return (__m128i)(__v16qi){ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_setzero_si128(void) { return (__m128i){ 0LL, 0LL }; } static __inline__ void __DEFAULT_FN_ATTRS _mm_store_si128(__m128i *__p, __m128i __b) { *__p = __b; } static __inline__ void __DEFAULT_FN_ATTRS _mm_storeu_si128(__m128i *__p, __m128i __b) { __builtin_ia32_storedqu((char *)__p, (__v16qi)__b); } static __inline__ void __DEFAULT_FN_ATTRS _mm_maskmoveu_si128(__m128i __d, __m128i __n, char *__p) { __builtin_ia32_maskmovdqu((__v16qi)__d, (__v16qi)__n, __p); } static __inline__ void __DEFAULT_FN_ATTRS _mm_storel_epi64(__m128i *__p, __m128i __a) { struct __mm_storel_epi64_struct { long long __u; } __attribute__((__packed__, __may_alias__)); ((struct __mm_storel_epi64_struct*)__p)->__u = __a[0]; } static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_pd(double *__p, __m128d __a) { __builtin_ia32_movntpd(__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_si128(__m128i *__p, __m128i __a) { __builtin_ia32_movntdq(__p, __a); } static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_si32(int *__p, int __a) { __builtin_ia32_movnti(__p, __a); } #ifdef __x86_64__ static __inline__ void __DEFAULT_FN_ATTRS _mm_stream_si64(long long *__p, long long __a) { __builtin_ia32_movnti64(__p, __a); } #endif static __inline__ void __DEFAULT_FN_ATTRS _mm_clflush(void const *__p) { __builtin_ia32_clflush(__p); } static __inline__ void __DEFAULT_FN_ATTRS _mm_lfence(void) { __builtin_ia32_lfence(); } static __inline__ void __DEFAULT_FN_ATTRS _mm_mfence(void) { __builtin_ia32_mfence(); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_packs_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_packsswb128((__v8hi)__a, (__v8hi)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_packs_epi32(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_packssdw128((__v4si)__a, (__v4si)__b); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_packus_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_ia32_packuswb128((__v8hi)__a, (__v8hi)__b); } static __inline__ int __DEFAULT_FN_ATTRS _mm_extract_epi16(__m128i __a, int __imm) { __v8hi __b = (__v8hi)__a; return (unsigned short)__b[__imm & 7]; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_insert_epi16(__m128i __a, int __b, int __imm) { __v8hi __c = (__v8hi)__a; __c[__imm & 7] = __b; return (__m128i)__c; } static __inline__ int __DEFAULT_FN_ATTRS _mm_movemask_epi8(__m128i __a) { return __builtin_ia32_pmovmskb128((__v16qi)__a); } #define _mm_shuffle_epi32(a, imm) __extension__ ({ \ (__m128i)__builtin_shufflevector((__v4si)(__m128i)(a), \ (__v4si)_mm_set1_epi32(0), \ (imm) & 0x3, ((imm) & 0xc) >> 2, \ ((imm) & 0x30) >> 4, ((imm) & 0xc0) >> 6); }) #define _mm_shufflelo_epi16(a, imm) __extension__ ({ \ (__m128i)__builtin_shufflevector((__v8hi)(__m128i)(a), \ (__v8hi)_mm_set1_epi16(0), \ (imm) & 0x3, ((imm) & 0xc) >> 2, \ ((imm) & 0x30) >> 4, ((imm) & 0xc0) >> 6, \ 4, 5, 6, 7); }) #define _mm_shufflehi_epi16(a, imm) __extension__ ({ \ (__m128i)__builtin_shufflevector((__v8hi)(__m128i)(a), \ (__v8hi)_mm_set1_epi16(0), \ 0, 1, 2, 3, \ 4 + (((imm) & 0x03) >> 0), \ 4 + (((imm) & 0x0c) >> 2), \ 4 + (((imm) & 0x30) >> 4), \ 4 + (((imm) & 0xc0) >> 6)); }) static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpackhi_epi8(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector((__v16qi)__a, (__v16qi)__b, 8, 16+8, 9, 16+9, 10, 16+10, 11, 16+11, 12, 16+12, 13, 16+13, 14, 16+14, 15, 16+15); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpackhi_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector((__v8hi)__a, (__v8hi)__b, 4, 8+4, 5, 8+5, 6, 8+6, 7, 8+7); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpackhi_epi32(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector((__v4si)__a, (__v4si)__b, 2, 4+2, 3, 4+3); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpackhi_epi64(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector(__a, __b, 1, 2+1); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpacklo_epi8(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector((__v16qi)__a, (__v16qi)__b, 0, 16+0, 1, 16+1, 2, 16+2, 3, 16+3, 4, 16+4, 5, 16+5, 6, 16+6, 7, 16+7); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpacklo_epi16(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector((__v8hi)__a, (__v8hi)__b, 0, 8+0, 1, 8+1, 2, 8+2, 3, 8+3); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpacklo_epi32(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector((__v4si)__a, (__v4si)__b, 0, 4+0, 1, 4+1); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_unpacklo_epi64(__m128i __a, __m128i __b) { return (__m128i)__builtin_shufflevector(__a, __b, 0, 2+0); } static __inline__ __m64 __DEFAULT_FN_ATTRS _mm_movepi64_pi64(__m128i __a) { return (__m64)__a[0]; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_movpi64_epi64(__m64 __a) { return (__m128i){ (long long)__a, 0 }; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_move_epi64(__m128i __a) { return __builtin_shufflevector(__a, (__m128i){ 0 }, 0, 2); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_unpackhi_pd(__m128d __a, __m128d __b) { return __builtin_shufflevector(__a, __b, 1, 2+1); } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_unpacklo_pd(__m128d __a, __m128d __b) { return __builtin_shufflevector(__a, __b, 0, 2+0); } static __inline__ int __DEFAULT_FN_ATTRS _mm_movemask_pd(__m128d __a) { return __builtin_ia32_movmskpd(__a); } #define _mm_shuffle_pd(a, b, i) __extension__ ({ \ __builtin_shufflevector((__m128d)(a), (__m128d)(b), \ (i) & 1, (((i) & 2) >> 1) + 2); }) static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_castpd_ps(__m128d __a) { return (__m128)__a; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_castpd_si128(__m128d __a) { return (__m128i)__a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_castps_pd(__m128 __a) { return (__m128d)__a; } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_castps_si128(__m128 __a) { return (__m128i)__a; } static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_castsi128_ps(__m128i __a) { return (__m128)__a; } static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_castsi128_pd(__m128i __a) { return (__m128d)__a; } static __inline__ void __DEFAULT_FN_ATTRS _mm_pause(void) { __asm__ volatile ("pause"); } #undef __DEFAULT_FN_ATTRS #define _MM_SHUFFLE2(x, y) (((x) << 1) | (y)) #endif /* __SSE2__ */ #endif /* __EMMINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/stddef.h
/*===---- stddef.h - Basic type definitions --------------------------------=== * * Copyright (c) 2008 Eli Friedman * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if !defined(__STDDEF_H) || defined(__need_ptrdiff_t) || \ defined(__need_size_t) || defined(__need_wchar_t) || \ defined(__need_NULL) || defined(__need_wint_t) #if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \ !defined(__need_wchar_t) && !defined(__need_NULL) && \ !defined(__need_wint_t) /* Always define miscellaneous pieces when modules are available. */ #if !__has_feature(modules) #define __STDDEF_H #endif #define __need_ptrdiff_t #define __need_size_t #define __need_wchar_t #define __need_NULL #define __need_STDDEF_H_misc /* __need_wint_t is intentionally not defined here. */ #endif #if defined(__need_ptrdiff_t) #if !defined(_PTRDIFF_T) || __has_feature(modules) /* Always define ptrdiff_t when modules are available. */ #if !__has_feature(modules) #define _PTRDIFF_T #endif typedef __PTRDIFF_TYPE__ ptrdiff_t; #endif #undef __need_ptrdiff_t #endif /* defined(__need_ptrdiff_t) */ #if defined(__need_size_t) #if !defined(_SIZE_T) || __has_feature(modules) /* Always define size_t when modules are available. */ #if !__has_feature(modules) #define _SIZE_T #endif typedef __SIZE_TYPE__ size_t; #endif #undef __need_size_t #endif /*defined(__need_size_t) */ #if defined(__need_STDDEF_H_misc) /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is * enabled. */ #if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && \ !defined(_RSIZE_T)) || __has_feature(modules) /* Always define rsize_t when modules are available. */ #if !__has_feature(modules) #define _RSIZE_T #endif typedef __SIZE_TYPE__ rsize_t; #endif #endif /* defined(__need_STDDEF_H_misc) */ #if defined(__need_wchar_t) #ifndef __cplusplus /* Always define wchar_t when modules are available. */ #if !defined(_WCHAR_T) || __has_feature(modules) #if !__has_feature(modules) #define _WCHAR_T #if defined(_MSC_EXTENSIONS) #define _WCHAR_T_DEFINED #endif #endif typedef __WCHAR_TYPE__ wchar_t; #endif #endif #undef __need_wchar_t #endif /* defined(__need_wchar_t) */ #if defined(__need_NULL) #undef NULL #ifdef __cplusplus # if !defined(__MINGW32__) && !defined(_MSC_VER) # define NULL __null # else # define NULL 0 # endif #else # define NULL ((void*)0) #endif #ifdef __cplusplus #if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED) namespace std { typedef decltype(nullptr) nullptr_t; } using ::std::nullptr_t; #endif #endif #undef __need_NULL #endif /* defined(__need_NULL) */ #if defined(__need_STDDEF_H_misc) #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L #include "__stddef_max_align_t.h" #endif #define offsetof(t, d) __builtin_offsetof(t, d) #undef __need_STDDEF_H_misc #endif /* defined(__need_STDDEF_H_misc) */ /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */ #if defined(__need_wint_t) /* Always define wint_t when modules are available. */ #if !defined(_WINT_T) || __has_feature(modules) #if !__has_feature(modules) #define _WINT_T #endif typedef __WINT_TYPE__ wint_t; #endif #undef __need_wint_t #endif /* __need_wint_t */ #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/f16cintrin.h
/*===---- f16cintrin.h - F16C intrinsics -----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H #error "Never use <f16cintrin.h> directly; include <x86intrin.h> instead." #endif #ifndef __F16C__ # error "F16C instruction is not enabled" #endif /* __F16C__ */ #ifndef __F16CINTRIN_H #define __F16CINTRIN_H typedef float __v8sf __attribute__ ((__vector_size__ (32))); typedef float __m256 __attribute__ ((__vector_size__ (32))); /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) #define _mm_cvtps_ph(a, imm) __extension__ ({ \ __m128 __a = (a); \ (__m128i)__builtin_ia32_vcvtps2ph((__v4sf)__a, (imm)); }) #define _mm256_cvtps_ph(a, imm) __extension__ ({ \ __m256 __a = (a); \ (__m128i)__builtin_ia32_vcvtps2ph256((__v8sf)__a, (imm)); }) static __inline __m128 __DEFAULT_FN_ATTRS _mm_cvtph_ps(__m128i __a) { return (__m128)__builtin_ia32_vcvtph2ps((__v8hi)__a); } static __inline __m256 __DEFAULT_FN_ATTRS _mm256_cvtph_ps(__m128i __a) { return (__m256)__builtin_ia32_vcvtph2ps256((__v8hi)__a); } #undef __DEFAULT_FN_ATTRS #endif /* __F16CINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avx512vlbwintrin.h
/*===---- avx512vlbwintrin.h - AVX512VL and AVX512BW intrinsics ----------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avx512vlbwintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVX512VLBWINTRIN_H #define __AVX512VLBWINTRIN_H /* Define the default attributes for the functions in this file. */ #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) /* Integer compare */ static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpeq_epi8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_pcmpeqb128_mask((__v16qi)__a, (__v16qi)__b, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epi8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_pcmpeqb128_mask((__v16qi)__a, (__v16qi)__b, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpeq_epu8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 0, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epu8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 0, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpeq_epi8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_pcmpeqb256_mask((__v32qi)__a, (__v32qi)__b, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epi8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_pcmpeqb256_mask((__v32qi)__a, (__v32qi)__b, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpeq_epu8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 0, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epu8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 0, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpeq_epi16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpeqw128_mask((__v8hi)__a, (__v8hi)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epi16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpeqw128_mask((__v8hi)__a, (__v8hi)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpeq_epu16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 0, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpeq_epu16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 0, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpeq_epi16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_pcmpeqw256_mask((__v16hi)__a, (__v16hi)__b, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epi16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_pcmpeqw256_mask((__v16hi)__a, (__v16hi)__b, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpeq_epu16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 0, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpeq_epu16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 0, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpge_epi8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 5, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epi8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 5, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpge_epu8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 5, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epu8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 5, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpge_epi8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 5, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epi8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 5, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpge_epu8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 5, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epu8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpge_epi16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epi16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 5, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpge_epu16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 5, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpge_epu16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 5, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpge_epi16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 5, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epi16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 5, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpge_epu16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 5, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpge_epu16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 5, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpgt_epi8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_pcmpgtb128_mask((__v16qi)__a, (__v16qi)__b, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epi8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_pcmpgtb128_mask((__v16qi)__a, (__v16qi)__b, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpgt_epu8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 6, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epu8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 6, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpgt_epi8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_pcmpgtb256_mask((__v32qi)__a, (__v32qi)__b, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epi8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_pcmpgtb256_mask((__v32qi)__a, (__v32qi)__b, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpgt_epu8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 6, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epu8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 6, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpgt_epi16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpgtw128_mask((__v8hi)__a, (__v8hi)__b, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epi16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_pcmpgtw128_mask((__v8hi)__a, (__v8hi)__b, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpgt_epu16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 6, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpgt_epu16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 6, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpgt_epi16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_pcmpgtw256_mask((__v16hi)__a, (__v16hi)__b, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epi16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_pcmpgtw256_mask((__v16hi)__a, (__v16hi)__b, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpgt_epu16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 6, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpgt_epu16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 6, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmple_epi8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 2, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmple_epi8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 2, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmple_epu8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 2, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmple_epu8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 2, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmple_epi8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 2, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epi8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 2, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmple_epu8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 2, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epu8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmple_epi16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmple_epi16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 2, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmple_epu16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 2, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmple_epu16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 2, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmple_epi16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 2, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epi16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 2, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmple_epu16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 2, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmple_epu16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 2, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmplt_epi8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 1, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epi8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 1, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmplt_epu8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 1, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epu8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 1, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmplt_epi8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 1, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epi8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 1, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmplt_epu8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 1, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epu8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmplt_epi16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epi16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 1, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmplt_epu16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 1, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmplt_epu16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 1, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmplt_epi16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 1, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epi16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 1, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmplt_epu16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 1, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmplt_epu16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 1, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpneq_epi8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 4, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epi8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)__a, (__v16qi)__b, 4, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_cmpneq_epu8_mask(__m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 4, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epu8_mask(__mmask16 __u, __m128i __a, __m128i __b) { return (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)__a, (__v16qi)__b, 4, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpneq_epi8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 4, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epi8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)__a, (__v32qi)__b, 4, __u); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_cmpneq_epu8_mask(__m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 4, (__mmask32)-1); } static __inline__ __mmask32 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epu8_mask(__mmask32 __u, __m256i __a, __m256i __b) { return (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)__a, (__v32qi)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpneq_epi16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epi16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)__a, (__v8hi)__b, 4, __u); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_cmpneq_epu16_mask(__m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 4, (__mmask8)-1); } static __inline__ __mmask8 __DEFAULT_FN_ATTRS _mm_mask_cmpneq_epu16_mask(__mmask8 __u, __m128i __a, __m128i __b) { return (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)__a, (__v8hi)__b, 4, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpneq_epi16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 4, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epi16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)__a, (__v16hi)__b, 4, __u); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_cmpneq_epu16_mask(__m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 4, (__mmask16)-1); } static __inline__ __mmask16 __DEFAULT_FN_ATTRS _mm256_mask_cmpneq_epu16_mask(__mmask16 __u, __m256i __a, __m256i __b) { return (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)__a, (__v16hi)__b, 4, __u); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_add_epi8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B){ return (__m256i) __builtin_ia32_paddb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_add_epi8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_add_epi16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_add_epi16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_sub_epi8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_sub_epi8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_sub_epi16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_sub_epi16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_add_epi8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_add_epi8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_add_epi16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_add_epi16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_sub_epi8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_sub_epi8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_sub_epi16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_sub_epi16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_mullo_epi16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmullw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_mullo_epi16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmullw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_mullo_epi16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmullw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_mullo_epi16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmullw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_blend_epi8 (__mmask16 __U, __m128i __A, __m128i __W) { return (__m128i) __builtin_ia32_blendmb_128_mask ((__v16qi) __A, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_blend_epi8 (__mmask32 __U, __m256i __A, __m256i __W) { return (__m256i) __builtin_ia32_blendmb_256_mask ((__v32qi) __A, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_blend_epi16 (__mmask8 __U, __m128i __A, __m128i __W) { return (__m128i) __builtin_ia32_blendmw_128_mask ((__v8hi) __A, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_blend_epi16 (__mmask16 __U, __m256i __A, __m256i __W) { return (__m256i) __builtin_ia32_blendmw_256_mask ((__v16hi) __A, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_abs_epi8 (__m128i __W, __mmask16 __U, __m128i __A) { return (__m128i) __builtin_ia32_pabsb128_mask ((__v16qi) __A, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_abs_epi8 (__mmask16 __U, __m128i __A) { return (__m128i) __builtin_ia32_pabsb128_mask ((__v16qi) __A, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_abs_epi8 (__m256i __W, __mmask32 __U, __m256i __A) { return (__m256i) __builtin_ia32_pabsb256_mask ((__v32qi) __A, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_abs_epi8 (__mmask32 __U, __m256i __A) { return (__m256i) __builtin_ia32_pabsb256_mask ((__v32qi) __A, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_abs_epi16 (__m128i __W, __mmask8 __U, __m128i __A) { return (__m128i) __builtin_ia32_pabsw128_mask ((__v8hi) __A, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_abs_epi16 (__mmask8 __U, __m128i __A) { return (__m128i) __builtin_ia32_pabsw128_mask ((__v8hi) __A, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_abs_epi16 (__m256i __W, __mmask16 __U, __m256i __A) { return (__m256i) __builtin_ia32_pabsw256_mask ((__v16hi) __A, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_abs_epi16 (__mmask16 __U, __m256i __A) { return (__m256i) __builtin_ia32_pabsw256_mask ((__v16hi) __A, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_packs_epi32 (__mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packssdw128_mask ((__v4si) __A, (__v4si) __B, (__v8hi) _mm_setzero_si128 (), __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_packs_epi32 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packssdw128_mask ((__v4si) __A, (__v4si) __B, (__v8hi) __W, __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_packs_epi32 (__mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packssdw256_mask ((__v8si) __A, (__v8si) __B, (__v16hi) _mm256_setzero_si256 (), __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_packs_epi32 (__m256i __W, __mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packssdw256_mask ((__v8si) __A, (__v8si) __B, (__v16hi) __W, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_packs_epi16 (__mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packsswb128_mask ((__v8hi) __A, (__v8hi) __B, (__v16qi) _mm_setzero_si128 (), __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_packs_epi16 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packsswb128_mask ((__v8hi) __A, (__v8hi) __B, (__v16qi) __W, __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_packs_epi16 (__mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packsswb256_mask ((__v16hi) __A, (__v16hi) __B, (__v32qi) _mm256_setzero_si256 (), __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_packs_epi16 (__m256i __W, __mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packsswb256_mask ((__v16hi) __A, (__v16hi) __B, (__v32qi) __W, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_packus_epi32 (__mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packusdw128_mask ((__v4si) __A, (__v4si) __B, (__v8hi) _mm_setzero_si128 (), __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_packus_epi32 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packusdw128_mask ((__v4si) __A, (__v4si) __B, (__v8hi) __W, __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_packus_epi32 (__mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packusdw256_mask ((__v8si) __A, (__v8si) __B, (__v16hi) _mm256_setzero_si256 (), __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_packus_epi32 (__m256i __W, __mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packusdw256_mask ((__v8si) __A, (__v8si) __B, (__v16hi) __W, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_packus_epi16 (__mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packuswb128_mask ((__v8hi) __A, (__v8hi) __B, (__v16qi) _mm_setzero_si128 (), __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_packus_epi16 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_packuswb128_mask ((__v8hi) __A, (__v8hi) __B, (__v16qi) __W, __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_packus_epi16 (__mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packuswb256_mask ((__v16hi) __A, (__v16hi) __B, (__v32qi) _mm256_setzero_si256 (), __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_packus_epi16 (__m256i __W, __mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_packuswb256_mask ((__v16hi) __A, (__v16hi) __B, (__v32qi) __W, __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_adds_epi8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_adds_epi8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_adds_epi8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_adds_epi8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_adds_epi16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_adds_epi16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_adds_epi16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_adds_epi16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_adds_epu8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddusb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_adds_epu8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddusb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_adds_epu8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddusb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_adds_epu8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddusb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_adds_epu16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddusw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_adds_epu16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_paddusw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_adds_epu16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddusw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_adds_epu16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_paddusw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_avg_epu8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pavgb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_avg_epu8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pavgb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_avg_epu8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pavgb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_avg_epu8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pavgb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_avg_epu16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pavgw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_avg_epu16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pavgw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_avg_epu16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pavgw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_avg_epu16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pavgw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_max_epi8 (__mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_max_epi8 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_max_epi8 (__mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_max_epi8 (__m256i __W, __mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_max_epi16 (__mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_max_epi16 (__m128i __W, __mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_max_epi16 (__mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_max_epi16 (__m256i __W, __mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_max_epu8 (__mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxub128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_max_epu8 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxub128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_max_epu8 (__mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxub256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_max_epu8 (__m256i __W, __mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxub256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_max_epu16 (__mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxuw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_max_epu16 (__m128i __W, __mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pmaxuw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_max_epu16 (__mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxuw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_max_epu16 (__m256i __W, __mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pmaxuw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_min_epi8 (__mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_min_epi8 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_min_epi8 (__mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_min_epi8 (__m256i __W, __mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_min_epi16 (__mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_min_epi16 (__m128i __W, __mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_min_epi16 (__mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_min_epi16 (__m256i __W, __mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_min_epu8 (__mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminub128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_min_epu8 (__m128i __W, __mmask16 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminub128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_min_epu8 (__mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminub256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_min_epu8 (__m256i __W, __mmask32 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminub256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_min_epu16 (__mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminuw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_min_epu16 (__m128i __W, __mmask8 __M, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pminuw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_min_epu16 (__mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminuw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __M); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_min_epu16 (__m256i __W, __mmask16 __M, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pminuw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __M); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_shuffle_epi8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pshufb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_shuffle_epi8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_pshufb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_shuffle_epi8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pshufb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_shuffle_epi8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_pshufb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_subs_epi8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_subs_epi8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubsb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_subs_epi8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_subs_epi8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubsb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_subs_epi16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_subs_epi16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubsw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_subs_epi16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_subs_epi16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubsw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_subs_epu8 (__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubusb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) __W, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_subs_epu8 (__mmask16 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubusb128_mask ((__v16qi) __A, (__v16qi) __B, (__v16qi) _mm_setzero_si128 (), (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_subs_epu8 (__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubusb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) __W, (__mmask32) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_subs_epu8 (__mmask32 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubusb256_mask ((__v32qi) __A, (__v32qi) __B, (__v32qi) _mm256_setzero_si256 (), (__mmask32) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_subs_epu16 (__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubusw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) __W, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_subs_epu16 (__mmask8 __U, __m128i __A, __m128i __B) { return (__m128i) __builtin_ia32_psubusw128_mask ((__v8hi) __A, (__v8hi) __B, (__v8hi) _mm_setzero_si128 (), (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_subs_epu16 (__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubusw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) __W, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_subs_epu16 (__mmask16 __U, __m256i __A, __m256i __B) { return (__m256i) __builtin_ia32_psubusw256_mask ((__v16hi) __A, (__v16hi) __B, (__v16hi) _mm256_setzero_si256 (), (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask2_permutex2var_epi16 (__m128i __A, __m128i __I, __mmask8 __U, __m128i __B) { return (__m128i) __builtin_ia32_vpermi2varhi128_mask ((__v8hi) __A, (__v8hi) __I /* idx */ , (__v8hi) __B, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask2_permutex2var_epi16 (__m256i __A, __m256i __I, __mmask16 __U, __m256i __B) { return (__m256i) __builtin_ia32_vpermi2varhi256_mask ((__v16hi) __A, (__v16hi) __I /* idx */ , (__v16hi) __B, (__mmask16) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_permutex2var_epi16 (__m128i __A, __m128i __I, __m128i __B) { return (__m128i) __builtin_ia32_vpermt2varhi128_mask ((__v8hi) __I/* idx */, (__v8hi) __A, (__v8hi) __B, (__mmask8) -1); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mask_permutex2var_epi16 (__m128i __A, __mmask8 __U, __m128i __I, __m128i __B) { return (__m128i) __builtin_ia32_vpermt2varhi128_mask ((__v8hi) __I/* idx */, (__v8hi) __A, (__v8hi) __B, (__mmask8) __U); } static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_maskz_permutex2var_epi16 (__mmask8 __U, __m128i __A, __m128i __I, __m128i __B) { return (__m128i) __builtin_ia32_vpermt2varhi128_maskz ((__v8hi) __I/* idx */, (__v8hi) __A, (__v8hi) __B, (__mmask8) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_permutex2var_epi16 (__m256i __A, __m256i __I, __m256i __B) { return (__m256i) __builtin_ia32_vpermt2varhi256_mask ((__v16hi) __I/* idx */, (__v16hi) __A, (__v16hi) __B, (__mmask16) -1); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_mask_permutex2var_epi16 (__m256i __A, __mmask16 __U, __m256i __I, __m256i __B) { return (__m256i) __builtin_ia32_vpermt2varhi256_mask ((__v16hi) __I/* idx */, (__v16hi) __A, (__v16hi) __B, (__mmask16) __U); } static __inline__ __m256i __DEFAULT_FN_ATTRS _mm256_maskz_permutex2var_epi16 (__mmask16 __U, __m256i __A, __m256i __I, __m256i __B) { return (__m256i) __builtin_ia32_vpermt2varhi256_maskz ((__v16hi) __I/* idx */, (__v16hi) __A, (__v16hi) __B, (__mmask16) __U); } #define _mm_cmp_epi8_mask(a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)(__m128i)(a), \ (__v16qi)(__m128i)(b), \ (p), (__mmask16)-1); }) #define _mm_mask_cmp_epi8_mask(m, a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_cmpb128_mask((__v16qi)(__m128i)(a), \ (__v16qi)(__m128i)(b), \ (p), (__mmask16)(m)); }) #define _mm_cmp_epu8_mask(a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)(__m128i)(a), \ (__v16qi)(__m128i)(b), \ (p), (__mmask16)-1); }) #define _mm_mask_cmp_epu8_mask(m, a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_ucmpb128_mask((__v16qi)(__m128i)(a), \ (__v16qi)(__m128i)(b), \ (p), (__mmask16)(m)); }) #define _mm256_cmp_epi8_mask(a, b, p) __extension__ ({ \ (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)(__m256i)(a), \ (__v32qi)(__m256i)(b), \ (p), (__mmask32)-1); }) #define _mm256_mask_cmp_epi8_mask(m, a, b, p) __extension__ ({ \ (__mmask32)__builtin_ia32_cmpb256_mask((__v32qi)(__m256i)(a), \ (__v32qi)(__m256i)(b), \ (p), (__mmask32)(m)); }) #define _mm256_cmp_epu8_mask(a, b, p) __extension__ ({ \ (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)(__m256i)(a), \ (__v32qi)(__m256i)(b), \ (p), (__mmask32)-1); }) #define _mm256_mask_cmp_epu8_mask(m, a, b, p) __extension__ ({ \ (__mmask32)__builtin_ia32_ucmpb256_mask((__v32qi)(__m256i)(a), \ (__v32qi)(__m256i)(b), \ (p), (__mmask32)(m)); }) #define _mm_cmp_epi16_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)(__m128i)(a), \ (__v8hi)(__m128i)(b), \ (p), (__mmask8)-1); }) #define _mm_mask_cmp_epi16_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_cmpw128_mask((__v8hi)(__m128i)(a), \ (__v8hi)(__m128i)(b), \ (p), (__mmask8)(m)); }) #define _mm_cmp_epu16_mask(a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)(__m128i)(a), \ (__v8hi)(__m128i)(b), \ (p), (__mmask8)-1); }) #define _mm_mask_cmp_epu16_mask(m, a, b, p) __extension__ ({ \ (__mmask8)__builtin_ia32_ucmpw128_mask((__v8hi)(__m128i)(a), \ (__v8hi)(__m128i)(b), \ (p), (__mmask8)(m)); }) #define _mm256_cmp_epi16_mask(a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)(__m256i)(a), \ (__v16hi)(__m256i)(b), \ (p), (__mmask16)-1); }) #define _mm256_mask_cmp_epi16_mask(m, a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_cmpw256_mask((__v16hi)(__m256i)(a), \ (__v16hi)(__m256i)(b), \ (p), (__mmask16)(m)); }) #define _mm256_cmp_epu16_mask(a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)(__m256i)(a), \ (__v16hi)(__m256i)(b), \ (p), (__mmask16)-1); }) #define _mm256_mask_cmp_epu16_mask(m, a, b, p) __extension__ ({ \ (__mmask16)__builtin_ia32_ucmpw256_mask((__v16hi)(__m256i)(a), \ (__v16hi)(__m256i)(b), \ (p), (__mmask16)(m)); }) #undef __DEFAULT_FN_ATTRS #endif /* __AVX512VLBWINTRIN_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/tgmath.h
/*===---- tgmath.h - Standard header for type generic math ----------------===*\ * * Copyright (c) 2009 Howard Hinnant * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * \*===----------------------------------------------------------------------===*/ #ifndef __TGMATH_H #define __TGMATH_H /* C99 7.22 Type-generic math <tgmath.h>. */ #include <math.h> /* C++ handles type genericity with overloading in math.h. */ #ifndef __cplusplus #include <complex.h> #define _TG_ATTRSp __attribute__((__overloadable__)) #define _TG_ATTRS __attribute__((__overloadable__, __always_inline__)) // promotion typedef void _Argument_type_is_not_arithmetic; static _Argument_type_is_not_arithmetic __tg_promote(...) __attribute__((__unavailable__,__overloadable__)); static double _TG_ATTRSp __tg_promote(int); static double _TG_ATTRSp __tg_promote(unsigned int); static double _TG_ATTRSp __tg_promote(long); static double _TG_ATTRSp __tg_promote(unsigned long); static double _TG_ATTRSp __tg_promote(long long); static double _TG_ATTRSp __tg_promote(unsigned long long); static float _TG_ATTRSp __tg_promote(float); static double _TG_ATTRSp __tg_promote(double); static long double _TG_ATTRSp __tg_promote(long double); static float _Complex _TG_ATTRSp __tg_promote(float _Complex); static double _Complex _TG_ATTRSp __tg_promote(double _Complex); static long double _Complex _TG_ATTRSp __tg_promote(long double _Complex); #define __tg_promote1(__x) (__typeof__(__tg_promote(__x))) #define __tg_promote2(__x, __y) (__typeof__(__tg_promote(__x) + \ __tg_promote(__y))) #define __tg_promote3(__x, __y, __z) (__typeof__(__tg_promote(__x) + \ __tg_promote(__y) + \ __tg_promote(__z))) // acos static float _TG_ATTRS __tg_acos(float __x) {return acosf(__x);} static double _TG_ATTRS __tg_acos(double __x) {return acos(__x);} static long double _TG_ATTRS __tg_acos(long double __x) {return acosl(__x);} static float _Complex _TG_ATTRS __tg_acos(float _Complex __x) {return cacosf(__x);} static double _Complex _TG_ATTRS __tg_acos(double _Complex __x) {return cacos(__x);} static long double _Complex _TG_ATTRS __tg_acos(long double _Complex __x) {return cacosl(__x);} #undef acos #define acos(__x) __tg_acos(__tg_promote1((__x))(__x)) // asin static float _TG_ATTRS __tg_asin(float __x) {return asinf(__x);} static double _TG_ATTRS __tg_asin(double __x) {return asin(__x);} static long double _TG_ATTRS __tg_asin(long double __x) {return asinl(__x);} static float _Complex _TG_ATTRS __tg_asin(float _Complex __x) {return casinf(__x);} static double _Complex _TG_ATTRS __tg_asin(double _Complex __x) {return casin(__x);} static long double _Complex _TG_ATTRS __tg_asin(long double _Complex __x) {return casinl(__x);} #undef asin #define asin(__x) __tg_asin(__tg_promote1((__x))(__x)) // atan static float _TG_ATTRS __tg_atan(float __x) {return atanf(__x);} static double _TG_ATTRS __tg_atan(double __x) {return atan(__x);} static long double _TG_ATTRS __tg_atan(long double __x) {return atanl(__x);} static float _Complex _TG_ATTRS __tg_atan(float _Complex __x) {return catanf(__x);} static double _Complex _TG_ATTRS __tg_atan(double _Complex __x) {return catan(__x);} static long double _Complex _TG_ATTRS __tg_atan(long double _Complex __x) {return catanl(__x);} #undef atan #define atan(__x) __tg_atan(__tg_promote1((__x))(__x)) // acosh static float _TG_ATTRS __tg_acosh(float __x) {return acoshf(__x);} static double _TG_ATTRS __tg_acosh(double __x) {return acosh(__x);} static long double _TG_ATTRS __tg_acosh(long double __x) {return acoshl(__x);} static float _Complex _TG_ATTRS __tg_acosh(float _Complex __x) {return cacoshf(__x);} static double _Complex _TG_ATTRS __tg_acosh(double _Complex __x) {return cacosh(__x);} static long double _Complex _TG_ATTRS __tg_acosh(long double _Complex __x) {return cacoshl(__x);} #undef acosh #define acosh(__x) __tg_acosh(__tg_promote1((__x))(__x)) // asinh static float _TG_ATTRS __tg_asinh(float __x) {return asinhf(__x);} static double _TG_ATTRS __tg_asinh(double __x) {return asinh(__x);} static long double _TG_ATTRS __tg_asinh(long double __x) {return asinhl(__x);} static float _Complex _TG_ATTRS __tg_asinh(float _Complex __x) {return casinhf(__x);} static double _Complex _TG_ATTRS __tg_asinh(double _Complex __x) {return casinh(__x);} static long double _Complex _TG_ATTRS __tg_asinh(long double _Complex __x) {return casinhl(__x);} #undef asinh #define asinh(__x) __tg_asinh(__tg_promote1((__x))(__x)) // atanh static float _TG_ATTRS __tg_atanh(float __x) {return atanhf(__x);} static double _TG_ATTRS __tg_atanh(double __x) {return atanh(__x);} static long double _TG_ATTRS __tg_atanh(long double __x) {return atanhl(__x);} static float _Complex _TG_ATTRS __tg_atanh(float _Complex __x) {return catanhf(__x);} static double _Complex _TG_ATTRS __tg_atanh(double _Complex __x) {return catanh(__x);} static long double _Complex _TG_ATTRS __tg_atanh(long double _Complex __x) {return catanhl(__x);} #undef atanh #define atanh(__x) __tg_atanh(__tg_promote1((__x))(__x)) // cos static float _TG_ATTRS __tg_cos(float __x) {return cosf(__x);} static double _TG_ATTRS __tg_cos(double __x) {return cos(__x);} static long double _TG_ATTRS __tg_cos(long double __x) {return cosl(__x);} static float _Complex _TG_ATTRS __tg_cos(float _Complex __x) {return ccosf(__x);} static double _Complex _TG_ATTRS __tg_cos(double _Complex __x) {return ccos(__x);} static long double _Complex _TG_ATTRS __tg_cos(long double _Complex __x) {return ccosl(__x);} #undef cos #define cos(__x) __tg_cos(__tg_promote1((__x))(__x)) // sin static float _TG_ATTRS __tg_sin(float __x) {return sinf(__x);} static double _TG_ATTRS __tg_sin(double __x) {return sin(__x);} static long double _TG_ATTRS __tg_sin(long double __x) {return sinl(__x);} static float _Complex _TG_ATTRS __tg_sin(float _Complex __x) {return csinf(__x);} static double _Complex _TG_ATTRS __tg_sin(double _Complex __x) {return csin(__x);} static long double _Complex _TG_ATTRS __tg_sin(long double _Complex __x) {return csinl(__x);} #undef sin #define sin(__x) __tg_sin(__tg_promote1((__x))(__x)) // tan static float _TG_ATTRS __tg_tan(float __x) {return tanf(__x);} static double _TG_ATTRS __tg_tan(double __x) {return tan(__x);} static long double _TG_ATTRS __tg_tan(long double __x) {return tanl(__x);} static float _Complex _TG_ATTRS __tg_tan(float _Complex __x) {return ctanf(__x);} static double _Complex _TG_ATTRS __tg_tan(double _Complex __x) {return ctan(__x);} static long double _Complex _TG_ATTRS __tg_tan(long double _Complex __x) {return ctanl(__x);} #undef tan #define tan(__x) __tg_tan(__tg_promote1((__x))(__x)) // cosh static float _TG_ATTRS __tg_cosh(float __x) {return coshf(__x);} static double _TG_ATTRS __tg_cosh(double __x) {return cosh(__x);} static long double _TG_ATTRS __tg_cosh(long double __x) {return coshl(__x);} static float _Complex _TG_ATTRS __tg_cosh(float _Complex __x) {return ccoshf(__x);} static double _Complex _TG_ATTRS __tg_cosh(double _Complex __x) {return ccosh(__x);} static long double _Complex _TG_ATTRS __tg_cosh(long double _Complex __x) {return ccoshl(__x);} #undef cosh #define cosh(__x) __tg_cosh(__tg_promote1((__x))(__x)) // sinh static float _TG_ATTRS __tg_sinh(float __x) {return sinhf(__x);} static double _TG_ATTRS __tg_sinh(double __x) {return sinh(__x);} static long double _TG_ATTRS __tg_sinh(long double __x) {return sinhl(__x);} static float _Complex _TG_ATTRS __tg_sinh(float _Complex __x) {return csinhf(__x);} static double _Complex _TG_ATTRS __tg_sinh(double _Complex __x) {return csinh(__x);} static long double _Complex _TG_ATTRS __tg_sinh(long double _Complex __x) {return csinhl(__x);} #undef sinh #define sinh(__x) __tg_sinh(__tg_promote1((__x))(__x)) // tanh static float _TG_ATTRS __tg_tanh(float __x) {return tanhf(__x);} static double _TG_ATTRS __tg_tanh(double __x) {return tanh(__x);} static long double _TG_ATTRS __tg_tanh(long double __x) {return tanhl(__x);} static float _Complex _TG_ATTRS __tg_tanh(float _Complex __x) {return ctanhf(__x);} static double _Complex _TG_ATTRS __tg_tanh(double _Complex __x) {return ctanh(__x);} static long double _Complex _TG_ATTRS __tg_tanh(long double _Complex __x) {return ctanhl(__x);} #undef tanh #define tanh(__x) __tg_tanh(__tg_promote1((__x))(__x)) // exp static float _TG_ATTRS __tg_exp(float __x) {return expf(__x);} static double _TG_ATTRS __tg_exp(double __x) {return exp(__x);} static long double _TG_ATTRS __tg_exp(long double __x) {return expl(__x);} static float _Complex _TG_ATTRS __tg_exp(float _Complex __x) {return cexpf(__x);} static double _Complex _TG_ATTRS __tg_exp(double _Complex __x) {return cexp(__x);} static long double _Complex _TG_ATTRS __tg_exp(long double _Complex __x) {return cexpl(__x);} #undef exp #define exp(__x) __tg_exp(__tg_promote1((__x))(__x)) // log static float _TG_ATTRS __tg_log(float __x) {return logf(__x);} static double _TG_ATTRS __tg_log(double __x) {return log(__x);} static long double _TG_ATTRS __tg_log(long double __x) {return logl(__x);} static float _Complex _TG_ATTRS __tg_log(float _Complex __x) {return clogf(__x);} static double _Complex _TG_ATTRS __tg_log(double _Complex __x) {return clog(__x);} static long double _Complex _TG_ATTRS __tg_log(long double _Complex __x) {return clogl(__x);} #undef log #define log(__x) __tg_log(__tg_promote1((__x))(__x)) // pow static float _TG_ATTRS __tg_pow(float __x, float __y) {return powf(__x, __y);} static double _TG_ATTRS __tg_pow(double __x, double __y) {return pow(__x, __y);} static long double _TG_ATTRS __tg_pow(long double __x, long double __y) {return powl(__x, __y);} static float _Complex _TG_ATTRS __tg_pow(float _Complex __x, float _Complex __y) {return cpowf(__x, __y);} static double _Complex _TG_ATTRS __tg_pow(double _Complex __x, double _Complex __y) {return cpow(__x, __y);} static long double _Complex _TG_ATTRS __tg_pow(long double _Complex __x, long double _Complex __y) {return cpowl(__x, __y);} #undef pow #define pow(__x, __y) __tg_pow(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // sqrt static float _TG_ATTRS __tg_sqrt(float __x) {return sqrtf(__x);} static double _TG_ATTRS __tg_sqrt(double __x) {return sqrt(__x);} static long double _TG_ATTRS __tg_sqrt(long double __x) {return sqrtl(__x);} static float _Complex _TG_ATTRS __tg_sqrt(float _Complex __x) {return csqrtf(__x);} static double _Complex _TG_ATTRS __tg_sqrt(double _Complex __x) {return csqrt(__x);} static long double _Complex _TG_ATTRS __tg_sqrt(long double _Complex __x) {return csqrtl(__x);} #undef sqrt #define sqrt(__x) __tg_sqrt(__tg_promote1((__x))(__x)) // fabs static float _TG_ATTRS __tg_fabs(float __x) {return fabsf(__x);} static double _TG_ATTRS __tg_fabs(double __x) {return fabs(__x);} static long double _TG_ATTRS __tg_fabs(long double __x) {return fabsl(__x);} static float _TG_ATTRS __tg_fabs(float _Complex __x) {return cabsf(__x);} static double _TG_ATTRS __tg_fabs(double _Complex __x) {return cabs(__x);} static long double _TG_ATTRS __tg_fabs(long double _Complex __x) {return cabsl(__x);} #undef fabs #define fabs(__x) __tg_fabs(__tg_promote1((__x))(__x)) // atan2 static float _TG_ATTRS __tg_atan2(float __x, float __y) {return atan2f(__x, __y);} static double _TG_ATTRS __tg_atan2(double __x, double __y) {return atan2(__x, __y);} static long double _TG_ATTRS __tg_atan2(long double __x, long double __y) {return atan2l(__x, __y);} #undef atan2 #define atan2(__x, __y) __tg_atan2(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // cbrt static float _TG_ATTRS __tg_cbrt(float __x) {return cbrtf(__x);} static double _TG_ATTRS __tg_cbrt(double __x) {return cbrt(__x);} static long double _TG_ATTRS __tg_cbrt(long double __x) {return cbrtl(__x);} #undef cbrt #define cbrt(__x) __tg_cbrt(__tg_promote1((__x))(__x)) // ceil static float _TG_ATTRS __tg_ceil(float __x) {return ceilf(__x);} static double _TG_ATTRS __tg_ceil(double __x) {return ceil(__x);} static long double _TG_ATTRS __tg_ceil(long double __x) {return ceill(__x);} #undef ceil #define ceil(__x) __tg_ceil(__tg_promote1((__x))(__x)) // copysign static float _TG_ATTRS __tg_copysign(float __x, float __y) {return copysignf(__x, __y);} static double _TG_ATTRS __tg_copysign(double __x, double __y) {return copysign(__x, __y);} static long double _TG_ATTRS __tg_copysign(long double __x, long double __y) {return copysignl(__x, __y);} #undef copysign #define copysign(__x, __y) __tg_copysign(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // erf static float _TG_ATTRS __tg_erf(float __x) {return erff(__x);} static double _TG_ATTRS __tg_erf(double __x) {return erf(__x);} static long double _TG_ATTRS __tg_erf(long double __x) {return erfl(__x);} #undef erf #define erf(__x) __tg_erf(__tg_promote1((__x))(__x)) // erfc static float _TG_ATTRS __tg_erfc(float __x) {return erfcf(__x);} static double _TG_ATTRS __tg_erfc(double __x) {return erfc(__x);} static long double _TG_ATTRS __tg_erfc(long double __x) {return erfcl(__x);} #undef erfc #define erfc(__x) __tg_erfc(__tg_promote1((__x))(__x)) // exp2 static float _TG_ATTRS __tg_exp2(float __x) {return exp2f(__x);} static double _TG_ATTRS __tg_exp2(double __x) {return exp2(__x);} static long double _TG_ATTRS __tg_exp2(long double __x) {return exp2l(__x);} #undef exp2 #define exp2(__x) __tg_exp2(__tg_promote1((__x))(__x)) // expm1 static float _TG_ATTRS __tg_expm1(float __x) {return expm1f(__x);} static double _TG_ATTRS __tg_expm1(double __x) {return expm1(__x);} static long double _TG_ATTRS __tg_expm1(long double __x) {return expm1l(__x);} #undef expm1 #define expm1(__x) __tg_expm1(__tg_promote1((__x))(__x)) // fdim static float _TG_ATTRS __tg_fdim(float __x, float __y) {return fdimf(__x, __y);} static double _TG_ATTRS __tg_fdim(double __x, double __y) {return fdim(__x, __y);} static long double _TG_ATTRS __tg_fdim(long double __x, long double __y) {return fdiml(__x, __y);} #undef fdim #define fdim(__x, __y) __tg_fdim(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // floor static float _TG_ATTRS __tg_floor(float __x) {return floorf(__x);} static double _TG_ATTRS __tg_floor(double __x) {return floor(__x);} static long double _TG_ATTRS __tg_floor(long double __x) {return floorl(__x);} #undef floor #define floor(__x) __tg_floor(__tg_promote1((__x))(__x)) // fma static float _TG_ATTRS __tg_fma(float __x, float __y, float __z) {return fmaf(__x, __y, __z);} static double _TG_ATTRS __tg_fma(double __x, double __y, double __z) {return fma(__x, __y, __z);} static long double _TG_ATTRS __tg_fma(long double __x,long double __y, long double __z) {return fmal(__x, __y, __z);} #undef fma #define fma(__x, __y, __z) \ __tg_fma(__tg_promote3((__x), (__y), (__z))(__x), \ __tg_promote3((__x), (__y), (__z))(__y), \ __tg_promote3((__x), (__y), (__z))(__z)) // fmax static float _TG_ATTRS __tg_fmax(float __x, float __y) {return fmaxf(__x, __y);} static double _TG_ATTRS __tg_fmax(double __x, double __y) {return fmax(__x, __y);} static long double _TG_ATTRS __tg_fmax(long double __x, long double __y) {return fmaxl(__x, __y);} #undef fmax #define fmax(__x, __y) __tg_fmax(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // fmin static float _TG_ATTRS __tg_fmin(float __x, float __y) {return fminf(__x, __y);} static double _TG_ATTRS __tg_fmin(double __x, double __y) {return fmin(__x, __y);} static long double _TG_ATTRS __tg_fmin(long double __x, long double __y) {return fminl(__x, __y);} #undef fmin #define fmin(__x, __y) __tg_fmin(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // fmod static float _TG_ATTRS __tg_fmod(float __x, float __y) {return fmodf(__x, __y);} static double _TG_ATTRS __tg_fmod(double __x, double __y) {return fmod(__x, __y);} static long double _TG_ATTRS __tg_fmod(long double __x, long double __y) {return fmodl(__x, __y);} #undef fmod #define fmod(__x, __y) __tg_fmod(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // frexp static float _TG_ATTRS __tg_frexp(float __x, int* __y) {return frexpf(__x, __y);} static double _TG_ATTRS __tg_frexp(double __x, int* __y) {return frexp(__x, __y);} static long double _TG_ATTRS __tg_frexp(long double __x, int* __y) {return frexpl(__x, __y);} #undef frexp #define frexp(__x, __y) __tg_frexp(__tg_promote1((__x))(__x), __y) // hypot static float _TG_ATTRS __tg_hypot(float __x, float __y) {return hypotf(__x, __y);} static double _TG_ATTRS __tg_hypot(double __x, double __y) {return hypot(__x, __y);} static long double _TG_ATTRS __tg_hypot(long double __x, long double __y) {return hypotl(__x, __y);} #undef hypot #define hypot(__x, __y) __tg_hypot(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // ilogb static int _TG_ATTRS __tg_ilogb(float __x) {return ilogbf(__x);} static int _TG_ATTRS __tg_ilogb(double __x) {return ilogb(__x);} static int _TG_ATTRS __tg_ilogb(long double __x) {return ilogbl(__x);} #undef ilogb #define ilogb(__x) __tg_ilogb(__tg_promote1((__x))(__x)) // ldexp static float _TG_ATTRS __tg_ldexp(float __x, int __y) {return ldexpf(__x, __y);} static double _TG_ATTRS __tg_ldexp(double __x, int __y) {return ldexp(__x, __y);} static long double _TG_ATTRS __tg_ldexp(long double __x, int __y) {return ldexpl(__x, __y);} #undef ldexp #define ldexp(__x, __y) __tg_ldexp(__tg_promote1((__x))(__x), __y) // lgamma static float _TG_ATTRS __tg_lgamma(float __x) {return lgammaf(__x);} static double _TG_ATTRS __tg_lgamma(double __x) {return lgamma(__x);} static long double _TG_ATTRS __tg_lgamma(long double __x) {return lgammal(__x);} #undef lgamma #define lgamma(__x) __tg_lgamma(__tg_promote1((__x))(__x)) // llrint static long long _TG_ATTRS __tg_llrint(float __x) {return llrintf(__x);} static long long _TG_ATTRS __tg_llrint(double __x) {return llrint(__x);} static long long _TG_ATTRS __tg_llrint(long double __x) {return llrintl(__x);} #undef llrint #define llrint(__x) __tg_llrint(__tg_promote1((__x))(__x)) // llround static long long _TG_ATTRS __tg_llround(float __x) {return llroundf(__x);} static long long _TG_ATTRS __tg_llround(double __x) {return llround(__x);} static long long _TG_ATTRS __tg_llround(long double __x) {return llroundl(__x);} #undef llround #define llround(__x) __tg_llround(__tg_promote1((__x))(__x)) // log10 static float _TG_ATTRS __tg_log10(float __x) {return log10f(__x);} static double _TG_ATTRS __tg_log10(double __x) {return log10(__x);} static long double _TG_ATTRS __tg_log10(long double __x) {return log10l(__x);} #undef log10 #define log10(__x) __tg_log10(__tg_promote1((__x))(__x)) // log1p static float _TG_ATTRS __tg_log1p(float __x) {return log1pf(__x);} static double _TG_ATTRS __tg_log1p(double __x) {return log1p(__x);} static long double _TG_ATTRS __tg_log1p(long double __x) {return log1pl(__x);} #undef log1p #define log1p(__x) __tg_log1p(__tg_promote1((__x))(__x)) // log2 static float _TG_ATTRS __tg_log2(float __x) {return log2f(__x);} static double _TG_ATTRS __tg_log2(double __x) {return log2(__x);} static long double _TG_ATTRS __tg_log2(long double __x) {return log2l(__x);} #undef log2 #define log2(__x) __tg_log2(__tg_promote1((__x))(__x)) // logb static float _TG_ATTRS __tg_logb(float __x) {return logbf(__x);} static double _TG_ATTRS __tg_logb(double __x) {return logb(__x);} static long double _TG_ATTRS __tg_logb(long double __x) {return logbl(__x);} #undef logb #define logb(__x) __tg_logb(__tg_promote1((__x))(__x)) // lrint static long _TG_ATTRS __tg_lrint(float __x) {return lrintf(__x);} static long _TG_ATTRS __tg_lrint(double __x) {return lrint(__x);} static long _TG_ATTRS __tg_lrint(long double __x) {return lrintl(__x);} #undef lrint #define lrint(__x) __tg_lrint(__tg_promote1((__x))(__x)) // lround static long _TG_ATTRS __tg_lround(float __x) {return lroundf(__x);} static long _TG_ATTRS __tg_lround(double __x) {return lround(__x);} static long _TG_ATTRS __tg_lround(long double __x) {return lroundl(__x);} #undef lround #define lround(__x) __tg_lround(__tg_promote1((__x))(__x)) // nearbyint static float _TG_ATTRS __tg_nearbyint(float __x) {return nearbyintf(__x);} static double _TG_ATTRS __tg_nearbyint(double __x) {return nearbyint(__x);} static long double _TG_ATTRS __tg_nearbyint(long double __x) {return nearbyintl(__x);} #undef nearbyint #define nearbyint(__x) __tg_nearbyint(__tg_promote1((__x))(__x)) // nextafter static float _TG_ATTRS __tg_nextafter(float __x, float __y) {return nextafterf(__x, __y);} static double _TG_ATTRS __tg_nextafter(double __x, double __y) {return nextafter(__x, __y);} static long double _TG_ATTRS __tg_nextafter(long double __x, long double __y) {return nextafterl(__x, __y);} #undef nextafter #define nextafter(__x, __y) __tg_nextafter(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // nexttoward static float _TG_ATTRS __tg_nexttoward(float __x, long double __y) {return nexttowardf(__x, __y);} static double _TG_ATTRS __tg_nexttoward(double __x, long double __y) {return nexttoward(__x, __y);} static long double _TG_ATTRS __tg_nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);} #undef nexttoward #define nexttoward(__x, __y) __tg_nexttoward(__tg_promote1((__x))(__x), (__y)) // remainder static float _TG_ATTRS __tg_remainder(float __x, float __y) {return remainderf(__x, __y);} static double _TG_ATTRS __tg_remainder(double __x, double __y) {return remainder(__x, __y);} static long double _TG_ATTRS __tg_remainder(long double __x, long double __y) {return remainderl(__x, __y);} #undef remainder #define remainder(__x, __y) __tg_remainder(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y)) // remquo static float _TG_ATTRS __tg_remquo(float __x, float __y, int* __z) {return remquof(__x, __y, __z);} static double _TG_ATTRS __tg_remquo(double __x, double __y, int* __z) {return remquo(__x, __y, __z);} static long double _TG_ATTRS __tg_remquo(long double __x,long double __y, int* __z) {return remquol(__x, __y, __z);} #undef remquo #define remquo(__x, __y, __z) \ __tg_remquo(__tg_promote2((__x), (__y))(__x), \ __tg_promote2((__x), (__y))(__y), \ (__z)) // rint static float _TG_ATTRS __tg_rint(float __x) {return rintf(__x);} static double _TG_ATTRS __tg_rint(double __x) {return rint(__x);} static long double _TG_ATTRS __tg_rint(long double __x) {return rintl(__x);} #undef rint #define rint(__x) __tg_rint(__tg_promote1((__x))(__x)) // round static float _TG_ATTRS __tg_round(float __x) {return roundf(__x);} static double _TG_ATTRS __tg_round(double __x) {return round(__x);} static long double _TG_ATTRS __tg_round(long double __x) {return roundl(__x);} #undef round #define round(__x) __tg_round(__tg_promote1((__x))(__x)) // scalbn static float _TG_ATTRS __tg_scalbn(float __x, int __y) {return scalbnf(__x, __y);} static double _TG_ATTRS __tg_scalbn(double __x, int __y) {return scalbn(__x, __y);} static long double _TG_ATTRS __tg_scalbn(long double __x, int __y) {return scalbnl(__x, __y);} #undef scalbn #define scalbn(__x, __y) __tg_scalbn(__tg_promote1((__x))(__x), __y) // scalbln static float _TG_ATTRS __tg_scalbln(float __x, long __y) {return scalblnf(__x, __y);} static double _TG_ATTRS __tg_scalbln(double __x, long __y) {return scalbln(__x, __y);} static long double _TG_ATTRS __tg_scalbln(long double __x, long __y) {return scalblnl(__x, __y);} #undef scalbln #define scalbln(__x, __y) __tg_scalbln(__tg_promote1((__x))(__x), __y) // tgamma static float _TG_ATTRS __tg_tgamma(float __x) {return tgammaf(__x);} static double _TG_ATTRS __tg_tgamma(double __x) {return tgamma(__x);} static long double _TG_ATTRS __tg_tgamma(long double __x) {return tgammal(__x);} #undef tgamma #define tgamma(__x) __tg_tgamma(__tg_promote1((__x))(__x)) // trunc static float _TG_ATTRS __tg_trunc(float __x) {return truncf(__x);} static double _TG_ATTRS __tg_trunc(double __x) {return trunc(__x);} static long double _TG_ATTRS __tg_trunc(long double __x) {return truncl(__x);} #undef trunc #define trunc(__x) __tg_trunc(__tg_promote1((__x))(__x)) // carg static float _TG_ATTRS __tg_carg(float __x) {return atan2f(0.F, __x);} static double _TG_ATTRS __tg_carg(double __x) {return atan2(0., __x);} static long double _TG_ATTRS __tg_carg(long double __x) {return atan2l(0.L, __x);} static float _TG_ATTRS __tg_carg(float _Complex __x) {return cargf(__x);} static double _TG_ATTRS __tg_carg(double _Complex __x) {return carg(__x);} static long double _TG_ATTRS __tg_carg(long double _Complex __x) {return cargl(__x);} #undef carg #define carg(__x) __tg_carg(__tg_promote1((__x))(__x)) // cimag static float _TG_ATTRS __tg_cimag(float __x) {return 0;} static double _TG_ATTRS __tg_cimag(double __x) {return 0;} static long double _TG_ATTRS __tg_cimag(long double __x) {return 0;} static float _TG_ATTRS __tg_cimag(float _Complex __x) {return cimagf(__x);} static double _TG_ATTRS __tg_cimag(double _Complex __x) {return cimag(__x);} static long double _TG_ATTRS __tg_cimag(long double _Complex __x) {return cimagl(__x);} #undef cimag #define cimag(__x) __tg_cimag(__tg_promote1((__x))(__x)) // conj static float _Complex _TG_ATTRS __tg_conj(float __x) {return __x;} static double _Complex _TG_ATTRS __tg_conj(double __x) {return __x;} static long double _Complex _TG_ATTRS __tg_conj(long double __x) {return __x;} static float _Complex _TG_ATTRS __tg_conj(float _Complex __x) {return conjf(__x);} static double _Complex _TG_ATTRS __tg_conj(double _Complex __x) {return conj(__x);} static long double _Complex _TG_ATTRS __tg_conj(long double _Complex __x) {return conjl(__x);} #undef conj #define conj(__x) __tg_conj(__tg_promote1((__x))(__x)) // cproj static float _Complex _TG_ATTRS __tg_cproj(float __x) {return cprojf(__x);} static double _Complex _TG_ATTRS __tg_cproj(double __x) {return cproj(__x);} static long double _Complex _TG_ATTRS __tg_cproj(long double __x) {return cprojl(__x);} static float _Complex _TG_ATTRS __tg_cproj(float _Complex __x) {return cprojf(__x);} static double _Complex _TG_ATTRS __tg_cproj(double _Complex __x) {return cproj(__x);} static long double _Complex _TG_ATTRS __tg_cproj(long double _Complex __x) {return cprojl(__x);} #undef cproj #define cproj(__x) __tg_cproj(__tg_promote1((__x))(__x)) // creal static float _TG_ATTRS __tg_creal(float __x) {return __x;} static double _TG_ATTRS __tg_creal(double __x) {return __x;} static long double _TG_ATTRS __tg_creal(long double __x) {return __x;} static float _TG_ATTRS __tg_creal(float _Complex __x) {return crealf(__x);} static double _TG_ATTRS __tg_creal(double _Complex __x) {return creal(__x);} static long double _TG_ATTRS __tg_creal(long double _Complex __x) {return creall(__x);} #undef creal #define creal(__x) __tg_creal(__tg_promote1((__x))(__x)) #undef _TG_ATTRSp #undef _TG_ATTRS #endif /* __cplusplus */ #endif /* __TGMATH_H */
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Headers/avx512erintrin.h
/*===---- avx512fintrin.h - AVX2 intrinsics -----------------------------------=== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *===-----------------------------------------------------------------------=== */ #ifndef __IMMINTRIN_H #error "Never use <avx512erintrin.h> directly; include <immintrin.h> instead." #endif #ifndef __AVX512ERINTRIN_H #define __AVX512ERINTRIN_H // exp2a23 #define _mm512_exp2a23_round_pd(A, R) __extension__ ({ \ (__m512d)__builtin_ia32_exp2pd_mask((__v8df)(__m512d)(A), \ (__v8df)_mm512_setzero_pd(), \ (__mmask8)-1, (R)); }) #define _mm512_mask_exp2a23_round_pd(S, M, A, R) __extension__ ({ \ (__m512d)__builtin_ia32_exp2pd_mask((__v8df)(__m512d)(A), \ (__v8df)(__m512d)(S), \ (__mmask8)(M), (R)); }) #define _mm512_maskz_exp2a23_round_pd(M, A, R) __extension__ ({ \ (__m512d)__builtin_ia32_exp2pd_mask((__v8df)(__m512d)(A), \ (__v8df)_mm512_setzero_pd(), \ (__mmask8)(M), (R)); }) #define _mm512_exp2a23_pd(A) \ _mm512_exp2a23_round_pd((A), _MM_FROUND_CUR_DIRECTION) #define _mm512_mask_exp2a23_pd(S, M, A) \ _mm512_mask_exp2a23_round_pd((S), (M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_maskz_exp2a23_pd(M, A) \ _mm512_maskz_exp2a23_round_pd((M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_exp2a23_round_ps(A, R) __extension__ ({ \ (__m512)__builtin_ia32_exp2ps_mask((__v16sf)(__m512)(A), \ (__v16sf)_mm512_setzero_ps(), \ (__mmask8)-1, (R)); }) #define _mm512_mask_exp2a23_round_ps(S, M, A, R) __extension__ ({ \ (__m512)__builtin_ia32_exp2ps_mask((__v16sf)(__m512)(A), \ (__v16sf)(__m512)(S), \ (__mmask8)(M), (R)); }) #define _mm512_maskz_exp2a23_round_ps(M, A, R) __extension__ ({ \ (__m512)__builtin_ia32_exp2ps_mask((__v16sf)(__m512)(A), \ (__v16sf)_mm512_setzero_ps(), \ (__mmask8)(M), (R)); }) #define _mm512_exp2a23_ps(A) \ _mm512_exp2a23_round_ps((A), _MM_FROUND_CUR_DIRECTION) #define _mm512_mask_exp2a23_ps(S, M, A) \ _mm512_mask_exp2a23_round_ps((S), (M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_maskz_exp2a23_ps(M, A) \ _mm512_maskz_exp2a23_round_ps((M), (A), _MM_FROUND_CUR_DIRECTION) // rsqrt28 #define _mm512_rsqrt28_round_pd(A, R) __extension__ ({ \ (__m512d)__builtin_ia32_rsqrt28pd_mask((__v8df)(__m512d)(A), \ (__v8df)_mm512_setzero_pd(), \ (__mmask8)-1, (R)); }) #define _mm512_mask_rsqrt28_round_pd(S, M, A, R) __extension__ ({ \ (__m512d)__builtin_ia32_rsqrt28pd_mask((__v8df)(__m512d)(A), \ (__v8df)(__m512d)(S), \ (__mmask8)(M), (R)); }) #define _mm512_maskz_rsqrt28_round_pd(M, A, R) __extension__ ({ \ (__m512d)__builtin_ia32_rsqrt28pd_mask((__v8df)(__m512d)(A), \ (__v8df)_mm512_setzero_pd(), \ (__mmask8)(M), (R)); }) #define _mm512_rsqrt28_pd(A) \ _mm512_rsqrt28_round_pd((A), _MM_FROUND_CUR_DIRECTION) #define _mm512_mask_rsqrt28_pd(S, M, A) \ _mm512_mask_rsqrt28_round_pd((S), (M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_maskz_rsqrt28_pd(M, A) \ _mm512_maskz_rsqrt28_round_pd((M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_rsqrt28_round_ps(A, R) __extension__ ({ \ (__m512)__builtin_ia32_rsqrt28ps_mask((__v16sf)(__m512)(A), \ (__v16sf)_mm512_setzero_ps(), \ (__mmask16)-1, (R)); }) #define _mm512_mask_rsqrt28_round_ps(S, M, A, R) __extension__ ({ \ (__m512)__builtin_ia32_rsqrt28ps_mask((__v16sf)(__m512)(A), \ (__v16sf)(__m512)(S), \ (__mmask16)(M), (R)); }) #define _mm512_maskz_rsqrt28_round_ps(M, A, R) __extension__ ({ \ (__m512)__builtin_ia32_rsqrt28ps_mask((__v16sf)(__m512)(A), \ (__v16sf)_mm512_setzero_ps(), \ (__mmask16)(M), (R)); }) #define _mm512_rsqrt28_ps(A) \ _mm512_rsqrt28_round_ps((A), _MM_FROUND_CUR_DIRECTION) #define _mm512_mask_rsqrt28_ps(S, M, A) \ _mm512_mask_rsqrt28_round_ps((S), (M), A, _MM_FROUND_CUR_DIRECTION) #define _mm512_maskz_rsqrt28_ps(M, A) \ _mm512_maskz_rsqrt28_round_ps((M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm_rsqrt28_round_ss(A, B, R) __extension__ ({ \ (__m128)__builtin_ia32_rsqrt28ss_mask((__v4sf)(__m128)(A), \ (__v4sf)(__m128)(B), \ (__v4sf)_mm_setzero_ps(), \ (__mmask8)-1, (R)); }) #define _mm_mask_rsqrt28_round_ss(S, M, A, B, R) __extension__ ({ \ (__m128)__builtin_ia32_rsqrt28ss_mask((__v4sf)(__m128)(A), \ (__v4sf)(__m128)(B), \ (__v4sf)(__m128)(S), \ (__mmask8)(M), (R)); }) #define _mm_maskz_rsqrt28_round_ss(M, A, B, R) __extension__ ({ \ (__m128)__builtin_ia32_rsqrt28ss_mask((__v4sf)(__m128)(A), \ (__v4sf)(__m128)(B), \ (__v4sf)_mm_setzero_ps(), \ (__mmask8)(M), (R)); }) #define _mm_rsqrt28_ss(A, B) \ _mm_rsqrt28_round_ss((A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_mask_rsqrt28_ss(S, M, A, B) \ _mm_mask_rsqrt28_round_ss((S), (M), (A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_maskz_rsqrt28_ss(M, A, B) \ _mm_maskz_rsqrt28_round_ss((M), (A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_rsqrt28_round_sd(A, B, R) __extension__ ({ \ (__m128d)__builtin_ia32_rsqrt28sd_mask((__v2df)(__m128d)(A), \ (__v2df)(__m128d)(B), \ (__v2df)_mm_setzero_pd(), \ (__mmask8)-1, (R)); }) #define _mm_mask_rsqrt28_round_sd(S, M, A, B, R) __extension__ ({ \ (__m128d)__builtin_ia32_rsqrt28sd_mask((__v2df)(__m128d)(A), \ (__v2df)(__m128d)(B), \ (__v2df)(__m128d)(S), \ (__mmask8)(M), (R)); }) #define _mm_maskz_rsqrt28_round_sd(M, A, B, R) __extension__ ({ \ (__m128d)__builtin_ia32_rsqrt28sd_mask((__v2df)(__m128d)(A), \ (__v2df)(__m128d)(B), \ (__v2df)_mm_setzero_pd(), \ (__mmask8)(M), (R)); }) #define _mm_rsqrt28_sd(A, B) \ _mm_rsqrt28_round_sd((A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_mask_rsqrt28_sd(S, M, A, B) \ _mm_mask_rsqrt28_round_sd((S), (M), (A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_maskz_rsqrt28_sd(M, A, B) \ _mm_mask_rsqrt28_round_sd((M), (A), (B), _MM_FROUND_CUR_DIRECTION) // rcp28 #define _mm512_rcp28_round_pd(A, R) __extension__ ({ \ (__m512d)__builtin_ia32_rcp28pd_mask((__v8df)(__m512d)(A), \ (__v8df)_mm512_setzero_pd(), \ (__mmask8)-1, (R)); }) #define _mm512_mask_rcp28_round_pd(S, M, A, R) __extension__ ({ \ (__m512d)__builtin_ia32_rcp28pd_mask((__v8df)(__m512d)(A), \ (__v8df)(__m512d)(S), \ (__mmask8)(M), (R)); }) #define _mm512_maskz_rcp28_round_pd(M, A, R) __extension__ ({ \ (__m512d)__builtin_ia32_rcp28pd_mask((__v8df)(__m512d)(A), \ (__v8df)_mm512_setzero_pd(), \ (__mmask8)(M), (R)); }) #define _mm512_rcp28_pd(A) \ _mm512_rcp28_round_pd((A), _MM_FROUND_CUR_DIRECTION) #define _mm512_mask_rcp28_pd(S, M, A) \ _mm512_mask_rcp28_round_pd((S), (M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_maskz_rcp28_pd(M, A) \ _mm512_maskz_rcp28_round_pd((M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_rcp28_round_ps(A, R) __extension__ ({ \ (__m512)__builtin_ia32_rcp28ps_mask((__v16sf)(__m512)(A), \ (__v16sf)_mm512_setzero_ps(), \ (__mmask16)-1, (R)); }) #define _mm512_mask_rcp28_round_ps(S, M, A, R) __extension__ ({ \ (__m512)__builtin_ia32_rcp28ps_mask((__v16sf)(__m512)(A), \ (__v16sf)(__m512)(S), \ (__mmask16)(M), (R)); }) #define _mm512_maskz_rcp28_round_ps(M, A, R) __extension__ ({ \ (__m512)__builtin_ia32_rcp28ps_mask((__v16sf)(__m512)(A), \ (__v16sf)_mm512_setzero_ps(), \ (__mmask16)(M), (R)); }) #define _mm512_rcp28_ps(A) \ _mm512_rcp28_round_ps((A), _MM_FROUND_CUR_DIRECTION) #define _mm512_mask_rcp28_ps(S, M, A) \ _mm512_mask_rcp28_round_ps((S), (M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm512_maskz_rcp28_ps(M, A) \ _mm512_maskz_rcp28_round_ps((M), (A), _MM_FROUND_CUR_DIRECTION) #define _mm_rcp28_round_ss(A, B, R) __extension__ ({ \ (__m128)__builtin_ia32_rcp28ss_mask((__v4sf)(__m128)(A), \ (__v4sf)(__m128)(B), \ (__v4sf)_mm_setzero_ps(), \ (__mmask8)-1, (R)); }) #define _mm_mask_rcp28_round_ss(S, M, A, B, R) __extension__ ({ \ (__m128)__builtin_ia32_rcp28ss_mask((__v4sf)(__m128)(A), \ (__v4sf)(__m128)(B), \ (__v4sf)(__m128)(S), \ (__mmask8)(M), (R)); }) #define _mm_maskz_rcp28_round_ss(M, A, B, R) __extension__ ({ \ (__m128)__builtin_ia32_rcp28ss_mask((__v4sf)(__m128)(A), \ (__v4sf)(__m128)(B), \ (__v4sf)_mm_setzero_ps(), \ (__mmask8)(M), (R)); }) #define _mm_rcp28_ss(A, B) \ _mm_rcp28_round_ss((A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_mask_rcp28_ss(S, M, A, B) \ _mm_mask_rcp28_round_ss((S), (M), (A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_maskz_rcp28_ss(M, A, B) \ _mm_maskz_rcp28_round_ss((M), (A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_rcp28_round_sd(A, B, R) __extension__ ({ \ (__m128d)__builtin_ia32_rcp28sd_mask((__v2df)(__m128d)(A), \ (__v2df)(__m128d)(B), \ (__v2df)_mm_setzero_pd(), \ (__mmask8)-1, (R)); }) #define _mm_mask_rcp28_round_sd(S, M, A, B, R) __extension__ ({ \ (__m128d)__builtin_ia32_rcp28sd_mask((__v2df)(__m128d)(A), \ (__v2df)(__m128d)(B), \ (__v2df)(__m128d)(S), \ (__mmask8)(M), (R)); }) #define _mm_maskz_rcp28_round_sd(M, A, B, R) __extension__ ({ \ (__m128d)__builtin_ia32_rcp28sd_mask((__v2df)(__m128d)(A), \ (__v2df)(__m128d)(B), \ (__v2df)_mm_setzero_pd(), \ (__mmask8)(M), (R)); }) #define _mm_rcp28_sd(A, B) \ _mm_rcp28_round_sd((A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_mask_rcp28_sd(S, M, A, B) \ _mm_mask_rcp28_round_sd((S), (M), (A), (B), _MM_FROUND_CUR_DIRECTION) #define _mm_maskz_rcp28_sd(M, A, B) \ _mm_maskz_rcp28_round_sd((M), (A), (B), _MM_FROUND_CUR_DIRECTION) #endif // __AVX512ERINTRIN_H
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/SanitizerArgs.cpp
//===--- SanitizerArgs.cpp - Arguments for sanitizer tools ---------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/SanitizerArgs.h" #include "Tools.h" #include "clang/Basic/Sanitizers.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/SpecialCaseList.h" #include <memory> // // /////////////////////////////////////////////////////////////////////////////// using namespace clang; using namespace clang::SanitizerKind; using namespace clang::driver; using namespace llvm::opt; enum : SanitizerMask { NeedsUbsanRt = Undefined | Integer | CFI, NeedsUbsanCxxRt = Vptr | CFI, NotAllowedWithTrap = Vptr, RequiresPIE = Memory | DataFlow, NeedsUnwindTables = Address | Thread | Memory | DataFlow, SupportsCoverage = Address | Memory | Leak | Undefined | Integer | DataFlow, RecoverableByDefault = Undefined | Integer, Unrecoverable = Address | Unreachable | Return, LegacyFsanitizeRecoverMask = Undefined | Integer, NeedsLTO = CFI, TrappingSupported = (Undefined & ~Vptr) | UnsignedIntegerOverflow | LocalBounds | CFI, TrappingDefault = CFI, }; enum CoverageFeature { CoverageFunc = 1 << 0, CoverageBB = 1 << 1, CoverageEdge = 1 << 2, CoverageIndirCall = 1 << 3, CoverageTraceBB = 1 << 4, CoverageTraceCmp = 1 << 5, Coverage8bitCounters = 1 << 6, }; /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any /// invalid components. Returns a SanitizerMask. static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors); /// Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid /// components. Returns OR of members of \c CoverageFeature enumeration. static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A); /// Produce an argument string from ArgList \p Args, which shows how it /// provides some sanitizer kind from \p Mask. For example, the argument list /// "-fsanitize=thread,vptr -fsanitize=address" with mask \c NeedsUbsanRt /// would produce "-fsanitize=vptr". static std::string lastArgumentForMask(const Driver &D, const llvm::opt::ArgList &Args, SanitizerMask Mask); /// Produce an argument string from argument \p A, which shows how it provides /// a value in \p Mask. For instance, the argument /// "-fsanitize=address,alignment" with mask \c NeedsUbsanRt would produce /// "-fsanitize=alignment". static std::string describeSanitizeArg(const llvm::opt::Arg *A, SanitizerMask Mask); /// Produce a string containing comma-separated names of sanitizers in \p /// Sanitizers set. static std::string toString(const clang::SanitizerSet &Sanitizers); static bool getDefaultBlacklist(const Driver &D, SanitizerMask Kinds, std::string &BLPath) { const char *BlacklistFile = nullptr; if (Kinds & Address) BlacklistFile = "asan_blacklist.txt"; else if (Kinds & Memory) BlacklistFile = "msan_blacklist.txt"; else if (Kinds & Thread) BlacklistFile = "tsan_blacklist.txt"; else if (Kinds & DataFlow) BlacklistFile = "dfsan_abilist.txt"; if (BlacklistFile) { clang::SmallString<64> Path(D.ResourceDir); llvm::sys::path::append(Path, BlacklistFile); BLPath = Path.str(); return true; } return false; } /// Sets group bits for every group that has at least one representative already /// enabled in \p Kinds. static SanitizerMask setGroupBits(SanitizerMask Kinds) { #define SANITIZER(NAME, ID) #define SANITIZER_GROUP(NAME, ID, ALIAS) \ if (Kinds & SanitizerKind::ID) \ Kinds |= SanitizerKind::ID##Group; #include "clang/Basic/Sanitizers.def" return Kinds; } static SanitizerMask parseSanitizeTrapArgs(const Driver &D, const llvm::opt::ArgList &Args) { SanitizerMask TrapRemove = 0; // During the loop below, the accumulated set of // sanitizers disabled by the current sanitizer // argument or any argument after it. SanitizerMask TrappingKinds = 0; SanitizerMask TrappingSupportedWithGroups = setGroupBits(TrappingSupported); for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend(); I != E; ++I) { const auto *Arg = *I; if (Arg->getOption().matches(options::OPT_fsanitize_trap_EQ)) { Arg->claim(); SanitizerMask Add = parseArgValues(D, Arg, true); Add &= ~TrapRemove; if (SanitizerMask InvalidValues = Add & ~TrappingSupportedWithGroups) { SanitizerSet S; S.Mask = InvalidValues; D.Diag(diag::err_drv_unsupported_option_argument) << "-fsanitize-trap" << toString(S); } TrappingKinds |= expandSanitizerGroups(Add) & ~TrapRemove; } else if (Arg->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) { Arg->claim(); TrapRemove |= expandSanitizerGroups(parseArgValues(D, Arg, true)); } else if (Arg->getOption().matches( options::OPT_fsanitize_undefined_trap_on_error)) { Arg->claim(); TrappingKinds |= expandSanitizerGroups(UndefinedGroup & ~TrapRemove) & ~TrapRemove; } else if (Arg->getOption().matches( options::OPT_fno_sanitize_undefined_trap_on_error)) { Arg->claim(); TrapRemove |= expandSanitizerGroups(UndefinedGroup); } } // Apply default trapping behavior. TrappingKinds |= TrappingDefault & ~TrapRemove; return TrappingKinds; } bool SanitizerArgs::needsUbsanRt() const { return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) && !Sanitizers.has(Address) && !Sanitizers.has(Memory) && !Sanitizers.has(Thread); } bool SanitizerArgs::requiresPIE() const { return AsanZeroBaseShadow || (Sanitizers.Mask & RequiresPIE); } bool SanitizerArgs::needsUnwindTables() const { return Sanitizers.Mask & NeedsUnwindTables; } void SanitizerArgs::clear() { Sanitizers.clear(); RecoverableSanitizers.clear(); TrapSanitizers.clear(); BlacklistFiles.clear(); CoverageFeatures = 0; MsanTrackOrigins = 0; MsanUseAfterDtor = false; AsanFieldPadding = 0; AsanZeroBaseShadow = false; AsanSharedRuntime = false; LinkCXXRuntimes = false; } SanitizerArgs::SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args) { clear(); SanitizerMask AllRemove = 0; // During the loop below, the accumulated set of // sanitizers disabled by the current sanitizer // argument or any argument after it. SanitizerMask AllAddedKinds = 0; // Mask of all sanitizers ever enabled by // -fsanitize= flags (directly or via group // expansion), some of which may be disabled // later. Used to carefully prune // unused-argument diagnostics. SanitizerMask DiagnosedKinds = 0; // All Kinds we have diagnosed up to now. // Used to deduplicate diagnostics. SanitizerMask Kinds = 0; const SanitizerMask Supported = setGroupBits(TC.getSupportedSanitizers()); ToolChain::RTTIMode RTTIMode = TC.getRTTIMode(); const Driver &D = TC.getDriver(); SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args); SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap; for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend(); I != E; ++I) { const auto *Arg = *I; if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) { Arg->claim(); SanitizerMask Add = parseArgValues(D, Arg, true); AllAddedKinds |= expandSanitizerGroups(Add); // Avoid diagnosing any sanitizer which is disabled later. Add &= ~AllRemove; // At this point we have not expanded groups, so any unsupported // sanitizers in Add are those which have been explicitly enabled. // Diagnose them. if (SanitizerMask KindsToDiagnose = Add & InvalidTrappingKinds & ~DiagnosedKinds) { std::string Desc = describeSanitizeArg(*I, KindsToDiagnose); D.Diag(diag::err_drv_argument_not_allowed_with) << Desc << "-fsanitize-trap=undefined"; DiagnosedKinds |= KindsToDiagnose; } Add &= ~InvalidTrappingKinds; if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) { std::string Desc = describeSanitizeArg(*I, KindsToDiagnose); D.Diag(diag::err_drv_unsupported_opt_for_target) << Desc << TC.getTriple().str(); DiagnosedKinds |= KindsToDiagnose; } Add &= Supported; // Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups // so we don't error out if -fno-rtti and -fsanitize=undefined were // passed. if (Add & Vptr && (RTTIMode == ToolChain::RM_DisabledImplicitly || RTTIMode == ToolChain::RM_DisabledExplicitly)) { if (RTTIMode == ToolChain::RM_DisabledImplicitly) // Warn about not having rtti enabled if the vptr sanitizer is // explicitly enabled D.Diag(diag::warn_drv_disabling_vptr_no_rtti_default); else { const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg(); assert(NoRTTIArg && "RTTI disabled explicitly but we have no argument!"); D.Diag(diag::err_drv_argument_not_allowed_with) << "-fsanitize=vptr" << NoRTTIArg->getAsString(Args); } // Take out the Vptr sanitizer from the enabled sanitizers AllRemove |= Vptr; } Add = expandSanitizerGroups(Add); // Group expansion may have enabled a sanitizer which is disabled later. Add &= ~AllRemove; // Silently discard any unsupported sanitizers implicitly enabled through // group expansion. Add &= ~InvalidTrappingKinds; Add &= Supported; Kinds |= Add; } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) { Arg->claim(); SanitizerMask Remove = parseArgValues(D, Arg, true); AllRemove |= expandSanitizerGroups(Remove); } } // We disable the vptr sanitizer if it was enabled by group expansion but RTTI // is disabled. if ((Kinds & Vptr) && (RTTIMode == ToolChain::RM_DisabledImplicitly || RTTIMode == ToolChain::RM_DisabledExplicitly)) { Kinds &= ~Vptr; } // Check that LTO is enabled if we need it. if ((Kinds & NeedsLTO) && !D.IsUsingLTO(Args)) { D.Diag(diag::err_drv_argument_only_allowed_with) << lastArgumentForMask(D, Args, Kinds & NeedsLTO) << "-flto"; } // Report error if there are non-trapping sanitizers that require // c++abi-specific parts of UBSan runtime, and they are not provided by the // toolchain. We don't have a good way to check the latter, so we just // check if the toolchan supports vptr. if (~Supported & Vptr) { SanitizerMask KindsToDiagnose = Kinds & ~TrappingKinds & NeedsUbsanCxxRt; // The runtime library supports the Microsoft C++ ABI, but only well enough // for CFI. FIXME: Remove this once we support vptr on Windows. if (TC.getTriple().isOSWindows()) KindsToDiagnose &= ~CFI; if (KindsToDiagnose) { SanitizerSet S; S.Mask = KindsToDiagnose; D.Diag(diag::err_drv_unsupported_opt_for_target) << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str(); Kinds &= ~KindsToDiagnose; } } // Warn about incompatible groups of sanitizers. std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = { std::make_pair(Address, Thread), std::make_pair(Address, Memory), std::make_pair(Thread, Memory), std::make_pair(Leak, Thread), std::make_pair(Leak, Memory), std::make_pair(KernelAddress, Address), std::make_pair(KernelAddress, Leak), std::make_pair(KernelAddress, Thread), std::make_pair(KernelAddress, Memory)}; for (auto G : IncompatibleGroups) { SanitizerMask Group = G.first; if (Kinds & Group) { if (SanitizerMask Incompatible = Kinds & G.second) { D.Diag(clang::diag::err_drv_argument_not_allowed_with) << lastArgumentForMask(D, Args, Group) << lastArgumentForMask(D, Args, Incompatible); Kinds &= ~Incompatible; } } } // FIXME: Currently -fsanitize=leak is silently ignored in the presence of // -fsanitize=address. Perhaps it should print an error, or perhaps // -f(-no)sanitize=leak should change whether leak detection is enabled by // default in ASan? // Parse -f(no-)?sanitize-recover flags. SanitizerMask RecoverableKinds = RecoverableByDefault; SanitizerMask DiagnosedUnrecoverableKinds = 0; for (const auto *Arg : Args) { const char *DeprecatedReplacement = nullptr; if (Arg->getOption().matches(options::OPT_fsanitize_recover)) { DeprecatedReplacement = "-fsanitize-recover=undefined,integer"; RecoverableKinds |= expandSanitizerGroups(LegacyFsanitizeRecoverMask); Arg->claim(); } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover)) { DeprecatedReplacement = "-fno-sanitize-recover=undefined,integer"; RecoverableKinds &= ~expandSanitizerGroups(LegacyFsanitizeRecoverMask); Arg->claim(); } else if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) { SanitizerMask Add = parseArgValues(D, Arg, true); // Report error if user explicitly tries to recover from unrecoverable // sanitizer. if (SanitizerMask KindsToDiagnose = Add & Unrecoverable & ~DiagnosedUnrecoverableKinds) { SanitizerSet SetToDiagnose; SetToDiagnose.Mask |= KindsToDiagnose; D.Diag(diag::err_drv_unsupported_option_argument) << Arg->getOption().getName() << toString(SetToDiagnose); DiagnosedUnrecoverableKinds |= KindsToDiagnose; } RecoverableKinds |= expandSanitizerGroups(Add); Arg->claim(); } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover_EQ)) { RecoverableKinds &= ~expandSanitizerGroups(parseArgValues(D, Arg, true)); Arg->claim(); } if (DeprecatedReplacement) { D.Diag(diag::warn_drv_deprecated_arg) << Arg->getAsString(Args) << DeprecatedReplacement; } } RecoverableKinds &= Kinds; RecoverableKinds &= ~Unrecoverable; TrappingKinds &= Kinds; // Setup blacklist files. // Add default blacklist from resource directory. { std::string BLPath; if (getDefaultBlacklist(D, Kinds, BLPath) && llvm::sys::fs::exists(BLPath)) BlacklistFiles.push_back(BLPath); } // Parse -f(no-)sanitize-blacklist options. for (const auto *Arg : Args) { if (Arg->getOption().matches(options::OPT_fsanitize_blacklist)) { Arg->claim(); std::string BLPath = Arg->getValue(); if (llvm::sys::fs::exists(BLPath)) BlacklistFiles.push_back(BLPath); else D.Diag(clang::diag::err_drv_no_such_file) << BLPath; } else if (Arg->getOption().matches(options::OPT_fno_sanitize_blacklist)) { Arg->claim(); BlacklistFiles.clear(); } } // Validate blacklists format. { std::string BLError; std::unique_ptr<llvm::SpecialCaseList> SCL( llvm::SpecialCaseList::create(BlacklistFiles, BLError)); if (!SCL.get()) D.Diag(clang::diag::err_drv_malformed_sanitizer_blacklist) << BLError; } // Parse -f[no-]sanitize-memory-track-origins[=level] options. if (AllAddedKinds & Memory) { if (Arg *A = Args.getLastArg(options::OPT_fsanitize_memory_track_origins_EQ, options::OPT_fsanitize_memory_track_origins, options::OPT_fno_sanitize_memory_track_origins)) { if (A->getOption().matches(options::OPT_fsanitize_memory_track_origins)) { MsanTrackOrigins = 2; } else if (A->getOption().matches( options::OPT_fno_sanitize_memory_track_origins)) { MsanTrackOrigins = 0; } else { StringRef S = A->getValue(); if (S.getAsInteger(0, MsanTrackOrigins) || MsanTrackOrigins < 0 || MsanTrackOrigins > 2) { D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S; } } } MsanUseAfterDtor = Args.hasArg(options::OPT_fsanitize_memory_use_after_dtor); } // Parse -f(no-)?sanitize-coverage flags if coverage is supported by the // enabled sanitizers. if (AllAddedKinds & SupportsCoverage) { for (const auto *Arg : Args) { if (Arg->getOption().matches(options::OPT_fsanitize_coverage)) { Arg->claim(); int LegacySanitizeCoverage; if (Arg->getNumValues() == 1 && !StringRef(Arg->getValue(0)) .getAsInteger(0, LegacySanitizeCoverage) && LegacySanitizeCoverage >= 0 && LegacySanitizeCoverage <= 4) { // TODO: Add deprecation notice for this form. switch (LegacySanitizeCoverage) { case 0: CoverageFeatures = 0; break; case 1: CoverageFeatures = CoverageFunc; break; case 2: CoverageFeatures = CoverageBB; break; case 3: CoverageFeatures = CoverageEdge; break; case 4: CoverageFeatures = CoverageEdge | CoverageIndirCall; break; } continue; } CoverageFeatures |= parseCoverageFeatures(D, Arg); } else if (Arg->getOption().matches(options::OPT_fno_sanitize_coverage)) { Arg->claim(); CoverageFeatures &= ~parseCoverageFeatures(D, Arg); } } } // Choose at most one coverage type: function, bb, or edge. if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageBB)) D.Diag(clang::diag::err_drv_argument_not_allowed_with) << "-fsanitize-coverage=func" << "-fsanitize-coverage=bb"; if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageEdge)) D.Diag(clang::diag::err_drv_argument_not_allowed_with) << "-fsanitize-coverage=func" << "-fsanitize-coverage=edge"; if ((CoverageFeatures & CoverageBB) && (CoverageFeatures & CoverageEdge)) D.Diag(clang::diag::err_drv_argument_not_allowed_with) << "-fsanitize-coverage=bb" << "-fsanitize-coverage=edge"; // Basic block tracing and 8-bit counters require some type of coverage // enabled. int CoverageTypes = CoverageFunc | CoverageBB | CoverageEdge; if ((CoverageFeatures & CoverageTraceBB) && !(CoverageFeatures & CoverageTypes)) D.Diag(clang::diag::err_drv_argument_only_allowed_with) << "-fsanitize-coverage=trace-bb" << "-fsanitize-coverage=(func|bb|edge)"; if ((CoverageFeatures & Coverage8bitCounters) && !(CoverageFeatures & CoverageTypes)) D.Diag(clang::diag::err_drv_argument_only_allowed_with) << "-fsanitize-coverage=8bit-counters" << "-fsanitize-coverage=(func|bb|edge)"; if (AllAddedKinds & Address) { AsanSharedRuntime = Args.hasArg(options::OPT_shared_libasan) || (TC.getTriple().getEnvironment() == llvm::Triple::Android); AsanZeroBaseShadow = (TC.getTriple().getEnvironment() == llvm::Triple::Android); if (Arg *A = Args.getLastArg(options::OPT_fsanitize_address_field_padding)) { StringRef S = A->getValue(); // Legal values are 0 and 1, 2, but in future we may add more levels. if (S.getAsInteger(0, AsanFieldPadding) || AsanFieldPadding < 0 || AsanFieldPadding > 2) { D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S; } } if (Arg *WindowsDebugRTArg = Args.getLastArg(options::OPT__SLASH_MTd, options::OPT__SLASH_MT, options::OPT__SLASH_MDd, options::OPT__SLASH_MD, options::OPT__SLASH_LDd, options::OPT__SLASH_LD)) { switch (WindowsDebugRTArg->getOption().getID()) { case options::OPT__SLASH_MTd: case options::OPT__SLASH_MDd: case options::OPT__SLASH_LDd: D.Diag(clang::diag::err_drv_argument_not_allowed_with) << WindowsDebugRTArg->getAsString(Args) << lastArgumentForMask(D, Args, Address); D.Diag(clang::diag::note_drv_address_sanitizer_debug_runtime); } } } // Parse -link-cxx-sanitizer flag. LinkCXXRuntimes = Args.hasArg(options::OPT_fsanitize_link_cxx_runtime) || D.CCCIsCXX(); // Finally, initialize the set of available and recoverable sanitizers. Sanitizers.Mask |= Kinds; RecoverableSanitizers.Mask |= RecoverableKinds; TrapSanitizers.Mask |= TrappingKinds; } static std::string toString(const clang::SanitizerSet &Sanitizers) { std::string Res; #define SANITIZER(NAME, ID) \ if (Sanitizers.has(ID)) { \ if (!Res.empty()) \ Res += ","; \ Res += NAME; \ } #include "clang/Basic/Sanitizers.def" return Res; } void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const { if (Sanitizers.empty()) return; CmdArgs.push_back(Args.MakeArgString("-fsanitize=" + toString(Sanitizers))); if (!RecoverableSanitizers.empty()) CmdArgs.push_back(Args.MakeArgString("-fsanitize-recover=" + toString(RecoverableSanitizers))); if (!TrapSanitizers.empty()) CmdArgs.push_back( Args.MakeArgString("-fsanitize-trap=" + toString(TrapSanitizers))); for (const auto &BLPath : BlacklistFiles) { SmallString<64> BlacklistOpt("-fsanitize-blacklist="); BlacklistOpt += BLPath; CmdArgs.push_back(Args.MakeArgString(BlacklistOpt)); } if (MsanTrackOrigins) CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-track-origins=" + llvm::utostr(MsanTrackOrigins))); if (MsanUseAfterDtor) CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-use-after-dtor")); if (AsanFieldPadding) CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-field-padding=" + llvm::utostr(AsanFieldPadding))); // Translate available CoverageFeatures to corresponding clang-cc1 flags. std::pair<int, const char *> CoverageFlags[] = { std::make_pair(CoverageFunc, "-fsanitize-coverage-type=1"), std::make_pair(CoverageBB, "-fsanitize-coverage-type=2"), std::make_pair(CoverageEdge, "-fsanitize-coverage-type=3"), std::make_pair(CoverageIndirCall, "-fsanitize-coverage-indirect-calls"), std::make_pair(CoverageTraceBB, "-fsanitize-coverage-trace-bb"), std::make_pair(CoverageTraceCmp, "-fsanitize-coverage-trace-cmp"), std::make_pair(Coverage8bitCounters, "-fsanitize-coverage-8bit-counters")}; for (auto F : CoverageFlags) { if (CoverageFeatures & F.first) CmdArgs.push_back(Args.MakeArgString(F.second)); } // MSan: Workaround for PR16386. // ASan: This is mainly to help LSan with cases such as // https://code.google.com/p/address-sanitizer/issues/detail?id=373 // We can't make this conditional on -fsanitize=leak, as that flag shouldn't // affect compilation. if (Sanitizers.has(Memory) || Sanitizers.has(Address)) CmdArgs.push_back(Args.MakeArgString("-fno-assume-sane-operator-new")); if (TC.getTriple().isOSWindows() && needsUbsanRt()) { // Instruct the code generator to embed linker directives in the object file // that cause the required runtime libraries to be linked. CmdArgs.push_back(Args.MakeArgString( "--dependent-lib=" + tools::getCompilerRT(TC, "ubsan_standalone"))); if (types::isCXX(InputType)) CmdArgs.push_back( Args.MakeArgString("--dependent-lib=" + tools::getCompilerRT(TC, "ubsan_standalone_cxx"))); } } SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors) { assert((A->getOption().matches(options::OPT_fsanitize_EQ) || A->getOption().matches(options::OPT_fno_sanitize_EQ) || A->getOption().matches(options::OPT_fsanitize_recover_EQ) || A->getOption().matches(options::OPT_fno_sanitize_recover_EQ) || A->getOption().matches(options::OPT_fsanitize_trap_EQ) || A->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) && "Invalid argument in parseArgValues!"); SanitizerMask Kinds = 0; for (int i = 0, n = A->getNumValues(); i != n; ++i) { const char *Value = A->getValue(i); SanitizerMask Kind; // Special case: don't accept -fsanitize=all. if (A->getOption().matches(options::OPT_fsanitize_EQ) && 0 == strcmp("all", Value)) Kind = 0; else Kind = parseSanitizerValue(Value, /*AllowGroups=*/true); if (Kind) Kinds |= Kind; else if (DiagnoseErrors) D.Diag(clang::diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Value; } return Kinds; } int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A) { assert(A->getOption().matches(options::OPT_fsanitize_coverage) || A->getOption().matches(options::OPT_fno_sanitize_coverage)); int Features = 0; for (int i = 0, n = A->getNumValues(); i != n; ++i) { const char *Value = A->getValue(i); int F = llvm::StringSwitch<int>(Value) .Case("func", CoverageFunc) .Case("bb", CoverageBB) .Case("edge", CoverageEdge) .Case("indirect-calls", CoverageIndirCall) .Case("trace-bb", CoverageTraceBB) .Case("trace-cmp", CoverageTraceCmp) .Case("8bit-counters", Coverage8bitCounters) .Default(0); if (F == 0) D.Diag(clang::diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Value; Features |= F; } return Features; } std::string lastArgumentForMask(const Driver &D, const llvm::opt::ArgList &Args, SanitizerMask Mask) { for (llvm::opt::ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend(); I != E; ++I) { const auto *Arg = *I; if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) { SanitizerMask AddKinds = expandSanitizerGroups(parseArgValues(D, Arg, false)); if (AddKinds & Mask) return describeSanitizeArg(Arg, Mask); } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) { SanitizerMask RemoveKinds = expandSanitizerGroups(parseArgValues(D, Arg, false)); Mask &= ~RemoveKinds; } } llvm_unreachable("arg list didn't provide expected value"); } std::string describeSanitizeArg(const llvm::opt::Arg *A, SanitizerMask Mask) { assert(A->getOption().matches(options::OPT_fsanitize_EQ) && "Invalid argument in describeSanitizerArg!"); std::string Sanitizers; for (int i = 0, n = A->getNumValues(); i != n; ++i) { if (expandSanitizerGroups( parseSanitizerValue(A->getValue(i), /*AllowGroups=*/true)) & Mask) { if (!Sanitizers.empty()) Sanitizers += ","; Sanitizers += A->getValue(i); } } assert(!Sanitizers.empty() && "arg didn't provide expected value"); return "-fsanitize=" + Sanitizers; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/ToolChains.cpp
//===--- ToolChains.cpp - ToolChain Implementations -----------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "ToolChains.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Version.h" #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/SanitizerArgs.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" #include "llvm/Support/TargetParser.h" #include "llvm/Support/raw_ostream.h" #include <cstdlib> // ::getenv #include <system_error> using namespace clang::driver; using namespace clang::driver::toolchains; using namespace clang; using namespace llvm::opt; MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : ToolChain(D, Triple, Args) { // We expect 'as', 'ld', etc. to be adjacent to our install dir. getProgramPaths().push_back(getDriver().getInstalledDir()); if (getDriver().getInstalledDir() != getDriver().Dir) getProgramPaths().push_back(getDriver().Dir); } /// Darwin - Darwin tool chain for i386 and x86_64. Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : MachO(D, Triple, Args), TargetInitialized(false) {} types::ID MachO::LookupTypeForExtension(const char *Ext) const { types::ID Ty = types::lookupTypeForExtension(Ext); // Darwin always preprocesses assembly files (unless -x is used explicitly). if (Ty == types::TY_PP_Asm) return types::TY_Asm; return Ty; } bool MachO::HasNativeLLVMSupport() const { return true; } /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { if (isTargetIOSBased()) return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); if (isNonFragile) return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); } /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. bool Darwin::hasBlocksRuntime() const { if (isTargetIOSBased()) return !isIPhoneOSVersionLT(3, 2); else { assert(isTargetMacOS() && "unexpected darwin target"); return !isMacosxVersionLT(10, 6); } } // This is just a MachO name translation routine and there's no // way to join this into ARMTargetParser without breaking all // other assumptions. Maybe MachO should consider standardising // their nomenclature. static const char *ArmMachOArchName(StringRef Arch) { return llvm::StringSwitch<const char *>(Arch) .Case("armv6k", "armv6") .Case("armv6m", "armv6m") .Case("armv5tej", "armv5") .Case("xscale", "xscale") .Case("armv4t", "armv4t") .Case("armv7", "armv7") .Cases("armv7a", "armv7-a", "armv7") .Cases("armv7r", "armv7-r", "armv7") .Cases("armv7em", "armv7e-m", "armv7em") .Cases("armv7k", "armv7-k", "armv7k") .Cases("armv7m", "armv7-m", "armv7m") .Cases("armv7s", "armv7-s", "armv7s") .Default(nullptr); } static const char *ArmMachOArchNameCPU(StringRef CPU) { unsigned ArchKind = llvm::ARMTargetParser::parseCPUArch(CPU); if (ArchKind == llvm::ARM::AK_INVALID) return nullptr; StringRef Arch = llvm::ARMTargetParser::getArchName(ArchKind); // FIXME: Make sure this MachO triple mangling is really necessary. // ARMv5* normalises to ARMv5. if (Arch.startswith("armv5")) Arch = Arch.substr(0, 5); // ARMv6*, except ARMv6M, normalises to ARMv6. else if (Arch.startswith("armv6") && !Arch.endswith("6m")) Arch = Arch.substr(0, 5); // ARMv7A normalises to ARMv7. else if (Arch.endswith("v7a")) Arch = Arch.substr(0, 5); return Arch.data(); } static bool isSoftFloatABI(const ArgList &Args) { Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, options::OPT_mfloat_abi_EQ); if (!A) return false; return A->getOption().matches(options::OPT_msoft_float) || (A->getOption().matches(options::OPT_mfloat_abi_EQ) && A->getValue() == StringRef("soft")); } StringRef MachO::getMachOArchName(const ArgList &Args) const { switch (getTriple().getArch()) { default: return getDefaultUniversalArchName(); case llvm::Triple::aarch64: return "arm64"; case llvm::Triple::thumb: case llvm::Triple::arm: { if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) if (const char *Arch = ArmMachOArchName(A->getValue())) return Arch; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) return Arch; return "arm"; } } } Darwin::~Darwin() {} MachO::~MachO() {} std::string MachO::ComputeEffectiveClangTriple(const ArgList &Args, types::ID InputType) const { llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); return Triple.getTriple(); } std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, types::ID InputType) const { llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); // If the target isn't initialized (e.g., an unknown Darwin platform, return // the default triple). if (!isTargetInitialized()) return Triple.getTriple(); SmallString<16> Str; Str += isTargetIOSBased() ? "ios" : "macosx"; Str += getTargetVersion().getAsString(); Triple.setOSName(Str); return Triple.getTriple(); } void Generic_ELF::anchor() {} Tool *MachO::getTool(Action::ActionClass AC) const { switch (AC) { case Action::LipoJobClass: if (!Lipo) Lipo.reset(new tools::darwin::Lipo(*this)); return Lipo.get(); case Action::DsymutilJobClass: if (!Dsymutil) Dsymutil.reset(new tools::darwin::Dsymutil(*this)); return Dsymutil.get(); case Action::VerifyDebugInfoJobClass: if (!VerifyDebug) VerifyDebug.reset(new tools::darwin::VerifyDebug(*this)); return VerifyDebug.get(); default: return ToolChain::getTool(AC); } } Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } Tool *MachO::buildAssembler() const { return new tools::darwin::Assembler(*this); } DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Darwin(D, Triple, Args) {} void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const { // For iOS, 64-bit, promote certain warnings to errors. if (!isTargetMacOS() && getTriple().isArch64Bit()) { // Always enable -Wdeprecated-objc-isa-usage and promote it // to an error. CC1Args.push_back("-Wdeprecated-objc-isa-usage"); CC1Args.push_back("-Werror=deprecated-objc-isa-usage"); // Also error about implicit function declarations, as that // can impact calling conventions. CC1Args.push_back("-Werror=implicit-function-declaration"); } } /// \brief Determine whether Objective-C automated reference counting is /// enabled. static bool isObjCAutoRefCount(const ArgList &Args) { return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); } void DarwinClang::AddLinkARCArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // Avoid linking compatibility stubs on i386 mac. if (isTargetMacOS() && getArch() == llvm::Triple::x86) return; ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true); if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) && runtime.hasSubscripting()) return; CmdArgs.push_back("-force_load"); SmallString<128> P(getDriver().ClangExecutable); llvm::sys::path::remove_filename(P); // 'clang' llvm::sys::path::remove_filename(P); // 'bin' llvm::sys::path::append(P, "lib", "arc", "libarclite_"); // Mash in the platform. if (isTargetIOSSimulator()) P += "iphonesimulator"; else if (isTargetIPhoneOS()) P += "iphoneos"; else P += "macosx"; P += ".a"; CmdArgs.push_back(Args.MakeArgString(P)); } void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, StringRef DarwinLibName, bool AlwaysLink, bool IsEmbedded, bool AddRPath) const { SmallString<128> Dir(getDriver().ResourceDir); llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); SmallString<128> P(Dir); llvm::sys::path::append(P, DarwinLibName); // For now, allow missing resource libraries to support developers who may // not have compiler-rt checked out or integrated into their build (unless // we explicitly force linking with this library). if (AlwaysLink || llvm::sys::fs::exists(P)) CmdArgs.push_back(Args.MakeArgString(P)); // Adding the rpaths might negatively interact when other rpaths are involved, // so we should make sure we add the rpaths last, after all user-specified // rpaths. This is currently true from this place, but we need to be // careful if this function is ever called before user's rpaths are emitted. if (AddRPath) { assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); // Add @executable_path to rpath to support having the dylib copied with // the executable. CmdArgs.push_back("-rpath"); CmdArgs.push_back("@executable_path"); // Add the path to the resource dir to rpath to support using the dylib // from the default location without copying. CmdArgs.push_back("-rpath"); CmdArgs.push_back(Args.MakeArgString(Dir)); } } void Darwin::addProfileRTLibs(const ArgList &Args, ArgStringList &CmdArgs) const { if (!(Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, false) || Args.hasArg(options::OPT_fprofile_generate) || Args.hasArg(options::OPT_fprofile_generate_EQ) || Args.hasArg(options::OPT_fprofile_instr_generate) || Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || Args.hasArg(options::OPT_fcreate_profile) || Args.hasArg(options::OPT_coverage))) return; // Select the appropriate runtime library for the target. if (isTargetIOSBased()) AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a", /*AlwaysLink*/ true); else AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a", /*AlwaysLink*/ true); } void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer) const { if (!Args.hasArg(options::OPT_dynamiclib) && !Args.hasArg(options::OPT_bundle)) { // Sanitizer runtime libraries requires C++. AddCXXStdlibLibArgs(Args, CmdArgs); } assert(isTargetMacOS() || isTargetIOSSimulator()); StringRef OS = isTargetMacOS() ? "osx" : "iossim"; AddLinkRuntimeLib( Args, CmdArgs, (Twine("libclang_rt.") + Sanitizer + "_" + OS + "_dynamic.dylib").str(), /*AlwaysLink*/ true, /*IsEmbedded*/ false, /*AddRPath*/ true); if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export // all RTTI-related symbols that UBSan uses. CmdArgs.push_back("-lc++abi"); } } void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // Darwin only supports the compiler-rt based runtime libraries. switch (GetRuntimeLibType(Args)) { case ToolChain::RLT_CompilerRT: break; default: getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; return; } // Darwin doesn't support real static executables, don't link any runtime // libraries with -static. if (Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_fapple_kext) || Args.hasArg(options::OPT_mkernel)) return; // Reject -static-libgcc for now, we can deal with this when and if someone // cares. This is useful in situations where someone wants to statically link // something like libstdc++, and needs its runtime support routines. if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); return; } const SanitizerArgs &Sanitize = getSanitizerArgs(); if (Sanitize.needsAsanRt()) AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); if (Sanitize.needsUbsanRt()) AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); // Otherwise link libSystem, then the dynamic runtime library, and finally any // target specific static runtime library. CmdArgs.push_back("-lSystem"); // Select the dynamic runtime library and the target specific static library. if (isTargetIOSBased()) { // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, // it never went into the SDK. // Linking against libgcc_s.1 isn't needed for iOS 5.0+ if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && getTriple().getArch() != llvm::Triple::aarch64) CmdArgs.push_back("-lgcc_s.1"); // We currently always need a static runtime library for iOS. AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); } else { assert(isTargetMacOS() && "unexpected non MacOS platform"); // The dynamic runtime library was merged with libSystem for 10.6 and // beyond; only 10.4 and 10.5 need an additional runtime library. if (isMacosxVersionLT(10, 5)) CmdArgs.push_back("-lgcc_s.10.4"); else if (isMacosxVersionLT(10, 6)) CmdArgs.push_back("-lgcc_s.10.5"); // For OS X, we thought we would only need a static runtime library when // targeting 10.4, to provide versions of the static functions which were // omitted from 10.4.dylib. // // Unfortunately, that turned out to not be true, because Darwin system // headers can still use eprintf on i386, and it is not exported from // libSystem. Therefore, we still must provide a runtime library just for // the tiny tiny handful of projects that *might* use that symbol. if (isMacosxVersionLT(10, 5)) { AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); } else { if (getTriple().getArch() == llvm::Triple::x86) AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); } } } void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { const OptTable &Opts = getDriver().getOpts(); // Support allowing the SDKROOT environment variable used by xcrun and other // Xcode tools to define the default sysroot, by making it the default for // isysroot. if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { // Warn if the path does not exist. if (!llvm::sys::fs::exists(A->getValue())) getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); } else { if (char *env = ::getenv("SDKROOT")) { // We only use this value as the default if it is an absolute path, // exists, and it is not the root path. if (llvm::sys::path::is_absolute(env) && llvm::sys::fs::exists(env) && StringRef(env) != "/") { Args.append(Args.MakeSeparateArg( nullptr, Opts.getOption(options::OPT_isysroot), env)); } } } Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); if (OSXVersion && iOSVersion) { getDriver().Diag(diag::err_drv_argument_not_allowed_with) << OSXVersion->getAsString(Args) << iOSVersion->getAsString(Args); iOSVersion = nullptr; } else if (!OSXVersion && !iOSVersion) { // If no deployment target was specified on the command line, check for // environment defines. std::string OSXTarget; std::string iOSTarget; if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) OSXTarget = env; if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) iOSTarget = env; // If there is no command-line argument to specify the Target version and // no environment variable defined, see if we can set the default based // on -isysroot. if (iOSTarget.empty() && OSXTarget.empty() && Args.hasArg(options::OPT_isysroot)) { if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { StringRef isysroot = A->getValue(); // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk size_t BeginSDK = isysroot.rfind("SDKs/"); size_t EndSDK = isysroot.rfind(".sdk"); if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); // Slice the version number out. // Version number is between the first and the last number. size_t StartVer = SDK.find_first_of("0123456789"); size_t EndVer = SDK.find_last_of("0123456789"); if (StartVer != StringRef::npos && EndVer > StartVer) { StringRef Version = SDK.slice(StartVer, EndVer + 1); if (SDK.startswith("iPhoneOS") || SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) OSXTarget = Version; } } } } // If no OSX or iOS target has been specified, try to guess platform // from arch name and compute the version from the triple. if (OSXTarget.empty() && iOSTarget.empty()) { StringRef MachOArchName = getMachOArchName(Args); unsigned Major, Minor, Micro; if (MachOArchName == "armv7" || MachOArchName == "armv7s" || MachOArchName == "arm64") { getTriple().getiOSVersion(Major, Minor, Micro); llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' << Micro; } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && MachOArchName != "armv7em") { if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { getDriver().Diag(diag::err_drv_invalid_darwin_version) << getTriple().getOSName(); } llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' << Micro; } } // Allow conflicts among OSX and iOS for historical reasons, but choose the // default platform. if (!OSXTarget.empty() && !iOSTarget.empty()) { if (getTriple().getArch() == llvm::Triple::arm || getTriple().getArch() == llvm::Triple::aarch64 || getTriple().getArch() == llvm::Triple::thumb) OSXTarget = ""; else iOSTarget = ""; } if (!OSXTarget.empty()) { const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); Args.append(OSXVersion); } else if (!iOSTarget.empty()) { const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); Args.append(iOSVersion); } } DarwinPlatformKind Platform; if (OSXVersion) Platform = MacOS; else if (iOSVersion) Platform = IPhoneOS; else llvm_unreachable("Unable to infer Darwin variant"); // Set the tool chain target information. unsigned Major, Minor, Micro; bool HadExtra; if (Platform == MacOS) { assert(!iOSVersion && "Unknown target platform!"); if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, HadExtra) || HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) getDriver().Diag(diag::err_drv_invalid_version_number) << OSXVersion->getAsString(Args); } else if (Platform == IPhoneOS) { assert(iOSVersion && "Unknown target platform!"); if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, HadExtra) || HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) getDriver().Diag(diag::err_drv_invalid_version_number) << iOSVersion->getAsString(Args); } else llvm_unreachable("unknown kind of Darwin platform"); // Recognize iOS targets with an x86 architecture as the iOS simulator. if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || getTriple().getArch() == llvm::Triple::x86_64)) Platform = IPhoneOSSimulator; setTarget(Platform, Major, Minor, Micro); } void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { CXXStdlibType Type = GetCXXStdlibType(Args); switch (Type) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); break; case ToolChain::CST_Libstdcxx: { // Unfortunately, -lstdc++ doesn't always exist in the standard search path; // it was previously found in the gcc lib dir. However, for all the Darwin // platforms we care about it was -lstdc++.6, so we search for that // explicitly if we can't see an obvious -lstdc++ candidate. // Check in the sysroot first. if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { SmallString<128> P(A->getValue()); llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); if (!llvm::sys::fs::exists(P)) { llvm::sys::path::remove_filename(P); llvm::sys::path::append(P, "libstdc++.6.dylib"); if (llvm::sys::fs::exists(P)) { CmdArgs.push_back(Args.MakeArgString(P)); return; } } } // Otherwise, look in the root. // FIXME: This should be removed someday when we don't have to care about // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. if (!llvm::sys::fs::exists("/usr/lib/libstdc++.dylib") && llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib")) { CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); return; } // Otherwise, let the linker search. CmdArgs.push_back("-lstdc++"); break; } } } void DarwinClang::AddCCKextLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // For Darwin platforms, use the compiler-rt-based support library // instead of the gcc-provided one (which is also incidentally // only present in the gcc lib dir, which makes it hard to find). SmallString<128> P(getDriver().ResourceDir); llvm::sys::path::append(P, "lib", "darwin"); // Use the newer cc_kext for iOS ARM after 6.0. if (!isTargetIPhoneOS() || isTargetIOSSimulator() || getTriple().getArch() == llvm::Triple::aarch64 || !isIPhoneOSVersionLT(6, 0)) { llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); } else { llvm::sys::path::append(P, "libclang_rt.cc_kext_ios5.a"); } // For now, allow missing resource libraries to support developers who may // not have compiler-rt checked out or integrated into their build. if (llvm::sys::fs::exists(P)) CmdArgs.push_back(Args.MakeArgString(P)); } DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, const char *BoundArch) const { DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); const OptTable &Opts = getDriver().getOpts(); // FIXME: We really want to get out of the tool chain level argument // translation business, as it makes the driver functionality much // more opaque. For now, we follow gcc closely solely for the // purpose of easily achieving feature parity & testability. Once we // have something that works, we should reevaluate each translation // and try to push it down into tool specific logic. for (Arg *A : Args) { if (A->getOption().matches(options::OPT_Xarch__)) { // Skip this argument unless the architecture matches either the toolchain // triple arch, or the arch being bound. llvm::Triple::ArchType XarchArch = tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); if (!(XarchArch == getArch() || (BoundArch && XarchArch == tools::darwin::getArchTypeForMachOArchName(BoundArch)))) continue; Arg *OriginalArg = A; unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); unsigned Prev = Index; std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); // If the argument parsing failed or more than one argument was // consumed, the -Xarch_ argument's parameter tried to consume // extra arguments. Emit an error and ignore. // // We also want to disallow any options which would alter the // driver behavior; that isn't going to work in our model. We // use isDriverOption() as an approximation, although things // like -O4 are going to slip through. if (!XarchArg || Index > Prev + 1) { getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) << A->getAsString(Args); continue; } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) << A->getAsString(Args); continue; } XarchArg->setBaseArg(A); A = XarchArg.release(); DAL->AddSynthesizedArg(A); // Linker input arguments require custom handling. The problem is that we // have already constructed the phase actions, so we can not treat them as // "input arguments". if (A->getOption().hasFlag(options::LinkerInput)) { // Convert the argument into individual Zlinker_input_args. for (const char *Value : A->getValues()) { DAL->AddSeparateArg( OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); } continue; } } // Sob. These is strictly gcc compatible for the time being. Apple // gcc translates options twice, which means that self-expanding // options add duplicates. switch ((options::ID)A->getOption().getID()) { default: DAL->append(A); break; case options::OPT_mkernel: case options::OPT_fapple_kext: DAL->append(A); DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); break; case options::OPT_dependency_file: DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); break; case options::OPT_gfull: DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); DAL->AddFlagArg( A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); break; case options::OPT_gused: DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); DAL->AddFlagArg( A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); break; case options::OPT_shared: DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); break; case options::OPT_fconstant_cfstrings: DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); break; case options::OPT_fno_constant_cfstrings: DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); break; case options::OPT_Wnonportable_cfstrings: DAL->AddFlagArg(A, Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); break; case options::OPT_Wno_nonportable_cfstrings: DAL->AddFlagArg( A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); break; case options::OPT_fpascal_strings: DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); break; case options::OPT_fno_pascal_strings: DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); break; } } if (getTriple().getArch() == llvm::Triple::x86 || getTriple().getArch() == llvm::Triple::x86_64) if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), "core2"); // Add the arch options based on the particular spelling of -arch, to match // how the driver driver works. if (BoundArch) { StringRef Name = BoundArch; const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); const Option MArch = Opts.getOption(options::OPT_march_EQ); // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, // which defines the list of which architectures we accept. if (Name == "ppc") ; else if (Name == "ppc601") DAL->AddJoinedArg(nullptr, MCpu, "601"); else if (Name == "ppc603") DAL->AddJoinedArg(nullptr, MCpu, "603"); else if (Name == "ppc604") DAL->AddJoinedArg(nullptr, MCpu, "604"); else if (Name == "ppc604e") DAL->AddJoinedArg(nullptr, MCpu, "604e"); else if (Name == "ppc750") DAL->AddJoinedArg(nullptr, MCpu, "750"); else if (Name == "ppc7400") DAL->AddJoinedArg(nullptr, MCpu, "7400"); else if (Name == "ppc7450") DAL->AddJoinedArg(nullptr, MCpu, "7450"); else if (Name == "ppc970") DAL->AddJoinedArg(nullptr, MCpu, "970"); else if (Name == "ppc64" || Name == "ppc64le") DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); else if (Name == "i386") ; else if (Name == "i486") DAL->AddJoinedArg(nullptr, MArch, "i486"); else if (Name == "i586") DAL->AddJoinedArg(nullptr, MArch, "i586"); else if (Name == "i686") DAL->AddJoinedArg(nullptr, MArch, "i686"); else if (Name == "pentium") DAL->AddJoinedArg(nullptr, MArch, "pentium"); else if (Name == "pentium2") DAL->AddJoinedArg(nullptr, MArch, "pentium2"); else if (Name == "pentpro") DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); else if (Name == "pentIIm3") DAL->AddJoinedArg(nullptr, MArch, "pentium2"); else if (Name == "x86_64") DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); else if (Name == "x86_64h") { DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); } else if (Name == "arm") DAL->AddJoinedArg(nullptr, MArch, "armv4t"); else if (Name == "armv4t") DAL->AddJoinedArg(nullptr, MArch, "armv4t"); else if (Name == "armv5") DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); else if (Name == "xscale") DAL->AddJoinedArg(nullptr, MArch, "xscale"); else if (Name == "armv6") DAL->AddJoinedArg(nullptr, MArch, "armv6k"); else if (Name == "armv6m") DAL->AddJoinedArg(nullptr, MArch, "armv6m"); else if (Name == "armv7") DAL->AddJoinedArg(nullptr, MArch, "armv7a"); else if (Name == "armv7em") DAL->AddJoinedArg(nullptr, MArch, "armv7em"); else if (Name == "armv7k") DAL->AddJoinedArg(nullptr, MArch, "armv7k"); else if (Name == "armv7m") DAL->AddJoinedArg(nullptr, MArch, "armv7m"); else if (Name == "armv7s") DAL->AddJoinedArg(nullptr, MArch, "armv7s"); } return DAL; } void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // Embedded targets are simple at the moment, not supporting sanitizers and // with different libraries for each member of the product { static, PIC } x // { hard-float, soft-float } llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); CompilerRT += tools::arm::getARMFloatABI(getDriver(), Args, getTriple()) == "hard" ? "hard" : "soft"; CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); } DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, const char *BoundArch) const { // First get the generic Apple args, before moving onto Darwin-specific ones. DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); const OptTable &Opts = getDriver().getOpts(); // If no architecture is bound, none of the translations here are relevant. if (!BoundArch) return DAL; // Add an explicit version min argument for the deployment target. We do this // after argument translation because -Xarch_ arguments may add a version min // argument. AddDeploymentTarget(*DAL); // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. // FIXME: It would be far better to avoid inserting those -static arguments, // but we can't check the deployment target in the translation code until // it is set here. if (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0)) { for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie;) { Arg *A = *it; ++it; if (A->getOption().getID() != options::OPT_mkernel && A->getOption().getID() != options::OPT_fapple_kext) continue; assert(it != ie && "unexpected argument translation"); A = *it; assert(A->getOption().getID() == options::OPT_static && "missing expected -static argument"); it = DAL->getArgs().erase(it); } } // Default to use libc++ on OS X 10.9+ and iOS 7+. if (((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0))) && !Args.getLastArg(options::OPT_stdlib_EQ)) DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), "libc++"); // Validate the C++ standard library choice. CXXStdlibType Type = GetCXXStdlibType(*DAL); if (Type == ToolChain::CST_Libcxx) { // Check whether the target provides libc++. StringRef where; // Complain about targeting iOS < 5.0 in any way. if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) where = "iOS 5.0"; if (where != StringRef()) { getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; } } return DAL; } bool MachO::IsUnwindTablesDefault() const { return getArch() == llvm::Triple::x86_64; } bool MachO::UseDwarfDebugFlags() const { if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) return S[0] != '\0'; return false; } bool Darwin::UseSjLjExceptions() const { // Darwin uses SjLj exceptions on ARM. return (getTriple().getArch() == llvm::Triple::arm || getTriple().getArch() == llvm::Triple::thumb); } bool MachO::isPICDefault() const { return true; } bool MachO::isPIEDefault() const { return false; } bool MachO::isPICDefaultForced() const { return (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64); } bool MachO::SupportsProfiling() const { // Profiling instrumentation is only supported on x86. return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; } void Darwin::addMinVersionArgs(const ArgList &Args, ArgStringList &CmdArgs) const { VersionTuple TargetVersion = getTargetVersion(); if (isTargetIOSSimulator()) CmdArgs.push_back("-ios_simulator_version_min"); else if (isTargetIOSBased()) CmdArgs.push_back("-iphoneos_version_min"); else { assert(isTargetMacOS() && "unexpected target"); CmdArgs.push_back("-macosx_version_min"); } CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); } void Darwin::addStartObjectFileArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // Derived from startfile spec. if (Args.hasArg(options::OPT_dynamiclib)) { // Derived from darwin_dylib1 spec. if (isTargetIOSSimulator()) { ; // iOS simulator does not need dylib1.o. } else if (isTargetIPhoneOS()) { if (isIPhoneOSVersionLT(3, 1)) CmdArgs.push_back("-ldylib1.o"); } else { if (isMacosxVersionLT(10, 5)) CmdArgs.push_back("-ldylib1.o"); else if (isMacosxVersionLT(10, 6)) CmdArgs.push_back("-ldylib1.10.5.o"); } } else { if (Args.hasArg(options::OPT_bundle)) { if (!Args.hasArg(options::OPT_static)) { // Derived from darwin_bundle1 spec. if (isTargetIOSSimulator()) { ; // iOS simulator does not need bundle1.o. } else if (isTargetIPhoneOS()) { if (isIPhoneOSVersionLT(3, 1)) CmdArgs.push_back("-lbundle1.o"); } else { if (isMacosxVersionLT(10, 6)) CmdArgs.push_back("-lbundle1.o"); } } } else { if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { if (Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_object) || Args.hasArg(options::OPT_preload)) { CmdArgs.push_back("-lgcrt0.o"); } else { CmdArgs.push_back("-lgcrt1.o"); // darwin_crt2 spec is empty. } // By default on OS X 10.8 and later, we don't link with a crt1.o // file and the linker knows to use _main as the entry point. But, // when compiling with -pg, we need to link with the gcrt1.o file, // so pass the -no_new_main option to tell the linker to use the // "start" symbol as the entry point. if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) CmdArgs.push_back("-no_new_main"); } else { if (Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_object) || Args.hasArg(options::OPT_preload)) { CmdArgs.push_back("-lcrt0.o"); } else { // Derived from darwin_crt1 spec. if (isTargetIOSSimulator()) { ; // iOS simulator does not need crt1.o. } else if (isTargetIPhoneOS()) { if (getArch() == llvm::Triple::aarch64) ; // iOS does not need any crt1 files for arm64 else if (isIPhoneOSVersionLT(3, 1)) CmdArgs.push_back("-lcrt1.o"); else if (isIPhoneOSVersionLT(6, 0)) CmdArgs.push_back("-lcrt1.3.1.o"); } else { if (isMacosxVersionLT(10, 5)) CmdArgs.push_back("-lcrt1.o"); else if (isMacosxVersionLT(10, 6)) CmdArgs.push_back("-lcrt1.10.5.o"); else if (isMacosxVersionLT(10, 8)) CmdArgs.push_back("-lcrt1.10.6.o"); // darwin_crt2 spec is empty. } } } } } if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && isMacosxVersionLT(10, 5)) { const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); CmdArgs.push_back(Str); } } bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } void Darwin::CheckObjCARC() const { if (isTargetIOSBased() || (isTargetMacOS() && !isMacosxVersionLT(10, 6))) return; getDriver().Diag(diag::err_arc_unsupported_on_toolchain); } SanitizerMask Darwin::getSupportedSanitizers() const { SanitizerMask Res = ToolChain::getSupportedSanitizers(); if (isTargetMacOS() || isTargetIOSSimulator()) Res |= SanitizerKind::Address; if (isTargetMacOS()) { if (!isMacosxVersionLT(10, 9)) Res |= SanitizerKind::Vptr; Res |= SanitizerKind::SafeStack; } return Res; } /// Generic_GCC - A tool chain using the 'gcc' command to perform /// all subcommands; this relies on gcc translating the majority of /// command line options. /// \brief Parse a GCCVersion object out of a string of text. /// /// This is the primary means of forming GCCVersion objects. /*static*/ Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; std::pair<StringRef, StringRef> First = VersionText.split('.'); std::pair<StringRef, StringRef> Second = First.second.split('.'); GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) return BadVersion; GoodVersion.MajorStr = First.first.str(); if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) return BadVersion; GoodVersion.MinorStr = Second.first.str(); // First look for a number prefix and parse that if present. Otherwise just // stash the entire patch string in the suffix, and leave the number // unspecified. This covers versions strings such as: // 4.4 // 4.4.0 // 4.4.x // 4.4.2-rc4 // 4.4.x-patched // And retains any patch number it finds. StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); if (!PatchText.empty()) { if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { // Try to parse the number and any suffix. if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || GoodVersion.Patch < 0) return BadVersion; GoodVersion.PatchSuffix = PatchText.substr(EndNumber); } } return GoodVersion; } /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch, StringRef RHSPatchSuffix) const { if (Major != RHSMajor) return Major < RHSMajor; if (Minor != RHSMinor) return Minor < RHSMinor; if (Patch != RHSPatch) { // Note that versions without a specified patch sort higher than those with // a patch. if (RHSPatch == -1) return true; if (Patch == -1) return false; // Otherwise just sort on the patch itself. return Patch < RHSPatch; } if (PatchSuffix != RHSPatchSuffix) { // Sort empty suffixes higher. if (RHSPatchSuffix.empty()) return true; if (PatchSuffix.empty()) return false; // Provide a lexicographic sort to make this a total ordering. return PatchSuffix < RHSPatchSuffix; } // The versions are equal. return false; } static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); if (A) return A->getValue(); return GCC_INSTALL_PREFIX; } /// \brief Initialize a GCCInstallationDetector from the driver. /// /// This performs all of the autodetection and sets up the various paths. /// Once constructed, a GCCInstallationDetector is essentially immutable. /// /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and /// should instead pull the target out of the driver. This is currently /// necessary because the driver doesn't store the final version of the target /// triple. void Generic_GCC::GCCInstallationDetector::init( const Driver &D, const llvm::Triple &TargetTriple, const ArgList &Args) { llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() ? TargetTriple.get64BitArchVariant() : TargetTriple.get32BitArchVariant(); // The library directories which may contain GCC installations. SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; // The compatible GCC triples for this particular architecture. SmallVector<StringRef, 16> CandidateTripleAliases; SmallVector<StringRef, 16> CandidateBiarchTripleAliases; CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, CandidateTripleAliases, CandidateBiarchLibDirs, CandidateBiarchTripleAliases); // Compute the set of prefixes for our search. SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), D.PrefixDirs.end()); StringRef GCCToolchainDir = getGCCToolchainDir(Args); if (GCCToolchainDir != "") { if (GCCToolchainDir.back() == '/') GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / Prefixes.push_back(GCCToolchainDir); } else { // If we have a SysRoot, try that first. if (!D.SysRoot.empty()) { Prefixes.push_back(D.SysRoot); Prefixes.push_back(D.SysRoot + "/usr"); } // Then look for gcc installed alongside clang. Prefixes.push_back(D.InstalledDir + "/.."); // And finally in /usr. if (D.SysRoot.empty()) Prefixes.push_back("/usr"); } // Loop over the various components which exist and select the best GCC // installation available. GCC installs are ranked by version number. Version = GCCVersion::Parse("0.0.0"); for (const std::string &Prefix : Prefixes) { if (!llvm::sys::fs::exists(Prefix)) continue; for (const StringRef Suffix : CandidateLibDirs) { const std::string LibDir = Prefix + Suffix.str(); if (!llvm::sys::fs::exists(LibDir)) continue; for (const StringRef Candidate : CandidateTripleAliases) ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); } for (const StringRef Suffix : CandidateBiarchLibDirs) { const std::string LibDir = Prefix + Suffix.str(); if (!llvm::sys::fs::exists(LibDir)) continue; for (const StringRef Candidate : CandidateBiarchTripleAliases) ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, /*NeedsBiarchSuffix=*/ true); } } } void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { for (const auto &InstallPath : CandidateGCCInstallPaths) OS << "Found candidate GCC installation: " << InstallPath << "\n"; if (!GCCInstallPath.empty()) OS << "Selected GCC installation: " << GCCInstallPath << "\n"; for (const auto &Multilib : Multilibs) OS << "Candidate multilib: " << Multilib << "\n"; if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) OS << "Selected multilib: " << SelectedMultilib << "\n"; } bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { if (BiarchSibling.hasValue()) { M = BiarchSibling.getValue(); return true; } return false; } /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, SmallVectorImpl<StringRef> &LibDirs, SmallVectorImpl<StringRef> &TripleAliases, SmallVectorImpl<StringRef> &BiarchLibDirs, SmallVectorImpl<StringRef> &BiarchTripleAliases) { // Declare a bunch of static data sets that we'll select between below. These // are specifically designed to always refer to string literals to avoid any // lifetime or initialization issues. static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; static const char *const AArch64Triples[] = { "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", "aarch64-redhat-linux"}; static const char *const AArch64beLibDirs[] = {"/lib"}; static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", "aarch64_be-linux-gnu"}; static const char *const ARMLibDirs[] = {"/lib"}; static const char *const ARMTriples[] = {"arm-linux-gnueabi", "arm-linux-androideabi"}; static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", "armv7hl-redhat-linux-gnueabi"}; static const char *const ARMebLibDirs[] = {"/lib"}; static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", "armeb-linux-androideabi"}; static const char *const ARMebHFTriples[] = { "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; static const char *const X86_64Triples[] = { "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E", "x86_64-redhat-linux", "x86_64-suse-linux", "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", "x86_64-slackware-linux", "x86_64-linux-android", "x86_64-unknown-linux"}; static const char *const X32LibDirs[] = {"/libx32"}; static const char *const X86LibDirs[] = {"/lib32", "/lib"}; static const char *const X86Triples[] = { "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux", "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", "i586-linux-gnu"}; static const char *const MIPSLibDirs[] = {"/lib"}; static const char *const MIPSTriples[] = { "mips-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu"}; static const char *const MIPSELLibDirs[] = {"/lib"}; static const char *const MIPSELTriples[] = { "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; static const char *const MIPS64Triples[] = { "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", "mips64-linux-gnuabi64"}; static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; static const char *const MIPS64ELTriples[] = { "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", "mips64el-linux-android", "mips64el-linux-gnuabi64"}; static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; static const char *const PPCTriples[] = { "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; static const char *const PPC64Triples[] = { "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", "powerpc64-suse-linux", "ppc64-redhat-linux"}; static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; static const char *const PPC64LETriples[] = { "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", "sparcv8-linux-gnu"}; static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", "sparcv9-linux-gnu"}; static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; static const char *const SystemZTriples[] = { "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", "s390x-suse-linux", "s390x-redhat-linux"}; using std::begin; using std::end; switch (TargetTriple.getArch()) { case llvm::Triple::aarch64: LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); break; case llvm::Triple::aarch64_be: LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); break; case llvm::Triple::arm: case llvm::Triple::thumb: LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); } else { TripleAliases.append(begin(ARMTriples), end(ARMTriples)); } break; case llvm::Triple::armeb: case llvm::Triple::thumbeb: LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); } else { TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); } break; case llvm::Triple::x86_64: LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); // x32 is always available when x86_64 is available, so adding it as // secondary arch with x86_64 triples if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); } else { BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); } break; case llvm::Triple::x86: LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); TripleAliases.append(begin(X86Triples), end(X86Triples)); BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); break; case llvm::Triple::mips: LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); break; case llvm::Triple::mipsel: LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); break; case llvm::Triple::mips64: LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); break; case llvm::Triple::mips64el: LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); break; case llvm::Triple::ppc: LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); TripleAliases.append(begin(PPCTriples), end(PPCTriples)); BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); break; case llvm::Triple::ppc64: LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); break; case llvm::Triple::ppc64le: LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); break; case llvm::Triple::sparc: LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); break; case llvm::Triple::sparcv9: LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); break; case llvm::Triple::systemz: LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); break; default: // By default, just rely on the standard lib directories and the original // triple. break; } // Always append the drivers target triple to the end, in case it doesn't // match any of our aliases. TripleAliases.push_back(TargetTriple.str()); // Also include the multiarch variant if it's different. if (TargetTriple.str() != BiarchTriple.str()) BiarchTripleAliases.push_back(BiarchTriple.str()); } namespace { // Filter to remove Multilibs that don't exist as a suffix to Path class FilterNonExistent { StringRef Base; public: FilterNonExistent(StringRef Base) : Base(Base) {} bool operator()(const Multilib &M) { return !llvm::sys::fs::exists(Base + M.gccSuffix() + "/crtbegin.o"); } }; } // end anonymous namespace static void addMultilibFlag(bool Enabled, const char *const Flag, std::vector<std::string> &Flags) { if (Enabled) Flags.push_back(std::string("+") + Flag); else Flags.push_back(std::string("-") + Flag); } static bool isMipsArch(llvm::Triple::ArchType Arch) { return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; } static bool isMips32(llvm::Triple::ArchType Arch) { return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; } static bool isMips64(llvm::Triple::ArchType Arch) { return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; } static bool isMipsEL(llvm::Triple::ArchType Arch) { return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; } static bool isMips16(const ArgList &Args) { Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); return A && A->getOption().matches(options::OPT_mips16); } static bool isMicroMips(const ArgList &Args) { Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); return A && A->getOption().matches(options::OPT_mmicromips); } struct DetectedMultilibs { /// The set of multilibs that the detected installation supports. MultilibSet Multilibs; /// The primary multilib appropriate for the given flags. Multilib SelectedMultilib; /// On Biarch systems, this corresponds to the default multilib when /// targeting the non-default multilib. Otherwise, it is empty. llvm::Optional<Multilib> BiarchSibling; }; static Multilib makeMultilib(StringRef commonSuffix) { return Multilib(commonSuffix, commonSuffix, commonSuffix); } static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result) { // Some MIPS toolchains put libraries and object files compiled // using different options in to the sub-directoris which names // reflects the flags used for compilation. For example sysroot // directory might looks like the following examples: // // /usr // /lib <= crt*.o files compiled with '-mips32' // /mips16 // /usr // /lib <= crt*.o files compiled with '-mips16' // /el // /usr // /lib <= crt*.o files compiled with '-mips16 -EL' // // or // // /usr // /lib <= crt*.o files compiled with '-mips32r2' // /mips16 // /usr // /lib <= crt*.o files compiled with '-mips32r2 -mips16' // /mips32 // /usr // /lib <= crt*.o files compiled with '-mips32' FilterNonExistent NonExistent(Path); // Check for FSF toolchain multilibs MultilibSet FSFMipsMultilibs; { auto MArchMips32 = makeMultilib("/mips32") .flag("+m32") .flag("-m64") .flag("-mmicromips") .flag("+march=mips32"); auto MArchMicroMips = makeMultilib("/micromips") .flag("+m32") .flag("-m64") .flag("+mmicromips"); auto MArchMips64r2 = makeMultilib("/mips64r2") .flag("-m32") .flag("+m64") .flag("+march=mips64r2"); auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( "-march=mips64r2"); auto MArchDefault = makeMultilib("") .flag("+m32") .flag("-m64") .flag("-mmicromips") .flag("+march=mips32r2"); auto Mips16 = makeMultilib("/mips16").flag("+mips16"); auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); auto MAbi64 = makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); FSFMipsMultilibs = MultilibSet() .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, MArchDefault) .Maybe(UCLibc) .Maybe(Mips16) .FilterOut("/mips64/mips16") .FilterOut("/mips64r2/mips16") .FilterOut("/micromips/mips16") .Maybe(MAbi64) .FilterOut("/micromips/64") .FilterOut("/mips32/64") .FilterOut("^/64") .FilterOut("/mips16/64") .Either(BigEndian, LittleEndian) .Maybe(SoftFloat) .Maybe(Nan2008) .FilterOut(".*sof/nan2008") .FilterOut(NonExistent) .setIncludeDirsCallback([](StringRef InstallDir, StringRef TripleStr, const Multilib &M) { std::vector<std::string> Dirs; Dirs.push_back((InstallDir + "/include").str()); std::string SysRootInc = InstallDir.str() + "/../../../../sysroot"; if (StringRef(M.includeSuffix()).startswith("/uclibc")) Dirs.push_back(SysRootInc + "/uclibc/usr/include"); else Dirs.push_back(SysRootInc + "/usr/include"); return Dirs; }); } // Check for Code Sourcery toolchain multilibs MultilibSet CSMipsMultilibs; { auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); auto MArchMicroMips = makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); auto DefaultFloat = makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); // Note that this one's osSuffix is "" auto MAbi64 = makeMultilib("") .gccSuffix("/64") .includeSuffix("/64") .flag("+mabi=n64") .flag("-mabi=n32") .flag("-m32"); CSMipsMultilibs = MultilibSet() .Either(MArchMips16, MArchMicroMips, MArchDefault) .Maybe(UCLibc) .Either(SoftFloat, Nan2008, DefaultFloat) .FilterOut("/micromips/nan2008") .FilterOut("/mips16/nan2008") .Either(BigEndian, LittleEndian) .Maybe(MAbi64) .FilterOut("/mips16.*/64") .FilterOut("/micromips.*/64") .FilterOut(NonExistent) .setIncludeDirsCallback([](StringRef InstallDir, StringRef TripleStr, const Multilib &M) { std::vector<std::string> Dirs; Dirs.push_back((InstallDir + "/include").str()); std::string SysRootInc = InstallDir.str() + "/../../../../" + TripleStr.str(); if (StringRef(M.includeSuffix()).startswith("/uclibc")) Dirs.push_back(SysRootInc + "/libc/uclibc/usr/include"); else Dirs.push_back(SysRootInc + "/libc/usr/include"); return Dirs; }); } MultilibSet AndroidMipsMultilibs = MultilibSet() .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) .FilterOut(NonExistent); MultilibSet DebianMipsMultilibs; { Multilib MAbiN32 = Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); Multilib M64 = Multilib() .gccSuffix("/64") .includeSuffix("/64") .flag("+m64") .flag("-m32") .flag("-mabi=n32"); Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); DebianMipsMultilibs = MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); } MultilibSet ImgMultilibs; { auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); auto MAbi64 = makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); ImgMultilibs = MultilibSet() .Maybe(Mips64r6) .Maybe(MAbi64) .Maybe(LittleEndian) .FilterOut(NonExistent) .setIncludeDirsCallback([](StringRef InstallDir, StringRef TripleStr, const Multilib &M) { std::vector<std::string> Dirs; Dirs.push_back((InstallDir + "/include").str()); Dirs.push_back( (InstallDir + "/../../../../sysroot/usr/include").str()); return Dirs; }); } StringRef CPUName; StringRef ABIName; tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); Multilib::flags_list Flags; addMultilibFlag(isMips32(TargetArch), "m32", Flags); addMultilibFlag(isMips64(TargetArch), "m64", Flags); addMultilibFlag(isMips16(Args), "mips16", Flags); addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || CPUName == "mips32r5", "march=mips32r2", Flags); addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || CPUName == "mips64r5" || CPUName == "octeon", "march=mips64r2", Flags); addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", Flags); addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); if (TargetTriple.getEnvironment() == llvm::Triple::Android) { // Select Android toolchain. It's the only choice in that case. if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { Result.Multilibs = AndroidMipsMultilibs; return true; } return false; } if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && TargetTriple.getOS() == llvm::Triple::Linux && TargetTriple.getEnvironment() == llvm::Triple::GNU) { // Select mips-img-linux-gnu toolchain. if (ImgMultilibs.select(Flags, Result.SelectedMultilib)) { Result.Multilibs = ImgMultilibs; return true; } return false; } // Sort candidates. Toolchain that best meets the directories goes first. // Then select the first toolchains matches command line flags. MultilibSet *candidates[] = {&DebianMipsMultilibs, &FSFMipsMultilibs, &CSMipsMultilibs}; std::sort( std::begin(candidates), std::end(candidates), [](MultilibSet *a, MultilibSet *b) { return a->size() > b->size(); }); for (const auto &candidate : candidates) { if (candidate->select(Flags, Result.SelectedMultilib)) { if (candidate == &DebianMipsMultilibs) Result.BiarchSibling = Multilib(); Result.Multilibs = *candidate; return true; } } { // Fallback to the regular toolchain-tree structure. Multilib Default; Result.Multilibs.push_back(Default); Result.Multilibs.FilterOut(NonExistent); if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { Result.BiarchSibling = Multilib(); return true; } } return false; } static bool findBiarchMultilibs(const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, bool NeedsBiarchSuffix, DetectedMultilibs &Result) { // Some versions of SUSE and Fedora on ppc64 put 32-bit libs // in what would normally be GCCInstallPath and put the 64-bit // libs in a subdirectory named 64. The simple logic we follow is that // *if* there is a subdirectory of the right name with crtbegin.o in it, // we use that. If not, and if not a biarch triple alias, we look for // crtbegin.o without the subdirectory. Multilib Default; Multilib Alt64 = Multilib() .gccSuffix("/64") .includeSuffix("/64") .flag("-m32") .flag("+m64") .flag("-mx32"); Multilib Alt32 = Multilib() .gccSuffix("/32") .includeSuffix("/32") .flag("+m32") .flag("-m64") .flag("-mx32"); Multilib Altx32 = Multilib() .gccSuffix("/x32") .includeSuffix("/x32") .flag("-m32") .flag("-m64") .flag("+mx32"); FilterNonExistent NonExistent(Path); // Determine default multilib from: 32, 64, x32 // Also handle cases such as 64 on 32, 32 on 64, etc. enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) Want = WANT64; else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) Want = WANT64; else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) Want = WANT32; else { if (TargetTriple.isArch32Bit()) Want = NeedsBiarchSuffix ? WANT64 : WANT32; else if (IsX32) Want = NeedsBiarchSuffix ? WANT64 : WANTX32; else Want = NeedsBiarchSuffix ? WANT32 : WANT64; } if (Want == WANT32) Default.flag("+m32").flag("-m64").flag("-mx32"); else if (Want == WANT64) Default.flag("-m32").flag("+m64").flag("-mx32"); else if (Want == WANTX32) Default.flag("-m32").flag("-m64").flag("+mx32"); else return false; Result.Multilibs.push_back(Default); Result.Multilibs.push_back(Alt64); Result.Multilibs.push_back(Alt32); Result.Multilibs.push_back(Altx32); Result.Multilibs.FilterOut(NonExistent); Multilib::flags_list Flags; addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) return false; if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || Result.SelectedMultilib == Altx32) Result.BiarchSibling = Default; return true; } void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( const llvm::Triple &TargetTriple, const ArgList &Args, const std::string &LibDir, StringRef CandidateTriple, bool NeedsBiarchSuffix) { llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); // There are various different suffixes involving the triple we // check for. We also record what is necessary to walk from each back // up to the lib directory. const std::string LibSuffixes[] = { "/gcc/" + CandidateTriple.str(), // Debian puts cross-compilers in gcc-cross "/gcc-cross/" + CandidateTriple.str(), "/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), // The Freescale PPC SDK has the gcc libraries in // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. "/" + CandidateTriple.str(), // Ubuntu has a strange mis-matched pair of triples that this happens to // match. // FIXME: It may be worthwhile to generalize this and look for a second // triple. "/i386-linux-gnu/gcc/" + CandidateTriple.str()}; const std::string InstallSuffixes[] = { "/../../..", // gcc/ "/../../..", // gcc-cross/ "/../../../..", // <triple>/gcc/ "/../..", // <triple>/ "/../../../.." // i386-linux-gnu/gcc/<triple>/ }; // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. const unsigned NumLibSuffixes = (llvm::array_lengthof(LibSuffixes) - (TargetArch != llvm::Triple::x86)); for (unsigned i = 0; i < NumLibSuffixes; ++i) { StringRef LibSuffix = LibSuffixes[i]; std::error_code EC; for (llvm::sys::fs::directory_iterator LI(LibDir + LibSuffix, EC), LE; !EC && LI != LE; LI = LI.increment(EC)) { StringRef VersionText = llvm::sys::path::filename(LI->path()); GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); if (CandidateVersion.Major != -1) // Filter obviously bad entries. if (!CandidateGCCInstallPaths.insert(LI->path()).second) continue; // Saw this path before; no need to look at it again. if (CandidateVersion.isOlderThan(4, 1, 1)) continue; if (CandidateVersion <= Version) continue; DetectedMultilibs Detected; // Debian mips multilibs behave more like the rest of the biarch ones, // so handle them there if (isMipsArch(TargetArch)) { if (!findMIPSMultilibs(TargetTriple, LI->path(), Args, Detected)) continue; } else if (!findBiarchMultilibs(TargetTriple, LI->path(), Args, NeedsBiarchSuffix, Detected)) { continue; } Multilibs = Detected.Multilibs; SelectedMultilib = Detected.SelectedMultilib; BiarchSibling = Detected.BiarchSibling; Version = CandidateVersion; GCCTriple.setTriple(CandidateTriple); // FIXME: We hack together the directory name here instead of // using LI to ensure stable path separators across Windows and // Linux. GCCInstallPath = LibDir + LibSuffixes[i] + "/" + VersionText.str(); GCCParentLibPath = GCCInstallPath + InstallSuffixes[i]; IsValid = true; } } } Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : ToolChain(D, Triple, Args), GCCInstallation() { getProgramPaths().push_back(getDriver().getInstalledDir()); if (getDriver().getInstalledDir() != getDriver().Dir) getProgramPaths().push_back(getDriver().Dir); } Generic_GCC::~Generic_GCC() {} Tool *Generic_GCC::getTool(Action::ActionClass AC) const { switch (AC) { case Action::PreprocessJobClass: if (!Preprocess) Preprocess.reset(new tools::gcc::Preprocessor(*this)); return Preprocess.get(); case Action::CompileJobClass: if (!Compile) Compile.reset(new tools::gcc::Compiler(*this)); return Compile.get(); default: return ToolChain::getTool(AC); } } Tool *Generic_GCC::buildAssembler() const { return new tools::gnutools::Assembler(*this); } Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { // Print the information about how we detected the GCC installation. GCCInstallation.print(OS); } bool Generic_GCC::IsUnwindTablesDefault() const { return getArch() == llvm::Triple::x86_64; } bool Generic_GCC::isPICDefault() const { return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); } bool Generic_GCC::isPIEDefault() const { return false; } bool Generic_GCC::isPICDefaultForced() const { return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); } bool Generic_GCC::IsIntegratedAssemblerDefault() const { switch (getTriple().getArch()) { case llvm::Triple::x86: case llvm::Triple::x86_64: case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::bpfel: case llvm::Triple::bpfeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: case llvm::Triple::sparc: case llvm::Triple::sparcel: case llvm::Triple::sparcv9: case llvm::Triple::systemz: return true; default: return false; } } void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); bool UseInitArrayDefault = getTriple().getArch() == llvm::Triple::aarch64 || getTriple().getArch() == llvm::Triple::aarch64_be || (getTriple().getOS() == llvm::Triple::Linux && (!V.isOlderThan(4, 7, 0) || getTriple().getEnvironment() == llvm::Triple::Android)) || getTriple().getOS() == llvm::Triple::NaCl; if (DriverArgs.hasFlag(options::OPT_fuse_init_array, options::OPT_fno_use_init_array, UseInitArrayDefault)) CC1Args.push_back("-fuse-init-array"); } /// Hexagon Toolchain std::string Hexagon_TC::GetGnuDir(const std::string &InstalledDir, const ArgList &Args) { // Locate the rest of the toolchain ... std::string GccToolchain = getGCCToolchainDir(Args); if (!GccToolchain.empty()) return GccToolchain; std::string InstallRelDir = InstalledDir + "/../../gnu"; if (llvm::sys::fs::exists(InstallRelDir)) return InstallRelDir; std::string PrefixRelDir = std::string(LLVM_PREFIX) + "/../gnu"; if (llvm::sys::fs::exists(PrefixRelDir)) return PrefixRelDir; return InstallRelDir; } const char *Hexagon_TC::GetSmallDataThreshold(const ArgList &Args) { Arg *A; A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, options::OPT_msmall_data_threshold_EQ); if (A) return A->getValue(); A = Args.getLastArg(options::OPT_shared, options::OPT_fpic, options::OPT_fPIC); if (A) return "0"; return 0; } bool Hexagon_TC::UsesG0(const char *smallDataThreshold) { return smallDataThreshold && smallDataThreshold[0] == '0'; } static void GetHexagonLibraryPaths(const ArgList &Args, const std::string &Ver, const std::string &MarchString, const std::string &InstalledDir, ToolChain::path_list *LibPaths) { bool buildingLib = Args.hasArg(options::OPT_shared); //---------------------------------------------------------------------------- // -L Args //---------------------------------------------------------------------------- for (Arg *A : Args.filtered(options::OPT_L)) for (const char *Value : A->getValues()) LibPaths->push_back(Value); //---------------------------------------------------------------------------- // Other standard paths //---------------------------------------------------------------------------- const std::string MarchSuffix = "/" + MarchString; const std::string G0Suffix = "/G0"; const std::string MarchG0Suffix = MarchSuffix + G0Suffix; const std::string RootDir = Hexagon_TC::GetGnuDir(InstalledDir, Args) + "/"; // lib/gcc/hexagon/... std::string LibGCCHexagonDir = RootDir + "lib/gcc/hexagon/"; if (buildingLib) { LibPaths->push_back(LibGCCHexagonDir + Ver + MarchG0Suffix); LibPaths->push_back(LibGCCHexagonDir + Ver + G0Suffix); } LibPaths->push_back(LibGCCHexagonDir + Ver + MarchSuffix); LibPaths->push_back(LibGCCHexagonDir + Ver); // lib/gcc/... LibPaths->push_back(RootDir + "lib/gcc"); // hexagon/lib/... std::string HexagonLibDir = RootDir + "hexagon/lib"; if (buildingLib) { LibPaths->push_back(HexagonLibDir + MarchG0Suffix); LibPaths->push_back(HexagonLibDir + G0Suffix); } LibPaths->push_back(HexagonLibDir + MarchSuffix); LibPaths->push_back(HexagonLibDir); } Hexagon_TC::Hexagon_TC(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Linux(D, Triple, Args) { const std::string InstalledDir(getDriver().getInstalledDir()); const std::string GnuDir = Hexagon_TC::GetGnuDir(InstalledDir, Args); // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to // program paths const std::string BinDir(GnuDir + "/bin"); if (llvm::sys::fs::exists(BinDir)) getProgramPaths().push_back(BinDir); // Determine version of GCC libraries and headers to use. const std::string HexagonDir(GnuDir + "/lib/gcc/hexagon"); std::error_code ec; GCCVersion MaxVersion = GCCVersion::Parse("0.0.0"); for (llvm::sys::fs::directory_iterator di(HexagonDir, ec), de; !ec && di != de; di = di.increment(ec)) { GCCVersion cv = GCCVersion::Parse(llvm::sys::path::filename(di->path())); if (MaxVersion < cv) MaxVersion = cv; } GCCLibAndIncVersion = MaxVersion; ToolChain::path_list *LibPaths = &getFilePaths(); // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets // 'elf' OS type, so the Linux paths are not appropriate. When we actually // support 'linux' we'll need to fix this up LibPaths->clear(); GetHexagonLibraryPaths(Args, GetGCCLibAndIncVersion(), GetTargetCPU(Args), InstalledDir, LibPaths); } Hexagon_TC::~Hexagon_TC() {} Tool *Hexagon_TC::buildAssembler() const { return new tools::hexagon::Assembler(*this); } Tool *Hexagon_TC::buildLinker() const { return new tools::hexagon::Linker(*this); } void Hexagon_TC::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); if (DriverArgs.hasArg(options::OPT_nostdinc) || DriverArgs.hasArg(options::OPT_nostdlibinc)) return; std::string Ver(GetGCCLibAndIncVersion()); std::string GnuDir = Hexagon_TC::GetGnuDir(D.InstalledDir, DriverArgs); std::string HexagonDir(GnuDir + "/lib/gcc/hexagon/" + Ver); addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include"); addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include-fixed"); addExternCSystemInclude(DriverArgs, CC1Args, GnuDir + "/hexagon/include"); } void Hexagon_TC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; const Driver &D = getDriver(); std::string Ver(GetGCCLibAndIncVersion()); SmallString<128> IncludeDir( Hexagon_TC::GetGnuDir(D.InstalledDir, DriverArgs)); llvm::sys::path::append(IncludeDir, "hexagon/include/c++/"); llvm::sys::path::append(IncludeDir, Ver); addSystemInclude(DriverArgs, CC1Args, IncludeDir); } ToolChain::CXXStdlibType Hexagon_TC::GetCXXStdlibType(const ArgList &Args) const { Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); if (!A) return ToolChain::CST_Libstdcxx; StringRef Value = A->getValue(); if (Value != "libstdc++") { getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); } return ToolChain::CST_Libstdcxx; } static int getHexagonVersion(const ArgList &Args) { Arg *A = Args.getLastArg(options::OPT_march_EQ, options::OPT_mcpu_EQ); // Select the default CPU (v4) if none was given. if (!A) return 4; // FIXME: produce errors if we cannot parse the version. StringRef WhichHexagon = A->getValue(); if (WhichHexagon.startswith("hexagonv")) { int Val; if (!WhichHexagon.substr(sizeof("hexagonv") - 1).getAsInteger(10, Val)) return Val; } if (WhichHexagon.startswith("v")) { int Val; if (!WhichHexagon.substr(1).getAsInteger(10, Val)) return Val; } // FIXME: should probably be an error. return 4; } StringRef Hexagon_TC::GetTargetCPU(const ArgList &Args) { int V = getHexagonVersion(Args); // FIXME: We don't support versions < 4. We should error on them. switch (V) { default: llvm_unreachable("Unexpected version"); case 5: return "v5"; case 4: return "v4"; case 3: return "v3"; case 2: return "v2"; case 1: return "v1"; } } // End Hexagon /// NaCl Toolchain NaCl_TC::NaCl_TC(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the // default paths, and must instead only use the paths provided // with this toolchain based on architecture. path_list &file_paths = getFilePaths(); path_list &prog_paths = getProgramPaths(); file_paths.clear(); prog_paths.clear(); // Path for library files (libc.a, ...) std::string FilePath(getDriver().Dir + "/../"); // Path for tools (clang, ld, etc..) std::string ProgPath(getDriver().Dir + "/../"); // Path for toolchain libraries (libgcc.a, ...) std::string ToolPath(getDriver().ResourceDir + "/lib/"); switch (Triple.getArch()) { case llvm::Triple::x86: { file_paths.push_back(FilePath + "x86_64-nacl/lib32"); file_paths.push_back(FilePath + "x86_64-nacl/usr/lib32"); prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); file_paths.push_back(ToolPath + "i686-nacl"); break; } case llvm::Triple::x86_64: { file_paths.push_back(FilePath + "x86_64-nacl/lib"); file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); file_paths.push_back(ToolPath + "x86_64-nacl"); break; } case llvm::Triple::arm: { file_paths.push_back(FilePath + "arm-nacl/lib"); file_paths.push_back(FilePath + "arm-nacl/usr/lib"); prog_paths.push_back(ProgPath + "arm-nacl/bin"); file_paths.push_back(ToolPath + "arm-nacl"); break; } case llvm::Triple::mipsel: { file_paths.push_back(FilePath + "mipsel-nacl/lib"); file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); prog_paths.push_back(ProgPath + "bin"); file_paths.push_back(ToolPath + "mipsel-nacl"); break; } default: break; } // Use provided linker, not system linker Linker = GetProgramPath("ld"); NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); } void NaCl_TC::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); if (DriverArgs.hasArg(options::OPT_nostdinc)) return; if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { SmallString<128> P(D.ResourceDir); llvm::sys::path::append(P, "include"); addSystemInclude(DriverArgs, CC1Args, P.str()); } if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; SmallString<128> P(D.Dir + "/../"); switch (getTriple().getArch()) { case llvm::Triple::arm: llvm::sys::path::append(P, "arm-nacl/usr/include"); break; case llvm::Triple::x86: llvm::sys::path::append(P, "x86_64-nacl/usr/include"); break; case llvm::Triple::x86_64: llvm::sys::path::append(P, "x86_64-nacl/usr/include"); break; case llvm::Triple::mipsel: llvm::sys::path::append(P, "mipsel-nacl/usr/include"); break; default: return; } addSystemInclude(DriverArgs, CC1Args, P.str()); llvm::sys::path::remove_filename(P); llvm::sys::path::remove_filename(P); llvm::sys::path::append(P, "include"); addSystemInclude(DriverArgs, CC1Args, P.str()); } void NaCl_TC::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // Check for -stdlib= flags. We only support libc++ but this consumes the arg // if the value is libc++, and emits an error for other values. GetCXXStdlibType(Args); CmdArgs.push_back("-lc++"); } void NaCl_TC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; // Check for -stdlib= flags. We only support libc++ but this consumes the arg // if the value is libc++, and emits an error for other values. GetCXXStdlibType(DriverArgs); SmallString<128> P(D.Dir + "/../"); switch (getTriple().getArch()) { case llvm::Triple::arm: llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); addSystemInclude(DriverArgs, CC1Args, P.str()); break; case llvm::Triple::x86: llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); addSystemInclude(DriverArgs, CC1Args, P.str()); break; case llvm::Triple::x86_64: llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); addSystemInclude(DriverArgs, CC1Args, P.str()); break; case llvm::Triple::mipsel: llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); addSystemInclude(DriverArgs, CC1Args, P.str()); break; default: break; } } ToolChain::CXXStdlibType NaCl_TC::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value == "libc++") return ToolChain::CST_Libcxx; getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); } return ToolChain::CST_Libcxx; } std::string NaCl_TC::ComputeEffectiveClangTriple(const ArgList &Args, types::ID InputType) const { llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); if (TheTriple.getArch() == llvm::Triple::arm && TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); return TheTriple.getTriple(); } Tool *NaCl_TC::buildLinker() const { return new tools::nacltools::Linker(*this); } Tool *NaCl_TC::buildAssembler() const { if (getTriple().getArch() == llvm::Triple::arm) return new tools::nacltools::AssemblerARM(*this); return new tools::gnutools::Assembler(*this); } // End NaCl /// TCEToolChain - A tool chain using the llvm bitcode tools to perform /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. /// Currently does not support anything else but compilation. TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : ToolChain(D, Triple, Args) { // Path mangling to find libexec std::string Path(getDriver().Dir); Path += "/../libexec"; getProgramPaths().push_back(Path); } TCEToolChain::~TCEToolChain() {} bool TCEToolChain::IsMathErrnoDefault() const { return true; } bool TCEToolChain::isPICDefault() const { return false; } bool TCEToolChain::isPIEDefault() const { return false; } bool TCEToolChain::isPICDefaultForced() const { return false; } // CloudABI - CloudABI tool chain which can call ld(1) directly. CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { SmallString<128> P(getDriver().Dir); llvm::sys::path::append(P, "..", getTriple().str(), "lib"); getFilePaths().push_back(P.str()); } void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdlibinc) && DriverArgs.hasArg(options::OPT_nostdincxx)) return; SmallString<128> P(getDriver().Dir); llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); addSystemInclude(DriverArgs, CC1Args, P.str()); } void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { CmdArgs.push_back("-lc++"); CmdArgs.push_back("-lc++abi"); CmdArgs.push_back("-lunwind"); } Tool *CloudABI::buildLinker() const { return new tools::cloudabi::Linker(*this); } /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { getFilePaths().push_back(getDriver().Dir + "/../lib"); getFilePaths().push_back("/usr/lib"); } Tool *OpenBSD::buildAssembler() const { return new tools::openbsd::Assembler(*this); } Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { getFilePaths().push_back(getDriver().Dir + "/../lib"); getFilePaths().push_back("/usr/lib"); } Tool *Bitrig::buildAssembler() const { return new tools::bitrig::Assembler(*this); } Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } ToolChain::CXXStdlibType Bitrig::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value == "libstdc++") return ToolChain::CST_Libstdcxx; if (Value == "libc++") return ToolChain::CST_Libcxx; getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); } return ToolChain::CST_Libcxx; } void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/v1"); break; case ToolChain::CST_Libstdcxx: addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/stdc++"); addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); StringRef Triple = getTriple().str(); if (Triple.startswith("amd64")) addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + Triple.substr(5)); else addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/stdc++/" + Triple); break; } } void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { switch (GetCXXStdlibType(Args)) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); CmdArgs.push_back("-lc++abi"); CmdArgs.push_back("-lpthread"); break; case ToolChain::CST_Libstdcxx: CmdArgs.push_back("-lstdc++"); break; } } /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall // back to '/usr/lib' if it doesn't exist. if ((Triple.getArch() == llvm::Triple::x86 || Triple.getArch() == llvm::Triple::ppc) && llvm::sys::fs::exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); else getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); } ToolChain::CXXStdlibType FreeBSD::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value == "libstdc++") return ToolChain::CST_Libstdcxx; if (Value == "libc++") return ToolChain::CST_Libcxx; getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); } if (getTriple().getOSMajorVersion() >= 10) return ToolChain::CST_Libcxx; return ToolChain::CST_Libstdcxx; } void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/v1"); break; case ToolChain::CST_Libstdcxx: addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/4.2"); addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/4.2/backward"); break; } } Tool *FreeBSD::buildAssembler() const { return new tools::freebsd::Assembler(*this); } Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } bool FreeBSD::UseSjLjExceptions() const { // FreeBSD uses SjLj exceptions on ARM oabi. switch (getTriple().getEnvironment()) { case llvm::Triple::GNUEABIHF: case llvm::Triple::GNUEABI: case llvm::Triple::EABI: return false; default: return (getTriple().getArch() == llvm::Triple::arm || getTriple().getArch() == llvm::Triple::thumb); } } bool FreeBSD::HasNativeLLVMSupport() const { return true; } bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } SanitizerMask FreeBSD::getSupportedSanitizers() const { const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || getTriple().getArch() == llvm::Triple::mips64el; SanitizerMask Res = ToolChain::getSupportedSanitizers(); Res |= SanitizerKind::Address; Res |= SanitizerKind::Vptr; if (IsX86_64 || IsMIPS64) { Res |= SanitizerKind::Leak; Res |= SanitizerKind::Thread; } if (IsX86 || IsX86_64) { Res |= SanitizerKind::SafeStack; } return Res; } /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { if (getDriver().UseStdLib) { // When targeting a 32-bit platform, try the special directory used on // 64-bit hosts, and only fall back to the main library directory if that // doesn't work. // FIXME: It'd be nicer to test if this directory exists, but I'm not sure // what all logic is needed to emulate the '=' prefix here. switch (Triple.getArch()) { case llvm::Triple::x86: getFilePaths().push_back("=/usr/lib/i386"); break; case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: switch (Triple.getEnvironment()) { case llvm::Triple::EABI: case llvm::Triple::GNUEABI: getFilePaths().push_back("=/usr/lib/eabi"); break; case llvm::Triple::EABIHF: case llvm::Triple::GNUEABIHF: getFilePaths().push_back("=/usr/lib/eabihf"); break; default: getFilePaths().push_back("=/usr/lib/oabi"); break; } break; case llvm::Triple::mips64: case llvm::Triple::mips64el: if (tools::mips::hasMipsAbiArg(Args, "o32")) getFilePaths().push_back("=/usr/lib/o32"); else if (tools::mips::hasMipsAbiArg(Args, "64")) getFilePaths().push_back("=/usr/lib/64"); break; case llvm::Triple::ppc: getFilePaths().push_back("=/usr/lib/powerpc"); break; case llvm::Triple::sparc: getFilePaths().push_back("=/usr/lib/sparc"); break; default: break; } getFilePaths().push_back("=/usr/lib"); } } Tool *NetBSD::buildAssembler() const { return new tools::netbsd::Assembler(*this); } Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } ToolChain::CXXStdlibType NetBSD::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value == "libstdc++") return ToolChain::CST_Libstdcxx; if (Value == "libc++") return ToolChain::CST_Libcxx; getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); } unsigned Major, Minor, Micro; getTriple().getOSVersion(Major, Minor, Micro); if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 49) || Major == 0) { switch (getArch()) { case llvm::Triple::aarch64: case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: case llvm::Triple::x86: case llvm::Triple::x86_64: return ToolChain::CST_Libcxx; default: break; } } return ToolChain::CST_Libstdcxx; } void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/c++/"); break; case ToolChain::CST_Libstdcxx: addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/g++"); addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/usr/include/g++/backward"); break; } } /// Minix - Minix tool chain which can call as(1) and ld(1) directly. Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { getFilePaths().push_back(getDriver().Dir + "/../lib"); getFilePaths().push_back("/usr/lib"); } Tool *Minix::buildAssembler() const { return new tools::minix::Assembler(*this); } Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_GCC(D, Triple, Args) { getProgramPaths().push_back(getDriver().getInstalledDir()); if (getDriver().getInstalledDir() != getDriver().Dir) getProgramPaths().push_back(getDriver().Dir); getFilePaths().push_back(getDriver().Dir + "/../lib"); getFilePaths().push_back("/usr/lib"); } Tool *Solaris::buildAssembler() const { return new tools::solaris::Assembler(*this); } Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } /// Distribution (very bare-bones at the moment). enum Distro { // NB: Releases of a particular Linux distro should be kept together // in this enum, because some tests are done by integer comparison against // the first and last known member in the family, e.g. IsRedHat(). ArchLinux, DebianLenny, DebianSqueeze, DebianWheezy, DebianJessie, DebianStretch, Exherbo, RHEL4, RHEL5, RHEL6, RHEL7, Fedora, OpenSUSE, UbuntuHardy, UbuntuIntrepid, UbuntuJaunty, UbuntuKarmic, UbuntuLucid, UbuntuMaverick, UbuntuNatty, UbuntuOneiric, UbuntuPrecise, UbuntuQuantal, UbuntuRaring, UbuntuSaucy, UbuntuTrusty, UbuntuUtopic, UbuntuVivid, UbuntuWily, UnknownDistro }; static bool IsRedhat(enum Distro Distro) { return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL7); } static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } static bool IsDebian(enum Distro Distro) { return Distro >= DebianLenny && Distro <= DebianStretch; } static bool IsUbuntu(enum Distro Distro) { return Distro >= UbuntuHardy && Distro <= UbuntuWily; } static Distro DetectDistro(llvm::Triple::ArchType Arch) { llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = llvm::MemoryBuffer::getFile("/etc/lsb-release"); if (File) { StringRef Data = File.get()->getBuffer(); SmallVector<StringRef, 16> Lines; Data.split(Lines, "\n"); Distro Version = UnknownDistro; for (const StringRef Line : Lines) if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) Version = llvm::StringSwitch<Distro>(Line.substr(17)) .Case("hardy", UbuntuHardy) .Case("intrepid", UbuntuIntrepid) .Case("jaunty", UbuntuJaunty) .Case("karmic", UbuntuKarmic) .Case("lucid", UbuntuLucid) .Case("maverick", UbuntuMaverick) .Case("natty", UbuntuNatty) .Case("oneiric", UbuntuOneiric) .Case("precise", UbuntuPrecise) .Case("quantal", UbuntuQuantal) .Case("raring", UbuntuRaring) .Case("saucy", UbuntuSaucy) .Case("trusty", UbuntuTrusty) .Case("utopic", UbuntuUtopic) .Case("vivid", UbuntuVivid) .Case("wily", UbuntuWily) .Default(UnknownDistro); return Version; } File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); if (File) { StringRef Data = File.get()->getBuffer(); if (Data.startswith("Fedora release")) return Fedora; if (Data.startswith("Red Hat Enterprise Linux") || Data.startswith("CentOS")) { if (Data.find("release 7") != StringRef::npos) return RHEL7; else if (Data.find("release 6") != StringRef::npos) return RHEL6; else if (Data.find("release 5") != StringRef::npos) return RHEL5; else if (Data.find("release 4") != StringRef::npos) return RHEL4; } return UnknownDistro; } File = llvm::MemoryBuffer::getFile("/etc/debian_version"); if (File) { StringRef Data = File.get()->getBuffer(); if (Data[0] == '5') return DebianLenny; else if (Data.startswith("squeeze/sid") || Data[0] == '6') return DebianSqueeze; else if (Data.startswith("wheezy/sid") || Data[0] == '7') return DebianWheezy; else if (Data.startswith("jessie/sid") || Data[0] == '8') return DebianJessie; else if (Data.startswith("stretch/sid") || Data[0] == '9') return DebianStretch; return UnknownDistro; } if (llvm::sys::fs::exists("/etc/SuSE-release")) return OpenSUSE; if (llvm::sys::fs::exists("/etc/exherbo-release")) return Exherbo; if (llvm::sys::fs::exists("/etc/arch-release")) return ArchLinux; return UnknownDistro; } /// \brief Get our best guess at the multiarch triple for a target. /// /// Debian-based systems are starting to use a multiarch setup where they use /// a target-triple directory in the library and header search paths. /// Unfortunately, this triple does not align with the vanilla target triple, /// so we provide a rough mapping here. static std::string getMultiarchTriple(const llvm::Triple &TargetTriple, StringRef SysRoot) { llvm::Triple::EnvironmentType TargetEnvironment = TargetTriple.getEnvironment(); // For most architectures, just use whatever we have rather than trying to be // clever. switch (TargetTriple.getArch()) { default: break; // We use the existence of '/lib/<triple>' as a directory to detect some // common linux triples that don't quite match the Clang triple for both // 32-bit and 64-bit targets. Multiarch fixes its install triples to these // regardless of what the actual target triple is. case llvm::Triple::arm: case llvm::Triple::thumb: if (TargetEnvironment == llvm::Triple::GNUEABIHF) { if (llvm::sys::fs::exists(SysRoot + "/lib/arm-linux-gnueabihf")) return "arm-linux-gnueabihf"; } else { if (llvm::sys::fs::exists(SysRoot + "/lib/arm-linux-gnueabi")) return "arm-linux-gnueabi"; } break; case llvm::Triple::armeb: case llvm::Triple::thumbeb: if (TargetEnvironment == llvm::Triple::GNUEABIHF) { if (llvm::sys::fs::exists(SysRoot + "/lib/armeb-linux-gnueabihf")) return "armeb-linux-gnueabihf"; } else { if (llvm::sys::fs::exists(SysRoot + "/lib/armeb-linux-gnueabi")) return "armeb-linux-gnueabi"; } break; case llvm::Triple::x86: if (llvm::sys::fs::exists(SysRoot + "/lib/i386-linux-gnu")) return "i386-linux-gnu"; break; case llvm::Triple::x86_64: // We don't want this for x32, otherwise it will match x86_64 libs if (TargetEnvironment != llvm::Triple::GNUX32 && llvm::sys::fs::exists(SysRoot + "/lib/x86_64-linux-gnu")) return "x86_64-linux-gnu"; break; case llvm::Triple::aarch64: if (llvm::sys::fs::exists(SysRoot + "/lib/aarch64-linux-gnu")) return "aarch64-linux-gnu"; break; case llvm::Triple::aarch64_be: if (llvm::sys::fs::exists(SysRoot + "/lib/aarch64_be-linux-gnu")) return "aarch64_be-linux-gnu"; break; case llvm::Triple::mips: if (llvm::sys::fs::exists(SysRoot + "/lib/mips-linux-gnu")) return "mips-linux-gnu"; break; case llvm::Triple::mipsel: if (llvm::sys::fs::exists(SysRoot + "/lib/mipsel-linux-gnu")) return "mipsel-linux-gnu"; break; case llvm::Triple::mips64: if (llvm::sys::fs::exists(SysRoot + "/lib/mips64-linux-gnu")) return "mips64-linux-gnu"; if (llvm::sys::fs::exists(SysRoot + "/lib/mips64-linux-gnuabi64")) return "mips64-linux-gnuabi64"; break; case llvm::Triple::mips64el: if (llvm::sys::fs::exists(SysRoot + "/lib/mips64el-linux-gnu")) return "mips64el-linux-gnu"; if (llvm::sys::fs::exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) return "mips64el-linux-gnuabi64"; break; case llvm::Triple::ppc: if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc-linux-gnuspe")) return "powerpc-linux-gnuspe"; if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc-linux-gnu")) return "powerpc-linux-gnu"; break; case llvm::Triple::ppc64: if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc64-linux-gnu")) return "powerpc64-linux-gnu"; break; case llvm::Triple::ppc64le: if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc64le-linux-gnu")) return "powerpc64le-linux-gnu"; break; case llvm::Triple::sparc: if (llvm::sys::fs::exists(SysRoot + "/lib/sparc-linux-gnu")) return "sparc-linux-gnu"; break; case llvm::Triple::sparcv9: if (llvm::sys::fs::exists(SysRoot + "/lib/sparc64-linux-gnu")) return "sparc64-linux-gnu"; break; } return TargetTriple.str(); } static void addPathIfExists(Twine Path, ToolChain::path_list &Paths) { if (llvm::sys::fs::exists(Path)) Paths.push_back(Path.str()); } static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { if (isMipsArch(Triple.getArch())) { // lib32 directory has a special meaning on MIPS targets. // It contains N32 ABI binaries. Use this folder if produce // code for N32 ABI only. if (tools::mips::hasMipsAbiArg(Args, "n32")) return "lib32"; return Triple.isArch32Bit() ? "lib" : "lib64"; } // It happens that only x86 and PPC use the 'lib32' variant of oslibdir, and // using that variant while targeting other architectures causes problems // because the libraries are laid out in shared system roots that can't cope // with a 'lib32' library search path being considered. So we only enable // them when we know we may need it. // // FIXME: This is a bit of a hack. We should really unify this code for // reasoning about oslibdir spellings with the lib dir spellings in the // GCCInstallationDetector, but that is a more significant refactoring. if (Triple.getArch() == llvm::Triple::x86 || Triple.getArch() == llvm::Triple::ppc) return "lib32"; if (Triple.getArch() == llvm::Triple::x86_64 && Triple.getEnvironment() == llvm::Triple::GNUX32) return "libx32"; return Triple.isArch32Bit() ? "lib" : "lib64"; } Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { GCCInstallation.init(D, Triple, Args); Multilibs = GCCInstallation.getMultilibs(); llvm::Triple::ArchType Arch = Triple.getArch(); std::string SysRoot = computeSysRoot(); // Cross-compiling binutils and GCC installations (vanilla and openSUSE at // least) put various tools in a triple-prefixed directory off of the parent // of the GCC installation. We use the GCC triple here to ensure that we end // up with tools that support the same amount of cross compiling as the // detected GCC installation. For example, if we find a GCC installation // targeting x86_64, but it is a bi-arch GCC installation, it can also be // used to target i386. // FIXME: This seems unlikely to be Linux-specific. ToolChain::path_list &PPaths = getProgramPaths(); PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + GCCInstallation.getTriple().str() + "/bin") .str()); Linker = GetLinkerPath(); Distro Distro = DetectDistro(Arch); if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { ExtraOpts.push_back("-z"); ExtraOpts.push_back("relro"); } if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) ExtraOpts.push_back("-X"); const bool IsAndroid = Triple.getEnvironment() == llvm::Triple::Android; const bool IsMips = isMipsArch(Arch); if (IsMips && !SysRoot.empty()) ExtraOpts.push_back("--sysroot=" + SysRoot); // Do not use 'gnu' hash style for Mips targets because .gnu.hash // and the MIPS ABI require .dynsym to be sorted in different ways. // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS // ABI requires a mapping between the GOT and the symbol table. // Android loader does not support .gnu.hash. if (!IsMips && !IsAndroid) { if (IsRedhat(Distro) || IsOpenSUSE(Distro) || (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) ExtraOpts.push_back("--hash-style=gnu"); if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || Distro == UbuntuJaunty || Distro == UbuntuKarmic) ExtraOpts.push_back("--hash-style=both"); } if (IsRedhat(Distro)) ExtraOpts.push_back("--no-add-needed"); if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) ExtraOpts.push_back("--build-id"); if (IsOpenSUSE(Distro)) ExtraOpts.push_back("--enable-new-dtags"); // The selection of paths to try here is designed to match the patterns which // the GCC driver itself uses, as this is part of the GCC-compatible driver. // This was determined by running GCC in a fake filesystem, creating all // possible permutations of these directories, and seeing which ones it added // to the link paths. path_list &Paths = getFilePaths(); const std::string OSLibDir = getOSLibDir(Triple, Args); const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot); // Add the multilib suffixed paths where they are available. if (GCCInstallation.isValid()) { const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); const std::string &LibPath = GCCInstallation.getParentLibPath(); const Multilib &Multilib = GCCInstallation.getMultilib(); // Sourcery CodeBench MIPS toolchain holds some libraries under // a biarch-like suffix of the GCC installation. addPathIfExists((GCCInstallation.getInstallPath() + Multilib.gccSuffix()), Paths); // GCC cross compiling toolchains will install target libraries which ship // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as // any part of the GCC installation in // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat // debatable, but is the reality today. We need to search this tree even // when we have a sysroot somewhere else. It is the responsibility of // whomever is doing the cross build targeting a sysroot using a GCC // installation that is *not* within the system root to ensure two things: // // 1) Any DSOs that are linked in from this tree or from the install path // above must be present on the system root and found via an // appropriate rpath. // 2) There must not be libraries installed into // <prefix>/<triple>/<libdir> unless they should be preferred over // those within the system root. // // Note that this matches the GCC behavior. See the below comment for where // Clang diverges from GCC's behavior. addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib/../" + OSLibDir + Multilib.osSuffix(), Paths); // If the GCC installation we found is inside of the sysroot, we want to // prefer libraries installed in the parent prefix of the GCC installation. // It is important to *not* use these paths when the GCC installation is // outside of the system root as that can pick up unintended libraries. // This usually happens when there is an external cross compiler on the // host system, and a more minimal sysroot available that is the target of // the cross. Note that GCC does include some of these directories in some // configurations but this seems somewhere between questionable and simply // a bug. if (StringRef(LibPath).startswith(SysRoot)) { addPathIfExists(LibPath + "/" + MultiarchTriple, Paths); addPathIfExists(LibPath + "/../" + OSLibDir, Paths); } } // Similar to the logic for GCC above, if we currently running Clang inside // of the requested system root, add its parent library paths to // those searched. // FIXME: It's not clear whether we should use the driver's installed // directory ('Dir' below) or the ResourceDir. if (StringRef(D.Dir).startswith(SysRoot)) { addPathIfExists(D.Dir + "/../lib/" + MultiarchTriple, Paths); addPathIfExists(D.Dir + "/../" + OSLibDir, Paths); } addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths); addPathIfExists(SysRoot + "/lib/../" + OSLibDir, Paths); addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths); addPathIfExists(SysRoot + "/usr/lib/../" + OSLibDir, Paths); // Try walking via the GCC triple path in case of biarch or multiarch GCC // installations with strange symlinks. if (GCCInstallation.isValid()) { addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + "/../../" + OSLibDir, Paths); // Add the 'other' biarch variant path Multilib BiarchSibling; if (GCCInstallation.getBiarchSibling(BiarchSibling)) { addPathIfExists( GCCInstallation.getInstallPath() + BiarchSibling.gccSuffix(), Paths); } // See comments above on the multilib variant for details of why this is // included even from outside the sysroot. const std::string &LibPath = GCCInstallation.getParentLibPath(); const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); const Multilib &Multilib = GCCInstallation.getMultilib(); addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib" + Multilib.osSuffix(), Paths); // See comments above on the multilib variant for details of why this is // only included from within the sysroot. if (StringRef(LibPath).startswith(SysRoot)) addPathIfExists(LibPath, Paths); } // Similar to the logic for GCC above, if we are currently running Clang // inside of the requested system root, add its parent library path to those // searched. // FIXME: It's not clear whether we should use the driver's installed // directory ('Dir' below) or the ResourceDir. if (StringRef(D.Dir).startswith(SysRoot)) addPathIfExists(D.Dir + "/../lib", Paths); addPathIfExists(SysRoot + "/lib", Paths); addPathIfExists(SysRoot + "/usr/lib", Paths); } bool Linux::HasNativeLLVMSupport() const { return true; } Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } Tool *Linux::buildAssembler() const { return new tools::gnutools::Assembler(*this); } std::string Linux::computeSysRoot() const { if (!getDriver().SysRoot.empty()) return getDriver().SysRoot; if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) return std::string(); // Standalone MIPS toolchains use different names for sysroot folder // and put it into different places. Here we try to check some known // variants. const StringRef InstallDir = GCCInstallation.getInstallPath(); const StringRef TripleStr = GCCInstallation.getTriple().str(); const Multilib &Multilib = GCCInstallation.getMultilib(); std::string Path = (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) .str(); if (llvm::sys::fs::exists(Path)) return Path; Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); if (llvm::sys::fs::exists(Path)) return Path; return std::string(); } void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); std::string SysRoot = computeSysRoot(); if (DriverArgs.hasArg(options::OPT_nostdinc)) return; if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { SmallString<128> P(D.ResourceDir); llvm::sys::path::append(P, "include"); addSystemInclude(DriverArgs, CC1Args, P); } if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; // Check for configure-time C include directories. StringRef CIncludeDirs(C_INCLUDE_DIRS); if (CIncludeDirs != "") { SmallVector<StringRef, 5> dirs; CIncludeDirs.split(dirs, ":"); for (StringRef dir : dirs) { StringRef Prefix = llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); } return; } // Lacking those, try to detect the correct set of system includes for the // target triple. // Add include directories specific to the selected multilib set and multilib. if (GCCInstallation.isValid()) { const auto &Callback = Multilibs.includeDirsCallback(); if (Callback) { const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), GCCInstallation.getTriple().str(), GCCInstallation.getMultilib()); for (const auto &Path : IncludePaths) addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); } } // Implement generic Debian multiarch support. const StringRef X86_64MultiarchIncludeDirs[] = { "/usr/include/x86_64-linux-gnu", // FIXME: These are older forms of multiarch. It's not clear that they're // in use in any released version of Debian, so we should consider // removing them. "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; const StringRef X86MultiarchIncludeDirs[] = { "/usr/include/i386-linux-gnu", // FIXME: These are older forms of multiarch. It's not clear that they're // in use in any released version of Debian, so we should consider // removing them. "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", "/usr/include/i486-linux-gnu"}; const StringRef AArch64MultiarchIncludeDirs[] = { "/usr/include/aarch64-linux-gnu"}; const StringRef ARMMultiarchIncludeDirs[] = { "/usr/include/arm-linux-gnueabi"}; const StringRef ARMHFMultiarchIncludeDirs[] = { "/usr/include/arm-linux-gnueabihf"}; const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; const StringRef MIPSELMultiarchIncludeDirs[] = { "/usr/include/mipsel-linux-gnu"}; const StringRef MIPS64MultiarchIncludeDirs[] = { "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; const StringRef MIPS64ELMultiarchIncludeDirs[] = { "/usr/include/mips64el-linux-gnu", "/usr/include/mips64el-linux-gnuabi64"}; const StringRef PPCMultiarchIncludeDirs[] = { "/usr/include/powerpc-linux-gnu"}; const StringRef PPC64MultiarchIncludeDirs[] = { "/usr/include/powerpc64-linux-gnu"}; const StringRef PPC64LEMultiarchIncludeDirs[] = { "/usr/include/powerpc64le-linux-gnu"}; const StringRef SparcMultiarchIncludeDirs[] = { "/usr/include/sparc-linux-gnu"}; const StringRef Sparc64MultiarchIncludeDirs[] = { "/usr/include/sparc64-linux-gnu"}; ArrayRef<StringRef> MultiarchIncludeDirs; switch (getTriple().getArch()) { case llvm::Triple::x86_64: MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; break; case llvm::Triple::x86: MultiarchIncludeDirs = X86MultiarchIncludeDirs; break; case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; break; case llvm::Triple::arm: if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; else MultiarchIncludeDirs = ARMMultiarchIncludeDirs; break; case llvm::Triple::mips: MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; break; case llvm::Triple::mipsel: MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; break; case llvm::Triple::mips64: MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; break; case llvm::Triple::mips64el: MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; break; case llvm::Triple::ppc: MultiarchIncludeDirs = PPCMultiarchIncludeDirs; break; case llvm::Triple::ppc64: MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; break; case llvm::Triple::ppc64le: MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; break; case llvm::Triple::sparc: MultiarchIncludeDirs = SparcMultiarchIncludeDirs; break; case llvm::Triple::sparcv9: MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; break; default: break; } for (StringRef Dir : MultiarchIncludeDirs) { if (llvm::sys::fs::exists(SysRoot + Dir)) { addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); break; } } if (getTriple().getOS() == llvm::Triple::RTEMS) return; // Add an include of '/include' directly. This isn't provided by default by // system GCCs, but is often used with cross-compiling GCCs, and harmless to // add even when Clang is acting as-if it were a system compiler. addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); } /// \brief Helper to add the variant paths of a libstdc++ installation. /*static*/ bool Linux::addLibStdCXXIncludePaths( Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, StringRef TargetMultiarchTriple, Twine IncludeSuffix, const ArgList &DriverArgs, ArgStringList &CC1Args) { if (!llvm::sys::fs::exists(Base + Suffix)) return false; addSystemInclude(DriverArgs, CC1Args, Base + Suffix); // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If // that path exists or we have neither a GCC nor target multiarch triple, use // this vanilla search path. if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || llvm::sys::fs::exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/" + GCCTriple + IncludeSuffix); } else { // Otherwise try to use multiarch naming schemes which have normalized the // triples and put the triple before the suffix. // // GCC surprisingly uses *both* the GCC triple with a multilib suffix and // the target triple, so we support that here. addSystemInclude(DriverArgs, CC1Args, Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); addSystemInclude(DriverArgs, CC1Args, Base + "/" + TargetMultiarchTriple + Suffix); } addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); return true; } void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; // Check if libc++ has been enabled and provide its include paths if so. if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { const std::string LibCXXIncludePathCandidates[] = { // The primary location is within the Clang installation. // FIXME: We shouldn't hard code 'v1' here to make Clang future proof to // newer ABI versions. getDriver().Dir + "/../include/c++/v1", // We also check the system as for a long time this is the only place // Clang looked. // FIXME: We should really remove this. It doesn't make any sense. getDriver().SysRoot + "/usr/include/c++/v1"}; for (const auto &IncludePath : LibCXXIncludePathCandidates) { if (!llvm::sys::fs::exists(IncludePath)) continue; // Add the first candidate that exists. addSystemInclude(DriverArgs, CC1Args, IncludePath); break; } return; } // We need a detected GCC installation on Linux to provide libstdc++'s // headers. We handled the libc++ case above. if (!GCCInstallation.isValid()) return; // By default, look for the C++ headers in an include directory adjacent to // the lib directory of the GCC installation. Note that this is expect to be // equivalent to '/usr/include/c++/X.Y' in almost all cases. StringRef LibDir = GCCInstallation.getParentLibPath(); StringRef InstallDir = GCCInstallation.getInstallPath(); StringRef TripleStr = GCCInstallation.getTriple().str(); const Multilib &Multilib = GCCInstallation.getMultilib(); const std::string GCCMultiarchTriple = getMultiarchTriple(GCCInstallation.getTriple(), getDriver().SysRoot); const std::string TargetMultiarchTriple = getMultiarchTriple(getTriple(), getDriver().SysRoot); const GCCVersion &Version = GCCInstallation.getVersion(); // The primary search for libstdc++ supports multiarch variants. if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", "/c++/" + Version.Text, TripleStr, GCCMultiarchTriple, TargetMultiarchTriple, Multilib.includeSuffix(), DriverArgs, CC1Args)) return; // Otherwise, fall back on a bunch of options which don't use multiarch // layouts for simplicity. const std::string LibStdCXXIncludePathCandidates[] = { // Gentoo is weird and places its headers inside the GCC install, // so if the first attempt to find the headers fails, try these patterns. InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + Version.MinorStr, InstallDir.str() + "/include/g++-v" + Version.MajorStr, // Android standalone toolchain has C++ headers in yet another place. LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, // without a subdirectory corresponding to the gcc version. LibDir.str() + "/../include/c++", }; for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, /*GCCMultiarchTriple*/ "", /*TargetMultiarchTriple*/ "", Multilib.includeSuffix(), DriverArgs, CC1Args)) break; } } bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } SanitizerMask Linux::getSupportedSanitizers() const { const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || getTriple().getArch() == llvm::Triple::mips64el; const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || getTriple().getArch() == llvm::Triple::ppc64le; SanitizerMask Res = ToolChain::getSupportedSanitizers(); Res |= SanitizerKind::Address; Res |= SanitizerKind::KernelAddress; Res |= SanitizerKind::Vptr; if (IsX86_64 || IsMIPS64) { Res |= SanitizerKind::DataFlow; Res |= SanitizerKind::Leak; Res |= SanitizerKind::Thread; } if (IsX86_64 || IsMIPS64 || IsPowerPC64) Res |= SanitizerKind::Memory; if (IsX86 || IsX86_64) { Res |= SanitizerKind::Function; Res |= SanitizerKind::SafeStack; } return Res; } /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { // Path mangling to find libexec getProgramPaths().push_back(getDriver().getInstalledDir()); if (getDriver().getInstalledDir() != getDriver().Dir) getProgramPaths().push_back(getDriver().Dir); getFilePaths().push_back(getDriver().Dir + "/../lib"); getFilePaths().push_back("/usr/lib"); if (llvm::sys::fs::exists("/usr/lib/gcc47")) getFilePaths().push_back("/usr/lib/gcc47"); else getFilePaths().push_back("/usr/lib/gcc44"); } Tool *DragonFly::buildAssembler() const { return new tools::dragonfly::Assembler(*this); } Tool *DragonFly::buildLinker() const { return new tools::dragonfly::Linker(*this); } /// Stub for CUDA toolchain. At the moment we don't have assembler or /// linker and need toolchain mainly to propagate device-side options /// to CC1. CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Linux(D, Triple, Args) {} void CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { Linux::addClangTargetOptions(DriverArgs, CC1Args); CC1Args.push_back("-fcuda-is-device"); } llvm::opt::DerivedArgList * CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, const char *BoundArch) const { DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); const OptTable &Opts = getDriver().getOpts(); for (Arg *A : Args) { if (A->getOption().matches(options::OPT_Xarch__)) { // Skip this argument unless the architecture matches BoundArch if (A->getValue(0) != StringRef(BoundArch)) continue; unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); unsigned Prev = Index; std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); // If the argument parsing failed or more than one argument was // consumed, the -Xarch_ argument's parameter tried to consume // extra arguments. Emit an error and ignore. // // We also want to disallow any options which would alter the // driver behavior; that isn't going to work in our model. We // use isDriverOption() as an approximation, although things // like -O4 are going to slip through. if (!XarchArg || Index > Prev + 1) { getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) << A->getAsString(Args); continue; } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) << A->getAsString(Args); continue; } XarchArg->setBaseArg(A); A = XarchArg.release(); DAL->AddSynthesizedArg(A); } DAL->append(A); } DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); return DAL; } /// XCore tool chain XCore::XCore(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : ToolChain(D, Triple, Args) { // ProgramPaths are found via 'PATH' environment variable. } Tool *XCore::buildAssembler() const { return new tools::XCore::Assembler(*this); } Tool *XCore::buildLinker() const { return new tools::XCore::Linker(*this); } bool XCore::isPICDefault() const { return false; } bool XCore::isPIEDefault() const { return false; } bool XCore::isPICDefaultForced() const { return false; } bool XCore::SupportsProfiling() const { return false; } bool XCore::hasBlocksRuntime() const { return false; } void XCore::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdinc) || DriverArgs.hasArg(options::OPT_nostdlibinc)) return; if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { SmallVector<StringRef, 4> Dirs; const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); ArrayRef<StringRef> DirVec(Dirs); addSystemIncludes(DriverArgs, CC1Args, DirVec); } } void XCore::addClangTargetOptions(const ArgList &DriverArgs, ArgStringList &CC1Args) const { CC1Args.push_back("-nostdsysteminc"); } void XCore::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdinc) || DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { SmallVector<StringRef, 4> Dirs; const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); ArrayRef<StringRef> DirVec(Dirs); addSystemIncludes(DriverArgs, CC1Args, DirVec); } } void XCore::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // We don't output any lib args. This is handled by xcc. } // SHAVEToolChain does not call Clang's C compiler. // We override SelectTool to avoid testing ShouldUseClangCompiler(). Tool *SHAVEToolChain::SelectTool(const JobAction &JA) const { switch (JA.getKind()) { case Action::CompileJobClass: if (!Compiler) Compiler.reset(new tools::SHAVE::Compiler(*this)); return Compiler.get(); case Action::AssembleJobClass: if (!Assembler) Assembler.reset(new tools::SHAVE::Assembler(*this)); return Assembler.get(); default: return ToolChain::getTool(JA.getKind()); } } SHAVEToolChain::SHAVEToolChain(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_GCC(D, Triple, Args) {} SHAVEToolChain::~SHAVEToolChain() {} /// Following are methods necessary to avoid having moviClang be an abstract /// class. Tool *SHAVEToolChain::getTool(Action::ActionClass AC) const { // SelectTool() must find a tool using the method in the superclass. // There's nothing we can do if that fails. llvm_unreachable("SHAVEToolChain can't getTool"); } Tool *SHAVEToolChain::buildLinker() const { // SHAVEToolChain executables can not be linked except by the vendor tools. llvm_unreachable("SHAVEToolChain can't buildLinker"); } Tool *SHAVEToolChain::buildAssembler() const { // This one you'd think should be reachable since we expose an // assembler to the driver, except not the way it expects. llvm_unreachable("SHAVEToolChain can't buildAssembler"); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Tools.cpp
//===--- Tools.cpp - Tools Implementations --------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "Tools.h" #include "InputInfo.h" #include "ToolChains.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Version.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Job.h" #include "clang/Driver/Options.h" #include "clang/Driver/SanitizerArgs.h" #include "clang/Driver/ToolChain.h" #include "clang/Driver/Util.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Twine.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" #include "llvm/Support/TargetParser.h" #include "llvm/Support/Compression.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" #ifdef LLVM_ON_UNIX #include <unistd.h> // For getuid(). #endif using namespace clang::driver; using namespace clang::driver::tools; using namespace clang; using namespace llvm::opt; static void addAssemblerKPIC(const ArgList &Args, ArgStringList &CmdArgs) { Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, options::OPT_fpic, options::OPT_fno_pic, options::OPT_fPIE, options::OPT_fno_PIE, options::OPT_fpie, options::OPT_fno_pie); if (!LastPICArg) return; if (LastPICArg->getOption().matches(options::OPT_fPIC) || LastPICArg->getOption().matches(options::OPT_fpic) || LastPICArg->getOption().matches(options::OPT_fPIE) || LastPICArg->getOption().matches(options::OPT_fpie)) { CmdArgs.push_back("-KPIC"); } } /// CheckPreprocessingOptions - Perform some validation of preprocessing /// arguments that is shared with gcc. static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC)) { if (!Args.hasArg(options::OPT_E) && !Args.hasArg(options::OPT__SLASH_P) && !Args.hasArg(options::OPT__SLASH_EP) && !D.CCCIsCPP()) { D.Diag(diag::err_drv_argument_only_allowed_with) << A->getBaseArg().getAsString(Args) << (D.IsCLMode() ? "/E, /P or /EP" : "-E"); } } } /// CheckCodeGenerationOptions - Perform some validation of code generation /// arguments that is shared with gcc. static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) { // In gcc, only ARM checks this, but it seems reasonable to check universally. if (Args.hasArg(options::OPT_static)) if (const Arg *A = Args.getLastArg(options::OPT_dynamic, options::OPT_mdynamic_no_pic)) D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "-static"; } // Add backslashes to escape spaces and other backslashes. // This is used for the space-separated argument list specified with // the -dwarf-debug-flags option. static void EscapeSpacesAndBackslashes(const char *Arg, SmallVectorImpl<char> &Res) { for (; *Arg; ++Arg) { switch (*Arg) { default: break; case ' ': case '\\': Res.push_back('\\'); break; } Res.push_back(*Arg); } } // Quote target names for inclusion in GNU Make dependency files. // Only the characters '$', '#', ' ', '\t' are quoted. static void QuoteTarget(StringRef Target, SmallVectorImpl<char> &Res) { for (unsigned i = 0, e = Target.size(); i != e; ++i) { switch (Target[i]) { case ' ': case '\t': // Escape the preceding backslashes for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j) Res.push_back('\\'); // Escape the space/tab Res.push_back('\\'); break; case '$': Res.push_back('$'); break; case '#': Res.push_back('\\'); break; default: break; } Res.push_back(Target[i]); } } static void addDirectoryList(const ArgList &Args, ArgStringList &CmdArgs, const char *ArgName, const char *EnvVar) { const char *DirList = ::getenv(EnvVar); bool CombinedArg = false; if (!DirList) return; // Nothing to do. StringRef Name(ArgName); if (Name.equals("-I") || Name.equals("-L")) CombinedArg = true; StringRef Dirs(DirList); if (Dirs.empty()) // Empty string should not add '.'. return; StringRef::size_type Delim; while ((Delim = Dirs.find(llvm::sys::EnvPathSeparator)) != StringRef::npos) { if (Delim == 0) { // Leading colon. if (CombinedArg) { CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + ".")); } else { CmdArgs.push_back(ArgName); CmdArgs.push_back("."); } } else { if (CombinedArg) { CmdArgs.push_back( Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim))); } else { CmdArgs.push_back(ArgName); CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim))); } } Dirs = Dirs.substr(Delim + 1); } if (Dirs.empty()) { // Trailing colon. if (CombinedArg) { CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + ".")); } else { CmdArgs.push_back(ArgName); CmdArgs.push_back("."); } } else { // Add the last path. if (CombinedArg) { CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs)); } else { CmdArgs.push_back(ArgName); CmdArgs.push_back(Args.MakeArgString(Dirs)); } } } static void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const ArgList &Args, ArgStringList &CmdArgs) { const Driver &D = TC.getDriver(); // Add extra linker input arguments which are not treated as inputs // (constructed via -Xarch_). Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input); for (const auto &II : Inputs) { if (!TC.HasNativeLLVMSupport()) { // Don't try to pass LLVM inputs unless we have native support. if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) D.Diag(diag::err_drv_no_linker_llvm_support) << TC.getTripleString(); } // Add filenames immediately. if (II.isFilename()) { CmdArgs.push_back(II.getFilename()); continue; } // Otherwise, this is a linker input argument. const Arg &A = II.getInputArg(); // Handle reserved library options. if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) TC.AddCXXStdlibLibArgs(Args, CmdArgs); else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext)) TC.AddCCKextLibArgs(Args, CmdArgs); else if (A.getOption().matches(options::OPT_z)) { // Pass -z prefix for gcc linker compatibility. A.claim(); A.render(Args, CmdArgs); } else { A.renderAsInput(Args, CmdArgs); } } // LIBRARY_PATH - included following the user specified library paths. // and only supported on native toolchains. if (!TC.isCrossCompiling()) addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); } /// \brief Determine whether Objective-C automated reference counting is /// enabled. static bool isObjCAutoRefCount(const ArgList &Args) { return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); } /// \brief Determine whether we are linking the ObjC runtime. static bool isObjCRuntimeLinked(const ArgList &Args) { if (isObjCAutoRefCount(Args)) { Args.ClaimAllArgs(options::OPT_fobjc_link_runtime); return true; } return Args.hasArg(options::OPT_fobjc_link_runtime); } static bool forwardToGCC(const Option &O) { // Don't forward inputs from the original command line. They are added from // InputInfoList. return O.getKind() != Option::InputClass && !O.hasFlag(options::DriverOption) && !O.hasFlag(options::LinkerInput); } void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, const InputInfo &Output, const InputInfoList &Inputs) const { Arg *A; CheckPreprocessingOptions(D, Args); Args.AddLastArg(CmdArgs, options::OPT_C); Args.AddLastArg(CmdArgs, options::OPT_CC); // Handle dependency file generation. if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) || (A = Args.getLastArg(options::OPT_MD)) || (A = Args.getLastArg(options::OPT_MMD))) { // Determine the output location. const char *DepFile; if (Arg *MF = Args.getLastArg(options::OPT_MF)) { DepFile = MF->getValue(); C.addFailureResultFile(DepFile, &JA); } else if (Output.getType() == types::TY_Dependencies) { DepFile = Output.getFilename(); } else if (A->getOption().matches(options::OPT_M) || A->getOption().matches(options::OPT_MM)) { DepFile = "-"; } else { DepFile = getDependencyFileName(Args, Inputs); C.addFailureResultFile(DepFile, &JA); } CmdArgs.push_back("-dependency-file"); CmdArgs.push_back(DepFile); // Add a default target if one wasn't specified. if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) { const char *DepTarget; // If user provided -o, that is the dependency target, except // when we are only generating a dependency file. Arg *OutputOpt = Args.getLastArg(options::OPT_o); if (OutputOpt && Output.getType() != types::TY_Dependencies) { DepTarget = OutputOpt->getValue(); } else { // Otherwise derive from the base input. // // FIXME: This should use the computed output file location. SmallString<128> P(Inputs[0].getBaseInput()); llvm::sys::path::replace_extension(P, "o"); DepTarget = Args.MakeArgString(llvm::sys::path::filename(P)); } CmdArgs.push_back("-MT"); SmallString<128> Quoted; QuoteTarget(DepTarget, Quoted); CmdArgs.push_back(Args.MakeArgString(Quoted)); } if (A->getOption().matches(options::OPT_M) || A->getOption().matches(options::OPT_MD)) CmdArgs.push_back("-sys-header-deps"); if ((isa<PrecompileJobAction>(JA) && !Args.hasArg(options::OPT_fno_module_file_deps)) || Args.hasArg(options::OPT_fmodule_file_deps)) CmdArgs.push_back("-module-file-deps"); } if (Args.hasArg(options::OPT_MG)) { if (!A || A->getOption().matches(options::OPT_MD) || A->getOption().matches(options::OPT_MMD)) D.Diag(diag::err_drv_mg_requires_m_or_mm); CmdArgs.push_back("-MG"); } Args.AddLastArg(CmdArgs, options::OPT_MP); Args.AddLastArg(CmdArgs, options::OPT_MV); // Convert all -MQ <target> args to -MT <quoted target> for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) { A->claim(); if (A->getOption().matches(options::OPT_MQ)) { CmdArgs.push_back("-MT"); SmallString<128> Quoted; QuoteTarget(A->getValue(), Quoted); CmdArgs.push_back(Args.MakeArgString(Quoted)); // -MT flag - no change } else { A->render(Args, CmdArgs); } } // Add -i* options, and automatically translate to // -include-pch/-include-pth for transparent PCH support. It's // wonky, but we include looking for .gch so we can support seamless // replacement into a build system already set up to be generating // .gch files. bool RenderedImplicitInclude = false; for (const Arg *A : Args.filtered(options::OPT_clang_i_Group)) { if (A->getOption().matches(options::OPT_include)) { bool IsFirstImplicitInclude = !RenderedImplicitInclude; RenderedImplicitInclude = true; // Use PCH if the user requested it. bool UsePCH = D.CCCUsePCH; bool FoundPTH = false; bool FoundPCH = false; SmallString<128> P(A->getValue()); // We want the files to have a name like foo.h.pch. Add a dummy extension // so that replace_extension does the right thing. P += ".dummy"; if (UsePCH) { llvm::sys::path::replace_extension(P, "pch"); if (llvm::sys::fs::exists(P)) FoundPCH = true; } if (!FoundPCH) { llvm::sys::path::replace_extension(P, "pth"); if (llvm::sys::fs::exists(P)) FoundPTH = true; } if (!FoundPCH && !FoundPTH) { llvm::sys::path::replace_extension(P, "gch"); if (llvm::sys::fs::exists(P)) { FoundPCH = UsePCH; FoundPTH = !UsePCH; } } if (FoundPCH || FoundPTH) { if (IsFirstImplicitInclude) { A->claim(); if (UsePCH) CmdArgs.push_back("-include-pch"); else CmdArgs.push_back("-include-pth"); CmdArgs.push_back(Args.MakeArgString(P)); continue; } else { // Ignore the PCH if not first on command line and emit warning. D.Diag(diag::warn_drv_pch_not_first_include) << P << A->getAsString(Args); } } } // Not translated, render as usual. A->claim(); A->render(Args, CmdArgs); } Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F, options::OPT_index_header_map); // Add -Wp, and -Xassembler if using the preprocessor. // FIXME: There is a very unfortunate problem here, some troubled // souls abuse -Wp, to pass preprocessor options in gcc syntax. To // really support that we would have to parse and then translate // those options. :( Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, options::OPT_Xpreprocessor); // -I- is a deprecated GCC feature, reject it. if (Arg *A = Args.getLastArg(options::OPT_I_)) D.Diag(diag::err_drv_I_dash_not_supported) << A->getAsString(Args); // If we have a --sysroot, and don't have an explicit -isysroot flag, add an // -isysroot to the CC1 invocation. StringRef sysroot = C.getSysRoot(); if (sysroot != "") { if (!Args.hasArg(options::OPT_isysroot)) { CmdArgs.push_back("-isysroot"); CmdArgs.push_back(C.getArgs().MakeArgString(sysroot)); } } // Parse additional include paths from environment variables. // FIXME: We should probably sink the logic for handling these from the // frontend into the driver. It will allow deleting 4 otherwise unused flags. // CPATH - included following the user specified includes (but prior to // builtin and standard includes). addDirectoryList(Args, CmdArgs, "-I", "CPATH"); // C_INCLUDE_PATH - system includes enabled when compiling C. addDirectoryList(Args, CmdArgs, "-c-isystem", "C_INCLUDE_PATH"); // CPLUS_INCLUDE_PATH - system includes enabled when compiling C++. addDirectoryList(Args, CmdArgs, "-cxx-isystem", "CPLUS_INCLUDE_PATH"); // OBJC_INCLUDE_PATH - system includes enabled when compiling ObjC. addDirectoryList(Args, CmdArgs, "-objc-isystem", "OBJC_INCLUDE_PATH"); // OBJCPLUS_INCLUDE_PATH - system includes enabled when compiling ObjC++. addDirectoryList(Args, CmdArgs, "-objcxx-isystem", "OBJCPLUS_INCLUDE_PATH"); // Add C++ include arguments, if needed. if (types::isCXX(Inputs[0].getType())) getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs); // Add system include arguments. getToolChain().AddClangSystemIncludeArgs(Args, CmdArgs); } // FIXME: Move to target hook. static bool isSignedCharDefault(const llvm::Triple &Triple) { switch (Triple.getArch()) { default: return true; case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: if (Triple.isOSDarwin() || Triple.isOSWindows()) return true; return false; case llvm::Triple::ppc: case llvm::Triple::ppc64: if (Triple.isOSDarwin()) return true; return false; case llvm::Triple::hexagon: case llvm::Triple::ppc64le: case llvm::Triple::systemz: case llvm::Triple::xcore: return false; } } static bool isNoCommonDefault(const llvm::Triple &Triple) { switch (Triple.getArch()) { default: return false; case llvm::Triple::xcore: return true; } } // ARM tools start. // Get SubArch (vN). static int getARMSubArchVersionNumber(const llvm::Triple &Triple) { llvm::StringRef Arch = Triple.getArchName(); return llvm::ARMTargetParser::parseArchVersion(Arch); } // True if M-profile. static bool isARMMProfile(const llvm::Triple &Triple) { llvm::StringRef Arch = Triple.getArchName(); unsigned Profile = llvm::ARMTargetParser::parseArchProfile(Arch); return Profile == llvm::ARM::PK_M; } // Get Arch/CPU from args. static void getARMArchCPUFromArgs(const ArgList &Args, llvm::StringRef &Arch, llvm::StringRef &CPU, bool FromAs = false) { if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) CPU = A->getValue(); if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) Arch = A->getValue(); if (!FromAs) return; for (const Arg *A : Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) { StringRef Value = A->getValue(); if (Value.startswith("-mcpu=")) CPU = Value.substr(6); if (Value.startswith("-march=")) Arch = Value.substr(7); } } // Handle -mhwdiv=. // FIXME: Use ARMTargetParser. static void getARMHWDivFeatures(const Driver &D, const Arg *A, const ArgList &Args, StringRef HWDiv, std::vector<const char *> &Features) { if (HWDiv == "arm") { Features.push_back("+hwdiv-arm"); Features.push_back("-hwdiv"); } else if (HWDiv == "thumb") { Features.push_back("-hwdiv-arm"); Features.push_back("+hwdiv"); } else if (HWDiv == "arm,thumb" || HWDiv == "thumb,arm") { Features.push_back("+hwdiv-arm"); Features.push_back("+hwdiv"); } else if (HWDiv == "none") { Features.push_back("-hwdiv-arm"); Features.push_back("-hwdiv"); } else D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); } // Handle -mfpu=. static void getARMFPUFeatures(const Driver &D, const Arg *A, const ArgList &Args, StringRef FPU, std::vector<const char *> &Features) { unsigned FPUID = llvm::ARMTargetParser::parseFPU(FPU); if (!llvm::ARMTargetParser::getFPUFeatures(FPUID, Features)) D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); } // Check if -march is valid by checking if it can be canonicalised and parsed. // getARMArch is used here instead of just checking the -march value in order // to handle -march=native correctly. static void checkARMArchName(const Driver &D, const Arg *A, const ArgList &Args, llvm::StringRef ArchName, const llvm::Triple &Triple) { std::string MArch = arm::getARMArch(ArchName, Triple); if (llvm::ARMTargetParser::parseArch(MArch) == llvm::ARM::AK_INVALID) D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); } // Check -mcpu=. Needs ArchName to handle -mcpu=generic. static void checkARMCPUName(const Driver &D, const Arg *A, const ArgList &Args, llvm::StringRef CPUName, llvm::StringRef ArchName, const llvm::Triple &Triple) { std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple); std::string Arch = arm::getARMArch(ArchName, Triple); if (strcmp(arm::getLLVMArchSuffixForARM(CPU, Arch), "") == 0) D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); } // Select the float ABI as determined by -msoft-float, -mhard-float, and // -mfloat-abi=. StringRef tools::arm::getARMFloatABI(const Driver &D, const ArgList &Args, const llvm::Triple &Triple) { StringRef FloatABI; if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, options::OPT_mfloat_abi_EQ)) { if (A->getOption().matches(options::OPT_msoft_float)) FloatABI = "soft"; else if (A->getOption().matches(options::OPT_mhard_float)) FloatABI = "hard"; else { FloatABI = A->getValue(); if (FloatABI != "soft" && FloatABI != "softfp" && FloatABI != "hard") { D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args); FloatABI = "soft"; } } } // If unspecified, choose the default based on the platform. if (FloatABI.empty()) { switch (Triple.getOS()) { case llvm::Triple::Darwin: case llvm::Triple::MacOSX: case llvm::Triple::IOS: { // Darwin defaults to "softfp" for v6 and v7. // if (getARMSubArchVersionNumber(Triple) == 6 || getARMSubArchVersionNumber(Triple) == 7) FloatABI = "softfp"; else FloatABI = "soft"; break; } // FIXME: this is invalid for WindowsCE case llvm::Triple::Win32: FloatABI = "hard"; break; case llvm::Triple::FreeBSD: switch (Triple.getEnvironment()) { case llvm::Triple::GNUEABIHF: FloatABI = "hard"; break; default: // FreeBSD defaults to soft float FloatABI = "soft"; break; } break; default: switch (Triple.getEnvironment()) { case llvm::Triple::GNUEABIHF: FloatABI = "hard"; break; case llvm::Triple::GNUEABI: FloatABI = "softfp"; break; case llvm::Triple::EABIHF: FloatABI = "hard"; break; case llvm::Triple::EABI: // EABI is always AAPCS, and if it was not marked 'hard', it's softfp FloatABI = "softfp"; break; case llvm::Triple::Android: { if (getARMSubArchVersionNumber(Triple) == 7) FloatABI = "softfp"; else FloatABI = "soft"; break; } default: // Assume "soft", but warn the user we are guessing. FloatABI = "soft"; if (Triple.getOS() != llvm::Triple::UnknownOS || !Triple.isOSBinFormatMachO()) D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft"; break; } } } return FloatABI; } static void getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector<const char *> &Features, bool ForAS) { bool KernelOrKext = Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext); StringRef FloatABI = tools::arm::getARMFloatABI(D, Args, Triple); const Arg *WaCPU = nullptr, *WaFPU = nullptr; const Arg *WaHDiv = nullptr, *WaArch = nullptr; if (!ForAS) { // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these // yet (it uses the -mfloat-abi and -msoft-float options), and it is // stripped out by the ARM target. We should probably pass this a new // -target-option, which is handled by the -cc1/-cc1as invocation. // // FIXME2: For consistency, it would be ideal if we set up the target // machine state the same when using the frontend or the assembler. We don't // currently do that for the assembler, we pass the options directly to the // backend and never even instantiate the frontend TargetInfo. If we did, // and used its handleTargetFeatures hook, then we could ensure the // assembler and the frontend behave the same. // Use software floating point operations? if (FloatABI == "soft") Features.push_back("+soft-float"); // Use software floating point argument passing? if (FloatABI != "hard") Features.push_back("+soft-float-abi"); } else { // Here, we make sure that -Wa,-mfpu/cpu/arch/hwdiv will be passed down // to the assembler correctly. for (const Arg *A : Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) { StringRef Value = A->getValue(); if (Value.startswith("-mfpu=")) { WaFPU = A; } else if (Value.startswith("-mcpu=")) { WaCPU = A; } else if (Value.startswith("-mhwdiv=")) { WaHDiv = A; } else if (Value.startswith("-march=")) { WaArch = A; } } } // Honor -mfpu=. ClangAs gives preference to -Wa,-mfpu=. const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ); if (WaFPU) { if (FPUArg) D.Diag(clang::diag::warn_drv_unused_argument) << FPUArg->getAsString(Args); getARMFPUFeatures(D, WaFPU, Args, StringRef(WaFPU->getValue()).substr(6), Features); } else if (FPUArg) { getARMFPUFeatures(D, FPUArg, Args, FPUArg->getValue(), Features); } // Honor -mhwdiv=. ClangAs gives preference to -Wa,-mhwdiv=. const Arg *HDivArg = Args.getLastArg(options::OPT_mhwdiv_EQ); if (WaHDiv) { if (HDivArg) D.Diag(clang::diag::warn_drv_unused_argument) << HDivArg->getAsString(Args); getARMHWDivFeatures(D, WaHDiv, Args, StringRef(WaHDiv->getValue()).substr(8), Features); } else if (HDivArg) getARMHWDivFeatures(D, HDivArg, Args, HDivArg->getValue(), Features); // Check -march. ClangAs gives preference to -Wa,-march=. const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ); StringRef ArchName; if (WaArch) { if (ArchArg) D.Diag(clang::diag::warn_drv_unused_argument) << ArchArg->getAsString(Args); ArchName = StringRef(WaArch->getValue()).substr(7); checkARMArchName(D, WaArch, Args, ArchName, Triple); // FIXME: Set Arch. D.Diag(clang::diag::warn_drv_unused_argument) << WaArch->getAsString(Args); } else if (ArchArg) { ArchName = ArchArg->getValue(); checkARMArchName(D, ArchArg, Args, ArchName, Triple); } // Check -mcpu. ClangAs gives preference to -Wa,-mcpu=. const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ); StringRef CPUName; if (WaCPU) { if (CPUArg) D.Diag(clang::diag::warn_drv_unused_argument) << CPUArg->getAsString(Args); CPUName = StringRef(WaCPU->getValue()).substr(6); checkARMCPUName(D, WaCPU, Args, CPUName, ArchName, Triple); } else if (CPUArg) { CPUName = CPUArg->getValue(); checkARMCPUName(D, CPUArg, Args, CPUName, ArchName, Triple); } // Setting -msoft-float effectively disables NEON because of the GCC // implementation, although the same isn't true of VFP or VFP3. if (FloatABI == "soft") { Features.push_back("-neon"); // Also need to explicitly disable features which imply NEON. Features.push_back("-crypto"); } // En/disable crc code generation. if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) { if (A->getOption().matches(options::OPT_mcrc)) Features.push_back("+crc"); else Features.push_back("-crc"); } if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8_1a) { Features.insert(Features.begin(), "+v8.1a"); } // Look for the last occurrence of -mlong-calls or -mno-long-calls. If // neither options are specified, see if we are compiling for kernel/kext and // decide whether to pass "+long-calls" based on the OS and its version. if (Arg *A = Args.getLastArg(options::OPT_mlong_calls, options::OPT_mno_long_calls)) { if (A->getOption().matches(options::OPT_mlong_calls)) Features.push_back("+long-calls"); } else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6))) { Features.push_back("+long-calls"); } } void Clang::AddARMTargetArgs(const ArgList &Args, ArgStringList &CmdArgs, bool KernelOrKext) const { const Driver &D = getToolChain().getDriver(); // Get the effective triple, which takes into account the deployment target. std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); llvm::Triple Triple(TripleStr); // Select the ABI to use. // // FIXME: Support -meabi. // FIXME: Parts of this are duplicated in the backend, unify this somehow. const char *ABIName = nullptr; if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { ABIName = A->getValue(); } else if (Triple.isOSBinFormatMachO()) { // The backend is hardwired to assume AAPCS for M-class processors, ensure // the frontend matches that. if (Triple.getEnvironment() == llvm::Triple::EABI || Triple.getOS() == llvm::Triple::UnknownOS || isARMMProfile(Triple)) { ABIName = "aapcs"; } else { ABIName = "apcs-gnu"; } } else if (Triple.isOSWindows()) { // FIXME: this is invalid for WindowsCE ABIName = "aapcs"; } else { // Select the default based on the platform. switch (Triple.getEnvironment()) { case llvm::Triple::Android: case llvm::Triple::GNUEABI: case llvm::Triple::GNUEABIHF: ABIName = "aapcs-linux"; break; case llvm::Triple::EABIHF: case llvm::Triple::EABI: ABIName = "aapcs"; break; default: if (Triple.getOS() == llvm::Triple::NetBSD) ABIName = "apcs-gnu"; else ABIName = "aapcs"; break; } } CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName); // Determine floating point ABI from the options & target defaults. StringRef FloatABI = tools::arm::getARMFloatABI(D, Args, Triple); if (FloatABI == "soft") { // Floating point operations and argument passing are soft. // // FIXME: This changes CPP defines, we need -target-soft-float. CmdArgs.push_back("-msoft-float"); CmdArgs.push_back("-mfloat-abi"); CmdArgs.push_back("soft"); } else if (FloatABI == "softfp") { // Floating point operations are hard, but argument passing is soft. CmdArgs.push_back("-mfloat-abi"); CmdArgs.push_back("soft"); } else { // Floating point operations and argument passing are hard. assert(FloatABI == "hard" && "Invalid float abi!"); CmdArgs.push_back("-mfloat-abi"); CmdArgs.push_back("hard"); } // Kernel code has more strict alignment requirements. if (KernelOrKext) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-arm-strict-align"); // The kext linker doesn't know how to deal with movw/movt. CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-arm-use-movt=0"); } // -mkernel implies -mstrict-align; don't add the redundant option. if (!KernelOrKext) { if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) { CmdArgs.push_back("-backend-option"); if (A->getOption().matches(options::OPT_mno_unaligned_access)) CmdArgs.push_back("-arm-strict-align"); else { if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m) D.Diag(diag::err_target_unsupported_unaligned) << "v6m"; CmdArgs.push_back("-arm-no-strict-align"); } } } // Forward the -mglobal-merge option for explicit control over the pass. if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge, options::OPT_mno_global_merge)) { CmdArgs.push_back("-backend-option"); if (A->getOption().matches(options::OPT_mno_global_merge)) CmdArgs.push_back("-arm-global-merge=false"); else CmdArgs.push_back("-arm-global-merge=true"); } if (!Args.hasFlag(options::OPT_mimplicit_float, options::OPT_mno_implicit_float, true)) CmdArgs.push_back("-no-implicit-float"); // llvm does not support reserving registers in general. There is support // for reserving r9 on ARM though (defined as a platform-specific register // in ARM EABI). if (Args.hasArg(options::OPT_ffixed_r9)) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-arm-reserve-r9"); } } // ARM tools end. /// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are /// targeting. static std::string getAArch64TargetCPU(const ArgList &Args) { Arg *A; std::string CPU; // If we have -mtune or -mcpu, use that. if ((A = Args.getLastArg(options::OPT_mtune_EQ))) { CPU = A->getValue(); } else if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) { StringRef Mcpu = A->getValue(); CPU = Mcpu.split("+").first.lower(); } // Handle CPU name is 'native'. if (CPU == "native") return llvm::sys::getHostCPUName(); else if (CPU.size()) return CPU; // Make sure we pick "cyclone" if -arch is used. // FIXME: Should this be picked by checking the target triple instead? if (Args.getLastArg(options::OPT_arch)) return "cyclone"; return "generic"; } void Clang::AddAArch64TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); llvm::Triple Triple(TripleStr); if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true) || Args.hasArg(options::OPT_mkernel) || Args.hasArg(options::OPT_fapple_kext)) CmdArgs.push_back("-disable-red-zone"); if (!Args.hasFlag(options::OPT_mimplicit_float, options::OPT_mno_implicit_float, true)) CmdArgs.push_back("-no-implicit-float"); const char *ABIName = nullptr; if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) ABIName = A->getValue(); else if (Triple.isOSDarwin()) ABIName = "darwinpcs"; else ABIName = "aapcs"; CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName); if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) { CmdArgs.push_back("-backend-option"); if (A->getOption().matches(options::OPT_mno_unaligned_access)) CmdArgs.push_back("-aarch64-strict-align"); else CmdArgs.push_back("-aarch64-no-strict-align"); } if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a53_835769, options::OPT_mno_fix_cortex_a53_835769)) { CmdArgs.push_back("-backend-option"); if (A->getOption().matches(options::OPT_mfix_cortex_a53_835769)) CmdArgs.push_back("-aarch64-fix-cortex-a53-835769=1"); else CmdArgs.push_back("-aarch64-fix-cortex-a53-835769=0"); } else if (Triple.getEnvironment() == llvm::Triple::Android) { // Enabled A53 errata (835769) workaround by default on android CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-aarch64-fix-cortex-a53-835769=1"); } // Forward the -mglobal-merge option for explicit control over the pass. if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge, options::OPT_mno_global_merge)) { CmdArgs.push_back("-backend-option"); if (A->getOption().matches(options::OPT_mno_global_merge)) CmdArgs.push_back("-aarch64-global-merge=false"); else CmdArgs.push_back("-aarch64-global-merge=true"); } if (Args.hasArg(options::OPT_ffixed_x18)) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-aarch64-reserve-x18"); } } // Get CPU and ABI names. They are not independent // so we have to calculate them together. void mips::getMipsCPUAndABI(const ArgList &Args, const llvm::Triple &Triple, StringRef &CPUName, StringRef &ABIName) { const char *DefMips32CPU = "mips32r2"; const char *DefMips64CPU = "mips64r2"; // MIPS32r6 is the default for mips(el)?-img-linux-gnu and MIPS64r6 is the // default for mips64(el)?-img-linux-gnu. if (Triple.getVendor() == llvm::Triple::ImaginationTechnologies && Triple.getEnvironment() == llvm::Triple::GNU) { DefMips32CPU = "mips32r6"; DefMips64CPU = "mips64r6"; } // MIPS3 is the default for mips64*-unknown-openbsd. if (Triple.getOS() == llvm::Triple::OpenBSD) DefMips64CPU = "mips3"; if (Arg *A = Args.getLastArg(options::OPT_march_EQ, options::OPT_mcpu_EQ)) CPUName = A->getValue(); if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { ABIName = A->getValue(); // Convert a GNU style Mips ABI name to the name // accepted by LLVM Mips backend. ABIName = llvm::StringSwitch<llvm::StringRef>(ABIName) .Case("32", "o32") .Case("64", "n64") .Default(ABIName); } // Setup default CPU and ABI names. if (CPUName.empty() && ABIName.empty()) { switch (Triple.getArch()) { default: llvm_unreachable("Unexpected triple arch name"); case llvm::Triple::mips: case llvm::Triple::mipsel: CPUName = DefMips32CPU; break; case llvm::Triple::mips64: case llvm::Triple::mips64el: CPUName = DefMips64CPU; break; } } if (ABIName.empty()) { // Deduce ABI name from the target triple. if (Triple.getArch() == llvm::Triple::mips || Triple.getArch() == llvm::Triple::mipsel) ABIName = "o32"; else ABIName = "n64"; } if (CPUName.empty()) { // Deduce CPU name from ABI name. CPUName = llvm::StringSwitch<const char *>(ABIName) .Cases("o32", "eabi", DefMips32CPU) .Cases("n32", "n64", DefMips64CPU) .Default(""); } // FIXME: Warn on inconsistent use of -march and -mabi. } // Convert ABI name to the GNU tools acceptable variant. static StringRef getGnuCompatibleMipsABIName(StringRef ABI) { return llvm::StringSwitch<llvm::StringRef>(ABI) .Case("o32", "32") .Case("n64", "64") .Default(ABI); } // Select the MIPS float ABI as determined by -msoft-float, -mhard-float, // and -mfloat-abi=. static StringRef getMipsFloatABI(const Driver &D, const ArgList &Args) { StringRef FloatABI; if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, options::OPT_mfloat_abi_EQ)) { if (A->getOption().matches(options::OPT_msoft_float)) FloatABI = "soft"; else if (A->getOption().matches(options::OPT_mhard_float)) FloatABI = "hard"; else { FloatABI = A->getValue(); if (FloatABI != "soft" && FloatABI != "hard") { D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args); FloatABI = "hard"; } } } // If unspecified, choose the default based on the platform. if (FloatABI.empty()) { // Assume "hard", because it's a default value used by gcc. // When we start to recognize specific target MIPS processors, // we will be able to select the default more correctly. FloatABI = "hard"; } return FloatABI; } static void AddTargetFeature(const ArgList &Args, std::vector<const char *> &Features, OptSpecifier OnOpt, OptSpecifier OffOpt, StringRef FeatureName) { if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) { if (A->getOption().matches(OnOpt)) Features.push_back(Args.MakeArgString("+" + FeatureName)); else Features.push_back(Args.MakeArgString("-" + FeatureName)); } } static void getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector<const char *> &Features) { StringRef CPUName; StringRef ABIName; mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName); ABIName = getGnuCompatibleMipsABIName(ABIName); AddTargetFeature(Args, Features, options::OPT_mno_abicalls, options::OPT_mabicalls, "noabicalls"); StringRef FloatABI = getMipsFloatABI(D, Args); if (FloatABI == "soft") { // FIXME: Note, this is a hack. We need to pass the selected float // mode to the MipsTargetInfoBase to define appropriate macros there. // Now it is the only method. Features.push_back("+soft-float"); } if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) { StringRef Val = StringRef(A->getValue()); if (Val == "2008") { if (mips::getSupportedNanEncoding(CPUName) & mips::Nan2008) Features.push_back("+nan2008"); else { Features.push_back("-nan2008"); D.Diag(diag::warn_target_unsupported_nan2008) << CPUName; } } else if (Val == "legacy") { if (mips::getSupportedNanEncoding(CPUName) & mips::NanLegacy) Features.push_back("-nan2008"); else { Features.push_back("+nan2008"); D.Diag(diag::warn_target_unsupported_nanlegacy) << CPUName; } } else D.Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Val; } AddTargetFeature(Args, Features, options::OPT_msingle_float, options::OPT_mdouble_float, "single-float"); AddTargetFeature(Args, Features, options::OPT_mips16, options::OPT_mno_mips16, "mips16"); AddTargetFeature(Args, Features, options::OPT_mmicromips, options::OPT_mno_micromips, "micromips"); AddTargetFeature(Args, Features, options::OPT_mdsp, options::OPT_mno_dsp, "dsp"); AddTargetFeature(Args, Features, options::OPT_mdspr2, options::OPT_mno_dspr2, "dspr2"); AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa, "msa"); // Add the last -mfp32/-mfpxx/-mfp64 or if none are given and the ABI is O32 // pass -mfpxx if (Arg *A = Args.getLastArg(options::OPT_mfp32, options::OPT_mfpxx, options::OPT_mfp64)) { if (A->getOption().matches(options::OPT_mfp32)) Features.push_back(Args.MakeArgString("-fp64")); else if (A->getOption().matches(options::OPT_mfpxx)) { Features.push_back(Args.MakeArgString("+fpxx")); Features.push_back(Args.MakeArgString("+nooddspreg")); } else Features.push_back(Args.MakeArgString("+fp64")); } else if (mips::shouldUseFPXX(Args, Triple, CPUName, ABIName, FloatABI)) { Features.push_back(Args.MakeArgString("+fpxx")); Features.push_back(Args.MakeArgString("+nooddspreg")); } AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg, options::OPT_modd_spreg, "nooddspreg"); } void Clang::AddMIPSTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { const Driver &D = getToolChain().getDriver(); StringRef CPUName; StringRef ABIName; const llvm::Triple &Triple = getToolChain().getTriple(); mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName); CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName.data()); StringRef FloatABI = getMipsFloatABI(D, Args); if (FloatABI == "soft") { // Floating point operations and argument passing are soft. CmdArgs.push_back("-msoft-float"); CmdArgs.push_back("-mfloat-abi"); CmdArgs.push_back("soft"); } else { // Floating point operations and argument passing are hard. assert(FloatABI == "hard" && "Invalid float abi!"); CmdArgs.push_back("-mfloat-abi"); CmdArgs.push_back("hard"); } if (Arg *A = Args.getLastArg(options::OPT_mxgot, options::OPT_mno_xgot)) { if (A->getOption().matches(options::OPT_mxgot)) { CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-mxgot"); } } if (Arg *A = Args.getLastArg(options::OPT_mldc1_sdc1, options::OPT_mno_ldc1_sdc1)) { if (A->getOption().matches(options::OPT_mno_ldc1_sdc1)) { CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-mno-ldc1-sdc1"); } } if (Arg *A = Args.getLastArg(options::OPT_mcheck_zero_division, options::OPT_mno_check_zero_division)) { if (A->getOption().matches(options::OPT_mno_check_zero_division)) { CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-mno-check-zero-division"); } } if (Arg *A = Args.getLastArg(options::OPT_G)) { StringRef v = A->getValue(); CmdArgs.push_back("-mllvm"); CmdArgs.push_back(Args.MakeArgString("-mips-ssection-threshold=" + v)); A->claim(); } } /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting. static std::string getPPCTargetCPU(const ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { StringRef CPUName = A->getValue(); if (CPUName == "native") { std::string CPU = llvm::sys::getHostCPUName(); if (!CPU.empty() && CPU != "generic") return CPU; else return ""; } return llvm::StringSwitch<const char *>(CPUName) .Case("common", "generic") .Case("440", "440") .Case("440fp", "440") .Case("450", "450") .Case("601", "601") .Case("602", "602") .Case("603", "603") .Case("603e", "603e") .Case("603ev", "603ev") .Case("604", "604") .Case("604e", "604e") .Case("620", "620") .Case("630", "pwr3") .Case("G3", "g3") .Case("7400", "7400") .Case("G4", "g4") .Case("7450", "7450") .Case("G4+", "g4+") .Case("750", "750") .Case("970", "970") .Case("G5", "g5") .Case("a2", "a2") .Case("a2q", "a2q") .Case("e500mc", "e500mc") .Case("e5500", "e5500") .Case("power3", "pwr3") .Case("power4", "pwr4") .Case("power5", "pwr5") .Case("power5x", "pwr5x") .Case("power6", "pwr6") .Case("power6x", "pwr6x") .Case("power7", "pwr7") .Case("power8", "pwr8") .Case("pwr3", "pwr3") .Case("pwr4", "pwr4") .Case("pwr5", "pwr5") .Case("pwr5x", "pwr5x") .Case("pwr6", "pwr6") .Case("pwr6x", "pwr6x") .Case("pwr7", "pwr7") .Case("pwr8", "pwr8") .Case("powerpc", "ppc") .Case("powerpc64", "ppc64") .Case("powerpc64le", "ppc64le") .Default(""); } return ""; } static void getPPCTargetFeatures(const ArgList &Args, std::vector<const char *> &Features) { for (const Arg *A : Args.filtered(options::OPT_m_ppc_Features_Group)) { StringRef Name = A->getOption().getName(); A->claim(); // Skip over "-m". assert(Name.startswith("m") && "Invalid feature name."); Name = Name.substr(1); bool IsNegative = Name.startswith("no-"); if (IsNegative) Name = Name.substr(3); // Note that gcc calls this mfcrf and LLVM calls this mfocrf so we // pass the correct option to the backend while calling the frontend // option the same. // TODO: Change the LLVM backend option maybe? if (Name == "mfcrf") Name = "mfocrf"; Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); } // Altivec is a bit weird, allow overriding of the Altivec feature here. AddTargetFeature(Args, Features, options::OPT_faltivec, options::OPT_fno_altivec, "altivec"); } void Clang::AddPPCTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // Select the ABI to use. const char *ABIName = nullptr; if (getToolChain().getTriple().isOSLinux()) switch (getToolChain().getArch()) { case llvm::Triple::ppc64: { // When targeting a processor that supports QPX, or if QPX is // specifically enabled, default to using the ABI that supports QPX (so // long as it is not specifically disabled). bool HasQPX = false; if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) HasQPX = A->getValue() == StringRef("a2q"); HasQPX = Args.hasFlag(options::OPT_mqpx, options::OPT_mno_qpx, HasQPX); if (HasQPX) { ABIName = "elfv1-qpx"; break; } ABIName = "elfv1"; break; } case llvm::Triple::ppc64le: ABIName = "elfv2"; break; default: break; } if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) // The ppc64 linux abis are all "altivec" abis by default. Accept and ignore // the option if given as we don't have backend support for any targets // that don't use the altivec abi. if (StringRef(A->getValue()) != "altivec") ABIName = A->getValue(); if (ABIName) { CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName); } } bool ppc::hasPPCAbiArg(const ArgList &Args, const char *Value) { Arg *A = Args.getLastArg(options::OPT_mabi_EQ); return A && (A->getValue() == StringRef(Value)); } /// Get the (LLVM) name of the R600 gpu we are targeting. static std::string getR600TargetGPU(const ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { const char *GPUName = A->getValue(); return llvm::StringSwitch<const char *>(GPUName) .Cases("rv630", "rv635", "r600") .Cases("rv610", "rv620", "rs780", "rs880") .Case("rv740", "rv770") .Case("palm", "cedar") .Cases("sumo", "sumo2", "sumo") .Case("hemlock", "cypress") .Case("aruba", "cayman") .Default(GPUName); } return ""; } void Clang::AddSparcTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { const Driver &D = getToolChain().getDriver(); std::string Triple = getToolChain().ComputeEffectiveClangTriple(Args); bool SoftFloatABI = false; if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float)) { if (A->getOption().matches(options::OPT_msoft_float)) SoftFloatABI = true; } // Only the hard-float ABI on Sparc is standardized, and it is the // default. GCC also supports a nonstandard soft-float ABI mode, and // perhaps LLVM should implement that, too. However, since llvm // currently does not support Sparc soft-float, at all, display an // error if it's requested. if (SoftFloatABI) { D.Diag(diag::err_drv_unsupported_opt_for_target) << "-msoft-float" << Triple; } } static const char *getSystemZTargetCPU(const ArgList &Args) { if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) return A->getValue(); return "z10"; } static void getSystemZTargetFeatures(const ArgList &Args, std::vector<const char *> &Features) { // -m(no-)htm overrides use of the transactional-execution facility. if (Arg *A = Args.getLastArg(options::OPT_mhtm, options::OPT_mno_htm)) { if (A->getOption().matches(options::OPT_mhtm)) Features.push_back("+transactional-execution"); else Features.push_back("-transactional-execution"); } // -m(no-)vx overrides use of the vector facility. if (Arg *A = Args.getLastArg(options::OPT_mvx, options::OPT_mno_vx)) { if (A->getOption().matches(options::OPT_mvx)) Features.push_back("+vector"); else Features.push_back("-vector"); } } static const char *getX86TargetCPU(const ArgList &Args, const llvm::Triple &Triple) { if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { if (StringRef(A->getValue()) != "native") { if (Triple.isOSDarwin() && Triple.getArchName() == "x86_64h") return "core-avx2"; return A->getValue(); } // FIXME: Reject attempts to use -march=native unless the target matches // the host. // // FIXME: We should also incorporate the detected target features for use // with -native. std::string CPU = llvm::sys::getHostCPUName(); if (!CPU.empty() && CPU != "generic") return Args.MakeArgString(CPU); } if (const Arg *A = Args.getLastArg(options::OPT__SLASH_arch)) { // Mapping built by referring to X86TargetInfo::getDefaultFeatures(). StringRef Arch = A->getValue(); const char *CPU; if (Triple.getArch() == llvm::Triple::x86) { CPU = llvm::StringSwitch<const char *>(Arch) .Case("IA32", "i386") .Case("SSE", "pentium3") .Case("SSE2", "pentium4") .Case("AVX", "sandybridge") .Case("AVX2", "haswell") .Default(nullptr); } else { CPU = llvm::StringSwitch<const char *>(Arch) .Case("AVX", "sandybridge") .Case("AVX2", "haswell") .Default(nullptr); } if (CPU) return CPU; } // Select the default CPU if none was given (or detection failed). if (Triple.getArch() != llvm::Triple::x86_64 && Triple.getArch() != llvm::Triple::x86) return nullptr; // This routine is only handling x86 targets. bool Is64Bit = Triple.getArch() == llvm::Triple::x86_64; // FIXME: Need target hooks. if (Triple.isOSDarwin()) { if (Triple.getArchName() == "x86_64h") return "core-avx2"; return Is64Bit ? "core2" : "yonah"; } // Set up default CPU name for PS4 compilers. if (Triple.isPS4CPU()) return "btver2"; // On Android use targets compatible with gcc if (Triple.getEnvironment() == llvm::Triple::Android) return Is64Bit ? "x86-64" : "i686"; // Everything else goes to x86-64 in 64-bit mode. if (Is64Bit) return "x86-64"; switch (Triple.getOS()) { case llvm::Triple::FreeBSD: case llvm::Triple::NetBSD: case llvm::Triple::OpenBSD: return "i486"; case llvm::Triple::Haiku: return "i586"; case llvm::Triple::Bitrig: return "i686"; default: // Fallback to p4. return "pentium4"; } } static std::string getCPUName(const ArgList &Args, const llvm::Triple &T, bool FromAs = false) { switch (T.getArch()) { default: return ""; case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: return getAArch64TargetCPU(Args); case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: { StringRef MArch, MCPU; getARMArchCPUFromArgs(Args, MArch, MCPU, FromAs); return arm::getARMTargetCPU(MCPU, MArch, T); } case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: { StringRef CPUName; StringRef ABIName; mips::getMipsCPUAndABI(Args, T, CPUName, ABIName); return CPUName; } case llvm::Triple::nvptx: case llvm::Triple::nvptx64: if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) return A->getValue(); return ""; case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: { std::string TargetCPUName = getPPCTargetCPU(Args); // LLVM may default to generating code for the native CPU, // but, like gcc, we default to a more generic option for // each architecture. (except on Darwin) if (TargetCPUName.empty() && !T.isOSDarwin()) { if (T.getArch() == llvm::Triple::ppc64) TargetCPUName = "ppc64"; else if (T.getArch() == llvm::Triple::ppc64le) TargetCPUName = "ppc64le"; else TargetCPUName = "ppc"; } return TargetCPUName; } case llvm::Triple::sparc: case llvm::Triple::sparcel: case llvm::Triple::sparcv9: if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) return A->getValue(); return ""; case llvm::Triple::x86: case llvm::Triple::x86_64: return getX86TargetCPU(Args, T); case llvm::Triple::hexagon: return "hexagon" + toolchains::Hexagon_TC::GetTargetCPU(Args).str(); case llvm::Triple::systemz: return getSystemZTargetCPU(Args); case llvm::Triple::r600: case llvm::Triple::amdgcn: return getR600TargetGPU(Args); } } static void AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, ArgStringList &CmdArgs) { // Tell the linker to load the plugin. This has to come before AddLinkerInputs // as gold requires -plugin to come before any -plugin-opt that -Wl might // forward. CmdArgs.push_back("-plugin"); std::string Plugin = ToolChain.getDriver().Dir + "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold.so"; CmdArgs.push_back(Args.MakeArgString(Plugin)); // Try to pass driver level flags relevant to LTO code generation down to // the plugin. // Handle flags for selecting CPU variants. std::string CPU = getCPUName(Args, ToolChain.getTriple()); if (!CPU.empty()) CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mcpu=") + CPU)); } /// This is a helper function for validating the optional refinement step /// parameter in reciprocal argument strings. Return false if there is an error /// parsing the refinement step. Otherwise, return true and set the Position /// of the refinement step in the input string. static bool getRefinementStep(const StringRef &In, const Driver &D, const Arg &A, size_t &Position) { const char RefinementStepToken = ':'; Position = In.find(RefinementStepToken); if (Position != StringRef::npos) { StringRef Option = A.getOption().getName(); StringRef RefStep = In.substr(Position + 1); // Allow exactly one numeric character for the additional refinement // step parameter. This is reasonable for all currently-supported // operations and architectures because we would expect that a larger value // of refinement steps would cause the estimate "optimization" to // under-perform the native operation. Also, if the estimate does not // converge quickly, it probably will not ever converge, so further // refinement steps will not produce a better answer. if (RefStep.size() != 1) { D.Diag(diag::err_drv_invalid_value) << Option << RefStep; return false; } char RefStepChar = RefStep[0]; if (RefStepChar < '0' || RefStepChar > '9') { D.Diag(diag::err_drv_invalid_value) << Option << RefStep; return false; } } return true; } /// The -mrecip flag requires processing of many optional parameters. static void ParseMRecip(const Driver &D, const ArgList &Args, ArgStringList &OutStrings) { StringRef DisabledPrefixIn = "!"; StringRef DisabledPrefixOut = "!"; StringRef EnabledPrefixOut = ""; StringRef Out = "-mrecip="; Arg *A = Args.getLastArg(options::OPT_mrecip, options::OPT_mrecip_EQ); if (!A) return; unsigned NumOptions = A->getNumValues(); if (NumOptions == 0) { // No option is the same as "all". OutStrings.push_back(Args.MakeArgString(Out + "all")); return; } // Pass through "all", "none", or "default" with an optional refinement step. if (NumOptions == 1) { StringRef Val = A->getValue(0); size_t RefStepLoc; if (!getRefinementStep(Val, D, *A, RefStepLoc)) return; StringRef ValBase = Val.slice(0, RefStepLoc); if (ValBase == "all" || ValBase == "none" || ValBase == "default") { OutStrings.push_back(Args.MakeArgString(Out + Val)); return; } } // Each reciprocal type may be enabled or disabled individually. // Check each input value for validity, concatenate them all back together, // and pass through. llvm::StringMap<bool> OptionStrings; OptionStrings.insert(std::make_pair("divd", false)); OptionStrings.insert(std::make_pair("divf", false)); OptionStrings.insert(std::make_pair("vec-divd", false)); OptionStrings.insert(std::make_pair("vec-divf", false)); OptionStrings.insert(std::make_pair("sqrtd", false)); OptionStrings.insert(std::make_pair("sqrtf", false)); OptionStrings.insert(std::make_pair("vec-sqrtd", false)); OptionStrings.insert(std::make_pair("vec-sqrtf", false)); for (unsigned i = 0; i != NumOptions; ++i) { StringRef Val = A->getValue(i); bool IsDisabled = Val.startswith(DisabledPrefixIn); // Ignore the disablement token for string matching. if (IsDisabled) Val = Val.substr(1); size_t RefStep; if (!getRefinementStep(Val, D, *A, RefStep)) return; StringRef ValBase = Val.slice(0, RefStep); llvm::StringMap<bool>::iterator OptionIter = OptionStrings.find(ValBase); if (OptionIter == OptionStrings.end()) { // Try again specifying float suffix. OptionIter = OptionStrings.find(ValBase.str() + 'f'); if (OptionIter == OptionStrings.end()) { // The input name did not match any known option string. D.Diag(diag::err_drv_unknown_argument) << Val; return; } // The option was specified without a float or double suffix. // Make sure that the double entry was not already specified. // The float entry will be checked below. if (OptionStrings[ValBase.str() + 'd']) { D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val; return; } } if (OptionIter->second == true) { // Duplicate option specified. D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val; return; } // Mark the matched option as found. Do not allow duplicate specifiers. OptionIter->second = true; // If the precision was not specified, also mark the double entry as found. if (ValBase.back() != 'f' && ValBase.back() != 'd') OptionStrings[ValBase.str() + 'd'] = true; // Build the output string. StringRef Prefix = IsDisabled ? DisabledPrefixOut : EnabledPrefixOut; Out = Args.MakeArgString(Out + Prefix + Val); if (i != NumOptions - 1) Out = Args.MakeArgString(Out + ","); } OutStrings.push_back(Args.MakeArgString(Out)); } static void getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector<const char *> &Features) { // If -march=native, autodetect the feature list. if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { if (StringRef(A->getValue()) == "native") { llvm::StringMap<bool> HostFeatures; if (llvm::sys::getHostCPUFeatures(HostFeatures)) for (auto &F : HostFeatures) Features.push_back( Args.MakeArgString((F.second ? "+" : "-") + F.first())); } } if (Triple.getArchName() == "x86_64h") { // x86_64h implies quite a few of the more modern subtarget features // for Haswell class CPUs, but not all of them. Opt-out of a few. Features.push_back("-rdrnd"); Features.push_back("-aes"); Features.push_back("-pclmul"); Features.push_back("-rtm"); Features.push_back("-hle"); Features.push_back("-fsgsbase"); } const llvm::Triple::ArchType ArchType = Triple.getArch(); // Add features to be compatible with gcc for Android. if (Triple.getEnvironment() == llvm::Triple::Android) { if (ArchType == llvm::Triple::x86_64) { Features.push_back("+sse4.2"); Features.push_back("+popcnt"); } else Features.push_back("+ssse3"); } // Set features according to the -arch flag on MSVC. if (Arg *A = Args.getLastArg(options::OPT__SLASH_arch)) { StringRef Arch = A->getValue(); bool ArchUsed = false; // First, look for flags that are shared in x86 and x86-64. if (ArchType == llvm::Triple::x86_64 || ArchType == llvm::Triple::x86) { if (Arch == "AVX" || Arch == "AVX2") { ArchUsed = true; Features.push_back(Args.MakeArgString("+" + Arch.lower())); } } // Then, look for x86-specific flags. if (ArchType == llvm::Triple::x86) { if (Arch == "IA32") { ArchUsed = true; } else if (Arch == "SSE" || Arch == "SSE2") { ArchUsed = true; Features.push_back(Args.MakeArgString("+" + Arch.lower())); } } if (!ArchUsed) D.Diag(clang::diag::warn_drv_unused_argument) << A->getAsString(Args); } // Now add any that the user explicitly requested on the command line, // which may override the defaults. for (const Arg *A : Args.filtered(options::OPT_m_x86_Features_Group)) { StringRef Name = A->getOption().getName(); A->claim(); // Skip over "-m". assert(Name.startswith("m") && "Invalid feature name."); Name = Name.substr(1); bool IsNegative = Name.startswith("no-"); if (IsNegative) Name = Name.substr(3); Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); } } void Clang::AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true) || Args.hasArg(options::OPT_mkernel) || Args.hasArg(options::OPT_fapple_kext)) CmdArgs.push_back("-disable-red-zone"); // Default to avoid implicit floating-point for kernel/kext code, but allow // that to be overridden with -mno-soft-float. bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) || Args.hasArg(options::OPT_fapple_kext)); if (Arg *A = Args.getLastArg( options::OPT_msoft_float, options::OPT_mno_soft_float, options::OPT_mimplicit_float, options::OPT_mno_implicit_float)) { const Option &O = A->getOption(); NoImplicitFloat = (O.matches(options::OPT_mno_implicit_float) || O.matches(options::OPT_msoft_float)); } if (NoImplicitFloat) CmdArgs.push_back("-no-implicit-float"); if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) { StringRef Value = A->getValue(); if (Value == "intel" || Value == "att") { CmdArgs.push_back("-mllvm"); CmdArgs.push_back(Args.MakeArgString("-x86-asm-syntax=" + Value)); } else { getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Value; } } } void Clang::AddHexagonTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { CmdArgs.push_back("-mqdsp6-compat"); CmdArgs.push_back("-Wreturn-type"); if (const char *v = toolchains::Hexagon_TC::GetSmallDataThreshold(Args)) { std::string SmallDataThreshold = "-hexagon-small-data-threshold="; SmallDataThreshold += v; CmdArgs.push_back("-mllvm"); CmdArgs.push_back(Args.MakeArgString(SmallDataThreshold)); } if (!Args.hasArg(options::OPT_fno_short_enums)) CmdArgs.push_back("-fshort-enums"); if (Args.getLastArg(options::OPT_mieee_rnd_near)) { CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-enable-hexagon-ieee-rnd-near"); } CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-machine-sink-split=0"); } // Decode AArch64 features from string like +[no]featureA+[no]featureB+... static bool DecodeAArch64Features(const Driver &D, StringRef text, std::vector<const char *> &Features) { SmallVector<StringRef, 8> Split; text.split(Split, StringRef("+"), -1, false); for (const StringRef Feature : Split) { const char *result = llvm::StringSwitch<const char *>(Feature) .Case("fp", "+fp-armv8") .Case("simd", "+neon") .Case("crc", "+crc") .Case("crypto", "+crypto") .Case("nofp", "-fp-armv8") .Case("nosimd", "-neon") .Case("nocrc", "-crc") .Case("nocrypto", "-crypto") .Default(nullptr); if (result) Features.push_back(result); else if (Feature == "neon" || Feature == "noneon") D.Diag(diag::err_drv_no_neon_modifier); else return false; } return true; } // Check if the CPU name and feature modifiers in -mcpu are legal. If yes, // decode CPU and feature. static bool DecodeAArch64Mcpu(const Driver &D, StringRef Mcpu, StringRef &CPU, std::vector<const char *> &Features) { std::pair<StringRef, StringRef> Split = Mcpu.split("+"); CPU = Split.first; if (CPU == "cyclone" || CPU == "cortex-a53" || CPU == "cortex-a57" || CPU == "cortex-a72") { Features.push_back("+neon"); Features.push_back("+crc"); Features.push_back("+crypto"); } else if (CPU == "generic") { Features.push_back("+neon"); } else { return false; } if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features)) return false; return true; } static bool getAArch64ArchFeaturesFromMarch(const Driver &D, StringRef March, const ArgList &Args, std::vector<const char *> &Features) { std::string MarchLowerCase = March.lower(); std::pair<StringRef, StringRef> Split = StringRef(MarchLowerCase).split("+"); if (Split.first == "armv8-a" || Split.first == "armv8a") { // ok, no additional features. } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") { Features.push_back("+v8.1a"); } else { return false; } if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features)) return false; return true; } static bool getAArch64ArchFeaturesFromMcpu(const Driver &D, StringRef Mcpu, const ArgList &Args, std::vector<const char *> &Features) { StringRef CPU; std::string McpuLowerCase = Mcpu.lower(); if (!DecodeAArch64Mcpu(D, McpuLowerCase, CPU, Features)) return false; return true; } static bool getAArch64MicroArchFeaturesFromMtune(const Driver &D, StringRef Mtune, const ArgList &Args, std::vector<const char *> &Features) { // Handle CPU name is 'native'. if (Mtune == "native") Mtune = llvm::sys::getHostCPUName(); if (Mtune == "cyclone") { Features.push_back("+zcm"); Features.push_back("+zcz"); } return true; } static bool getAArch64MicroArchFeaturesFromMcpu(const Driver &D, StringRef Mcpu, const ArgList &Args, std::vector<const char *> &Features) { StringRef CPU; std::vector<const char *> DecodedFeature; std::string McpuLowerCase = Mcpu.lower(); if (!DecodeAArch64Mcpu(D, McpuLowerCase, CPU, DecodedFeature)) return false; return getAArch64MicroArchFeaturesFromMtune(D, CPU, Args, Features); } static void getAArch64TargetFeatures(const Driver &D, const ArgList &Args, std::vector<const char *> &Features) { Arg *A; bool success = true; // Enable NEON by default. Features.push_back("+neon"); if ((A = Args.getLastArg(options::OPT_march_EQ))) success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features); else if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features); else if (Args.hasArg(options::OPT_arch)) success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args), Args, Features); if (success && (A = Args.getLastArg(options::OPT_mtune_EQ))) success = getAArch64MicroArchFeaturesFromMtune(D, A->getValue(), Args, Features); else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ))) success = getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features); else if (Args.hasArg(options::OPT_arch)) success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args), Args, Features); if (!success) D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); if (Args.getLastArg(options::OPT_mgeneral_regs_only)) { Features.push_back("-fp-armv8"); Features.push_back("-crypto"); Features.push_back("-neon"); } // En/disable crc if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) { if (A->getOption().matches(options::OPT_mcrc)) Features.push_back("+crc"); else Features.push_back("-crc"); } } static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, ArgStringList &CmdArgs, bool ForAS) { std::vector<const char *> Features; switch (Triple.getArch()) { default: break; case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: getMIPSTargetFeatures(D, Triple, Args, Features); break; case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: getARMTargetFeatures(D, Triple, Args, Features, ForAS); break; case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: getPPCTargetFeatures(Args, Features); break; case llvm::Triple::systemz: getSystemZTargetFeatures(Args, Features); break; case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: getAArch64TargetFeatures(D, Args, Features); break; case llvm::Triple::x86: case llvm::Triple::x86_64: getX86TargetFeatures(D, Triple, Args, Features); break; } // Find the last of each feature. llvm::StringMap<unsigned> LastOpt; for (unsigned I = 0, N = Features.size(); I < N; ++I) { const char *Name = Features[I]; assert(Name[0] == '-' || Name[0] == '+'); LastOpt[Name + 1] = I; } for (unsigned I = 0, N = Features.size(); I < N; ++I) { // If this feature was overridden, ignore it. const char *Name = Features[I]; llvm::StringMap<unsigned>::iterator LastI = LastOpt.find(Name + 1); assert(LastI != LastOpt.end()); unsigned Last = LastI->second; if (Last != I) continue; CmdArgs.push_back("-target-feature"); CmdArgs.push_back(Name); } } static bool shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime, const llvm::Triple &Triple) { // We use the zero-cost exception tables for Objective-C if the non-fragile // ABI is enabled or when compiling for x86_64 and ARM on Snow Leopard and // later. if (runtime.isNonFragile()) return true; if (!Triple.isMacOSX()) return false; return (!Triple.isMacOSXVersionLT(10, 5) && (Triple.getArch() == llvm::Triple::x86_64 || Triple.getArch() == llvm::Triple::arm)); } /// Adds exception related arguments to the driver command arguments. There's a /// master flag, -fexceptions and also language specific flags to enable/disable /// C++ and Objective-C exceptions. This makes it possible to for example /// disable C++ exceptions but enable Objective-C exceptions. static void addExceptionArgs(const ArgList &Args, types::ID InputType, const ToolChain &TC, bool KernelOrKext, const ObjCRuntime &objcRuntime, ArgStringList &CmdArgs) { const Driver &D = TC.getDriver(); const llvm::Triple &Triple = TC.getTriple(); if (KernelOrKext) { // -mkernel and -fapple-kext imply no exceptions, so claim exception related // arguments now to avoid warnings about unused arguments. Args.ClaimAllArgs(options::OPT_fexceptions); Args.ClaimAllArgs(options::OPT_fno_exceptions); Args.ClaimAllArgs(options::OPT_fobjc_exceptions); Args.ClaimAllArgs(options::OPT_fno_objc_exceptions); Args.ClaimAllArgs(options::OPT_fcxx_exceptions); Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions); return; } // See if the user explicitly enabled exceptions. bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, false); // Obj-C exceptions are enabled by default, regardless of -fexceptions. This // is not necessarily sensible, but follows GCC. if (types::isObjC(InputType) && Args.hasFlag(options::OPT_fobjc_exceptions, options::OPT_fno_objc_exceptions, true)) { CmdArgs.push_back("-fobjc-exceptions"); EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); } if (types::isCXX(InputType)) { // Disable C++ EH by default on XCore, PS4, and MSVC. // FIXME: Remove MSVC from this list once things work. bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU() && !Triple.isWindowsMSVCEnvironment(); Arg *ExceptionArg = Args.getLastArg( options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, options::OPT_fexceptions, options::OPT_fno_exceptions); if (ExceptionArg) CXXExceptionsEnabled = ExceptionArg->getOption().matches(options::OPT_fcxx_exceptions) || ExceptionArg->getOption().matches(options::OPT_fexceptions); if (CXXExceptionsEnabled) { if (Triple.isPS4CPU()) { ToolChain::RTTIMode RTTIMode = TC.getRTTIMode(); assert(ExceptionArg && "On the PS4 exceptions should only be enabled if passing " "an argument"); if (RTTIMode == ToolChain::RM_DisabledExplicitly) { const Arg *RTTIArg = TC.getRTTIArg(); assert(RTTIArg && "RTTI disabled explicitly but no RTTIArg!"); D.Diag(diag::err_drv_argument_not_allowed_with) << RTTIArg->getAsString(Args) << ExceptionArg->getAsString(Args); } else if (RTTIMode == ToolChain::RM_EnabledImplicitly) D.Diag(diag::warn_drv_enabling_rtti_with_exceptions); } else assert(TC.getRTTIMode() != ToolChain::RM_DisabledImplicitly); CmdArgs.push_back("-fcxx-exceptions"); EH = true; } } if (EH) CmdArgs.push_back("-fexceptions"); } static bool ShouldDisableAutolink(const ArgList &Args, const ToolChain &TC) { bool Default = true; if (TC.getTriple().isOSDarwin()) { // The native darwin assembler doesn't support the linker_option directives, // so we disable them if we think the .s file will be passed to it. Default = TC.useIntegratedAs(); } return !Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink, Default); } static bool ShouldDisableDwarfDirectory(const ArgList &Args, const ToolChain &TC) { bool UseDwarfDirectory = Args.hasFlag(options::OPT_fdwarf_directory_asm, options::OPT_fno_dwarf_directory_asm, TC.useIntegratedAs()); return !UseDwarfDirectory; } /// \brief Check whether the given input tree contains any compilation actions. static bool ContainsCompileAction(const Action *A) { if (isa<CompileJobAction>(A) || isa<BackendJobAction>(A)) return true; for (const auto &Act : *A) if (ContainsCompileAction(Act)) return true; return false; } /// \brief Check if -relax-all should be passed to the internal assembler. /// This is done by default when compiling non-assembler source with -O0. static bool UseRelaxAll(Compilation &C, const ArgList &Args) { bool RelaxDefault = true; if (Arg *A = Args.getLastArg(options::OPT_O_Group)) RelaxDefault = A->getOption().matches(options::OPT_O0); if (RelaxDefault) { RelaxDefault = false; for (const auto &Act : C.getActions()) { if (ContainsCompileAction(Act)) { RelaxDefault = true; break; } } } return Args.hasFlag(options::OPT_mrelax_all, options::OPT_mno_relax_all, RelaxDefault); } static void CollectArgsForIntegratedAssembler(Compilation &C, const ArgList &Args, ArgStringList &CmdArgs, const Driver &D) { if (UseRelaxAll(C, Args)) CmdArgs.push_back("-mrelax-all"); // When passing -I arguments to the assembler we sometimes need to // unconditionally take the next argument. For example, when parsing // '-Wa,-I -Wa,foo' we need to accept the -Wa,foo arg after seeing the // -Wa,-I arg and when parsing '-Wa,-I,foo' we need to accept the 'foo' // arg after parsing the '-I' arg. bool TakeNextArg = false; // When using an integrated assembler, translate -Wa, and -Xassembler // options. bool CompressDebugSections = false; for (const Arg *A : Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) { A->claim(); for (const StringRef Value : A->getValues()) { if (TakeNextArg) { CmdArgs.push_back(Value.data()); TakeNextArg = false; continue; } if (Value == "-force_cpusubtype_ALL") { // Do nothing, this is the default and we don't support anything else. } else if (Value == "-L") { CmdArgs.push_back("-msave-temp-labels"); } else if (Value == "--fatal-warnings") { CmdArgs.push_back("-massembler-fatal-warnings"); } else if (Value == "--noexecstack") { CmdArgs.push_back("-mnoexecstack"); } else if (Value == "-compress-debug-sections" || Value == "--compress-debug-sections") { CompressDebugSections = true; } else if (Value == "-nocompress-debug-sections" || Value == "--nocompress-debug-sections") { CompressDebugSections = false; } else if (Value.startswith("-I")) { CmdArgs.push_back(Value.data()); // We need to consume the next argument if the current arg is a plain // -I. The next arg will be the include directory. if (Value == "-I") TakeNextArg = true; } else if (Value.startswith("-gdwarf-")) { CmdArgs.push_back(Value.data()); } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") || Value.startswith("-mhwdiv") || Value.startswith("-march")) { // Do nothing, we'll validate it later. } else { D.Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Value; } } } if (CompressDebugSections) { if (llvm::zlib::isAvailable()) CmdArgs.push_back("-compress-debug-sections"); else D.Diag(diag::warn_debug_compression_unavailable); } } // Until ARM libraries are build separately, we have them all in one library static StringRef getArchNameForCompilerRTLib(const ToolChain &TC) { if (TC.getTriple().isWindowsMSVCEnvironment() && TC.getArch() == llvm::Triple::x86) return "i386"; if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb) return "arm"; return TC.getArchName(); } static SmallString<128> getCompilerRTLibDir(const ToolChain &TC) { // The runtimes are located in the OS-specific resource directory. SmallString<128> Res(TC.getDriver().ResourceDir); const llvm::Triple &Triple = TC.getTriple(); // TC.getOS() yield "freebsd10.0" whereas "freebsd" is expected. StringRef OSLibName = (Triple.getOS() == llvm::Triple::FreeBSD) ? "freebsd" : TC.getOS(); llvm::sys::path::append(Res, "lib", OSLibName); return Res; } SmallString<128> tools::getCompilerRT(const ToolChain &TC, StringRef Component, bool Shared) { const char *Env = TC.getTriple().getEnvironment() == llvm::Triple::Android ? "-android" : ""; bool IsOSWindows = TC.getTriple().isOSWindows(); bool IsITANMSVCWindows = TC.getTriple().isWindowsMSVCEnvironment() || TC.getTriple().isWindowsItaniumEnvironment(); StringRef Arch = getArchNameForCompilerRTLib(TC); const char *Prefix = IsITANMSVCWindows ? "" : "lib"; const char *Suffix = Shared ? (IsOSWindows ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); SmallString<128> Path = getCompilerRTLibDir(TC); llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" + Arch + Env + Suffix); return Path; } // This adds the static libclang_rt.builtins-arch.a directly to the command line // FIXME: Make sure we can also emit shared objects if they're requested // and available, check for possible errors, etc. static void addClangRT(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { CmdArgs.push_back(Args.MakeArgString(getCompilerRT(TC, "builtins"))); if (!TC.getTriple().isOSWindows()) { // FIXME: why do we link against gcc when we are using compiler-rt? CmdArgs.push_back("-lgcc_s"); if (TC.getDriver().CCCIsCXX()) CmdArgs.push_back("-lgcc_eh"); } } static void addProfileRT(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { if (!(Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, false) || Args.hasArg(options::OPT_fprofile_generate) || Args.hasArg(options::OPT_fprofile_generate_EQ) || Args.hasArg(options::OPT_fprofile_instr_generate) || Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || Args.hasArg(options::OPT_fcreate_profile) || Args.hasArg(options::OPT_coverage))) return; CmdArgs.push_back(Args.MakeArgString(getCompilerRT(TC, "profile"))); } namespace { enum OpenMPRuntimeKind { /// An unknown OpenMP runtime. We can't generate effective OpenMP code /// without knowing what runtime to target. OMPRT_Unknown, /// The LLVM OpenMP runtime. When completed and integrated, this will become /// the default for Clang. OMPRT_OMP, /// The GNU OpenMP runtime. Clang doesn't support generating OpenMP code for /// this runtime but can swallow the pragmas, and find and link against the /// runtime library itself. OMPRT_GOMP, /// The legacy name for the LLVM OpenMP runtime from when it was the Intel /// OpenMP runtime. We support this mode for users with existing dependencies /// on this runtime library name. OMPRT_IOMP5 }; } /// Compute the desired OpenMP runtime from the flag provided. static OpenMPRuntimeKind getOpenMPRuntime(const ToolChain &TC, const ArgList &Args) { StringRef RuntimeName(CLANG_DEFAULT_OPENMP_RUNTIME); const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ); if (A) RuntimeName = A->getValue(); auto RT = llvm::StringSwitch<OpenMPRuntimeKind>(RuntimeName) .Case("libomp", OMPRT_OMP) .Case("libgomp", OMPRT_GOMP) .Case("libiomp5", OMPRT_IOMP5) .Default(OMPRT_Unknown); if (RT == OMPRT_Unknown) { if (A) TC.getDriver().Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << A->getValue(); else // FIXME: We could use a nicer diagnostic here. TC.getDriver().Diag(diag::err_drv_unsupported_opt) << "-fopenmp"; } return RT; } static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer, bool IsShared) { // Static runtimes must be forced into executable, so we wrap them in // whole-archive. if (!IsShared) CmdArgs.push_back("-whole-archive"); CmdArgs.push_back(Args.MakeArgString(getCompilerRT(TC, Sanitizer, IsShared))); if (!IsShared) CmdArgs.push_back("-no-whole-archive"); } // Tries to use a file with the list of dynamic symbols that need to be exported // from the runtime library. Returns true if the file was found. static bool addSanitizerDynamicList(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer) { SmallString<128> SanRT = getCompilerRT(TC, Sanitizer); if (llvm::sys::fs::exists(SanRT + ".syms")) { CmdArgs.push_back(Args.MakeArgString("--dynamic-list=" + SanRT + ".syms")); return true; } return false; } static void linkSanitizerRuntimeDeps(const ToolChain &TC, ArgStringList &CmdArgs) { // Force linking against the system libraries sanitizers depends on // (see PR15823 why this is necessary). CmdArgs.push_back("--no-as-needed"); CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-lrt"); CmdArgs.push_back("-lm"); // There's no libdl on FreeBSD. if (TC.getTriple().getOS() != llvm::Triple::FreeBSD) CmdArgs.push_back("-ldl"); } static void collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, SmallVectorImpl<StringRef> &SharedRuntimes, SmallVectorImpl<StringRef> &StaticRuntimes, SmallVectorImpl<StringRef> &HelperStaticRuntimes) { const SanitizerArgs &SanArgs = TC.getSanitizerArgs(); // Collect shared runtimes. if (SanArgs.needsAsanRt() && SanArgs.needsSharedAsanRt()) { SharedRuntimes.push_back("asan"); } // Collect static runtimes. if (Args.hasArg(options::OPT_shared) || (TC.getTriple().getEnvironment() == llvm::Triple::Android)) { // Don't link static runtimes into DSOs or if compiling for Android. return; } if (SanArgs.needsAsanRt()) { if (SanArgs.needsSharedAsanRt()) { HelperStaticRuntimes.push_back("asan-preinit"); } else { StaticRuntimes.push_back("asan"); if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("asan_cxx"); } } if (SanArgs.needsDfsanRt()) StaticRuntimes.push_back("dfsan"); if (SanArgs.needsLsanRt()) StaticRuntimes.push_back("lsan"); if (SanArgs.needsMsanRt()) { StaticRuntimes.push_back("msan"); if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("msan_cxx"); } if (SanArgs.needsTsanRt()) { StaticRuntimes.push_back("tsan"); if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("tsan_cxx"); } if (SanArgs.needsUbsanRt()) { StaticRuntimes.push_back("ubsan_standalone"); if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("ubsan_standalone_cxx"); } if (SanArgs.needsSafeStackRt()) StaticRuntimes.push_back("safestack"); } // Should be called before we add system libraries (C++ ABI, libstdc++/libc++, // C runtime, etc). Returns true if sanitizer system deps need to be linked in. static bool addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { SmallVector<StringRef, 4> SharedRuntimes, StaticRuntimes, HelperStaticRuntimes; collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes, HelperStaticRuntimes); for (auto RT : SharedRuntimes) addSanitizerRuntime(TC, Args, CmdArgs, RT, true); for (auto RT : HelperStaticRuntimes) addSanitizerRuntime(TC, Args, CmdArgs, RT, false); bool AddExportDynamic = false; for (auto RT : StaticRuntimes) { addSanitizerRuntime(TC, Args, CmdArgs, RT, false); AddExportDynamic |= !addSanitizerDynamicList(TC, Args, CmdArgs, RT); } // If there is a static runtime with no dynamic list, force all the symbols // to be dynamic to be sure we export sanitizer interface functions. if (AddExportDynamic) CmdArgs.push_back("-export-dynamic"); return !StaticRuntimes.empty(); } static bool areOptimizationsEnabled(const ArgList &Args) { // Find the last -O arg and see if it is non-zero. if (Arg *A = Args.getLastArg(options::OPT_O_Group)) return !A->getOption().matches(options::OPT_O0); // Defaults to -O0. return false; } static bool shouldUseFramePointerForTarget(const ArgList &Args, const llvm::Triple &Triple) { // XCore never wants frame pointers, regardless of OS. if (Triple.getArch() == llvm::Triple::xcore) { return false; } if (Triple.isOSLinux()) { switch (Triple.getArch()) { // Don't use a frame pointer on linux if optimizing for certain targets. case llvm::Triple::mips64: case llvm::Triple::mips64el: case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::systemz: case llvm::Triple::x86: case llvm::Triple::x86_64: return !areOptimizationsEnabled(Args); default: return true; } } if (Triple.isOSWindows()) { switch (Triple.getArch()) { case llvm::Triple::x86: return !areOptimizationsEnabled(Args); default: // All other supported Windows ISAs use xdata unwind information, so frame // pointers are not generally useful. return false; } } return true; } static bool shouldUseFramePointer(const ArgList &Args, const llvm::Triple &Triple) { if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer, options::OPT_fomit_frame_pointer)) return A->getOption().matches(options::OPT_fno_omit_frame_pointer); return shouldUseFramePointerForTarget(Args, Triple); } static bool shouldUseLeafFramePointer(const ArgList &Args, const llvm::Triple &Triple) { if (Arg *A = Args.getLastArg(options::OPT_mno_omit_leaf_frame_pointer, options::OPT_momit_leaf_frame_pointer)) return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer); if (Triple.isPS4CPU()) return false; return shouldUseFramePointerForTarget(Args, Triple); } /// Add a CC1 option to specify the debug compilation directory. static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) { SmallString<128> cwd; if (!llvm::sys::fs::current_path(cwd)) { CmdArgs.push_back("-fdebug-compilation-dir"); CmdArgs.push_back(Args.MakeArgString(cwd)); } } static const char *SplitDebugName(const ArgList &Args, const InputInfo &Input) { Arg *FinalOutput = Args.getLastArg(options::OPT_o); if (FinalOutput && Args.hasArg(options::OPT_c)) { SmallString<128> T(FinalOutput->getValue()); llvm::sys::path::replace_extension(T, "dwo"); return Args.MakeArgString(T); } else { // Use the compilation dir. SmallString<128> T( Args.getLastArgValue(options::OPT_fdebug_compilation_dir)); SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput())); llvm::sys::path::replace_extension(F, "dwo"); T += F; return Args.MakeArgString(F); } } static void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T, const JobAction &JA, const ArgList &Args, const InputInfo &Output, const char *OutFile) { ArgStringList ExtractArgs; ExtractArgs.push_back("--extract-dwo"); ArgStringList StripArgs; StripArgs.push_back("--strip-dwo"); // Grabbing the output of the earlier compile step. StripArgs.push_back(Output.getFilename()); ExtractArgs.push_back(Output.getFilename()); ExtractArgs.push_back(OutFile); const char *Exec = Args.MakeArgString(TC.GetProgramPath("objcopy")); // First extract the dwo sections. C.addCommand(llvm::make_unique<Command>(JA, T, Exec, ExtractArgs)); // Then remove them from the original .o file. C.addCommand(llvm::make_unique<Command>(JA, T, Exec, StripArgs)); } /// \brief Vectorize at all optimization levels greater than 1 except for -Oz. /// For -Oz the loop vectorizer is disable, while the slp vectorizer is enabled. static bool shouldEnableVectorizerAtOLevel(const ArgList &Args, bool isSlpVec) { if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { if (A->getOption().matches(options::OPT_O4) || A->getOption().matches(options::OPT_Ofast)) return true; if (A->getOption().matches(options::OPT_O0)) return false; assert(A->getOption().matches(options::OPT_O) && "Must have a -O flag"); // Vectorize -Os. StringRef S(A->getValue()); if (S == "s") return true; // Don't vectorize -Oz, unless it's the slp vectorizer. if (S == "z") return isSlpVec; unsigned OptLevel = 0; if (S.getAsInteger(10, OptLevel)) return false; return OptLevel > 1; } return false; } /// Add -x lang to \p CmdArgs for \p Input. static void addDashXForInput(const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs) { // When using -verify-pch, we don't want to provide the type // 'precompiled-header' if it was inferred from the file extension if (Args.hasArg(options::OPT_verify_pch) && Input.getType() == types::TY_PCH) return; CmdArgs.push_back("-x"); if (Args.hasArg(options::OPT_rewrite_objc)) CmdArgs.push_back(types::getTypeName(types::TY_PP_ObjCXX)); else CmdArgs.push_back(types::getTypeName(Input.getType())); } static VersionTuple getMSCompatibilityVersion(unsigned Version) { if (Version < 100) return VersionTuple(Version); if (Version < 10000) return VersionTuple(Version / 100, Version % 100); unsigned Build = 0, Factor = 1; for (; Version > 10000; Version = Version / 10, Factor = Factor * 10) Build = Build + (Version % 10) * Factor; return VersionTuple(Version / 100, Version % 100, Build); } // Claim options we don't want to warn if they are unused. We do this for // options that build systems might add but are unused when assembling or only // running the preprocessor for example. static void claimNoWarnArgs(const ArgList &Args) { // Don't warn about unused -f(no-)?lto. This can happen when we're // preprocessing, precompiling or assembling. Args.ClaimAllArgs(options::OPT_flto); Args.ClaimAllArgs(options::OPT_fno_lto); } static void appendUserToPath(SmallVectorImpl<char> &Result) { #ifdef LLVM_ON_UNIX const char *Username = getenv("LOGNAME"); #else const char *Username = getenv("USERNAME"); #endif if (Username) { // Validate that LoginName can be used in a path, and get its length. size_t Len = 0; for (const char *P = Username; *P; ++P, ++Len) { if (!isAlphanumeric(*P) && *P != '_') { Username = nullptr; break; } } if (Username && Len > 0) { Result.append(Username, Username + Len); return; } } // Fallback to user id. #ifdef LLVM_ON_UNIX std::string UID = llvm::utostr(getuid()); #else // FIXME: Windows seems to have an 'SID' that might work. std::string UID = "9999"; #endif Result.append(UID.begin(), UID.end()); } VersionTuple visualstudio::getMSVCVersion(const Driver *D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, bool IsWindowsMSVC) { if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, IsWindowsMSVC) || Args.hasArg(options::OPT_fmsc_version) || Args.hasArg(options::OPT_fms_compatibility_version)) { const Arg *MSCVersion = Args.getLastArg(options::OPT_fmsc_version); const Arg *MSCompatibilityVersion = Args.getLastArg(options::OPT_fms_compatibility_version); if (MSCVersion && MSCompatibilityVersion) { if (D) D->Diag(diag::err_drv_argument_not_allowed_with) << MSCVersion->getAsString(Args) << MSCompatibilityVersion->getAsString(Args); return VersionTuple(); } if (MSCompatibilityVersion) { VersionTuple MSVT; if (MSVT.tryParse(MSCompatibilityVersion->getValue()) && D) D->Diag(diag::err_drv_invalid_value) << MSCompatibilityVersion->getAsString(Args) << MSCompatibilityVersion->getValue(); return MSVT; } if (MSCVersion) { unsigned Version = 0; if (StringRef(MSCVersion->getValue()).getAsInteger(10, Version) && D) D->Diag(diag::err_drv_invalid_value) << MSCVersion->getAsString(Args) << MSCVersion->getValue(); return getMSCompatibilityVersion(Version); } unsigned Major, Minor, Micro; Triple.getEnvironmentVersion(Major, Minor, Micro); if (Major || Minor || Micro) return VersionTuple(Major, Minor, Micro); return VersionTuple(18); } return VersionTuple(); } static void addPGOAndCoverageFlags(Compilation &C, const Driver &D, const InputInfo &Output, const ArgList &Args, ArgStringList &CmdArgs) { auto *ProfileGenerateArg = Args.getLastArg( options::OPT_fprofile_instr_generate, options::OPT_fprofile_instr_generate_EQ, options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ); auto *ProfileUseArg = Args.getLastArg( options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ, options::OPT_fprofile_use, options::OPT_fprofile_use_EQ); if (ProfileGenerateArg && ProfileUseArg) D.Diag(diag::err_drv_argument_not_allowed_with) << ProfileGenerateArg->getSpelling() << ProfileUseArg->getSpelling(); if (ProfileGenerateArg && ProfileGenerateArg->getOption().matches( options::OPT_fprofile_instr_generate_EQ)) ProfileGenerateArg->render(Args, CmdArgs); else if (ProfileGenerateArg && ProfileGenerateArg->getOption().matches( options::OPT_fprofile_generate_EQ)) { SmallString<128> Path(ProfileGenerateArg->getValue()); llvm::sys::path::append(Path, "default.profraw"); CmdArgs.push_back( Args.MakeArgString(Twine("-fprofile-instr-generate=") + Path)); } else Args.AddAllArgs(CmdArgs, options::OPT_fprofile_instr_generate); if (ProfileUseArg && ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ)) ProfileUseArg->render(Args, CmdArgs); else if (ProfileUseArg && (ProfileUseArg->getOption().matches(options::OPT_fprofile_use_EQ) || ProfileUseArg->getOption().matches( options::OPT_fprofile_instr_use))) { SmallString<128> Path( ProfileUseArg->getNumValues() == 0 ? "" : ProfileUseArg->getValue()); if (Path.empty() || llvm::sys::fs::is_directory(Path)) llvm::sys::path::append(Path, "default.profdata"); CmdArgs.push_back(Args.MakeArgString(Twine("-fprofile-instr-use=") + Path)); } if (Args.hasArg(options::OPT_ftest_coverage) || Args.hasArg(options::OPT_coverage)) CmdArgs.push_back("-femit-coverage-notes"); if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, false) || Args.hasArg(options::OPT_coverage)) CmdArgs.push_back("-femit-coverage-data"); if (Args.hasArg(options::OPT_fcoverage_mapping) && !ProfileGenerateArg) D.Diag(diag::err_drv_argument_only_allowed_with) << "-fcoverage-mapping" << "-fprofile-instr-generate"; if (Args.hasArg(options::OPT_fcoverage_mapping)) CmdArgs.push_back("-fcoverage-mapping"); if (C.getArgs().hasArg(options::OPT_c) || C.getArgs().hasArg(options::OPT_S)) { if (Output.isFilename()) { CmdArgs.push_back("-coverage-file"); SmallString<128> CoverageFilename; if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o)) { CoverageFilename = FinalOutput->getValue(); } else { CoverageFilename = llvm::sys::path::filename(Output.getBaseInput()); } if (llvm::sys::path::is_relative(CoverageFilename)) { SmallString<128> Pwd; if (!llvm::sys::fs::current_path(Pwd)) { llvm::sys::path::append(Pwd, CoverageFilename); CoverageFilename.swap(Pwd); } } CmdArgs.push_back(Args.MakeArgString(CoverageFilename)); } } } void Clang::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { bool KernelOrKext = Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext); const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; bool IsWindowsGNU = getToolChain().getTriple().isWindowsGNUEnvironment(); bool IsWindowsCygnus = getToolChain().getTriple().isWindowsCygwinEnvironment(); bool IsWindowsMSVC = getToolChain().getTriple().isWindowsMSVCEnvironment(); // Check number of inputs for sanity. We need at least one input. assert(Inputs.size() >= 1 && "Must have at least one input."); const InputInfo &Input = Inputs[0]; // CUDA compilation may have multiple inputs (source file + results of // device-side compilations). All other jobs are expected to have exactly one // input. bool IsCuda = types::isCuda(Input.getType()); assert((IsCuda || Inputs.size() == 1) && "Unable to handle multiple inputs."); // Invoke ourselves in -cc1 mode. // // FIXME: Implement custom jobs for internal actions. CmdArgs.push_back("-cc1"); // Add the "effective" target triple. CmdArgs.push_back("-triple"); std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); CmdArgs.push_back(Args.MakeArgString(TripleStr)); const llvm::Triple TT(TripleStr); if (TT.isOSWindows() && (TT.getArch() == llvm::Triple::arm || TT.getArch() == llvm::Triple::thumb)) { unsigned Offset = TT.getArch() == llvm::Triple::arm ? 4 : 6; unsigned Version; TT.getArchName().substr(Offset).getAsInteger(10, Version); if (Version < 7) D.Diag(diag::err_target_unsupported_arch) << TT.getArchName() << TripleStr; } // Push all default warning arguments that are specific to // the given target. These come before user provided warning options // are provided. getToolChain().addClangWarningOptions(CmdArgs); // Select the appropriate action. RewriteKind rewriteKind = RK_None; if (isa<AnalyzeJobAction>(JA)) { assert(JA.getType() == types::TY_Plist && "Invalid output type."); CmdArgs.push_back("-analyze"); } else if (isa<MigrateJobAction>(JA)) { CmdArgs.push_back("-migrate"); } else if (isa<PreprocessJobAction>(JA)) { if (Output.getType() == types::TY_Dependencies) CmdArgs.push_back("-Eonly"); else { CmdArgs.push_back("-E"); if (Args.hasArg(options::OPT_rewrite_objc) && !Args.hasArg(options::OPT_g_Group)) CmdArgs.push_back("-P"); } } else if (isa<AssembleJobAction>(JA)) { CmdArgs.push_back("-emit-obj"); CollectArgsForIntegratedAssembler(C, Args, CmdArgs, D); // Also ignore explicit -force_cpusubtype_ALL option. (void)Args.hasArg(options::OPT_force__cpusubtype__ALL); } else if (isa<PrecompileJobAction>(JA)) { // Use PCH if the user requested it. bool UsePCH = D.CCCUsePCH; if (JA.getType() == types::TY_Nothing) CmdArgs.push_back("-fsyntax-only"); else if (UsePCH) CmdArgs.push_back("-emit-pch"); else CmdArgs.push_back("-emit-pth"); } else if (isa<VerifyPCHJobAction>(JA)) { CmdArgs.push_back("-verify-pch"); } else { assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) && "Invalid action for clang tool."); if (JA.getType() == types::TY_LTO_IR || JA.getType() == types::TY_LTO_BC) { CmdArgs.push_back("-flto"); } if (JA.getType() == types::TY_Nothing) { CmdArgs.push_back("-fsyntax-only"); } else if (JA.getType() == types::TY_LLVM_IR || JA.getType() == types::TY_LTO_IR) { CmdArgs.push_back("-emit-llvm"); } else if (JA.getType() == types::TY_LLVM_BC || JA.getType() == types::TY_LTO_BC) { CmdArgs.push_back("-emit-llvm-bc"); } else if (JA.getType() == types::TY_PP_Asm) { CmdArgs.push_back("-S"); } else if (JA.getType() == types::TY_AST) { CmdArgs.push_back("-emit-pch"); } else if (JA.getType() == types::TY_ModuleFile) { CmdArgs.push_back("-module-file-info"); } else if (JA.getType() == types::TY_RewrittenObjC) { CmdArgs.push_back("-rewrite-objc"); rewriteKind = RK_NonFragile; } else if (JA.getType() == types::TY_RewrittenLegacyObjC) { CmdArgs.push_back("-rewrite-objc"); rewriteKind = RK_Fragile; } else { assert(JA.getType() == types::TY_PP_Asm && "Unexpected output type!"); } // Preserve use-list order by default when emitting bitcode, so that // loading the bitcode up in 'opt' or 'llc' and running passes gives the // same result as running passes here. For LTO, we don't need to preserve // the use-list order, since serialization to bitcode is part of the flow. if (JA.getType() == types::TY_LLVM_BC) CmdArgs.push_back("-emit-llvm-uselists"); } // We normally speed up the clang process a bit by skipping destructors at // exit, but when we're generating diagnostics we can rely on some of the // cleanup. if (!C.isForDiagnostics()) CmdArgs.push_back("-disable-free"); // Disable the verification pass in -asserts builds. #ifdef NDEBUG CmdArgs.push_back("-disable-llvm-verifier"); #endif // Set the main file name, so that debug info works even with // -save-temps. CmdArgs.push_back("-main-file-name"); CmdArgs.push_back(getBaseInputName(Args, Input)); // Some flags which affect the language (via preprocessor // defines). if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("-static-define"); if (isa<AnalyzeJobAction>(JA)) { // Enable region store model by default. CmdArgs.push_back("-analyzer-store=region"); // Treat blocks as analysis entry points. CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks"); CmdArgs.push_back("-analyzer-eagerly-assume"); // Add default argument set. if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) { CmdArgs.push_back("-analyzer-checker=core"); if (!IsWindowsMSVC) CmdArgs.push_back("-analyzer-checker=unix"); if (getToolChain().getTriple().getVendor() == llvm::Triple::Apple) CmdArgs.push_back("-analyzer-checker=osx"); CmdArgs.push_back("-analyzer-checker=deadcode"); if (types::isCXX(Input.getType())) CmdArgs.push_back("-analyzer-checker=cplusplus"); // Enable the following experimental checkers for testing. CmdArgs.push_back( "-analyzer-checker=security.insecureAPI.UncheckedReturn"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.getpw"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.gets"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mktemp"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mkstemp"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.vfork"); } // Set the output format. The default is plist, for (lame) historical // reasons. CmdArgs.push_back("-analyzer-output"); if (Arg *A = Args.getLastArg(options::OPT__analyzer_output)) CmdArgs.push_back(A->getValue()); else CmdArgs.push_back("plist"); // Disable the presentation of standard compiler warnings when // using --analyze. We only want to show static analyzer diagnostics // or frontend errors. CmdArgs.push_back("-w"); // Add -Xanalyzer arguments when running as analyzer. Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); } CheckCodeGenerationOptions(D, Args); bool PIE = getToolChain().isPIEDefault(); bool PIC = PIE || getToolChain().isPICDefault(); bool IsPICLevelTwo = PIC; // Android-specific defaults for PIC/PIE if (getToolChain().getTriple().getEnvironment() == llvm::Triple::Android) { switch (getToolChain().getArch()) { case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: case llvm::Triple::aarch64: case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: PIC = true; // "-fpic" break; case llvm::Triple::x86: case llvm::Triple::x86_64: PIC = true; // "-fPIC" IsPICLevelTwo = true; break; default: break; } } // OpenBSD-specific defaults for PIE if (getToolChain().getTriple().getOS() == llvm::Triple::OpenBSD) { switch (getToolChain().getArch()) { case llvm::Triple::mips64: case llvm::Triple::mips64el: case llvm::Triple::sparcel: case llvm::Triple::x86: case llvm::Triple::x86_64: IsPICLevelTwo = false; // "-fpie" break; case llvm::Triple::ppc: case llvm::Triple::sparc: case llvm::Triple::sparcv9: IsPICLevelTwo = true; // "-fPIE" break; default: break; } } // For the PIC and PIE flag options, this logic is different from the // legacy logic in very old versions of GCC, as that logic was just // a bug no one had ever fixed. This logic is both more rational and // consistent with GCC's new logic now that the bugs are fixed. The last // argument relating to either PIC or PIE wins, and no other argument is // used. If the last argument is any flavor of the '-fno-...' arguments, // both PIC and PIE are disabled. Any PIE option implicitly enables PIC // at the same level. Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, options::OPT_fpic, options::OPT_fno_pic, options::OPT_fPIE, options::OPT_fno_PIE, options::OPT_fpie, options::OPT_fno_pie); // Check whether the tool chain trumps the PIC-ness decision. If the PIC-ness // is forced, then neither PIC nor PIE flags will have no effect. if (!getToolChain().isPICDefaultForced()) { if (LastPICArg) { Option O = LastPICArg->getOption(); if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) || O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) { PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie); PIC = PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic); IsPICLevelTwo = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC); } else { PIE = PIC = false; } } } // Introduce a Darwin-specific hack. If the default is PIC but the flags // specified while enabling PIC enabled level 1 PIC, just force it back to // level 2 PIC instead. This matches the behavior of Darwin GCC (based on my // informal testing). if (PIC && getToolChain().getTriple().isOSDarwin()) IsPICLevelTwo |= getToolChain().isPICDefault(); // Note that these flags are trump-cards. Regardless of the order w.r.t. the // PIC or PIE options above, if these show up, PIC is disabled. llvm::Triple Triple(TripleStr); if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6))) PIC = PIE = false; if (Args.hasArg(options::OPT_static)) PIC = PIE = false; if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) { // This is a very special mode. It trumps the other modes, almost no one // uses it, and it isn't even valid on any OS but Darwin. if (!getToolChain().getTriple().isOSDarwin()) D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getSpelling() << getToolChain().getTriple().str(); // FIXME: Warn when this flag trumps some other PIC or PIE flag. CmdArgs.push_back("-mrelocation-model"); CmdArgs.push_back("dynamic-no-pic"); // Only a forced PIC mode can cause the actual compile to have PIC defines // etc., no flags are sufficient. This behavior was selected to closely // match that of llvm-gcc and Apple GCC before that. if (getToolChain().isPICDefault() && getToolChain().isPICDefaultForced()) { CmdArgs.push_back("-pic-level"); CmdArgs.push_back("2"); } } else { // Currently, LLVM only knows about PIC vs. static; the PIE differences are // handled in Clang's IRGen by the -pie-level flag. CmdArgs.push_back("-mrelocation-model"); CmdArgs.push_back(PIC ? "pic" : "static"); if (PIC) { CmdArgs.push_back("-pic-level"); CmdArgs.push_back(IsPICLevelTwo ? "2" : "1"); if (PIE) { CmdArgs.push_back("-pie-level"); CmdArgs.push_back(IsPICLevelTwo ? "2" : "1"); } } } CmdArgs.push_back("-mthread-model"); if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) CmdArgs.push_back(A->getValue()); else CmdArgs.push_back(Args.MakeArgString(getToolChain().getThreadModel())); Args.AddLastArg(CmdArgs, options::OPT_fveclib); if (!Args.hasFlag(options::OPT_fmerge_all_constants, options::OPT_fno_merge_all_constants)) CmdArgs.push_back("-fno-merge-all-constants"); // LLVM Code Generator Options. if (Args.hasArg(options::OPT_frewrite_map_file) || Args.hasArg(options::OPT_frewrite_map_file_EQ)) { for (const Arg *A : Args.filtered(options::OPT_frewrite_map_file, options::OPT_frewrite_map_file_EQ)) { CmdArgs.push_back("-frewrite-map-file"); CmdArgs.push_back(A->getValue()); A->claim(); } } if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) { StringRef v = A->getValue(); CmdArgs.push_back("-mllvm"); CmdArgs.push_back(Args.MakeArgString("-warn-stack-size=" + v)); A->claim(); } if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) { CmdArgs.push_back("-mregparm"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return, options::OPT_freg_struct_return)) { if (getToolChain().getArch() != llvm::Triple::x86) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getSpelling() << getToolChain().getTriple().str(); } else if (A->getOption().matches(options::OPT_fpcc_struct_return)) { CmdArgs.push_back("-fpcc-struct-return"); } else { assert(A->getOption().matches(options::OPT_freg_struct_return)); CmdArgs.push_back("-freg-struct-return"); } } if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd, false)) CmdArgs.push_back("-mrtd"); if (shouldUseFramePointer(Args, getToolChain().getTriple())) CmdArgs.push_back("-mdisable-fp-elim"); if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, options::OPT_fno_zero_initialized_in_bss)) CmdArgs.push_back("-mno-zero-initialized-in-bss"); bool OFastEnabled = isOptimizationLevelFast(Args); // If -Ofast is the optimization level, then -fstrict-aliasing should be // enabled. This alias option is being used to simplify the hasFlag logic. OptSpecifier StrictAliasingAliasOption = OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing; // We turn strict aliasing off by default if we're in CL mode, since MSVC // doesn't do any TBAA. bool TBAAOnByDefault = !getToolChain().getDriver().IsCLMode(); if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption, options::OPT_fno_strict_aliasing, TBAAOnByDefault)) CmdArgs.push_back("-relaxed-aliasing"); if (!Args.hasFlag(options::OPT_fstruct_path_tbaa, options::OPT_fno_struct_path_tbaa)) CmdArgs.push_back("-no-struct-path-tbaa"); if (Args.hasFlag(options::OPT_fstrict_enums, options::OPT_fno_strict_enums, false)) CmdArgs.push_back("-fstrict-enums"); if (!Args.hasFlag(options::OPT_foptimize_sibling_calls, options::OPT_fno_optimize_sibling_calls)) CmdArgs.push_back("-mdisable-tail-calls"); // Handle segmented stacks. if (Args.hasArg(options::OPT_fsplit_stack)) CmdArgs.push_back("-split-stacks"); // If -Ofast is the optimization level, then -ffast-math should be enabled. // This alias option is being used to simplify the getLastArg logic. OptSpecifier FastMathAliasOption = OFastEnabled ? options::OPT_Ofast : options::OPT_ffast_math; // Handle various floating point optimization flags, mapping them to the // appropriate LLVM code generation flags. The pattern for all of these is to // default off the codegen optimizations, and if any flag enables them and no // flag disables them after the flag enabling them, enable the codegen // optimization. This is complicated by several "umbrella" flags. if (Arg *A = Args.getLastArg( options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_ffinite_math_only, options::OPT_fno_finite_math_only, options::OPT_fhonor_infinities, options::OPT_fno_honor_infinities)) if (A->getOption().getID() != options::OPT_fno_fast_math && A->getOption().getID() != options::OPT_fno_finite_math_only && A->getOption().getID() != options::OPT_fhonor_infinities) CmdArgs.push_back("-menable-no-infs"); if (Arg *A = Args.getLastArg( options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_ffinite_math_only, options::OPT_fno_finite_math_only, options::OPT_fhonor_nans, options::OPT_fno_honor_nans)) if (A->getOption().getID() != options::OPT_fno_fast_math && A->getOption().getID() != options::OPT_fno_finite_math_only && A->getOption().getID() != options::OPT_fhonor_nans) CmdArgs.push_back("-menable-no-nans"); // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes. bool MathErrno = getToolChain().IsMathErrnoDefault(); if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_fmath_errno, options::OPT_fno_math_errno)) { // Turning on -ffast_math (with either flag) removes the need for MathErrno. // However, turning *off* -ffast_math merely restores the toolchain default // (which may be false). if (A->getOption().getID() == options::OPT_fno_math_errno || A->getOption().getID() == options::OPT_ffast_math || A->getOption().getID() == options::OPT_Ofast) MathErrno = false; else if (A->getOption().getID() == options::OPT_fmath_errno) MathErrno = true; } if (MathErrno) CmdArgs.push_back("-fmath-errno"); // There are several flags which require disabling very specific // optimizations. Any of these being disabled forces us to turn off the // entire set of LLVM optimizations, so collect them through all the flag // madness. bool AssociativeMath = false; if (Arg *A = Args.getLastArg( options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations, options::OPT_fno_unsafe_math_optimizations, options::OPT_fassociative_math, options::OPT_fno_associative_math)) if (A->getOption().getID() != options::OPT_fno_fast_math && A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && A->getOption().getID() != options::OPT_fno_associative_math) AssociativeMath = true; bool ReciprocalMath = false; if (Arg *A = Args.getLastArg( options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations, options::OPT_fno_unsafe_math_optimizations, options::OPT_freciprocal_math, options::OPT_fno_reciprocal_math)) if (A->getOption().getID() != options::OPT_fno_fast_math && A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && A->getOption().getID() != options::OPT_fno_reciprocal_math) ReciprocalMath = true; bool SignedZeros = true; if (Arg *A = Args.getLastArg( options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations, options::OPT_fno_unsafe_math_optimizations, options::OPT_fsigned_zeros, options::OPT_fno_signed_zeros)) if (A->getOption().getID() != options::OPT_fno_fast_math && A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && A->getOption().getID() != options::OPT_fsigned_zeros) SignedZeros = false; bool TrappingMath = true; if (Arg *A = Args.getLastArg( options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations, options::OPT_fno_unsafe_math_optimizations, options::OPT_ftrapping_math, options::OPT_fno_trapping_math)) if (A->getOption().getID() != options::OPT_fno_fast_math && A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && A->getOption().getID() != options::OPT_ftrapping_math) TrappingMath = false; if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && !TrappingMath) CmdArgs.push_back("-menable-unsafe-fp-math"); if (!SignedZeros) CmdArgs.push_back("-fno-signed-zeros"); if (ReciprocalMath) CmdArgs.push_back("-freciprocal-math"); // Validate and pass through -fp-contract option. if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, options::OPT_ffp_contract)) { if (A->getOption().getID() == options::OPT_ffp_contract) { StringRef Val = A->getValue(); if (Val == "fast" || Val == "on" || Val == "off") { CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + Val)); } else { D.Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Val; } } else if (A->getOption().matches(options::OPT_ffast_math) || (OFastEnabled && A->getOption().matches(options::OPT_Ofast))) { // If fast-math is set then set the fp-contract mode to fast. CmdArgs.push_back(Args.MakeArgString("-ffp-contract=fast")); } } ParseMRecip(getToolChain().getDriver(), Args, CmdArgs); // We separately look for the '-ffast-math' and '-ffinite-math-only' flags, // and if we find them, tell the frontend to provide the appropriate // preprocessor macros. This is distinct from enabling any optimizations as // these options induce language changes which must survive serialization // and deserialization, etc. if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math)) if (!A->getOption().matches(options::OPT_fno_fast_math)) CmdArgs.push_back("-ffast-math"); if (Arg *A = Args.getLastArg(options::OPT_ffinite_math_only, options::OPT_fno_fast_math)) if (A->getOption().matches(options::OPT_ffinite_math_only)) CmdArgs.push_back("-ffinite-math-only"); // Decide whether to use verbose asm. Verbose assembly is the default on // toolchains which have the integrated assembler on by default. bool IsIntegratedAssemblerDefault = getToolChain().IsIntegratedAssemblerDefault(); if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm, IsIntegratedAssemblerDefault) || Args.hasArg(options::OPT_dA)) CmdArgs.push_back("-masm-verbose"); if (!Args.hasFlag(options::OPT_fintegrated_as, options::OPT_fno_integrated_as, IsIntegratedAssemblerDefault)) CmdArgs.push_back("-no-integrated-as"); if (Args.hasArg(options::OPT_fdebug_pass_structure)) { CmdArgs.push_back("-mdebug-pass"); CmdArgs.push_back("Structure"); } if (Args.hasArg(options::OPT_fdebug_pass_arguments)) { CmdArgs.push_back("-mdebug-pass"); CmdArgs.push_back("Arguments"); } // Enable -mconstructor-aliases except on darwin, where we have to // work around a linker bug; see <rdar://problem/7651567>. if (!getToolChain().getTriple().isOSDarwin()) CmdArgs.push_back("-mconstructor-aliases"); // Darwin's kernel doesn't support guard variables; just die if we // try to use them. if (KernelOrKext && getToolChain().getTriple().isOSDarwin()) CmdArgs.push_back("-fforbid-guard-variables"); if (Args.hasArg(options::OPT_mms_bitfields)) { CmdArgs.push_back("-mms-bitfields"); } // This is a coarse approximation of what llvm-gcc actually does, both // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more // complicated ways. bool AsynchronousUnwindTables = Args.hasFlag(options::OPT_fasynchronous_unwind_tables, options::OPT_fno_asynchronous_unwind_tables, (getToolChain().IsUnwindTablesDefault() || getToolChain().getSanitizerArgs().needsUnwindTables()) && !KernelOrKext); if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables, AsynchronousUnwindTables)) CmdArgs.push_back("-munwind-tables"); getToolChain().addClangTargetOptions(Args, CmdArgs); if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { CmdArgs.push_back("-mlimit-float-precision"); CmdArgs.push_back(A->getValue()); } // FIXME: Handle -mtune=. (void)Args.hasArg(options::OPT_mtune_EQ); if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { CmdArgs.push_back("-mcode-model"); CmdArgs.push_back(A->getValue()); } // Add the target cpu std::string CPU = getCPUName(Args, Triple, /*FromAs*/ false); if (!CPU.empty()) { CmdArgs.push_back("-target-cpu"); CmdArgs.push_back(Args.MakeArgString(CPU)); } if (const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) { CmdArgs.push_back("-mfpmath"); CmdArgs.push_back(A->getValue()); } // Add the target features getTargetFeatures(D, Triple, Args, CmdArgs, false); // Add target specific flags. switch (getToolChain().getArch()) { default: break; case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: AddARMTargetArgs(Args, CmdArgs, KernelOrKext); break; case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: AddAArch64TargetArgs(Args, CmdArgs); break; case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: AddMIPSTargetArgs(Args, CmdArgs); break; case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: AddPPCTargetArgs(Args, CmdArgs); break; case llvm::Triple::sparc: case llvm::Triple::sparcel: case llvm::Triple::sparcv9: AddSparcTargetArgs(Args, CmdArgs); break; case llvm::Triple::x86: case llvm::Triple::x86_64: AddX86TargetArgs(Args, CmdArgs); break; case llvm::Triple::hexagon: AddHexagonTargetArgs(Args, CmdArgs); break; } // Add clang-cl arguments. if (getToolChain().getDriver().IsCLMode()) AddClangCLArgs(Args, CmdArgs); // Pass the linker version in use. if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { CmdArgs.push_back("-target-linker-version"); CmdArgs.push_back(A->getValue()); } if (!shouldUseLeafFramePointer(Args, getToolChain().getTriple())) CmdArgs.push_back("-momit-leaf-frame-pointer"); // Explicitly error on some things we know we don't support and can't just // ignore. types::ID InputType = Input.getType(); if (!Args.hasArg(options::OPT_fallow_unsupported)) { Arg *Unsupported; if (types::isCXX(InputType) && getToolChain().getTriple().isOSDarwin() && getToolChain().getArch() == llvm::Triple::x86) { if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) || (Unsupported = Args.getLastArg(options::OPT_mkernel))) D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386) << Unsupported->getOption().getName(); } } Args.AddAllArgs(CmdArgs, options::OPT_v); Args.AddLastArg(CmdArgs, options::OPT_H); if (D.CCPrintHeaders && !D.CCGenDiagnostics) { CmdArgs.push_back("-header-include-file"); CmdArgs.push_back(D.CCPrintHeadersFilename ? D.CCPrintHeadersFilename : "-"); } Args.AddLastArg(CmdArgs, options::OPT_P); Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); if (D.CCLogDiagnostics && !D.CCGenDiagnostics) { CmdArgs.push_back("-diagnostic-log-file"); CmdArgs.push_back(D.CCLogDiagnosticsFilename ? D.CCLogDiagnosticsFilename : "-"); } // Use the last option from "-g" group. "-gline-tables-only" and "-gdwarf-x" // are preserved, all other debug options are substituted with "-g". Args.ClaimAllArgs(options::OPT_g_Group); if (Arg *A = Args.getLastArg(options::OPT_g_Group)) { if (A->getOption().matches(options::OPT_gline_tables_only) || A->getOption().matches(options::OPT_g1)) { // FIXME: we should support specifying dwarf version with // -gline-tables-only. CmdArgs.push_back("-gline-tables-only"); // Default is dwarf-2 for Darwin, OpenBSD, FreeBSD and Solaris. const llvm::Triple &Triple = getToolChain().getTriple(); if (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::OpenBSD || Triple.getOS() == llvm::Triple::FreeBSD || Triple.getOS() == llvm::Triple::Solaris) CmdArgs.push_back("-gdwarf-2"); } else if (A->getOption().matches(options::OPT_gdwarf_2)) CmdArgs.push_back("-gdwarf-2"); else if (A->getOption().matches(options::OPT_gdwarf_3)) CmdArgs.push_back("-gdwarf-3"); else if (A->getOption().matches(options::OPT_gdwarf_4)) CmdArgs.push_back("-gdwarf-4"); else if (!A->getOption().matches(options::OPT_g0) && !A->getOption().matches(options::OPT_ggdb0)) { // Default is dwarf-2 for Darwin, OpenBSD, FreeBSD and Solaris. const llvm::Triple &Triple = getToolChain().getTriple(); if (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::OpenBSD || Triple.getOS() == llvm::Triple::FreeBSD || Triple.getOS() == llvm::Triple::Solaris) CmdArgs.push_back("-gdwarf-2"); else CmdArgs.push_back("-g"); } } // We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now. Args.ClaimAllArgs(options::OPT_g_flags_Group); if (Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info, /*Default*/ true)) CmdArgs.push_back("-dwarf-column-info"); // FIXME: Move backend command line options to the module. // -gsplit-dwarf should turn on -g and enable the backend dwarf // splitting and extraction. // FIXME: Currently only works on Linux. if (getToolChain().getTriple().isOSLinux() && Args.hasArg(options::OPT_gsplit_dwarf)) { CmdArgs.push_back("-g"); CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-split-dwarf=Enable"); } // -ggnu-pubnames turns on gnu style pubnames in the backend. if (Args.hasArg(options::OPT_ggnu_pubnames)) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-generate-gnu-dwarf-pub-sections"); } // -gdwarf-aranges turns on the emission of the aranges section in the // backend. if (Args.hasArg(options::OPT_gdwarf_aranges)) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-generate-arange-section"); } if (Args.hasFlag(options::OPT_fdebug_types_section, options::OPT_fno_debug_types_section, false)) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-generate-type-units"); } // CloudABI uses -ffunction-sections and -fdata-sections by default. bool UseSeparateSections = Triple.getOS() == llvm::Triple::CloudABI; if (Args.hasFlag(options::OPT_ffunction_sections, options::OPT_fno_function_sections, UseSeparateSections)) { CmdArgs.push_back("-ffunction-sections"); } if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections, UseSeparateSections)) { CmdArgs.push_back("-fdata-sections"); } if (!Args.hasFlag(options::OPT_funique_section_names, options::OPT_fno_unique_section_names, true)) CmdArgs.push_back("-fno-unique-section-names"); Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs); // Pass options for controlling the default header search paths. if (Args.hasArg(options::OPT_nostdinc)) { CmdArgs.push_back("-nostdsysteminc"); CmdArgs.push_back("-nobuiltininc"); } else { if (Args.hasArg(options::OPT_nostdlibinc)) CmdArgs.push_back("-nostdsysteminc"); Args.AddLastArg(CmdArgs, options::OPT_nostdincxx); Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc); } // Pass the path to compiler resource files. CmdArgs.push_back("-resource-dir"); CmdArgs.push_back(D.ResourceDir.c_str()); Args.AddLastArg(CmdArgs, options::OPT_working_directory); bool ARCMTEnabled = false; if (!Args.hasArg(options::OPT_fno_objc_arc, options::OPT_fobjc_arc)) { if (const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check, options::OPT_ccc_arcmt_modify, options::OPT_ccc_arcmt_migrate)) { ARCMTEnabled = true; switch (A->getOption().getID()) { default: llvm_unreachable("missed a case"); case options::OPT_ccc_arcmt_check: CmdArgs.push_back("-arcmt-check"); break; case options::OPT_ccc_arcmt_modify: CmdArgs.push_back("-arcmt-modify"); break; case options::OPT_ccc_arcmt_migrate: CmdArgs.push_back("-arcmt-migrate"); CmdArgs.push_back("-mt-migrate-directory"); CmdArgs.push_back(A->getValue()); Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output); Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors); break; } } } else { Args.ClaimAllArgs(options::OPT_ccc_arcmt_check); Args.ClaimAllArgs(options::OPT_ccc_arcmt_modify); Args.ClaimAllArgs(options::OPT_ccc_arcmt_migrate); } if (const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) { if (ARCMTEnabled) { D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "-ccc-arcmt-migrate"; } CmdArgs.push_back("-mt-migrate-directory"); CmdArgs.push_back(A->getValue()); if (!Args.hasArg(options::OPT_objcmt_migrate_literals, options::OPT_objcmt_migrate_subscripting, options::OPT_objcmt_migrate_property)) { // None specified, means enable them all. CmdArgs.push_back("-objcmt-migrate-literals"); CmdArgs.push_back("-objcmt-migrate-subscripting"); CmdArgs.push_back("-objcmt-migrate-property"); } else { Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property); } } else { Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_all); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readonly_property); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readwrite_property); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property_dot_syntax); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_annotation); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_instancetype); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_nsmacros); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_protocol_conformance); Args.AddLastArg(CmdArgs, options::OPT_objcmt_atomic_property); Args.AddLastArg(CmdArgs, options::OPT_objcmt_returns_innerpointer_property); Args.AddLastArg(CmdArgs, options::OPT_objcmt_ns_nonatomic_iosonly); Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_designated_init); Args.AddLastArg(CmdArgs, options::OPT_objcmt_whitelist_dir_path); } // Add preprocessing options like -I, -D, etc. if we are using the // preprocessor. // // FIXME: Support -fpreprocessed if (types::getPreprocessedType(InputType) != types::TY_INVALID) AddPreprocessingOptions(C, JA, D, Args, CmdArgs, Output, Inputs); // Don't warn about "clang -c -DPIC -fPIC test.i" because libtool.m4 assumes // that "The compiler can only warn and ignore the option if not recognized". // When building with ccache, it will pass -D options to clang even on // preprocessed inputs and configure concludes that -fPIC is not supported. Args.ClaimAllArgs(options::OPT_D); Args.AddLastArg(CmdArgs, options::OPT_hlsl_version); // HLSL Change - add the HLSL version argument // Manually translate -O4 to -O3; let clang reject others. if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { if (A->getOption().matches(options::OPT_O4)) { CmdArgs.push_back("-O3"); D.Diag(diag::warn_O4_is_O3); } else { A->render(Args, CmdArgs); } } // Warn about ignored options to clang. for (const Arg *A : Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) { D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args); } claimNoWarnArgs(Args); Args.AddAllArgs(CmdArgs, options::OPT_R_Group); Args.AddAllArgs(CmdArgs, options::OPT_W_Group); if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic, false)) CmdArgs.push_back("-pedantic"); Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors); Args.AddLastArg(CmdArgs, options::OPT_w); // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} // (-ansi is equivalent to -std=c89 or -std=c++98). // // If a std is supplied, only add -trigraphs if it follows the // option. bool ImplyVCPPCXXVer = false; if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { if (Std->getOption().matches(options::OPT_ansi)) if (types::isCXX(InputType)) CmdArgs.push_back("-std=c++98"); else CmdArgs.push_back("-std=c89"); else Std->render(Args, CmdArgs); // If -f(no-)trigraphs appears after the language standard flag, honor it. if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi, options::OPT_ftrigraphs, options::OPT_fno_trigraphs)) if (A != Std) A->render(Args, CmdArgs); } else { // Honor -std-default. // // FIXME: Clang doesn't correctly handle -std= when the input language // doesn't match. For the time being just ignore this for C++ inputs; // eventually we want to do all the standard defaulting here instead of // splitting it between the driver and clang -cc1. if (!types::isCXX(InputType)) Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, "-std=", /*Joined=*/true); else if (IsWindowsMSVC) ImplyVCPPCXXVer = true; Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs, options::OPT_fno_trigraphs); } // GCC's behavior for -Wwrite-strings is a bit strange: // * In C, this "warning flag" changes the types of string literals from // 'char[N]' to 'const char[N]', and thus triggers an unrelated warning // for the discarded qualifier. // * In C++, this is just a normal warning flag. // // Implementing this warning correctly in C is hard, so we follow GCC's // behavior for now. FIXME: Directly diagnose uses of a string literal as // a non-const char* in C, rather than using this crude hack. if (!types::isCXX(InputType)) { // FIXME: This should behave just like a warning flag, and thus should also // respect -Weverything, -Wno-everything, -Werror=write-strings, and so on. Arg *WriteStrings = Args.getLastArg(options::OPT_Wwrite_strings, options::OPT_Wno_write_strings, options::OPT_w); if (WriteStrings && WriteStrings->getOption().matches(options::OPT_Wwrite_strings)) CmdArgs.push_back("-fconst-strings"); } // GCC provides a macro definition '__DEPRECATED' when -Wdeprecated is active // during C++ compilation, which it is by default. GCC keeps this define even // in the presence of '-w', match this behavior bug-for-bug. if (types::isCXX(InputType) && Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated, true)) { CmdArgs.push_back("-fdeprecated-macro"); } // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'. if (Arg *Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) { if (Asm->getOption().matches(options::OPT_fasm)) CmdArgs.push_back("-fgnu-keywords"); else CmdArgs.push_back("-fno-gnu-keywords"); } if (ShouldDisableDwarfDirectory(Args, getToolChain())) CmdArgs.push_back("-fno-dwarf-directory-asm"); if (ShouldDisableAutolink(Args, getToolChain())) CmdArgs.push_back("-fno-autolink"); // Add in -fdebug-compilation-dir if necessary. addDebugCompDirArg(Args, CmdArgs); if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_, options::OPT_ftemplate_depth_EQ)) { CmdArgs.push_back("-ftemplate-depth"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_foperator_arrow_depth_EQ)) { CmdArgs.push_back("-foperator-arrow-depth"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_depth_EQ)) { CmdArgs.push_back("-fconstexpr-depth"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_steps_EQ)) { CmdArgs.push_back("-fconstexpr-steps"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_fbracket_depth_EQ)) { CmdArgs.push_back("-fbracket-depth"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ, options::OPT_Wlarge_by_value_copy_def)) { if (A->getNumValues()) { StringRef bytes = A->getValue(); CmdArgs.push_back(Args.MakeArgString("-Wlarge-by-value-copy=" + bytes)); } else CmdArgs.push_back("-Wlarge-by-value-copy=64"); // default value } if (Args.hasArg(options::OPT_relocatable_pch)) CmdArgs.push_back("-relocatable-pch"); if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) { CmdArgs.push_back("-fconstant-string-class"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) { CmdArgs.push_back("-ftabstop"); CmdArgs.push_back(A->getValue()); } CmdArgs.push_back("-ferror-limit"); if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ)) CmdArgs.push_back(A->getValue()); else CmdArgs.push_back("19"); if (Arg *A = Args.getLastArg(options::OPT_fmacro_backtrace_limit_EQ)) { CmdArgs.push_back("-fmacro-backtrace-limit"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ)) { CmdArgs.push_back("-ftemplate-backtrace-limit"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_backtrace_limit_EQ)) { CmdArgs.push_back("-fconstexpr-backtrace-limit"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg(options::OPT_fspell_checking_limit_EQ)) { CmdArgs.push_back("-fspell-checking-limit"); CmdArgs.push_back(A->getValue()); } // Pass -fmessage-length=. CmdArgs.push_back("-fmessage-length"); if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) { CmdArgs.push_back(A->getValue()); } else { // If -fmessage-length=N was not specified, determine whether this is a // terminal and, if so, implicitly define -fmessage-length appropriately. unsigned N = llvm::sys::Process::StandardErrColumns(); CmdArgs.push_back(Args.MakeArgString(Twine(N))); } // -fvisibility= and -fvisibility-ms-compat are of a piece. if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ, options::OPT_fvisibility_ms_compat)) { if (A->getOption().matches(options::OPT_fvisibility_EQ)) { CmdArgs.push_back("-fvisibility"); CmdArgs.push_back(A->getValue()); } else { assert(A->getOption().matches(options::OPT_fvisibility_ms_compat)); CmdArgs.push_back("-fvisibility"); CmdArgs.push_back("hidden"); CmdArgs.push_back("-ftype-visibility"); CmdArgs.push_back("default"); } } Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden); Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ); // -fhosted is default. if (Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted, false) || KernelOrKext) CmdArgs.push_back("-ffreestanding"); // Forward -f (flag) options which we can pass directly. Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); Args.AddLastArg(CmdArgs, options::OPT_fstandalone_debug); Args.AddLastArg(CmdArgs, options::OPT_fno_standalone_debug); Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); // AltiVec-like language extensions aren't relevant for assembling. if (!isa<PreprocessJobAction>(JA) || Output.getType() != types::TY_PP_Asm) { Args.AddLastArg(CmdArgs, options::OPT_faltivec); Args.AddLastArg(CmdArgs, options::OPT_fzvector); } Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree); Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type); // Forward flags for OpenMP if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, options::OPT_fno_openmp, false)) switch (getOpenMPRuntime(getToolChain(), Args)) { case OMPRT_OMP: case OMPRT_IOMP5: // Clang can generate useful OpenMP code for these two runtime libraries. CmdArgs.push_back("-fopenmp"); // If no option regarding the use of TLS in OpenMP codegeneration is // given, decide a default based on the target. Otherwise rely on the // options and pass the right information to the frontend. if (!Args.hasFlag(options::OPT_fopenmp_use_tls, options::OPT_fnoopenmp_use_tls, getToolChain().getArch() == llvm::Triple::ppc || getToolChain().getArch() == llvm::Triple::ppc64 || getToolChain().getArch() == llvm::Triple::ppc64le)) CmdArgs.push_back("-fnoopenmp-use-tls"); break; default: // By default, if Clang doesn't know how to generate useful OpenMP code // for a specific runtime library, we just don't pass the '-fopenmp' flag // down to the actual compilation. // FIXME: It would be better to have a mode which *only* omits IR // generation based on the OpenMP support so that we get consistent // semantic analysis, etc. break; } const SanitizerArgs &Sanitize = getToolChain().getSanitizerArgs(); Sanitize.addArgs(getToolChain(), Args, CmdArgs, InputType); // Report an error for -faltivec on anything other than PowerPC. if (const Arg *A = Args.getLastArg(options::OPT_faltivec)) { const llvm::Triple::ArchType Arch = getToolChain().getArch(); if (!(Arch == llvm::Triple::ppc || Arch == llvm::Triple::ppc64 || Arch == llvm::Triple::ppc64le)) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "ppc/ppc64/ppc64le"; } // -fzvector is incompatible with -faltivec. if (Arg *A = Args.getLastArg(options::OPT_fzvector)) if (Args.hasArg(options::OPT_faltivec)) D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "-faltivec"; if (getToolChain().SupportsProfiling()) Args.AddLastArg(CmdArgs, options::OPT_pg); // -flax-vector-conversions is default. if (!Args.hasFlag(options::OPT_flax_vector_conversions, options::OPT_fno_lax_vector_conversions)) CmdArgs.push_back("-fno-lax-vector-conversions"); if (Args.getLastArg(options::OPT_fapple_kext)) CmdArgs.push_back("-fapple-kext"); Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch); Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info); Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits); Args.AddLastArg(CmdArgs, options::OPT_ftime_report); Args.AddLastArg(CmdArgs, options::OPT_ftime_trace); // HLSL Change Args.AddLastArg(CmdArgs, options::OPT_ftrapv); if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) { CmdArgs.push_back("-ftrapv-handler"); CmdArgs.push_back(A->getValue()); } Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ); // -fno-strict-overflow implies -fwrapv if it isn't disabled, but // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) { if (A->getOption().matches(options::OPT_fwrapv)) CmdArgs.push_back("-fwrapv"); } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow, options::OPT_fno_strict_overflow)) { if (A->getOption().matches(options::OPT_fno_strict_overflow)) CmdArgs.push_back("-fwrapv"); } if (Arg *A = Args.getLastArg(options::OPT_freroll_loops, options::OPT_fno_reroll_loops)) if (A->getOption().matches(options::OPT_freroll_loops)) CmdArgs.push_back("-freroll-loops"); Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); Args.AddLastArg(CmdArgs, options::OPT_funroll_loops, options::OPT_fno_unroll_loops); Args.AddLastArg(CmdArgs, options::OPT_pthread); // -stack-protector=0 is default. unsigned StackProtectorLevel = 0; if (getToolChain().getSanitizerArgs().needsSafeStackRt()) { Args.ClaimAllArgs(options::OPT_fno_stack_protector); Args.ClaimAllArgs(options::OPT_fstack_protector_all); Args.ClaimAllArgs(options::OPT_fstack_protector_strong); Args.ClaimAllArgs(options::OPT_fstack_protector); } else if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, options::OPT_fstack_protector_all, options::OPT_fstack_protector_strong, options::OPT_fstack_protector)) { if (A->getOption().matches(options::OPT_fstack_protector)) { StackProtectorLevel = std::max<unsigned>( LangOptions::SSPOn, getToolChain().GetDefaultStackProtectorLevel(KernelOrKext)); } else if (A->getOption().matches(options::OPT_fstack_protector_strong)) StackProtectorLevel = LangOptions::SSPStrong; else if (A->getOption().matches(options::OPT_fstack_protector_all)) StackProtectorLevel = LangOptions::SSPReq; } else { StackProtectorLevel = getToolChain().GetDefaultStackProtectorLevel(KernelOrKext); } if (StackProtectorLevel) { CmdArgs.push_back("-stack-protector"); CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel))); } // --param ssp-buffer-size= for (const Arg *A : Args.filtered(options::OPT__param)) { StringRef Str(A->getValue()); if (Str.startswith("ssp-buffer-size=")) { if (StackProtectorLevel) { CmdArgs.push_back("-stack-protector-buffer-size"); // FIXME: Verify the argument is a valid integer. CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16))); } A->claim(); } } // Translate -mstackrealign if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign, false)) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-force-align-stack"); } if (!Args.hasFlag(options::OPT_mno_stackrealign, options::OPT_mstackrealign, false)) { CmdArgs.push_back(Args.MakeArgString("-mstackrealign")); } if (Args.hasArg(options::OPT_mstack_alignment)) { StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment); CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment)); } if (Args.hasArg(options::OPT_mstack_probe_size)) { StringRef Size = Args.getLastArgValue(options::OPT_mstack_probe_size); if (!Size.empty()) CmdArgs.push_back(Args.MakeArgString("-mstack-probe-size=" + Size)); else CmdArgs.push_back("-mstack-probe-size=0"); } if (getToolChain().getArch() == llvm::Triple::aarch64 || getToolChain().getArch() == llvm::Triple::aarch64_be) CmdArgs.push_back("-fallow-half-arguments-and-returns"); if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it, options::OPT_mno_restrict_it)) { if (A->getOption().matches(options::OPT_mrestrict_it)) { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-arm-restrict-it"); } else { CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-arm-no-restrict-it"); } } else if (TT.isOSWindows() && (TT.getArch() == llvm::Triple::arm || TT.getArch() == llvm::Triple::thumb)) { // Windows on ARM expects restricted IT blocks CmdArgs.push_back("-backend-option"); CmdArgs.push_back("-arm-restrict-it"); } // Forward -f options with positive and negative forms; we translate // these by hand. if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) { StringRef fname = A->getValue(); if (!llvm::sys::fs::exists(fname)) D.Diag(diag::err_drv_no_such_file) << fname; else A->render(Args, CmdArgs); } if (Args.hasArg(options::OPT_mkernel)) { if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType)) CmdArgs.push_back("-fapple-kext"); if (!Args.hasArg(options::OPT_fbuiltin)) CmdArgs.push_back("-fno-builtin"); Args.ClaimAllArgs(options::OPT_fno_builtin); } // -fbuiltin is default. else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin)) CmdArgs.push_back("-fno-builtin"); if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, options::OPT_fno_assume_sane_operator_new)) CmdArgs.push_back("-fno-assume-sane-operator-new"); // -fblocks=0 is default. if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks, getToolChain().IsBlocksDefault()) || (Args.hasArg(options::OPT_fgnu_runtime) && Args.hasArg(options::OPT_fobjc_nonfragile_abi) && !Args.hasArg(options::OPT_fno_blocks))) { CmdArgs.push_back("-fblocks"); if (!Args.hasArg(options::OPT_fgnu_runtime) && !getToolChain().hasBlocksRuntime()) CmdArgs.push_back("-fblocks-runtime-optional"); } // -fmodules enables the use of precompiled modules (off by default). // Users can pass -fno-cxx-modules to turn off modules support for // C++/Objective-C++ programs. bool HaveModules = false; if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) { bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules, true); if (AllowedInCXX || !types::isCXX(InputType)) { CmdArgs.push_back("-fmodules"); HaveModules = true; } } // -fmodule-maps enables implicit reading of module map files. By default, // this is enabled if we are using precompiled modules. if (Args.hasFlag(options::OPT_fimplicit_module_maps, options::OPT_fno_implicit_module_maps, HaveModules)) { CmdArgs.push_back("-fimplicit-module-maps"); } // -fmodules-decluse checks that modules used are declared so (off by // default). if (Args.hasFlag(options::OPT_fmodules_decluse, options::OPT_fno_modules_decluse, false)) { CmdArgs.push_back("-fmodules-decluse"); } // -fmodules-strict-decluse is like -fmodule-decluse, but also checks that // all #included headers are part of modules. if (Args.hasFlag(options::OPT_fmodules_strict_decluse, options::OPT_fno_modules_strict_decluse, false)) { CmdArgs.push_back("-fmodules-strict-decluse"); } // -fno-implicit-modules turns off implicitly compiling modules on demand. if (!Args.hasFlag(options::OPT_fimplicit_modules, options::OPT_fno_implicit_modules)) { CmdArgs.push_back("-fno-implicit-modules"); } // -fmodule-name specifies the module that is currently being built (or // used for header checking by -fmodule-maps). Args.AddLastArg(CmdArgs, options::OPT_fmodule_name); // -fmodule-map-file can be used to specify files containing module // definitions. Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file); // -fmodule-file can be used to specify files containing precompiled modules. Args.AddAllArgs(CmdArgs, options::OPT_fmodule_file); // -fmodule-cache-path specifies where our implicitly-built module files // should be written. SmallString<128> Path; if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path)) Path = A->getValue(); if (HaveModules) { if (C.isForDiagnostics()) { // When generating crash reports, we want to emit the modules along with // the reproduction sources, so we ignore any provided module path. Path = Output.getFilename(); llvm::sys::path::replace_extension(Path, ".cache"); llvm::sys::path::append(Path, "modules"); } else if (Path.empty()) { // No module path was provided: use the default. llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false, Path); llvm::sys::path::append(Path, "org.llvm.clang."); appendUserToPath(Path); llvm::sys::path::append(Path, "ModuleCache"); } const char Arg[] = "-fmodules-cache-path="; Path.insert(Path.begin(), Arg, Arg + strlen(Arg)); CmdArgs.push_back(Args.MakeArgString(Path)); } // When building modules and generating crashdumps, we need to dump a module // dependency VFS alongside the output. if (HaveModules && C.isForDiagnostics()) { SmallString<128> VFSDir(Output.getFilename()); llvm::sys::path::replace_extension(VFSDir, ".cache"); // Add the cache directory as a temp so the crash diagnostics pick it up. C.addTempFile(Args.MakeArgString(VFSDir)); llvm::sys::path::append(VFSDir, "vfs"); CmdArgs.push_back("-module-dependency-dir"); CmdArgs.push_back(Args.MakeArgString(VFSDir)); } if (HaveModules) Args.AddLastArg(CmdArgs, options::OPT_fmodules_user_build_path); // Pass through all -fmodules-ignore-macro arguments. Args.AddAllArgs(CmdArgs, options::OPT_fmodules_ignore_macro); Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval); Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after); Args.AddLastArg(CmdArgs, options::OPT_fbuild_session_timestamp); if (Arg *A = Args.getLastArg(options::OPT_fbuild_session_file)) { if (Args.hasArg(options::OPT_fbuild_session_timestamp)) D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "-fbuild-session-timestamp"; llvm::sys::fs::file_status Status; if (llvm::sys::fs::status(A->getValue(), Status)) D.Diag(diag::err_drv_no_such_file) << A->getValue(); CmdArgs.push_back(Args.MakeArgString( "-fbuild-session-timestamp=" + Twine((uint64_t)Status.getLastModificationTime().toEpochTime()))); } if (Args.getLastArg(options::OPT_fmodules_validate_once_per_build_session)) { if (!Args.getLastArg(options::OPT_fbuild_session_timestamp, options::OPT_fbuild_session_file)) D.Diag(diag::err_drv_modules_validate_once_requires_timestamp); Args.AddLastArg(CmdArgs, options::OPT_fmodules_validate_once_per_build_session); } Args.AddLastArg(CmdArgs, options::OPT_fmodules_validate_system_headers); // -faccess-control is default. if (Args.hasFlag(options::OPT_fno_access_control, options::OPT_faccess_control, false)) CmdArgs.push_back("-fno-access-control"); // -felide-constructors is the default. if (Args.hasFlag(options::OPT_fno_elide_constructors, options::OPT_felide_constructors, false)) CmdArgs.push_back("-fno-elide-constructors"); ToolChain::RTTIMode RTTIMode = getToolChain().getRTTIMode(); if (KernelOrKext || (types::isCXX(InputType) && (RTTIMode == ToolChain::RM_DisabledExplicitly || RTTIMode == ToolChain::RM_DisabledImplicitly))) CmdArgs.push_back("-fno-rtti"); // -fshort-enums=0 is default for all architectures except Hexagon. if (Args.hasFlag(options::OPT_fshort_enums, options::OPT_fno_short_enums, getToolChain().getArch() == llvm::Triple::hexagon)) CmdArgs.push_back("-fshort-enums"); // -fsigned-char is default. if (Arg *A = Args.getLastArg( options::OPT_fsigned_char, options::OPT_fno_signed_char, options::OPT_funsigned_char, options::OPT_fno_unsigned_char)) { if (A->getOption().matches(options::OPT_funsigned_char) || A->getOption().matches(options::OPT_fno_signed_char)) { CmdArgs.push_back("-fno-signed-char"); } } else if (!isSignedCharDefault(getToolChain().getTriple())) { CmdArgs.push_back("-fno-signed-char"); } // -fuse-cxa-atexit is default. if (!Args.hasFlag(options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit, !IsWindowsCygnus && !IsWindowsGNU && getToolChain().getArch() != llvm::Triple::hexagon && getToolChain().getArch() != llvm::Triple::xcore) || KernelOrKext) CmdArgs.push_back("-fno-use-cxa-atexit"); // -fms-extensions=0 is default. if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, IsWindowsMSVC)) CmdArgs.push_back("-fms-extensions"); // -fno-use-line-directives is default. if (Args.hasFlag(options::OPT_fuse_line_directives, options::OPT_fno_use_line_directives, false)) CmdArgs.push_back("-fuse-line-directives"); // -fms-compatibility=0 is default. if (Args.hasFlag(options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility, (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, true)))) CmdArgs.push_back("-fms-compatibility"); // -fms-compatibility-version=18.00 is default. VersionTuple MSVT = visualstudio::getMSVCVersion( &D, getToolChain().getTriple(), Args, IsWindowsMSVC); if (!MSVT.empty()) CmdArgs.push_back( Args.MakeArgString("-fms-compatibility-version=" + MSVT.getAsString())); bool IsMSVC2015Compatible = MSVT.getMajor() >= 19; if (ImplyVCPPCXXVer) { if (IsMSVC2015Compatible) CmdArgs.push_back("-std=c++14"); else CmdArgs.push_back("-std=c++11"); } // -fno-borland-extensions is default. if (Args.hasFlag(options::OPT_fborland_extensions, options::OPT_fno_borland_extensions, false)) CmdArgs.push_back("-fborland-extensions"); // -fthreadsafe-static is default, except for MSVC compatibility versions less // than 19. if (!Args.hasFlag(options::OPT_fthreadsafe_statics, options::OPT_fno_threadsafe_statics, !IsWindowsMSVC || IsMSVC2015Compatible)) CmdArgs.push_back("-fno-threadsafe-statics"); // -fno-delayed-template-parsing is default, except for Windows where MSVC STL // needs it. if (Args.hasFlag(options::OPT_fdelayed_template_parsing, options::OPT_fno_delayed_template_parsing, IsWindowsMSVC)) CmdArgs.push_back("-fdelayed-template-parsing"); // -fgnu-keywords default varies depending on language; only pass if // specified. if (Arg *A = Args.getLastArg(options::OPT_fgnu_keywords, options::OPT_fno_gnu_keywords)) A->render(Args, CmdArgs); if (Args.hasFlag(options::OPT_fgnu89_inline, options::OPT_fno_gnu89_inline, false)) CmdArgs.push_back("-fgnu89-inline"); if (Args.hasArg(options::OPT_fno_inline)) CmdArgs.push_back("-fno-inline"); if (Args.hasArg(options::OPT_fno_inline_functions)) CmdArgs.push_back("-fno-inline-functions"); ObjCRuntime objcRuntime = AddObjCRuntimeArgs(Args, CmdArgs, rewriteKind); // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and // legacy is the default. Except for deployment taget of 10.5, // next runtime is always legacy dispatch and -fno-objc-legacy-dispatch // gets ignored silently. if (objcRuntime.isNonFragile()) { if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch, options::OPT_fno_objc_legacy_dispatch, objcRuntime.isLegacyDispatchDefaultForArch( getToolChain().getArch()))) { if (getToolChain().UseObjCMixedDispatch()) CmdArgs.push_back("-fobjc-dispatch-method=mixed"); else CmdArgs.push_back("-fobjc-dispatch-method=non-legacy"); } } // When ObjectiveC legacy runtime is in effect on MacOSX, // turn on the option to do Array/Dictionary subscripting // by default. if (getToolChain().getArch() == llvm::Triple::x86 && getToolChain().getTriple().isMacOSX() && !getToolChain().getTriple().isMacOSXVersionLT(10, 7) && objcRuntime.getKind() == ObjCRuntime::FragileMacOSX && objcRuntime.isNeXTFamily()) CmdArgs.push_back("-fobjc-subscripting-legacy-runtime"); // -fencode-extended-block-signature=1 is default. if (getToolChain().IsEncodeExtendedBlockSignatureDefault()) { CmdArgs.push_back("-fencode-extended-block-signature"); } // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc. // NOTE: This logic is duplicated in ToolChains.cpp. bool ARC = isObjCAutoRefCount(Args); if (ARC) { getToolChain().CheckObjCARC(); CmdArgs.push_back("-fobjc-arc"); // FIXME: It seems like this entire block, and several around it should be // wrapped in isObjC, but for now we just use it here as this is where it // was being used previously. if (types::isCXX(InputType) && types::isObjC(InputType)) { if (getToolChain().GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) CmdArgs.push_back("-fobjc-arc-cxxlib=libc++"); else CmdArgs.push_back("-fobjc-arc-cxxlib=libstdc++"); } // Allow the user to enable full exceptions code emission. // We define off for Objective-CC, on for Objective-C++. if (Args.hasFlag(options::OPT_fobjc_arc_exceptions, options::OPT_fno_objc_arc_exceptions, /*default*/ types::isCXX(InputType))) CmdArgs.push_back("-fobjc-arc-exceptions"); } // -fobjc-infer-related-result-type is the default, except in the Objective-C // rewriter. if (rewriteKind != RK_None) CmdArgs.push_back("-fno-objc-infer-related-result-type"); // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only // takes precedence. const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); if (!GCArg) GCArg = Args.getLastArg(options::OPT_fobjc_gc); if (GCArg) { if (ARC) { D.Diag(diag::err_drv_objc_gc_arr) << GCArg->getAsString(Args); } else if (getToolChain().SupportsObjCGC()) { GCArg->render(Args, CmdArgs); } else { // FIXME: We should move this to a hard error. D.Diag(diag::warn_drv_objc_gc_unsupported) << GCArg->getAsString(Args); } } if (Args.hasFlag(options::OPT_fapplication_extension, options::OPT_fno_application_extension, false)) CmdArgs.push_back("-fapplication-extension"); // Handle GCC-style exception args. if (!C.getDriver().IsCLMode()) addExceptionArgs(Args, InputType, getToolChain(), KernelOrKext, objcRuntime, CmdArgs); if (getToolChain().UseSjLjExceptions()) CmdArgs.push_back("-fsjlj-exceptions"); // C++ "sane" operator new. if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, options::OPT_fno_assume_sane_operator_new)) CmdArgs.push_back("-fno-assume-sane-operator-new"); // -fsized-deallocation is off by default, as it is an ABI-breaking change for // most platforms. if (Args.hasFlag(options::OPT_fsized_deallocation, options::OPT_fno_sized_deallocation, false)) CmdArgs.push_back("-fsized-deallocation"); // -fconstant-cfstrings is default, and may be subject to argument translation // on Darwin. if (!Args.hasFlag(options::OPT_fconstant_cfstrings, options::OPT_fno_constant_cfstrings) || !Args.hasFlag(options::OPT_mconstant_cfstrings, options::OPT_mno_constant_cfstrings)) CmdArgs.push_back("-fno-constant-cfstrings"); // -fshort-wchar default varies depending on platform; only // pass if specified. if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar, options::OPT_fno_short_wchar)) A->render(Args, CmdArgs); // -fno-pascal-strings is default, only pass non-default. if (Args.hasFlag(options::OPT_fpascal_strings, options::OPT_fno_pascal_strings, false)) CmdArgs.push_back("-fpascal-strings"); // Honor -fpack-struct= and -fpack-struct, if given. Note that // -fno-pack-struct doesn't apply to -fpack-struct=. if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) { std::string PackStructStr = "-fpack-struct="; PackStructStr += A->getValue(); CmdArgs.push_back(Args.MakeArgString(PackStructStr)); } else if (Args.hasFlag(options::OPT_fpack_struct, options::OPT_fno_pack_struct, false)) { CmdArgs.push_back("-fpack-struct=1"); } // Handle -fmax-type-align=N and -fno-type-align bool SkipMaxTypeAlign = Args.hasArg(options::OPT_fno_max_type_align); if (Arg *A = Args.getLastArg(options::OPT_fmax_type_align_EQ)) { if (!SkipMaxTypeAlign) { std::string MaxTypeAlignStr = "-fmax-type-align="; MaxTypeAlignStr += A->getValue(); CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr)); } } else if (getToolChain().getTriple().isOSDarwin()) { if (!SkipMaxTypeAlign) { std::string MaxTypeAlignStr = "-fmax-type-align=16"; CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr)); } } if (KernelOrKext || isNoCommonDefault(getToolChain().getTriple())) { if (!Args.hasArg(options::OPT_fcommon)) CmdArgs.push_back("-fno-common"); Args.ClaimAllArgs(options::OPT_fno_common); } // -fcommon is default, only pass non-default. else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common)) CmdArgs.push_back("-fno-common"); // -fsigned-bitfields is default, and clang doesn't yet support // -funsigned-bitfields. if (!Args.hasFlag(options::OPT_fsigned_bitfields, options::OPT_funsigned_bitfields)) D.Diag(diag::warn_drv_clang_unsupported) << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args); // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope. if (!Args.hasFlag(options::OPT_ffor_scope, options::OPT_fno_for_scope)) D.Diag(diag::err_drv_clang_unsupported) << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args); // -finput_charset=UTF-8 is default. Reject others if (Arg *inputCharset = Args.getLastArg(options::OPT_finput_charset_EQ)) { StringRef value = inputCharset->getValue(); if (value != "UTF-8") D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args) << value; } // -fexec_charset=UTF-8 is default. Reject others if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ)) { StringRef value = execCharset->getValue(); if (value != "UTF-8") D.Diag(diag::err_drv_invalid_value) << execCharset->getAsString(Args) << value; } // -fcaret-diagnostics is default. if (!Args.hasFlag(options::OPT_fcaret_diagnostics, options::OPT_fno_caret_diagnostics, true)) CmdArgs.push_back("-fno-caret-diagnostics"); // -fdiagnostics-fixit-info is default, only pass non-default. if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info, options::OPT_fno_diagnostics_fixit_info)) CmdArgs.push_back("-fno-diagnostics-fixit-info"); // Enable -fdiagnostics-show-option by default. if (Args.hasFlag(options::OPT_fdiagnostics_show_option, options::OPT_fno_diagnostics_show_option)) CmdArgs.push_back("-fdiagnostics-show-option"); if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) { CmdArgs.push_back("-fdiagnostics-show-category"); CmdArgs.push_back(A->getValue()); } if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { CmdArgs.push_back("-fdiagnostics-format"); CmdArgs.push_back(A->getValue()); } if (Arg *A = Args.getLastArg( options::OPT_fdiagnostics_show_note_include_stack, options::OPT_fno_diagnostics_show_note_include_stack)) { if (A->getOption().matches( options::OPT_fdiagnostics_show_note_include_stack)) CmdArgs.push_back("-fdiagnostics-show-note-include-stack"); else CmdArgs.push_back("-fno-diagnostics-show-note-include-stack"); } // Color diagnostics are the default, unless the terminal doesn't support // them. // Support both clang's -f[no-]color-diagnostics and gcc's // -f[no-]diagnostics-colors[=never|always|auto]. enum { Colors_On, Colors_Off, Colors_Auto } ShowColors = Colors_Auto; for (const auto &Arg : Args) { const Option &O = Arg->getOption(); if (!O.matches(options::OPT_fcolor_diagnostics) && !O.matches(options::OPT_fdiagnostics_color) && !O.matches(options::OPT_fno_color_diagnostics) && !O.matches(options::OPT_fno_diagnostics_color) && !O.matches(options::OPT_fdiagnostics_color_EQ)) continue; Arg->claim(); if (O.matches(options::OPT_fcolor_diagnostics) || O.matches(options::OPT_fdiagnostics_color)) { ShowColors = Colors_On; } else if (O.matches(options::OPT_fno_color_diagnostics) || O.matches(options::OPT_fno_diagnostics_color)) { ShowColors = Colors_Off; } else { assert(O.matches(options::OPT_fdiagnostics_color_EQ)); StringRef value(Arg->getValue()); if (value == "always") ShowColors = Colors_On; else if (value == "never") ShowColors = Colors_Off; else if (value == "auto") ShowColors = Colors_Auto; else getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) << ("-fdiagnostics-color=" + value).str(); } } if (ShowColors == Colors_On || (ShowColors == Colors_Auto && llvm::sys::Process::StandardErrHasColors())) CmdArgs.push_back("-fcolor-diagnostics"); #ifdef MSFT_SUPPORTS_ANSI_ESCAPE_CODES if (Args.hasArg(options::OPT_fansi_escape_codes)) CmdArgs.push_back("-fansi-escape-codes"); #endif if (!Args.hasFlag(options::OPT_fshow_source_location, options::OPT_fno_show_source_location)) CmdArgs.push_back("-fno-show-source-location"); if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column, true)) CmdArgs.push_back("-fno-show-column"); if (!Args.hasFlag(options::OPT_fspell_checking, options::OPT_fno_spell_checking)) CmdArgs.push_back("-fno-spell-checking"); // -fno-asm-blocks is default. if (Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks, false)) CmdArgs.push_back("-fasm-blocks"); // -fgnu-inline-asm is default. if (!Args.hasFlag(options::OPT_fgnu_inline_asm, options::OPT_fno_gnu_inline_asm, true)) CmdArgs.push_back("-fno-gnu-inline-asm"); // Enable vectorization per default according to the optimization level // selected. For optimization levels that want vectorization we use the alias // option to simplify the hasFlag logic. bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false); OptSpecifier VectorizeAliasOption = EnableVec ? options::OPT_O_Group : options::OPT_fvectorize; if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption, options::OPT_fno_vectorize, EnableVec)) CmdArgs.push_back("-vectorize-loops"); // -fslp-vectorize is enabled based on the optimization level selected. bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true); OptSpecifier SLPVectAliasOption = EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize; if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption, options::OPT_fno_slp_vectorize, EnableSLPVec)) CmdArgs.push_back("-vectorize-slp"); // -fno-slp-vectorize-aggressive is default. if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive, options::OPT_fno_slp_vectorize_aggressive, false)) CmdArgs.push_back("-vectorize-slp-aggressive"); if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ)) A->render(Args, CmdArgs); // -fdollars-in-identifiers default varies depending on platform and // language; only pass if specified. if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers, options::OPT_fno_dollars_in_identifiers)) { if (A->getOption().matches(options::OPT_fdollars_in_identifiers)) CmdArgs.push_back("-fdollars-in-identifiers"); else CmdArgs.push_back("-fno-dollars-in-identifiers"); } // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for // practical purposes. if (Arg *A = Args.getLastArg(options::OPT_funit_at_a_time, options::OPT_fno_unit_at_a_time)) { if (A->getOption().matches(options::OPT_fno_unit_at_a_time)) D.Diag(diag::warn_drv_clang_unsupported) << A->getAsString(Args); } if (Args.hasFlag(options::OPT_fapple_pragma_pack, options::OPT_fno_apple_pragma_pack, false)) CmdArgs.push_back("-fapple-pragma-pack"); // le32-specific flags: // -fno-math-builtin: clang should not convert math builtins to intrinsics // by default. if (getToolChain().getArch() == llvm::Triple::le32) { CmdArgs.push_back("-fno-math-builtin"); } // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM. // // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941. #if 0 if (getToolChain().getTriple().isOSDarwin() && (getToolChain().getArch() == llvm::Triple::arm || getToolChain().getArch() == llvm::Triple::thumb)) { if (!Args.hasArg(options::OPT_fbuiltin_strcat)) CmdArgs.push_back("-fno-builtin-strcat"); if (!Args.hasArg(options::OPT_fbuiltin_strcpy)) CmdArgs.push_back("-fno-builtin-strcpy"); } #endif // Enable rewrite includes if the user's asked for it or if we're generating // diagnostics. // TODO: Once -module-dependency-dir works with -frewrite-includes it'd be // nice to enable this when doing a crashdump for modules as well. if (Args.hasFlag(options::OPT_frewrite_includes, options::OPT_fno_rewrite_includes, false) || (C.isForDiagnostics() && !HaveModules)) CmdArgs.push_back("-frewrite-includes"); // Only allow -traditional or -traditional-cpp outside in preprocessing modes. if (Arg *A = Args.getLastArg(options::OPT_traditional, options::OPT_traditional_cpp)) { if (isa<PreprocessJobAction>(JA)) CmdArgs.push_back("-traditional-cpp"); else D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); } Args.AddLastArg(CmdArgs, options::OPT_dM); Args.AddLastArg(CmdArgs, options::OPT_dD); // Handle serialized diagnostics. if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) { CmdArgs.push_back("-serialize-diagnostic-file"); CmdArgs.push_back(Args.MakeArgString(A->getValue())); } if (Args.hasArg(options::OPT_fretain_comments_from_system_headers)) CmdArgs.push_back("-fretain-comments-from-system-headers"); // Forward -fcomment-block-commands to -cc1. Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands); // Forward -fparse-all-comments to -cc1. Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments); // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option // parser. Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); bool OptDisabled = false; for (const Arg *A : Args.filtered(options::OPT_mllvm)) { A->claim(); // We translate this by hand to the -cc1 argument, since nightly test uses // it and developers have been trained to spell it with -mllvm. if (StringRef(A->getValue(0)) == "-disable-llvm-optzns") { CmdArgs.push_back("-disable-llvm-optzns"); OptDisabled = true; } else A->render(Args, CmdArgs); } // With -save-temps, we want to save the unoptimized bitcode output from the // CompileJobAction, so disable optimizations if they are not already // disabled. if (C.getDriver().isSaveTempsEnabled() && !OptDisabled && isa<CompileJobAction>(JA)) CmdArgs.push_back("-disable-llvm-optzns"); if (Output.getType() == types::TY_Dependencies) { // Handled with other dependency code. } else if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } addDashXForInput(Args, Input, CmdArgs); if (Input.isFilename()) CmdArgs.push_back(Input.getFilename()); else Input.getInputArg().renderAsInput(Args, CmdArgs); Args.AddAllArgs(CmdArgs, options::OPT_undef); const char *Exec = getToolChain().getDriver().getClangProgramPath(); // Optionally embed the -cc1 level arguments into the debug info, for build // analysis. if (getToolChain().UseDwarfDebugFlags()) { ArgStringList OriginalArgs; for (const auto &Arg : Args) Arg->render(Args, OriginalArgs); SmallString<256> Flags; Flags += Exec; for (const char *OriginalArg : OriginalArgs) { SmallString<128> EscapedArg; EscapeSpacesAndBackslashes(OriginalArg, EscapedArg); Flags += " "; Flags += EscapedArg; } CmdArgs.push_back("-dwarf-debug-flags"); CmdArgs.push_back(Args.MakeArgString(Flags)); } // Add the split debug info name to the command lines here so we // can propagate it to the backend. bool SplitDwarf = Args.hasArg(options::OPT_gsplit_dwarf) && getToolChain().getTriple().isOSLinux() && (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)); const char *SplitDwarfOut; if (SplitDwarf) { CmdArgs.push_back("-split-dwarf-file"); SplitDwarfOut = SplitDebugName(Args, Input); CmdArgs.push_back(SplitDwarfOut); } // Host-side cuda compilation receives device-side outputs as Inputs[1...]. // Include them with -fcuda-include-gpubinary. if (IsCuda && Inputs.size() > 1) for (InputInfoList::const_iterator it = std::next(Inputs.begin()), ie = Inputs.end(); it != ie; ++it) { CmdArgs.push_back("-fcuda-include-gpubinary"); CmdArgs.push_back(it->getFilename()); } // Finally add the compile command to the compilation. if (Args.hasArg(options::OPT__SLASH_fallback) && Output.getType() == types::TY_Object && (InputType == types::TY_C || InputType == types::TY_CXX)) { auto CLCommand = getCLFallback()->GetCommand(C, JA, Output, Inputs, Args, LinkingOutput); C.addCommand(llvm::make_unique<FallbackCommand>(JA, *this, Exec, CmdArgs, std::move(CLCommand))); } else { C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } // Handle the debug info splitting at object creation time if we're // creating an object. // TODO: Currently only works on linux with newer objcopy. if (SplitDwarf && !isa<CompileJobAction>(JA) && !isa<BackendJobAction>(JA)) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDwarfOut); if (Arg *A = Args.getLastArg(options::OPT_pg)) if (Args.hasArg(options::OPT_fomit_frame_pointer)) D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer" << A->getAsString(Args); // Claim some arguments which clang supports automatically. // -fpch-preprocess is used with gcc to add a special marker in the output to // include the PCH file. Clang's PTH solution is completely transparent, so we // do not need to deal with it at all. Args.ClaimAllArgs(options::OPT_fpch_preprocess); // Claim some arguments which clang doesn't support, but we don't // care to warn the user about. Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group); Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group); // Disable warnings for clang -E -emit-llvm foo.c Args.ClaimAllArgs(options::OPT_emit_llvm); } /// Add options related to the Objective-C runtime/ABI. /// /// Returns true if the runtime is non-fragile. ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args, ArgStringList &cmdArgs, RewriteKind rewriteKind) const { // Look for the controlling runtime option. Arg *runtimeArg = args.getLastArg(options::OPT_fnext_runtime, options::OPT_fgnu_runtime, options::OPT_fobjc_runtime_EQ); // Just forward -fobjc-runtime= to the frontend. This supercedes // options about fragility. if (runtimeArg && runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) { ObjCRuntime runtime; StringRef value = runtimeArg->getValue(); if (runtime.tryParse(value)) { getToolChain().getDriver().Diag(diag::err_drv_unknown_objc_runtime) << value; } runtimeArg->render(args, cmdArgs); return runtime; } // Otherwise, we'll need the ABI "version". Version numbers are // slightly confusing for historical reasons: // 1 - Traditional "fragile" ABI // 2 - Non-fragile ABI, version 1 // 3 - Non-fragile ABI, version 2 unsigned objcABIVersion = 1; // If -fobjc-abi-version= is present, use that to set the version. if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) { StringRef value = abiArg->getValue(); if (value == "1") objcABIVersion = 1; else if (value == "2") objcABIVersion = 2; else if (value == "3") objcABIVersion = 3; else getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) << value; } else { // Otherwise, determine if we are using the non-fragile ABI. bool nonFragileABIIsDefault = (rewriteKind == RK_NonFragile || (rewriteKind == RK_None && getToolChain().IsObjCNonFragileABIDefault())); if (args.hasFlag(options::OPT_fobjc_nonfragile_abi, options::OPT_fno_objc_nonfragile_abi, nonFragileABIIsDefault)) { // Determine the non-fragile ABI version to use. #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO unsigned nonFragileABIVersion = 1; #else unsigned nonFragileABIVersion = 2; #endif if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_nonfragile_abi_version_EQ)) { StringRef value = abiArg->getValue(); if (value == "1") nonFragileABIVersion = 1; else if (value == "2") nonFragileABIVersion = 2; else getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) << value; } objcABIVersion = 1 + nonFragileABIVersion; } else { objcABIVersion = 1; } } // We don't actually care about the ABI version other than whether // it's non-fragile. bool isNonFragile = objcABIVersion != 1; // If we have no runtime argument, ask the toolchain for its default runtime. // However, the rewriter only really supports the Mac runtime, so assume that. ObjCRuntime runtime; if (!runtimeArg) { switch (rewriteKind) { case RK_None: runtime = getToolChain().getDefaultObjCRuntime(isNonFragile); break; case RK_Fragile: runtime = ObjCRuntime(ObjCRuntime::FragileMacOSX, VersionTuple()); break; case RK_NonFragile: runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple()); break; } // -fnext-runtime } else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) { // On Darwin, make this use the default behavior for the toolchain. if (getToolChain().getTriple().isOSDarwin()) { runtime = getToolChain().getDefaultObjCRuntime(isNonFragile); // Otherwise, build for a generic macosx port. } else { runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple()); } // -fgnu-runtime } else { assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime)); // Legacy behaviour is to target the gnustep runtime if we are i // non-fragile mode or the GCC runtime in fragile mode. if (isNonFragile) runtime = ObjCRuntime(ObjCRuntime::GNUstep, VersionTuple(1, 6)); else runtime = ObjCRuntime(ObjCRuntime::GCC, VersionTuple()); } cmdArgs.push_back( args.MakeArgString("-fobjc-runtime=" + runtime.getAsString())); return runtime; } static bool maybeConsumeDash(const std::string &EH, size_t &I) { bool HaveDash = (I + 1 < EH.size() && EH[I + 1] == '-'); I += HaveDash; return !HaveDash; } struct EHFlags { EHFlags() : Synch(false), Asynch(false), NoExceptC(false) {} bool Synch; bool Asynch; bool NoExceptC; }; /// /EH controls whether to run destructor cleanups when exceptions are /// thrown. There are three modifiers: /// - s: Cleanup after "synchronous" exceptions, aka C++ exceptions. /// - a: Cleanup after "asynchronous" exceptions, aka structured exceptions. /// The 'a' modifier is unimplemented and fundamentally hard in LLVM IR. /// - c: Assume that extern "C" functions are implicitly noexcept. This /// modifier is an optimization, so we ignore it for now. /// The default is /EHs-c-, meaning cleanups are disabled. static EHFlags parseClangCLEHFlags(const Driver &D, const ArgList &Args) { EHFlags EH; std::vector<std::string> EHArgs = Args.getAllArgValues(options::OPT__SLASH_EH); for (auto EHVal : EHArgs) { for (size_t I = 0, E = EHVal.size(); I != E; ++I) { switch (EHVal[I]) { case 'a': EH.Asynch = maybeConsumeDash(EHVal, I); continue; case 'c': EH.NoExceptC = maybeConsumeDash(EHVal, I); continue; case 's': EH.Synch = maybeConsumeDash(EHVal, I); continue; default: break; } D.Diag(clang::diag::err_drv_invalid_value) << "/EH" << EHVal; break; } } // FIXME: Disable C++ EH completely, until it becomes more reliable. Users // can use -Xclang to manually enable C++ EH until then. EH = EHFlags(); return EH; } void Clang::AddClangCLArgs(const ArgList &Args, ArgStringList &CmdArgs) const { unsigned RTOptionID = options::OPT__SLASH_MT; if (Args.hasArg(options::OPT__SLASH_LDd)) // The /LDd option implies /MTd. The dependent lib part can be overridden, // but defining _DEBUG is sticky. RTOptionID = options::OPT__SLASH_MTd; if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group)) RTOptionID = A->getOption().getID(); switch (RTOptionID) { case options::OPT__SLASH_MD: if (Args.hasArg(options::OPT__SLASH_LDd)) CmdArgs.push_back("-D_DEBUG"); CmdArgs.push_back("-D_MT"); CmdArgs.push_back("-D_DLL"); CmdArgs.push_back("--dependent-lib=msvcrt"); break; case options::OPT__SLASH_MDd: CmdArgs.push_back("-D_DEBUG"); CmdArgs.push_back("-D_MT"); CmdArgs.push_back("-D_DLL"); CmdArgs.push_back("--dependent-lib=msvcrtd"); break; case options::OPT__SLASH_MT: if (Args.hasArg(options::OPT__SLASH_LDd)) CmdArgs.push_back("-D_DEBUG"); CmdArgs.push_back("-D_MT"); CmdArgs.push_back("--dependent-lib=libcmt"); break; case options::OPT__SLASH_MTd: CmdArgs.push_back("-D_DEBUG"); CmdArgs.push_back("-D_MT"); CmdArgs.push_back("--dependent-lib=libcmtd"); break; default: llvm_unreachable("Unexpected option ID."); } // This provides POSIX compatibility (maps 'open' to '_open'), which most // users want. The /Za flag to cl.exe turns this off, but it's not // implemented in clang. CmdArgs.push_back("--dependent-lib=oldnames"); // Both /showIncludes and /E (and /EP) write to stdout. Allowing both // would produce interleaved output, so ignore /showIncludes in such cases. if (!Args.hasArg(options::OPT_E) && !Args.hasArg(options::OPT__SLASH_EP)) if (Arg *A = Args.getLastArg(options::OPT_show_includes)) A->render(Args, CmdArgs); // This controls whether or not we emit RTTI data for polymorphic types. if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR, /*default=*/false)) CmdArgs.push_back("-fno-rtti-data"); const Driver &D = getToolChain().getDriver(); EHFlags EH = parseClangCLEHFlags(D, Args); // FIXME: Do something with NoExceptC. if (EH.Synch || EH.Asynch) { CmdArgs.push_back("-fcxx-exceptions"); CmdArgs.push_back("-fexceptions"); } // /EP should expand to -E -P. if (Args.hasArg(options::OPT__SLASH_EP)) { CmdArgs.push_back("-E"); CmdArgs.push_back("-P"); } unsigned VolatileOptionID; if (getToolChain().getArch() == llvm::Triple::x86_64 || getToolChain().getArch() == llvm::Triple::x86) VolatileOptionID = options::OPT__SLASH_volatile_ms; else VolatileOptionID = options::OPT__SLASH_volatile_iso; if (Arg *A = Args.getLastArg(options::OPT__SLASH_volatile_Group)) VolatileOptionID = A->getOption().getID(); if (VolatileOptionID == options::OPT__SLASH_volatile_ms) CmdArgs.push_back("-fms-volatile"); Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg); Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb); if (MostGeneralArg && BestCaseArg) D.Diag(clang::diag::err_drv_argument_not_allowed_with) << MostGeneralArg->getAsString(Args) << BestCaseArg->getAsString(Args); if (MostGeneralArg) { Arg *SingleArg = Args.getLastArg(options::OPT__SLASH_vms); Arg *MultipleArg = Args.getLastArg(options::OPT__SLASH_vmm); Arg *VirtualArg = Args.getLastArg(options::OPT__SLASH_vmv); Arg *FirstConflict = SingleArg ? SingleArg : MultipleArg; Arg *SecondConflict = VirtualArg ? VirtualArg : MultipleArg; if (FirstConflict && SecondConflict && FirstConflict != SecondConflict) D.Diag(clang::diag::err_drv_argument_not_allowed_with) << FirstConflict->getAsString(Args) << SecondConflict->getAsString(Args); if (SingleArg) CmdArgs.push_back("-fms-memptr-rep=single"); else if (MultipleArg) CmdArgs.push_back("-fms-memptr-rep=multiple"); else CmdArgs.push_back("-fms-memptr-rep=virtual"); } if (Arg *A = Args.getLastArg(options::OPT_vtordisp_mode_EQ)) A->render(Args, CmdArgs); if (!Args.hasArg(options::OPT_fdiagnostics_format_EQ)) { CmdArgs.push_back("-fdiagnostics-format"); if (Args.hasArg(options::OPT__SLASH_fallback)) CmdArgs.push_back("msvc-fallback"); else CmdArgs.push_back("msvc"); } } visualstudio::Compiler *Clang::getCLFallback() const { if (!CLFallback) CLFallback.reset(new visualstudio::Compiler(getToolChain())); return CLFallback.get(); } void ClangAs::AddMIPSTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { StringRef CPUName; StringRef ABIName; const llvm::Triple &Triple = getToolChain().getTriple(); mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName); CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName.data()); } void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; assert(Inputs.size() == 1 && "Unexpected number of inputs."); const InputInfo &Input = Inputs[0]; // Don't warn about "clang -w -c foo.s" Args.ClaimAllArgs(options::OPT_w); // and "clang -emit-llvm -c foo.s" Args.ClaimAllArgs(options::OPT_emit_llvm); claimNoWarnArgs(Args); // Invoke ourselves in -cc1as mode. // // FIXME: Implement custom jobs for internal actions. CmdArgs.push_back("-cc1as"); // Add the "effective" target triple. CmdArgs.push_back("-triple"); std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args, Input.getType()); CmdArgs.push_back(Args.MakeArgString(TripleStr)); // Set the output mode, we currently only expect to be used as a real // assembler. CmdArgs.push_back("-filetype"); CmdArgs.push_back("obj"); // Set the main file name, so that debug info works even with // -save-temps or preprocessed assembly. CmdArgs.push_back("-main-file-name"); CmdArgs.push_back(Clang::getBaseInputName(Args, Input)); // Add the target cpu const llvm::Triple Triple(TripleStr); std::string CPU = getCPUName(Args, Triple, /*FromAs*/ true); if (!CPU.empty()) { CmdArgs.push_back("-target-cpu"); CmdArgs.push_back(Args.MakeArgString(CPU)); } // Add the target features const Driver &D = getToolChain().getDriver(); getTargetFeatures(D, Triple, Args, CmdArgs, true); // Ignore explicit -force_cpusubtype_ALL option. (void)Args.hasArg(options::OPT_force__cpusubtype__ALL); // Pass along any -I options so we get proper .include search paths. Args.AddAllArgs(CmdArgs, options::OPT_I_Group); // Determine the original source input. const Action *SourceAction = &JA; while (SourceAction->getKind() != Action::InputClass) { assert(!SourceAction->getInputs().empty() && "unexpected root action!"); SourceAction = SourceAction->getInputs()[0]; } // Forward -g and handle debug info related flags, assuming we are dealing // with an actual assembly file. if (SourceAction->getType() == types::TY_Asm || SourceAction->getType() == types::TY_PP_Asm) { Args.ClaimAllArgs(options::OPT_g_Group); if (Arg *A = Args.getLastArg(options::OPT_g_Group)) if (!A->getOption().matches(options::OPT_g0)) CmdArgs.push_back("-g"); if (Args.hasArg(options::OPT_gdwarf_2)) CmdArgs.push_back("-gdwarf-2"); if (Args.hasArg(options::OPT_gdwarf_3)) CmdArgs.push_back("-gdwarf-3"); if (Args.hasArg(options::OPT_gdwarf_4)) CmdArgs.push_back("-gdwarf-4"); // Add the -fdebug-compilation-dir flag if needed. addDebugCompDirArg(Args, CmdArgs); // Set the AT_producer to the clang version when using the integrated // assembler on assembly source files. CmdArgs.push_back("-dwarf-debug-producer"); CmdArgs.push_back(Args.MakeArgString(getClangFullVersion())); } // Optionally embed the -cc1as level arguments into the debug info, for build // analysis. if (getToolChain().UseDwarfDebugFlags()) { ArgStringList OriginalArgs; for (const auto &Arg : Args) Arg->render(Args, OriginalArgs); SmallString<256> Flags; const char *Exec = getToolChain().getDriver().getClangProgramPath(); Flags += Exec; for (const char *OriginalArg : OriginalArgs) { SmallString<128> EscapedArg; EscapeSpacesAndBackslashes(OriginalArg, EscapedArg); Flags += " "; Flags += EscapedArg; } CmdArgs.push_back("-dwarf-debug-flags"); CmdArgs.push_back(Args.MakeArgString(Flags)); } // FIXME: Add -static support, once we have it. // Add target specific flags. switch (getToolChain().getArch()) { default: break; case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: AddMIPSTargetArgs(Args, CmdArgs); break; } // Consume all the warning flags. Usually this would be handled more // gracefully by -cc1 (warning about unknown warning flags, etc) but -cc1as // doesn't handle that so rather than warning about unused flags that are // actually used, we'll lie by omission instead. // FIXME: Stop lying and consume only the appropriate driver flags for (const Arg *A : Args.filtered(options::OPT_W_Group)) A->claim(); CollectArgsForIntegratedAssembler(C, Args, CmdArgs, getToolChain().getDriver()); Args.AddAllArgs(CmdArgs, options::OPT_mllvm); assert(Output.isFilename() && "Unexpected lipo output."); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); assert(Input.isFilename() && "Invalid input."); CmdArgs.push_back(Input.getFilename()); const char *Exec = getToolChain().getDriver().getClangProgramPath(); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); // Handle the debug info splitting at object creation time if we're // creating an object. // TODO: Currently only works on linux with newer objcopy. if (Args.hasArg(options::OPT_gsplit_dwarf) && getToolChain().getTriple().isOSLinux()) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDebugName(Args, Input)); } void GnuTool::anchor() {} void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; for (const auto &A : Args) { if (forwardToGCC(A->getOption())) { // Don't forward any -g arguments to assembly steps. if (isa<AssembleJobAction>(JA) && A->getOption().matches(options::OPT_g_Group)) continue; // Don't forward any -W arguments to assembly and link steps. if ((isa<AssembleJobAction>(JA) || isa<LinkJobAction>(JA)) && A->getOption().matches(options::OPT_W_Group)) continue; // It is unfortunate that we have to claim here, as this means // we will basically never report anything interesting for // platforms using a generic gcc, even if we are just using gcc // to get to the assembler. A->claim(); A->render(Args, CmdArgs); } } RenderExtraToolArgs(JA, CmdArgs); // If using a driver driver, force the arch. if (getToolChain().getTriple().isOSDarwin()) { CmdArgs.push_back("-arch"); CmdArgs.push_back( Args.MakeArgString(getToolChain().getDefaultUniversalArchName())); } // Try to force gcc to match the tool chain we want, if we recognize // the arch. // // FIXME: The triple class should directly provide the information we want // here. const llvm::Triple::ArchType Arch = getToolChain().getArch(); if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc) CmdArgs.push_back("-m32"); else if (Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::ppc64 || Arch == llvm::Triple::ppc64le) CmdArgs.push_back("-m64"); if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Unexpected output"); CmdArgs.push_back("-fsyntax-only"); } Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); // Only pass -x if gcc will understand it; otherwise hope gcc // understands the suffix correctly. The main use case this would go // wrong in is for linker inputs if they happened to have an odd // suffix; really the only way to get this to happen is a command // like '-x foobar a.c' which will treat a.c like a linker input. // // FIXME: For the linker case specifically, can we safely convert // inputs into '-Wl,' options? for (const auto &II : Inputs) { // Don't try to pass LLVM or AST inputs to a generic gcc. if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) D.Diag(diag::err_drv_no_linker_llvm_support) << getToolChain().getTripleString(); else if (II.getType() == types::TY_AST) D.Diag(diag::err_drv_no_ast_support) << getToolChain().getTripleString(); else if (II.getType() == types::TY_ModuleFile) D.Diag(diag::err_drv_no_module_support) << getToolChain().getTripleString(); if (types::canTypeBeUserSpecified(II.getType())) { CmdArgs.push_back("-x"); CmdArgs.push_back(types::getTypeName(II.getType())); } if (II.isFilename()) CmdArgs.push_back(II.getFilename()); else { const Arg &A = II.getInputArg(); // Reverse translate some rewritten options. if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) { CmdArgs.push_back("-lstdc++"); continue; } // Don't render as input, we need gcc to do the translations. A.render(Args, CmdArgs); } } const std::string customGCCName = D.getCCCGenericGCCName(); const char *GCCName; if (!customGCCName.empty()) GCCName = customGCCName.c_str(); else if (D.CCCIsCXX()) { GCCName = "g++"; } else GCCName = "gcc"; const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void gcc::Preprocessor::RenderExtraToolArgs(const JobAction &JA, ArgStringList &CmdArgs) const { CmdArgs.push_back("-E"); } void gcc::Compiler::RenderExtraToolArgs(const JobAction &JA, ArgStringList &CmdArgs) const { const Driver &D = getToolChain().getDriver(); switch (JA.getType()) { // If -flto, etc. are present then make sure not to force assembly output. case types::TY_LLVM_IR: case types::TY_LTO_IR: case types::TY_LLVM_BC: case types::TY_LTO_BC: CmdArgs.push_back("-c"); break; case types::TY_PP_Asm: CmdArgs.push_back("-S"); break; case types::TY_Nothing: CmdArgs.push_back("-fsyntax-only"); break; default: D.Diag(diag::err_drv_invalid_gcc_output_type) << getTypeName(JA.getType()); } } void gcc::Linker::RenderExtraToolArgs(const JobAction &JA, ArgStringList &CmdArgs) const { // The types are (hopefully) good enough. } // Hexagon tools start. void hexagon::Assembler::RenderExtraToolArgs(const JobAction &JA, ArgStringList &CmdArgs) const {} void hexagon::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; std::string MarchString = "-march="; MarchString += toolchains::Hexagon_TC::GetTargetCPU(Args); CmdArgs.push_back(Args.MakeArgString(MarchString)); RenderExtraToolArgs(JA, CmdArgs); if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Unexpected output"); CmdArgs.push_back("-fsyntax-only"); } if (const char *v = toolchains::Hexagon_TC::GetSmallDataThreshold(Args)) CmdArgs.push_back(Args.MakeArgString(std::string("-G") + v)); Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); // Only pass -x if gcc will understand it; otherwise hope gcc // understands the suffix correctly. The main use case this would go // wrong in is for linker inputs if they happened to have an odd // suffix; really the only way to get this to happen is a command // like '-x foobar a.c' which will treat a.c like a linker input. // // FIXME: For the linker case specifically, can we safely convert // inputs into '-Wl,' options? for (const auto &II : Inputs) { // Don't try to pass LLVM or AST inputs to a generic gcc. if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) D.Diag(clang::diag::err_drv_no_linker_llvm_support) << getToolChain().getTripleString(); else if (II.getType() == types::TY_AST) D.Diag(clang::diag::err_drv_no_ast_support) << getToolChain().getTripleString(); else if (II.getType() == types::TY_ModuleFile) D.Diag(diag::err_drv_no_module_support) << getToolChain().getTripleString(); if (II.isFilename()) CmdArgs.push_back(II.getFilename()); else // Don't render as input, we need gcc to do the translations. // FIXME: Pranav: What is this ? II.getInputArg().render(Args, CmdArgs); } const char *GCCName = "hexagon-as"; const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void hexagon::Linker::RenderExtraToolArgs(const JobAction &JA, ArgStringList &CmdArgs) const { // The types are (hopefully) good enough. } static void constructHexagonLinkArgs(Compilation &C, const JobAction &JA, const toolchains::Hexagon_TC &ToolChain, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, ArgStringList &CmdArgs, const char *LinkingOutput) { const Driver &D = ToolChain.getDriver(); //---------------------------------------------------------------------------- // //---------------------------------------------------------------------------- bool hasStaticArg = Args.hasArg(options::OPT_static); bool buildingLib = Args.hasArg(options::OPT_shared); bool buildPIE = Args.hasArg(options::OPT_pie); bool incStdLib = !Args.hasArg(options::OPT_nostdlib); bool incStartFiles = !Args.hasArg(options::OPT_nostartfiles); bool incDefLibs = !Args.hasArg(options::OPT_nodefaultlibs); bool useG0 = false; bool useShared = buildingLib && !hasStaticArg; //---------------------------------------------------------------------------- // Silence warnings for various options //---------------------------------------------------------------------------- Args.ClaimAllArgs(options::OPT_g_Group); Args.ClaimAllArgs(options::OPT_emit_llvm); Args.ClaimAllArgs(options::OPT_w); // Other warning options are already // handled somewhere else. Args.ClaimAllArgs(options::OPT_static_libgcc); //---------------------------------------------------------------------------- // //---------------------------------------------------------------------------- for (const auto &Opt : ToolChain.ExtraOpts) CmdArgs.push_back(Opt.c_str()); std::string MarchString = toolchains::Hexagon_TC::GetTargetCPU(Args); CmdArgs.push_back(Args.MakeArgString("-m" + MarchString)); if (buildingLib) { CmdArgs.push_back("-shared"); CmdArgs.push_back("-call_shared"); // should be the default, but doing as // hexagon-gcc does } if (hasStaticArg) CmdArgs.push_back("-static"); if (buildPIE && !buildingLib) CmdArgs.push_back("-pie"); if (const char *v = toolchains::Hexagon_TC::GetSmallDataThreshold(Args)) { CmdArgs.push_back(Args.MakeArgString(std::string("-G") + v)); useG0 = toolchains::Hexagon_TC::UsesG0(v); } //---------------------------------------------------------------------------- // //---------------------------------------------------------------------------- CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); const std::string MarchSuffix = "/" + MarchString; const std::string G0Suffix = "/G0"; const std::string MarchG0Suffix = MarchSuffix + G0Suffix; const std::string RootDir = toolchains::Hexagon_TC::GetGnuDir(D.InstalledDir, Args) + "/"; const std::string StartFilesDir = RootDir + "hexagon/lib" + (useG0 ? MarchG0Suffix : MarchSuffix); //---------------------------------------------------------------------------- // moslib //---------------------------------------------------------------------------- std::vector<std::string> oslibs; bool hasStandalone = false; for (const Arg *A : Args.filtered(options::OPT_moslib_EQ)) { A->claim(); oslibs.emplace_back(A->getValue()); hasStandalone = hasStandalone || (oslibs.back() == "standalone"); } if (oslibs.empty()) { oslibs.push_back("standalone"); hasStandalone = true; } //---------------------------------------------------------------------------- // Start Files //---------------------------------------------------------------------------- if (incStdLib && incStartFiles) { if (!buildingLib) { if (hasStandalone) { CmdArgs.push_back( Args.MakeArgString(StartFilesDir + "/crt0_standalone.o")); } CmdArgs.push_back(Args.MakeArgString(StartFilesDir + "/crt0.o")); } std::string initObj = useShared ? "/initS.o" : "/init.o"; CmdArgs.push_back(Args.MakeArgString(StartFilesDir + initObj)); } //---------------------------------------------------------------------------- // Library Search Paths //---------------------------------------------------------------------------- const ToolChain::path_list &LibPaths = ToolChain.getFilePaths(); for (const auto &LibPath : LibPaths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); //---------------------------------------------------------------------------- // //---------------------------------------------------------------------------- Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); Args.AddAllArgs(CmdArgs, options::OPT_s); Args.AddAllArgs(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_u_Group); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); //---------------------------------------------------------------------------- // Libraries //---------------------------------------------------------------------------- if (incStdLib && incDefLibs) { if (D.CCCIsCXX()) { ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } CmdArgs.push_back("--start-group"); if (!buildingLib) { for (const std::string &Lib : oslibs) CmdArgs.push_back(Args.MakeArgString("-l" + Lib)); CmdArgs.push_back("-lc"); } CmdArgs.push_back("-lgcc"); CmdArgs.push_back("--end-group"); } //---------------------------------------------------------------------------- // End files //---------------------------------------------------------------------------- if (incStdLib && incStartFiles) { std::string finiObj = useShared ? "/finiS.o" : "/fini.o"; CmdArgs.push_back(Args.MakeArgString(StartFilesDir + finiObj)); } } void hexagon::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const toolchains::Hexagon_TC &ToolChain = static_cast<const toolchains::Hexagon_TC &>(getToolChain()); ArgStringList CmdArgs; constructHexagonLinkArgs(C, JA, ToolChain, Output, Inputs, Args, CmdArgs, LinkingOutput); std::string Linker = ToolChain.GetProgramPath("hexagon-ld"); C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), CmdArgs)); } // Hexagon tools end. const std::string arm::getARMArch(StringRef Arch, const llvm::Triple &Triple) { std::string MArch; if (!Arch.empty()) MArch = Arch; else MArch = Triple.getArchName(); MArch = StringRef(MArch).lower(); // Handle -march=native. if (MArch == "native") { std::string CPU = llvm::sys::getHostCPUName(); if (CPU != "generic") { // Translate the native cpu into the architecture suffix for that CPU. const char *Suffix = arm::getLLVMArchSuffixForARM(CPU, MArch); // If there is no valid architecture suffix for this CPU we don't know how // to handle it, so return no architecture. if (strcmp(Suffix, "") == 0) MArch = ""; else MArch = std::string("arm") + Suffix; } } return MArch; } /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting. const char *arm::getARMCPUForMArch(StringRef Arch, const llvm::Triple &Triple) { std::string MArch = getARMArch(Arch, Triple); // getARMCPUForArch defaults to the triple if MArch is empty, but empty MArch // here means an -march=native that we can't handle, so instead return no CPU. if (MArch.empty()) return ""; // We need to return an empty string here on invalid MArch values as the // various places that call this function can't cope with a null result. const char *result = Triple.getARMCPUForArch(MArch); if (result) return result; else return ""; } /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting. std::string arm::getARMTargetCPU(StringRef CPU, StringRef Arch, const llvm::Triple &Triple) { // FIXME: Warn on inconsistent use of -mcpu and -march. // If we have -mcpu=, use that. if (!CPU.empty()) { std::string MCPU = StringRef(CPU).lower(); // Handle -mcpu=native. if (MCPU == "native") return llvm::sys::getHostCPUName(); else return MCPU; } return getARMCPUForMArch(Arch, Triple); } /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular /// CPU (or Arch, if CPU is generic). // FIXME: This is redundant with -mcpu, why does LLVM use this. const char *arm::getLLVMArchSuffixForARM(StringRef CPU, StringRef Arch) { if (CPU == "generic" && llvm::ARMTargetParser::parseArch(Arch) == llvm::ARM::AK_ARMV8_1A) return "v8.1a"; unsigned ArchKind = llvm::ARMTargetParser::parseCPUArch(CPU); if (ArchKind == llvm::ARM::AK_INVALID) return ""; return llvm::ARMTargetParser::getSubArch(ArchKind); } void arm::appendEBLinkFlags(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple) { if (Args.hasArg(options::OPT_r)) return; // ARMv7 (and later) and ARMv6-M do not support BE-32, so instruct the linker // to generate BE-8 executables. if (getARMSubArchVersionNumber(Triple) >= 7 || isARMMProfile(Triple)) CmdArgs.push_back("--be8"); } mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) { return (NanEncoding)llvm::StringSwitch<int>(CPU) .Case("mips1", NanLegacy) .Case("mips2", NanLegacy) .Case("mips3", NanLegacy) .Case("mips4", NanLegacy) .Case("mips5", NanLegacy) .Case("mips32", NanLegacy) .Case("mips32r2", NanLegacy) .Case("mips32r3", NanLegacy | Nan2008) .Case("mips32r5", NanLegacy | Nan2008) .Case("mips32r6", Nan2008) .Case("mips64", NanLegacy) .Case("mips64r2", NanLegacy) .Case("mips64r3", NanLegacy | Nan2008) .Case("mips64r5", NanLegacy | Nan2008) .Case("mips64r6", Nan2008) .Default(NanLegacy); } bool mips::hasMipsAbiArg(const ArgList &Args, const char *Value) { Arg *A = Args.getLastArg(options::OPT_mabi_EQ); return A && (A->getValue() == StringRef(Value)); } bool mips::isUCLibc(const ArgList &Args) { Arg *A = Args.getLastArg(options::OPT_m_libc_Group); return A && A->getOption().matches(options::OPT_muclibc); } bool mips::isNaN2008(const ArgList &Args, const llvm::Triple &Triple) { if (Arg *NaNArg = Args.getLastArg(options::OPT_mnan_EQ)) return llvm::StringSwitch<bool>(NaNArg->getValue()) .Case("2008", true) .Case("legacy", false) .Default(false); // NaN2008 is the default for MIPS32r6/MIPS64r6. return llvm::StringSwitch<bool>(getCPUName(Args, Triple)) .Cases("mips32r6", "mips64r6", true) .Default(false); return false; } bool mips::isFPXXDefault(const llvm::Triple &Triple, StringRef CPUName, StringRef ABIName, StringRef FloatABI) { if (Triple.getVendor() != llvm::Triple::ImaginationTechnologies && Triple.getVendor() != llvm::Triple::MipsTechnologies) return false; if (ABIName != "32") return false; // FPXX shouldn't be used if either -msoft-float or -mfloat-abi=soft is // present. if (FloatABI == "soft") return false; return llvm::StringSwitch<bool>(CPUName) .Cases("mips2", "mips3", "mips4", "mips5", true) .Cases("mips32", "mips32r2", "mips32r3", "mips32r5", true) .Cases("mips64", "mips64r2", "mips64r3", "mips64r5", true) .Default(false); } bool mips::shouldUseFPXX(const ArgList &Args, const llvm::Triple &Triple, StringRef CPUName, StringRef ABIName, StringRef FloatABI) { bool UseFPXX = isFPXXDefault(Triple, CPUName, ABIName, FloatABI); // FPXX shouldn't be used if -msingle-float is present. if (Arg *A = Args.getLastArg(options::OPT_msingle_float, options::OPT_mdouble_float)) if (A->getOption().matches(options::OPT_msingle_float)) UseFPXX = false; return UseFPXX; } llvm::Triple::ArchType darwin::getArchTypeForMachOArchName(StringRef Str) { // See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for // archs which Darwin doesn't use. // The matching this routine does is fairly pointless, since it is neither the // complete architecture list, nor a reasonable subset. The problem is that // historically the driver driver accepts this and also ties its -march= // handling to the architecture name, so we need to be careful before removing // support for it. // This code must be kept in sync with Clang's Darwin specific argument // translation. return llvm::StringSwitch<llvm::Triple::ArchType>(Str) .Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", llvm::Triple::ppc) .Cases("ppc750", "ppc7400", "ppc7450", "ppc970", llvm::Triple::ppc) .Case("ppc64", llvm::Triple::ppc64) .Cases("i386", "i486", "i486SX", "i586", "i686", llvm::Triple::x86) .Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4", llvm::Triple::x86) .Cases("x86_64", "x86_64h", llvm::Triple::x86_64) // This is derived from the driver driver. .Cases("arm", "armv4t", "armv5", "armv6", "armv6m", llvm::Triple::arm) .Cases("armv7", "armv7em", "armv7k", "armv7m", llvm::Triple::arm) .Cases("armv7s", "xscale", llvm::Triple::arm) .Case("arm64", llvm::Triple::aarch64) .Case("r600", llvm::Triple::r600) .Case("amdgcn", llvm::Triple::amdgcn) .Case("nvptx", llvm::Triple::nvptx) .Case("nvptx64", llvm::Triple::nvptx64) .Case("amdil", llvm::Triple::amdil) .Case("spir", llvm::Triple::spir) .Default(llvm::Triple::UnknownArch); } void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str) { const llvm::Triple::ArchType Arch = getArchTypeForMachOArchName(Str); T.setArch(Arch); if (Str == "x86_64h") T.setArchName(Str); else if (Str == "armv6m" || Str == "armv7m" || Str == "armv7em") { T.setOS(llvm::Triple::UnknownOS); T.setObjectFormat(llvm::Triple::MachO); } } const char *Clang::getBaseInputName(const ArgList &Args, const InputInfo &Input) { return Args.MakeArgString(llvm::sys::path::filename(Input.getBaseInput())); } const char *Clang::getBaseInputStem(const ArgList &Args, const InputInfoList &Inputs) { const char *Str = getBaseInputName(Args, Inputs[0]); if (const char *End = strrchr(Str, '.')) return Args.MakeArgString(std::string(Str, End)); return Str; } const char *Clang::getDependencyFileName(const ArgList &Args, const InputInfoList &Inputs) { // FIXME: Think about this more. std::string Res; if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { std::string Str(OutputOpt->getValue()); Res = Str.substr(0, Str.rfind('.')); } else { Res = getBaseInputStem(Args, Inputs); } return Args.MakeArgString(Res + ".d"); } void cloudabi::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const ToolChain &ToolChain = getToolChain(); const Driver &D = ToolChain.getDriver(); ArgStringList CmdArgs; // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); // and "clang -emit-llvm foo.o -o foo" Args.ClaimAllArgs(options::OPT_emit_llvm); // and for "clang -w foo.o -o foo". Other warning options are already // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); // CloudABI only supports static linkage. CmdArgs.push_back("-Bstatic"); CmdArgs.push_back("--eh-frame-hdr"); CmdArgs.push_back("--gc-sections"); if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o"))); } Args.AddAllArgs(CmdArgs, options::OPT_L); const ToolChain::path_list &Paths = ToolChain.getFilePaths(); for (const auto &Path : Paths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); Args.AddAllArgs(CmdArgs, options::OPT_s); Args.AddAllArgs(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); Args.AddAllArgs(CmdArgs, options::OPT_r); if (D.IsUsingLTO(Args)) AddGoldPlugin(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (D.CCCIsCXX()) ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lc"); CmdArgs.push_back("-lcompiler_rt"); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void darwin::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; assert(Inputs.size() == 1 && "Unexpected number of inputs."); const InputInfo &Input = Inputs[0]; // Determine the original source input. const Action *SourceAction = &JA; while (SourceAction->getKind() != Action::InputClass) { assert(!SourceAction->getInputs().empty() && "unexpected root action!"); SourceAction = SourceAction->getInputs()[0]; } // If -fno_integrated_as is used add -Q to the darwin assember driver to make // sure it runs its system assembler not clang's integrated assembler. // Applicable to darwin11+ and Xcode 4+. darwin<10 lacked integrated-as. // FIXME: at run-time detect assembler capabilities or rely on version // information forwarded by -target-assembler-version (future) if (Args.hasArg(options::OPT_fno_integrated_as)) { const llvm::Triple &T(getToolChain().getTriple()); if (!(T.isMacOSX() && T.isMacOSXVersionLT(10, 7))) CmdArgs.push_back("-Q"); } // Forward -g, assuming we are dealing with an actual assembly file. if (SourceAction->getType() == types::TY_Asm || SourceAction->getType() == types::TY_PP_Asm) { if (Args.hasArg(options::OPT_gstabs)) CmdArgs.push_back("--gstabs"); else if (Args.hasArg(options::OPT_g_Group)) CmdArgs.push_back("-g"); } // Derived from asm spec. AddMachOArch(Args, CmdArgs); // Use -force_cpusubtype_ALL on x86 by default. if (getToolChain().getArch() == llvm::Triple::x86 || getToolChain().getArch() == llvm::Triple::x86_64 || Args.hasArg(options::OPT_force__cpusubtype__ALL)) CmdArgs.push_back("-force_cpusubtype_ALL"); if (getToolChain().getArch() != llvm::Triple::x86_64 && (((Args.hasArg(options::OPT_mkernel) || Args.hasArg(options::OPT_fapple_kext)) && getMachOToolChain().isKernelStatic()) || Args.hasArg(options::OPT_static))) CmdArgs.push_back("-static"); Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); assert(Output.isFilename() && "Unexpected lipo output."); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); assert(Input.isFilename() && "Invalid input."); CmdArgs.push_back(Input.getFilename()); // asm_final spec is empty. const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void darwin::MachOTool::anchor() {} void darwin::MachOTool::AddMachOArch(const ArgList &Args, ArgStringList &CmdArgs) const { StringRef ArchName = getMachOToolChain().getMachOArchName(Args); // Derived from darwin_arch spec. CmdArgs.push_back("-arch"); CmdArgs.push_back(Args.MakeArgString(ArchName)); // FIXME: Is this needed anymore? if (ArchName == "arm") CmdArgs.push_back("-force_cpusubtype_ALL"); } bool darwin::Linker::NeedsTempPath(const InputInfoList &Inputs) const { // We only need to generate a temp path for LTO if we aren't compiling object // files. When compiling source files, we run 'dsymutil' after linking. We // don't run 'dsymutil' when compiling object files. for (const auto &Input : Inputs) if (Input.getType() != types::TY_Object) return true; return false; } void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args, ArgStringList &CmdArgs, const InputInfoList &Inputs) const { const Driver &D = getToolChain().getDriver(); const toolchains::MachO &MachOTC = getMachOToolChain(); unsigned Version[3] = {0, 0, 0}; if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { bool HadExtra; if (!Driver::GetReleaseVersion(A->getValue(), Version[0], Version[1], Version[2], HadExtra) || HadExtra) D.Diag(diag::err_drv_invalid_version_number) << A->getAsString(Args); } // Newer linkers support -demangle. Pass it if supported and not disabled by // the user. if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) CmdArgs.push_back("-demangle"); if (Args.hasArg(options::OPT_rdynamic) && Version[0] >= 137) CmdArgs.push_back("-export_dynamic"); // If we are using App Extension restrictions, pass a flag to the linker // telling it that the compiled code has been audited. if (Args.hasFlag(options::OPT_fapplication_extension, options::OPT_fno_application_extension, false)) CmdArgs.push_back("-application_extension"); // If we are using LTO, then automatically create a temporary file path for // the linker to use, so that it's lifetime will extend past a possible // dsymutil step. if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) { const char *TmpPath = C.getArgs().MakeArgString( D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object))); C.addTempFile(TmpPath); CmdArgs.push_back("-object_path_lto"); CmdArgs.push_back(TmpPath); } // Derived from the "link" spec. Args.AddAllArgs(CmdArgs, options::OPT_static); if (!Args.hasArg(options::OPT_static)) CmdArgs.push_back("-dynamic"); if (Args.hasArg(options::OPT_fgnu_runtime)) { // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu // here. How do we wish to handle such things? } if (!Args.hasArg(options::OPT_dynamiclib)) { AddMachOArch(Args, CmdArgs); // FIXME: Why do this only on this path? Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL); Args.AddLastArg(CmdArgs, options::OPT_bundle); Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); Args.AddAllArgs(CmdArgs, options::OPT_client__name); Arg *A; if ((A = Args.getLastArg(options::OPT_compatibility__version)) || (A = Args.getLastArg(options::OPT_current__version)) || (A = Args.getLastArg(options::OPT_install__name))) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-dynamiclib"; Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace); Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs); Args.AddLastArg(CmdArgs, options::OPT_private__bundle); } else { CmdArgs.push_back("-dylib"); Arg *A; if ((A = Args.getLastArg(options::OPT_bundle)) || (A = Args.getLastArg(options::OPT_bundle__loader)) || (A = Args.getLastArg(options::OPT_client__name)) || (A = Args.getLastArg(options::OPT_force__flat__namespace)) || (A = Args.getLastArg(options::OPT_keep__private__externs)) || (A = Args.getLastArg(options::OPT_private__bundle))) D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "-dynamiclib"; Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version, "-dylib_compatibility_version"); Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, "-dylib_current_version"); AddMachOArch(Args, CmdArgs); Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, "-dylib_install_name"); } Args.AddLastArg(CmdArgs, options::OPT_all__load); Args.AddAllArgs(CmdArgs, options::OPT_allowable__client); Args.AddLastArg(CmdArgs, options::OPT_bind__at__load); if (MachOTC.isTargetIOSBased()) Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal); Args.AddLastArg(CmdArgs, options::OPT_dead__strip); Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms); Args.AddAllArgs(CmdArgs, options::OPT_dylib__file); Args.AddLastArg(CmdArgs, options::OPT_dynamic); Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list); Args.AddLastArg(CmdArgs, options::OPT_flat__namespace); Args.AddAllArgs(CmdArgs, options::OPT_force__load); Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names); Args.AddAllArgs(CmdArgs, options::OPT_image__base); Args.AddAllArgs(CmdArgs, options::OPT_init); // Add the deployment target. MachOTC.addMinVersionArgs(Args, CmdArgs); Args.AddLastArg(CmdArgs, options::OPT_nomultidefs); Args.AddLastArg(CmdArgs, options::OPT_multi__module); Args.AddLastArg(CmdArgs, options::OPT_single__module); Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); if (const Arg *A = Args.getLastArg(options::OPT_fpie, options::OPT_fPIE, options::OPT_fno_pie, options::OPT_fno_PIE)) { if (A->getOption().matches(options::OPT_fpie) || A->getOption().matches(options::OPT_fPIE)) CmdArgs.push_back("-pie"); else CmdArgs.push_back("-no_pie"); } Args.AddLastArg(CmdArgs, options::OPT_prebind); Args.AddLastArg(CmdArgs, options::OPT_noprebind); Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules); Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs); Args.AddAllArgs(CmdArgs, options::OPT_sectcreate); Args.AddAllArgs(CmdArgs, options::OPT_sectorder); Args.AddAllArgs(CmdArgs, options::OPT_seg1addr); Args.AddAllArgs(CmdArgs, options::OPT_segprot); Args.AddAllArgs(CmdArgs, options::OPT_segaddr); Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr); Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr); Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table); Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename); Args.AddAllArgs(CmdArgs, options::OPT_sub__library); Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella); // Give --sysroot= preference, over the Apple specific behavior to also use // --isysroot as the syslibroot. StringRef sysroot = C.getSysRoot(); if (sysroot != "") { CmdArgs.push_back("-syslibroot"); CmdArgs.push_back(C.getArgs().MakeArgString(sysroot)); } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { CmdArgs.push_back("-syslibroot"); CmdArgs.push_back(A->getValue()); } Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace); Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints); Args.AddAllArgs(CmdArgs, options::OPT_umbrella); Args.AddAllArgs(CmdArgs, options::OPT_undefined); Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list); Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches); Args.AddLastArg(CmdArgs, options::OPT_X_Flag); Args.AddAllArgs(CmdArgs, options::OPT_y); Args.AddLastArg(CmdArgs, options::OPT_w); Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size); Args.AddAllArgs(CmdArgs, options::OPT_segs__read__); Args.AddLastArg(CmdArgs, options::OPT_seglinkedit); Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit); Args.AddAllArgs(CmdArgs, options::OPT_sectalign); Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols); Args.AddAllArgs(CmdArgs, options::OPT_segcreate); Args.AddLastArg(CmdArgs, options::OPT_whyload); Args.AddLastArg(CmdArgs, options::OPT_whatsloaded); Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); Args.AddLastArg(CmdArgs, options::OPT_dylinker); Args.AddLastArg(CmdArgs, options::OPT_Mach); } void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { assert(Output.getType() == types::TY_Image && "Invalid linker output type."); // If the number of arguments surpasses the system limits, we will encode the // input files in a separate file, shortening the command line. To this end, // build a list of input file names that can be passed via a file with the // -filelist linker option. llvm::opt::ArgStringList InputFileList; // The logic here is derived from gcc's behavior; most of which // comes from specs (starting with link_command). Consult gcc for // more information. ArgStringList CmdArgs; /// Hack(tm) to ignore linking errors when we are doing ARC migration. if (Args.hasArg(options::OPT_ccc_arcmt_check, options::OPT_ccc_arcmt_migrate)) { for (const auto &Arg : Args) Arg->claim(); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("touch")); CmdArgs.push_back(Output.getFilename()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); return; } // I'm not sure why this particular decomposition exists in gcc, but // we follow suite for ease of comparison. AddLinkArgs(C, Args, CmdArgs, Inputs); Args.AddAllArgs(CmdArgs, options::OPT_d_Flag); Args.AddAllArgs(CmdArgs, options::OPT_s); Args.AddAllArgs(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); Args.AddAllArgs(CmdArgs, options::OPT_u_Group); Args.AddLastArg(CmdArgs, options::OPT_e); Args.AddAllArgs(CmdArgs, options::OPT_r); // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading // members of static archive libraries which implement Objective-C classes or // categories. if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX)) CmdArgs.push_back("-ObjC"); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) getMachOToolChain().addStartObjectFileArgs(Args, CmdArgs); // SafeStack requires its own runtime libraries // These libraries should be linked first, to make sure the // __safestack_init constructor executes before everything else if (getToolChain().getSanitizerArgs().needsSafeStackRt()) { getMachOToolChain().AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.safestack_osx.a", /*AlwaysLink=*/true); } Args.AddAllArgs(CmdArgs, options::OPT_L); if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, options::OPT_fno_openmp, false)) { switch (getOpenMPRuntime(getToolChain(), Args)) { case OMPRT_OMP: CmdArgs.push_back("-lomp"); break; case OMPRT_GOMP: CmdArgs.push_back("-lgomp"); break; case OMPRT_IOMP5: CmdArgs.push_back("-liomp5"); break; case OMPRT_Unknown: // Already diagnosed. break; } } AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); // Build the input file for -filelist (list of linker input files) in case we // need it later for (const auto &II : Inputs) { if (!II.isFilename()) { // This is a linker input argument. // We cannot mix input arguments and file names in a -filelist input, thus // we prematurely stop our list (remaining files shall be passed as // arguments). if (InputFileList.size() > 0) break; continue; } InputFileList.push_back(II.getFilename()); } if (isObjCRuntimeLinked(Args) && !Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { // We use arclite library for both ARC and subscripting support. getMachOToolChain().AddLinkARCArgs(Args, CmdArgs); CmdArgs.push_back("-framework"); CmdArgs.push_back("Foundation"); // Link libobj. CmdArgs.push_back("-lobjc"); } if (LinkingOutput) { CmdArgs.push_back("-arch_multiple"); CmdArgs.push_back("-final_output"); CmdArgs.push_back(LinkingOutput); } if (Args.hasArg(options::OPT_fnested_functions)) CmdArgs.push_back("-allow_stack_execute"); // TODO: It would be nice to use addProfileRT() here, but darwin's compiler-rt // paths are different enough from other toolchains that this needs a fair // amount of refactoring done first. getMachOToolChain().addProfileRTLibs(Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (getToolChain().getDriver().CCCIsCXX()) getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); // link_ssp spec is empty. // Let the tool chain choose which runtime library to link. getMachOToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { // endfile_spec is empty. } Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_F); // -iframework should be forwarded as -F. for (const Arg *A : Args.filtered(options::OPT_iframework)) CmdArgs.push_back(Args.MakeArgString(std::string("-F") + A->getValue())); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (Arg *A = Args.getLastArg(options::OPT_fveclib)) { if (A->getValue() == StringRef("Accelerate")) { CmdArgs.push_back("-framework"); CmdArgs.push_back("Accelerate"); } } } const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); std::unique_ptr<Command> Cmd = llvm::make_unique<Command>(JA, *this, Exec, CmdArgs); Cmd->setInputFileList(std::move(InputFileList)); C.addCommand(std::move(Cmd)); } void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; CmdArgs.push_back("-create"); assert(Output.isFilename() && "Unexpected lipo output."); CmdArgs.push_back("-output"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) { assert(II.isFilename() && "Unexpected lipo input."); CmdArgs.push_back(II.getFilename()); } const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); const InputInfo &Input = Inputs[0]; assert(Input.isFilename() && "Unexpected dsymutil input."); CmdArgs.push_back(Input.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("dsymutil")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; CmdArgs.push_back("--verify"); CmdArgs.push_back("--debug-info"); CmdArgs.push_back("--eh-frame"); CmdArgs.push_back("--quiet"); assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); const InputInfo &Input = Inputs[0]; assert(Input.isFilename() && "Unexpected verify input"); // Grabbing the output of the earlier dsymutil run. CmdArgs.push_back(Input.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void solaris::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { // FIXME: Find a real GCC, don't hard-code versions here std::string GCCLibPath = "/usr/gcc/4.5/lib/gcc/"; const llvm::Triple &T = getToolChain().getTriple(); std::string LibPath = "/usr/lib/"; const llvm::Triple::ArchType Arch = T.getArch(); switch (Arch) { case llvm::Triple::x86: GCCLibPath += ("i386-" + T.getVendorName() + "-" + T.getOSName()).str() + "/4.5.2/"; break; case llvm::Triple::x86_64: GCCLibPath += ("i386-" + T.getVendorName() + "-" + T.getOSName()).str(); GCCLibPath += "/4.5.2/amd64/"; LibPath += "amd64/"; break; default: llvm_unreachable("Unsupported architecture"); } ArgStringList CmdArgs; // Demangle C++ names in errors CmdArgs.push_back("-C"); if ((!Args.hasArg(options::OPT_nostdlib)) && (!Args.hasArg(options::OPT_shared))) { CmdArgs.push_back("-e"); CmdArgs.push_back("_start"); } if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); CmdArgs.push_back("-dn"); } else { CmdArgs.push_back("-Bdynamic"); if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-shared"); } else { CmdArgs.push_back("--dynamic-linker"); CmdArgs.push_back(Args.MakeArgString(LibPath + "ld.so.1")); } } if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) { CmdArgs.push_back(Args.MakeArgString(LibPath + "crt1.o")); CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o")); CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o")); CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o")); } else { CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o")); CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o")); CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o")); } if (getToolChain().getDriver().CCCIsCXX()) CmdArgs.push_back(Args.MakeArgString(LibPath + "cxa_finalize.o")); } CmdArgs.push_back(Args.MakeArgString("-L" + GCCLibPath)); Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); Args.AddAllArgs(CmdArgs, options::OPT_r); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (getToolChain().getDriver().CCCIsCXX()) getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lgcc_s"); if (!Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-lgcc"); CmdArgs.push_back("-lc"); CmdArgs.push_back("-lm"); } } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtend.o")); } CmdArgs.push_back(Args.MakeArgString(LibPath + "crtn.o")); addProfileRT(getToolChain(), Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void openbsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; bool NeedsKPIC = false; switch (getToolChain().getArch()) { case llvm::Triple::x86: // When building 32-bit code on OpenBSD/amd64, we have to explicitly // instruct as in the base system to assemble 32-bit code. CmdArgs.push_back("--32"); break; case llvm::Triple::ppc: CmdArgs.push_back("-mppc"); CmdArgs.push_back("-many"); break; case llvm::Triple::sparc: case llvm::Triple::sparcel: CmdArgs.push_back("-32"); NeedsKPIC = true; break; case llvm::Triple::sparcv9: CmdArgs.push_back("-64"); CmdArgs.push_back("-Av9a"); NeedsKPIC = true; break; case llvm::Triple::mips64: case llvm::Triple::mips64el: { StringRef CPUName; StringRef ABIName; mips::getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName); CmdArgs.push_back("-mabi"); CmdArgs.push_back(getGnuCompatibleMipsABIName(ABIName).data()); if (getToolChain().getArch() == llvm::Triple::mips64) CmdArgs.push_back("-EB"); else CmdArgs.push_back("-EL"); NeedsKPIC = true; break; } default: break; } if (NeedsKPIC) addAssemblerKPIC(Args, CmdArgs); Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); // and "clang -emit-llvm foo.o -o foo" Args.ClaimAllArgs(options::OPT_emit_llvm); // and for "clang -w foo.o -o foo". Other warning options are already // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); if (getToolChain().getArch() == llvm::Triple::mips64) CmdArgs.push_back("-EB"); else if (getToolChain().getArch() == llvm::Triple::mips64el) CmdArgs.push_back("-EL"); if ((!Args.hasArg(options::OPT_nostdlib)) && (!Args.hasArg(options::OPT_shared))) { CmdArgs.push_back("-e"); CmdArgs.push_back("__start"); } if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); CmdArgs.push_back("--eh-frame-hdr"); CmdArgs.push_back("-Bdynamic"); if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-shared"); } else { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/usr/libexec/ld.so"); } } if (Args.hasArg(options::OPT_nopie)) CmdArgs.push_back("-nopie"); if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("gcrt0.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crt0.o"))); CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); } else { CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); } } std::string Triple = getToolChain().getTripleString(); if (Triple.substr(0, 6) == "x86_64") Triple.replace(0, 6, "amd64"); CmdArgs.push_back( Args.MakeArgString("-L/usr/lib/gcc-lib/" + Triple + "/4.2.1")); Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); Args.AddAllArgs(CmdArgs, options::OPT_s); Args.AddAllArgs(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); Args.AddAllArgs(CmdArgs, options::OPT_r); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lm_p"); else CmdArgs.push_back("-lm"); } // FIXME: For some reason GCC passes -lgcc before adding // the default system libraries. Just mimic this for now. CmdArgs.push_back("-lgcc"); if (Args.hasArg(options::OPT_pthread)) { if (!Args.hasArg(options::OPT_shared) && Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lpthread_p"); else CmdArgs.push_back("-lpthread"); } if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lc_p"); else CmdArgs.push_back("-lc"); } CmdArgs.push_back("-lgcc"); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtendS.o"))); } const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void bitrig::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void bitrig::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; if ((!Args.hasArg(options::OPT_nostdlib)) && (!Args.hasArg(options::OPT_shared))) { CmdArgs.push_back("-e"); CmdArgs.push_back("__start"); } if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); CmdArgs.push_back("--eh-frame-hdr"); CmdArgs.push_back("-Bdynamic"); if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-shared"); } else { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/usr/libexec/ld.so"); } } if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("gcrt0.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crt0.o"))); CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); } else { CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); } } Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lm_p"); else CmdArgs.push_back("-lm"); } if (Args.hasArg(options::OPT_pthread)) { if (!Args.hasArg(options::OPT_shared) && Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lpthread_p"); else CmdArgs.push_back("-lpthread"); } if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lc_p"); else CmdArgs.push_back("-lc"); } StringRef MyArch; switch (getToolChain().getArch()) { case llvm::Triple::arm: MyArch = "arm"; break; case llvm::Triple::x86: MyArch = "i386"; break; case llvm::Triple::x86_64: MyArch = "amd64"; break; default: llvm_unreachable("Unsupported architecture"); } CmdArgs.push_back(Args.MakeArgString("-lclang_rt." + MyArch)); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtendS.o"))); } const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void freebsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; // When building 32-bit code on FreeBSD/amd64, we have to explicitly // instruct as in the base system to assemble 32-bit code. if (getToolChain().getArch() == llvm::Triple::x86) CmdArgs.push_back("--32"); else if (getToolChain().getArch() == llvm::Triple::ppc) CmdArgs.push_back("-a32"); else if (getToolChain().getArch() == llvm::Triple::mips || getToolChain().getArch() == llvm::Triple::mipsel || getToolChain().getArch() == llvm::Triple::mips64 || getToolChain().getArch() == llvm::Triple::mips64el) { StringRef CPUName; StringRef ABIName; mips::getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName); CmdArgs.push_back("-march"); CmdArgs.push_back(CPUName.data()); CmdArgs.push_back("-mabi"); CmdArgs.push_back(getGnuCompatibleMipsABIName(ABIName).data()); if (getToolChain().getArch() == llvm::Triple::mips || getToolChain().getArch() == llvm::Triple::mips64) CmdArgs.push_back("-EB"); else CmdArgs.push_back("-EL"); addAssemblerKPIC(Args, CmdArgs); } else if (getToolChain().getArch() == llvm::Triple::arm || getToolChain().getArch() == llvm::Triple::armeb || getToolChain().getArch() == llvm::Triple::thumb || getToolChain().getArch() == llvm::Triple::thumbeb) { const Driver &D = getToolChain().getDriver(); const llvm::Triple &Triple = getToolChain().getTriple(); StringRef FloatABI = arm::getARMFloatABI(D, Args, Triple); if (FloatABI == "hard") { CmdArgs.push_back("-mfpu=vfp"); } else { CmdArgs.push_back("-mfpu=softvfp"); } switch (getToolChain().getTriple().getEnvironment()) { case llvm::Triple::GNUEABIHF: case llvm::Triple::GNUEABI: case llvm::Triple::EABI: CmdArgs.push_back("-meabi=5"); break; default: CmdArgs.push_back("-matpcs"); } } else if (getToolChain().getArch() == llvm::Triple::sparc || getToolChain().getArch() == llvm::Triple::sparcel || getToolChain().getArch() == llvm::Triple::sparcv9) { if (getToolChain().getArch() == llvm::Triple::sparc) CmdArgs.push_back("-Av8plusa"); else CmdArgs.push_back("-Av9a"); addAssemblerKPIC(Args, CmdArgs); } Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const toolchains::FreeBSD &ToolChain = static_cast<const toolchains::FreeBSD &>(getToolChain()); const Driver &D = ToolChain.getDriver(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); const bool IsPIE = !Args.hasArg(options::OPT_shared) && (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault()); ArgStringList CmdArgs; // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); // and "clang -emit-llvm foo.o -o foo" Args.ClaimAllArgs(options::OPT_emit_llvm); // and for "clang -w foo.o -o foo". Other warning options are already // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); if (IsPIE) CmdArgs.push_back("-pie"); if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); CmdArgs.push_back("--eh-frame-hdr"); if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-Bshareable"); } else { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/libexec/ld-elf.so.1"); } if (ToolChain.getTriple().getOSMajorVersion() >= 9) { if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc || Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) { CmdArgs.push_back("--hash-style=both"); } } CmdArgs.push_back("--enable-new-dtags"); } // When building 32-bit code on FreeBSD/amd64, we have to explicitly // instruct ld in the base system to link 32-bit code. if (Arch == llvm::Triple::x86) { CmdArgs.push_back("-m"); CmdArgs.push_back("elf_i386_fbsd"); } if (Arch == llvm::Triple::ppc) { CmdArgs.push_back("-m"); CmdArgs.push_back("elf32ppc_fbsd"); } if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { const char *crt1 = nullptr; if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) crt1 = "gcrt1.o"; else if (IsPIE) crt1 = "Scrt1.o"; else crt1 = "crt1.o"; } if (crt1) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); const char *crtbegin = nullptr; if (Args.hasArg(options::OPT_static)) crtbegin = "crtbeginT.o"; else if (Args.hasArg(options::OPT_shared) || IsPIE) crtbegin = "crtbeginS.o"; else crtbegin = "crtbegin.o"; CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); } Args.AddAllArgs(CmdArgs, options::OPT_L); const ToolChain::path_list &Paths = ToolChain.getFilePaths(); for (const auto &Path : Paths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); Args.AddAllArgs(CmdArgs, options::OPT_s); Args.AddAllArgs(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); Args.AddAllArgs(CmdArgs, options::OPT_r); if (D.IsUsingLTO(Args)) AddGoldPlugin(ToolChain, Args, CmdArgs); bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (D.CCCIsCXX()) { ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lm_p"); else CmdArgs.push_back("-lm"); } if (NeedsSanitizerDeps) linkSanitizerRuntimeDeps(ToolChain, CmdArgs); // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding // the default system libraries. Just mimic this for now. if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lgcc_p"); else CmdArgs.push_back("-lgcc"); if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-lgcc_eh"); } else if (Args.hasArg(options::OPT_pg)) { CmdArgs.push_back("-lgcc_eh_p"); } else { CmdArgs.push_back("--as-needed"); CmdArgs.push_back("-lgcc_s"); CmdArgs.push_back("--no-as-needed"); } if (Args.hasArg(options::OPT_pthread)) { if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lpthread_p"); else CmdArgs.push_back("-lpthread"); } if (Args.hasArg(options::OPT_pg)) { if (Args.hasArg(options::OPT_shared)) CmdArgs.push_back("-lc"); else CmdArgs.push_back("-lc_p"); CmdArgs.push_back("-lgcc_p"); } else { CmdArgs.push_back("-lc"); CmdArgs.push_back("-lgcc"); } if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-lgcc_eh"); } else if (Args.hasArg(options::OPT_pg)) { CmdArgs.push_back("-lgcc_eh_p"); } else { CmdArgs.push_back("--as-needed"); CmdArgs.push_back("-lgcc_s"); CmdArgs.push_back("--no-as-needed"); } } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (Args.hasArg(options::OPT_shared) || IsPIE) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); else CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); } addProfileRT(ToolChain, Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void netbsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; // GNU as needs different flags for creating the correct output format // on architectures with different ABIs or optional feature sets. switch (getToolChain().getArch()) { case llvm::Triple::x86: CmdArgs.push_back("--32"); break; case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: { StringRef MArch, MCPU; getARMArchCPUFromArgs(Args, MArch, MCPU, /*FromAs*/ true); std::string Arch = arm::getARMTargetCPU(MCPU, MArch, getToolChain().getTriple()); CmdArgs.push_back(Args.MakeArgString("-mcpu=" + Arch)); break; } case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: { StringRef CPUName; StringRef ABIName; mips::getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName); CmdArgs.push_back("-march"); CmdArgs.push_back(CPUName.data()); CmdArgs.push_back("-mabi"); CmdArgs.push_back(getGnuCompatibleMipsABIName(ABIName).data()); if (getToolChain().getArch() == llvm::Triple::mips || getToolChain().getArch() == llvm::Triple::mips64) CmdArgs.push_back("-EB"); else CmdArgs.push_back("-EL"); addAssemblerKPIC(Args, CmdArgs); break; } case llvm::Triple::sparc: case llvm::Triple::sparcel: CmdArgs.push_back("-32"); addAssemblerKPIC(Args, CmdArgs); break; case llvm::Triple::sparcv9: CmdArgs.push_back("-64"); CmdArgs.push_back("-Av9"); addAssemblerKPIC(Args, CmdArgs); break; default: break; } Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString((getToolChain().GetProgramPath("as"))); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); CmdArgs.push_back("--eh-frame-hdr"); if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-Bshareable"); } else { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/libexec/ld.elf_so"); } } // Many NetBSD architectures support more than one ABI. // Determine the correct emulation for ld. switch (getToolChain().getArch()) { case llvm::Triple::x86: CmdArgs.push_back("-m"); CmdArgs.push_back("elf_i386"); break; case llvm::Triple::arm: case llvm::Triple::thumb: CmdArgs.push_back("-m"); switch (getToolChain().getTriple().getEnvironment()) { case llvm::Triple::EABI: case llvm::Triple::GNUEABI: CmdArgs.push_back("armelf_nbsd_eabi"); break; case llvm::Triple::EABIHF: case llvm::Triple::GNUEABIHF: CmdArgs.push_back("armelf_nbsd_eabihf"); break; default: CmdArgs.push_back("armelf_nbsd"); break; } break; case llvm::Triple::armeb: case llvm::Triple::thumbeb: arm::appendEBLinkFlags( Args, CmdArgs, llvm::Triple(getToolChain().ComputeEffectiveClangTriple(Args))); CmdArgs.push_back("-m"); switch (getToolChain().getTriple().getEnvironment()) { case llvm::Triple::EABI: case llvm::Triple::GNUEABI: CmdArgs.push_back("armelfb_nbsd_eabi"); break; case llvm::Triple::EABIHF: case llvm::Triple::GNUEABIHF: CmdArgs.push_back("armelfb_nbsd_eabihf"); break; default: CmdArgs.push_back("armelfb_nbsd"); break; } break; case llvm::Triple::mips64: case llvm::Triple::mips64el: if (mips::hasMipsAbiArg(Args, "32")) { CmdArgs.push_back("-m"); if (getToolChain().getArch() == llvm::Triple::mips64) CmdArgs.push_back("elf32btsmip"); else CmdArgs.push_back("elf32ltsmip"); } else if (mips::hasMipsAbiArg(Args, "64")) { CmdArgs.push_back("-m"); if (getToolChain().getArch() == llvm::Triple::mips64) CmdArgs.push_back("elf64btsmip"); else CmdArgs.push_back("elf64ltsmip"); } break; case llvm::Triple::ppc: CmdArgs.push_back("-m"); CmdArgs.push_back("elf32ppc_nbsd"); break; case llvm::Triple::ppc64: case llvm::Triple::ppc64le: CmdArgs.push_back("-m"); CmdArgs.push_back("elf64ppc"); break; case llvm::Triple::sparc: CmdArgs.push_back("-m"); CmdArgs.push_back("elf32_sparc"); break; case llvm::Triple::sparcv9: CmdArgs.push_back("-m"); CmdArgs.push_back("elf64_sparc"); break; default: break; } if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) { CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crt0.o"))); CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); } else { CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); } } Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); Args.AddAllArgs(CmdArgs, options::OPT_s); Args.AddAllArgs(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); Args.AddAllArgs(CmdArgs, options::OPT_r); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); unsigned Major, Minor, Micro; getToolChain().getTriple().getOSVersion(Major, Minor, Micro); bool useLibgcc = true; if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 49) || Major == 0) { switch (getToolChain().getArch()) { case llvm::Triple::aarch64: case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: case llvm::Triple::ppc: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: case llvm::Triple::x86: case llvm::Triple::x86_64: useLibgcc = false; break; default: break; } } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } if (Args.hasArg(options::OPT_pthread)) CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-lc"); if (useLibgcc) { if (Args.hasArg(options::OPT_static)) { // libgcc_eh depends on libc, so resolve as much as possible, // pull in any new requirements from libc and then get the rest // of libgcc. CmdArgs.push_back("-lgcc_eh"); CmdArgs.push_back("-lc"); CmdArgs.push_back("-lgcc"); } else { CmdArgs.push_back("-lgcc"); CmdArgs.push_back("--as-needed"); CmdArgs.push_back("-lgcc_s"); CmdArgs.push_back("--no-as-needed"); } } } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtendS.o"))); CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); } addProfileRT(getToolChain(), Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void gnutools::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; bool NeedsKPIC = false; switch (getToolChain().getArch()) { default: break; // Add --32/--64 to make sure we get the format we want. // This is incomplete case llvm::Triple::x86: CmdArgs.push_back("--32"); break; case llvm::Triple::x86_64: if (getToolChain().getTriple().getEnvironment() == llvm::Triple::GNUX32) CmdArgs.push_back("--x32"); else CmdArgs.push_back("--64"); break; case llvm::Triple::ppc: CmdArgs.push_back("-a32"); CmdArgs.push_back("-mppc"); CmdArgs.push_back("-many"); break; case llvm::Triple::ppc64: CmdArgs.push_back("-a64"); CmdArgs.push_back("-mppc64"); CmdArgs.push_back("-many"); break; case llvm::Triple::ppc64le: CmdArgs.push_back("-a64"); CmdArgs.push_back("-mppc64"); CmdArgs.push_back("-many"); CmdArgs.push_back("-mlittle-endian"); break; case llvm::Triple::sparc: case llvm::Triple::sparcel: CmdArgs.push_back("-32"); CmdArgs.push_back("-Av8plusa"); NeedsKPIC = true; break; case llvm::Triple::sparcv9: CmdArgs.push_back("-64"); CmdArgs.push_back("-Av9a"); NeedsKPIC = true; break; case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: { const llvm::Triple &Triple = getToolChain().getTriple(); switch (Triple.getSubArch()) { case llvm::Triple::ARMSubArch_v7: CmdArgs.push_back("-mfpu=neon"); break; case llvm::Triple::ARMSubArch_v8: CmdArgs.push_back("-mfpu=crypto-neon-fp-armv8"); break; default: break; } StringRef ARMFloatABI = tools::arm::getARMFloatABI( getToolChain().getDriver(), Args, llvm::Triple(getToolChain().ComputeEffectiveClangTriple(Args))); CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=" + ARMFloatABI)); Args.AddLastArg(CmdArgs, options::OPT_march_EQ); // FIXME: remove krait check when GNU tools support krait cpu // for now replace it with -march=armv7-a to avoid a lower // march from being picked in the absence of a cpu flag. Arg *A; if ((A = Args.getLastArg(options::OPT_mcpu_EQ)) && StringRef(A->getValue()).lower() == "krait") CmdArgs.push_back("-march=armv7-a"); else Args.AddLastArg(CmdArgs, options::OPT_mcpu_EQ); Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ); break; } case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: { StringRef CPUName; StringRef ABIName; mips::getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName); ABIName = getGnuCompatibleMipsABIName(ABIName); CmdArgs.push_back("-march"); CmdArgs.push_back(CPUName.data()); CmdArgs.push_back("-mabi"); CmdArgs.push_back(ABIName.data()); // -mno-shared should be emitted unless -fpic, -fpie, -fPIC, -fPIE, // or -mshared (not implemented) is in effect. bool IsPicOrPie = false; if (Arg *A = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, options::OPT_fpic, options::OPT_fno_pic, options::OPT_fPIE, options::OPT_fno_PIE, options::OPT_fpie, options::OPT_fno_pie)) { if (A->getOption().matches(options::OPT_fPIC) || A->getOption().matches(options::OPT_fpic) || A->getOption().matches(options::OPT_fPIE) || A->getOption().matches(options::OPT_fpie)) IsPicOrPie = true; } if (!IsPicOrPie) CmdArgs.push_back("-mno-shared"); // LLVM doesn't support -mplt yet and acts as if it is always given. // However, -mplt has no effect with the N64 ABI. CmdArgs.push_back(ABIName == "64" ? "-KPIC" : "-call_nonpic"); if (getToolChain().getArch() == llvm::Triple::mips || getToolChain().getArch() == llvm::Triple::mips64) CmdArgs.push_back("-EB"); else CmdArgs.push_back("-EL"); if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) { if (StringRef(A->getValue()) == "2008") CmdArgs.push_back(Args.MakeArgString("-mnan=2008")); } // Add the last -mfp32/-mfpxx/-mfp64 or -mfpxx if it is enabled by default. StringRef MIPSFloatABI = getMipsFloatABI(getToolChain().getDriver(), Args); if (Arg *A = Args.getLastArg(options::OPT_mfp32, options::OPT_mfpxx, options::OPT_mfp64)) { A->claim(); A->render(Args, CmdArgs); } else if (mips::shouldUseFPXX(Args, getToolChain().getTriple(), CPUName, ABIName, MIPSFloatABI)) CmdArgs.push_back("-mfpxx"); // Pass on -mmips16 or -mno-mips16. However, the assembler equivalent of // -mno-mips16 is actually -no-mips16. if (Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16)) { if (A->getOption().matches(options::OPT_mips16)) { A->claim(); A->render(Args, CmdArgs); } else { A->claim(); CmdArgs.push_back("-no-mips16"); } } Args.AddLastArg(CmdArgs, options::OPT_mmicromips, options::OPT_mno_micromips); Args.AddLastArg(CmdArgs, options::OPT_mdsp, options::OPT_mno_dsp); Args.AddLastArg(CmdArgs, options::OPT_mdspr2, options::OPT_mno_dspr2); if (Arg *A = Args.getLastArg(options::OPT_mmsa, options::OPT_mno_msa)) { // Do not use AddLastArg because not all versions of MIPS assembler // support -mmsa / -mno-msa options. if (A->getOption().matches(options::OPT_mmsa)) CmdArgs.push_back(Args.MakeArgString("-mmsa")); } Args.AddLastArg(CmdArgs, options::OPT_mhard_float, options::OPT_msoft_float); Args.AddLastArg(CmdArgs, options::OPT_mdouble_float, options::OPT_msingle_float); Args.AddLastArg(CmdArgs, options::OPT_modd_spreg, options::OPT_mno_odd_spreg); NeedsKPIC = true; break; } case llvm::Triple::systemz: { // Always pass an -march option, since our default of z10 is later // than the GNU assembler's default. StringRef CPUName = getSystemZTargetCPU(Args); CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName)); break; } } if (NeedsKPIC) addAssemblerKPIC(Args, CmdArgs); Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); // Handle the debug info splitting at object creation time if we're // creating an object. // TODO: Currently only works on linux with newer objcopy. if (Args.hasArg(options::OPT_gsplit_dwarf) && getToolChain().getTriple().isOSLinux()) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDebugName(Args, Inputs[0])); } static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args) { bool isAndroid = Triple.getEnvironment() == llvm::Triple::Android; bool isCygMing = Triple.isOSCygMing(); bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) || Args.hasArg(options::OPT_static); if (!D.CCCIsCXX()) CmdArgs.push_back("-lgcc"); if (StaticLibgcc || isAndroid) { if (D.CCCIsCXX()) CmdArgs.push_back("-lgcc"); } else { if (!D.CCCIsCXX() && !isCygMing) CmdArgs.push_back("--as-needed"); CmdArgs.push_back("-lgcc_s"); if (!D.CCCIsCXX() && !isCygMing) CmdArgs.push_back("--no-as-needed"); } if (StaticLibgcc && !isAndroid) CmdArgs.push_back("-lgcc_eh"); else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX()) CmdArgs.push_back("-lgcc"); // According to Android ABI, we have to link with libdl if we are // linking with non-static libgcc. // // NOTE: This fixes a link error on Android MIPS as well. The non-static // libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl. if (isAndroid && !StaticLibgcc) CmdArgs.push_back("-ldl"); } static std::string getLinuxDynamicLinker(const ArgList &Args, const toolchains::Linux &ToolChain) { const llvm::Triple::ArchType Arch = ToolChain.getArch(); if (ToolChain.getTriple().getEnvironment() == llvm::Triple::Android) { if (ToolChain.getTriple().isArch64Bit()) return "/system/bin/linker64"; else return "/system/bin/linker"; } else if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcel) return "/lib/ld-linux.so.2"; else if (Arch == llvm::Triple::aarch64) return "/lib/ld-linux-aarch64.so.1"; else if (Arch == llvm::Triple::aarch64_be) return "/lib/ld-linux-aarch64_be.so.1"; else if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) { if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF || tools::arm::getARMFloatABI(ToolChain.getDriver(), Args, ToolChain.getTriple()) == "hard") return "/lib/ld-linux-armhf.so.3"; else return "/lib/ld-linux.so.3"; } else if (Arch == llvm::Triple::armeb || Arch == llvm::Triple::thumbeb) { // TODO: check which dynamic linker name. if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF || tools::arm::getARMFloatABI(ToolChain.getDriver(), Args, ToolChain.getTriple()) == "hard") return "/lib/ld-linux-armhf.so.3"; else return "/lib/ld-linux.so.3"; } else if (Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el) { StringRef CPUName; StringRef ABIName; mips::getMipsCPUAndABI(Args, ToolChain.getTriple(), CPUName, ABIName); bool IsNaN2008 = mips::isNaN2008(Args, ToolChain.getTriple()); StringRef LibDir = llvm::StringSwitch<llvm::StringRef>(ABIName) .Case("o32", "/lib") .Case("n32", "/lib32") .Case("n64", "/lib64") .Default("/lib"); StringRef LibName; if (mips::isUCLibc(Args)) LibName = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0"; else LibName = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1"; return (LibDir + "/" + LibName).str(); } else if (Arch == llvm::Triple::ppc) return "/lib/ld.so.1"; else if (Arch == llvm::Triple::ppc64) { if (ppc::hasPPCAbiArg(Args, "elfv2")) return "/lib64/ld64.so.2"; return "/lib64/ld64.so.1"; } else if (Arch == llvm::Triple::ppc64le) { if (ppc::hasPPCAbiArg(Args, "elfv1")) return "/lib64/ld64.so.1"; return "/lib64/ld64.so.2"; } else if (Arch == llvm::Triple::systemz) return "/lib64/ld64.so.1"; else if (Arch == llvm::Triple::sparcv9) return "/lib64/ld-linux.so.2"; else if (Arch == llvm::Triple::x86_64 && ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUX32) return "/libx32/ld-linux-x32.so.2"; else return "/lib64/ld-linux-x86-64.so.2"; } static void AddRunTimeLibs(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args) { // Make use of compiler-rt if --rtlib option is used ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(Args); switch (RLT) { case ToolChain::RLT_CompilerRT: switch (TC.getTriple().getOS()) { default: llvm_unreachable("unsupported OS"); case llvm::Triple::Win32: case llvm::Triple::Linux: addClangRT(TC, Args, CmdArgs); break; } break; case ToolChain::RLT_Libgcc: AddLibgcc(TC.getTriple(), D, CmdArgs, Args); break; } } static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) { switch (T.getArch()) { case llvm::Triple::x86: return "elf_i386"; case llvm::Triple::aarch64: return "aarch64linux"; case llvm::Triple::aarch64_be: return "aarch64_be_linux"; case llvm::Triple::arm: case llvm::Triple::thumb: return "armelf_linux_eabi"; case llvm::Triple::armeb: case llvm::Triple::thumbeb: return "armebelf_linux_eabi"; /* TODO: check which NAME. */ case llvm::Triple::ppc: return "elf32ppclinux"; case llvm::Triple::ppc64: return "elf64ppc"; case llvm::Triple::ppc64le: return "elf64lppc"; case llvm::Triple::sparc: case llvm::Triple::sparcel: return "elf32_sparc"; case llvm::Triple::sparcv9: return "elf64_sparc"; case llvm::Triple::mips: return "elf32btsmip"; case llvm::Triple::mipsel: return "elf32ltsmip"; case llvm::Triple::mips64: if (mips::hasMipsAbiArg(Args, "n32")) return "elf32btsmipn32"; return "elf64btsmip"; case llvm::Triple::mips64el: if (mips::hasMipsAbiArg(Args, "n32")) return "elf32ltsmipn32"; return "elf64ltsmip"; case llvm::Triple::systemz: return "elf64_s390"; case llvm::Triple::x86_64: if (T.getEnvironment() == llvm::Triple::GNUX32) return "elf32_x86_64"; return "elf_x86_64"; default: llvm_unreachable("Unexpected arch"); } } void gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const toolchains::Linux &ToolChain = static_cast<const toolchains::Linux &>(getToolChain()); const Driver &D = ToolChain.getDriver(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); const bool isAndroid = ToolChain.getTriple().getEnvironment() == llvm::Triple::Android; const bool IsPIE = !Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_static) && (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault()); ArgStringList CmdArgs; // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); // and "clang -emit-llvm foo.o -o foo" Args.ClaimAllArgs(options::OPT_emit_llvm); // and for "clang -w foo.o -o foo". Other warning options are already // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); if (IsPIE) CmdArgs.push_back("-pie"); if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_s)) CmdArgs.push_back("-s"); if (Arch == llvm::Triple::armeb || Arch == llvm::Triple::thumbeb) arm::appendEBLinkFlags( Args, CmdArgs, llvm::Triple(getToolChain().ComputeEffectiveClangTriple(Args))); for (const auto &Opt : ToolChain.ExtraOpts) CmdArgs.push_back(Opt.c_str()); if (!Args.hasArg(options::OPT_static)) { CmdArgs.push_back("--eh-frame-hdr"); } CmdArgs.push_back("-m"); CmdArgs.push_back(getLDMOption(ToolChain.getTriple(), Args)); if (Args.hasArg(options::OPT_static)) { if (Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb || Arch == llvm::Triple::thumb || Arch == llvm::Triple::thumbeb) CmdArgs.push_back("-Bstatic"); else CmdArgs.push_back("-static"); } else if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-shared"); } if (Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb || Arch == llvm::Triple::thumb || Arch == llvm::Triple::thumbeb || (!Args.hasArg(options::OPT_static) && !Args.hasArg(options::OPT_shared))) { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back(Args.MakeArgString( D.DyldPrefix + getLinuxDynamicLinker(Args, ToolChain))); } CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!isAndroid) { const char *crt1 = nullptr; if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) crt1 = "gcrt1.o"; else if (IsPIE) crt1 = "Scrt1.o"; else crt1 = "crt1.o"; } if (crt1) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); } const char *crtbegin; if (Args.hasArg(options::OPT_static)) crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o"; else if (Args.hasArg(options::OPT_shared)) crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o"; else if (IsPIE) crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o"; else crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o"; CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); // Add crtfastmath.o if available and fast math is enabled. ToolChain.AddFastMathRuntimeIfAvailable(Args, CmdArgs); } Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_u); const ToolChain::path_list &Paths = ToolChain.getFilePaths(); for (const auto &Path : Paths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); if (D.IsUsingLTO(Args)) AddGoldPlugin(ToolChain, Args, CmdArgs); if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) CmdArgs.push_back("--no-demangle"); bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); // The profile runtime also needs access to system libraries. addProfileRT(getToolChain(), Args, CmdArgs); if (D.CCCIsCXX() && !Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && !Args.hasArg(options::OPT_static); if (OnlyLibstdcxxStatic) CmdArgs.push_back("-Bstatic"); ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); if (OnlyLibstdcxxStatic) CmdArgs.push_back("-Bdynamic"); CmdArgs.push_back("-lm"); } // Silence warnings when linking C code with a C++ '-stdlib' argument. Args.ClaimAllArgs(options::OPT_stdlib_EQ); if (!Args.hasArg(options::OPT_nostdlib)) { if (!Args.hasArg(options::OPT_nodefaultlibs)) { if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("--start-group"); if (NeedsSanitizerDeps) linkSanitizerRuntimeDeps(ToolChain, CmdArgs); bool WantPthread = Args.hasArg(options::OPT_pthread) || Args.hasArg(options::OPT_pthreads); if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, options::OPT_fno_openmp, false)) { // OpenMP runtimes implies pthreads when using the GNU toolchain. // FIXME: Does this really make sense for all GNU toolchains? WantPthread = true; // Also link the particular OpenMP runtimes. switch (getOpenMPRuntime(ToolChain, Args)) { case OMPRT_OMP: CmdArgs.push_back("-lomp"); break; case OMPRT_GOMP: CmdArgs.push_back("-lgomp"); // FIXME: Exclude this for platforms with libgomp that don't require // librt. Most modern Linux platforms require it, but some may not. CmdArgs.push_back("-lrt"); break; case OMPRT_IOMP5: CmdArgs.push_back("-liomp5"); break; case OMPRT_Unknown: // Already diagnosed. break; } } AddRunTimeLibs(ToolChain, D, CmdArgs, Args); if (WantPthread && !isAndroid) CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-lc"); if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("--end-group"); else AddRunTimeLibs(ToolChain, D, CmdArgs, Args); } if (!Args.hasArg(options::OPT_nostartfiles)) { const char *crtend; if (Args.hasArg(options::OPT_shared)) crtend = isAndroid ? "crtend_so.o" : "crtendS.o"; else if (IsPIE) crtend = isAndroid ? "crtend_android.o" : "crtendS.o"; else crtend = isAndroid ? "crtend_android.o" : "crtend.o"; CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); if (!isAndroid) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); } } C.addCommand( llvm::make_unique<Command>(JA, *this, ToolChain.Linker.c_str(), CmdArgs)); } // NaCl ARM assembly (inline or standalone) can be written with a set of macros // for the various SFI requirements like register masking. The assembly tool // inserts the file containing the macros as an input into all the assembly // jobs. void nacltools::AssemblerARM::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const toolchains::NaCl_TC &ToolChain = static_cast<const toolchains::NaCl_TC &>(getToolChain()); InputInfo NaClMacros(ToolChain.GetNaClArmMacrosPath(), types::TY_PP_Asm, "nacl-arm-macros.s"); InputInfoList NewInputs; NewInputs.push_back(NaClMacros); NewInputs.append(Inputs.begin(), Inputs.end()); gnutools::Assembler::ConstructJob(C, JA, Output, NewInputs, Args, LinkingOutput); } // This is quite similar to gnutools::Linker::ConstructJob with changes that // we use static by default, do not yet support sanitizers or LTO, and a few // others. Eventually we can support more of that and hopefully migrate back // to gnutools::Linker. void nacltools::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const toolchains::NaCl_TC &ToolChain = static_cast<const toolchains::NaCl_TC &>(getToolChain()); const Driver &D = ToolChain.getDriver(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); const bool IsStatic = !Args.hasArg(options::OPT_dynamic) && !Args.hasArg(options::OPT_shared); ArgStringList CmdArgs; // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); // and "clang -emit-llvm foo.o -o foo" Args.ClaimAllArgs(options::OPT_emit_llvm); // and for "clang -w foo.o -o foo". Other warning options are already // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_s)) CmdArgs.push_back("-s"); // NaCl_TC doesn't have ExtraOpts like Linux; the only relevant flag from // there is --build-id, which we do want. CmdArgs.push_back("--build-id"); if (!IsStatic) CmdArgs.push_back("--eh-frame-hdr"); CmdArgs.push_back("-m"); if (Arch == llvm::Triple::x86) CmdArgs.push_back("elf_i386_nacl"); else if (Arch == llvm::Triple::arm) CmdArgs.push_back("armelf_nacl"); else if (Arch == llvm::Triple::x86_64) CmdArgs.push_back("elf_x86_64_nacl"); else if (Arch == llvm::Triple::mipsel) CmdArgs.push_back("mipselelf_nacl"); else D.Diag(diag::err_target_unsupported_arch) << ToolChain.getArchName() << "Native Client"; if (IsStatic) CmdArgs.push_back("-static"); else if (Args.hasArg(options::OPT_shared)) CmdArgs.push_back("-shared"); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o"))); CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); const char *crtbegin; if (IsStatic) crtbegin = "crtbeginT.o"; else if (Args.hasArg(options::OPT_shared)) crtbegin = "crtbeginS.o"; else crtbegin = "crtbegin.o"; CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); } Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_u); const ToolChain::path_list &Paths = ToolChain.getFilePaths(); for (const auto &Path : Paths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) CmdArgs.push_back("--no-demangle"); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); if (D.CCCIsCXX() && !Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && !IsStatic; if (OnlyLibstdcxxStatic) CmdArgs.push_back("-Bstatic"); ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); if (OnlyLibstdcxxStatic) CmdArgs.push_back("-Bdynamic"); CmdArgs.push_back("-lm"); } if (!Args.hasArg(options::OPT_nostdlib)) { if (!Args.hasArg(options::OPT_nodefaultlibs)) { // Always use groups, since it has no effect on dynamic libraries. CmdArgs.push_back("--start-group"); CmdArgs.push_back("-lc"); // NaCl's libc++ currently requires libpthread, so just always include it // in the group for C++. if (Args.hasArg(options::OPT_pthread) || Args.hasArg(options::OPT_pthreads) || D.CCCIsCXX()) { // Gold, used by Mips, handles nested groups differently than ld, and // without '-lnacl' it prefers symbols from libpthread.a over libnacl.a, // which is not a desired behaviour here. // See https://sourceware.org/ml/binutils/2015-03/msg00034.html if (getToolChain().getArch() == llvm::Triple::mipsel) CmdArgs.push_back("-lnacl"); CmdArgs.push_back("-lpthread"); } CmdArgs.push_back("-lgcc"); CmdArgs.push_back("--as-needed"); if (IsStatic) CmdArgs.push_back("-lgcc_eh"); else CmdArgs.push_back("-lgcc_s"); CmdArgs.push_back("--no-as-needed"); // Mips needs to create and use pnacl_legacy library that contains // definitions from bitcode/pnaclmm.c and definitions for // __nacl_tp_tls_offset() and __nacl_tp_tdb_offset(). if (getToolChain().getArch() == llvm::Triple::mipsel) CmdArgs.push_back("-lpnacl_legacy"); CmdArgs.push_back("--end-group"); } if (!Args.hasArg(options::OPT_nostartfiles)) { const char *crtend; if (Args.hasArg(options::OPT_shared)) crtend = "crtendS.o"; else crtend = "crtend.o"; CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); } } C.addCommand( llvm::make_unique<Command>(JA, *this, ToolChain.Linker.c_str(), CmdArgs)); } void minix::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void minix::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); } Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); addProfileRT(getToolChain(), Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (Args.hasArg(options::OPT_pthread)) CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-lc"); CmdArgs.push_back("-lCompilerRT-Generic"); CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib"); CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); } const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } /// DragonFly Tools // For now, DragonFly Assemble does just about the same as for // FreeBSD, but this may change soon. void dragonfly::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; // When building 32-bit code on DragonFly/pc64, we have to explicitly // instruct as in the base system to assemble 32-bit code. if (getToolChain().getArch() == llvm::Triple::x86) CmdArgs.push_back("--32"); Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; bool UseGCC47 = llvm::sys::fs::exists("/usr/lib/gcc47"); if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); CmdArgs.push_back("--eh-frame-hdr"); if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else { if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_shared)) CmdArgs.push_back("-Bshareable"); else { CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/usr/libexec/ld-elf.so.2"); } CmdArgs.push_back("--hash-style=both"); } // When building 32-bit code on DragonFly/pc64, we have to explicitly // instruct ld in the base system to link 32-bit code. if (getToolChain().getArch() == llvm::Triple::x86) { CmdArgs.push_back("-m"); CmdArgs.push_back("elf_i386"); } if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("gcrt1.o"))); else { if (Args.hasArg(options::OPT_pie)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("Scrt1.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); } } CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); } Args.AddAllArgs(CmdArgs, options::OPT_L); Args.AddAllArgs(CmdArgs, options::OPT_T_Group); Args.AddAllArgs(CmdArgs, options::OPT_e); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of // rpaths if (UseGCC47) CmdArgs.push_back("-L/usr/lib/gcc47"); else CmdArgs.push_back("-L/usr/lib/gcc44"); if (!Args.hasArg(options::OPT_static)) { if (UseGCC47) { CmdArgs.push_back("-rpath"); CmdArgs.push_back("/usr/lib/gcc47"); } else { CmdArgs.push_back("-rpath"); CmdArgs.push_back("/usr/lib/gcc44"); } } if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } if (Args.hasArg(options::OPT_pthread)) CmdArgs.push_back("-lpthread"); if (!Args.hasArg(options::OPT_nolibc)) { CmdArgs.push_back("-lc"); } if (UseGCC47) { if (Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_libgcc)) { CmdArgs.push_back("-lgcc"); CmdArgs.push_back("-lgcc_eh"); } else { if (Args.hasArg(options::OPT_shared_libgcc)) { CmdArgs.push_back("-lgcc_pic"); if (!Args.hasArg(options::OPT_shared)) CmdArgs.push_back("-lgcc"); } else { CmdArgs.push_back("-lgcc"); CmdArgs.push_back("--as-needed"); CmdArgs.push_back("-lgcc_pic"); CmdArgs.push_back("--no-as-needed"); } } } else { if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-lgcc_pic"); } else { CmdArgs.push_back("-lgcc"); } } } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtendS.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); } addProfileRT(getToolChain(), Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } // Try to find Exe from a Visual Studio distribution. This first tries to find // an installed copy of Visual Studio and, failing that, looks in the PATH, // making sure that whatever executable that's found is not a same-named exe // from clang itself to prevent clang from falling back to itself. static std::string FindVisualStudioExecutable(const ToolChain &TC, const char *Exe, const char *ClangProgramPath) { const auto &MSVC = static_cast<const toolchains::MSVCToolChain &>(TC); std::string visualStudioBinDir; if (MSVC.getVisualStudioBinariesFolder(ClangProgramPath, visualStudioBinDir)) { SmallString<128> FilePath(visualStudioBinDir); llvm::sys::path::append(FilePath, Exe); if (llvm::sys::fs::can_execute(FilePath.c_str())) return FilePath.str(); } return Exe; } void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; const ToolChain &TC = getToolChain(); assert((Output.isFilename() || Output.isNothing()) && "invalid output"); if (Output.isFilename()) CmdArgs.push_back( Args.MakeArgString(std::string("-out:") + Output.getFilename())); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles) && !C.getDriver().IsCLMode()) CmdArgs.push_back("-defaultlib:libcmt"); if (!llvm::sys::Process::GetEnv("LIB")) { // If the VC environment hasn't been configured (perhaps because the user // did not run vcvarsall), try to build a consistent link environment. If // the environment variable is set however, assume the user knows what // they're doing. std::string VisualStudioDir; const auto &MSVC = static_cast<const toolchains::MSVCToolChain &>(TC); if (MSVC.getVisualStudioInstallDir(VisualStudioDir)) { SmallString<128> LibDir(VisualStudioDir); llvm::sys::path::append(LibDir, "VC", "lib"); switch (MSVC.getArch()) { case llvm::Triple::x86: // x86 just puts the libraries directly in lib break; case llvm::Triple::x86_64: llvm::sys::path::append(LibDir, "amd64"); break; case llvm::Triple::arm: llvm::sys::path::append(LibDir, "arm"); break; default: break; } CmdArgs.push_back( Args.MakeArgString(std::string("-libpath:") + LibDir.c_str())); } std::string WindowsSdkLibPath; if (MSVC.getWindowsSDKLibraryPath(WindowsSdkLibPath)) CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath.c_str())); } CmdArgs.push_back("-nologo"); if (Args.hasArg(options::OPT_g_Group)) CmdArgs.push_back("-debug"); bool DLL = Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd, options::OPT_shared); if (DLL) { CmdArgs.push_back(Args.MakeArgString("-dll")); SmallString<128> ImplibName(Output.getFilename()); llvm::sys::path::replace_extension(ImplibName, "lib"); CmdArgs.push_back(Args.MakeArgString(std::string("-implib:") + ImplibName)); } if (TC.getSanitizerArgs().needsAsanRt()) { CmdArgs.push_back(Args.MakeArgString("-debug")); CmdArgs.push_back(Args.MakeArgString("-incremental:no")); if (Args.hasArg(options::OPT__SLASH_MD, options::OPT__SLASH_MDd)) { static const char *CompilerRTComponents[] = { "asan_dynamic", "asan_dynamic_runtime_thunk", }; for (const auto &Component : CompilerRTComponents) CmdArgs.push_back(Args.MakeArgString(getCompilerRT(TC, Component))); // Make sure the dynamic runtime thunk is not optimized out at link time // to ensure proper SEH handling. CmdArgs.push_back(Args.MakeArgString("-include:___asan_seh_interceptor")); } else if (DLL) { CmdArgs.push_back( Args.MakeArgString(getCompilerRT(TC, "asan_dll_thunk"))); } else { static const char *CompilerRTComponents[] = { "asan", "asan_cxx", }; for (const auto &Component : CompilerRTComponents) CmdArgs.push_back(Args.MakeArgString(getCompilerRT(TC, Component))); } } Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); // Add filenames, libraries, and other linker inputs. for (const auto &Input : Inputs) { if (Input.isFilename()) { CmdArgs.push_back(Input.getFilename()); continue; } const Arg &A = Input.getInputArg(); // Render -l options differently for the MSVC linker. if (A.getOption().matches(options::OPT_l)) { StringRef Lib = A.getValue(); const char *LinkLibArg; if (Lib.endswith(".lib")) LinkLibArg = Args.MakeArgString(Lib); else LinkLibArg = Args.MakeArgString(Lib + ".lib"); CmdArgs.push_back(LinkLibArg); continue; } // Otherwise, this is some other kind of linker input option like -Wl, -z, // or -L. Render it, even if MSVC doesn't understand it. A.renderAsInput(Args, CmdArgs); } // We need to special case some linker paths. In the case of lld, we need to // translate 'lld' into 'lld-link', and in the case of the regular msvc // linker, we need to use a special search algorithm. llvm::SmallString<128> linkPath; StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "link"); if (Linker.equals_lower("lld")) Linker = "lld-link"; if (Linker.equals_lower("link")) { // If we're using the MSVC linker, it's not sufficient to just use link // from the program PATH, because other environments like GnuWin32 install // their own link.exe which may come first. linkPath = FindVisualStudioExecutable(TC, "link.exe", C.getDriver().getClangProgramPath()); } else { linkPath = Linker; llvm::sys::path::replace_extension(linkPath, "exe"); linkPath = TC.GetProgramPath(linkPath.c_str()); } const char *Exec = Args.MakeArgString(linkPath); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void visualstudio::Compiler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { C.addCommand(GetCommand(C, JA, Output, Inputs, Args, LinkingOutput)); } std::unique_ptr<Command> visualstudio::Compiler::GetCommand( Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; CmdArgs.push_back("/nologo"); CmdArgs.push_back("/c"); // Compile only. CmdArgs.push_back("/W0"); // No warnings. // The goal is to be able to invoke this tool correctly based on // any flag accepted by clang-cl. // These are spelled the same way in clang and cl.exe,. Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); Args.AddAllArgs(CmdArgs, options::OPT_I); // Optimization level. if (Arg *A = Args.getLastArg(options::OPT_O, options::OPT_O0)) { if (A->getOption().getID() == options::OPT_O0) { CmdArgs.push_back("/Od"); } else { StringRef OptLevel = A->getValue(); if (OptLevel == "1" || OptLevel == "2" || OptLevel == "s") A->render(Args, CmdArgs); else if (OptLevel == "3") CmdArgs.push_back("/Ox"); } } // Flags for which clang-cl has an alias. // FIXME: How can we ensure this stays in sync with relevant clang-cl options? if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR, /*default=*/false)) CmdArgs.push_back("/GR-"); if (Arg *A = Args.getLastArg(options::OPT_ffunction_sections, options::OPT_fno_function_sections)) CmdArgs.push_back(A->getOption().getID() == options::OPT_ffunction_sections ? "/Gy" : "/Gy-"); if (Arg *A = Args.getLastArg(options::OPT_fdata_sections, options::OPT_fno_data_sections)) CmdArgs.push_back( A->getOption().getID() == options::OPT_fdata_sections ? "/Gw" : "/Gw-"); if (Args.hasArg(options::OPT_fsyntax_only)) CmdArgs.push_back("/Zs"); if (Args.hasArg(options::OPT_g_Flag, options::OPT_gline_tables_only)) CmdArgs.push_back("/Z7"); std::vector<std::string> Includes = Args.getAllArgValues(options::OPT_include); for (const auto &Include : Includes) CmdArgs.push_back(Args.MakeArgString(std::string("/FI") + Include)); // Flags that can simply be passed through. Args.AddAllArgs(CmdArgs, options::OPT__SLASH_LD); Args.AddAllArgs(CmdArgs, options::OPT__SLASH_LDd); Args.AddAllArgs(CmdArgs, options::OPT__SLASH_EH); // The order of these flags is relevant, so pick the last one. if (Arg *A = Args.getLastArg(options::OPT__SLASH_MD, options::OPT__SLASH_MDd, options::OPT__SLASH_MT, options::OPT__SLASH_MTd)) A->render(Args, CmdArgs); // Input filename. assert(Inputs.size() == 1); const InputInfo &II = Inputs[0]; assert(II.getType() == types::TY_C || II.getType() == types::TY_CXX); CmdArgs.push_back(II.getType() == types::TY_C ? "/Tc" : "/Tp"); if (II.isFilename()) CmdArgs.push_back(II.getFilename()); else II.getInputArg().renderAsInput(Args, CmdArgs); // Output filename. assert(Output.getType() == types::TY_Object); const char *Fo = Args.MakeArgString(std::string("/Fo") + Output.getFilename()); CmdArgs.push_back(Fo); const Driver &D = getToolChain().getDriver(); std::string Exec = FindVisualStudioExecutable(getToolChain(), "cl.exe", D.getClangProgramPath()); return llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Exec), CmdArgs); } /// MinGW Tools void MinGW::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; if (getToolChain().getArch() == llvm::Triple::x86) { CmdArgs.push_back("--32"); } else if (getToolChain().getArch() == llvm::Triple::x86_64) { CmdArgs.push_back("--64"); } Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); if (Args.hasArg(options::OPT_gsplit_dwarf)) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDebugName(Args, Inputs[0])); } void MinGW::Linker::AddLibGCC(const ArgList &Args, ArgStringList &CmdArgs) const { if (Args.hasArg(options::OPT_mthreads)) CmdArgs.push_back("-lmingwthrd"); CmdArgs.push_back("-lmingw32"); // Add libgcc or compiler-rt. AddRunTimeLibs(getToolChain(), getToolChain().getDriver(), CmdArgs, Args); CmdArgs.push_back("-lmoldname"); CmdArgs.push_back("-lmingwex"); CmdArgs.push_back("-lmsvcrt"); } void MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const ToolChain &TC = getToolChain(); const Driver &D = TC.getDriver(); // const SanitizerArgs &Sanitize = TC.getSanitizerArgs(); ArgStringList CmdArgs; // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); // and "clang -emit-llvm foo.o -o foo" Args.ClaimAllArgs(options::OPT_emit_llvm); // and for "clang -w foo.o -o foo". Other warning options are already // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); StringRef LinkerName = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "ld"); if (LinkerName.equals_lower("lld")) { CmdArgs.push_back("-flavor"); CmdArgs.push_back("gnu"); } if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); if (Args.hasArg(options::OPT_s)) CmdArgs.push_back("-s"); CmdArgs.push_back("-m"); if (TC.getArch() == llvm::Triple::x86) CmdArgs.push_back("i386pe"); if (TC.getArch() == llvm::Triple::x86_64) CmdArgs.push_back("i386pep"); if (TC.getArch() == llvm::Triple::arm) CmdArgs.push_back("thumb2pe"); if (Args.hasArg(options::OPT_mwindows)) { CmdArgs.push_back("--subsystem"); CmdArgs.push_back("windows"); } else if (Args.hasArg(options::OPT_mconsole)) { CmdArgs.push_back("--subsystem"); CmdArgs.push_back("console"); } if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("-Bstatic"); else { if (Args.hasArg(options::OPT_mdll)) CmdArgs.push_back("--dll"); else if (Args.hasArg(options::OPT_shared)) CmdArgs.push_back("--shared"); CmdArgs.push_back("-Bdynamic"); if (Args.hasArg(options::OPT_mdll) || Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-e"); if (TC.getArch() == llvm::Triple::x86) CmdArgs.push_back("_DllMainCRTStartup@12"); else CmdArgs.push_back("DllMainCRTStartup"); CmdArgs.push_back("--enable-auto-image-base"); } } CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); Args.AddAllArgs(CmdArgs, options::OPT_e); // FIXME: add -N, -n flags Args.AddLastArg(CmdArgs, options::OPT_r); Args.AddLastArg(CmdArgs, options::OPT_s); Args.AddLastArg(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_u_Group); Args.AddLastArg(CmdArgs, options::OPT_Z_Flag); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_mdll)) { CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("dllcrt2.o"))); } else { if (Args.hasArg(options::OPT_municode)) CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2u.o"))); else CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2.o"))); } if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("gcrt2.o"))); CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtbegin.o"))); } Args.AddAllArgs(CmdArgs, options::OPT_L); const ToolChain::path_list Paths = TC.getFilePaths(); for (const auto &Path : Paths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); AddLinkerInputs(TC, Inputs, Args, CmdArgs); // TODO: Add ASan stuff here // TODO: Add profile stuff here if (D.CCCIsCXX() && !Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && !Args.hasArg(options::OPT_static); if (OnlyLibstdcxxStatic) CmdArgs.push_back("-Bstatic"); TC.AddCXXStdlibLibArgs(Args, CmdArgs); if (OnlyLibstdcxxStatic) CmdArgs.push_back("-Bdynamic"); } if (!Args.hasArg(options::OPT_nostdlib)) { if (!Args.hasArg(options::OPT_nodefaultlibs)) { if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("--start-group"); if (Args.hasArg(options::OPT_fstack_protector) || Args.hasArg(options::OPT_fstack_protector_strong) || Args.hasArg(options::OPT_fstack_protector_all)) { CmdArgs.push_back("-lssp_nonshared"); CmdArgs.push_back("-lssp"); } if (Args.hasArg(options::OPT_fopenmp)) CmdArgs.push_back("-lgomp"); AddLibGCC(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lgmon"); if (Args.hasArg(options::OPT_pthread)) CmdArgs.push_back("-lpthread"); // add system libraries if (Args.hasArg(options::OPT_mwindows)) { CmdArgs.push_back("-lgdi32"); CmdArgs.push_back("-lcomdlg32"); } CmdArgs.push_back("-ladvapi32"); CmdArgs.push_back("-lshell32"); CmdArgs.push_back("-luser32"); CmdArgs.push_back("-lkernel32"); if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("--end-group"); else if (!LinkerName.equals_lower("lld")) AddLibGCC(Args, CmdArgs); } if (!Args.hasArg(options::OPT_nostartfiles)) { // Add crtfastmath.o if available and fast math is enabled. TC.AddFastMathRuntimeIfAvailable(Args, CmdArgs); CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtend.o"))); } } const char *Exec = Args.MakeArgString(TC.GetProgramPath(LinkerName.data())); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } /// XCore Tools // We pass assemble and link construction to the xcc tool. void XCore::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); ArgStringList CmdArgs; CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); CmdArgs.push_back("-c"); if (Args.hasArg(options::OPT_v)) CmdArgs.push_back("-v"); if (Arg *A = Args.getLastArg(options::OPT_g_Group)) if (!A->getOption().matches(options::OPT_g0)) CmdArgs.push_back("-g"); if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm, false)) CmdArgs.push_back("-fverbose-asm"); Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void XCore::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; if (Output.isFilename()) { CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); } else { assert(Output.isNothing() && "Invalid output."); } if (Args.hasArg(options::OPT_v)) CmdArgs.push_back("-v"); // Pass -fexceptions through to the linker if it was present. if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, false)) CmdArgs.push_back("-fexceptions"); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void CrossWindows::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { claimNoWarnArgs(Args); const auto &TC = static_cast<const toolchains::CrossWindowsToolChain &>(getToolChain()); ArgStringList CmdArgs; const char *Exec; switch (TC.getArch()) { default: llvm_unreachable("unsupported architecture"); case llvm::Triple::arm: case llvm::Triple::thumb: break; case llvm::Triple::x86: CmdArgs.push_back("--32"); break; case llvm::Triple::x86_64: CmdArgs.push_back("--64"); break; } Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); for (const auto &Input : Inputs) CmdArgs.push_back(Input.getFilename()); const std::string Assembler = TC.GetProgramPath("as"); Exec = Args.MakeArgString(Assembler); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void CrossWindows::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const auto &TC = static_cast<const toolchains::CrossWindowsToolChain &>(getToolChain()); const llvm::Triple &T = TC.getTriple(); const Driver &D = TC.getDriver(); SmallString<128> EntryPoint; ArgStringList CmdArgs; const char *Exec; // Silence warning for "clang -g foo.o -o foo" Args.ClaimAllArgs(options::OPT_g_Group); // and "clang -emit-llvm foo.o -o foo" Args.ClaimAllArgs(options::OPT_emit_llvm); // and for "clang -w foo.o -o foo" Args.ClaimAllArgs(options::OPT_w); // Other warning options are already handled somewhere else. if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); if (Args.hasArg(options::OPT_pie)) CmdArgs.push_back("-pie"); if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_s)) CmdArgs.push_back("--strip-all"); CmdArgs.push_back("-m"); switch (TC.getArch()) { default: llvm_unreachable("unsupported architecture"); case llvm::Triple::arm: case llvm::Triple::thumb: // FIXME: this is incorrect for WinCE CmdArgs.push_back("thumb2pe"); break; case llvm::Triple::x86: CmdArgs.push_back("i386pe"); EntryPoint.append("_"); break; case llvm::Triple::x86_64: CmdArgs.push_back("i386pep"); break; } if (Args.hasArg(options::OPT_shared)) { switch (T.getArch()) { default: llvm_unreachable("unsupported architecture"); case llvm::Triple::arm: case llvm::Triple::thumb: case llvm::Triple::x86_64: EntryPoint.append("_DllMainCRTStartup"); break; case llvm::Triple::x86: EntryPoint.append("_DllMainCRTStartup@12"); break; } CmdArgs.push_back("-shared"); CmdArgs.push_back("-Bdynamic"); CmdArgs.push_back("--enable-auto-image-base"); CmdArgs.push_back("--entry"); CmdArgs.push_back(Args.MakeArgString(EntryPoint)); } else { EntryPoint.append("mainCRTStartup"); CmdArgs.push_back(Args.hasArg(options::OPT_static) ? "-Bstatic" : "-Bdynamic"); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { CmdArgs.push_back("--entry"); CmdArgs.push_back(Args.MakeArgString(EntryPoint)); } // FIXME: handle subsystem } // NOTE: deal with multiple definitions on Windows (e.g. COMDAT) CmdArgs.push_back("--allow-multiple-definition"); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_rdynamic)) { SmallString<261> ImpLib(Output.getFilename()); llvm::sys::path::replace_extension(ImpLib, ".lib"); CmdArgs.push_back("--out-implib"); CmdArgs.push_back(Args.MakeArgString(ImpLib)); } if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { const std::string CRTPath(D.SysRoot + "/usr/lib/"); const char *CRTBegin; CRTBegin = Args.hasArg(options::OPT_shared) ? "crtbeginS.obj" : "crtbegin.obj"; CmdArgs.push_back(Args.MakeArgString(CRTPath + CRTBegin)); } Args.AddAllArgs(CmdArgs, options::OPT_L); const auto &Paths = TC.getFilePaths(); for (const auto &Path : Paths) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); AddLinkerInputs(TC, Inputs, Args, CmdArgs); if (D.CCCIsCXX() && !Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { bool StaticCXX = Args.hasArg(options::OPT_static_libstdcxx) && !Args.hasArg(options::OPT_static); if (StaticCXX) CmdArgs.push_back("-Bstatic"); TC.AddCXXStdlibLibArgs(Args, CmdArgs); if (StaticCXX) CmdArgs.push_back("-Bdynamic"); } if (!Args.hasArg(options::OPT_nostdlib)) { if (!Args.hasArg(options::OPT_nodefaultlibs)) { // TODO handle /MT[d] /MD[d] CmdArgs.push_back("-lmsvcrt"); AddRunTimeLibs(TC, D, CmdArgs, Args); } } const std::string Linker = TC.GetProgramPath("ld"); Exec = Args.MakeArgString(Linker); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); } void tools::SHAVE::Compiler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; assert(Inputs.size() == 1); const InputInfo &II = Inputs[0]; assert(II.getType() == types::TY_C || II.getType() == types::TY_CXX); assert(Output.getType() == types::TY_PP_Asm); // Require preprocessed asm. // Append all -I, -iquote, -isystem paths. Args.AddAllArgs(CmdArgs, options::OPT_clang_i_Group); // These are spelled the same way in clang and moviCompile. Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); CmdArgs.push_back("-DMYRIAD2"); CmdArgs.push_back("-mcpu=myriad2"); CmdArgs.push_back("-S"); // Any -O option passes through without translation. What about -Ofast ? if (Arg *A = Args.getLastArg(options::OPT_O_Group)) A->render(Args, CmdArgs); if (Args.hasFlag(options::OPT_ffunction_sections, options::OPT_fno_function_sections)) { CmdArgs.push_back("-ffunction-sections"); } if (Args.hasArg(options::OPT_fno_inline_functions)) CmdArgs.push_back("-fno-inline-functions"); CmdArgs.push_back("-fno-exceptions"); // Always do this even if unspecified. CmdArgs.push_back(II.getFilename()); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); std::string Exec = Args.MakeArgString(getToolChain().GetProgramPath("moviCompile")); C.addCommand( llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Exec), CmdArgs)); } void tools::SHAVE::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; assert(Inputs.size() == 1); const InputInfo &II = Inputs[0]; assert(II.getType() == types::TY_PP_Asm); // Require preprocessed asm input. assert(Output.getType() == types::TY_Object); CmdArgs.push_back("-no6thSlotCompression"); CmdArgs.push_back("-cv:myriad2"); // Chip Version ? CmdArgs.push_back("-noSPrefixing"); CmdArgs.push_back("-a"); // Mystery option. for (auto Arg : Args.filtered(options::OPT_I)) { Arg->claim(); CmdArgs.push_back( Args.MakeArgString(std::string("-i:") + Arg->getValue(0))); } CmdArgs.push_back("-elf"); // Output format. CmdArgs.push_back(II.getFilename()); CmdArgs.push_back( Args.MakeArgString(std::string("-o:") + Output.getFilename())); std::string Exec = Args.MakeArgString(getToolChain().GetProgramPath("moviAsm")); C.addCommand( llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Exec), CmdArgs)); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/MinGWToolChain.cpp
//===--- MinGWToolChain.cpp - MinGWToolChain Implementation ---------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "ToolChains.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Options.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" using namespace clang::diag; using namespace clang::driver; using namespace clang::driver::toolchains; using namespace clang; using namespace llvm::opt; namespace { // Simplified from Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple. bool findGccVersion(StringRef LibDir, std::string &GccLibDir, std::string &Ver) { Generic_GCC::GCCVersion Version = Generic_GCC::GCCVersion::Parse("0.0.0"); std::error_code EC; for (llvm::sys::fs::directory_iterator LI(LibDir, EC), LE; !EC && LI != LE; LI = LI.increment(EC)) { StringRef VersionText = llvm::sys::path::filename(LI->path()); Generic_GCC::GCCVersion CandidateVersion = Generic_GCC::GCCVersion::Parse(VersionText); if (CandidateVersion.Major == -1) continue; if (CandidateVersion <= Version) continue; Ver = VersionText; GccLibDir = LI->path(); } return Ver.size(); } } void MinGW::findGccLibDir() { llvm::SmallVector<llvm::SmallString<32>, 2> Archs; Archs.emplace_back(getTriple().getArchName()); Archs[0] += "-w64-mingw32"; Archs.emplace_back("mingw32"); Arch = Archs[0].str(); // lib: Arch Linux, Ubuntu, Windows // lib64: openSUSE Linux for (StringRef CandidateLib : {"lib", "lib64"}) { for (StringRef CandidateArch : Archs) { llvm::SmallString<1024> LibDir(Base); llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateArch); if (findGccVersion(LibDir, GccLibDir, Ver)) { Arch = CandidateArch; return; } } } } MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : ToolChain(D, Triple, Args) { getProgramPaths().push_back(getDriver().getInstalledDir()); // In Windows there aren't any standard install locations, we search // for gcc on the PATH. In Linux the base is always /usr. #ifdef LLVM_ON_WIN32 if (getDriver().SysRoot.size()) Base = getDriver().SysRoot; else if (llvm::ErrorOr<std::string> GPPName = llvm::sys::findProgramByName("gcc")) Base = llvm::sys::path::parent_path( llvm::sys::path::parent_path(GPPName.get())); else Base = llvm::sys::path::parent_path(getDriver().getInstalledDir()); #else if (getDriver().SysRoot.size()) Base = getDriver().SysRoot; else Base = "/usr"; #endif Base += llvm::sys::path::get_separator(); findGccLibDir(); // GccLibDir must precede Base/lib so that the // correct crtbegin.o ,cetend.o would be found. getFilePaths().push_back(GccLibDir); getFilePaths().push_back( (Base + Arch + llvm::sys::path::get_separator() + "lib").str()); getFilePaths().push_back(Base + "lib"); // openSUSE getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib"); } bool MinGW::IsIntegratedAssemblerDefault() const { return true; } Tool *MinGW::getTool(Action::ActionClass AC) const { switch (AC) { case Action::PreprocessJobClass: if (!Preprocessor) Preprocessor.reset(new tools::gcc::Preprocessor(*this)); return Preprocessor.get(); case Action::CompileJobClass: if (!Compiler) Compiler.reset(new tools::gcc::Compiler(*this)); return Compiler.get(); default: return ToolChain::getTool(AC); } } Tool *MinGW::buildAssembler() const { return new tools::MinGW::Assembler(*this); } Tool *MinGW::buildLinker() const { return new tools::MinGW::Linker(*this); } bool MinGW::IsUnwindTablesDefault() const { return getArch() == llvm::Triple::x86_64; } bool MinGW::isPICDefault() const { return getArch() == llvm::Triple::x86_64; } bool MinGW::isPIEDefault() const { return false; } bool MinGW::isPICDefaultForced() const { return getArch() == llvm::Triple::x86_64; } bool MinGW::UseSEHExceptions() const { return getArch() == llvm::Triple::x86_64; } // Include directories for various hosts: // Windows, mingw.org // c:\mingw\lib\gcc\mingw32\4.8.1\include\c++ // c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32 // c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\backward // c:\mingw\lib\gcc\mingw32\4.8.1\include // c:\mingw\include // c:\mingw\lib\gcc\mingw32\4.8.1\include-fixed // c:\mingw\mingw32\include // Windows, mingw-w64 mingw-builds // c:\mingw32\lib\gcc\i686-w64-mingw32\4.9.1\include // c:\mingw32\lib\gcc\i686-w64-mingw32\4.9.1\include-fixed // c:\mingw32\i686-w64-mingw32\include // c:\mingw32\i686-w64-mingw32\include\c++ // c:\mingw32\i686-w64-mingw32\include\c++\i686-w64-mingw32 // c:\mingw32\i686-w64-mingw32\include\c++\backward // Windows, mingw-w64 msys2 // c:\msys64\mingw32\lib\gcc\i686-w64-mingw32\4.9.2\include // c:\msys64\mingw32\include // c:\msys64\mingw32\lib\gcc\i686-w64-mingw32\4.9.2\include-fixed // c:\msys64\mingw32\i686-w64-mingw32\include // c:\msys64\mingw32\include\c++\4.9.2 // c:\msys64\mingw32\include\c++\4.9.2\i686-w64-mingw32 // c:\msys64\mingw32\include\c++\4.9.2\backward // openSUSE // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++ // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32 // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include-fixed // /usr/x86_64-w64-mingw32/sys-root/mingw/include // Arch Linux // /usr/i686-w64-mingw32/include/c++/5.1.0 // /usr/i686-w64-mingw32/include/c++/5.1.0/i686-w64-mingw32 // /usr/i686-w64-mingw32/include/c++/5.1.0/backward // /usr/lib/gcc/i686-w64-mingw32/5.1.0/include // /usr/lib/gcc/i686-w64-mingw32/5.1.0/include-fixed // /usr/i686-w64-mingw32/include // Ubuntu // /usr/include/c++/4.8 // /usr/include/c++/4.8/x86_64-w64-mingw32 // /usr/include/c++/4.8/backward // /usr/lib/gcc/x86_64-w64-mingw32/4.8/include // /usr/lib/gcc/x86_64-w64-mingw32/4.8/include-fixed // /usr/x86_64-w64-mingw32/include void MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdinc)) return; if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { SmallString<1024> P(getDriver().ResourceDir); llvm::sys::path::append(P, "include"); addSystemInclude(DriverArgs, CC1Args, P.str()); } if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) { llvm::SmallString<1024> IncludeDir(GccLibDir); llvm::sys::path::append(IncludeDir, "include"); addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str()); IncludeDir += "-fixed"; // openSUSE addSystemInclude(DriverArgs, CC1Args, Base + Arch + "/sys-root/mingw/include"); addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str()); } addSystemInclude(DriverArgs, CC1Args, Base + Arch + llvm::sys::path::get_separator() + "include"); addSystemInclude(DriverArgs, CC1Args, Base + "include"); } void MinGW::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: addSystemInclude(DriverArgs, CC1Args, Base + "include" + llvm::sys::path::get_separator() + "c++" + llvm::sys::path::get_separator() + "v1"); break; case ToolChain::CST_Libstdcxx: llvm::SmallVector<llvm::SmallString<1024>, 4> CppIncludeBases; CppIncludeBases.emplace_back(Base); llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++"); CppIncludeBases.emplace_back(Base); llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver); CppIncludeBases.emplace_back(Base); llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver); CppIncludeBases.emplace_back(GccLibDir); llvm::sys::path::append(CppIncludeBases[3], "include", "c++"); for (auto &CppIncludeBase : CppIncludeBases) { addSystemInclude(DriverArgs, CC1Args, CppIncludeBase); CppIncludeBase += llvm::sys::path::get_separator(); addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch); addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward"); } break; } }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Multilib.cpp
//===--- Multilib.cpp - Multilib Implementation ---------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Multilib.h" #include "Tools.h" #include "clang/Driver/Options.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Regex.h" #include "llvm/Support/YAMLParser.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> using namespace clang::driver; using namespace clang; using namespace llvm::opt; using namespace llvm::sys; /// normalize Segment to "/foo/bar" or "". static void normalizePathSegment(std::string &Segment) { StringRef seg = Segment; // Prune trailing "/" or "./" while (1) { StringRef last = path::filename(seg); if (last != ".") break; seg = path::parent_path(seg); } if (seg.empty() || seg == "/") { Segment = ""; return; } // Add leading '/' if (seg.front() != '/') { Segment = "/" + seg.str(); } else { Segment = seg; } } Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix, StringRef IncludeSuffix) : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) { normalizePathSegment(this->GCCSuffix); normalizePathSegment(this->OSSuffix); normalizePathSegment(this->IncludeSuffix); } Multilib &Multilib::gccSuffix(StringRef S) { GCCSuffix = S; normalizePathSegment(GCCSuffix); return *this; } Multilib &Multilib::osSuffix(StringRef S) { OSSuffix = S; normalizePathSegment(OSSuffix); return *this; } Multilib &Multilib::includeSuffix(StringRef S) { IncludeSuffix = S; normalizePathSegment(IncludeSuffix); return *this; } void Multilib::print(raw_ostream &OS) const { assert(GCCSuffix.empty() || (StringRef(GCCSuffix).front() == '/')); if (GCCSuffix.empty()) OS << "."; else { OS << StringRef(GCCSuffix).drop_front(); } OS << ";"; for (StringRef Flag : Flags) { if (Flag.front() == '+') OS << "@" << Flag.substr(1); } } bool Multilib::isValid() const { llvm::StringMap<int> FlagSet; for (unsigned I = 0, N = Flags.size(); I != N; ++I) { StringRef Flag(Flags[I]); llvm::StringMap<int>::iterator SI = FlagSet.find(Flag.substr(1)); assert(StringRef(Flag).front() == '+' || StringRef(Flag).front() == '-'); if (SI == FlagSet.end()) FlagSet[Flag.substr(1)] = I; else if (Flags[I] != Flags[SI->getValue()]) return false; } return true; } bool Multilib::operator==(const Multilib &Other) const { // Check whether the flags sets match // allowing for the match to be order invariant llvm::StringSet<> MyFlags; for (const auto &Flag : Flags) MyFlags.insert(Flag); for (const auto &Flag : Other.Flags) if (MyFlags.find(Flag) == MyFlags.end()) return false; if (osSuffix() != Other.osSuffix()) return false; if (gccSuffix() != Other.gccSuffix()) return false; if (includeSuffix() != Other.includeSuffix()) return false; return true; } raw_ostream &clang::driver::operator<<(raw_ostream &OS, const Multilib &M) { M.print(OS); return OS; } MultilibSet &MultilibSet::Maybe(const Multilib &M) { Multilib Opposite; // Negate any '+' flags for (StringRef Flag : M.flags()) { if (Flag.front() == '+') Opposite.flags().push_back(("-" + Flag.substr(1)).str()); } return Either(M, Opposite); } MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2) { return Either({M1, M2}); } MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2, const Multilib &M3) { return Either({M1, M2, M3}); } MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2, const Multilib &M3, const Multilib &M4) { return Either({M1, M2, M3, M4}); } MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2, const Multilib &M3, const Multilib &M4, const Multilib &M5) { return Either({M1, M2, M3, M4, M5}); } static Multilib compose(const Multilib &Base, const Multilib &New) { SmallString<128> GCCSuffix; llvm::sys::path::append(GCCSuffix, "/", Base.gccSuffix(), New.gccSuffix()); SmallString<128> OSSuffix; llvm::sys::path::append(OSSuffix, "/", Base.osSuffix(), New.osSuffix()); SmallString<128> IncludeSuffix; llvm::sys::path::append(IncludeSuffix, "/", Base.includeSuffix(), New.includeSuffix()); Multilib Composed(GCCSuffix, OSSuffix, IncludeSuffix); Multilib::flags_list &Flags = Composed.flags(); Flags.insert(Flags.end(), Base.flags().begin(), Base.flags().end()); Flags.insert(Flags.end(), New.flags().begin(), New.flags().end()); return Composed; } MultilibSet &MultilibSet::Either(ArrayRef<Multilib> MultilibSegments) { multilib_list Composed; if (Multilibs.empty()) Multilibs.insert(Multilibs.end(), MultilibSegments.begin(), MultilibSegments.end()); else { for (const Multilib &New : MultilibSegments) { for (const Multilib &Base : *this) { Multilib MO = compose(Base, New); if (MO.isValid()) Composed.push_back(MO); } } Multilibs = Composed; } return *this; } MultilibSet &MultilibSet::FilterOut(FilterCallback F) { filterInPlace(F, Multilibs); return *this; } MultilibSet &MultilibSet::FilterOut(const char *Regex) { llvm::Regex R(Regex); #ifndef NDEBUG std::string Error; if (!R.isValid(Error)) { llvm::errs() << Error; llvm_unreachable("Invalid regex!"); } #endif filterInPlace([&R](const Multilib &M) { return R.match(M.gccSuffix()); }, Multilibs); return *this; } void MultilibSet::push_back(const Multilib &M) { Multilibs.push_back(M); } void MultilibSet::combineWith(const MultilibSet &Other) { Multilibs.insert(Multilibs.end(), Other.begin(), Other.end()); } static bool isFlagEnabled(StringRef Flag) { char Indicator = Flag.front(); assert(Indicator == '+' || Indicator == '-'); return Indicator == '+'; } bool MultilibSet::select(const Multilib::flags_list &Flags, Multilib &M) const { llvm::StringMap<bool> FlagSet; // Stuff all of the flags into the FlagSet such that a true mappend indicates // the flag was enabled, and a false mappend indicates the flag was disabled. for (StringRef Flag : Flags) FlagSet[Flag.substr(1)] = isFlagEnabled(Flag); multilib_list Filtered = filterCopy([&FlagSet](const Multilib &M) { for (StringRef Flag : M.flags()) { llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1)); if (SI != FlagSet.end()) if (SI->getValue() != isFlagEnabled(Flag)) return true; } return false; }, Multilibs); if (Filtered.size() == 0) { return false; } else if (Filtered.size() == 1) { M = Filtered[0]; return true; } // TODO: pick the "best" multlib when more than one is suitable assert(false); return false; } void MultilibSet::print(raw_ostream &OS) const { for (const Multilib &M : *this) OS << M << "\n"; } MultilibSet::multilib_list MultilibSet::filterCopy(FilterCallback F, const multilib_list &Ms) { multilib_list Copy(Ms); filterInPlace(F, Copy); return Copy; } void MultilibSet::filterInPlace(FilterCallback F, multilib_list &Ms) { Ms.erase(std::remove_if(Ms.begin(), Ms.end(), F), Ms.end()); } raw_ostream &clang::driver::operator<<(raw_ostream &OS, const MultilibSet &MS) { MS.print(OS); return OS; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Phases.cpp
//===--- Phases.cpp - Transformations on Driver Types ---------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Phases.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> using namespace clang::driver; const char *phases::getPhaseName(ID Id) { switch (Id) { case Preprocess: return "preprocessor"; case Precompile: return "precompiler"; case Compile: return "compiler"; case Backend: return "backend"; case Assemble: return "assembler"; case Link: return "linker"; } llvm_unreachable("Invalid phase id."); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Compilation.cpp
//===--- Compilation.cpp - Compilation Task Implementation ----------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Compilation.h" #include "clang/Driver/Action.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" using namespace clang::driver; using namespace clang; using namespace llvm::opt; Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain, InputArgList *_Args, DerivedArgList *_TranslatedArgs) : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args), TranslatedArgs(_TranslatedArgs), Redirects(nullptr), ForDiagnostics(false) {} Compilation::~Compilation() { delete TranslatedArgs; delete Args; // Free any derived arg lists. for (llvm::DenseMap<std::pair<const ToolChain*, const char*>, DerivedArgList*>::iterator it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) if (it->second != TranslatedArgs) delete it->second; // Free the actions, if built. for (ActionList::iterator it = Actions.begin(), ie = Actions.end(); it != ie; ++it) delete *it; // Free redirections of stdout/stderr. if (Redirects) { delete Redirects[1]; delete Redirects[2]; delete [] Redirects; } } const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC, const char *BoundArch) { if (!TC) TC = &DefaultToolChain; DerivedArgList *&Entry = TCArgs[std::make_pair(TC, BoundArch)]; if (!Entry) { Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch); if (!Entry) Entry = TranslatedArgs; } return *Entry; } bool Compilation::CleanupFile(const char *File, bool IssueErrors) const { // FIXME: Why are we trying to remove files that we have not created? For // example we should only try to remove a temporary assembly file if // "clang -cc1" succeed in writing it. Was this a workaround for when // clang was writing directly to a .s file and sometimes leaving it behind // during a failure? // FIXME: If this is necessary, we can still try to split // llvm::sys::fs::remove into a removeFile and a removeDir and avoid the // duplicated stat from is_regular_file. // Don't try to remove files which we don't have write access to (but may be // able to remove), or non-regular files. Underlying tools may have // intentionally not overwritten them. if (!llvm::sys::fs::can_write(File) || !llvm::sys::fs::is_regular_file(File)) return true; if (std::error_code EC = llvm::sys::fs::remove(File)) { // Failure is only failure if the file exists and is "regular". We checked // for it being regular before, and llvm::sys::fs::remove ignores ENOENT, // so we don't need to check again. if (IssueErrors) getDriver().Diag(clang::diag::err_drv_unable_to_remove_file) << EC.message(); return false; } return true; } bool Compilation::CleanupFileList(const ArgStringList &Files, bool IssueErrors) const { bool Success = true; for (ArgStringList::const_iterator it = Files.begin(), ie = Files.end(); it != ie; ++it) Success &= CleanupFile(*it, IssueErrors); return Success; } bool Compilation::CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors) const { bool Success = true; for (ArgStringMap::const_iterator it = Files.begin(), ie = Files.end(); it != ie; ++it) { // If specified, only delete the files associated with the JobAction. // Otherwise, delete all files in the map. if (JA && it->first != JA) continue; Success &= CleanupFile(it->second, IssueErrors); } return Success; } int Compilation::ExecuteCommand(const Command &C, const Command *&FailingCommand) const { if ((getDriver().CCPrintOptions || getArgs().hasArg(options::OPT_v)) && !getDriver().CCGenDiagnostics) { raw_ostream *OS = &llvm::errs(); // Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the // output stream. if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) { std::error_code EC; OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text); if (EC) { getDriver().Diag(clang::diag::err_drv_cc_print_options_failure) << EC.message(); FailingCommand = &C; delete OS; return 1; } } if (getDriver().CCPrintOptions) *OS << "[Logging clang options]"; C.Print(*OS, "\n", /*Quote=*/getDriver().CCPrintOptions); if (OS != &llvm::errs()) delete OS; } std::string Error; bool ExecutionFailed; int Res = C.Execute(Redirects, &Error, &ExecutionFailed); if (!Error.empty()) { assert(Res && "Error string set with 0 result code!"); getDriver().Diag(clang::diag::err_drv_command_failure) << Error; } if (Res) FailingCommand = &C; return ExecutionFailed ? 1 : Res; } typedef SmallVectorImpl< std::pair<int, const Command *> > FailingCommandList; static bool ActionFailed(const Action *A, const FailingCommandList &FailingCommands) { if (FailingCommands.empty()) return false; for (FailingCommandList::const_iterator CI = FailingCommands.begin(), CE = FailingCommands.end(); CI != CE; ++CI) if (A == &(CI->second->getSource())) return true; for (Action::const_iterator AI = A->begin(), AE = A->end(); AI != AE; ++AI) if (ActionFailed(*AI, FailingCommands)) return true; return false; } static bool InputsOk(const Command &C, const FailingCommandList &FailingCommands) { return !ActionFailed(&C.getSource(), FailingCommands); } void Compilation::ExecuteJobs(const JobList &Jobs, FailingCommandList &FailingCommands) const { for (const auto &Job : Jobs) { if (!InputsOk(Job, FailingCommands)) continue; const Command *FailingCommand = nullptr; if (int Res = ExecuteCommand(Job, FailingCommand)) FailingCommands.push_back(std::make_pair(Res, FailingCommand)); } } void Compilation::initCompilationForDiagnostics() { ForDiagnostics = true; // Free actions and jobs. DeleteContainerPointers(Actions); Jobs.clear(); // Clear temporary/results file lists. TempFiles.clear(); ResultFiles.clear(); FailureResultFiles.clear(); // Remove any user specified output. Claim any unclaimed arguments, so as // to avoid emitting warnings about unused args. OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD, options::OPT_MMD }; for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) { if (TranslatedArgs->hasArg(OutputOpts[i])) TranslatedArgs->eraseArg(OutputOpts[i]); } TranslatedArgs->ClaimAllArgs(); // Redirect stdout/stderr to /dev/null. Redirects = new const StringRef*[3](); Redirects[0] = nullptr; Redirects[1] = new StringRef(); Redirects[2] = new StringRef(); } StringRef Compilation::getSysRoot() const { return getDriver().SysRoot; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/ToolChain.cpp
//===--- ToolChain.cpp - Collections of tools for one platform ------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "Tools.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Driver/Action.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/SanitizerArgs.h" #include "clang/Driver/ToolChain.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" using namespace clang::driver; using namespace clang; using namespace llvm::opt; static llvm::opt::Arg *GetRTTIArgument(const ArgList &Args) { return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext, options::OPT_fno_rtti, options::OPT_frtti); } static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, const llvm::Triple &Triple, const Arg *CachedRTTIArg) { // Explicit rtti/no-rtti args if (CachedRTTIArg) { if (CachedRTTIArg->getOption().matches(options::OPT_frtti)) return ToolChain::RM_EnabledExplicitly; else return ToolChain::RM_DisabledExplicitly; } // -frtti is default, except for the PS4 CPU. if (!Triple.isPS4CPU()) return ToolChain::RM_EnabledImplicitly; // On the PS4, turning on c++ exceptions turns on rtti. // We're assuming that, if we see -fexceptions, rtti gets turned on. Arg *Exceptions = Args.getLastArgNoClaim( options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, options::OPT_fexceptions, options::OPT_fno_exceptions); if (Exceptions && (Exceptions->getOption().matches(options::OPT_fexceptions) || Exceptions->getOption().matches(options::OPT_fcxx_exceptions))) return ToolChain::RM_EnabledImplicitly; return ToolChain::RM_DisabledImplicitly; } ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) if (!isThreadModelSupported(A->getValue())) D.Diag(diag::err_drv_invalid_thread_model_for_target) << A->getValue() << A->getAsString(Args); } ToolChain::~ToolChain() { } const Driver &ToolChain::getDriver() const { return D; } bool ToolChain::useIntegratedAs() const { return Args.hasFlag(options::OPT_fintegrated_as, options::OPT_fno_integrated_as, IsIntegratedAssemblerDefault()); } const SanitizerArgs& ToolChain::getSanitizerArgs() const { if (!SanitizerArguments.get()) SanitizerArguments.reset(new SanitizerArgs(*this, Args)); return *SanitizerArguments.get(); } StringRef ToolChain::getDefaultUniversalArchName() const { // In universal driver terms, the arch name accepted by -arch isn't exactly // the same as the ones that appear in the triple. Roughly speaking, this is // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the // only interesting special case is powerpc. switch (Triple.getArch()) { case llvm::Triple::ppc: return "ppc"; case llvm::Triple::ppc64: return "ppc64"; case llvm::Triple::ppc64le: return "ppc64le"; default: return Triple.getArchName(); } } bool ToolChain::IsUnwindTablesDefault() const { return false; } Tool *ToolChain::getClang() const { if (!Clang) Clang.reset(new tools::Clang(*this)); return Clang.get(); } Tool *ToolChain::buildAssembler() const { return new tools::ClangAs(*this); } Tool *ToolChain::buildLinker() const { llvm_unreachable("Linking is not supported by this toolchain"); } Tool *ToolChain::getAssemble() const { if (!Assemble) Assemble.reset(buildAssembler()); return Assemble.get(); } Tool *ToolChain::getClangAs() const { if (!Assemble) Assemble.reset(new tools::ClangAs(*this)); return Assemble.get(); } Tool *ToolChain::getLink() const { if (!Link) Link.reset(buildLinker()); return Link.get(); } Tool *ToolChain::getTool(Action::ActionClass AC) const { switch (AC) { case Action::AssembleJobClass: return getAssemble(); case Action::LinkJobClass: return getLink(); case Action::InputClass: case Action::BindArchClass: case Action::CudaDeviceClass: case Action::CudaHostClass: case Action::LipoJobClass: case Action::DsymutilJobClass: case Action::VerifyDebugInfoJobClass: llvm_unreachable("Invalid tool kind."); case Action::CompileJobClass: case Action::PrecompileJobClass: case Action::PreprocessJobClass: case Action::AnalyzeJobClass: case Action::MigrateJobClass: case Action::VerifyPCHJobClass: case Action::BackendJobClass: return getClang(); } llvm_unreachable("Invalid tool kind."); } Tool *ToolChain::SelectTool(const JobAction &JA) const { if (getDriver().ShouldUseClangCompiler(JA)) return getClang(); Action::ActionClass AC = JA.getKind(); if (AC == Action::AssembleJobClass && useIntegratedAs()) return getClangAs(); return getTool(AC); } std::string ToolChain::GetFilePath(const char *Name) const { return D.GetFilePath(Name, *this); } std::string ToolChain::GetProgramPath(const char *Name) const { return D.GetProgramPath(Name, *this); } std::string ToolChain::GetLinkerPath() const { if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) { StringRef Suffix = A->getValue(); // If we're passed -fuse-ld= with no argument, or with the argument ld, // then use whatever the default system linker is. if (Suffix.empty() || Suffix == "ld") return GetProgramPath("ld"); llvm::SmallString<8> LinkerName("ld."); LinkerName.append(Suffix); std::string LinkerPath(GetProgramPath(LinkerName.c_str())); if (llvm::sys::fs::exists(LinkerPath)) return LinkerPath; getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args); return ""; } return GetProgramPath("ld"); } types::ID ToolChain::LookupTypeForExtension(const char *Ext) const { return types::lookupTypeForExtension(Ext); } bool ToolChain::HasNativeLLVMSupport() const { return false; } bool ToolChain::isCrossCompiling() const { llvm::Triple HostTriple(LLVM_HOST_TRIPLE); switch (HostTriple.getArch()) { // The A32/T32/T16 instruction sets are not separate architectures in this // context. case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: return getArch() != llvm::Triple::arm && getArch() != llvm::Triple::thumb && getArch() != llvm::Triple::armeb && getArch() != llvm::Triple::thumbeb; default: return HostTriple.getArch() != getArch(); } } ObjCRuntime ToolChain::getDefaultObjCRuntime(bool isNonFragile) const { return ObjCRuntime(isNonFragile ? ObjCRuntime::GNUstep : ObjCRuntime::GCC, VersionTuple()); } bool ToolChain::isThreadModelSupported(const StringRef Model) const { if (Model == "single") { // FIXME: 'single' is only supported on ARM so far. return Triple.getArch() == llvm::Triple::arm || Triple.getArch() == llvm::Triple::armeb || Triple.getArch() == llvm::Triple::thumb || Triple.getArch() == llvm::Triple::thumbeb; } else if (Model == "posix") return true; return false; } std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, types::ID InputType) const { switch (getTriple().getArch()) { default: return getTripleString(); case llvm::Triple::x86_64: { llvm::Triple Triple = getTriple(); if (!Triple.isOSBinFormatMachO()) return getTripleString(); if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) { // x86_64h goes in the triple. Other -march options just use the // vanilla triple we already have. StringRef MArch = A->getValue(); if (MArch == "x86_64h") Triple.setArchName(MArch); } return Triple.getTriple(); } case llvm::Triple::aarch64: { llvm::Triple Triple = getTriple(); if (!Triple.isOSBinFormatMachO()) return getTripleString(); // FIXME: older versions of ld64 expect the "arm64" component in the actual // triple string and query it to determine whether an LTO file can be // handled. Remove this when we don't care any more. Triple.setArchName("arm64"); return Triple.getTriple(); } case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: { // FIXME: Factor into subclasses. llvm::Triple Triple = getTriple(); bool IsBigEndian = getTriple().getArch() == llvm::Triple::armeb || getTriple().getArch() == llvm::Triple::thumbeb; // Handle pseudo-target flags '-mlittle-endian'/'-EL' and // '-mbig-endian'/'-EB'. if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian, options::OPT_mbig_endian)) { IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian); } // Thumb2 is the default for V7 on Darwin. // // FIXME: Thumb should just be another -target-feaure, not in the triple. StringRef MCPU, MArch; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) MCPU = A->getValue(); if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) MArch = A->getValue(); std::string CPU = Triple.isOSBinFormatMachO() ? tools::arm::getARMCPUForMArch(MArch, Triple) : tools::arm::getARMTargetCPU(MCPU, MArch, Triple); StringRef Suffix = tools::arm::getLLVMArchSuffixForARM(CPU, tools::arm::getARMArch(MArch, Triple)); bool ThumbDefault = Suffix.startswith("v6m") || Suffix.startswith("v7m") || Suffix.startswith("v7em") || (Suffix.startswith("v7") && getTriple().isOSBinFormatMachO()); // FIXME: this is invalid for WindowsCE if (getTriple().isOSWindows()) ThumbDefault = true; std::string ArchName; if (IsBigEndian) ArchName = "armeb"; else ArchName = "arm"; // Assembly files should start in ARM mode. if (InputType != types::TY_PP_Asm && Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault)) { if (IsBigEndian) ArchName = "thumbeb"; else ArchName = "thumb"; } Triple.setArchName(ArchName + Suffix.str()); return Triple.getTriple(); } } } std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args, types::ID InputType) const { return ComputeLLVMTriple(Args, InputType); } void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { // Each toolchain should provide the appropriate include flags. } void ToolChain::addClangTargetOptions(const ArgList &DriverArgs, ArgStringList &CC1Args) const { } void ToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {} ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) { StringRef Value = A->getValue(); if (Value == "compiler-rt") return ToolChain::RLT_CompilerRT; if (Value == "libgcc") return ToolChain::RLT_Libgcc; getDriver().Diag(diag::err_drv_invalid_rtlib_name) << A->getAsString(Args); } return GetDefaultRuntimeLibType(); } ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value == "libc++") return ToolChain::CST_Libcxx; if (Value == "libstdc++") return ToolChain::CST_Libstdcxx; getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); } return ToolChain::CST_Libstdcxx; } /// \brief Utility function to add a system include directory to CC1 arguments. /*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs, ArgStringList &CC1Args, const Twine &Path) { CC1Args.push_back("-internal-isystem"); CC1Args.push_back(DriverArgs.MakeArgString(Path)); } /// \brief Utility function to add a system include directory with extern "C" /// semantics to CC1 arguments. /// /// Note that this should be used rarely, and only for directories that /// historically and for legacy reasons are treated as having implicit extern /// "C" semantics. These semantics are *ignored* by and large today, but its /// important to preserve the preprocessor changes resulting from the /// classification. /*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs, ArgStringList &CC1Args, const Twine &Path) { CC1Args.push_back("-internal-externc-isystem"); CC1Args.push_back(DriverArgs.MakeArgString(Path)); } void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs, ArgStringList &CC1Args, const Twine &Path) { if (llvm::sys::fs::exists(Path)) addExternCSystemInclude(DriverArgs, CC1Args, Path); } /// \brief Utility function to add a list of system include directories to CC1. /*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs, ArgStringList &CC1Args, ArrayRef<StringRef> Paths) { for (ArrayRef<StringRef>::iterator I = Paths.begin(), E = Paths.end(); I != E; ++I) { CC1Args.push_back("-internal-isystem"); CC1Args.push_back(DriverArgs.MakeArgString(*I)); } } void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { // Header search paths should be handled by each of the subclasses. // Historically, they have not been, and instead have been handled inside of // the CC1-layer frontend. As the logic is hoisted out, this generic function // will slowly stop being called. // // While it is being called, replicate a bit of a hack to propagate the // '-stdlib=' flag down to CC1 so that it can in turn customize the C++ // header search paths with it. Once all systems are overriding this // function, the CC1 flag and this line can be removed. DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ); } void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { CXXStdlibType Type = GetCXXStdlibType(Args); switch (Type) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); break; case ToolChain::CST_Libstdcxx: CmdArgs.push_back("-lstdc++"); break; } } void ToolChain::AddCCKextLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { CmdArgs.push_back("-lcc_kext"); } bool ToolChain::AddFastMathRuntimeIfAvailable(const ArgList &Args, ArgStringList &CmdArgs) const { // Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed // (to keep the linker options consistent with gcc and clang itself). if (!isOptimizationLevelFast(Args)) { // Check if -ffast-math or -funsafe-math. Arg *A = Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations, options::OPT_fno_unsafe_math_optimizations); if (!A || A->getOption().getID() == options::OPT_fno_fast_math || A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations) return false; } // If crtfastmath.o exists add it to the arguments. std::string Path = GetFilePath("crtfastmath.o"); if (Path == "crtfastmath.o") // Not found. return false; CmdArgs.push_back(Args.MakeArgString(Path)); return true; } SanitizerMask ToolChain::getSupportedSanitizers() const { // Return sanitizers which don't require runtime support and are not // platform or architecture-dependent. using namespace SanitizerKind; return (Undefined & ~Vptr & ~Function) | CFI | CFICastStrict | UnsignedIntegerOverflow | LocalBounds; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Tools.h
//===--- Tools.h - Tool Implementations -------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_LIB_DRIVER_TOOLS_H #define LLVM_CLANG_LIB_DRIVER_TOOLS_H #include "clang/Basic/VersionTuple.h" #include "clang/Driver/Tool.h" #include "clang/Driver/Types.h" #include "clang/Driver/Util.h" #include "llvm/ADT/Triple.h" #include "llvm/Option/Option.h" #include "llvm/Support/Compiler.h" namespace clang { class ObjCRuntime; namespace driver { class Command; class Driver; namespace toolchains { class MachO; } namespace tools { namespace visualstudio { class Compiler; } using llvm::opt::ArgStringList; SmallString<128> getCompilerRT(const ToolChain &TC, StringRef Component, bool Shared = false); /// \brief Clang compiler tool. class LLVM_LIBRARY_VISIBILITY Clang : public Tool { public: static const char *getBaseInputName(const llvm::opt::ArgList &Args, const InputInfo &Input); static const char *getBaseInputStem(const llvm::opt::ArgList &Args, const InputInfoList &Inputs); static const char *getDependencyFileName(const llvm::opt::ArgList &Args, const InputInfoList &Inputs); private: void AddPreprocessingOptions(Compilation &C, const JobAction &JA, const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfoList &Inputs) const; void AddAArch64TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddARMTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool KernelOrKext) const; void AddARM64TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddMIPSTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddPPCTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddR600TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddSparcTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddSystemZTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddX86TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddHexagonTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile }; ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args, llvm::opt::ArgStringList &cmdArgs, RewriteKind rewrite) const; void AddClangCLArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; visualstudio::Compiler *getCLFallback() const; mutable std::unique_ptr<visualstudio::Compiler> CLFallback; public: // CAUTION! The first constructor argument ("clang") is not arbitrary, // as it is for other tools. Some operations on a Tool actually test // whether that tool is Clang based on the Tool's Name as a string. Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC, RF_Full) {} bool hasGoodDiagnostics() const override { return true; } bool hasIntegratedAssembler() const override { return true; } bool hasIntegratedCPP() const override { return true; } bool canEmitIR() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; /// \brief Clang integrated assembler tool. class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool { public: ClangAs(const ToolChain &TC) : Tool("clang::as", "clang integrated assembler", TC, RF_Full) {} void AddMIPSTargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; bool hasGoodDiagnostics() const override { return true; } bool hasIntegratedAssembler() const override { return false; } bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; /// \brief Base class for all GNU tools that provide the same behavior when /// it comes to response files support class LLVM_LIBRARY_VISIBILITY GnuTool : public Tool { virtual void anchor(); public: GnuTool(const char *Name, const char *ShortName, const ToolChain &TC) : Tool(Name, ShortName, TC, RF_Full, llvm::sys::WEM_CurrentCodePage) {} }; /// gcc - Generic GCC tool implementations. namespace gcc { class LLVM_LIBRARY_VISIBILITY Common : public GnuTool { public: Common(const char *Name, const char *ShortName, const ToolChain &TC) : GnuTool(Name, ShortName, TC) {} void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; /// RenderExtraToolArgs - Render any arguments necessary to force /// the particular tool mode. virtual void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const = 0; }; class LLVM_LIBRARY_VISIBILITY Preprocessor : public Common { public: Preprocessor(const ToolChain &TC) : Common("gcc::Preprocessor", "gcc preprocessor", TC) {} bool hasGoodDiagnostics() const override { return true; } bool hasIntegratedCPP() const override { return false; } void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const override; }; class LLVM_LIBRARY_VISIBILITY Compiler : public Common { public: Compiler(const ToolChain &TC) : Common("gcc::Compiler", "gcc frontend", TC) {} bool hasGoodDiagnostics() const override { return true; } bool hasIntegratedCPP() const override { return true; } void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public Common { public: Linker(const ToolChain &TC) : Common("gcc::Linker", "linker (via gcc)", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const override; }; } // end namespace gcc namespace hexagon { // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile // and Compile. // We simply use "clang -cc1" for those actions. class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("hexagon::Assembler", "hexagon-as", TC) {} bool hasIntegratedCPP() const override { return false; } void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const; void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("hexagon::Linker", "hexagon-ld", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } virtual void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const; void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace hexagon. namespace arm { std::string getARMTargetCPU(StringRef CPU, StringRef Arch, const llvm::Triple &Triple); const std::string getARMArch(StringRef Arch, const llvm::Triple &Triple); const char* getARMCPUForMArch(StringRef Arch, const llvm::Triple &Triple); const char* getLLVMArchSuffixForARM(StringRef CPU, StringRef Arch); void appendEBLinkFlags(const llvm::opt::ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple); } namespace mips { typedef enum { NanLegacy = 1, Nan2008 = 2 } NanEncoding; NanEncoding getSupportedNanEncoding(StringRef &CPU); void getMipsCPUAndABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, StringRef &CPUName, StringRef &ABIName); bool hasMipsAbiArg(const llvm::opt::ArgList &Args, const char *Value); bool isUCLibc(const llvm::opt::ArgList &Args); bool isNaN2008(const llvm::opt::ArgList &Args, const llvm::Triple &Triple); bool isFPXXDefault(const llvm::Triple &Triple, StringRef CPUName, StringRef ABIName, StringRef FloatABI); bool shouldUseFPXX(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, StringRef CPUName, StringRef ABIName, StringRef FloatABI); } namespace ppc { bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value); } /// cloudabi -- Directly call GNU Binutils linker namespace cloudabi { class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("cloudabi::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace cloudabi namespace darwin { llvm::Triple::ArchType getArchTypeForMachOArchName(StringRef Str); void setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str); class LLVM_LIBRARY_VISIBILITY MachOTool : public Tool { virtual void anchor(); protected: void AddMachOArch(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; const toolchains::MachO &getMachOToolChain() const { return reinterpret_cast<const toolchains::MachO&>(getToolChain()); } public: MachOTool( const char *Name, const char *ShortName, const ToolChain &TC, ResponseFileSupport ResponseSupport = RF_None, llvm::sys::WindowsEncodingMethod ResponseEncoding = llvm::sys::WEM_UTF8, const char *ResponseFlag = "@") : Tool(Name, ShortName, TC, ResponseSupport, ResponseEncoding, ResponseFlag) {} }; class LLVM_LIBRARY_VISIBILITY Assembler : public MachOTool { public: Assembler(const ToolChain &TC) : MachOTool("darwin::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public MachOTool { bool NeedsTempPath(const InputInfoList &Inputs) const; void AddLinkArgs(Compilation &C, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfoList &Inputs) const; public: Linker(const ToolChain &TC) : MachOTool("darwin::Linker", "linker", TC, RF_FileList, llvm::sys::WEM_UTF8, "-filelist") {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Lipo : public MachOTool { public: Lipo(const ToolChain &TC) : MachOTool("darwin::Lipo", "lipo", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Dsymutil : public MachOTool { public: Dsymutil(const ToolChain &TC) : MachOTool("darwin::Dsymutil", "dsymutil", TC) {} bool hasIntegratedCPP() const override { return false; } bool isDsymutilJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY VerifyDebug : public MachOTool { public: VerifyDebug(const ToolChain &TC) : MachOTool("darwin::VerifyDebug", "dwarfdump", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } /// openbsd -- Directly call GNU Binutils assembler and linker namespace openbsd { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("openbsd::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("openbsd::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace openbsd /// bitrig -- Directly call GNU Binutils assembler and linker namespace bitrig { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("bitrig::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("bitrig::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace bitrig /// freebsd -- Directly call GNU Binutils assembler and linker namespace freebsd { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("freebsd::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("freebsd::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace freebsd /// netbsd -- Directly call GNU Binutils assembler and linker namespace netbsd { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("netbsd::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("netbsd::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace netbsd /// Directly call GNU Binutils' assembler and linker. namespace gnutools { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("GNU::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("GNU::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } namespace nacltools { class LLVM_LIBRARY_VISIBILITY AssemblerARM : public gnutools::Assembler { public: AssemblerARM(const ToolChain &TC) : gnutools::Assembler(TC) {} void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public Tool { public: Linker(const ToolChain &TC) : Tool("NaCl::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } /// minix -- Directly call GNU Binutils assembler and linker namespace minix { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("minix::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("minix::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace minix /// solaris -- Directly call Solaris assembler and linker namespace solaris { class LLVM_LIBRARY_VISIBILITY Assembler : public Tool { public: Assembler(const ToolChain &TC) : Tool("solaris::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public Tool { public: Linker(const ToolChain &TC) : Tool("solaris::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace solaris /// dragonfly -- Directly call GNU Binutils assembler and linker namespace dragonfly { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { public: Assembler(const ToolChain &TC) : GnuTool("dragonfly::Assembler", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { public: Linker(const ToolChain &TC) : GnuTool("dragonfly::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace dragonfly /// Visual studio tools. namespace visualstudio { VersionTuple getMSVCVersion(const Driver *D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, bool IsWindowsMSVC); class LLVM_LIBRARY_VISIBILITY Linker : public Tool { public: Linker(const ToolChain &TC) : Tool("visualstudio::Linker", "linker", TC, RF_Full, llvm::sys::WEM_UTF16) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Compiler : public Tool { public: Compiler(const ToolChain &TC) : Tool("visualstudio::Compiler", "compiler", TC, RF_Full, llvm::sys::WEM_UTF16) {} bool hasIntegratedAssembler() const override { return true; } bool hasIntegratedCPP() const override { return true; } bool isLinkJob() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; std::unique_ptr<Command> GetCommand(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const; }; } // end namespace visualstudio /// MinGW -- Directly call GNU Binutils assembler and linker namespace MinGW { class LLVM_LIBRARY_VISIBILITY Assembler : public Tool { public: Assembler(const ToolChain &TC) : Tool("MinGW::Assemble", "assembler", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public Tool { public: Linker(const ToolChain &TC) : Tool("MinGW::Linker", "linker", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; private: void AddLibGCC(const llvm::opt::ArgList &Args, ArgStringList &CmdArgs) const; }; } // end namespace MinGW namespace arm { StringRef getARMFloatABI(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &Triple); } namespace XCore { // For XCore, we do not need to instantiate tools for PreProcess, PreCompile and // Compile. // We simply use "clang -cc1" for those actions. class LLVM_LIBRARY_VISIBILITY Assembler : public Tool { public: Assembler(const ToolChain &TC) : Tool("XCore::Assembler", "XCore-as", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public Tool { public: Linker(const ToolChain &TC) : Tool("XCore::Linker", "XCore-ld", TC) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace XCore. namespace CrossWindows { class LLVM_LIBRARY_VISIBILITY Assembler : public Tool { public: Assembler(const ToolChain &TC) : Tool("CrossWindows::Assembler", "as", TC) {} bool hasIntegratedCPP() const override { return false; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Linker : public Tool { public: Linker(const ToolChain &TC) : Tool("CrossWindows::Linker", "ld", TC, RF_Full) {} bool hasIntegratedCPP() const override { return false; } bool isLinkJob() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } /// SHAVE tools -- Directly call moviCompile and moviAsm namespace SHAVE { class LLVM_LIBRARY_VISIBILITY Compiler : public Tool { public: Compiler(const ToolChain &TC) : Tool("moviCompile", "movicompile", TC) {} bool hasIntegratedCPP() const override { return true; } void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; class LLVM_LIBRARY_VISIBILITY Assembler : public Tool { public: Assembler(const ToolChain &TC) : Tool("moviAsm", "moviAsm", TC) {} bool hasIntegratedCPP() const override { return false; } // not sure. void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; }; } // end namespace SHAVE } // end namespace tools } // end namespace driver } // end namespace clang #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/CrossWindowsToolChain.cpp
//===--- CrossWindowsToolChain.cpp - Cross Windows Tool Chain -------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "ToolChains.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Options.h" #include "llvm/Option/ArgList.h" using namespace clang::driver; using namespace clang::driver::toolchains; CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args) : Generic_GCC(D, T, Args) { if (GetCXXStdlibType(Args) == ToolChain::CST_Libstdcxx) { const std::string &SysRoot = D.SysRoot; // libstdc++ resides in /usr/lib, but depends on libgcc which is placed in // /usr/lib/gcc. getFilePaths().push_back(SysRoot + "/usr/lib"); getFilePaths().push_back(SysRoot + "/usr/lib/gcc"); } } bool CrossWindowsToolChain::IsUnwindTablesDefault() const { // FIXME: all non-x86 targets need unwind tables, however, LLVM currently does // not know how to emit them. return getArch() == llvm::Triple::x86_64; } bool CrossWindowsToolChain::isPICDefault() const { return getArch() == llvm::Triple::x86_64; } bool CrossWindowsToolChain::isPIEDefault() const { return getArch() == llvm::Triple::x86_64; } bool CrossWindowsToolChain::isPICDefaultForced() const { return getArch() == llvm::Triple::x86_64; } void CrossWindowsToolChain:: AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { const Driver &D = getDriver(); const std::string &SysRoot = D.SysRoot; if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { SmallString<128> ResourceDir(D.ResourceDir); llvm::sys::path::append(ResourceDir, "include"); addSystemInclude(DriverArgs, CC1Args, ResourceDir); } addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); } void CrossWindowsToolChain:: AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { const llvm::Triple &Triple = getTriple(); const std::string &SysRoot = getDriver().SysRoot; if (DriverArgs.hasArg(options::OPT_nostdlibinc) || DriverArgs.hasArg(options::OPT_nostdincxx)) return; switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/v1"); break; case ToolChain::CST_Libstdcxx: addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++"); addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/" + Triple.str()); addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/backwards"); } } void CrossWindowsToolChain:: AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: CC1Args.push_back("-lc++"); break; case ToolChain::CST_Libstdcxx: CC1Args.push_back("-lstdc++"); CC1Args.push_back("-lmingw32"); CC1Args.push_back("-lmingwex"); CC1Args.push_back("-lgcc"); CC1Args.push_back("-lmoldname"); CC1Args.push_back("-lmingw32"); break; } } Tool *CrossWindowsToolChain::buildLinker() const { return new tools::CrossWindows::Linker(*this); } Tool *CrossWindowsToolChain::buildAssembler() const { return new tools::CrossWindows::Assembler(*this); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Types.cpp
//===--- Types.cpp - Driver input & temporary type information ------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Types.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" #include <cassert> #include <string.h> using namespace clang::driver; using namespace clang::driver::types; struct TypeInfo { const char *Name; const char *Flags; const char *TempSuffix; ID PreprocessedType; }; static const TypeInfo TypeInfos[] = { #define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \ { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, }, #include "clang/Driver/Types.def" #undef TYPE }; static const unsigned numTypes = llvm::array_lengthof(TypeInfos); static const TypeInfo &getInfo(unsigned id) { assert(id > 0 && id - 1 < numTypes && "Invalid Type ID."); return TypeInfos[id - 1]; } const char *types::getTypeName(ID Id) { return getInfo(Id).Name; } types::ID types::getPreprocessedType(ID Id) { return getInfo(Id).PreprocessedType; } const char *types::getTypeTempSuffix(ID Id, bool CLMode) { if (Id == TY_Object && CLMode) return "obj"; if (Id == TY_Image && CLMode) return "exe"; if (Id == TY_PP_Asm && CLMode) return "asm"; return getInfo(Id).TempSuffix; } bool types::onlyAssembleType(ID Id) { return strchr(getInfo(Id).Flags, 'a'); } bool types::onlyPrecompileType(ID Id) { return strchr(getInfo(Id).Flags, 'p'); } bool types::canTypeBeUserSpecified(ID Id) { return strchr(getInfo(Id).Flags, 'u'); } bool types::appendSuffixForType(ID Id) { return strchr(getInfo(Id).Flags, 'A'); } bool types::canLipoType(ID Id) { return (Id == TY_Nothing || Id == TY_Image || Id == TY_Object || Id == TY_LTO_BC); } bool types::isAcceptedByClang(ID Id) { switch (Id) { default: return false; case TY_Asm: case TY_C: case TY_PP_C: case TY_CL: case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE: case TY_ObjC: case TY_PP_ObjC: case TY_PP_ObjC_Alias: case TY_CXX: case TY_PP_CXX: case TY_ObjCXX: case TY_PP_ObjCXX: case TY_PP_ObjCXX_Alias: case TY_CHeader: case TY_PP_CHeader: case TY_CLHeader: case TY_ObjCHeader: case TY_PP_ObjCHeader: case TY_CXXHeader: case TY_PP_CXXHeader: case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader: case TY_AST: case TY_ModuleFile: case TY_LLVM_IR: case TY_LLVM_BC: case TY_HLSL: // HLSL Change return true; } } bool types::isObjC(ID Id) { switch (Id) { default: return false; case TY_ObjC: case TY_PP_ObjC: case TY_PP_ObjC_Alias: case TY_ObjCXX: case TY_PP_ObjCXX: case TY_ObjCHeader: case TY_PP_ObjCHeader: case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader: case TY_PP_ObjCXX_Alias: return true; } } bool types::isCXX(ID Id) { switch (Id) { default: return false; case TY_CXX: case TY_PP_CXX: case TY_ObjCXX: case TY_PP_ObjCXX: case TY_PP_ObjCXX_Alias: case TY_CXXHeader: case TY_PP_CXXHeader: case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader: case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE: return true; } } bool types::isCuda(ID Id) { switch (Id) { default: return false; case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE: return true; } } types::ID types::lookupTypeForExtension(const char *Ext) { return llvm::StringSwitch<types::ID>(Ext) .Case("c", TY_C) .Case("i", TY_PP_C) .Case("m", TY_ObjC) .Case("M", TY_ObjCXX) .Case("h", TY_CHeader) .Case("hlsl", TY_HLSL) // HLSL Change .Case("C", TY_CXX) .Case("H", TY_CXXHeader) .Case("f", TY_PP_Fortran) .Case("F", TY_Fortran) .Case("s", TY_PP_Asm) .Case("asm", TY_PP_Asm) .Case("S", TY_Asm) .Case("o", TY_Object) .Case("obj", TY_Object) .Case("lib", TY_Object) .Case("ii", TY_PP_CXX) .Case("mi", TY_PP_ObjC) .Case("mm", TY_ObjCXX) .Case("bc", TY_LLVM_BC) .Case("cc", TY_CXX) .Case("CC", TY_CXX) .Case("cl", TY_CL) .Case("cp", TY_CXX) .Case("cu", TY_CUDA) .Case("cui", TY_PP_CUDA) .Case("hh", TY_CXXHeader) .Case("ll", TY_LLVM_IR) .Case("hpp", TY_CXXHeader) .Case("ads", TY_Ada) .Case("adb", TY_Ada) .Case("ast", TY_AST) .Case("c++", TY_CXX) .Case("C++", TY_CXX) .Case("cxx", TY_CXX) .Case("cpp", TY_CXX) .Case("CPP", TY_CXX) .Case("CXX", TY_CXX) .Case("for", TY_PP_Fortran) .Case("FOR", TY_PP_Fortran) .Case("fpp", TY_Fortran) .Case("FPP", TY_Fortran) .Case("f90", TY_PP_Fortran) .Case("f95", TY_PP_Fortran) .Case("F90", TY_Fortran) .Case("F95", TY_Fortran) .Case("mii", TY_PP_ObjCXX) .Case("pcm", TY_ModuleFile) .Case("pch", TY_PCH) .Case("gch", TY_PCH) .Default(TY_INVALID); } types::ID types::lookupTypeForTypeSpecifier(const char *Name) { for (unsigned i=0; i<numTypes; ++i) { types::ID Id = (types::ID) (i + 1); if (canTypeBeUserSpecified(Id) && strcmp(Name, getInfo(Id).Name) == 0) return Id; } return TY_INVALID; } // FIXME: Why don't we just put this list in the defs file, eh. void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl<phases::ID> &P) { if (Id != TY_Object) { if (getPreprocessedType(Id) != TY_INVALID) { P.push_back(phases::Preprocess); } if (onlyPrecompileType(Id)) { P.push_back(phases::Precompile); } else { if (!onlyAssembleType(Id)) { P.push_back(phases::Compile); P.push_back(phases::Backend); } if (Id != TY_CUDA_DEVICE) P.push_back(phases::Assemble); } } if (!onlyPrecompileType(Id) && Id != TY_CUDA_DEVICE) { P.push_back(phases::Link); } assert(0 < P.size() && "Not enough phases in list"); assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list"); return; } ID types::lookupCXXTypeForCType(ID Id) { switch (Id) { default: return Id; case types::TY_C: return types::TY_CXX; case types::TY_PP_C: return types::TY_PP_CXX; case types::TY_CHeader: return types::TY_CXXHeader; case types::TY_PP_CHeader: return types::TY_PP_CXXHeader; } }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/CMakeLists.txt
set(LLVM_LINK_COMPONENTS Option Support ) set(HLSL_IGNORE_SOURCES Action.cpp Compilation.cpp CrossWindowsToolChain.cpp Driver.cpp Job.cpp MinGWToolChain.cpp Multilib.cpp MSVCToolChain.cpp Phases.cpp SanitizerArgs.cpp Tool.cpp ToolChain.cpp ToolChains.cpp Tools.cpp Types.cpp ) add_clang_library(clangDriver DriverOptions.cpp DEPENDS ClangDriverOptions LINK_LIBS clangBasic )
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Driver.cpp
//===--- Driver.cpp - Clang GCC Compatible Driver -------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Driver.h" #include "InputInfo.h" #include "ToolChains.h" #include "clang/Basic/Version.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Job.h" #include "clang/Driver/Options.h" #include "clang/Driver/SanitizerArgs.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptSpecifier.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" #include <map> #include <memory> using namespace clang::driver; using namespace clang; using namespace llvm::opt; Driver::Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, DiagnosticsEngine &Diags) : Opts(createDriverOptTable()), Diags(Diags), Mode(GCCMode), SaveTemps(SaveTempsNone), ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT), UseStdLib(true), DefaultTargetTriple(DefaultTargetTriple), DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false), CCPrintHeaders(false), CCLogDiagnostics(false), CCGenDiagnostics(false), CCCGenericGCCName(""), CheckInputsExist(true), CCCUsePCH(true), SuppressMissingInputWarning(false) { Name = llvm::sys::path::filename(ClangExecutable); Dir = llvm::sys::path::parent_path(ClangExecutable); // Compute the path to the resource directory. StringRef ClangResourceDir(CLANG_RESOURCE_DIR); SmallString<128> P(Dir); if (ClangResourceDir != "") { llvm::sys::path::append(P, ClangResourceDir); } else { StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX); llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang", CLANG_VERSION_STRING); } ResourceDir = P.str(); } Driver::~Driver() { delete Opts; llvm::DeleteContainerSeconds(ToolChains); } void Driver::ParseDriverMode(ArrayRef<const char *> Args) { const std::string OptName = getOpts().getOption(options::OPT_driver_mode).getPrefixedName(); for (const char *ArgPtr : Args) { // Ingore nullptrs, they are response file's EOL markers if (ArgPtr == nullptr) continue; const StringRef Arg = ArgPtr; if (!Arg.startswith(OptName)) continue; const StringRef Value = Arg.drop_front(OptName.size()); const unsigned M = llvm::StringSwitch<unsigned>(Value) .Case("gcc", GCCMode) .Case("g++", GXXMode) .Case("cpp", CPPMode) .Case("cl", CLMode) .Default(~0U); if (M != ~0U) Mode = static_cast<DriverMode>(M); else Diag(diag::err_drv_unsupported_option_argument) << OptName << Value; } } InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings) { llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); unsigned IncludedFlagsBitmask; unsigned ExcludedFlagsBitmask; std::tie(IncludedFlagsBitmask, ExcludedFlagsBitmask) = getIncludeExcludeOptionFlagMasks(); unsigned MissingArgIndex, MissingArgCount; InputArgList Args = getOpts().ParseArgs(ArgStrings, MissingArgIndex, MissingArgCount, IncludedFlagsBitmask, ExcludedFlagsBitmask); // Check for missing argument error. if (MissingArgCount) Diag(clang::diag::err_drv_missing_argument) << Args.getArgString(MissingArgIndex) << MissingArgCount; // Check for unsupported options. for (const Arg *A : Args) { if (A->getOption().hasFlag(options::Unsupported)) { Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(Args); continue; } // Warn about -mcpu= without an argument. if (A->getOption().matches(options::OPT_mcpu_EQ) && A->containsValue("")) { Diag(clang::diag::warn_drv_empty_joined_argument) << A->getAsString(Args); } } for (const Arg *A : Args.filtered(options::OPT_UNKNOWN)) Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args); return Args; } // Determine which compilation mode we are in. We look for options which // affect the phase, starting with the earliest phases, and record which // option we used to determine the final phase. phases::ID Driver::getFinalPhase(const DerivedArgList &DAL, Arg **FinalPhaseArg) const { Arg *PhaseArg = nullptr; phases::ID FinalPhase; // -{E,EP,P,M,MM} only run the preprocessor. if (CCCIsCPP() || (PhaseArg = DAL.getLastArg(options::OPT_E)) || (PhaseArg = DAL.getLastArg(options::OPT__SLASH_EP)) || (PhaseArg = DAL.getLastArg(options::OPT_M, options::OPT_MM)) || (PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) { FinalPhase = phases::Preprocess; // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler. } else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) || (PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) || (PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) || (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) || (PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) || (PhaseArg = DAL.getLastArg(options::OPT__migrate)) || (PhaseArg = DAL.getLastArg(options::OPT__analyze, options::OPT__analyze_auto)) || (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) { FinalPhase = phases::Compile; // -S only runs up to the backend. } else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) { FinalPhase = phases::Backend; // -c and partial CUDA compilations only run up to the assembler. } else if ((PhaseArg = DAL.getLastArg(options::OPT_c)) || (PhaseArg = DAL.getLastArg(options::OPT_cuda_device_only)) || (PhaseArg = DAL.getLastArg(options::OPT_cuda_host_only))) { FinalPhase = phases::Assemble; // Otherwise do everything. } else FinalPhase = phases::Link; if (FinalPhaseArg) *FinalPhaseArg = PhaseArg; return FinalPhase; } static Arg *MakeInputArg(DerivedArgList &Args, OptTable *Opts, StringRef Value) { Arg *A = new Arg(Opts->getOption(options::OPT_INPUT), Value, Args.getBaseArgs().MakeIndex(Value), Value.data()); Args.AddSynthesizedArg(A); A->claim(); return A; } DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { DerivedArgList *DAL = new DerivedArgList(Args); bool HasNostdlib = Args.hasArg(options::OPT_nostdlib); for (Arg *A : Args) { // Unfortunately, we have to parse some forwarding options (-Xassembler, // -Xlinker, -Xpreprocessor) because we either integrate their functionality // (assembler and preprocessor), or bypass a previous driver ('collect2'). // Rewrite linker options, to replace --no-demangle with a custom internal // option. if ((A->getOption().matches(options::OPT_Wl_COMMA) || A->getOption().matches(options::OPT_Xlinker)) && A->containsValue("--no-demangle")) { // Add the rewritten no-demangle argument. DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_Xlinker__no_demangle)); // Add the remaining values as Xlinker arguments. for (const StringRef Val : A->getValues()) if (Val != "--no-demangle") DAL->AddSeparateArg(A, Opts->getOption(options::OPT_Xlinker), Val); continue; } // Rewrite preprocessor options, to replace -Wp,-MD,FOO which is used by // some build systems. We don't try to be complete here because we don't // care to encourage this usage model. if (A->getOption().matches(options::OPT_Wp_COMMA) && (A->getValue(0) == StringRef("-MD") || A->getValue(0) == StringRef("-MMD"))) { // Rewrite to -MD/-MMD along with -MF. if (A->getValue(0) == StringRef("-MD")) DAL->AddFlagArg(A, Opts->getOption(options::OPT_MD)); else DAL->AddFlagArg(A, Opts->getOption(options::OPT_MMD)); if (A->getNumValues() == 2) DAL->AddSeparateArg(A, Opts->getOption(options::OPT_MF), A->getValue(1)); continue; } // Rewrite reserved library names. if (A->getOption().matches(options::OPT_l)) { StringRef Value = A->getValue(); // Rewrite unless -nostdlib is present. if (!HasNostdlib && Value == "stdc++") { DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_stdcxx)); continue; } // Rewrite unconditionally. if (Value == "cc_kext") { DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_cckext)); continue; } } // Pick up inputs via the -- option. if (A->getOption().matches(options::OPT__DASH_DASH)) { A->claim(); for (const StringRef Val : A->getValues()) DAL->append(MakeInputArg(*DAL, Opts, Val)); continue; } DAL->append(A); } // Add a default value of -mlinker-version=, if one was given and the user // didn't specify one. #if defined(HOST_LINK_VERSION) if (!Args.hasArg(options::OPT_mlinker_version_EQ) && strlen(HOST_LINK_VERSION) > 0) { DAL->AddJoinedArg(0, Opts->getOption(options::OPT_mlinker_version_EQ), HOST_LINK_VERSION); DAL->getLastArg(options::OPT_mlinker_version_EQ)->claim(); } #endif return DAL; } /// \brief Compute target triple from args. /// /// This routine provides the logic to compute a target triple from various /// args passed to the driver and the default triple string. static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple, const ArgList &Args, StringRef DarwinArchName = "") { // FIXME: Already done in Compilation *Driver::BuildCompilation if (const Arg *A = Args.getLastArg(options::OPT_target)) DefaultTargetTriple = A->getValue(); llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple)); // Handle Apple-specific options available here. if (Target.isOSBinFormatMachO()) { // If an explict Darwin arch name is given, that trumps all. if (!DarwinArchName.empty()) { tools::darwin::setTripleTypeForMachOArchName(Target, DarwinArchName); return Target; } // Handle the Darwin '-arch' flag. if (Arg *A = Args.getLastArg(options::OPT_arch)) { StringRef ArchName = A->getValue(); tools::darwin::setTripleTypeForMachOArchName(Target, ArchName); } } // Handle pseudo-target flags '-mlittle-endian'/'-EL' and // '-mbig-endian'/'-EB'. if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian, options::OPT_mbig_endian)) { if (A->getOption().matches(options::OPT_mlittle_endian)) { llvm::Triple LE = Target.getLittleEndianArchVariant(); if (LE.getArch() != llvm::Triple::UnknownArch) Target = std::move(LE); } else { llvm::Triple BE = Target.getBigEndianArchVariant(); if (BE.getArch() != llvm::Triple::UnknownArch) Target = std::move(BE); } } // Skip further flag support on OSes which don't support '-m32' or '-m64'. if (Target.getArchName() == "tce" || Target.getOS() == llvm::Triple::Minix) return Target; // Handle pseudo-target flags '-m64', '-mx32', '-m32' and '-m16'. if (Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32, options::OPT_m32, options::OPT_m16)) { llvm::Triple::ArchType AT = llvm::Triple::UnknownArch; if (A->getOption().matches(options::OPT_m64)) { AT = Target.get64BitArchVariant().getArch(); if (Target.getEnvironment() == llvm::Triple::GNUX32) Target.setEnvironment(llvm::Triple::GNU); } else if (A->getOption().matches(options::OPT_mx32) && Target.get64BitArchVariant().getArch() == llvm::Triple::x86_64) { AT = llvm::Triple::x86_64; Target.setEnvironment(llvm::Triple::GNUX32); } else if (A->getOption().matches(options::OPT_m32)) { AT = Target.get32BitArchVariant().getArch(); if (Target.getEnvironment() == llvm::Triple::GNUX32) Target.setEnvironment(llvm::Triple::GNU); } else if (A->getOption().matches(options::OPT_m16) && Target.get32BitArchVariant().getArch() == llvm::Triple::x86) { AT = llvm::Triple::x86; Target.setEnvironment(llvm::Triple::CODE16); } if (AT != llvm::Triple::UnknownArch && AT != Target.getArch()) Target.setArch(AT); } return Target; } Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { llvm::PrettyStackTraceString CrashInfo("Compilation construction"); // FIXME: Handle environment options which affect driver behavior, somewhere // (client?). GCC_EXEC_PREFIX, LPATH, CC_PRINT_OPTIONS. #if 0 // HLSL Change - disallow COMPILER_PATH environment setting if (char *env = ::getenv("COMPILER_PATH")) { StringRef CompilerPath = env; while (!CompilerPath.empty()) { std::pair<StringRef, StringRef> Split = CompilerPath.split(llvm::sys::EnvPathSeparator); PrefixDirs.push_back(Split.first); CompilerPath = Split.second; } } #endif // HLSL Change // We look for the driver mode option early, because the mode can affect // how other options are parsed. ParseDriverMode(ArgList.slice(1)); // FIXME: What are we going to do with -V and -b? // FIXME: This stuff needs to go into the Compilation, not the driver. bool CCCPrintPhases; InputArgList Args = ParseArgStrings(ArgList.slice(1)); // -no-canonical-prefixes is used very early in main. Args.ClaimAllArgs(options::OPT_no_canonical_prefixes); // Ignore -pipe. Args.ClaimAllArgs(options::OPT_pipe); // Extract -ccc args. // // FIXME: We need to figure out where this behavior should live. Most of it // should be outside in the client; the parts that aren't should have proper // options, either by introducing new ones or by overloading gcc ones like -V // or -b. CCCPrintPhases = Args.hasArg(options::OPT_ccc_print_phases); CCCPrintBindings = Args.hasArg(options::OPT_ccc_print_bindings); if (const Arg *A = Args.getLastArg(options::OPT_ccc_gcc_name)) CCCGenericGCCName = A->getValue(); CCCUsePCH = Args.hasFlag(options::OPT_ccc_pch_is_pch, options::OPT_ccc_pch_is_pth); // FIXME: DefaultTargetTriple is used by the target-prefixed calls to as/ld // and getToolChain is const. if (IsCLMode()) { // clang-cl targets MSVC-style Win32. llvm::Triple T(DefaultTargetTriple); T.setOS(llvm::Triple::Win32); T.setEnvironment(llvm::Triple::MSVC); DefaultTargetTriple = T.str(); } if (const Arg *A = Args.getLastArg(options::OPT_target)) DefaultTargetTriple = A->getValue(); if (const Arg *A = Args.getLastArg(options::OPT_ccc_install_dir)) Dir = InstalledDir = A->getValue(); for (const Arg *A : Args.filtered(options::OPT_B)) { A->claim(); PrefixDirs.push_back(A->getValue(0)); } if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) SysRoot = A->getValue(); if (const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ)) DyldPrefix = A->getValue(); if (Args.hasArg(options::OPT_nostdlib)) UseStdLib = false; if (const Arg *A = Args.getLastArg(options::OPT_resource_dir)) ResourceDir = A->getValue(); if (const Arg *A = Args.getLastArg(options::OPT_save_temps_EQ)) { SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue()) .Case("cwd", SaveTempsCwd) .Case("obj", SaveTempsObj) .Default(SaveTempsCwd); } std::unique_ptr<llvm::opt::InputArgList> UArgs = llvm::make_unique<InputArgList>(std::move(Args)); // Perform the default argument translations. DerivedArgList *TranslatedArgs = TranslateInputArgs(*UArgs); // Owned by the host. const ToolChain &TC = getToolChain(*UArgs, computeTargetTriple(DefaultTargetTriple, *UArgs)); // The compilation takes ownership of Args. Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs); if (!HandleImmediateArgs(*C)) return C; // Construct the list of inputs. InputList Inputs; BuildInputs(C->getDefaultToolChain(), *TranslatedArgs, Inputs); // Construct the list of abstract actions to perform for this compilation. On // MachO targets this uses the driver-driver and universal actions. if (TC.getTriple().isOSBinFormatMachO()) BuildUniversalActions(C->getDefaultToolChain(), C->getArgs(), Inputs, C->getActions()); else BuildActions(C->getDefaultToolChain(), C->getArgs(), Inputs, C->getActions()); if (CCCPrintPhases) { PrintActions(*C); return C; } BuildJobs(*C); return C; } static void printArgList(raw_ostream &OS, const llvm::opt::ArgList &Args) { llvm::opt::ArgStringList ASL; for (const auto *A : Args) A->render(Args, ASL); for (auto I = ASL.begin(), E = ASL.end(); I != E; ++I) { if (I != ASL.begin()) OS << ' '; Command::printArg(OS, *I, true); } OS << '\n'; } // When clang crashes, produce diagnostic information including the fully // preprocessed source file(s). Request that the developer attach the // diagnostic information to a bug report. void Driver::generateCompilationDiagnostics(Compilation &C, const Command &FailingCommand) { if (C.getArgs().hasArg(options::OPT_fno_crash_diagnostics)) return; // Don't try to generate diagnostics for link or dsymutil jobs. if (FailingCommand.getCreator().isLinkJob() || FailingCommand.getCreator().isDsymutilJob()) return; // Print the version of the compiler. PrintVersion(C, llvm::errs()); Diag(clang::diag::note_drv_command_failed_diag_msg) << "PLEASE submit a bug report to " BUG_REPORT_URL " and include the " "crash backtrace, preprocessed source, and associated run script."; // Suppress driver output and emit preprocessor output to temp file. Mode = CPPMode; CCGenDiagnostics = true; // Save the original job command(s). Command Cmd = FailingCommand; // Keep track of whether we produce any errors while trying to produce // preprocessed sources. DiagnosticErrorTrap Trap(Diags); // Suppress tool output. C.initCompilationForDiagnostics(); // Construct the list of inputs. InputList Inputs; BuildInputs(C.getDefaultToolChain(), C.getArgs(), Inputs); for (InputList::iterator it = Inputs.begin(), ie = Inputs.end(); it != ie;) { bool IgnoreInput = false; // Ignore input from stdin or any inputs that cannot be preprocessed. // Check type first as not all linker inputs have a value. if (types::getPreprocessedType(it->first) == types::TY_INVALID) { IgnoreInput = true; } else if (!strcmp(it->second->getValue(), "-")) { Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating preprocessed source(s) - " "ignoring input from stdin."; IgnoreInput = true; } if (IgnoreInput) { it = Inputs.erase(it); ie = Inputs.end(); } else { ++it; } } if (Inputs.empty()) { Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating preprocessed source(s) - " "no preprocessable inputs."; return; } // Don't attempt to generate preprocessed files if multiple -arch options are // used, unless they're all duplicates. llvm::StringSet<> ArchNames; for (const Arg *A : C.getArgs()) { if (A->getOption().matches(options::OPT_arch)) { StringRef ArchName = A->getValue(); ArchNames.insert(ArchName); } } if (ArchNames.size() > 1) { Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating preprocessed source(s) - cannot generate " "preprocessed source with multiple -arch options."; return; } // Construct the list of abstract actions to perform for this compilation. On // Darwin OSes this uses the driver-driver and builds universal actions. const ToolChain &TC = C.getDefaultToolChain(); if (TC.getTriple().isOSBinFormatMachO()) BuildUniversalActions(TC, C.getArgs(), Inputs, C.getActions()); else BuildActions(TC, C.getArgs(), Inputs, C.getActions()); BuildJobs(C); // If there were errors building the compilation, quit now. if (Trap.hasErrorOccurred()) { Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating preprocessed source(s)."; return; } // Generate preprocessed output. SmallVector<std::pair<int, const Command *>, 4> FailingCommands; C.ExecuteJobs(C.getJobs(), FailingCommands); // If any of the preprocessing commands failed, clean up and exit. if (!FailingCommands.empty()) { if (!isSaveTempsEnabled()) C.CleanupFileList(C.getTempFiles(), true); Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating preprocessed source(s)."; return; } const ArgStringList &TempFiles = C.getTempFiles(); if (TempFiles.empty()) { Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating preprocessed source(s)."; return; } Diag(clang::diag::note_drv_command_failed_diag_msg) << "\n********************\n\n" "PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n" "Preprocessed source(s) and associated run script(s) are located at:"; SmallString<128> VFS; for (const char *TempFile : TempFiles) { Diag(clang::diag::note_drv_command_failed_diag_msg) << TempFile; if (StringRef(TempFile).endswith(".cache")) { // In some cases (modules) we'll dump extra data to help with reproducing // the crash into a directory next to the output. VFS = llvm::sys::path::filename(TempFile); llvm::sys::path::append(VFS, "vfs", "vfs.yaml"); } } // Assume associated files are based off of the first temporary file. CrashReportInfo CrashInfo(TempFiles[0], VFS); std::string Script = CrashInfo.Filename.rsplit('.').first.str() + ".sh"; std::error_code EC; llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl); if (EC) { Diag(clang::diag::note_drv_command_failed_diag_msg) << "Error generating run script: " + Script + " " + EC.message(); } else { ScriptOS << "# Crash reproducer for " << getClangFullVersion() << "\n" << "# Driver args: "; printArgList(ScriptOS, C.getInputArgs()); ScriptOS << "# Original command: "; Cmd.Print(ScriptOS, "\n", /*Quote=*/true); Cmd.Print(ScriptOS, "\n", /*Quote=*/true, &CrashInfo); Diag(clang::diag::note_drv_command_failed_diag_msg) << Script; } for (const auto &A : C.getArgs().filtered(options::OPT_frewrite_map_file, options::OPT_frewrite_map_file_EQ)) Diag(clang::diag::note_drv_command_failed_diag_msg) << A->getValue(); Diag(clang::diag::note_drv_command_failed_diag_msg) << "\n\n********************"; } void Driver::setUpResponseFiles(Compilation &C, Command &Cmd) { #ifdef MSFT_SUPPORTS_CHILD_PROCESSES // HLSL Change // Since argumentsFitWithinSystemLimits() may underestimate system's capacity // if the tool does not support response files, there is a chance/ that things // will just work without a response file, so we silently just skip it. if (Cmd.getCreator().getResponseFilesSupport() == Tool::RF_None || llvm::sys::argumentsFitWithinSystemLimits(Cmd.getArguments())) return; std::string TmpName = GetTemporaryPath("response", "txt"); Cmd.setResponseFile( C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()))); #endif } int Driver::ExecuteCompilation( Compilation &C, SmallVectorImpl<std::pair<int, const Command *>> &FailingCommands) { // Just print if -### was present. if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) { C.getJobs().Print(llvm::errs(), "\n", true); return 0; } // If there were errors building the compilation, quit now. if (Diags.hasErrorOccurred()) return 1; // Set up response file names for each command, if necessary for (auto &Job : C.getJobs()) setUpResponseFiles(C, Job); C.ExecuteJobs(C.getJobs(), FailingCommands); // Remove temp files. C.CleanupFileList(C.getTempFiles()); // If the command succeeded, we are done. if (FailingCommands.empty()) return 0; // Otherwise, remove result files and print extra information about abnormal // failures. for (const auto &CmdPair : FailingCommands) { int Res = CmdPair.first; const Command *FailingCommand = CmdPair.second; // Remove result files if we're not saving temps. if (!isSaveTempsEnabled()) { const JobAction *JA = cast<JobAction>(&FailingCommand->getSource()); C.CleanupFileMap(C.getResultFiles(), JA, true); // Failure result files are valid unless we crashed. if (Res < 0) C.CleanupFileMap(C.getFailureResultFiles(), JA, true); } // Print extra information about abnormal failures, if possible. // // This is ad-hoc, but we don't want to be excessively noisy. If the result // status was 1, assume the command failed normally. In particular, if it // was the compiler then assume it gave a reasonable error code. Failures // in other tools are less common, and they generally have worse // diagnostics, so always print the diagnostic there. const Tool &FailingTool = FailingCommand->getCreator(); if (!FailingCommand->getCreator().hasGoodDiagnostics() || Res != 1) { // FIXME: See FIXME above regarding result code interpretation. if (Res < 0) Diag(clang::diag::err_drv_command_signalled) << FailingTool.getShortName(); else Diag(clang::diag::err_drv_command_failed) << FailingTool.getShortName() << Res; } } return 0; } void Driver::PrintHelp(bool ShowHidden) const { unsigned IncludedFlagsBitmask; unsigned ExcludedFlagsBitmask; std::tie(IncludedFlagsBitmask, ExcludedFlagsBitmask) = getIncludeExcludeOptionFlagMasks(); ExcludedFlagsBitmask |= options::NoDriverOption; if (!ShowHidden) ExcludedFlagsBitmask |= HelpHidden; getOpts().PrintHelp(llvm::outs(), Name.c_str(), DriverTitle.c_str(), "", IncludedFlagsBitmask, ExcludedFlagsBitmask); } void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const { // FIXME: The following handlers should use a callback mechanism, we don't // know what the client would like to do. OS << getClangFullVersion() << '\n'; const ToolChain &TC = C.getDefaultToolChain(); OS << "Target: " << TC.getTripleString() << '\n'; // Print the threading model. if (Arg *A = C.getArgs().getLastArg(options::OPT_mthread_model)) { // Don't print if the ToolChain would have barfed on it already if (TC.isThreadModelSupported(A->getValue())) OS << "Thread model: " << A->getValue(); } else OS << "Thread model: " << TC.getThreadModel(); OS << '\n'; } /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories /// option. static void PrintDiagnosticCategories(raw_ostream &OS) { // Skip the empty category. for (unsigned i = 1, max = DiagnosticIDs::getNumberOfCategories(); i != max; ++i) OS << i << ',' << DiagnosticIDs::getCategoryNameFromID(i) << '\n'; } bool Driver::HandleImmediateArgs(const Compilation &C) { // The order these options are handled in gcc is all over the place, but we // don't expect inconsistencies w.r.t. that to matter in practice. if (C.getArgs().hasArg(options::OPT_dumpmachine)) { llvm::outs() << C.getDefaultToolChain().getTripleString() << '\n'; return false; } if (C.getArgs().hasArg(options::OPT_dumpversion)) { // Since -dumpversion is only implemented for pedantic GCC compatibility, we // return an answer which matches our definition of __VERSION__. // // If we want to return a more correct answer some day, then we should // introduce a non-pedantically GCC compatible mode to Clang in which we // provide sensible definitions for -dumpversion, __VERSION__, etc. llvm::outs() << "4.2.1\n"; return false; } if (C.getArgs().hasArg(options::OPT__print_diagnostic_categories)) { PrintDiagnosticCategories(llvm::outs()); return false; } if (C.getArgs().hasArg(options::OPT_help) || C.getArgs().hasArg(options::OPT__help_hidden)) { PrintHelp(C.getArgs().hasArg(options::OPT__help_hidden)); return false; } if (C.getArgs().hasArg(options::OPT__version)) { // Follow gcc behavior and use stdout for --version and stderr for -v. PrintVersion(C, llvm::outs()); return false; } if (C.getArgs().hasArg(options::OPT_v) || C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) { PrintVersion(C, llvm::errs()); SuppressMissingInputWarning = true; } const ToolChain &TC = C.getDefaultToolChain(); if (C.getArgs().hasArg(options::OPT_v)) TC.printVerboseInfo(llvm::errs()); if (C.getArgs().hasArg(options::OPT_print_search_dirs)) { llvm::outs() << "programs: ="; bool separator = false; for (const std::string &Path : TC.getProgramPaths()) { if (separator) llvm::outs() << ':'; llvm::outs() << Path; separator = true; } llvm::outs() << "\n"; llvm::outs() << "libraries: =" << ResourceDir; StringRef sysroot = C.getSysRoot(); for (const std::string &Path : TC.getFilePaths()) { // Always print a separator. ResourceDir was the first item shown. llvm::outs() << ':'; // Interpretation of leading '=' is needed only for NetBSD. if (Path[0] == '=') llvm::outs() << sysroot << Path.substr(1); else llvm::outs() << Path; } llvm::outs() << "\n"; return false; } // FIXME: The following handlers should use a callback mechanism, we don't // know what the client would like to do. if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) { llvm::outs() << GetFilePath(A->getValue(), TC) << "\n"; return false; } if (Arg *A = C.getArgs().getLastArg(options::OPT_print_prog_name_EQ)) { llvm::outs() << GetProgramPath(A->getValue(), TC) << "\n"; return false; } if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) { llvm::outs() << GetFilePath("libgcc.a", TC) << "\n"; return false; } if (C.getArgs().hasArg(options::OPT_print_multi_lib)) { for (const Multilib &Multilib : TC.getMultilibs()) llvm::outs() << Multilib << "\n"; return false; } if (C.getArgs().hasArg(options::OPT_print_multi_directory)) { for (const Multilib &Multilib : TC.getMultilibs()) { if (Multilib.gccSuffix().empty()) llvm::outs() << ".\n"; else { StringRef Suffix(Multilib.gccSuffix()); assert(Suffix.front() == '/'); llvm::outs() << Suffix.substr(1) << "\n"; } } return false; } return true; } // Display an action graph human-readably. Action A is the "sink" node // and latest-occuring action. Traversal is in pre-order, visiting the // inputs to each action before printing the action itself. static unsigned PrintActions1(const Compilation &C, Action *A, std::map<Action *, unsigned> &Ids) { if (Ids.count(A)) // A was already visited. return Ids[A]; std::string str; llvm::raw_string_ostream os(str); os << Action::getClassName(A->getKind()) << ", "; if (InputAction *IA = dyn_cast<InputAction>(A)) { os << "\"" << IA->getInputArg().getValue() << "\""; } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) { os << '"' << BIA->getArchName() << '"' << ", {" << PrintActions1(C, *BIA->begin(), Ids) << "}"; } else if (CudaDeviceAction *CDA = dyn_cast<CudaDeviceAction>(A)) { os << '"' << CDA->getGpuArchName() << '"' << ", {" << PrintActions1(C, *CDA->begin(), Ids) << "}"; } else { ActionList *AL; if (CudaHostAction *CHA = dyn_cast<CudaHostAction>(A)) { os << "{" << PrintActions1(C, *CHA->begin(), Ids) << "}" << ", gpu binaries "; AL = &CHA->getDeviceActions(); } else AL = &A->getInputs(); const char *Prefix = "{"; for (Action *PreRequisite : *AL) { os << Prefix << PrintActions1(C, PreRequisite, Ids); Prefix = ", "; } os << "}"; } unsigned Id = Ids.size(); Ids[A] = Id; llvm::errs() << Id << ": " << os.str() << ", " << types::getTypeName(A->getType()) << "\n"; return Id; } // Print the action graphs in a compilation C. // For example "clang -c file1.c file2.c" is composed of two subgraphs. void Driver::PrintActions(const Compilation &C) const { std::map<Action *, unsigned> Ids; for (Action *A : C.getActions()) PrintActions1(C, A, Ids); } /// \brief Check whether the given input tree contains any compilation or /// assembly actions. static bool ContainsCompileOrAssembleAction(const Action *A) { if (isa<CompileJobAction>(A) || isa<BackendJobAction>(A) || isa<AssembleJobAction>(A)) return true; for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it) if (ContainsCompileOrAssembleAction(*it)) return true; return false; } void Driver::BuildUniversalActions(const ToolChain &TC, DerivedArgList &Args, const InputList &BAInputs, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building universal build actions"); // Collect the list of architectures. Duplicates are allowed, but should only // be handled once (in the order seen). llvm::StringSet<> ArchNames; SmallVector<const char *, 4> Archs; for (Arg *A : Args) { if (A->getOption().matches(options::OPT_arch)) { // Validate the option here; we don't save the type here because its // particular spelling may participate in other driver choices. llvm::Triple::ArchType Arch = tools::darwin::getArchTypeForMachOArchName(A->getValue()); if (Arch == llvm::Triple::UnknownArch) { Diag(clang::diag::err_drv_invalid_arch_name) << A->getAsString(Args); continue; } A->claim(); if (ArchNames.insert(A->getValue()).second) Archs.push_back(A->getValue()); } } // When there is no explicit arch for this platform, make sure we still bind // the architecture (to the default) so that -Xarch_ is handled correctly. if (!Archs.size()) Archs.push_back(Args.MakeArgString(TC.getDefaultUniversalArchName())); ActionList SingleActions; BuildActions(TC, Args, BAInputs, SingleActions); // Add in arch bindings for every top level action, as well as lipo and // dsymutil steps if needed. for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) { Action *Act = SingleActions[i]; // Make sure we can lipo this kind of output. If not (and it is an actual // output) then we disallow, since we can't create an output file with the // right name without overwriting it. We could remove this oddity by just // changing the output names to include the arch, which would also fix // -save-temps. Compatibility wins for now. if (Archs.size() > 1 && !types::canLipoType(Act->getType())) Diag(clang::diag::err_drv_invalid_output_with_multiple_archs) << types::getTypeName(Act->getType()); ActionList Inputs; for (unsigned i = 0, e = Archs.size(); i != e; ++i) { Inputs.push_back( new BindArchAction(std::unique_ptr<Action>(Act), Archs[i])); if (i != 0) Inputs.back()->setOwnsInputs(false); } // Lipo if necessary, we do it this way because we need to set the arch flag // so that -Xarch_ gets overwritten. if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing) Actions.append(Inputs.begin(), Inputs.end()); else Actions.push_back(new LipoJobAction(Inputs, Act->getType())); // Handle debug info queries. Arg *A = Args.getLastArg(options::OPT_g_Group); if (A && !A->getOption().matches(options::OPT_g0) && !A->getOption().matches(options::OPT_gstabs) && ContainsCompileOrAssembleAction(Actions.back())) { // Add a 'dsymutil' step if necessary, when debug info is enabled and we // have a compile input. We need to run 'dsymutil' ourselves in such cases // because the debug info will refer to a temporary object file which // will be removed at the end of the compilation process. if (Act->getType() == types::TY_Image) { ActionList Inputs; Inputs.push_back(Actions.back()); Actions.pop_back(); Actions.push_back(new DsymutilJobAction(Inputs, types::TY_dSYM)); } // Verify the debug info output. if (Args.hasArg(options::OPT_verify_debug_info)) { std::unique_ptr<Action> VerifyInput(Actions.back()); Actions.pop_back(); Actions.push_back(new VerifyDebugInfoJobAction(std::move(VerifyInput), types::TY_Nothing)); } } } } /// \brief Check that the file referenced by Value exists. If it doesn't, /// issue a diagnostic and return false. static bool DiagnoseInputExistence(const Driver &D, const DerivedArgList &Args, StringRef Value) { if (!D.getCheckInputsExist()) return true; // stdin always exists. if (Value == "-") return true; SmallString<64> Path(Value); if (Arg *WorkDir = Args.getLastArg(options::OPT_working_directory)) { if (!llvm::sys::path::is_absolute(Path)) { SmallString<64> Directory(WorkDir->getValue()); llvm::sys::path::append(Directory, Value); Path.assign(Directory); } } if (llvm::sys::fs::exists(Twine(Path))) return true; if (D.IsCLMode() && !llvm::sys::path::is_absolute(Twine(Path)) && llvm::sys::Process::FindInEnvPath("LIB", Value)) return true; D.Diag(clang::diag::err_drv_no_such_file) << Path; return false; } // Construct a the list of inputs and their types. void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, InputList &Inputs) const { // Track the current user specified (-x) input. We also explicitly track the // argument used to set the type; we only want to claim the type when we // actually use it, so we warn about unused -x arguments. types::ID InputType = types::TY_Nothing; Arg *InputTypeArg = nullptr; // The last /TC or /TP option sets the input type to C or C++ globally. if (Arg *TCTP = Args.getLastArgNoClaim(options::OPT__SLASH_TC, options::OPT__SLASH_TP)) { InputTypeArg = TCTP; InputType = TCTP->getOption().matches(options::OPT__SLASH_TC) ? types::TY_C : types::TY_CXX; arg_iterator it = Args.filtered_begin(options::OPT__SLASH_TC, options::OPT__SLASH_TP); const arg_iterator ie = Args.filtered_end(); Arg *Previous = *it++; bool ShowNote = false; while (it != ie) { Diag(clang::diag::warn_drv_overriding_flag_option) << Previous->getSpelling() << (*it)->getSpelling(); Previous = *it++; ShowNote = true; } if (ShowNote) Diag(clang::diag::note_drv_t_option_is_global); // No driver mode exposes -x and /TC or /TP; we don't support mixing them. assert(!Args.hasArg(options::OPT_x) && "-x and /TC or /TP is not allowed"); } for (Arg *A : Args) { if (A->getOption().getKind() == Option::InputClass) { const char *Value = A->getValue(); types::ID Ty = types::TY_INVALID; // Infer the input type if necessary. if (InputType == types::TY_Nothing) { // If there was an explicit arg for this, claim it. if (InputTypeArg) InputTypeArg->claim(); // stdin must be handled specially. if (memcmp(Value, "-", 2) == 0) { // If running with -E, treat as a C input (this changes the builtin // macros, for example). This may be overridden by -ObjC below. // // Otherwise emit an error but still use a valid type to avoid // spurious errors (e.g., no inputs). if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP()) Diag(IsCLMode() ? clang::diag::err_drv_unknown_stdin_type_clang_cl : clang::diag::err_drv_unknown_stdin_type); Ty = types::TY_C; } else { // Otherwise lookup by extension. // Fallback is C if invoked as C preprocessor or Object otherwise. // We use a host hook here because Darwin at least has its own // idea of what .s is. if (const char *Ext = strrchr(Value, '.')) Ty = TC.LookupTypeForExtension(Ext + 1); if (Ty == types::TY_INVALID) { if (CCCIsCPP()) Ty = types::TY_C; else Ty = types::TY_Object; } // If the driver is invoked as C++ compiler (like clang++ or c++) it // should autodetect some input files as C++ for g++ compatibility. if (CCCIsCXX()) { types::ID OldTy = Ty; Ty = types::lookupCXXTypeForCType(Ty); if (Ty != OldTy) Diag(clang::diag::warn_drv_treating_input_as_cxx) << getTypeName(OldTy) << getTypeName(Ty); } } // -ObjC and -ObjC++ override the default language, but only for "source // files". We just treat everything that isn't a linker input as a // source file. // // FIXME: Clean this up if we move the phase sequence into the type. if (Ty != types::TY_Object) { if (Args.hasArg(options::OPT_ObjC)) Ty = types::TY_ObjC; else if (Args.hasArg(options::OPT_ObjCXX)) Ty = types::TY_ObjCXX; } } else { assert(InputTypeArg && "InputType set w/o InputTypeArg"); if (!InputTypeArg->getOption().matches(options::OPT_x)) { // If emulating cl.exe, make sure that /TC and /TP don't affect input // object files. const char *Ext = strrchr(Value, '.'); if (Ext && TC.LookupTypeForExtension(Ext + 1) == types::TY_Object) Ty = types::TY_Object; } if (Ty == types::TY_INVALID) { Ty = InputType; InputTypeArg->claim(); } } if (DiagnoseInputExistence(*this, Args, Value)) Inputs.push_back(std::make_pair(Ty, A)); } else if (A->getOption().matches(options::OPT__SLASH_Tc)) { StringRef Value = A->getValue(); if (DiagnoseInputExistence(*this, Args, Value)) { Arg *InputArg = MakeInputArg(Args, Opts, A->getValue()); Inputs.push_back(std::make_pair(types::TY_C, InputArg)); } A->claim(); } else if (A->getOption().matches(options::OPT__SLASH_Tp)) { StringRef Value = A->getValue(); if (DiagnoseInputExistence(*this, Args, Value)) { Arg *InputArg = MakeInputArg(Args, Opts, A->getValue()); Inputs.push_back(std::make_pair(types::TY_CXX, InputArg)); } A->claim(); } else if (A->getOption().hasFlag(options::LinkerInput)) { // Just treat as object type, we could make a special type for this if // necessary. Inputs.push_back(std::make_pair(types::TY_Object, A)); } else if (A->getOption().matches(options::OPT_x)) { InputTypeArg = A; InputType = types::lookupTypeForTypeSpecifier(A->getValue()); A->claim(); // Follow gcc behavior and treat as linker input for invalid -x // options. Its not clear why we shouldn't just revert to unknown; but // this isn't very important, we might as well be bug compatible. if (!InputType) { Diag(clang::diag::err_drv_unknown_language) << A->getValue(); InputType = types::TY_Object; } } } if (CCCIsCPP() && Inputs.empty()) { // If called as standalone preprocessor, stdin is processed // if no other input is present. Arg *A = MakeInputArg(Args, Opts, "-"); Inputs.push_back(std::make_pair(types::TY_C, A)); } } // For each unique --cuda-gpu-arch= argument creates a TY_CUDA_DEVICE input // action and then wraps each in CudaDeviceAction paired with appropriate GPU // arch name. If we're only building device-side code, each action remains // independent. Otherwise we pass device-side actions as inputs to a new // CudaHostAction which combines both host and device side actions. static std::unique_ptr<Action> buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, const Arg *InputArg, const types::ID InputType, std::unique_ptr<Action> Current, ActionList &Actions) { assert(InputType == types::TY_CUDA && "CUDA Actions only apply to CUDA inputs."); // Collect all cuda_gpu_arch parameters, removing duplicates. SmallVector<const char *, 4> GpuArchList; llvm::StringSet<> GpuArchNames; for (Arg *A : Args) { if (A->getOption().matches(options::OPT_cuda_gpu_arch_EQ)) { A->claim(); if (GpuArchNames.insert(A->getValue()).second) GpuArchList.push_back(A->getValue()); } } // Default to sm_20 which is the lowest common denominator for supported GPUs. // sm_20 code should work correctly, if suboptimally, on all newer GPUs. if (GpuArchList.empty()) GpuArchList.push_back("sm_20"); // Replicate inputs for each GPU architecture. Driver::InputList CudaDeviceInputs; for (unsigned i = 0, e = GpuArchList.size(); i != e; ++i) CudaDeviceInputs.push_back(std::make_pair(types::TY_CUDA_DEVICE, InputArg)); // Build actions for all device inputs. ActionList CudaDeviceActions; D.BuildActions(TC, Args, CudaDeviceInputs, CudaDeviceActions); assert(GpuArchList.size() == CudaDeviceActions.size() && "Failed to create actions for all devices"); // Check whether any of device actions stopped before they could generate PTX. bool PartialCompilation = false; bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only); for (unsigned i = 0, e = GpuArchList.size(); i != e; ++i) { if (CudaDeviceActions[i]->getKind() != Action::BackendJobClass) { PartialCompilation = true; break; } } // Figure out what to do with device actions -- pass them as inputs to the // host action or run each of them independently. if (PartialCompilation || DeviceOnlyCompilation) { // In case of partial or device-only compilation results of device actions // are not consumed by the host action device actions have to be added to // top-level actions list with AtTopLevel=true and run independently. // -o is ambiguous if we have more than one top-level action. if (Args.hasArg(options::OPT_o) && (!DeviceOnlyCompilation || GpuArchList.size() > 1)) { D.Diag(clang::diag::err_drv_output_argument_with_multiple_files); return nullptr; } for (unsigned i = 0, e = GpuArchList.size(); i != e; ++i) Actions.push_back( new CudaDeviceAction(std::unique_ptr<Action>(CudaDeviceActions[i]), GpuArchList[i], /* AtTopLevel */ true)); // Kill host action in case of device-only compilation. if (DeviceOnlyCompilation) Current.reset(nullptr); return Current; } else { // Outputs of device actions during complete CUDA compilation get created // with AtTopLevel=false and become inputs for the host action. ActionList DeviceActions; for (unsigned i = 0, e = GpuArchList.size(); i != e; ++i) DeviceActions.push_back( new CudaDeviceAction(std::unique_ptr<Action>(CudaDeviceActions[i]), GpuArchList[i], /* AtTopLevel */ false)); // Return a new host action that incorporates original host action and all // device actions. return std::unique_ptr<Action>( new CudaHostAction(std::move(Current), DeviceActions)); } } void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args, const InputList &Inputs, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building compilation actions"); if (!SuppressMissingInputWarning && Inputs.empty()) { Diag(clang::diag::err_drv_no_input_files); return; } Arg *FinalPhaseArg; phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg); if (FinalPhase == phases::Link && Args.hasArg(options::OPT_emit_llvm)) { Diag(clang::diag::err_drv_emit_llvm_link); } // Reject -Z* at the top level, these options should never have been exposed // by gcc. if (Arg *A = Args.getLastArg(options::OPT_Z_Joined)) Diag(clang::diag::err_drv_use_of_Z_option) << A->getAsString(Args); // Diagnose misuse of /Fo. if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fo)) { StringRef V = A->getValue(); if (Inputs.size() > 1 && !V.empty() && !llvm::sys::path::is_separator(V.back())) { // Check whether /Fo tries to name an output file for multiple inputs. Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources) << A->getSpelling() << V; Args.eraseArg(options::OPT__SLASH_Fo); } } // Diagnose misuse of /Fa. if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fa)) { StringRef V = A->getValue(); if (Inputs.size() > 1 && !V.empty() && !llvm::sys::path::is_separator(V.back())) { // Check whether /Fa tries to name an asm file for multiple inputs. Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources) << A->getSpelling() << V; Args.eraseArg(options::OPT__SLASH_Fa); } } // Diagnose misuse of /o. if (Arg *A = Args.getLastArg(options::OPT__SLASH_o)) { if (A->getValue()[0] == '\0') { // It has to have a value. Diag(clang::diag::err_drv_missing_argument) << A->getSpelling() << 1; Args.eraseArg(options::OPT__SLASH_o); } } // Construct the actions to perform. ActionList LinkerInputs; llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL; for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { types::ID InputType = Inputs[i].first; const Arg *InputArg = Inputs[i].second; PL.clear(); types::getCompilationPhases(InputType, PL); // If the first step comes after the final phase we are doing as part of // this compilation, warn the user about it. phases::ID InitialPhase = PL[0]; if (InitialPhase > FinalPhase) { // Claim here to avoid the more general unused warning. InputArg->claim(); // Suppress all unused style warnings with -Qunused-arguments if (Args.hasArg(options::OPT_Qunused_arguments)) continue; // Special case when final phase determined by binary name, rather than // by a command-line argument with a corresponding Arg. if (CCCIsCPP()) Diag(clang::diag::warn_drv_input_file_unused_by_cpp) << InputArg->getAsString(Args) << getPhaseName(InitialPhase); // Special case '-E' warning on a previously preprocessed file to make // more sense. else if (InitialPhase == phases::Compile && FinalPhase == phases::Preprocess && getPreprocessedType(InputType) == types::TY_INVALID) Diag(clang::diag::warn_drv_preprocessed_input_file_unused) << InputArg->getAsString(Args) << !!FinalPhaseArg << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() : ""); else Diag(clang::diag::warn_drv_input_file_unused) << InputArg->getAsString(Args) << getPhaseName(InitialPhase) << !!FinalPhaseArg << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() : ""); continue; } phases::ID CudaInjectionPhase; if (isSaveTempsEnabled()) { // All phases are done independently, inject GPU blobs during compilation // phase as that's where we generate glue code to init them. CudaInjectionPhase = phases::Compile; } else { // Assumes that clang does everything up until linking phase, so we inject // cuda device actions at the last step before linking. Otherwise CUDA // host action forces preprocessor into a separate invocation. if (FinalPhase == phases::Link) { for (auto i = PL.begin(), e = PL.end(); i != e; ++i) { auto next = i + 1; if (next != e && *next == phases::Link) CudaInjectionPhase = *i; } } else CudaInjectionPhase = FinalPhase; } // Build the pipeline for this file. std::unique_ptr<Action> Current(new InputAction(*InputArg, InputType)); for (SmallVectorImpl<phases::ID>::iterator i = PL.begin(), e = PL.end(); i != e; ++i) { phases::ID Phase = *i; // We are done if this step is past what the user requested. if (Phase > FinalPhase) break; // Queue linker inputs. if (Phase == phases::Link) { assert((i + 1) == e && "linking must be final compilation step."); LinkerInputs.push_back(Current.release()); break; } // Some types skip the assembler phase (e.g., llvm-bc), but we can't // encode this in the steps because the intermediate type depends on // arguments. Just special case here. if (Phase == phases::Assemble && Current->getType() != types::TY_PP_Asm) continue; // Otherwise construct the appropriate action. Current = ConstructPhaseAction(TC, Args, Phase, std::move(Current)); if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase && !Args.hasArg(options::OPT_cuda_host_only)) { Current = buildCudaActions(*this, TC, Args, InputArg, InputType, std::move(Current), Actions); if (!Current) break; } if (Current->getType() == types::TY_Nothing) break; } // If we ended with something, add to the output list. if (Current) Actions.push_back(Current.release()); } // Add a link action if necessary. if (!LinkerInputs.empty()) Actions.push_back(new LinkJobAction(LinkerInputs, types::TY_Image)); // If we are linking, claim any options which are obviously only used for // compilation. if (FinalPhase == phases::Link && PL.size() == 1) { Args.ClaimAllArgs(options::OPT_CompileOnly_Group); Args.ClaimAllArgs(options::OPT_cl_compile_Group); } // Claim ignored clang-cl options. Args.ClaimAllArgs(options::OPT_cl_ignored_Group); } std::unique_ptr<Action> Driver::ConstructPhaseAction(const ToolChain &TC, const ArgList &Args, phases::ID Phase, std::unique_ptr<Action> Input) const { llvm::PrettyStackTraceString CrashInfo("Constructing phase actions"); // Build the appropriate action. switch (Phase) { case phases::Link: llvm_unreachable("link action invalid here."); case phases::Preprocess: { types::ID OutputTy; // -{M, MM} alter the output type. if (Args.hasArg(options::OPT_M, options::OPT_MM)) { OutputTy = types::TY_Dependencies; } else { OutputTy = Input->getType(); if (!Args.hasFlag(options::OPT_frewrite_includes, options::OPT_fno_rewrite_includes, false) && !CCGenDiagnostics) OutputTy = types::getPreprocessedType(OutputTy); assert(OutputTy != types::TY_INVALID && "Cannot preprocess this input type!"); } return llvm::make_unique<PreprocessJobAction>(std::move(Input), OutputTy); } case phases::Precompile: { types::ID OutputTy = types::TY_PCH; if (Args.hasArg(options::OPT_fsyntax_only)) { // Syntax checks should not emit a PCH file OutputTy = types::TY_Nothing; } return llvm::make_unique<PrecompileJobAction>(std::move(Input), OutputTy); } case phases::Compile: { if (Args.hasArg(options::OPT_fsyntax_only)) return llvm::make_unique<CompileJobAction>(std::move(Input), types::TY_Nothing); if (Args.hasArg(options::OPT_rewrite_objc)) return llvm::make_unique<CompileJobAction>(std::move(Input), types::TY_RewrittenObjC); if (Args.hasArg(options::OPT_rewrite_legacy_objc)) return llvm::make_unique<CompileJobAction>(std::move(Input), types::TY_RewrittenLegacyObjC); if (Args.hasArg(options::OPT__analyze, options::OPT__analyze_auto)) return llvm::make_unique<AnalyzeJobAction>(std::move(Input), types::TY_Plist); if (Args.hasArg(options::OPT__migrate)) return llvm::make_unique<MigrateJobAction>(std::move(Input), types::TY_Remap); if (Args.hasArg(options::OPT_emit_ast)) return llvm::make_unique<CompileJobAction>(std::move(Input), types::TY_AST); if (Args.hasArg(options::OPT_module_file_info)) return llvm::make_unique<CompileJobAction>(std::move(Input), types::TY_ModuleFile); if (Args.hasArg(options::OPT_verify_pch)) return llvm::make_unique<VerifyPCHJobAction>(std::move(Input), types::TY_Nothing); return llvm::make_unique<CompileJobAction>(std::move(Input), types::TY_LLVM_BC); } case phases::Backend: { if (IsUsingLTO(Args)) { types::ID Output = Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC; return llvm::make_unique<BackendJobAction>(std::move(Input), Output); } if (Args.hasArg(options::OPT_emit_llvm)) { types::ID Output = Args.hasArg(options::OPT_S) ? types::TY_LLVM_IR : types::TY_LLVM_BC; return llvm::make_unique<BackendJobAction>(std::move(Input), Output); } return llvm::make_unique<BackendJobAction>(std::move(Input), types::TY_PP_Asm); } case phases::Assemble: return llvm::make_unique<AssembleJobAction>(std::move(Input), types::TY_Object); } llvm_unreachable("invalid phase in ConstructPhaseAction"); } bool Driver::IsUsingLTO(const ArgList &Args) const { return Args.hasFlag(options::OPT_flto, options::OPT_fno_lto, false); } void Driver::BuildJobs(Compilation &C) const { llvm::PrettyStackTraceString CrashInfo("Building compilation jobs"); Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o); // It is an error to provide a -o option if we are making multiple output // files. if (FinalOutput) { unsigned NumOutputs = 0; for (const Action *A : C.getActions()) if (A->getType() != types::TY_Nothing) ++NumOutputs; if (NumOutputs > 1) { Diag(clang::diag::err_drv_output_argument_with_multiple_files); FinalOutput = nullptr; } } // Collect the list of architectures. llvm::StringSet<> ArchNames; if (C.getDefaultToolChain().getTriple().isOSBinFormatMachO()) for (const Arg *A : C.getArgs()) if (A->getOption().matches(options::OPT_arch)) ArchNames.insert(A->getValue()); for (Action *A : C.getActions()) { // If we are linking an image for multiple archs then the linker wants // -arch_multiple and -final_output <final image name>. Unfortunately, this // doesn't fit in cleanly because we have to pass this information down. // // FIXME: This is a hack; find a cleaner way to integrate this into the // process. const char *LinkingOutput = nullptr; if (isa<LipoJobAction>(A)) { if (FinalOutput) LinkingOutput = FinalOutput->getValue(); else LinkingOutput = getDefaultImageName(); } InputInfo II; BuildJobsForAction(C, A, &C.getDefaultToolChain(), /*BoundArch*/ nullptr, /*AtTopLevel*/ true, /*MultipleArchs*/ ArchNames.size() > 1, /*LinkingOutput*/ LinkingOutput, II); } // If the user passed -Qunused-arguments or there were errors, don't warn // about any unused arguments. if (Diags.hasErrorOccurred() || C.getArgs().hasArg(options::OPT_Qunused_arguments)) return; // Claim -### here. (void)C.getArgs().hasArg(options::OPT__HASH_HASH_HASH); // Claim --driver-mode, it was handled earlier. (void)C.getArgs().hasArg(options::OPT_driver_mode); (void)C.getArgs().hasArg(options::OPT_verify); // HLSL Change - claim -verify for (Arg *A : C.getArgs()) { // FIXME: It would be nice to be able to send the argument to the // DiagnosticsEngine, so that extra values, position, and so on could be // printed. if (!A->isClaimed()) { if (A->getOption().hasFlag(options::NoArgumentUnused)) continue; // Suppress the warning automatically if this is just a flag, and it is an // instance of an argument we already claimed. const Option &Opt = A->getOption(); if (Opt.getKind() == Option::FlagClass) { bool DuplicateClaimed = false; for (const Arg *AA : C.getArgs().filtered(&Opt)) { if (AA->isClaimed()) { DuplicateClaimed = true; break; } } if (DuplicateClaimed) continue; } Diag(clang::diag::warn_drv_unused_argument) << A->getAsString(C.getArgs()); } } } static const Tool *SelectToolForJob(Compilation &C, bool SaveTemps, const ToolChain *TC, const JobAction *JA, const ActionList *&Inputs) { const Tool *ToolForJob = nullptr; // See if we should look for a compiler with an integrated assembler. We match // bottom up, so what we are actually looking for is an assembler job with a // compiler input. if (TC->useIntegratedAs() && !SaveTemps && !C.getArgs().hasArg(options::OPT_via_file_asm) && !C.getArgs().hasArg(options::OPT__SLASH_FA) && !C.getArgs().hasArg(options::OPT__SLASH_Fa) && isa<AssembleJobAction>(JA) && Inputs->size() == 1 && isa<BackendJobAction>(*Inputs->begin())) { // A BackendJob is always preceded by a CompileJob, and without // -save-temps they will always get combined together, so instead of // checking the backend tool, check if the tool for the CompileJob // has an integrated assembler. const ActionList *BackendInputs = &(*Inputs)[0]->getInputs(); JobAction *CompileJA = cast<CompileJobAction>(*BackendInputs->begin()); const Tool *Compiler = TC->SelectTool(*CompileJA); if (!Compiler) return nullptr; if (Compiler->hasIntegratedAssembler()) { Inputs = &(*BackendInputs)[0]->getInputs(); ToolForJob = Compiler; } } // A backend job should always be combined with the preceding compile job // unless OPT_save_temps is enabled and the compiler is capable of emitting // LLVM IR as an intermediate output. if (isa<BackendJobAction>(JA)) { // Check if the compiler supports emitting LLVM IR. assert(Inputs->size() == 1); JobAction *CompileJA; // Extract real host action, if it's a CudaHostAction. if (CudaHostAction *CudaHA = dyn_cast<CudaHostAction>(*Inputs->begin())) CompileJA = cast<CompileJobAction>(*CudaHA->begin()); else CompileJA = cast<CompileJobAction>(*Inputs->begin()); const Tool *Compiler = TC->SelectTool(*CompileJA); if (!Compiler) return nullptr; if (!Compiler->canEmitIR() || !SaveTemps) { Inputs = &(*Inputs)[0]->getInputs(); ToolForJob = Compiler; } } // Otherwise use the tool for the current job. if (!ToolForJob) ToolForJob = TC->SelectTool(*JA); // See if we should use an integrated preprocessor. We do so when we have // exactly one input, since this is the only use case we care about // (irrelevant since we don't support combine yet). if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin()) && !C.getArgs().hasArg(options::OPT_no_integrated_cpp) && !C.getArgs().hasArg(options::OPT_traditional_cpp) && !SaveTemps && !C.getArgs().hasArg(options::OPT_rewrite_objc) && ToolForJob->hasIntegratedCPP()) Inputs = &(*Inputs)[0]->getInputs(); return ToolForJob; } void Driver::BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC, const char *BoundArch, bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput, InputInfo &Result) const { llvm::PrettyStackTraceString CrashInfo("Building compilation jobs"); InputInfoList CudaDeviceInputInfos; if (const CudaHostAction *CHA = dyn_cast<CudaHostAction>(A)) { InputInfo II; // Append outputs of device jobs to the input list. for (const Action *DA : CHA->getDeviceActions()) { BuildJobsForAction(C, DA, TC, "", AtTopLevel, /*MultipleArchs*/ false, LinkingOutput, II); CudaDeviceInputInfos.push_back(II); } // Override current action with a real host compile action and continue // processing it. A = *CHA->begin(); } if (const InputAction *IA = dyn_cast<InputAction>(A)) { // FIXME: It would be nice to not claim this here; maybe the old scheme of // just using Args was better? const Arg &Input = IA->getInputArg(); Input.claim(); if (Input.getOption().matches(options::OPT_INPUT)) { const char *Name = Input.getValue(); Result = InputInfo(Name, A->getType(), Name); } else { Result = InputInfo(&Input, A->getType(), ""); } return; } if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) { const ToolChain *TC; const char *ArchName = BAA->getArchName(); if (ArchName) TC = &getToolChain( C.getArgs(), computeTargetTriple(DefaultTargetTriple, C.getArgs(), ArchName)); else TC = &C.getDefaultToolChain(); BuildJobsForAction(C, *BAA->begin(), TC, ArchName, AtTopLevel, MultipleArchs, LinkingOutput, Result); return; } if (const CudaDeviceAction *CDA = dyn_cast<CudaDeviceAction>(A)) { // Figure out which NVPTX triple to use for device-side compilation based on // whether host is 64-bit. llvm::Triple DeviceTriple(C.getDefaultToolChain().getTriple().isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda"); BuildJobsForAction(C, *CDA->begin(), &getToolChain(C.getArgs(), DeviceTriple), CDA->getGpuArchName(), CDA->isAtTopLevel(), /*MultipleArchs*/ true, LinkingOutput, Result); return; } const ActionList *Inputs = &A->getInputs(); const JobAction *JA = cast<JobAction>(A); const Tool *T = SelectToolForJob(C, isSaveTempsEnabled(), TC, JA, Inputs); if (!T) return; // Only use pipes when there is exactly one input. InputInfoList InputInfos; for (const Action *Input : *Inputs) { // Treat dsymutil and verify sub-jobs as being at the top-level too, they // shouldn't get temporary output names. // FIXME: Clean this up. bool SubJobAtTopLevel = false; if (AtTopLevel && (isa<DsymutilJobAction>(A) || isa<VerifyJobAction>(A))) SubJobAtTopLevel = true; InputInfo II; BuildJobsForAction(C, Input, TC, BoundArch, SubJobAtTopLevel, MultipleArchs, LinkingOutput, II); InputInfos.push_back(II); } // Always use the first input as the base input. const char *BaseInput = InputInfos[0].getBaseInput(); // ... except dsymutil actions, which use their actual input as the base // input. if (JA->getType() == types::TY_dSYM) BaseInput = InputInfos[0].getFilename(); // Append outputs of cuda device jobs to the input list if (CudaDeviceInputInfos.size()) InputInfos.append(CudaDeviceInputInfos.begin(), CudaDeviceInputInfos.end()); // Determine the place to write output to, if any. if (JA->getType() == types::TY_Nothing) Result = InputInfo(A->getType(), BaseInput); else Result = InputInfo(GetNamedOutputPath(C, *JA, BaseInput, BoundArch, AtTopLevel, MultipleArchs), A->getType(), BaseInput); if (CCCPrintBindings && !CCGenDiagnostics) { llvm::errs() << "# \"" << T->getToolChain().getTripleString() << '"' << " - \"" << T->getName() << "\", inputs: ["; for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) { llvm::errs() << InputInfos[i].getAsString(); if (i + 1 != e) llvm::errs() << ", "; } llvm::errs() << "], output: " << Result.getAsString() << "\n"; } else { T->ConstructJob(C, *JA, Result, InputInfos, C.getArgsForToolChain(TC, BoundArch), LinkingOutput); } } const char *Driver::getDefaultImageName() const { llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple)); return Target.isOSWindows() ? "a.exe" : "a.out"; } /// \brief Create output filename based on ArgValue, which could either be a /// full filename, filename without extension, or a directory. If ArgValue /// does not provide a filename, then use BaseName, and use the extension /// suitable for FileType. static const char *MakeCLOutputFilename(const ArgList &Args, StringRef ArgValue, StringRef BaseName, types::ID FileType) { SmallString<128> Filename = ArgValue; if (ArgValue.empty()) { // If the argument is empty, output to BaseName in the current dir. Filename = BaseName; } else if (llvm::sys::path::is_separator(Filename.back())) { // If the argument is a directory, output to BaseName in that dir. llvm::sys::path::append(Filename, BaseName); } if (!llvm::sys::path::has_extension(ArgValue)) { // If the argument didn't provide an extension, then set it. const char *Extension = types::getTypeTempSuffix(FileType, true); if (FileType == types::TY_Image && Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd)) { // The output file is a dll. Extension = "dll"; } llvm::sys::path::replace_extension(Filename, Extension); } return Args.MakeArgString(Filename.c_str()); } const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, const char *BaseInput, const char *BoundArch, bool AtTopLevel, bool MultipleArchs) const { llvm::PrettyStackTraceString CrashInfo("Computing output path"); // Output to a user requested destination? if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) { if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o)) return C.addResultFile(FinalOutput->getValue(), &JA); } // For /P, preprocess to file named after BaseInput. if (C.getArgs().hasArg(options::OPT__SLASH_P)) { assert(AtTopLevel && isa<PreprocessJobAction>(JA)); StringRef BaseName = llvm::sys::path::filename(BaseInput); StringRef NameArg; if (Arg *A = C.getArgs().getLastArg(options::OPT__SLASH_Fi)) NameArg = A->getValue(); return C.addResultFile( MakeCLOutputFilename(C.getArgs(), NameArg, BaseName, types::TY_PP_C), &JA); } // Default to writing to stdout? if (AtTopLevel && !CCGenDiagnostics && (isa<PreprocessJobAction>(JA) || JA.getType() == types::TY_ModuleFile)) return "-"; // Is this the assembly listing for /FA? if (JA.getType() == types::TY_PP_Asm && (C.getArgs().hasArg(options::OPT__SLASH_FA) || C.getArgs().hasArg(options::OPT__SLASH_Fa))) { // Use /Fa and the input filename to determine the asm file name. StringRef BaseName = llvm::sys::path::filename(BaseInput); StringRef FaValue = C.getArgs().getLastArgValue(options::OPT__SLASH_Fa); return C.addResultFile( MakeCLOutputFilename(C.getArgs(), FaValue, BaseName, JA.getType()), &JA); } // Output to a temporary file? if ((!AtTopLevel && !isSaveTempsEnabled() && !C.getArgs().hasArg(options::OPT__SLASH_Fo)) || CCGenDiagnostics) { StringRef Name = llvm::sys::path::filename(BaseInput); std::pair<StringRef, StringRef> Split = Name.split('.'); std::string TmpName = GetTemporaryPath( Split.first, types::getTypeTempSuffix(JA.getType(), IsCLMode())); return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str())); } SmallString<128> BasePath(BaseInput); StringRef BaseName; // Dsymutil actions should use the full path. if (isa<DsymutilJobAction>(JA) || isa<VerifyJobAction>(JA)) BaseName = BasePath; else BaseName = llvm::sys::path::filename(BasePath); // Determine what the derived output name should be. const char *NamedOutput; if (JA.getType() == types::TY_Object && C.getArgs().hasArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)) { // The /Fo or /o flag decides the object filename. StringRef Val = C.getArgs() .getLastArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o) ->getValue(); NamedOutput = MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Object); } else if (JA.getType() == types::TY_Image && C.getArgs().hasArg(options::OPT__SLASH_Fe, options::OPT__SLASH_o)) { // The /Fe or /o flag names the linked file. StringRef Val = C.getArgs() .getLastArg(options::OPT__SLASH_Fe, options::OPT__SLASH_o) ->getValue(); NamedOutput = MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Image); } else if (JA.getType() == types::TY_Image) { if (IsCLMode()) { // clang-cl uses BaseName for the executable name. NamedOutput = MakeCLOutputFilename(C.getArgs(), "", BaseName, types::TY_Image); } else if (MultipleArchs && BoundArch) { SmallString<128> Output(getDefaultImageName()); Output += "-"; Output.append(BoundArch); NamedOutput = C.getArgs().MakeArgString(Output.c_str()); } else NamedOutput = getDefaultImageName(); } else { const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode()); assert(Suffix && "All types used for output should have a suffix."); std::string::size_type End = std::string::npos; if (!types::appendSuffixForType(JA.getType())) End = BaseName.rfind('.'); SmallString<128> Suffixed(BaseName.substr(0, End)); if (MultipleArchs && BoundArch) { Suffixed += "-"; Suffixed.append(BoundArch); } // When using both -save-temps and -emit-llvm, use a ".tmp.bc" suffix for // the unoptimized bitcode so that it does not get overwritten by the ".bc" // optimized bitcode output. if (!AtTopLevel && C.getArgs().hasArg(options::OPT_emit_llvm) && JA.getType() == types::TY_LLVM_BC) Suffixed += ".tmp"; Suffixed += '.'; Suffixed += Suffix; NamedOutput = C.getArgs().MakeArgString(Suffixed.c_str()); } // Prepend object file path if -save-temps=obj if (!AtTopLevel && isSaveTempsObj() && C.getArgs().hasArg(options::OPT_o) && JA.getType() != types::TY_PCH) { Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o); SmallString<128> TempPath(FinalOutput->getValue()); llvm::sys::path::remove_filename(TempPath); StringRef OutputFileName = llvm::sys::path::filename(NamedOutput); llvm::sys::path::append(TempPath, OutputFileName); NamedOutput = C.getArgs().MakeArgString(TempPath.c_str()); } // If we're saving temps and the temp file conflicts with the input file, // then avoid overwriting input file. if (!AtTopLevel && isSaveTempsEnabled() && NamedOutput == BaseName) { bool SameFile = false; SmallString<256> Result; llvm::sys::fs::current_path(Result); llvm::sys::path::append(Result, BaseName); llvm::sys::fs::equivalent(BaseInput, Result.c_str(), SameFile); // Must share the same path to conflict. if (SameFile) { StringRef Name = llvm::sys::path::filename(BaseInput); std::pair<StringRef, StringRef> Split = Name.split('.'); std::string TmpName = GetTemporaryPath( Split.first, types::getTypeTempSuffix(JA.getType(), IsCLMode())); return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str())); } } // As an annoying special case, PCH generation doesn't strip the pathname. if (JA.getType() == types::TY_PCH) { llvm::sys::path::remove_filename(BasePath); if (BasePath.empty()) BasePath = NamedOutput; else llvm::sys::path::append(BasePath, NamedOutput); return C.addResultFile(C.getArgs().MakeArgString(BasePath.c_str()), &JA); } else { return C.addResultFile(NamedOutput, &JA); } } std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { // Respect a limited subset of the '-Bprefix' functionality in GCC by // attempting to use this prefix when looking for file paths. for (const std::string &Dir : PrefixDirs) { if (Dir.empty()) continue; SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); llvm::sys::path::append(P, Name); if (llvm::sys::fs::exists(Twine(P))) return P.str(); } SmallString<128> P(ResourceDir); llvm::sys::path::append(P, Name); if (llvm::sys::fs::exists(Twine(P))) return P.str(); for (const std::string &Dir : TC.getFilePaths()) { if (Dir.empty()) continue; SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); llvm::sys::path::append(P, Name); if (llvm::sys::fs::exists(Twine(P))) return P.str(); } return Name; } void Driver::generatePrefixedToolNames( const char *Tool, const ToolChain &TC, SmallVectorImpl<std::string> &Names) const { // FIXME: Needs a better variable than DefaultTargetTriple Names.emplace_back(DefaultTargetTriple + "-" + Tool); Names.emplace_back(Tool); } static bool ScanDirForExecutable(SmallString<128> &Dir, ArrayRef<std::string> Names) { for (const auto &Name : Names) { llvm::sys::path::append(Dir, Name); if (llvm::sys::fs::can_execute(Twine(Dir))) return true; llvm::sys::path::remove_filename(Dir); } return false; } std::string Driver::GetProgramPath(const char *Name, const ToolChain &TC) const { SmallVector<std::string, 2> TargetSpecificExecutables; generatePrefixedToolNames(Name, TC, TargetSpecificExecutables); // Respect a limited subset of the '-Bprefix' functionality in GCC by // attempting to use this prefix when looking for program paths. for (const auto &PrefixDir : PrefixDirs) { if (llvm::sys::fs::is_directory(PrefixDir)) { SmallString<128> P(PrefixDir); if (ScanDirForExecutable(P, TargetSpecificExecutables)) return P.str(); } else { SmallString<128> P(PrefixDir + Name); if (llvm::sys::fs::can_execute(Twine(P))) return P.str(); } } const ToolChain::path_list &List = TC.getProgramPaths(); for (const auto &Path : List) { SmallString<128> P(Path); if (ScanDirForExecutable(P, TargetSpecificExecutables)) return P.str(); } // If all else failed, search the path. for (const auto &TargetSpecificExecutable : TargetSpecificExecutables) if (llvm::ErrorOr<std::string> P = llvm::sys::findProgramByName(TargetSpecificExecutable)) return *P; return Name; } std::string Driver::GetTemporaryPath(StringRef Prefix, const char *Suffix) const { SmallString<128> Path; std::error_code EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, Path); if (EC) { Diag(clang::diag::err_unable_to_make_temp) << EC.message(); return ""; } return Path.str(); } const ToolChain &Driver::getToolChain(const ArgList &Args, const llvm::Triple &Target) const { ToolChain *&TC = ToolChains[Target.str()]; #if 0 // HLSL Change - remove toolchains if (!TC) { switch (Target.getOS()) { case llvm::Triple::CloudABI: TC = new toolchains::CloudABI(*this, Target, Args); break; case llvm::Triple::Darwin: case llvm::Triple::MacOSX: case llvm::Triple::IOS: TC = new toolchains::DarwinClang(*this, Target, Args); break; case llvm::Triple::DragonFly: TC = new toolchains::DragonFly(*this, Target, Args); break; case llvm::Triple::OpenBSD: TC = new toolchains::OpenBSD(*this, Target, Args); break; case llvm::Triple::Bitrig: TC = new toolchains::Bitrig(*this, Target, Args); break; case llvm::Triple::NetBSD: TC = new toolchains::NetBSD(*this, Target, Args); break; case llvm::Triple::FreeBSD: TC = new toolchains::FreeBSD(*this, Target, Args); break; case llvm::Triple::Minix: TC = new toolchains::Minix(*this, Target, Args); break; case llvm::Triple::Linux: if (Target.getArch() == llvm::Triple::hexagon) TC = new toolchains::Hexagon_TC(*this, Target, Args); else TC = new toolchains::Linux(*this, Target, Args); break; case llvm::Triple::NaCl: TC = new toolchains::NaCl_TC(*this, Target, Args); break; case llvm::Triple::Solaris: TC = new toolchains::Solaris(*this, Target, Args); break; case llvm::Triple::Win32: switch (Target.getEnvironment()) { default: if (Target.isOSBinFormatELF()) TC = new toolchains::Generic_ELF(*this, Target, Args); else if (Target.isOSBinFormatMachO()) TC = new toolchains::MachO(*this, Target, Args); else TC = new toolchains::Generic_GCC(*this, Target, Args); break; case llvm::Triple::GNU: TC = new toolchains::MinGW(*this, Target, Args); break; case llvm::Triple::Itanium: TC = new toolchains::CrossWindowsToolChain(*this, Target, Args); break; case llvm::Triple::MSVC: case llvm::Triple::UnknownEnvironment: TC = new toolchains::MSVCToolChain(*this, Target, Args); break; } break; case llvm::Triple::CUDA: TC = new toolchains::CudaToolChain(*this, Target, Args); break; default: // Of these targets, Hexagon is the only one that might have // an OS of Linux, in which case it got handled above already. if (Target.getArchName() == "tce") TC = new toolchains::TCEToolChain(*this, Target, Args); else if (Target.getArch() == llvm::Triple::hexagon) TC = new toolchains::Hexagon_TC(*this, Target, Args); else if (Target.getArch() == llvm::Triple::xcore) TC = new toolchains::XCore(*this, Target, Args); else if (Target.getArch() == llvm::Triple::shave) TC = new toolchains::SHAVEToolChain(*this, Target, Args); else if (Target.isOSBinFormatELF()) TC = new toolchains::Generic_ELF(*this, Target, Args); else if (Target.isOSBinFormatMachO()) TC = new toolchains::MachO(*this, Target, Args); else TC = new toolchains::Generic_GCC(*this, Target, Args); break; } } #else // HLSL Change - remove toolchains // TODO: revisit for HLSL proper TC = new toolchains::Generic_GCC(*this, Target, Args); #endif return *TC; } bool Driver::ShouldUseClangCompiler(const JobAction &JA) const { // Say "no" if there is not exactly one input of a type clang understands. if (JA.size() != 1 || !types::isAcceptedByClang((*JA.begin())->getType())) return false; // And say "no" if this is not a kind of action clang understands. if (!isa<PreprocessJobAction>(JA) && !isa<PrecompileJobAction>(JA) && !isa<CompileJobAction>(JA) && !isa<BackendJobAction>(JA)) return false; return true; } /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and return the /// grouped values as integers. Numbers which are not provided are set to 0. /// /// \return True if the entire string was parsed (9.2), or all groups were /// parsed (10.3.5extrastuff). bool Driver::GetReleaseVersion(const char *Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra) { HadExtra = false; Major = Minor = Micro = 0; if (*Str == '\0') return false; char *End; Major = (unsigned)strtol(Str, &End, 10); if (*Str != '\0' && *End == '\0') return true; if (*End != '.') return false; Str = End + 1; Minor = (unsigned)strtol(Str, &End, 10); if (*Str != '\0' && *End == '\0') return true; if (*End != '.') return false; Str = End + 1; Micro = (unsigned)strtol(Str, &End, 10); if (*Str != '\0' && *End == '\0') return true; if (Str == End) return false; HadExtra = true; return true; } std::pair<unsigned, unsigned> Driver::getIncludeExcludeOptionFlagMasks() const { unsigned IncludedFlagsBitmask = 0; unsigned ExcludedFlagsBitmask = options::NoDriverOption; if (Mode == CLMode) { // Include CL and Core options. IncludedFlagsBitmask |= options::CLOption; IncludedFlagsBitmask |= options::CoreOption; } else { ExcludedFlagsBitmask |= options::CLOption; } return std::make_pair(IncludedFlagsBitmask, ExcludedFlagsBitmask); } bool clang::driver::isOptimizationLevelFast(const ArgList &Args) { return Args.hasFlag(options::OPT_Ofast, options::OPT_O_Group, false); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/MSVCToolChain.cpp
//===--- ToolChains.cpp - ToolChain Implementations -----------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "ToolChains.h" #include "Tools.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/Version.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/llvm-config.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Process.h" #include <cstdio> // Include the necessary headers to interface with the Windows registry and // environment. #if defined(LLVM_ON_WIN32) #define USE_WIN32 #endif #ifdef USE_WIN32 #define WIN32_LEAN_AND_MEAN #define NOGDI #ifndef NOMINMAX #define NOMINMAX #endif #include <windows.h> #endif using namespace clang::driver; using namespace clang::driver::toolchains; using namespace clang; using namespace llvm::opt; MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) : ToolChain(D, Triple, Args) { getProgramPaths().push_back(getDriver().getInstalledDir()); if (getDriver().getInstalledDir() != getDriver().Dir) getProgramPaths().push_back(getDriver().Dir); } Tool *MSVCToolChain::buildLinker() const { return new tools::visualstudio::Linker(*this); } Tool *MSVCToolChain::buildAssembler() const { if (getTriple().isOSBinFormatMachO()) return new tools::darwin::Assembler(*this); getDriver().Diag(clang::diag::err_no_external_assembler); return nullptr; } bool MSVCToolChain::IsIntegratedAssemblerDefault() const { return true; } bool MSVCToolChain::IsUnwindTablesDefault() const { // Emit unwind tables by default on Win64. All non-x86_32 Windows platforms // such as ARM and PPC actually require unwind tables, but LLVM doesn't know // how to generate them yet. return getArch() == llvm::Triple::x86_64; } bool MSVCToolChain::isPICDefault() const { return getArch() == llvm::Triple::x86_64; } bool MSVCToolChain::isPIEDefault() const { return false; } bool MSVCToolChain::isPICDefaultForced() const { return getArch() == llvm::Triple::x86_64; } #ifdef USE_WIN32 static bool readFullStringValue(HKEY hkey, const char *valueName, std::string &value) { // FIXME: We should be using the W versions of the registry functions, but // doing so requires UTF8 / UTF16 conversions similar to how we handle command // line arguments. The UTF8 conversion functions are not exposed publicly // from LLVM though, so in order to do this we will probably need to create // a registry abstraction in LLVMSupport that is Windows only. DWORD result = 0; DWORD valueSize = 0; DWORD type = 0; // First just query for the required size. result = RegQueryValueEx(hkey, valueName, NULL, &type, NULL, &valueSize); if (result != ERROR_SUCCESS || type != REG_SZ) return false; std::vector<BYTE> buffer(valueSize); result = RegQueryValueEx(hkey, valueName, NULL, NULL, &buffer[0], &valueSize); if (result == ERROR_SUCCESS) value.assign(reinterpret_cast<const char *>(buffer.data())); return result; } #endif /// \brief Read registry string. /// This also supports a means to look for high-versioned keys by use /// of a $VERSION placeholder in the key path. /// $VERSION in the key path is a placeholder for the version number, /// causing the highest value path to be searched for and used. /// I.e. "SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". /// There can be additional characters in the component. Only the numeric /// characters are compared. This function only searches HKLM. static bool getSystemRegistryString(const char *keyPath, const char *valueName, std::string &value, std::string *phValue) { #ifndef USE_WIN32 return false; #else HKEY hRootKey = HKEY_LOCAL_MACHINE; HKEY hKey = NULL; long lResult; bool returnValue = false; const char *placeHolder = strstr(keyPath, "$VERSION"); std::string bestName; // If we have a $VERSION placeholder, do the highest-version search. if (placeHolder) { const char *keyEnd = placeHolder - 1; const char *nextKey = placeHolder; // Find end of previous key. while ((keyEnd > keyPath) && (*keyEnd != '\\')) keyEnd--; // Find end of key containing $VERSION. while (*nextKey && (*nextKey != '\\')) nextKey++; size_t partialKeyLength = keyEnd - keyPath; char partialKey[256]; if (partialKeyLength > sizeof(partialKey)) partialKeyLength = sizeof(partialKey); strncpy(partialKey, keyPath, partialKeyLength); partialKey[partialKeyLength] = '\0'; HKEY hTopKey = NULL; lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ | KEY_WOW64_32KEY, &hTopKey); if (lResult == ERROR_SUCCESS) { char keyName[256]; double bestValue = 0.0; DWORD index, size = sizeof(keyName) - 1; for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; index++) { const char *sp = keyName; while (*sp && !isDigit(*sp)) sp++; if (!*sp) continue; const char *ep = sp + 1; while (*ep && (isDigit(*ep) || (*ep == '.'))) ep++; char numBuf[32]; strncpy(numBuf, sp, sizeof(numBuf) - 1); numBuf[sizeof(numBuf) - 1] = '\0'; double dvalue = strtod(numBuf, NULL); if (dvalue > bestValue) { // Test that InstallDir is indeed there before keeping this index. // Open the chosen key path remainder. bestName = keyName; // Append rest of key. bestName.append(nextKey); lResult = RegOpenKeyEx(hTopKey, bestName.c_str(), 0, KEY_READ | KEY_WOW64_32KEY, &hKey); if (lResult == ERROR_SUCCESS) { lResult = readFullStringValue(hKey, valueName, value); if (lResult == ERROR_SUCCESS) { bestValue = dvalue; if (phValue) *phValue = bestName; returnValue = true; } RegCloseKey(hKey); } } size = sizeof(keyName) - 1; } RegCloseKey(hTopKey); } } else { lResult = RegOpenKeyEx(hRootKey, keyPath, 0, KEY_READ | KEY_WOW64_32KEY, &hKey); if (lResult == ERROR_SUCCESS) { lResult = readFullStringValue(hKey, valueName, value); if (lResult == ERROR_SUCCESS) returnValue = true; if (phValue) phValue->clear(); RegCloseKey(hKey); } } return returnValue; #endif // USE_WIN32 } /// \brief Get Windows SDK installation directory. bool MSVCToolChain::getWindowsSDKDir(std::string &path, int &major, int &minor) const { std::string sdkVersion; // Try the Windows registry. bool hasSDKDir = getSystemRegistryString( "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", "InstallationFolder", path, &sdkVersion); if (!sdkVersion.empty()) std::sscanf(sdkVersion.c_str(), "v%d.%d", &major, &minor); return hasSDKDir && !path.empty(); } // Gets the library path required to link against the Windows SDK. bool MSVCToolChain::getWindowsSDKLibraryPath(std::string &path) const { std::string sdkPath; int sdkMajor = 0; int sdkMinor = 0; path.clear(); if (!getWindowsSDKDir(sdkPath, sdkMajor, sdkMinor)) return false; llvm::SmallString<128> libPath(sdkPath); llvm::sys::path::append(libPath, "Lib"); if (sdkMajor <= 7) { switch (getArch()) { // In Windows SDK 7.x, x86 libraries are directly in the Lib folder. case llvm::Triple::x86: break; case llvm::Triple::x86_64: llvm::sys::path::append(libPath, "x64"); break; case llvm::Triple::arm: // It is not necessary to link against Windows SDK 7.x when targeting ARM. return false; default: return false; } } else { // Windows SDK 8.x installs libraries in a folder whose names depend on the // version of the OS you're targeting. By default choose the newest, which // usually corresponds to the version of the OS you've installed the SDK on. const char *tests[] = {"winv6.3", "win8", "win7"}; bool found = false; for (const char *test : tests) { llvm::SmallString<128> testPath(libPath); llvm::sys::path::append(testPath, test); if (llvm::sys::fs::exists(testPath.c_str())) { libPath = testPath; found = true; break; } } if (!found) return false; llvm::sys::path::append(libPath, "um"); switch (getArch()) { case llvm::Triple::x86: llvm::sys::path::append(libPath, "x86"); break; case llvm::Triple::x86_64: llvm::sys::path::append(libPath, "x64"); break; case llvm::Triple::arm: llvm::sys::path::append(libPath, "arm"); break; default: return false; } } path = libPath.str(); return true; } // Get the location to use for Visual Studio binaries. The location priority // is: %VCINSTALLDIR% > %PATH% > newest copy of Visual Studio installed on // system (as reported by the registry). bool MSVCToolChain::getVisualStudioBinariesFolder(const char *clangProgramPath, std::string &path) const { path.clear(); SmallString<128> BinDir; // First check the environment variables that vsvars32.bat sets. llvm::Optional<std::string> VcInstallDir = llvm::sys::Process::GetEnv("VCINSTALLDIR"); if (VcInstallDir.hasValue()) { BinDir = VcInstallDir.getValue(); llvm::sys::path::append(BinDir, "bin"); } else { // Next walk the PATH, trying to find a cl.exe in the path. If we find one, // use that. However, make sure it's not clang's cl.exe. llvm::Optional<std::string> OptPath = llvm::sys::Process::GetEnv("PATH"); if (OptPath.hasValue()) { const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; SmallVector<StringRef, 8> PathSegments; llvm::SplitString(OptPath.getValue(), PathSegments, EnvPathSeparatorStr); for (StringRef PathSegment : PathSegments) { if (PathSegment.empty()) continue; SmallString<128> FilePath(PathSegment); llvm::sys::path::append(FilePath, "cl.exe"); if (llvm::sys::fs::can_execute(FilePath.c_str()) && !llvm::sys::fs::equivalent(FilePath.c_str(), clangProgramPath)) { // If we found it on the PATH, use it exactly as is with no // modifications. path = PathSegment; return true; } } } std::string installDir; // With no VCINSTALLDIR and nothing on the PATH, if we can't find it in the // registry then we have no choice but to fail. if (!getVisualStudioInstallDir(installDir)) return false; // Regardless of what binary we're ultimately trying to find, we make sure // that this is a Visual Studio directory by checking for cl.exe. We use // cl.exe instead of other binaries like link.exe because programs such as // GnuWin32 also have a utility called link.exe, so cl.exe is the least // ambiguous. BinDir = installDir; llvm::sys::path::append(BinDir, "VC", "bin"); SmallString<128> ClPath(BinDir); llvm::sys::path::append(ClPath, "cl.exe"); if (!llvm::sys::fs::can_execute(ClPath.c_str())) return false; } if (BinDir.empty()) return false; switch (getArch()) { case llvm::Triple::x86: break; case llvm::Triple::x86_64: llvm::sys::path::append(BinDir, "amd64"); break; case llvm::Triple::arm: llvm::sys::path::append(BinDir, "arm"); break; default: // Whatever this is, Visual Studio doesn't have a toolchain for it. return false; } path = BinDir.str(); return true; } // Get Visual Studio installation directory. bool MSVCToolChain::getVisualStudioInstallDir(std::string &path) const { // First check the environment variables that vsvars32.bat sets. const char *vcinstalldir = getenv("VCINSTALLDIR"); if (vcinstalldir) { path = vcinstalldir; path = path.substr(0, path.find("\\VC")); return true; } std::string vsIDEInstallDir; std::string vsExpressIDEInstallDir; // Then try the windows registry. bool hasVCDir = getSystemRegistryString("SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", "InstallDir", vsIDEInstallDir, nullptr); if (hasVCDir && !vsIDEInstallDir.empty()) { path = vsIDEInstallDir.substr(0, vsIDEInstallDir.find("\\Common7\\IDE")); return true; } bool hasVCExpressDir = getSystemRegistryString("SOFTWARE\\Microsoft\\VCExpress\\$VERSION", "InstallDir", vsExpressIDEInstallDir, nullptr); if (hasVCExpressDir && !vsExpressIDEInstallDir.empty()) { path = vsExpressIDEInstallDir.substr( 0, vsIDEInstallDir.find("\\Common7\\IDE")); return true; } // Try the environment. const char *vs120comntools = getenv("VS120COMNTOOLS"); const char *vs100comntools = getenv("VS100COMNTOOLS"); const char *vs90comntools = getenv("VS90COMNTOOLS"); const char *vs80comntools = getenv("VS80COMNTOOLS"); const char *vscomntools = nullptr; // Find any version we can if (vs120comntools) vscomntools = vs120comntools; else if (vs100comntools) vscomntools = vs100comntools; else if (vs90comntools) vscomntools = vs90comntools; else if (vs80comntools) vscomntools = vs80comntools; if (vscomntools && *vscomntools) { const char *p = strstr(vscomntools, "\\Common7\\Tools"); path = p ? std::string(vscomntools, p) : vscomntools; return true; } return false; } void MSVCToolChain::AddSystemIncludeWithSubfolder(const ArgList &DriverArgs, ArgStringList &CC1Args, const std::string &folder, const char *subfolder) const { llvm::SmallString<128> path(folder); llvm::sys::path::append(path, subfolder); addSystemInclude(DriverArgs, CC1Args, path); } void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdinc)) return; if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { SmallString<128> P(getDriver().ResourceDir); llvm::sys::path::append(P, "include"); addSystemInclude(DriverArgs, CC1Args, P); } if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; // Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat. if (const char *cl_include_dir = getenv("INCLUDE")) { SmallVector<StringRef, 8> Dirs; StringRef(cl_include_dir) .split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false); for (StringRef Dir : Dirs) addSystemInclude(DriverArgs, CC1Args, Dir); if (!Dirs.empty()) return; } std::string VSDir; // When built with access to the proper Windows APIs, try to actually find // the correct include paths first. if (getVisualStudioInstallDir(VSDir)) { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include"); std::string WindowsSDKDir; int major, minor; if (getWindowsSDKDir(WindowsSDKDir, major, minor)) { if (major >= 8) { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include\\shared"); AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include\\um"); AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include\\winrt"); } else { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include"); } } else { addSystemInclude(DriverArgs, CC1Args, VSDir); } return; } // As a fallback, select default install paths. // FIXME: Don't guess drives and paths like this on Windows. const StringRef Paths[] = { "C:/Program Files/Microsoft Visual Studio 10.0/VC/include", "C:/Program Files/Microsoft Visual Studio 9.0/VC/include", "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", "C:/Program Files/Microsoft Visual Studio 8/VC/include", "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" }; addSystemIncludes(DriverArgs, CC1Args, Paths); } void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { // FIXME: There should probably be logic here to find libc++ on Windows. } std::string MSVCToolChain::ComputeEffectiveClangTriple(const ArgList &Args, types::ID InputType) const { std::string TripleStr = ToolChain::ComputeEffectiveClangTriple(Args, InputType); llvm::Triple Triple(TripleStr); VersionTuple MSVT = tools::visualstudio::getMSVCVersion(/*D=*/nullptr, Triple, Args, /*IsWindowsMSVC=*/true); if (MSVT.empty()) return TripleStr; MSVT = VersionTuple(MSVT.getMajor(), MSVT.getMinor().getValueOr(0), MSVT.getSubminor().getValueOr(0)); if (Triple.getEnvironment() == llvm::Triple::MSVC) { StringRef ObjFmt = Triple.getEnvironmentName().split('-').second; if (ObjFmt.empty()) Triple.setEnvironmentName((Twine("msvc") + MSVT.getAsString()).str()); else Triple.setEnvironmentName( (Twine("msvc") + MSVT.getAsString() + Twine('-') + ObjFmt).str()); } return Triple.getTriple(); } SanitizerMask MSVCToolChain::getSupportedSanitizers() const { SanitizerMask Res = ToolChain::getSupportedSanitizers(); Res |= SanitizerKind::Address; return Res; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Action.cpp
//===--- Action.cpp - Abstract compilation steps --------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Action.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> using namespace clang::driver; using namespace llvm::opt; Action::~Action() { if (OwnsInputs) { for (iterator it = begin(), ie = end(); it != ie; ++it) delete *it; } } const char *Action::getClassName(ActionClass AC) { switch (AC) { case InputClass: return "input"; case BindArchClass: return "bind-arch"; case CudaDeviceClass: return "cuda-device"; case CudaHostClass: return "cuda-host"; case PreprocessJobClass: return "preprocessor"; case PrecompileJobClass: return "precompiler"; case AnalyzeJobClass: return "analyzer"; case MigrateJobClass: return "migrator"; case CompileJobClass: return "compiler"; case BackendJobClass: return "backend"; case AssembleJobClass: return "assembler"; case LinkJobClass: return "linker"; case LipoJobClass: return "lipo"; case DsymutilJobClass: return "dsymutil"; case VerifyDebugInfoJobClass: return "verify-debug-info"; case VerifyPCHJobClass: return "verify-pch"; } llvm_unreachable("invalid class"); } void InputAction::anchor() {} InputAction::InputAction(const Arg &_Input, types::ID _Type) : Action(InputClass, _Type), Input(_Input) { } void BindArchAction::anchor() {} BindArchAction::BindArchAction(std::unique_ptr<Action> Input, const char *_ArchName) : Action(BindArchClass, std::move(Input)), ArchName(_ArchName) {} void CudaDeviceAction::anchor() {} CudaDeviceAction::CudaDeviceAction(std::unique_ptr<Action> Input, const char *ArchName, bool AtTopLevel) : Action(CudaDeviceClass, std::move(Input)), GpuArchName(ArchName), AtTopLevel(AtTopLevel) {} void CudaHostAction::anchor() {} CudaHostAction::CudaHostAction(std::unique_ptr<Action> Input, const ActionList &_DeviceActions) : Action(CudaHostClass, std::move(Input)), DeviceActions(_DeviceActions) {} CudaHostAction::~CudaHostAction() { for (iterator it = DeviceActions.begin(), ie = DeviceActions.end(); it != ie; ++it) delete *it; } void JobAction::anchor() {} JobAction::JobAction(ActionClass Kind, std::unique_ptr<Action> Input, types::ID Type) : Action(Kind, std::move(Input), Type) {} JobAction::JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type) : Action(Kind, Inputs, Type) { } void PreprocessJobAction::anchor() {} PreprocessJobAction::PreprocessJobAction(std::unique_ptr<Action> Input, types::ID OutputType) : JobAction(PreprocessJobClass, std::move(Input), OutputType) {} void PrecompileJobAction::anchor() {} PrecompileJobAction::PrecompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType) : JobAction(PrecompileJobClass, std::move(Input), OutputType) {} void AnalyzeJobAction::anchor() {} AnalyzeJobAction::AnalyzeJobAction(std::unique_ptr<Action> Input, types::ID OutputType) : JobAction(AnalyzeJobClass, std::move(Input), OutputType) {} void MigrateJobAction::anchor() {} MigrateJobAction::MigrateJobAction(std::unique_ptr<Action> Input, types::ID OutputType) : JobAction(MigrateJobClass, std::move(Input), OutputType) {} void CompileJobAction::anchor() {} CompileJobAction::CompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType) : JobAction(CompileJobClass, std::move(Input), OutputType) {} void BackendJobAction::anchor() {} BackendJobAction::BackendJobAction(std::unique_ptr<Action> Input, types::ID OutputType) : JobAction(BackendJobClass, std::move(Input), OutputType) {} void AssembleJobAction::anchor() {} AssembleJobAction::AssembleJobAction(std::unique_ptr<Action> Input, types::ID OutputType) : JobAction(AssembleJobClass, std::move(Input), OutputType) {} void LinkJobAction::anchor() {} LinkJobAction::LinkJobAction(ActionList &Inputs, types::ID Type) : JobAction(LinkJobClass, Inputs, Type) { } void LipoJobAction::anchor() {} LipoJobAction::LipoJobAction(ActionList &Inputs, types::ID Type) : JobAction(LipoJobClass, Inputs, Type) { } void DsymutilJobAction::anchor() {} DsymutilJobAction::DsymutilJobAction(ActionList &Inputs, types::ID Type) : JobAction(DsymutilJobClass, Inputs, Type) { } void VerifyJobAction::anchor() {} VerifyJobAction::VerifyJobAction(ActionClass Kind, std::unique_ptr<Action> Input, types::ID Type) : JobAction(Kind, std::move(Input), Type) { assert((Kind == VerifyDebugInfoJobClass || Kind == VerifyPCHJobClass) && "ActionClass is not a valid VerifyJobAction"); } VerifyJobAction::VerifyJobAction(ActionClass Kind, ActionList &Inputs, types::ID Type) : JobAction(Kind, Inputs, Type) { assert((Kind == VerifyDebugInfoJobClass || Kind == VerifyPCHJobClass) && "ActionClass is not a valid VerifyJobAction"); } void VerifyDebugInfoJobAction::anchor() {} VerifyDebugInfoJobAction::VerifyDebugInfoJobAction( std::unique_ptr<Action> Input, types::ID Type) : VerifyJobAction(VerifyDebugInfoJobClass, std::move(Input), Type) {} void VerifyPCHJobAction::anchor() {} VerifyPCHJobAction::VerifyPCHJobAction(std::unique_ptr<Action> Input, types::ID Type) : VerifyJobAction(VerifyPCHJobClass, std::move(Input), Type) {}
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/ToolChains.h
//===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H #include "Tools.h" #include "clang/Basic/VersionTuple.h" #include "clang/Driver/Action.h" #include "clang/Driver/Multilib.h" #include "clang/Driver/ToolChain.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" #include "llvm/Support/Compiler.h" #include <set> #include <vector> namespace clang { namespace driver { namespace toolchains { /// Generic_GCC - A tool chain using the 'gcc' command to perform /// all subcommands; this relies on gcc translating the majority of /// command line options. class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain { public: /// \brief Struct to store and manipulate GCC versions. /// /// We rely on assumptions about the form and structure of GCC version /// numbers: they consist of at most three '.'-separated components, and each /// component is a non-negative integer except for the last component. For /// the last component we are very flexible in order to tolerate release /// candidates or 'x' wildcards. /// /// Note that the ordering established among GCCVersions is based on the /// preferred version string to use. For example we prefer versions without /// a hard-coded patch number to those with a hard coded patch number. /// /// Currently this doesn't provide any logic for textual suffixes to patches /// in the way that (for example) Debian's version format does. If that ever /// becomes necessary, it can be added. struct GCCVersion { /// \brief The unparsed text of the version. std::string Text; /// \brief The parsed major, minor, and patch numbers. int Major, Minor, Patch; /// \brief The text of the parsed major, and major+minor versions. std::string MajorStr, MinorStr; /// \brief Any textual suffix on the patch number. std::string PatchSuffix; static GCCVersion Parse(StringRef VersionText); bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch, StringRef RHSPatchSuffix = StringRef()) const; bool operator<(const GCCVersion &RHS) const { return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix); } bool operator>(const GCCVersion &RHS) const { return RHS < *this; } bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); } bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); } }; /// \brief This is a class to find a viable GCC installation for Clang to /// use. /// /// This class tries to find a GCC installation on the system, and report /// information about it. It starts from the host information provided to the /// Driver, and has logic for fuzzing that where appropriate. class GCCInstallationDetector { bool IsValid; llvm::Triple GCCTriple; // FIXME: These might be better as path objects. std::string GCCInstallPath; std::string GCCParentLibPath; /// The primary multilib appropriate for the given flags. Multilib SelectedMultilib; /// On Biarch systems, this corresponds to the default multilib when /// targeting the non-default multilib. Otherwise, it is empty. llvm::Optional<Multilib> BiarchSibling; GCCVersion Version; // We retain the list of install paths that were considered and rejected in // order to print out detailed information in verbose mode. std::set<std::string> CandidateGCCInstallPaths; /// The set of multilibs that the detected installation supports. MultilibSet Multilibs; public: GCCInstallationDetector() : IsValid(false) {} void init(const Driver &D, const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args); /// \brief Check whether we detected a valid GCC install. bool isValid() const { return IsValid; } /// \brief Get the GCC triple for the detected install. const llvm::Triple &getTriple() const { return GCCTriple; } /// \brief Get the detected GCC installation path. StringRef getInstallPath() const { return GCCInstallPath; } /// \brief Get the detected GCC parent lib path. StringRef getParentLibPath() const { return GCCParentLibPath; } /// \brief Get the detected Multilib const Multilib &getMultilib() const { return SelectedMultilib; } /// \brief Get the whole MultilibSet const MultilibSet &getMultilibs() const { return Multilibs; } /// Get the biarch sibling multilib (if it exists). /// \return true iff such a sibling exists bool getBiarchSibling(Multilib &M) const; /// \brief Get the detected GCC version string. const GCCVersion &getVersion() const { return Version; } /// \brief Print information about the detected GCC installation. void print(raw_ostream &OS) const; private: static void CollectLibDirsAndTriples(const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, SmallVectorImpl<StringRef> &LibDirs, SmallVectorImpl<StringRef> &TripleAliases, SmallVectorImpl<StringRef> &BiarchLibDirs, SmallVectorImpl<StringRef> &BiarchTripleAliases); void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, const std::string &LibDir, StringRef CandidateTriple, bool NeedsBiarchSuffix = false); }; protected: GCCInstallationDetector GCCInstallation; public: Generic_GCC(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); ~Generic_GCC() override; void printVerboseInfo(raw_ostream &OS) const override; bool IsUnwindTablesDefault() const override; bool isPICDefault() const override; bool isPIEDefault() const override; bool isPICDefaultForced() const override; bool IsIntegratedAssemblerDefault() const override; protected: Tool *getTool(Action::ActionClass AC) const override; Tool *buildAssembler() const override; Tool *buildLinker() const override; /// \name ToolChain Implementation Helper Functions /// @{ /// \brief Check whether the target triple's architecture is 64-bits. bool isTarget64Bit() const { return getTriple().isArch64Bit(); } /// \brief Check whether the target triple's architecture is 32-bits. bool isTarget32Bit() const { return getTriple().isArch32Bit(); } /// @} private: mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocess; mutable std::unique_ptr<tools::gcc::Compiler> Compile; }; class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain { protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; Tool *getTool(Action::ActionClass AC) const override; private: mutable std::unique_ptr<tools::darwin::Lipo> Lipo; mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil; mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug; public: MachO(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); ~MachO() override; /// @name MachO specific toolchain API /// { /// Get the "MachO" arch name for a particular compiler invocation. For /// example, Apple treats different ARM variations as distinct architectures. StringRef getMachOArchName(const llvm::opt::ArgList &Args) const; /// Add the linker arguments to link the ARC runtime library. virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const {} /// Add the linker arguments to link the compiler runtime library. virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; virtual void addStartObjectFileArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { } virtual void addMinVersionArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const {} /// On some iOS platforms, kernel and kernel modules were built statically. Is /// this such a target? virtual bool isKernelStatic() const { return false; } /// Is the target either iOS or an iOS simulator? bool isTargetIOSBased() const { return false; } void AddLinkRuntimeLib(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, StringRef DarwinLibName, bool AlwaysLink = false, bool IsEmbedded = false, bool AddRPath = false) const; /// Add any profiling runtime libraries that are needed. This is essentially a /// MachO specific version of addProfileRT in Tools.cpp. virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { // There aren't any profiling libs for embedded targets currently. } /// } /// @name ToolChain Implementation /// { std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType) const override; types::ID LookupTypeForExtension(const char *Ext) const override; bool HasNativeLLVMSupport() const override; llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, const char *BoundArch) const override; bool IsBlocksDefault() const override { // Always allow blocks on Apple; users interested in versioning are // expected to use /usr/include/Block.h. return true; } bool IsIntegratedAssemblerDefault() const override { // Default integrated assembler to on for Apple's MachO targets. return true; } bool IsMathErrnoDefault() const override { return false; } bool IsEncodeExtendedBlockSignatureDefault() const override { return true; } bool IsObjCNonFragileABIDefault() const override { // Non-fragile ABI is default for everything but i386. return getTriple().getArch() != llvm::Triple::x86; } bool UseObjCMixedDispatch() const override { return true; } bool IsUnwindTablesDefault() const override; RuntimeLibType GetDefaultRuntimeLibType() const override { return ToolChain::RLT_CompilerRT; } bool isPICDefault() const override; bool isPIEDefault() const override; bool isPICDefaultForced() const override; bool SupportsProfiling() const override; bool SupportsObjCGC() const override { return false; } bool UseDwarfDebugFlags() const override; bool UseSjLjExceptions() const override { return false; } /// } }; /// Darwin - The base Darwin tool chain. class LLVM_LIBRARY_VISIBILITY Darwin : public MachO { public: /// Whether the information on the target has been initialized. // // FIXME: This should be eliminated. What we want to do is make this part of // the "default target for arguments" selection process, once we get out of // the argument translation business. mutable bool TargetInitialized; enum DarwinPlatformKind { MacOS, IPhoneOS, IPhoneOSSimulator }; mutable DarwinPlatformKind TargetPlatform; /// The OS version we are targeting. mutable VersionTuple TargetVersion; private: void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const; public: Darwin(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); ~Darwin() override; std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType) const override; /// @name Apple Specific Toolchain Implementation /// { void addMinVersionArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; void addStartObjectFileArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; bool isKernelStatic() const override { return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0); } void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; protected: /// } /// @name Darwin specific Toolchain functions /// { // FIXME: Eliminate these ...Target functions and derive separate tool chains // for these targets and put version in constructor. void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor, unsigned Micro) const { // FIXME: For now, allow reinitialization as long as values don't // change. This will go away when we move away from argument translation. if (TargetInitialized && TargetPlatform == Platform && TargetVersion == VersionTuple(Major, Minor, Micro)) return; assert(!TargetInitialized && "Target already initialized!"); TargetInitialized = true; TargetPlatform = Platform; TargetVersion = VersionTuple(Major, Minor, Micro); } bool isTargetIPhoneOS() const { assert(TargetInitialized && "Target not initialized!"); return TargetPlatform == IPhoneOS; } bool isTargetIOSSimulator() const { assert(TargetInitialized && "Target not initialized!"); return TargetPlatform == IPhoneOSSimulator; } bool isTargetIOSBased() const { assert(TargetInitialized && "Target not initialized!"); return isTargetIPhoneOS() || isTargetIOSSimulator(); } bool isTargetMacOS() const { assert(TargetInitialized && "Target not initialized!"); return TargetPlatform == MacOS; } bool isTargetInitialized() const { return TargetInitialized; } VersionTuple getTargetVersion() const { assert(TargetInitialized && "Target not initialized!"); return TargetVersion; } bool isIPhoneOSVersionLT(unsigned V0, unsigned V1 = 0, unsigned V2 = 0) const { assert(isTargetIOSBased() && "Unexpected call for non iOS target!"); return TargetVersion < VersionTuple(V0, V1, V2); } bool isMacosxVersionLT(unsigned V0, unsigned V1 = 0, unsigned V2 = 0) const { assert(isTargetMacOS() && "Unexpected call for non OS X target!"); return TargetVersion < VersionTuple(V0, V1, V2); } public: /// } /// @name ToolChain Implementation /// { // Darwin tools support multiple architecture (e.g., i386 and x86_64) and // most development is done against SDKs, so compiling for a different // architecture should not get any special treatment. bool isCrossCompiling() const override { return false; } llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, const char *BoundArch) const override; ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override; bool hasBlocksRuntime() const override; bool UseObjCMixedDispatch() const override { // This is only used with the non-fragile ABI and non-legacy dispatch. // Mixed dispatch is used everywhere except OS X before 10.6. return !(isTargetMacOS() && isMacosxVersionLT(10, 6)); } unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override { // Stack protectors default to on for user code on 10.5, // and for everything in 10.6 and beyond if (isTargetIOSBased()) return 1; else if (isTargetMacOS() && !isMacosxVersionLT(10, 6)) return 1; else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext) return 1; return 0; } bool SupportsObjCGC() const override; void CheckObjCARC() const override; bool UseSjLjExceptions() const override; SanitizerMask getSupportedSanitizers() const override; }; /// DarwinClang - The Darwin toolchain used by Clang. class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin { public: DarwinClang(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); /// @name Apple ToolChain Implementation /// { void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; void AddCCKextLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override; void AddLinkARCArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; /// } private: void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, StringRef Sanitizer) const; }; class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC { virtual void anchor(); public: Generic_ELF(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args) : Generic_GCC(D, Triple, Args) {} void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; }; class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF { public: CloudABI(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool HasNativeLLVMSupport() const override { return true; } bool IsMathErrnoDefault() const override { return false; } bool IsObjCNonFragileABIDefault() const override { return true; } CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override { return ToolChain::CST_Libcxx; } void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; bool isPIEDefault() const override { return false; } protected: Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC { public: Solaris(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool IsIntegratedAssemblerDefault() const override { return true; } protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain { public: MinGW(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool IsIntegratedAssemblerDefault() const override; bool IsUnwindTablesDefault() const override; bool isPICDefault() const override; bool isPIEDefault() const override; bool isPICDefaultForced() const override; bool UseSEHExceptions() const; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; protected: Tool *getTool(Action::ActionClass AC) const override; Tool *buildLinker() const override; Tool *buildAssembler() const override; private: std::string Base; std::string GccLibDir; std::string Ver; std::string Arch; mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor; mutable std::unique_ptr<tools::gcc::Compiler> Compiler; void findGccLibDir(); }; class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF { public: OpenBSD(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool IsMathErrnoDefault() const override { return false; } bool IsObjCNonFragileABIDefault() const override { return true; } bool isPIEDefault() const override { return true; } unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override { return 2; } protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF { public: Bitrig(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool IsMathErrnoDefault() const override { return false; } bool IsObjCNonFragileABIDefault() const override { return true; } CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override { return 1; } protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF { public: FreeBSD(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool HasNativeLLVMSupport() const override; bool IsMathErrnoDefault() const override { return false; } bool IsObjCNonFragileABIDefault() const override { return true; } CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; bool UseSjLjExceptions() const override; bool isPIEDefault() const override; SanitizerMask getSupportedSanitizers() const override; protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF { public: NetBSD(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool IsMathErrnoDefault() const override { return false; } bool IsObjCNonFragileABIDefault() const override { return true; } CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; bool IsUnwindTablesDefault() const override { return true; } protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF { public: Minix(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF { public: DragonFly(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool IsMathErrnoDefault() const override { return false; } protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; }; class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF { public: Linux(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool HasNativeLLVMSupport() const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; bool isPIEDefault() const override; SanitizerMask getSupportedSanitizers() const override; std::string Linker; std::vector<std::string> ExtraOpts; protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; private: static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, StringRef TargetMultiarchTriple, Twine IncludeSuffix, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args); std::string computeSysRoot() const; }; class LLVM_LIBRARY_VISIBILITY CudaToolChain : public Linux { public: CudaToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, const char *BoundArch) const override; void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; }; class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux { protected: GCCVersion GCCLibAndIncVersion; Tool *buildAssembler() const override; Tool *buildLinker() const override; public: Hexagon_TC(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); ~Hexagon_TC() override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; } static std::string GetGnuDir(const std::string &InstalledDir, const llvm::opt::ArgList &Args); static StringRef GetTargetCPU(const llvm::opt::ArgList &Args); static const char *GetSmallDataThreshold(const llvm::opt::ArgList &Args); static bool UsesG0(const char *smallDataThreshold); }; class LLVM_LIBRARY_VISIBILITY NaCl_TC : public Generic_ELF { public: NaCl_TC(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; bool IsIntegratedAssemblerDefault() const override { return getTriple().getArch() == llvm::Triple::mipsel; } // Get the path to the file containing NaCl's ARM macros. It lives in NaCl_TC // because the AssembleARM tool needs a const char * that it can pass around // and the toolchain outlives all the jobs. const char *GetNaClArmMacrosPath() const { return NaClArmMacrosPath.c_str(); } std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType) const override; std::string Linker; protected: Tool *buildLinker() const override; Tool *buildAssembler() const override; private: std::string NaClArmMacrosPath; }; /// TCEToolChain - A tool chain using the llvm bitcode tools to perform /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain { public: TCEToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); ~TCEToolChain() override; bool IsMathErrnoDefault() const override; bool isPICDefault() const override; bool isPIEDefault() const override; bool isPICDefaultForced() const override; }; class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain { public: MSVCToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); bool IsIntegratedAssemblerDefault() const override; bool IsUnwindTablesDefault() const override; bool isPICDefault() const override; bool isPIEDefault() const override; bool isPICDefaultForced() const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; bool getWindowsSDKDir(std::string &path, int &major, int &minor) const; bool getWindowsSDKLibraryPath(std::string &path) const; bool getVisualStudioInstallDir(std::string &path) const; bool getVisualStudioBinariesFolder(const char *clangProgramPath, std::string &path) const; std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType) const override; SanitizerMask getSupportedSanitizers() const override; protected: void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const std::string &folder, const char *subfolder) const; Tool *buildLinker() const override; Tool *buildAssembler() const override; }; class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC { public: CrossWindowsToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args); bool IsIntegratedAssemblerDefault() const override { return true; } bool IsUnwindTablesDefault() const override; bool isPICDefault() const override; bool isPIEDefault() const override; bool isPICDefaultForced() const override; unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override { return 0; } void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; protected: Tool *buildLinker() const override; Tool *buildAssembler() const override; }; class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain { public: XCore(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; public: bool isPICDefault() const override; bool isPIEDefault() const override; bool isPICDefaultForced() const override; bool SupportsProfiling() const override; bool hasBlocksRuntime() const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; }; /// SHAVEToolChain - A tool chain using the compiler installed by the the // Movidius SDK into MV_TOOLS_DIR (which we assume will be copied to llvm's // installation dir) to perform all subcommands. class LLVM_LIBRARY_VISIBILITY SHAVEToolChain : public Generic_GCC { public: SHAVEToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); ~SHAVEToolChain() override; virtual Tool *SelectTool(const JobAction &JA) const override; protected: Tool *getTool(Action::ActionClass AC) const override; Tool *buildAssembler() const override; Tool *buildLinker() const override; private: mutable std::unique_ptr<Tool> Compiler; mutable std::unique_ptr<Tool> Assembler; }; } // end namespace toolchains } // end namespace driver } // end namespace clang #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/DriverOptions.cpp
//===--- DriverOptions.cpp - Driver Options Table -------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Options.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" using namespace clang::driver; using namespace clang::driver::options; using namespace llvm::opt; #define PREFIX(NAME, VALUE) static const char *const NAME[] = VALUE; #include "clang/Driver/Options.inc" #undef PREFIX static const OptTable::Info InfoTable[] = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR) \ { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \ FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS }, #include "clang/Driver/Options.inc" #undef OPTION }; namespace { class DriverOptTable : public OptTable { public: DriverOptTable() : OptTable(InfoTable, llvm::array_lengthof(InfoTable)) {} }; } OptTable *clang::driver::createDriverOptTable() { return new DriverOptTable(); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Job.cpp
//===--- Job.cpp - Command to Execute -------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Job.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" #include <cassert> using namespace clang::driver; using llvm::raw_ostream; using llvm::StringRef; using llvm::ArrayRef; Command::Command(const Action &Source, const Tool &Creator, const char *Executable, const ArgStringList &Arguments) : Source(Source), Creator(Creator), Executable(Executable), Arguments(Arguments), ResponseFile(nullptr) {} static int skipArgs(const char *Flag, bool HaveCrashVFS) { // These flags are all of the form -Flag <Arg> and are treated as two // arguments. Therefore, we need to skip the flag and the next argument. bool Res = llvm::StringSwitch<bool>(Flag) .Cases("-I", "-MF", "-MT", "-MQ", true) .Cases("-o", "-coverage-file", "-dependency-file", true) .Cases("-fdebug-compilation-dir", "-idirafter", true) .Cases("-include", "-include-pch", "-internal-isystem", true) .Cases("-internal-externc-isystem", "-iprefix", "-iwithprefix", true) .Cases("-iwithprefixbefore", "-isystem", "-iquote", true) .Cases("-resource-dir", "-serialize-diagnostic-file", true) .Cases("-dwarf-debug-flags", "-ivfsoverlay", true) // Some include flags shouldn't be skipped if we have a crash VFS .Case("-isysroot", !HaveCrashVFS) .Default(false); // Match found. if (Res) return 2; // The remaining flags are treated as a single argument. // These flags are all of the form -Flag and have no second argument. Res = llvm::StringSwitch<bool>(Flag) .Cases("-M", "-MM", "-MG", "-MP", "-MD", true) .Case("-MMD", true) .Default(false); // Match found. if (Res) return 1; // These flags are treated as a single argument (e.g., -F<Dir>). StringRef FlagRef(Flag); if (FlagRef.startswith("-F") || FlagRef.startswith("-I") || FlagRef.startswith("-fmodules-cache-path=")) return 1; return 0; } void Command::printArg(raw_ostream &OS, const char *Arg, bool Quote) { const bool Escape = std::strpbrk(Arg, "\"\\$"); if (!Quote && !Escape) { OS << Arg; return; } // Quote and escape. This isn't really complete, but good enough. OS << '"'; while (const char c = *Arg++) { if (c == '"' || c == '\\' || c == '$') OS << '\\'; OS << c; } OS << '"'; } void Command::writeResponseFile(raw_ostream &OS) const { // In a file list, we only write the set of inputs to the response file if (Creator.getResponseFilesSupport() == Tool::RF_FileList) { for (const char *Arg : InputFileList) { OS << Arg << '\n'; } return; } // In regular response files, we send all arguments to the response file for (const char *Arg : Arguments) { OS << '"'; for (; *Arg != '\0'; Arg++) { if (*Arg == '\"' || *Arg == '\\') { OS << '\\'; } OS << *Arg; } OS << "\" "; } } void Command::buildArgvForResponseFile( llvm::SmallVectorImpl<const char *> &Out) const { // When not a file list, all arguments are sent to the response file. // This leaves us to set the argv to a single parameter, requesting the tool // to read the response file. if (Creator.getResponseFilesSupport() != Tool::RF_FileList) { Out.push_back(Executable); Out.push_back(ResponseFileFlag.c_str()); return; } llvm::StringSet<> Inputs; for (const char *InputName : InputFileList) Inputs.insert(InputName); Out.push_back(Executable); // In a file list, build args vector ignoring parameters that will go in the // response file (elements of the InputFileList vector) bool FirstInput = true; for (const char *Arg : Arguments) { if (Inputs.count(Arg) == 0) { Out.push_back(Arg); } else if (FirstInput) { FirstInput = false; Out.push_back(Creator.getResponseFileFlag()); Out.push_back(ResponseFile); } } } void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo) const { // Always quote the exe. OS << ' '; printArg(OS, Executable, /*Quote=*/true); llvm::ArrayRef<const char *> Args = Arguments; llvm::SmallVector<const char *, 128> ArgsRespFile; if (ResponseFile != nullptr) { buildArgvForResponseFile(ArgsRespFile); Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name } StringRef MainFilename; // We'll need the argument to -main-file-name to find the input file name. if (CrashInfo) for (size_t I = 0, E = Args.size(); I + 1 < E; ++I) if (StringRef(Args[I]).equals("-main-file-name")) MainFilename = Args[I + 1]; bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty(); for (size_t i = 0, e = Args.size(); i < e; ++i) { const char *const Arg = Args[i]; if (CrashInfo) { if (int Skip = skipArgs(Arg, HaveCrashVFS)) { i += Skip - 1; continue; } else if (llvm::sys::path::filename(Arg) == MainFilename && (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) { // Replace the input file name with the crashinfo's file name. OS << ' '; StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename); printArg(OS, ShortName.str().c_str(), Quote); continue; } } OS << ' '; printArg(OS, Arg, Quote); } if (CrashInfo && HaveCrashVFS) { OS << ' '; printArg(OS, "-ivfsoverlay", Quote); OS << ' '; printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote); } if (ResponseFile != nullptr) { OS << "\n Arguments passed via response file:\n"; writeResponseFile(OS); // Avoiding duplicated newline terminator, since FileLists are // newline-separated. if (Creator.getResponseFilesSupport() != Tool::RF_FileList) OS << "\n"; OS << " (end of response file)"; } OS << Terminator; } void Command::setResponseFile(const char *FileName) { ResponseFile = FileName; ResponseFileFlag = Creator.getResponseFileFlag(); ResponseFileFlag += FileName; } int Command::Execute(const StringRef **Redirects, std::string *ErrMsg, bool *ExecutionFailed) const { #ifdef MSFT_SUPPORTS_CHILD_PROCESSES SmallVector<const char*, 128> Argv; if (ResponseFile == nullptr) { Argv.push_back(Executable); Argv.append(Arguments.begin(), Arguments.end()); Argv.push_back(nullptr); return llvm::sys::ExecuteAndWait(Executable, Argv.data(), /*env*/ nullptr, Redirects, /*secondsToWait*/ 0, /*memoryLimit*/ 0, ErrMsg, ExecutionFailed); } // We need to put arguments in a response file (command is too large) // Open stream to store the response file contents std::string RespContents; llvm::raw_string_ostream SS(RespContents); // Write file contents and build the Argv vector writeResponseFile(SS); buildArgvForResponseFile(Argv); Argv.push_back(nullptr); SS.flush(); // Save the response file in the appropriate encoding if (std::error_code EC = writeFileWithEncoding( ResponseFile, RespContents, Creator.getResponseFileEncoding())) { if (ErrMsg) *ErrMsg = EC.message(); if (ExecutionFailed) *ExecutionFailed = true; return -1; } return llvm::sys::ExecuteAndWait(Executable, Argv.data(), /*env*/ nullptr, Redirects, /*secondsToWait*/ 0, /*memoryLimit*/ 0, ErrMsg, ExecutionFailed); #else assert(false && "support for spawning processes should be removed from public paths"); return 1; #endif } FallbackCommand::FallbackCommand(const Action &Source_, const Tool &Creator_, const char *Executable_, const ArgStringList &Arguments_, std::unique_ptr<Command> Fallback_) : Command(Source_, Creator_, Executable_, Arguments_), Fallback(std::move(Fallback_)) {} void FallbackCommand::Print(raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo) const { Command::Print(OS, "", Quote, CrashInfo); OS << " ||"; Fallback->Print(OS, Terminator, Quote, CrashInfo); } static bool ShouldFallback(int ExitCode) { // FIXME: We really just want to fall back for internal errors, such // as when some symbol cannot be mangled, when we should be able to // parse something but can't, etc. return ExitCode != 0; } int FallbackCommand::Execute(const StringRef **Redirects, std::string *ErrMsg, bool *ExecutionFailed) const { int PrimaryStatus = Command::Execute(Redirects, ErrMsg, ExecutionFailed); if (!ShouldFallback(PrimaryStatus)) return PrimaryStatus; // Clear ExecutionFailed and ErrMsg before falling back. if (ErrMsg) ErrMsg->clear(); if (ExecutionFailed) *ExecutionFailed = false; const Driver &D = getCreator().getToolChain().getDriver(); D.Diag(diag::warn_drv_invoking_fallback) << Fallback->getExecutable(); int SecondaryStatus = Fallback->Execute(Redirects, ErrMsg, ExecutionFailed); return SecondaryStatus; } void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo) const { for (const auto &Job : *this) Job.Print(OS, Terminator, Quote, CrashInfo); } void JobList::clear() { Jobs.clear(); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/Tool.cpp
//===--- Tool.cpp - Compilation Tools -------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Driver/Tool.h" using namespace clang::driver; Tool::Tool(const char *_Name, const char *_ShortName, const ToolChain &TC, ResponseFileSupport _ResponseSupport, llvm::sys::WindowsEncodingMethod _ResponseEncoding, const char *_ResponseFlag) : Name(_Name), ShortName(_ShortName), TheToolChain(TC), ResponseSupport(_ResponseSupport), ResponseEncoding(_ResponseEncoding), ResponseFlag(_ResponseFlag) {} Tool::~Tool() { }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Driver/InputInfo.h
//===--- InputInfo.h - Input Source & Type Information ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H #include "clang/Driver/Types.h" #include "llvm/Option/Arg.h" #include <cassert> #include <string> namespace clang { namespace driver { /// InputInfo - Wrapper for information about an input source. class InputInfo { // FIXME: The distinction between filenames and inputarg here is // gross; we should probably drop the idea of a "linker // input". Doing so means tweaking pipelining to still create link // steps when it sees linker inputs (but not treat them as // arguments), and making sure that arguments get rendered // correctly. enum Class { Nothing, Filename, InputArg, Pipe }; union { const char *Filename; const llvm::opt::Arg *InputArg; } Data; Class Kind; types::ID Type; const char *BaseInput; public: InputInfo() {} InputInfo(types::ID _Type, const char *_BaseInput) : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { } InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { Data.Filename = _Filename; } InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type, const char *_BaseInput) : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { Data.InputArg = _InputArg; } bool isNothing() const { return Kind == Nothing; } bool isFilename() const { return Kind == Filename; } bool isInputArg() const { return Kind == InputArg; } types::ID getType() const { return Type; } const char *getBaseInput() const { return BaseInput; } const char *getFilename() const { assert(isFilename() && "Invalid accessor."); return Data.Filename; } const llvm::opt::Arg &getInputArg() const { assert(isInputArg() && "Invalid accessor."); return *Data.InputArg; } /// getAsString - Return a string name for this input, for /// debugging. std::string getAsString() const { if (isFilename()) return std::string("\"") + getFilename() + '"'; else if (isInputArg()) return "(input arg)"; else return "(nothing)"; } }; } // end namespace driver } // end namespace clang #endif
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/LogDiagnosticPrinter.cpp
//===--- LogDiagnosticPrinter.cpp - Log Diagnostic Printer ----------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/LogDiagnosticPrinter.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/PlistSupport.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" using namespace clang; using namespace markup; LogDiagnosticPrinter::LogDiagnosticPrinter( raw_ostream &os, DiagnosticOptions *diags, std::unique_ptr<raw_ostream> StreamOwner) : OS(os), StreamOwner(std::move(StreamOwner)), LangOpts(nullptr), DiagOpts(diags) {} static StringRef getLevelName(DiagnosticsEngine::Level Level) { switch (Level) { case DiagnosticsEngine::Ignored: return "ignored"; case DiagnosticsEngine::Remark: return "remark"; case DiagnosticsEngine::Note: return "note"; case DiagnosticsEngine::Warning: return "warning"; case DiagnosticsEngine::Error: return "error"; case DiagnosticsEngine::Fatal: return "fatal error"; } llvm_unreachable("Invalid DiagnosticsEngine level!"); } void LogDiagnosticPrinter::EmitDiagEntry(llvm::raw_ostream &OS, const LogDiagnosticPrinter::DiagEntry &DE) { OS << " <dict>\n"; OS << " <key>level</key>\n" << " "; EmitString(OS, getLevelName(DE.DiagnosticLevel)) << '\n'; if (!DE.Filename.empty()) { OS << " <key>filename</key>\n" << " "; EmitString(OS, DE.Filename) << '\n'; } if (DE.Line != 0) { OS << " <key>line</key>\n" << " "; EmitInteger(OS, DE.Line) << '\n'; } if (DE.Column != 0) { OS << " <key>column</key>\n" << " "; EmitInteger(OS, DE.Column) << '\n'; } if (!DE.Message.empty()) { OS << " <key>message</key>\n" << " "; EmitString(OS, DE.Message) << '\n'; } OS << " <key>ID</key>\n" << " "; EmitInteger(OS, DE.DiagnosticID) << '\n'; if (!DE.WarningOption.empty()) { OS << " <key>WarningOption</key>\n" << " "; EmitString(OS, DE.WarningOption) << '\n'; } OS << " </dict>\n"; } void LogDiagnosticPrinter::EndSourceFile() { // We emit all the diagnostics in EndSourceFile. However, we don't emit any // entry if no diagnostics were present. // // Note that DiagnosticConsumer has no "end-of-compilation" callback, so we // will miss any diagnostics which are emitted after and outside the // translation unit processing. if (Entries.empty()) return; // Write to a temporary string to ensure atomic write of diagnostic object. SmallString<512> Msg; llvm::raw_svector_ostream OS(Msg); OS << "<dict>\n"; if (!MainFilename.empty()) { OS << " <key>main-file</key>\n" << " "; EmitString(OS, MainFilename) << '\n'; } if (!DwarfDebugFlags.empty()) { OS << " <key>dwarf-debug-flags</key>\n" << " "; EmitString(OS, DwarfDebugFlags) << '\n'; } OS << " <key>diagnostics</key>\n"; OS << " <array>\n"; for (auto &DE : Entries) EmitDiagEntry(OS, DE); OS << " </array>\n"; OS << "</dict>\n"; this->OS << OS.str(); } void LogDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info) { // Default implementation (Warnings/errors count). DiagnosticConsumer::HandleDiagnostic(Level, Info); // Initialize the main file name, if we haven't already fetched it. if (MainFilename.empty() && Info.hasSourceManager()) { const SourceManager &SM = Info.getSourceManager(); FileID FID = SM.getMainFileID(); if (!FID.isInvalid()) { const FileEntry *FE = SM.getFileEntryForID(FID); if (FE && FE->isValid()) MainFilename = FE->getName(); } } // Create the diag entry. DiagEntry DE; DE.DiagnosticID = Info.getID(); DE.DiagnosticLevel = Level; DE.WarningOption = DiagnosticIDs::getWarningOptionForDiag(DE.DiagnosticID); // Format the message. SmallString<100> MessageStr; Info.FormatDiagnostic(MessageStr); DE.Message = MessageStr.str(); // Set the location information. DE.Filename = ""; DE.Line = DE.Column = 0; if (Info.getLocation().isValid() && Info.hasSourceManager()) { const SourceManager &SM = Info.getSourceManager(); PresumedLoc PLoc = SM.getPresumedLoc(Info.getLocation()); if (PLoc.isInvalid()) { // At least print the file name if available: FileID FID = SM.getFileID(Info.getLocation()); if (!FID.isInvalid()) { const FileEntry *FE = SM.getFileEntryForID(FID); if (FE && FE->isValid()) DE.Filename = FE->getName(); } } else { DE.Filename = PLoc.getFilename(); DE.Line = PLoc.getLine(); DE.Column = PLoc.getColumn(); } } // Record the diagnostic entry. Entries.push_back(DE); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/FrontendOptions.cpp
//===--- FrontendOptions.cpp ----------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/FrontendOptions.h" #include "llvm/ADT/StringSwitch.h" using namespace clang; InputKind FrontendOptions::getInputKindForExtension(StringRef Extension) { return llvm::StringSwitch<InputKind>(Extension) .Cases("ast", "pcm", IK_AST) .Case("c", IK_C) .Cases("S", "s", IK_Asm) .Case("i", IK_PreprocessedC) .Case("ii", IK_PreprocessedCXX) .Case("cui", IK_PreprocessedCuda) .Case("m", IK_ObjC) .Case("mi", IK_PreprocessedObjC) .Cases("mm", "M", IK_ObjCXX) .Case("mii", IK_PreprocessedObjCXX) .Cases("C", "cc", "cp", IK_CXX) .Cases("cpp", "CPP", "c++", "cxx", "hpp", IK_CXX) .Case("cl", IK_OpenCL) .Case("cu", IK_CUDA) .Cases("hlsl", "fx", IK_HLSL) // HLSL Change: Inputkind files for hlsl .Cases("ll", "bc", IK_LLVM_IR) .Default(IK_C); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/PrintPreprocessedOutput.cpp
//===--- PrintPreprocessedOutput.cpp - Implement the -E mode --------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This code simply runs the preprocessor on the input file and prints out the // result. This is the traditional behavior of the -E option. // //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/PreprocessorOutputOptions.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Pragma.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/TokenConcatenation.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <cstdio> using namespace clang; /// PrintMacroDefinition - Print a macro definition in a form that will be /// properly accepted back as a definition. static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI, Preprocessor &PP, raw_ostream &OS) { OS << "#define " << II.getName(); if (MI.isFunctionLike()) { OS << '('; if (!MI.arg_empty()) { MacroInfo::arg_iterator AI = MI.arg_begin(), E = MI.arg_end(); for (; AI+1 != E; ++AI) { OS << (*AI)->getName(); OS << ','; } // Last argument. if ((*AI)->getName() == "__VA_ARGS__") OS << "..."; else OS << (*AI)->getName(); } if (MI.isGNUVarargs()) OS << "..."; // #define foo(x...) OS << ')'; } // GCC always emits a space, even if the macro body is empty. However, do not // want to emit two spaces if the first token has a leading space. if (MI.tokens_empty() || !MI.tokens_begin()->hasLeadingSpace()) OS << ' '; SmallString<128> SpellingBuffer; for (const auto &T : MI.tokens()) { if (T.hasLeadingSpace()) OS << ' '; OS << PP.getSpelling(T, SpellingBuffer); } } //===----------------------------------------------------------------------===// // Preprocessed token printer //===----------------------------------------------------------------------===// namespace { class PrintPPOutputPPCallbacks : public PPCallbacks { Preprocessor &PP; SourceManager &SM; TokenConcatenation ConcatInfo; public: raw_ostream &OS; private: unsigned CurLine; bool EmittedTokensOnThisLine; bool EmittedDirectiveOnThisLine; SrcMgr::CharacteristicKind FileType; SmallString<512> CurFilename; bool Initialized; bool DisableLineMarkers; bool DumpDefines; bool UseLineDirectives; bool IsFirstFileEntered; public: PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers, bool defines, bool UseLineDirectives) : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers), DumpDefines(defines), UseLineDirectives(UseLineDirectives) { CurLine = 0; CurFilename += "<uninit>"; EmittedTokensOnThisLine = false; EmittedDirectiveOnThisLine = false; FileType = SrcMgr::C_User; Initialized = false; IsFirstFileEntered = false; } void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; } bool hasEmittedTokensOnThisLine() const { return EmittedTokensOnThisLine; } void setEmittedDirectiveOnThisLine() { EmittedDirectiveOnThisLine = true; } bool hasEmittedDirectiveOnThisLine() const { return EmittedDirectiveOnThisLine; } bool startNewLineIfNeeded(bool ShouldUpdateCurrentLine = true); void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override; void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) override; void Ident(SourceLocation Loc, StringRef str) override; void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str) override; void PragmaDebug(SourceLocation Loc, StringRef DebugType) override; void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override; void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override; void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity Map, StringRef Str) override; void PragmaWarning(SourceLocation Loc, StringRef WarningSpec, ArrayRef<int> Ids) override; void PragmaWarningPush(SourceLocation Loc, int Level) override; void PragmaWarningPop(SourceLocation Loc) override; bool HandleFirstTokOnLine(Token &Tok); /// Move to the line of the provided source location. This will /// return true if the output stream required adjustment or if /// the requested location is on the first line. bool MoveToLine(SourceLocation Loc) { PresumedLoc PLoc = SM.getPresumedLoc(Loc); if (PLoc.isInvalid()) return false; return MoveToLine(PLoc.getLine()) || (PLoc.getLine() == 1); } bool MoveToLine(unsigned LineNo); bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok, const Token &Tok) { return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok); } void WriteLineInfo(unsigned LineNo, const char *Extra=nullptr, unsigned ExtraLen=0); bool LineMarkersAreDisabled() const { return DisableLineMarkers; } void HandleNewlinesInToken(const char *TokStr, unsigned Len); /// MacroDefined - This hook is called whenever a macro definition is seen. void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override; /// MacroUndefined - This hook is called whenever a macro #undef is seen. void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD) override; }; } // end anonymous namespace void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo, const char *Extra, unsigned ExtraLen) { startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false); // Emit #line directives or GNU line markers depending on what mode we're in. if (UseLineDirectives) { OS << "#line" << ' ' << LineNo << ' ' << '"'; OS.write_escaped(CurFilename); OS << '"'; } else { OS << '#' << ' ' << LineNo << ' ' << '"'; OS.write_escaped(CurFilename); OS << '"'; if (ExtraLen) OS.write(Extra, ExtraLen); if (FileType == SrcMgr::C_System) OS.write(" 3", 2); else if (FileType == SrcMgr::C_ExternCSystem) OS.write(" 3 4", 4); } OS << '\n'; } /// MoveToLine - Move the output to the source line specified by the location /// object. We can do this by emitting some number of \n's, or be emitting a /// #line directive. This returns false if already at the specified line, true /// if some newlines were emitted. bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo) { // If this line is "close enough" to the original line, just print newlines, // otherwise print a #line directive. if (LineNo-CurLine <= 8) { if (LineNo-CurLine == 1) OS << '\n'; else if (LineNo == CurLine) return false; // Spelling line moved, but expansion line didn't. else { const char *NewLines = "\n\n\n\n\n\n\n\n"; OS.write(NewLines, LineNo-CurLine); } } else if (!DisableLineMarkers) { // Emit a #line or line marker. WriteLineInfo(LineNo, nullptr, 0); } else { // Okay, we're in -P mode, which turns off line markers. However, we still // need to emit a newline between tokens on different lines. startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false); } CurLine = LineNo; return true; } bool PrintPPOutputPPCallbacks::startNewLineIfNeeded(bool ShouldUpdateCurrentLine) { if (EmittedTokensOnThisLine || EmittedDirectiveOnThisLine) { OS << '\n'; EmittedTokensOnThisLine = false; EmittedDirectiveOnThisLine = false; if (ShouldUpdateCurrentLine) ++CurLine; return true; } return false; } /// FileChanged - Whenever the preprocessor enters or exits a #include file /// it invokes this handler. Update our conception of the current source /// position. void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind NewFileType, FileID PrevFID) { // Unless we are exiting a #include, make sure to skip ahead to the line the // #include directive was at. SourceManager &SourceMgr = SM; PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc); if (UserLoc.isInvalid()) return; unsigned NewLine = UserLoc.getLine(); if (Reason == PPCallbacks::EnterFile) { SourceLocation IncludeLoc = UserLoc.getIncludeLoc(); if (IncludeLoc.isValid()) MoveToLine(IncludeLoc); } else if (Reason == PPCallbacks::SystemHeaderPragma) { // GCC emits the # directive for this directive on the line AFTER the // directive and emits a bunch of spaces that aren't needed. This is because // otherwise we will emit a line marker for THIS line, which requires an // extra blank line after the directive to avoid making all following lines // off by one. We can do better by simply incrementing NewLine here. NewLine += 1; } // HLSL Change Starts - do not report the same location multiple times if (PP.getLangOpts().HLSL && CurLine == NewLine && CurFilename == UserLoc.getFilename()) { assert(FileType == NewFileType && "else same file has different file type"); return; } if (PP.getLangOpts().HLSL) { if (0 == strcmp(UserLoc.getFilename(), "<built-in>")) { return; } } // HLSL Change Ends CurLine = NewLine; CurFilename.clear(); CurFilename += UserLoc.getFilename(); FileType = NewFileType; if (DisableLineMarkers) { startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false); return; } if (!Initialized) { WriteLineInfo(CurLine); Initialized = true; } // Do not emit an enter marker for the main file (which we expect is the first // entered file). This matches gcc, and improves compatibility with some tools // which track the # line markers as a way to determine when the preprocessed // output is in the context of the main file. if (Reason == PPCallbacks::EnterFile && !IsFirstFileEntered) { IsFirstFileEntered = true; return; } switch (Reason) { case PPCallbacks::EnterFile: WriteLineInfo(CurLine, " 1", 2); break; case PPCallbacks::ExitFile: WriteLineInfo(CurLine, " 2", 2); break; case PPCallbacks::SystemHeaderPragma: case PPCallbacks::RenameFile: WriteLineInfo(CurLine); break; } } void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) { // When preprocessing, turn implicit imports into @imports. // FIXME: This is a stop-gap until a more comprehensive "preprocessing with // modules" solution is introduced. if (Imported) { startNewLineIfNeeded(); MoveToLine(HashLoc); OS << "@import " << Imported->getFullModuleName() << ";" << " /* clang -E: implicit import for \"" << File->getName() << "\" */"; // Since we want a newline after the @import, but not a #<line>, start a new // line immediately. EmittedTokensOnThisLine = true; startNewLineIfNeeded(); } } /// Ident - Handle #ident directives when read by the preprocessor. /// void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, StringRef S) { MoveToLine(Loc); OS.write("#ident ", strlen("#ident ")); OS.write(S.begin(), S.size()); EmittedTokensOnThisLine = true; } /// MacroDefined - This hook is called whenever a macro definition is seen. void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) { const MacroInfo *MI = MD->getMacroInfo(); // Only print out macro definitions in -dD mode. if (!DumpDefines || // Ignore __FILE__ etc. MI->isBuiltinMacro()) return; MoveToLine(MI->getDefinitionLoc()); PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS); setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD) { // Only print out macro definitions in -dD mode. if (!DumpDefines) return; MoveToLine(MacroNameTok.getLocation()); OS << "#undef " << MacroNameTok.getIdentifierInfo()->getName(); setEmittedDirectiveOnThisLine(); } static void outputPrintable(llvm::raw_ostream& OS, const std::string &Str) { for (unsigned i = 0, e = Str.size(); i != e; ++i) { unsigned char Char = Str[i]; if (isPrintable(Char) && Char != '\\' && Char != '"') OS << (char)Char; else // Output anything hard as an octal escape. OS << '\\' << (char)('0'+ ((Char >> 6) & 7)) << (char)('0'+ ((Char >> 3) & 7)) << (char)('0'+ ((Char >> 0) & 7)); } } void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma "; if (!Namespace.empty()) OS << Namespace << ' '; switch (Kind) { case PMK_Message: OS << "message(\""; break; case PMK_Warning: OS << "warning \""; break; case PMK_Error: OS << "error \""; break; } outputPrintable(OS, Str); OS << '"'; if (Kind == PMK_Message) OS << ')'; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks::PragmaDebug(SourceLocation Loc, StringRef DebugType) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma clang __debug "; OS << DebugType; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks:: PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma " << Namespace << " diagnostic push"; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks:: PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma " << Namespace << " diagnostic pop"; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks::PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity Map, StringRef Str) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma " << Namespace << " diagnostic "; switch (Map) { case diag::Severity::Remark: OS << "remark"; break; case diag::Severity::Warning: OS << "warning"; break; case diag::Severity::Error: OS << "error"; break; case diag::Severity::Ignored: OS << "ignored"; break; case diag::Severity::Fatal: OS << "fatal"; break; } OS << " \"" << Str << '"'; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks::PragmaWarning(SourceLocation Loc, StringRef WarningSpec, ArrayRef<int> Ids) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma warning(" << WarningSpec << ':'; for (ArrayRef<int>::iterator I = Ids.begin(), E = Ids.end(); I != E; ++I) OS << ' ' << *I; OS << ')'; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks::PragmaWarningPush(SourceLocation Loc, int Level) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma warning(push"; if (Level >= 0) OS << ", " << Level; OS << ')'; setEmittedDirectiveOnThisLine(); } void PrintPPOutputPPCallbacks::PragmaWarningPop(SourceLocation Loc) { startNewLineIfNeeded(); MoveToLine(Loc); OS << "#pragma warning(pop)"; setEmittedDirectiveOnThisLine(); } /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this /// is called for the first token on each new line. If this really is the start /// of a new logical line, handle it and return true, otherwise return false. /// This may not be the start of a logical line because the "start of line" /// marker is set for spelling lines, not expansion ones. bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) { // Figure out what line we went to and insert the appropriate number of // newline characters. if (!MoveToLine(Tok.getLocation())) return false; // Print out space characters so that the first token on a line is // indented for easy reading. unsigned ColNo = SM.getExpansionColumnNumber(Tok.getLocation()); // The first token on a line can have a column number of 1, yet still expect // leading white space, if a macro expansion in column 1 starts with an empty // macro argument, or an empty nested macro expansion. In this case, move the // token to column 2. if (ColNo == 1 && Tok.hasLeadingSpace()) ColNo = 2; // This hack prevents stuff like: // #define HASH # // HASH define foo bar // From having the # character end up at column 1, which makes it so it // is not handled as a #define next time through the preprocessor if in // -fpreprocessed mode. if (ColNo <= 1 && Tok.is(tok::hash)) OS << ' '; // Otherwise, indent the appropriate number of spaces. for (; ColNo > 1; --ColNo) OS << ' '; return true; } void PrintPPOutputPPCallbacks::HandleNewlinesInToken(const char *TokStr, unsigned Len) { unsigned NumNewlines = 0; for (; Len; --Len, ++TokStr) { if (*TokStr != '\n' && *TokStr != '\r') continue; ++NumNewlines; // If we have \n\r or \r\n, skip both and count as one line. if (Len != 1 && (TokStr[1] == '\n' || TokStr[1] == '\r') && TokStr[0] != TokStr[1]) ++TokStr, --Len; } if (NumNewlines == 0) return; CurLine += NumNewlines; } namespace { struct UnknownPragmaHandler : public PragmaHandler { const char *Prefix; PrintPPOutputPPCallbacks *Callbacks; // Set to true if tokens should be expanded bool ShouldExpandTokens; UnknownPragmaHandler(const char *prefix, PrintPPOutputPPCallbacks *callbacks, bool RequireTokenExpansion) : Prefix(prefix), Callbacks(callbacks), ShouldExpandTokens(RequireTokenExpansion) {} void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &PragmaTok) override { // Figure out what line we went to and insert the appropriate number of // newline characters. Callbacks->startNewLineIfNeeded(); Callbacks->MoveToLine(PragmaTok.getLocation()); Callbacks->OS.write(Prefix, strlen(Prefix)); Token PrevToken; Token PrevPrevToken; PrevToken.startToken(); PrevPrevToken.startToken(); // Read and print all of the pragma tokens. while (PragmaTok.isNot(tok::eod)) { if (PragmaTok.hasLeadingSpace() || Callbacks->AvoidConcat(PrevPrevToken, PrevToken, PragmaTok)) Callbacks->OS << ' '; std::string TokSpell = PP.getSpelling(PragmaTok); Callbacks->OS.write(&TokSpell[0], TokSpell.size()); PrevPrevToken = PrevToken; PrevToken = PragmaTok; if (ShouldExpandTokens) PP.Lex(PragmaTok); else PP.LexUnexpandedToken(PragmaTok); } Callbacks->setEmittedDirectiveOnThisLine(); } }; } // end anonymous namespace static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, PrintPPOutputPPCallbacks *Callbacks, raw_ostream &OS) { bool DropComments = PP.getLangOpts().TraditionalCPP && !PP.getCommentRetentionState(); char Buffer[256]; Token PrevPrevTok, PrevTok; PrevPrevTok.startToken(); PrevTok.startToken(); while (1) { if (Callbacks->hasEmittedDirectiveOnThisLine()) { Callbacks->startNewLineIfNeeded(); Callbacks->MoveToLine(Tok.getLocation()); } // If this token is at the start of a line, emit newlines if needed. if (Tok.isAtStartOfLine() && Callbacks->HandleFirstTokOnLine(Tok)) { // done. } else if (Tok.hasLeadingSpace() || // If we haven't emitted a token on this line yet, PrevTok isn't // useful to look at and no concatenation could happen anyway. (Callbacks->hasEmittedTokensOnThisLine() && // Don't print "-" next to "-", it would form "--". Callbacks->AvoidConcat(PrevPrevTok, PrevTok, Tok))) { OS << ' '; } if (DropComments && Tok.is(tok::comment)) { // Skip comments. Normally the preprocessor does not generate // tok::comment nodes at all when not keeping comments, but under // -traditional-cpp the lexer keeps /all/ whitespace, including comments. SourceLocation StartLoc = Tok.getLocation(); Callbacks->MoveToLine(StartLoc.getLocWithOffset(Tok.getLength())); } else if (Tok.is(tok::annot_module_include) || Tok.is(tok::annot_module_begin) || Tok.is(tok::annot_module_end)) { // PrintPPOutputPPCallbacks::InclusionDirective handles producing // appropriate output here. Ignore this token entirely. PP.Lex(Tok); continue; } else if (IdentifierInfo *II = Tok.getIdentifierInfo()) { OS << II->getName(); } else if (Tok.isLiteral() && !Tok.needsCleaning() && Tok.getLiteralData()) { OS.write(Tok.getLiteralData(), Tok.getLength()); } else if (Tok.getLength() < 256) { const char *TokPtr = Buffer; unsigned Len = PP.getSpelling(Tok, TokPtr); OS.write(TokPtr, Len); // Tokens that can contain embedded newlines need to adjust our current // line number. if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown) Callbacks->HandleNewlinesInToken(TokPtr, Len); } else { std::string S = PP.getSpelling(Tok); OS.write(&S[0], S.size()); // Tokens that can contain embedded newlines need to adjust our current // line number. if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown) Callbacks->HandleNewlinesInToken(&S[0], S.size()); } Callbacks->setEmittedTokensOnThisLine(); if (Tok.is(tok::eof)) break; PrevPrevTok = PrevTok; PrevTok = Tok; PP.Lex(Tok); } } typedef std::pair<const IdentifierInfo *, MacroInfo *> id_macro_pair; // HLSL Change: changed calling convention to __cdecl static int __cdecl MacroIDCompare(const id_macro_pair *LHS, const id_macro_pair *RHS) { return LHS->first->getName().compare(RHS->first->getName()); } static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) { // Ignore unknown pragmas. PP.IgnorePragmas(); // -dM mode just scans and ignores all tokens in the files, then dumps out // the macro table at the end. PP.EnterMainSourceFile(); Token Tok; do PP.Lex(Tok); while (Tok.isNot(tok::eof)); SmallVector<id_macro_pair, 128> MacrosByID; for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end(); I != E; ++I) { auto *MD = I->second.getLatest(); if (MD && MD->isDefined()) MacrosByID.push_back(id_macro_pair(I->first, MD->getMacroInfo())); } llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare); for (unsigned i = 0, e = MacrosByID.size(); i != e; ++i) { MacroInfo &MI = *MacrosByID[i].second; // Ignore computed macros like __LINE__ and friends. if (MI.isBuiltinMacro()) continue; PrintMacroDefinition(*MacrosByID[i].first, MI, PP, *OS); *OS << '\n'; } } /// DoPrintPreprocessedInput - This implements -E mode. /// void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts) { // Show macros with no output is handled specially. if (!Opts.ShowCPP) { assert(Opts.ShowMacros && "Not yet implemented!"); DoPrintMacros(PP, OS); return; } // Inform the preprocessor whether we want it to retain comments or not, due // to -C or -CC. PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments); PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks( PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros, Opts.UseLineDirectives); // Expand macros in pragmas with -fms-extensions. The assumption is that // the majority of pragmas in such a file will be Microsoft pragmas. PP.AddPragmaHandler(new UnknownPragmaHandler( "#pragma", Callbacks, /*RequireTokenExpansion=*/PP.getLangOpts().MicrosoftExt)); PP.AddPragmaHandler( "GCC", new UnknownPragmaHandler( "#pragma GCC", Callbacks, /*RequireTokenExpansion=*/PP.getLangOpts().MicrosoftExt)); PP.AddPragmaHandler( "clang", new UnknownPragmaHandler( "#pragma clang", Callbacks, /*RequireTokenExpansion=*/PP.getLangOpts().MicrosoftExt)); // The tokens after pragma omp need to be expanded. // // OpenMP [2.1, Directive format] // Preprocessing tokens following the #pragma omp are subject to macro // replacement. PP.AddPragmaHandler("omp", new UnknownPragmaHandler("#pragma omp", Callbacks, /*RequireTokenExpansion=*/true)); PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callbacks)); // After we have configured the preprocessor, enter the main file. PP.EnterMainSourceFile(); // Consume all of the tokens that come from the predefines buffer. Those // should not be emitted into the output and are guaranteed to be at the // start. const SourceManager &SourceMgr = PP.getSourceManager(); Token Tok; do { PP.Lex(Tok); if (Tok.is(tok::eof) || !Tok.getLocation().isFileID()) break; PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation()); if (PLoc.isInvalid()) break; if (strcmp(PLoc.getFilename(), "<built-in>")) break; } while (true); // Read all the preprocessed tokens, printing them out to the stream. PrintPreprocessedTokens(PP, Tok, Callbacks, *OS); *OS << '\n'; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
//===--- CreateInvocationFromCommandLine.cpp - CompilerInvocation from Args ==// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // Construct a compiler invocation object for command line driver arguments // //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Action.h" #include "clang/Driver/Options.h" #include "clang/Driver/Tool.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/Host.h" using namespace clang; using namespace llvm::opt; /// createInvocationFromCommandLine - Construct a compiler invocation object for /// a command line argument vector. /// /// \return A CompilerInvocation, or 0 if none was built for the given /// argument vector. CompilerInvocation * clang::createInvocationFromCommandLine(ArrayRef<const char *> ArgList, IntrusiveRefCntPtr<DiagnosticsEngine> Diags) { if (!Diags.get()) { // No diagnostics engine was provided, so create our own diagnostics object // with the default options. Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions); } SmallVector<const char *, 16> Args; //Args.push_back("<clang>"); // FIXME: Remove dummy argument. // HLSL Change - parse directly as compilation Args.insert(Args.end(), ArgList.begin(), ArgList.end()); // FIXME: Find a cleaner way to force the driver into restricted modes. Args.push_back("-fsyntax-only"); #if 1 // HLSL Change Starts - no support for driver/toolchain support const SmallVector<const char *, 16> &CCArgs = Args; #else // FIXME: We shouldn't have to pass in the path info. driver::Driver TheDriver("clang", llvm::sys::getDefaultTargetTriple(), *Diags); // Don't check that inputs exist, they may have been remapped. TheDriver.setCheckInputsExist(false); std::unique_ptr<driver::Compilation> C(TheDriver.BuildCompilation(Args)); // Just print the cc1 options if -### was present. if (C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) { C->getJobs().Print(llvm::errs(), "\n", true); return nullptr; } // We expect to get back exactly one command job, if we didn't something // failed. CUDA compilation is an exception as it creates multiple jobs. If // that's the case, we proceed with the first job. If caller needs particular // CUDA job, it should be controlled via --cuda-{host|device}-only option // passed to the driver. const driver::JobList &Jobs = C->getJobs(); bool CudaCompilation = false; if (Jobs.size() > 1) { for (auto &A : C->getActions()){ // On MacOSX real actions may end up being wrapped in BindArchAction if (isa<driver::BindArchAction>(A)) A = *A->begin(); if (isa<driver::CudaDeviceAction>(A)) { CudaCompilation = true; break; } } } if (Jobs.size() == 0 || !isa<driver::Command>(*Jobs.begin()) || (Jobs.size() > 1 && !CudaCompilation)) { SmallString<256> Msg; llvm::raw_svector_ostream OS(Msg); Jobs.Print(OS, "; ", true); Diags->Report(diag::err_fe_expected_compiler_job) << OS.str(); return nullptr; } const driver::Command &Cmd = cast<driver::Command>(*Jobs.begin()); if (StringRef(Cmd.getCreator().getName()) != "clang") { Diags->Report(diag::err_fe_expected_clang_command); return nullptr; } const ArgStringList &CCArgs = Cmd.getArguments(); #endif // HLSL Change Ends - no support for driver/toolchain support std::unique_ptr<CompilerInvocation> CI(new CompilerInvocation()); if (!CompilerInvocation::CreateFromArgs(*CI, const_cast<const char **>(CCArgs.data()), const_cast<const char **>(CCArgs.data()) + CCArgs.size(), *Diags)) return nullptr; return CI.release(); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/LangStandards.cpp
//===--- LangStandards.cpp - Language Standard Definitions ----------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/LangStandard.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ErrorHandling.h" using namespace clang; using namespace clang::frontend; #define LANGSTANDARD(id, name, desc, features) \ static const LangStandard Lang_##id = { name, desc, features }; #include "clang/Frontend/LangStandards.def" const LangStandard &LangStandard::getLangStandardForKind(Kind K) { switch (K) { case lang_unspecified: llvm::report_fatal_error("getLangStandardForKind() on unspecified kind"); #define LANGSTANDARD(id, name, desc, features) \ case lang_##id: return Lang_##id; #include "clang/Frontend/LangStandards.def" } llvm_unreachable("Invalid language kind!"); } const LangStandard *LangStandard::getLangStandardForName(StringRef Name) { Kind K = llvm::StringSwitch<Kind>(Name) #define LANGSTANDARD(id, name, desc, features) \ .Case(name, lang_##id) #include "clang/Frontend/LangStandards.def" .Default(lang_unspecified); if (K == lang_unspecified) return nullptr; return &getLangStandardForKind(K); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/TextDiagnosticBuffer.cpp
//===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This is a concrete diagnostic client, which buffers the diagnostic messages. // //===----------------------------------------------------------------------===// #include "clang/Frontend/TextDiagnosticBuffer.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/ErrorHandling.h" using namespace clang; /// HandleDiagnostic - Store the errors, warnings, and notes that are /// reported. /// void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info) { // Default implementation (Warnings/errors count). DiagnosticConsumer::HandleDiagnostic(Level, Info); SmallString<100> Buf; Info.FormatDiagnostic(Buf); switch (Level) { default: llvm_unreachable( "Diagnostic not handled during diagnostic buffering!"); case DiagnosticsEngine::Note: Notes.emplace_back(Info.getLocation(), Buf.str()); break; case DiagnosticsEngine::Warning: Warnings.emplace_back(Info.getLocation(), Buf.str()); break; case DiagnosticsEngine::Remark: Remarks.emplace_back(Info.getLocation(), Buf.str()); break; case DiagnosticsEngine::Error: case DiagnosticsEngine::Fatal: Errors.emplace_back(Info.getLocation(), Buf.str()); break; } } void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { // FIXME: Flush the diagnostics in order. for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0")) << it->second; for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, "%0")) << it->second; for (const_iterator it = remark_begin(), ie = remark_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Remark, "%0")) << it->second; for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0")) << it->second; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
//===--- SerializedDiagnosticPrinter.cpp - Serializer for diagnostics -----===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/SerializedDiagnosticPrinter.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Frontend/DiagnosticRenderer.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/SerializedDiagnosticReader.h" #include "clang/Frontend/SerializedDiagnostics.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" #include <vector> using namespace clang; using namespace clang::serialized_diags; namespace { class AbbreviationMap { llvm::DenseMap<unsigned, unsigned> Abbrevs; public: AbbreviationMap() {} void set(unsigned recordID, unsigned abbrevID) { assert(Abbrevs.find(recordID) == Abbrevs.end() && "Abbreviation already set."); Abbrevs[recordID] = abbrevID; } unsigned get(unsigned recordID) { assert(Abbrevs.find(recordID) != Abbrevs.end() && "Abbreviation not set."); return Abbrevs[recordID]; } }; typedef SmallVector<uint64_t, 64> RecordData; typedef SmallVectorImpl<uint64_t> RecordDataImpl; class SDiagsWriter; class SDiagsRenderer : public DiagnosticNoteRenderer { SDiagsWriter &Writer; public: SDiagsRenderer(SDiagsWriter &Writer, const LangOptions &LangOpts, DiagnosticOptions *DiagOpts) : DiagnosticNoteRenderer(LangOpts, DiagOpts), Writer(Writer) {} ~SDiagsRenderer() override {} protected: void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<CharSourceRange> Ranges, const SourceManager *SM, DiagOrStoredDiag D) override; void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, ArrayRef<CharSourceRange> Ranges, const SourceManager &SM) override {} void emitNote(SourceLocation Loc, StringRef Message, const SourceManager *SM) override; void emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level, SmallVectorImpl<CharSourceRange>& Ranges, ArrayRef<FixItHint> Hints, const SourceManager &SM) override; void beginDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level) override; void endDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level) override; }; typedef llvm::DenseMap<unsigned, unsigned> AbbrevLookup; class SDiagsMerger : SerializedDiagnosticReader { SDiagsWriter &Writer; AbbrevLookup FileLookup; AbbrevLookup CategoryLookup; AbbrevLookup DiagFlagLookup; public: SDiagsMerger(SDiagsWriter &Writer) : SerializedDiagnosticReader(), Writer(Writer) {} std::error_code mergeRecordsFromFile(const char *File) { return readDiagnostics(File); } protected: std::error_code visitStartOfDiagnostic() override; std::error_code visitEndOfDiagnostic() override; std::error_code visitCategoryRecord(unsigned ID, StringRef Name) override; std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name) override; std::error_code visitDiagnosticRecord( unsigned Severity, const serialized_diags::Location &Location, unsigned Category, unsigned Flag, StringRef Message) override; std::error_code visitFilenameRecord(unsigned ID, unsigned Size, unsigned Timestamp, StringRef Name) override; std::error_code visitFixitRecord(const serialized_diags::Location &Start, const serialized_diags::Location &End, StringRef CodeToInsert) override; std::error_code visitSourceRangeRecord(const serialized_diags::Location &Start, const serialized_diags::Location &End) override; private: std::error_code adjustSourceLocFilename(RecordData &Record, unsigned int offset); void adjustAbbrevID(RecordData &Record, AbbrevLookup &Lookup, unsigned NewAbbrev); void writeRecordWithAbbrev(unsigned ID, RecordData &Record); void writeRecordWithBlob(unsigned ID, RecordData &Record, StringRef Blob); }; class SDiagsWriter : public DiagnosticConsumer { friend class SDiagsRenderer; friend class SDiagsMerger; struct SharedState; explicit SDiagsWriter(IntrusiveRefCntPtr<SharedState> State) : LangOpts(nullptr), OriginalInstance(false), MergeChildRecords(false), State(State) {} public: SDiagsWriter(StringRef File, DiagnosticOptions *Diags, bool MergeChildRecords) : LangOpts(nullptr), OriginalInstance(true), MergeChildRecords(MergeChildRecords), State(new SharedState(File, Diags)) { if (MergeChildRecords) RemoveOldDiagnostics(); EmitPreamble(); } ~SDiagsWriter() override {} void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override; void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override { LangOpts = &LO; } void finish() override; private: /// \brief Build a DiagnosticsEngine to emit diagnostics about the diagnostics DiagnosticsEngine *getMetaDiags(); /// \brief Remove old copies of the serialized diagnostics. This is necessary /// so that we can detect when subprocesses write diagnostics that we should /// merge into our own. void RemoveOldDiagnostics(); /// \brief Emit the preamble for the serialized diagnostics. void EmitPreamble(); /// \brief Emit the BLOCKINFO block. void EmitBlockInfoBlock(); /// \brief Emit the META data block. void EmitMetaBlock(); /// \brief Start a DIAG block. void EnterDiagBlock(); /// \brief End a DIAG block. void ExitDiagBlock(); /// \brief Emit a DIAG record. void EmitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, const SourceManager *SM, DiagOrStoredDiag D); /// \brief Emit FIXIT and SOURCE_RANGE records for a diagnostic. void EmitCodeContext(SmallVectorImpl<CharSourceRange> &Ranges, ArrayRef<FixItHint> Hints, const SourceManager &SM); /// \brief Emit a record for a CharSourceRange. void EmitCharSourceRange(CharSourceRange R, const SourceManager &SM); /// \brief Emit the string information for the category. unsigned getEmitCategory(unsigned category = 0); /// \brief Emit the string information for diagnostic flags. unsigned getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel, unsigned DiagID = 0); unsigned getEmitDiagnosticFlag(StringRef DiagName); /// \brief Emit (lazily) the file string and retrieved the file identifier. unsigned getEmitFile(const char *Filename); /// \brief Add SourceLocation information the specified record. void AddLocToRecord(SourceLocation Loc, const SourceManager *SM, PresumedLoc PLoc, RecordDataImpl &Record, unsigned TokSize = 0); /// \brief Add SourceLocation information the specified record. void AddLocToRecord(SourceLocation Loc, RecordDataImpl &Record, const SourceManager *SM, unsigned TokSize = 0) { AddLocToRecord(Loc, SM, SM ? SM->getPresumedLoc(Loc) : PresumedLoc(), Record, TokSize); } /// \brief Add CharSourceRange information the specified record. void AddCharSourceRangeToRecord(CharSourceRange R, RecordDataImpl &Record, const SourceManager &SM); /// \brief Language options, which can differ from one clone of this client /// to another. const LangOptions *LangOpts; /// \brief Whether this is the original instance (rather than one of its /// clones), responsible for writing the file at the end. bool OriginalInstance; /// \brief Whether this instance should aggregate diagnostics that are /// generated from child processes. bool MergeChildRecords; /// \brief State that is shared among the various clones of this diagnostic /// consumer. struct SharedState : RefCountedBase<SharedState> { SharedState(StringRef File, DiagnosticOptions *Diags) : DiagOpts(Diags), Stream(Buffer), OutputFile(File.str()), EmittedAnyDiagBlocks(false) {} /// \brief Diagnostic options. IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; /// \brief The byte buffer for the serialized content. SmallString<1024> Buffer; /// \brief The BitStreamWriter for the serialized diagnostics. llvm::BitstreamWriter Stream; /// \brief The name of the diagnostics file. std::string OutputFile; /// \brief The set of constructed record abbreviations. AbbreviationMap Abbrevs; /// \brief A utility buffer for constructing record content. RecordData Record; /// \brief A text buffer for rendering diagnostic text. SmallString<256> diagBuf; /// \brief The collection of diagnostic categories used. llvm::DenseSet<unsigned> Categories; /// \brief The collection of files used. llvm::DenseMap<const char *, unsigned> Files; typedef llvm::DenseMap<const void *, std::pair<unsigned, StringRef> > DiagFlagsTy; /// \brief Map for uniquing strings. DiagFlagsTy DiagFlags; /// \brief Whether we have already started emission of any DIAG blocks. Once /// this becomes \c true, we never close a DIAG block until we know that we're /// starting another one or we're done. bool EmittedAnyDiagBlocks; /// \brief Engine for emitting diagnostics about the diagnostics. std::unique_ptr<DiagnosticsEngine> MetaDiagnostics; }; /// \brief State shared among the various clones of this diagnostic consumer. IntrusiveRefCntPtr<SharedState> State; }; } // end anonymous namespace namespace clang { namespace serialized_diags { std::unique_ptr<DiagnosticConsumer> create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords) { return llvm::make_unique<SDiagsWriter>(OutputFile, Diags, MergeChildRecords); } } // end namespace serialized_diags } // end namespace clang //===----------------------------------------------------------------------===// // Serialization methods. //===----------------------------------------------------------------------===// /// \brief Emits a block ID in the BLOCKINFO block. static void EmitBlockID(unsigned ID, const char *Name, llvm::BitstreamWriter &Stream, RecordDataImpl &Record) { Record.clear(); Record.push_back(ID); Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); // Emit the block name if present. if (!Name || Name[0] == 0) return; Record.clear(); while (*Name) Record.push_back(*Name++); Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); } /// \brief Emits a record ID in the BLOCKINFO block. static void EmitRecordID(unsigned ID, const char *Name, llvm::BitstreamWriter &Stream, RecordDataImpl &Record){ Record.clear(); Record.push_back(ID); while (*Name) Record.push_back(*Name++); Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); } void SDiagsWriter::AddLocToRecord(SourceLocation Loc, const SourceManager *SM, PresumedLoc PLoc, RecordDataImpl &Record, unsigned TokSize) { if (PLoc.isInvalid()) { // Emit a "sentinel" location. Record.push_back((unsigned)0); // File. Record.push_back((unsigned)0); // Line. Record.push_back((unsigned)0); // Column. Record.push_back((unsigned)0); // Offset. return; } Record.push_back(getEmitFile(PLoc.getFilename())); Record.push_back(PLoc.getLine()); Record.push_back(PLoc.getColumn()+TokSize); Record.push_back(SM->getFileOffset(Loc)); } void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range, RecordDataImpl &Record, const SourceManager &SM) { AddLocToRecord(Range.getBegin(), Record, &SM); unsigned TokSize = 0; if (Range.isTokenRange()) TokSize = Lexer::MeasureTokenLength(Range.getEnd(), SM, *LangOpts); AddLocToRecord(Range.getEnd(), Record, &SM, TokSize); } unsigned SDiagsWriter::getEmitFile(const char *FileName){ if (!FileName) return 0; unsigned &entry = State->Files[FileName]; if (entry) return entry; // Lazily generate the record for the file. entry = State->Files.size(); RecordData Record; Record.push_back(RECORD_FILENAME); Record.push_back(entry); Record.push_back(0); // For legacy. Record.push_back(0); // For legacy. StringRef Name(FileName); Record.push_back(Name.size()); State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_FILENAME), Record, Name); return entry; } void SDiagsWriter::EmitCharSourceRange(CharSourceRange R, const SourceManager &SM) { State->Record.clear(); State->Record.push_back(RECORD_SOURCE_RANGE); AddCharSourceRangeToRecord(R, State->Record, SM); State->Stream.EmitRecordWithAbbrev(State->Abbrevs.get(RECORD_SOURCE_RANGE), State->Record); } /// \brief Emits the preamble of the diagnostics file. void SDiagsWriter::EmitPreamble() { // Emit the file header. State->Stream.Emit((unsigned)'D', 8); State->Stream.Emit((unsigned)'I', 8); State->Stream.Emit((unsigned)'A', 8); State->Stream.Emit((unsigned)'G', 8); EmitBlockInfoBlock(); EmitMetaBlock(); } static void AddSourceLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) { using namespace llvm; Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // File ID. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Line. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Column. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Offset; } static void AddRangeLocationAbbrev(llvm::BitCodeAbbrev *Abbrev) { AddSourceLocationAbbrev(Abbrev); AddSourceLocationAbbrev(Abbrev); } void SDiagsWriter::EmitBlockInfoBlock() { State->Stream.EnterBlockInfoBlock(3); using namespace llvm; llvm::BitstreamWriter &Stream = State->Stream; RecordData &Record = State->Record; AbbreviationMap &Abbrevs = State->Abbrevs; // ==---------------------------------------------------------------------==// // The subsequent records and Abbrevs are for the "Meta" block. // ==---------------------------------------------------------------------==// EmitBlockID(BLOCK_META, "Meta", Stream, Record); EmitRecordID(RECORD_VERSION, "Version", Stream, Record); BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); Abbrev->Add(BitCodeAbbrevOp(RECORD_VERSION)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); Abbrevs.set(RECORD_VERSION, Stream.EmitBlockInfoAbbrev(BLOCK_META, Abbrev)); // ==---------------------------------------------------------------------==// // The subsequent records and Abbrevs are for the "Diagnostic" block. // ==---------------------------------------------------------------------==// EmitBlockID(BLOCK_DIAG, "Diag", Stream, Record); EmitRecordID(RECORD_DIAG, "DiagInfo", Stream, Record); EmitRecordID(RECORD_SOURCE_RANGE, "SrcRange", Stream, Record); EmitRecordID(RECORD_CATEGORY, "CatName", Stream, Record); EmitRecordID(RECORD_DIAG_FLAG, "DiagFlag", Stream, Record); EmitRecordID(RECORD_FILENAME, "FileName", Stream, Record); EmitRecordID(RECORD_FIXIT, "FixIt", Stream, Record); // Emit abbreviation for RECORD_DIAG. Abbrev = new BitCodeAbbrev(); Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Diag level. AddSourceLocationAbbrev(Abbrev); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Category. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped Diag ID. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Diagnostc text. Abbrevs.set(RECORD_DIAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); // Emit abbrevation for RECORD_CATEGORY. Abbrev = new BitCodeAbbrev(); Abbrev->Add(BitCodeAbbrevOp(RECORD_CATEGORY)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Category ID. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // Text size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Category text. Abbrevs.set(RECORD_CATEGORY, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); // Emit abbrevation for RECORD_SOURCE_RANGE. Abbrev = new BitCodeAbbrev(); Abbrev->Add(BitCodeAbbrevOp(RECORD_SOURCE_RANGE)); AddRangeLocationAbbrev(Abbrev); Abbrevs.set(RECORD_SOURCE_RANGE, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); // Emit the abbreviation for RECORD_DIAG_FLAG. Abbrev = new BitCodeAbbrev(); Abbrev->Add(BitCodeAbbrevOp(RECORD_DIAG_FLAG)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped Diag ID. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Flag name text. Abbrevs.set(RECORD_DIAG_FLAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); // Emit the abbreviation for RECORD_FILENAME. Abbrev = new BitCodeAbbrev(); Abbrev->Add(BitCodeAbbrevOp(RECORD_FILENAME)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); // Mapped file ID. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // Modifcation time. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name text. Abbrevs.set(RECORD_FILENAME, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); // Emit the abbreviation for RECORD_FIXIT. Abbrev = new BitCodeAbbrev(); Abbrev->Add(BitCodeAbbrevOp(RECORD_FIXIT)); AddRangeLocationAbbrev(Abbrev); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Text size. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // FixIt text. Abbrevs.set(RECORD_FIXIT, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev)); Stream.ExitBlock(); } void SDiagsWriter::EmitMetaBlock() { llvm::BitstreamWriter &Stream = State->Stream; RecordData &Record = State->Record; AbbreviationMap &Abbrevs = State->Abbrevs; Stream.EnterSubblock(BLOCK_META, 3); Record.clear(); Record.push_back(RECORD_VERSION); Record.push_back(VersionNumber); Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record); Stream.ExitBlock(); } unsigned SDiagsWriter::getEmitCategory(unsigned int category) { if (!State->Categories.insert(category).second) return category; // We use a local version of 'Record' so that we can be generating // another record when we lazily generate one for the category entry. RecordData Record; Record.push_back(RECORD_CATEGORY); Record.push_back(category); StringRef catName = DiagnosticIDs::getCategoryNameFromID(category); Record.push_back(catName.size()); State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY), Record, catName); return category; } unsigned SDiagsWriter::getEmitDiagnosticFlag(DiagnosticsEngine::Level DiagLevel, unsigned DiagID) { if (DiagLevel == DiagnosticsEngine::Note) return 0; // No flag for notes. StringRef FlagName = DiagnosticIDs::getWarningOptionForDiag(DiagID); return getEmitDiagnosticFlag(FlagName); } unsigned SDiagsWriter::getEmitDiagnosticFlag(StringRef FlagName) { if (FlagName.empty()) return 0; // Here we assume that FlagName points to static data whose pointer // value is fixed. This allows us to unique by diagnostic groups. const void *data = FlagName.data(); std::pair<unsigned, StringRef> &entry = State->DiagFlags[data]; if (entry.first == 0) { entry.first = State->DiagFlags.size(); entry.second = FlagName; // Lazily emit the string in a separate record. RecordData Record; Record.push_back(RECORD_DIAG_FLAG); Record.push_back(entry.first); Record.push_back(FlagName.size()); State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_DIAG_FLAG), Record, FlagName); } return entry.first; } void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) { // Enter the block for a non-note diagnostic immediately, rather than waiting // for beginDiagnostic, in case associated notes are emitted before we get // there. if (DiagLevel != DiagnosticsEngine::Note) { if (State->EmittedAnyDiagBlocks) ExitDiagBlock(); EnterDiagBlock(); State->EmittedAnyDiagBlocks = true; } // Compute the diagnostic text. State->diagBuf.clear(); Info.FormatDiagnostic(State->diagBuf); if (Info.getLocation().isInvalid()) { // Special-case diagnostics with no location. We may not have entered a // source file in this case, so we can't use the normal DiagnosticsRenderer // machinery. // Make sure we bracket all notes as "sub-diagnostics". This matches // the behavior in SDiagsRenderer::emitDiagnostic(). if (DiagLevel == DiagnosticsEngine::Note) EnterDiagBlock(); EmitDiagnosticMessage(SourceLocation(), PresumedLoc(), DiagLevel, State->diagBuf, nullptr, &Info); if (DiagLevel == DiagnosticsEngine::Note) ExitDiagBlock(); return; } assert(Info.hasSourceManager() && LangOpts && "Unexpected diagnostic with valid location outside of a source file"); SDiagsRenderer Renderer(*this, *LangOpts, &*State->DiagOpts); Renderer.emitDiagnostic(Info.getLocation(), DiagLevel, State->diagBuf, Info.getRanges(), Info.getFixItHints(), &Info.getSourceManager(), &Info); } static serialized_diags::Level getStableLevel(DiagnosticsEngine::Level Level) { switch (Level) { #define CASE(X) case DiagnosticsEngine::X: return serialized_diags::X; CASE(Ignored) CASE(Note) CASE(Remark) CASE(Warning) CASE(Error) CASE(Fatal) #undef CASE } llvm_unreachable("invalid diagnostic level"); } void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, const SourceManager *SM, DiagOrStoredDiag D) { llvm::BitstreamWriter &Stream = State->Stream; RecordData &Record = State->Record; AbbreviationMap &Abbrevs = State->Abbrevs; // Emit the RECORD_DIAG record. Record.clear(); Record.push_back(RECORD_DIAG); Record.push_back(getStableLevel(Level)); AddLocToRecord(Loc, SM, PLoc, Record); if (const Diagnostic *Info = D.dyn_cast<const Diagnostic*>()) { // Emit the category string lazily and get the category ID. unsigned DiagID = DiagnosticIDs::getCategoryNumberForDiag(Info->getID()); Record.push_back(getEmitCategory(DiagID)); // Emit the diagnostic flag string lazily and get the mapped ID. Record.push_back(getEmitDiagnosticFlag(Level, Info->getID())); } else { Record.push_back(getEmitCategory()); Record.push_back(getEmitDiagnosticFlag(Level)); } Record.push_back(Message.size()); Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG), Record, Message); } void SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<clang::CharSourceRange> Ranges, const SourceManager *SM, DiagOrStoredDiag D) { Writer.EmitDiagnosticMessage(Loc, PLoc, Level, Message, SM, D); } void SDiagsWriter::EnterDiagBlock() { State->Stream.EnterSubblock(BLOCK_DIAG, 4); } void SDiagsWriter::ExitDiagBlock() { State->Stream.ExitBlock(); } void SDiagsRenderer::beginDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level) { if (Level == DiagnosticsEngine::Note) Writer.EnterDiagBlock(); } void SDiagsRenderer::endDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level) { // Only end note diagnostics here, because we can't be sure when we've seen // the last note associated with a non-note diagnostic. if (Level == DiagnosticsEngine::Note) Writer.ExitDiagBlock(); } void SDiagsWriter::EmitCodeContext(SmallVectorImpl<CharSourceRange> &Ranges, ArrayRef<FixItHint> Hints, const SourceManager &SM) { llvm::BitstreamWriter &Stream = State->Stream; RecordData &Record = State->Record; AbbreviationMap &Abbrevs = State->Abbrevs; // Emit Source Ranges. for (ArrayRef<CharSourceRange>::iterator I = Ranges.begin(), E = Ranges.end(); I != E; ++I) if (I->isValid()) EmitCharSourceRange(*I, SM); // Emit FixIts. for (ArrayRef<FixItHint>::iterator I = Hints.begin(), E = Hints.end(); I != E; ++I) { const FixItHint &Fix = *I; if (Fix.isNull()) continue; Record.clear(); Record.push_back(RECORD_FIXIT); AddCharSourceRangeToRecord(Fix.RemoveRange, Record, SM); Record.push_back(Fix.CodeToInsert.size()); Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_FIXIT), Record, Fix.CodeToInsert); } } void SDiagsRenderer::emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level, SmallVectorImpl<CharSourceRange> &Ranges, ArrayRef<FixItHint> Hints, const SourceManager &SM) { Writer.EmitCodeContext(Ranges, Hints, SM); } void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message, const SourceManager *SM) { Writer.EnterDiagBlock(); PresumedLoc PLoc = SM ? SM->getPresumedLoc(Loc) : PresumedLoc(); Writer.EmitDiagnosticMessage(Loc, PLoc, DiagnosticsEngine::Note, Message, SM, DiagOrStoredDiag()); Writer.ExitDiagBlock(); } DiagnosticsEngine *SDiagsWriter::getMetaDiags() { // FIXME: It's slightly absurd to create a new diagnostics engine here, but // the other options that are available today are worse: // // 1. Teach DiagnosticsConsumers to emit diagnostics to the engine they are a // part of. The DiagnosticsEngine would need to know not to send // diagnostics back to the consumer that failed. This would require us to // rework ChainedDiagnosticsConsumer and teach the engine about multiple // consumers, which is difficult today because most APIs interface with // consumers rather than the engine itself. // // 2. Pass a DiagnosticsEngine to SDiagsWriter on creation - this would need // to be distinct from the engine the writer was being added to and would // normally not be used. if (!State->MetaDiagnostics) { IntrusiveRefCntPtr<DiagnosticIDs> IDs(new DiagnosticIDs()); auto Client = new TextDiagnosticPrinter(llvm::errs(), State->DiagOpts.get()); State->MetaDiagnostics = llvm::make_unique<DiagnosticsEngine>( IDs, State->DiagOpts.get(), Client); } return State->MetaDiagnostics.get(); } void SDiagsWriter::RemoveOldDiagnostics() { if (!llvm::sys::fs::remove(State->OutputFile)) return; getMetaDiags()->Report(diag::warn_fe_serialized_diag_merge_failure); // Disable merging child records, as whatever is in this file may be // misleading. MergeChildRecords = false; } void SDiagsWriter::finish() { // The original instance is responsible for writing the file. if (!OriginalInstance) return; // Finish off any diagnostic we were in the process of emitting. if (State->EmittedAnyDiagBlocks) ExitDiagBlock(); if (MergeChildRecords) { if (!State->EmittedAnyDiagBlocks) // We have no diagnostics of our own, so we can just leave the child // process' output alone return; if (llvm::sys::fs::exists(State->OutputFile)) if (SDiagsMerger(*this).mergeRecordsFromFile(State->OutputFile.c_str())) getMetaDiags()->Report(diag::warn_fe_serialized_diag_merge_failure); } std::error_code EC; auto OS = llvm::make_unique<llvm::raw_fd_ostream>(State->OutputFile.c_str(), EC, llvm::sys::fs::F_None); if (EC) { getMetaDiags()->Report(diag::warn_fe_serialized_diag_failure) << State->OutputFile << EC.message(); return; } // Write the generated bitstream to "Out". OS->write((char *)&State->Buffer.front(), State->Buffer.size()); OS->flush(); } std::error_code SDiagsMerger::visitStartOfDiagnostic() { Writer.EnterDiagBlock(); return std::error_code(); } std::error_code SDiagsMerger::visitEndOfDiagnostic() { Writer.ExitDiagBlock(); return std::error_code(); } std::error_code SDiagsMerger::visitSourceRangeRecord(const serialized_diags::Location &Start, const serialized_diags::Location &End) { RecordData Record; Record.push_back(RECORD_SOURCE_RANGE); Record.push_back(FileLookup[Start.FileID]); Record.push_back(Start.Line); Record.push_back(Start.Col); Record.push_back(Start.Offset); Record.push_back(FileLookup[End.FileID]); Record.push_back(End.Line); Record.push_back(End.Col); Record.push_back(End.Offset); Writer.State->Stream.EmitRecordWithAbbrev( Writer.State->Abbrevs.get(RECORD_SOURCE_RANGE), Record); return std::error_code(); } std::error_code SDiagsMerger::visitDiagnosticRecord( unsigned Severity, const serialized_diags::Location &Location, unsigned Category, unsigned Flag, StringRef Message) { RecordData MergedRecord; MergedRecord.push_back(RECORD_DIAG); MergedRecord.push_back(Severity); MergedRecord.push_back(FileLookup[Location.FileID]); MergedRecord.push_back(Location.Line); MergedRecord.push_back(Location.Col); MergedRecord.push_back(Location.Offset); MergedRecord.push_back(CategoryLookup[Category]); MergedRecord.push_back(Flag ? DiagFlagLookup[Flag] : 0); MergedRecord.push_back(Message.size()); Writer.State->Stream.EmitRecordWithBlob( Writer.State->Abbrevs.get(RECORD_DIAG), MergedRecord, Message); return std::error_code(); } std::error_code SDiagsMerger::visitFixitRecord(const serialized_diags::Location &Start, const serialized_diags::Location &End, StringRef Text) { RecordData Record; Record.push_back(RECORD_FIXIT); Record.push_back(FileLookup[Start.FileID]); Record.push_back(Start.Line); Record.push_back(Start.Col); Record.push_back(Start.Offset); Record.push_back(FileLookup[End.FileID]); Record.push_back(End.Line); Record.push_back(End.Col); Record.push_back(End.Offset); Record.push_back(Text.size()); Writer.State->Stream.EmitRecordWithBlob( Writer.State->Abbrevs.get(RECORD_FIXIT), Record, Text); return std::error_code(); } std::error_code SDiagsMerger::visitFilenameRecord(unsigned ID, unsigned Size, unsigned Timestamp, StringRef Name) { FileLookup[ID] = Writer.getEmitFile(Name.str().c_str()); return std::error_code(); } std::error_code SDiagsMerger::visitCategoryRecord(unsigned ID, StringRef Name) { CategoryLookup[ID] = Writer.getEmitCategory(ID); return std::error_code(); } std::error_code SDiagsMerger::visitDiagFlagRecord(unsigned ID, StringRef Name) { DiagFlagLookup[ID] = Writer.getEmitDiagnosticFlag(Name); return std::error_code(); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/FrontendAction.cpp
//===--- FrontendAction.cpp -----------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/FrontendAction.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclGroup.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/Frontend/LayoutOverrideSource.h" #include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "clang/Parse/ParseAST.h" #include "clang/Serialization/ASTDeserializationListener.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/GlobalModuleIndex.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include <system_error> using namespace clang; template class llvm::Registry<clang::PluginASTAction>; #if 0 // HLSL Change Starts - no support for AST serialization namespace { class DelegatingDeserializationListener : public ASTDeserializationListener { ASTDeserializationListener *Previous; bool DeletePrevious; public: explicit DelegatingDeserializationListener( ASTDeserializationListener *Previous, bool DeletePrevious) : Previous(Previous), DeletePrevious(DeletePrevious) {} ~DelegatingDeserializationListener() override { if (DeletePrevious) delete Previous; } void ReaderInitialized(ASTReader *Reader) override { if (Previous) Previous->ReaderInitialized(Reader); } void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II) override { if (Previous) Previous->IdentifierRead(ID, II); } void TypeRead(serialization::TypeIdx Idx, QualType T) override { if (Previous) Previous->TypeRead(Idx, T); } void DeclRead(serialization::DeclID ID, const Decl *D) override { if (Previous) Previous->DeclRead(ID, D); } void SelectorRead(serialization::SelectorID ID, Selector Sel) override { if (Previous) Previous->SelectorRead(ID, Sel); } void MacroDefinitionRead(serialization::PreprocessedEntityID PPID, MacroDefinitionRecord *MD) override { if (Previous) Previous->MacroDefinitionRead(PPID, MD); } }; /// \brief Dumps deserialized declarations. class DeserializedDeclsDumper : public DelegatingDeserializationListener { public: explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous, bool DeletePrevious) : DelegatingDeserializationListener(Previous, DeletePrevious) {} void DeclRead(serialization::DeclID ID, const Decl *D) override { llvm::outs() << "PCH DECL: " << D->getDeclKindName(); if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) llvm::outs() << " - " << *ND; llvm::outs() << "\n"; DelegatingDeserializationListener::DeclRead(ID, D); } }; /// \brief Checks deserialized declarations and emits error if a name /// matches one given in command-line using -error-on-deserialized-decl. class DeserializedDeclsChecker : public DelegatingDeserializationListener { ASTContext &Ctx; std::set<std::string> NamesToCheck; public: DeserializedDeclsChecker(ASTContext &Ctx, const std::set<std::string> &NamesToCheck, ASTDeserializationListener *Previous, bool DeletePrevious) : DelegatingDeserializationListener(Previous, DeletePrevious), Ctx(Ctx), NamesToCheck(NamesToCheck) {} void DeclRead(serialization::DeclID ID, const Decl *D) override { if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) { unsigned DiagID = Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0 was deserialized"); Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID) << ND->getNameAsString(); } DelegatingDeserializationListener::DeclRead(ID, D); } }; } // end anonymous namespace #endif // HLSL Change Starts - no support for AST serialization FrontendAction::FrontendAction() : Instance(nullptr) {} FrontendAction::~FrontendAction() {} void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, std::unique_ptr<ASTUnit> AST) { this->CurrentInput = CurrentInput; CurrentASTUnit = std::move(AST); } std::unique_ptr<ASTConsumer> FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, StringRef InFile) { std::unique_ptr<ASTConsumer> Consumer = CreateASTConsumer(CI, InFile); if (!Consumer) return nullptr; if (CI.getFrontendOpts().AddPluginActions.size() == 0) return Consumer; // Make sure the non-plugin consumer is first, so that plugins can't // modifiy the AST. std::vector<std::unique_ptr<ASTConsumer>> Consumers; Consumers.push_back(std::move(Consumer)); for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); i != e; ++i) { // This is O(|plugins| * |add_plugins|), but since both numbers are // way below 50 in practice, that's ok. for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end(); it != ie; ++it) { if (it->getName() != CI.getFrontendOpts().AddPluginActions[i]) continue; std::unique_ptr<PluginASTAction> P = it->instantiate(); if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i])) Consumers.push_back(P->CreateASTConsumer(CI, InFile)); } } return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); } bool FrontendAction::BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input) { assert(!Instance && "Already processing a source file!"); assert(!Input.isEmpty() && "Unexpected empty filename!"); setCurrentInput(Input); setCompilerInstance(&CI); StringRef InputFile = Input.getFile(); bool HasBegunSourceFile = false; if (!BeginInvocation(CI)) goto failure; // AST files follow a very different path, since they share objects via the // AST unit. if (Input.getKind() == IK_AST) { #if 1 // HLSL Change Starts - no support for AST serialization goto failure; #else assert(!usesPreprocessorOnly() && "Attempt to pass AST file to preprocessor only action!"); assert(hasASTFileSupport() && "This action does not have AST file support!"); IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics()); std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(InputFile, CI.getPCHContainerReader(), Diags, CI.getFileSystemOpts()); if (!AST) goto failure; // Inform the diagnostic client we are processing a source file. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr); HasBegunSourceFile = true; // Set the shared objects, these are reset when we finish processing the // file, otherwise the CompilerInstance will happily destroy them. CI.setFileManager(&AST->getFileManager()); CI.setSourceManager(&AST->getSourceManager()); CI.setPreprocessor(&AST->getPreprocessor()); CI.setASTContext(&AST->getASTContext()); setCurrentInput(Input, std::move(AST)); // Initialize the action. if (!BeginSourceFileAction(CI, InputFile)) goto failure; // Create the AST consumer. CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile)); if (!CI.hasASTConsumer()) goto failure; return true; #endif // HLSL Change Ends - no support for AST serialization } if (!CI.hasVirtualFileSystem()) { if (IntrusiveRefCntPtr<vfs::FileSystem> VFS = createVFSFromCompilerInvocation(CI.getInvocation(), CI.getDiagnostics())) CI.setVirtualFileSystem(VFS); else goto failure; } // Set up the file and source managers, if needed. if (!CI.hasFileManager()) CI.createFileManager(); if (!CI.hasSourceManager()) CI.createSourceManager(CI.getFileManager()); // IR files bypass the rest of initialization. if (Input.getKind() == IK_LLVM_IR) { assert(hasIRSupport() && "This action does not have IR file support!"); // Inform the diagnostic client we are processing a source file. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr); HasBegunSourceFile = true; // Initialize the action. if (!BeginSourceFileAction(CI, InputFile)) goto failure; // Initialize the main file entry. if (!CI.InitializeSourceManager(CurrentInput)) goto failure; return true; } #if 0 // HLSL Change Starts - no support for AST serialization // If the implicit PCH include is actually a directory, rather than // a single file, search for a suitable PCH file in that directory. if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { FileManager &FileMgr = CI.getFileManager(); PreprocessorOptions &PPOpts = CI.getPreprocessorOpts(); StringRef PCHInclude = PPOpts.ImplicitPCHInclude; std::string SpecificModuleCachePath = CI.getSpecificModuleCachePath(); if (const DirectoryEntry *PCHDir = FileMgr.getDirectory(PCHInclude)) { std::error_code EC; SmallString<128> DirNative; llvm::sys::path::native(PCHDir->getName(), DirNative); bool Found = false; for (llvm::sys::fs::directory_iterator Dir(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { // Check whether this is an acceptable AST file. if (ASTReader::isAcceptableASTFile( Dir->path(), FileMgr, CI.getPCHContainerReader(), CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(), SpecificModuleCachePath)) { PPOpts.ImplicitPCHInclude = Dir->path(); Found = true; break; } } if (!Found) { CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude; return true; } } } #endif // HLSL Change Ends - no support for AST serialization // Set up the preprocessor if needed. When parsing model files the // preprocessor of the original source is reused. if (!isModelParsingAction()) CI.createPreprocessor(getTranslationUnitKind()); // Inform the diagnostic client we are processing a source file. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), &CI.getPreprocessor()); HasBegunSourceFile = true; // Initialize the action. if (!BeginSourceFileAction(CI, InputFile)) goto failure; // Initialize the main file entry. It is important that this occurs after // BeginSourceFileAction, which may change CurrentInput during module builds. if (!CI.InitializeSourceManager(CurrentInput)) goto failure; // Create the AST context and consumer unless this is a preprocessor only // action. if (!usesPreprocessorOnly()) { // Parsing a model file should reuse the existing ASTContext. if (!isModelParsingAction()) CI.createASTContext(); std::unique_ptr<ASTConsumer> Consumer = CreateWrappedASTConsumer(CI, InputFile); if (!Consumer) goto failure; // FIXME: should not overwrite ASTMutationListener when parsing model files? if (!isModelParsingAction()) CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener()); #if 0 // HLSL Change Starts - no support for AST serialization if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) { // Convert headers to PCH and chain them. IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader; source = createChainedIncludesSource(CI, FinalReader); if (!source) goto failure; CI.setModuleManager(static_cast<ASTReader *>(FinalReader.get())); CI.getASTContext().setExternalSource(source); } else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { // Use PCH. assert(hasPCHSupport() && "This action does not have PCH support!"); ASTDeserializationListener *DeserialListener = Consumer->GetASTDeserializationListener(); bool DeleteDeserialListener = false; if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls) { DeserialListener = new DeserializedDeclsDumper(DeserialListener, DeleteDeserialListener); DeleteDeserialListener = true; } if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty()) { DeserialListener = new DeserializedDeclsChecker( CI.getASTContext(), CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn, DeserialListener, DeleteDeserialListener); DeleteDeserialListener = true; } CI.createPCHExternalASTSource( CI.getPreprocessorOpts().ImplicitPCHInclude, CI.getPreprocessorOpts().DisablePCHValidation, CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, DeserialListener, DeleteDeserialListener); if (!CI.getASTContext().getExternalSource()) goto failure; } #endif // HLSL Change Ends - no support for AST serialization CI.setASTConsumer(std::move(Consumer)); if (!CI.hasASTConsumer()) goto failure; } // Initialize built-in info as long as we aren't using an external AST // source. if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) { Preprocessor &PP = CI.getPreprocessor(); // If modules are enabled, create the module manager before creating // any builtins, so that all declarations know that they might be // extended by an external source. if (CI.getLangOpts().Modules) CI.createModuleManager(); PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(), PP.getLangOpts()); } else { // FIXME: If this is a problem, recover from it by creating a multiplex // source. #if 0 // HLSL Change Starts - no support for AST serialization assert((!CI.getLangOpts().Modules || CI.getModuleManager()) && "modules enabled but created an external source that " "doesn't support modules"); #endif // HLSL Change End - no support for AST serialization } // If we were asked to load any module map files, do so now. for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) { if (auto *File = CI.getFileManager().getFile(Filename)) CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile( File, /*IsSystem*/false); else CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename; } // If we were asked to load any module files, do so now. for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles) if (!CI.loadModuleFile(ModuleFile)) goto failure; #if 0 // HLSL Change Starts - removes support for overriding layout source from external file specification // If there is a layout overrides file, attach an external AST source that // provides the layouts from that file. if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() && CI.hasASTContext() && !CI.getASTContext().getExternalSource()) { IntrusiveRefCntPtr<ExternalASTSource> Override(new LayoutOverrideSource( CI.getFrontendOpts().OverrideRecordLayoutsFile)); CI.getASTContext().setExternalSource(Override); } #endif return true; // If we failed, reset state since the client will not end up calling the // matching EndSourceFile(). failure: if (isCurrentFileAST()) { CI.setASTContext(nullptr); CI.setPreprocessor(nullptr); CI.setSourceManager(nullptr); CI.setFileManager(nullptr); } if (HasBegunSourceFile) CI.getDiagnosticClient().EndSourceFile(); CI.clearOutputFiles(/*EraseFiles=*/true); setCurrentInput(FrontendInputFile()); setCompilerInstance(nullptr); return false; } bool FrontendAction::Execute() { CompilerInstance &CI = getCompilerInstance(); if (CI.hasFrontendTimer()) { llvm::TimeRegion Timer(CI.getFrontendTimer()); ExecuteAction(); } else ExecuteAction(); #if 0 // HLSL Change Starts - no support for AST serialization // If we are supposed to rebuild the global module index, do so now unless // there were any module-build failures. if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() && CI.hasPreprocessor()) { GlobalModuleIndex::writeIndex( CI.getFileManager(), CI.getPCHContainerReader(), CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath()); } #endif // HLSL Change Ends - no support for AST serialization return true; } void FrontendAction::EndSourceFile() { CompilerInstance &CI = getCompilerInstance(); // Inform the diagnostic client we are done with this source file. CI.getDiagnosticClient().EndSourceFile(); // Inform the preprocessor we are done. if (CI.hasPreprocessor()) CI.getPreprocessor().EndSourceFile(); // Finalize the action. EndSourceFileAction(); // Sema references the ast consumer, so reset sema first. // // FIXME: There is more per-file stuff we could just drop here? bool DisableFree = CI.getFrontendOpts().DisableFree; if (DisableFree) { CI.resetAndLeakSema(); CI.resetAndLeakASTContext(); BuryPointer(CI.takeASTConsumer().get()); } else { CI.setSema(nullptr); CI.setASTContext(nullptr); CI.setASTConsumer(nullptr); } if (CI.getFrontendOpts().ShowStats) { llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n"; CI.getPreprocessor().PrintStats(); CI.getPreprocessor().getIdentifierTable().PrintStats(); CI.getPreprocessor().getHeaderSearchInfo().PrintStats(); CI.getSourceManager().PrintStats(); llvm::errs() << "\n"; } // Cleanup the output streams, and erase the output files if instructed by the // FrontendAction. CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles()); if (isCurrentFileAST()) { if (DisableFree) { CI.resetAndLeakPreprocessor(); CI.resetAndLeakSourceManager(); CI.resetAndLeakFileManager(); } else { CI.setPreprocessor(nullptr); CI.setSourceManager(nullptr); CI.setFileManager(nullptr); } } setCompilerInstance(nullptr); setCurrentInput(FrontendInputFile()); } bool FrontendAction::shouldEraseOutputFiles() { return getCompilerInstance().getDiagnostics().hasErrorOccurred(); } //===----------------------------------------------------------------------===// // Utility Actions //===----------------------------------------------------------------------===// void ASTFrontendAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); if (!CI.hasPreprocessor()) return; // FIXME: Move the truncation aspect of this into Sema, we delayed this till // here so the source manager would be initialized. if (hasCodeCompletionSupport() && !CI.getFrontendOpts().CodeCompletionAt.FileName.empty()) CI.createCodeCompletionConsumer(); // Use a code completion consumer? CodeCompleteConsumer *CompletionConsumer = nullptr; if (CI.hasCodeCompletionConsumer()) CompletionConsumer = &CI.getCodeCompletionConsumer(); if (!CI.hasSema()) CI.createSema(getTranslationUnitKind(), CompletionConsumer); ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats, CI.getFrontendOpts().SkipFunctionBodies); } void PluginASTAction::anchor() { } std::unique_ptr<ASTConsumer> PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); } std::unique_ptr<ASTConsumer> WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return WrappedAction->CreateASTConsumer(CI, InFile); } bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) { return WrappedAction->BeginInvocation(CI); } bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) { WrappedAction->setCurrentInput(getCurrentInput()); WrappedAction->setCompilerInstance(&CI); return WrappedAction->BeginSourceFileAction(CI, Filename); } void WrapperFrontendAction::ExecuteAction() { WrappedAction->ExecuteAction(); } void WrapperFrontendAction::EndSourceFileAction() { WrappedAction->EndSourceFileAction(); } bool WrapperFrontendAction::usesPreprocessorOnly() const { return WrappedAction->usesPreprocessorOnly(); } TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() { return WrappedAction->getTranslationUnitKind(); } bool WrapperFrontendAction::hasPCHSupport() const { return WrappedAction->hasPCHSupport(); } bool WrapperFrontendAction::hasASTFileSupport() const { return WrappedAction->hasASTFileSupport(); } bool WrapperFrontendAction::hasIRSupport() const { return WrappedAction->hasIRSupport(); } bool WrapperFrontendAction::hasCodeCompletionSupport() const { return WrappedAction->hasCodeCompletionSupport(); } WrapperFrontendAction::WrapperFrontendAction(FrontendAction *WrappedAction) : WrappedAction(WrappedAction) {}
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/DependencyFile.cpp
//===--- DependencyFile.cpp - Generate dependency file --------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This code generates dependency files. // //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/DependencyOutputOptions.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" using namespace clang; namespace { struct DepCollectorPPCallbacks : public PPCallbacks { DependencyCollector &DepCollector; SourceManager &SM; DepCollectorPPCallbacks(DependencyCollector &L, SourceManager &SM) : DepCollector(L), SM(SM) { } void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override { if (Reason != PPCallbacks::EnterFile) return; // Dependency generation really does want to go all the way to the // file entry for a source location to find out what is depended on. // We do not want #line markers to affect dependency generation! const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(SM.getExpansionLoc(Loc))); if (!FE) return; StringRef Filename = FE->getName(); // Remove leading "./" (or ".//" or "././" etc.) while (Filename.size() > 2 && Filename[0] == '.' && llvm::sys::path::is_separator(Filename[1])) { Filename = Filename.substr(1); while (llvm::sys::path::is_separator(Filename[0])) Filename = Filename.substr(1); } DepCollector.maybeAddDependency(Filename, /*FromModule*/false, FileType != SrcMgr::C_User, /*IsModuleFile*/false, /*IsMissing*/false); } void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) override { if (!File) DepCollector.maybeAddDependency(FileName, /*FromModule*/false, /*IsSystem*/false, /*IsModuleFile*/false, /*IsMissing*/true); // Files that actually exist are handled by FileChanged. } void EndOfMainFile() override { DepCollector.finishedMainFile(); } }; #if 0 // HLSL Change Starts - no support for AST serialization struct DepCollectorASTListener : public ASTReaderListener { DependencyCollector &DepCollector; DepCollectorASTListener(DependencyCollector &L) : DepCollector(L) { } bool needsInputFileVisitation() override { return true; } bool needsSystemInputFileVisitation() override { return DepCollector.needSystemDependencies(); } void visitModuleFile(StringRef Filename) override { DepCollector.maybeAddDependency(Filename, /*FromModule*/true, /*IsSystem*/false, /*IsModuleFile*/true, /*IsMissing*/false); } bool visitInputFile(StringRef Filename, bool IsSystem, bool IsOverridden) override { if (IsOverridden) return true; DepCollector.maybeAddDependency(Filename, /*FromModule*/true, IsSystem, /*IsModuleFile*/false, /*IsMissing*/false); return true; } }; #endif // HLSL Change Ends - no support for AST serialization } // end anonymous namespace void DependencyCollector::maybeAddDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing) { if (Seen.insert(Filename).second && sawDependency(Filename, FromModule, IsSystem, IsModuleFile, IsMissing)) Dependencies.push_back(Filename); } static bool isSpecialFilename(StringRef Filename) { return llvm::StringSwitch<bool>(Filename) .Case("<built-in>", true) .Case("<stdin>", true) .Default(false); } bool DependencyCollector::sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing) { return !isSpecialFilename(Filename) && (needSystemDependencies() || !IsSystem); } DependencyCollector::~DependencyCollector() { } void DependencyCollector::attachToPreprocessor(Preprocessor &PP) { PP.addPPCallbacks( llvm::make_unique<DepCollectorPPCallbacks>(*this, PP.getSourceManager())); } #if 0 // HLSL Change Starts - no support for AST serialization void DependencyCollector::attachToASTReader(ASTReader &R) { R.addListener(llvm::make_unique<DepCollectorASTListener>(*this)); } #endif // HLSL Change Ends - no support for AST serialization namespace { /// Private implementation for DependencyFileGenerator class DFGImpl : public PPCallbacks { std::vector<std::string> Files; llvm::StringSet<> FilesSet; const Preprocessor *PP; std::string OutputFile; std::vector<std::string> Targets; bool IncludeSystemHeaders; bool PhonyTarget; bool AddMissingHeaderDeps; bool SeenMissingHeader; bool IncludeModuleFiles; DependencyOutputFormat OutputFormat; private: bool FileMatchesDepCriteria(const char *Filename, SrcMgr::CharacteristicKind FileType); void OutputDependencyFile(); public: DFGImpl(const Preprocessor *_PP, const DependencyOutputOptions &Opts) : PP(_PP), OutputFile(Opts.OutputFile), Targets(Opts.Targets), IncludeSystemHeaders(Opts.IncludeSystemHeaders), PhonyTarget(Opts.UsePhonyTargets), AddMissingHeaderDeps(Opts.AddMissingHeaderDeps), SeenMissingHeader(false), IncludeModuleFiles(Opts.IncludeModuleFiles), OutputFormat(Opts.OutputFormat) {} void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override; void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) override; void EndOfMainFile() override { OutputDependencyFile(); } void AddFilename(StringRef Filename); bool includeSystemHeaders() const { return IncludeSystemHeaders; } bool includeModuleFiles() const { return IncludeModuleFiles; } }; #if 0 // HLSL Change Starts - no support for AST serialization class DFGASTReaderListener : public ASTReaderListener { DFGImpl &Parent; public: DFGASTReaderListener(DFGImpl &Parent) : Parent(Parent) { } bool needsInputFileVisitation() override { return true; } bool needsSystemInputFileVisitation() override { return Parent.includeSystemHeaders(); } void visitModuleFile(StringRef Filename) override; bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden) override; }; #endif // HLSL Change Ends - no support for AST serialization } DependencyFileGenerator::DependencyFileGenerator(void *Impl) : Impl(Impl) { } DependencyFileGenerator *DependencyFileGenerator::CreateAndAttachToPreprocessor( clang::Preprocessor &PP, const clang::DependencyOutputOptions &Opts) { if (Opts.Targets.empty()) { PP.getDiagnostics().Report(diag::err_fe_dependency_file_requires_MT); return nullptr; } // Disable the "file not found" diagnostic if the -MG option was given. if (Opts.AddMissingHeaderDeps) PP.SetSuppressIncludeNotFoundError(true); DFGImpl *Callback = new DFGImpl(&PP, Opts); PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callback)); return new DependencyFileGenerator(Callback); } #if 0 // HLSL Change Starts - no support for AST serialization void DependencyFileGenerator::AttachToASTReader(ASTReader &R) { DFGImpl *I = reinterpret_cast<DFGImpl *>(Impl); assert(I && "missing implementation"); R.addListener(llvm::make_unique<DFGASTReaderListener>(*I)); } #endif // HLSL Change Starts - no support for AST serialization /// FileMatchesDepCriteria - Determine whether the given Filename should be /// considered as a dependency. bool DFGImpl::FileMatchesDepCriteria(const char *Filename, SrcMgr::CharacteristicKind FileType) { if (isSpecialFilename(Filename)) return false; if (IncludeSystemHeaders) return true; return FileType == SrcMgr::C_User; } void DFGImpl::FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) { if (Reason != PPCallbacks::EnterFile) return; // Dependency generation really does want to go all the way to the // file entry for a source location to find out what is depended on. // We do not want #line markers to affect dependency generation! SourceManager &SM = PP->getSourceManager(); const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(SM.getExpansionLoc(Loc))); if (!FE) return; StringRef Filename = FE->getName(); if (!FileMatchesDepCriteria(Filename.data(), FileType)) return; // Remove leading "./" (or ".//" or "././" etc.) while (Filename.size() > 2 && Filename[0] == '.' && llvm::sys::path::is_separator(Filename[1])) { Filename = Filename.substr(1); while (llvm::sys::path::is_separator(Filename[0])) Filename = Filename.substr(1); } AddFilename(Filename); } void DFGImpl::InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) { if (!File) { if (AddMissingHeaderDeps) AddFilename(FileName); else SeenMissingHeader = true; } } void DFGImpl::AddFilename(StringRef Filename) { if (FilesSet.insert(Filename).second) Files.push_back(Filename); } /// Print the filename, with escaping or quoting that accommodates the three /// most likely tools that use dependency files: GNU Make, BSD Make, and /// NMake/Jom. /// /// BSD Make is the simplest case: It does no escaping at all. This means /// characters that are normally delimiters, i.e. space and # (the comment /// character) simply aren't supported in filenames. /// /// GNU Make does allow space and # in filenames, but to avoid being treated /// as a delimiter or comment, these must be escaped with a backslash. Because /// backslash is itself the escape character, if a backslash appears in a /// filename, it should be escaped as well. (As a special case, $ is escaped /// as $$, which is the normal Make way to handle the $ character.) /// For compatibility with BSD Make and historical practice, if GNU Make /// un-escapes characters in a filename but doesn't find a match, it will /// retry with the unmodified original string. /// /// GCC tries to accommodate both Make formats by escaping any space or # /// characters in the original filename, but not escaping backslashes. The /// apparent intent is so that filenames with backslashes will be handled /// correctly by BSD Make, and by GNU Make in its fallback mode of using the /// unmodified original string; filenames with # or space characters aren't /// supported by BSD Make at all, but will be handled correctly by GNU Make /// due to the escaping. /// /// A corner case that GCC gets only partly right is when the original filename /// has a backslash immediately followed by space or #. GNU Make would expect /// this backslash to be escaped; however GCC escapes the original backslash /// only when followed by space, not #. It will therefore take a dependency /// from a directive such as /// #include "a\ b\#c.h" /// and emit it as /// a\\\ b\\#c.h /// which GNU Make will interpret as /// a\ b\ /// followed by a comment. Failing to find this file, it will fall back to the /// original string, which probably doesn't exist either; in any case it won't /// find /// a\ b\#c.h /// which is the actual filename specified by the include directive. /// /// Clang does what GCC does, rather than what GNU Make expects. /// /// NMake/Jom has a different set of scary characters, but wraps filespecs in /// double-quotes to avoid misinterpreting them; see /// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info, /// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx /// for Windows file-naming info. static void PrintFilename(raw_ostream &OS, StringRef Filename, DependencyOutputFormat OutputFormat) { if (OutputFormat == DependencyOutputFormat::NMake) { // Add quotes if needed. These are the characters listed as "special" to // NMake, that are legal in a Windows filespec, and that could cause // misinterpretation of the dependency string. if (Filename.find_first_of(" #${}^!") != StringRef::npos) OS << '\"' << Filename << '\"'; else OS << Filename; return; } assert(OutputFormat == DependencyOutputFormat::Make); for (unsigned i = 0, e = Filename.size(); i != e; ++i) { if (Filename[i] == '#') // Handle '#' the broken gcc way. OS << '\\'; else if (Filename[i] == ' ') { // Handle space correctly. OS << '\\'; unsigned j = i; while (j > 0 && Filename[--j] == '\\') OS << '\\'; } else if (Filename[i] == '$') // $ is escaped by $$. OS << '$'; OS << Filename[i]; } } void DFGImpl::OutputDependencyFile() { if (SeenMissingHeader) { llvm::sys::fs::remove(OutputFile); return; } std::error_code EC; llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_Text); if (EC) { PP->getDiagnostics().Report(diag::err_fe_error_opening) << OutputFile << EC.message(); return; } // Write out the dependency targets, trying to avoid overly long // lines when possible. We try our best to emit exactly the same // dependency file as GCC (4.2), assuming the included files are the // same. const unsigned MaxColumns = 75; unsigned Columns = 0; for (std::vector<std::string>::iterator I = Targets.begin(), E = Targets.end(); I != E; ++I) { unsigned N = I->length(); if (Columns == 0) { Columns += N; } else if (Columns + N + 2 > MaxColumns) { Columns = N + 2; OS << " \\\n "; } else { Columns += N + 1; OS << ' '; } // Targets already quoted as needed. OS << *I; } OS << ':'; Columns += 1; // Now add each dependency in the order it was seen, but avoiding // duplicates. for (std::vector<std::string>::iterator I = Files.begin(), E = Files.end(); I != E; ++I) { // Start a new line if this would exceed the column limit. Make // sure to leave space for a trailing " \" in case we need to // break the line on the next iteration. unsigned N = I->length(); if (Columns + (N + 1) + 2 > MaxColumns) { OS << " \\\n "; Columns = 2; } OS << ' '; PrintFilename(OS, *I, OutputFormat); Columns += N + 1; } OS << '\n'; // Create phony targets if requested. if (PhonyTarget && !Files.empty()) { // Skip the first entry, this is always the input file itself. for (std::vector<std::string>::iterator I = Files.begin() + 1, E = Files.end(); I != E; ++I) { OS << '\n'; PrintFilename(OS, *I, OutputFormat); OS << ":\n"; } } } #if 0 // HLSL Change Starts - no support for AST serialization bool DFGASTReaderListener::visitInputFile(llvm::StringRef Filename, bool IsSystem, bool IsOverridden) { assert(!IsSystem || needsSystemInputFileVisitation()); if (IsOverridden) return true; Parent.AddFilename(Filename); return true; } void DFGASTReaderListener::visitModuleFile(llvm::StringRef Filename) { if (Parent.includeModuleFiles()) Parent.AddFilename(Filename); } #endif // HLSL Change Ends - no support for AST serialization
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/DependencyGraph.cpp
//===--- DependencyGraph.cpp - Generate dependency file -------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This code generates a header dependency graph in DOT format, for use // with, e.g., GraphViz. // //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/SetVector.h" #include "llvm/Support/GraphWriter.h" #include "llvm/Support/raw_ostream.h" using namespace clang; namespace DOT = llvm::DOT; namespace { class DependencyGraphCallback : public PPCallbacks { const Preprocessor *PP; std::string OutputFile; std::string SysRoot; llvm::SetVector<const FileEntry *> AllFiles; typedef llvm::DenseMap<const FileEntry *, SmallVector<const FileEntry *, 2> > DependencyMap; DependencyMap Dependencies; private: raw_ostream &writeNodeReference(raw_ostream &OS, const FileEntry *Node); void OutputGraphFile(); public: DependencyGraphCallback(const Preprocessor *_PP, StringRef OutputFile, StringRef SysRoot) : PP(_PP), OutputFile(OutputFile.str()), SysRoot(SysRoot.str()) { } void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) override; void EndOfMainFile() override { OutputGraphFile(); } }; } void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, StringRef SysRoot) { PP.addPPCallbacks(llvm::make_unique<DependencyGraphCallback>(&PP, OutputFile, SysRoot)); } void DependencyGraphCallback::InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) { if (!File) return; SourceManager &SM = PP->getSourceManager(); const FileEntry *FromFile = SM.getFileEntryForID(SM.getFileID(SM.getExpansionLoc(HashLoc))); if (!FromFile) return; Dependencies[FromFile].push_back(File); AllFiles.insert(File); AllFiles.insert(FromFile); } raw_ostream & DependencyGraphCallback::writeNodeReference(raw_ostream &OS, const FileEntry *Node) { OS << "header_" << Node->getUID(); return OS; } void DependencyGraphCallback::OutputGraphFile() { std::error_code EC; llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_Text); if (EC) { PP->getDiagnostics().Report(diag::err_fe_error_opening) << OutputFile << EC.message(); return; } OS << "digraph \"dependencies\" {\n"; // Write the nodes for (unsigned I = 0, N = AllFiles.size(); I != N; ++I) { // Write the node itself. OS.indent(2); writeNodeReference(OS, AllFiles[I]); OS << " [ shape=\"box\", label=\""; StringRef FileName = AllFiles[I]->getName(); if (FileName.startswith(SysRoot)) FileName = FileName.substr(SysRoot.size()); OS << DOT::EscapeString(FileName) << "\"];\n"; } // Write the edges for (DependencyMap::iterator F = Dependencies.begin(), FEnd = Dependencies.end(); F != FEnd; ++F) { for (unsigned I = 0, N = F->second.size(); I != N; ++I) { OS.indent(2); writeNodeReference(OS, F->first); OS << " -> "; writeNodeReference(OS, F->second[I]); OS << ";\n"; } } OS << "}\n"; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/ModuleDependencyCollector.cpp
//===--- ModuleDependencyCollector.cpp - Collect module dependencies ------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // Collect the dependencies of a set of modules. // //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" using namespace clang; namespace { /// Private implementation for ModuleDependencyCollector class ModuleDependencyListener : public ASTReaderListener { ModuleDependencyCollector &Collector; std::error_code copyToRoot(StringRef Src); public: ModuleDependencyListener(ModuleDependencyCollector &Collector) : Collector(Collector) {} bool needsInputFileVisitation() override { return true; } bool needsSystemInputFileVisitation() override { return true; } bool visitInputFile(StringRef Filename, bool IsSystem, bool IsOverridden) override; }; } void ModuleDependencyCollector::attachToASTReader(ASTReader &R) { R.addListener(llvm::make_unique<ModuleDependencyListener>(*this)); } void ModuleDependencyCollector::writeFileMap() { if (Seen.empty()) return; SmallString<256> Dest = getDest(); llvm::sys::path::append(Dest, "vfs.yaml"); std::error_code EC; llvm::raw_fd_ostream OS(Dest, EC, llvm::sys::fs::F_Text); if (EC) { setHasErrors(); return; } VFSWriter.write(OS); } std::error_code ModuleDependencyListener::copyToRoot(StringRef Src) { using namespace llvm::sys; // We need an absolute path to append to the root. SmallString<256> AbsoluteSrc = Src; fs::make_absolute(AbsoluteSrc); // Canonicalize to a native path to avoid mixed separator styles. path::native(AbsoluteSrc); // TODO: We probably need to handle .. as well as . in order to have valid // input to the YAMLVFSWriter. FileManager::removeDotPaths(AbsoluteSrc); // Build the destination path. SmallString<256> Dest = Collector.getDest(); path::append(Dest, path::relative_path(AbsoluteSrc)); // Copy the file into place. if (std::error_code EC = fs::create_directories(path::parent_path(Dest), /*IgnoreExisting=*/true)) return EC; if (std::error_code EC = fs::copy_file(AbsoluteSrc, Dest)) return EC; // Use the absolute path under the root for the file mapping. Collector.addFileMapping(AbsoluteSrc, Dest); return std::error_code(); } bool ModuleDependencyListener::visitInputFile(StringRef Filename, bool IsSystem, bool IsOverridden) { if (Collector.insertSeen(Filename)) if (copyToRoot(Filename)) Collector.setHasErrors(); return true; }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/HeaderIncludeGen.cpp
//===--- HeaderIncludes.cpp - Generate Header Includes --------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/raw_ostream.h" using namespace clang; namespace { class HeaderIncludesCallback : public PPCallbacks { SourceManager &SM; raw_ostream *OutputFile; unsigned CurrentIncludeDepth; bool HasProcessedPredefines; bool OwnsOutputFile; bool ShowAllHeaders; bool ShowDepth; bool MSStyle; public: HeaderIncludesCallback(const Preprocessor *PP, bool ShowAllHeaders_, raw_ostream *OutputFile_, bool OwnsOutputFile_, bool ShowDepth_, bool MSStyle_) : SM(PP->getSourceManager()), OutputFile(OutputFile_), CurrentIncludeDepth(0), HasProcessedPredefines(false), OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_), ShowDepth(ShowDepth_), MSStyle(MSStyle_) {} ~HeaderIncludesCallback() override { if (OwnsOutputFile) delete OutputFile; } void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override; }; } void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders, StringRef OutputPath, bool ShowDepth, bool MSStyle) { raw_ostream *OutputFile = MSStyle ? &llvm::outs() : &llvm::errs(); bool OwnsOutputFile = false; // Open the output file, if used. if (!OutputPath.empty()) { std::error_code EC; llvm::raw_fd_ostream *OS = new llvm::raw_fd_ostream( OutputPath.str(), EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text); if (EC) { PP.getDiagnostics().Report(clang::diag::warn_fe_cc_print_header_failure) << EC.message(); delete OS; } else { OS->SetUnbuffered(); OS->SetUseAtomicWrites(true); OutputFile = OS; OwnsOutputFile = true; } } PP.addPPCallbacks(llvm::make_unique<HeaderIncludesCallback>(&PP, ShowAllHeaders, OutputFile, OwnsOutputFile, ShowDepth, MSStyle)); } void HeaderIncludesCallback::FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind NewFileType, FileID PrevFID) { // Unless we are exiting a #include, make sure to skip ahead to the line the // #include directive was at. PresumedLoc UserLoc = SM.getPresumedLoc(Loc); if (UserLoc.isInvalid()) return; // Adjust the current include depth. if (Reason == PPCallbacks::EnterFile) { ++CurrentIncludeDepth; } else if (Reason == PPCallbacks::ExitFile) { if (CurrentIncludeDepth) --CurrentIncludeDepth; // We track when we are done with the predefines by watching for the first // place where we drop back to a nesting depth of 1. if (CurrentIncludeDepth == 1 && !HasProcessedPredefines) HasProcessedPredefines = true; return; } else return; // Show the header if we are (a) past the predefines, or (b) showing all // headers and in the predefines at a depth past the initial file and command // line buffers. bool ShowHeader = (HasProcessedPredefines || (ShowAllHeaders && CurrentIncludeDepth > 2)); // Dump the header include information we are past the predefines buffer or // are showing all headers. if (ShowHeader && Reason == PPCallbacks::EnterFile) { // Write to a temporary string to avoid unnecessary flushing on errs(). SmallString<512> Filename(UserLoc.getFilename()); if (!MSStyle) Lexer::Stringify(Filename); SmallString<256> Msg; if (MSStyle) Msg += "Note: including file:"; if (ShowDepth) { // The main source file is at depth 1, so skip one dot. for (unsigned i = 1; i != CurrentIncludeDepth; ++i) Msg += MSStyle ? ' ' : '.'; if (!MSStyle) Msg += ' '; } Msg += Filename; Msg += '\n'; OutputFile->write(Msg.data(), Msg.size()); OutputFile->flush(); } }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/DiagnosticRenderer.cpp
//===--- DiagnosticRenderer.cpp - Diagnostic Pretty-Printing --------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/DiagnosticRenderer.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Edit/Commit.h" #include "clang/Edit/EditedSource.h" #include "clang/Edit/EditsReceiver.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> using namespace clang; /// \brief Retrieve the name of the immediate macro expansion. /// /// This routine starts from a source location, and finds the name of the macro /// responsible for its immediate expansion. It looks through any intervening /// macro argument expansions to compute this. It returns a StringRef which /// refers to the SourceManager-owned buffer of the source where that macro /// name is spelled. Thus, the result shouldn't out-live that SourceManager. /// /// This differs from Lexer::getImmediateMacroName in that any macro argument /// location will result in the topmost function macro that accepted it. /// e.g. /// \code /// MAC1( MAC2(foo) ) /// \endcode /// for location of 'foo' token, this function will return "MAC1" while /// Lexer::getImmediateMacroName will return "MAC2". static StringRef getImmediateMacroName(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts) { assert(Loc.isMacroID() && "Only reasonble to call this on macros"); // Walk past macro argument expanions. while (SM.isMacroArgExpansion(Loc)) Loc = SM.getImmediateExpansionRange(Loc).first; // If the macro's spelling has no FileID, then it's actually a token paste // or stringization (or similar) and not a macro at all. if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc)))) return StringRef(); // Find the spelling location of the start of the non-argument expansion // range. This is where the macro name was spelled in order to begin // expanding this macro. Loc = SM.getSpellingLoc(SM.getImmediateExpansionRange(Loc).first); // Dig out the buffer where the macro name was spelled and the extents of the // name so that we can render it into the expansion note. std::pair<FileID, unsigned> ExpansionInfo = SM.getDecomposedLoc(Loc); unsigned MacroTokenLength = Lexer::MeasureTokenLength(Loc, SM, LangOpts); StringRef ExpansionBuffer = SM.getBufferData(ExpansionInfo.first); return ExpansionBuffer.substr(ExpansionInfo.second, MacroTokenLength); } DiagnosticRenderer::DiagnosticRenderer(const LangOptions &LangOpts, DiagnosticOptions *DiagOpts) : LangOpts(LangOpts), DiagOpts(DiagOpts), LastLevel() {} DiagnosticRenderer::~DiagnosticRenderer() {} namespace { class FixitReceiver : public edit::EditsReceiver { SmallVectorImpl<FixItHint> &MergedFixits; public: FixitReceiver(SmallVectorImpl<FixItHint> &MergedFixits) : MergedFixits(MergedFixits) { } void insert(SourceLocation loc, StringRef text) override { MergedFixits.push_back(FixItHint::CreateInsertion(loc, text)); } void replace(CharSourceRange range, StringRef text) override { MergedFixits.push_back(FixItHint::CreateReplacement(range, text)); } }; } static void mergeFixits(ArrayRef<FixItHint> FixItHints, const SourceManager &SM, const LangOptions &LangOpts, SmallVectorImpl<FixItHint> &MergedFixits) { edit::Commit commit(SM, LangOpts); for (ArrayRef<FixItHint>::const_iterator I = FixItHints.begin(), E = FixItHints.end(); I != E; ++I) { const FixItHint &Hint = *I; if (Hint.CodeToInsert.empty()) { if (Hint.InsertFromRange.isValid()) commit.insertFromRange(Hint.RemoveRange.getBegin(), Hint.InsertFromRange, /*afterToken=*/false, Hint.BeforePreviousInsertions); else commit.remove(Hint.RemoveRange); } else { if (Hint.RemoveRange.isTokenRange() || Hint.RemoveRange.getBegin() != Hint.RemoveRange.getEnd()) commit.replace(Hint.RemoveRange, Hint.CodeToInsert); else commit.insert(Hint.RemoveRange.getBegin(), Hint.CodeToInsert, /*afterToken=*/false, Hint.BeforePreviousInsertions); } } edit::EditedSource Editor(SM, LangOpts); if (Editor.commit(commit)) { FixitReceiver Rec(MergedFixits); Editor.applyRewrites(Rec); } } void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> FixItHints, const SourceManager *SM, DiagOrStoredDiag D) { assert(SM || Loc.isInvalid()); beginDiagnostic(D, Level); if (!Loc.isValid()) // If we have no source location, just emit the diagnostic message. emitDiagnosticMessage(Loc, PresumedLoc(), Level, Message, Ranges, SM, D); else { // Get the ranges into a local array we can hack on. SmallVector<CharSourceRange, 20> MutableRanges(Ranges.begin(), Ranges.end()); SmallVector<FixItHint, 8> MergedFixits; if (!FixItHints.empty()) { mergeFixits(FixItHints, *SM, LangOpts, MergedFixits); FixItHints = MergedFixits; } for (ArrayRef<FixItHint>::const_iterator I = FixItHints.begin(), E = FixItHints.end(); I != E; ++I) if (I->RemoveRange.isValid()) MutableRanges.push_back(I->RemoveRange); SourceLocation UnexpandedLoc = Loc; // Find the ultimate expansion location for the diagnostic. Loc = SM->getFileLoc(Loc); PresumedLoc PLoc = SM->getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc); // First, if this diagnostic is not in the main file, print out the // "included from" lines. emitIncludeStack(Loc, PLoc, Level, *SM); // Next, emit the actual diagnostic message and caret. emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, SM, D); emitCaret(Loc, Level, MutableRanges, FixItHints, *SM); // If this location is within a macro, walk from UnexpandedLoc up to Loc // and produce a macro backtrace. if (UnexpandedLoc.isValid() && UnexpandedLoc.isMacroID()) { unsigned MacroDepth = 0; emitMacroExpansions(UnexpandedLoc, Level, MutableRanges, FixItHints, *SM, MacroDepth); } } LastLoc = Loc; LastLevel = Level; endDiagnostic(D, Level); } void DiagnosticRenderer::emitStoredDiagnostic(StoredDiagnostic &Diag) { emitDiagnostic(Diag.getLocation(), Diag.getLevel(), Diag.getMessage(), Diag.getRanges(), Diag.getFixIts(), Diag.getLocation().isValid() ? &Diag.getLocation().getManager() : nullptr, &Diag); } void DiagnosticRenderer::emitBasicNote(StringRef Message) { emitDiagnosticMessage( SourceLocation(), PresumedLoc(), DiagnosticsEngine::Note, Message, None, nullptr, DiagOrStoredDiag()); } /// \brief Prints an include stack when appropriate for a particular /// diagnostic level and location. /// /// This routine handles all the logic of suppressing particular include /// stacks (such as those for notes) and duplicate include stacks when /// repeated warnings occur within the same file. It also handles the logic /// of customizing the formatting and display of the include stack. /// /// \param Loc The diagnostic location. /// \param PLoc The presumed location of the diagnostic location. /// \param Level The diagnostic level of the message this stack pertains to. void DiagnosticRenderer::emitIncludeStack(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, const SourceManager &SM) { SourceLocation IncludeLoc = PLoc.getIncludeLoc(); // Skip redundant include stacks altogether. if (LastIncludeLoc == IncludeLoc) return; LastIncludeLoc = IncludeLoc; if (!DiagOpts->ShowNoteIncludeStack && Level == DiagnosticsEngine::Note) return; if (IncludeLoc.isValid()) emitIncludeStackRecursively(IncludeLoc, SM); else { emitModuleBuildStack(SM); emitImportStack(Loc, SM); } } /// \brief Helper to recursivly walk up the include stack and print each layer /// on the way back down. void DiagnosticRenderer::emitIncludeStackRecursively(SourceLocation Loc, const SourceManager &SM) { if (Loc.isInvalid()) { emitModuleBuildStack(SM); return; } PresumedLoc PLoc = SM.getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc); if (PLoc.isInvalid()) return; // If this source location was imported from a module, print the module // import stack rather than the // FIXME: We want submodule granularity here. std::pair<SourceLocation, StringRef> Imported = SM.getModuleImportLoc(Loc); if (Imported.first.isValid()) { // This location was imported by a module. Emit the module import stack. emitImportStackRecursively(Imported.first, Imported.second, SM); return; } // Emit the other include frames first. emitIncludeStackRecursively(PLoc.getIncludeLoc(), SM); // Emit the inclusion text/note. emitIncludeLocation(Loc, PLoc, SM); } /// \brief Emit the module import stack associated with the current location. void DiagnosticRenderer::emitImportStack(SourceLocation Loc, const SourceManager &SM) { if (Loc.isInvalid()) { emitModuleBuildStack(SM); return; } std::pair<SourceLocation, StringRef> NextImportLoc = SM.getModuleImportLoc(Loc); emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second, SM); } /// \brief Helper to recursivly walk up the import stack and print each layer /// on the way back down. void DiagnosticRenderer::emitImportStackRecursively(SourceLocation Loc, StringRef ModuleName, const SourceManager &SM) { if (Loc.isInvalid()) { return; } PresumedLoc PLoc = SM.getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc); if (PLoc.isInvalid()) return; // Emit the other import frames first. std::pair<SourceLocation, StringRef> NextImportLoc = SM.getModuleImportLoc(Loc); emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second, SM); // Emit the inclusion text/note. emitImportLocation(Loc, PLoc, ModuleName, SM); } /// \brief Emit the module build stack, for cases where a module is (re-)built /// on demand. void DiagnosticRenderer::emitModuleBuildStack(const SourceManager &SM) { ModuleBuildStack Stack = SM.getModuleBuildStack(); for (unsigned I = 0, N = Stack.size(); I != N; ++I) { const SourceManager &CurSM = Stack[I].second.getManager(); SourceLocation CurLoc = Stack[I].second; emitBuildingModuleLocation(CurLoc, CurSM.getPresumedLoc(CurLoc, DiagOpts->ShowPresumedLoc), Stack[I].first, CurSM); } } // Helper function to fix up source ranges. It takes in an array of ranges, // and outputs an array of ranges where we want to draw the range highlighting // around the location specified by CaretLoc. // // To find locations which correspond to the caret, we crawl the macro caller // chain for the beginning and end of each range. If the caret location // is in a macro expansion, we search each chain for a location // in the same expansion as the caret; otherwise, we crawl to the top of // each chain. Two locations are part of the same macro expansion // iff the FileID is the same. static void mapDiagnosticRanges( SourceLocation CaretLoc, ArrayRef<CharSourceRange> Ranges, SmallVectorImpl<CharSourceRange> &SpellingRanges, const SourceManager *SM) { FileID CaretLocFileID = SM->getFileID(CaretLoc); for (ArrayRef<CharSourceRange>::const_iterator I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { SourceLocation Begin = I->getBegin(), End = I->getEnd(); bool IsTokenRange = I->isTokenRange(); FileID BeginFileID = SM->getFileID(Begin); FileID EndFileID = SM->getFileID(End); // Find the common parent for the beginning and end of the range. // First, crawl the expansion chain for the beginning of the range. llvm::SmallDenseMap<FileID, SourceLocation> BeginLocsMap; while (Begin.isMacroID() && BeginFileID != EndFileID) { BeginLocsMap[BeginFileID] = Begin; Begin = SM->getImmediateExpansionRange(Begin).first; BeginFileID = SM->getFileID(Begin); } // Then, crawl the expansion chain for the end of the range. if (BeginFileID != EndFileID) { while (End.isMacroID() && !BeginLocsMap.count(EndFileID)) { End = SM->getImmediateExpansionRange(End).second; EndFileID = SM->getFileID(End); } if (End.isMacroID()) { Begin = BeginLocsMap[EndFileID]; BeginFileID = EndFileID; } } while (Begin.isMacroID() && BeginFileID != CaretLocFileID) { if (SM->isMacroArgExpansion(Begin)) { Begin = SM->getImmediateSpellingLoc(Begin); End = SM->getImmediateSpellingLoc(End); } else { Begin = SM->getImmediateExpansionRange(Begin).first; End = SM->getImmediateExpansionRange(End).second; } BeginFileID = SM->getFileID(Begin); if (BeginFileID != SM->getFileID(End)) { // FIXME: Ugly hack to stop a crash; this code is making bad // assumptions and it's too complicated for me to reason // about. Begin = End = SourceLocation(); break; } } // Return the spelling location of the beginning and end of the range. Begin = SM->getSpellingLoc(Begin); End = SM->getSpellingLoc(End); SpellingRanges.push_back(CharSourceRange(SourceRange(Begin, End), IsTokenRange)); } } void DiagnosticRenderer::emitCaret(SourceLocation Loc, DiagnosticsEngine::Level Level, ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints, const SourceManager &SM) { SmallVector<CharSourceRange, 4> SpellingRanges; mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM); emitCodeContext(Loc, Level, SpellingRanges, Hints, SM); } /// \brief Recursively emit notes for each macro expansion and caret /// diagnostics where appropriate. /// /// Walks up the macro expansion stack printing expansion notes, the code /// snippet, caret, underlines and FixItHint display as appropriate at each /// level. /// /// \param Loc The location for this caret. /// \param Level The diagnostic level currently being emitted. /// \param Ranges The underlined ranges for this code snippet. /// \param Hints The FixIt hints active for this diagnostic. /// \param OnMacroInst The current depth of the macro expansion stack. void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc, DiagnosticsEngine::Level Level, ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints, const SourceManager &SM, unsigned &MacroDepth, unsigned OnMacroInst) { assert(!Loc.isInvalid() && "must have a valid source location here"); // Walk up to the caller of this macro, and produce a backtrace down to there. SourceLocation OneLevelUp = SM.getImmediateMacroCallerLoc(Loc); if (OneLevelUp.isMacroID()) emitMacroExpansions(OneLevelUp, Level, Ranges, Hints, SM, MacroDepth, OnMacroInst + 1); else MacroDepth = OnMacroInst + 1; unsigned MacroSkipStart = 0, MacroSkipEnd = 0; if (MacroDepth > DiagOpts->MacroBacktraceLimit && DiagOpts->MacroBacktraceLimit != 0) { MacroSkipStart = DiagOpts->MacroBacktraceLimit / 2 + DiagOpts->MacroBacktraceLimit % 2; MacroSkipEnd = MacroDepth - DiagOpts->MacroBacktraceLimit / 2; } // Whether to suppress printing this macro expansion. bool Suppressed = (OnMacroInst >= MacroSkipStart && OnMacroInst < MacroSkipEnd); if (Suppressed) { // Tell the user that we've skipped contexts. if (OnMacroInst == MacroSkipStart) { SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); Message << "(skipping " << (MacroSkipEnd - MacroSkipStart) << " expansions in backtrace; use -fmacro-backtrace-limit=0 to " "see all)"; emitBasicNote(Message.str()); } return; } // Find the spelling location for the macro definition. We must use the // spelling location here to avoid emitting a macro bactrace for the note. SourceLocation SpellingLoc = Loc; // If this is the expansion of a macro argument, point the caret at the // use of the argument in the definition of the macro, not the expansion. if (SM.isMacroArgExpansion(Loc)) SpellingLoc = SM.getImmediateExpansionRange(Loc).first; SpellingLoc = SM.getSpellingLoc(SpellingLoc); // Map the ranges into the FileID of the diagnostic location. SmallVector<CharSourceRange, 4> SpellingRanges; mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM); SmallString<100> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); StringRef MacroName = getImmediateMacroName(Loc, SM, LangOpts); if (MacroName.empty()) Message << "expanded from here"; else Message << "expanded from macro '" << MacroName << "'"; emitDiagnostic(SpellingLoc, DiagnosticsEngine::Note, Message.str(), SpellingRanges, None, &SM); } DiagnosticNoteRenderer::~DiagnosticNoteRenderer() {} void DiagnosticNoteRenderer::emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, const SourceManager &SM) { // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); Message << "in file included from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; emitNote(Loc, Message.str(), &SM); } void DiagnosticNoteRenderer::emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, StringRef ModuleName, const SourceManager &SM) { // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); Message << "in module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; emitNote(Loc, Message.str(), &SM); } void DiagnosticNoteRenderer::emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, StringRef ModuleName, const SourceManager &SM) { // Generate a note indicating the include location. SmallString<200> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); if (PLoc.getFilename()) Message << "while building module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":"; else Message << "while building module '" << ModuleName << "':"; emitNote(Loc, Message.str(), &SM); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/InitHeaderSearch.cpp
//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file implements the InitHeaderSearch class. // //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/LangOptions.h" #include "clang/Config/config.h" // C_INCLUDE_DIRS #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" using namespace clang; using namespace clang::frontend; namespace { /// InitHeaderSearch - This class makes it easier to set the search paths of /// a HeaderSearch object. InitHeaderSearch stores several search path lists /// internally, which can be sent to a HeaderSearch object in one swoop. class InitHeaderSearch { std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath; typedef std::vector<std::pair<IncludeDirGroup, DirectoryLookup> >::const_iterator path_iterator; std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes; HeaderSearch &Headers; bool Verbose; std::string IncludeSysroot; bool HasSysroot; public: InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot) : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot), HasSysroot(!(sysroot.empty() || sysroot == "/")) { } /// AddPath - Add the specified path to the specified group list, prefixing /// the sysroot if used. void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework); /// AddUnmappedPath - Add the specified path to the specified group list, /// without performing any sysroot remapping. void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, bool isFramework); /// AddSystemHeaderPrefix - Add the specified prefix to the system header /// prefix list. void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader); } /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu /// libstdc++. void AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir, StringRef Dir32, StringRef Dir64, const llvm::Triple &triple); /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW /// libstdc++. void AddMinGWCPlusPlusIncludePaths(StringRef Base, StringRef Arch, StringRef Version); // AddDefaultCIncludePaths - Add paths that should always be searched. void AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts); // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when // compiling c++. void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts); /// AddDefaultSystemIncludePaths - Adds the default system include paths so /// that e.g. stdio.h is found. void AddDefaultIncludePaths(const LangOptions &Lang, const llvm::Triple &triple, const HeaderSearchOptions &HSOpts); /// Realize - Merges all search path lists into one list and send it to /// HeaderSearch. void Realize(const LangOptions &Lang); }; } // end anonymous namespace. static bool CanPrefixSysroot(StringRef Path) { #if defined(LLVM_ON_WIN32) return !Path.empty() && llvm::sys::path::is_separator(Path[0]); #else return llvm::sys::path::is_absolute(Path); #endif } void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework) { // Add the path with sysroot prepended, if desired and this is a system header // group. if (HasSysroot) { SmallString<256> MappedPathStorage; StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); if (CanPrefixSysroot(MappedPathStr)) { AddUnmappedPath(IncludeSysroot + Path, Group, isFramework); return; } } AddUnmappedPath(Path, Group, isFramework); } void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, bool isFramework) { assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); FileManager &FM = Headers.getFileMgr(); SmallString<256> MappedPathStorage; StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); #if 1 // HLSL Change Starts - simplify mapping based on actual usage assert(Group == Angled); assert(!isFramework); // If the directory exists, add it. if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { IncludePath.push_back( std::make_pair(Angled, DirectoryLookup(DE, SrcMgr::C_User, false))); return; } #else // Compute the DirectoryLookup type. SrcMgr::CharacteristicKind Type; if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) { Type = SrcMgr::C_User; } else if (Group == ExternCSystem) { Type = SrcMgr::C_ExternCSystem; } else { Type = SrcMgr::C_System; } // If the directory exists, add it. if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { IncludePath.push_back( std::make_pair(Group, DirectoryLookup(DE, Type, isFramework))); return; } // Check to see if this is an apple-style headermap (which are not allowed to // be frameworks). if (!isFramework) { if (const FileEntry *FE = FM.getFile(MappedPathStr)) { if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { // It is a headermap, add it to the search path. IncludePath.push_back( std::make_pair(Group, DirectoryLookup(HM, Type, Group == IndexHeaderMap))); return; } } } if (Verbose) llvm::errs() << "ignoring nonexistent directory \"" << MappedPathStr << "\"\n"; #endif // HLSL Change Ends - simplify mapping based on actual usage } // HLSL Change: Remove unused function; #if 0 void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir, StringRef Dir32, StringRef Dir64, const llvm::Triple &triple) { // Add the base dir AddPath(Base, CXXSystem, false); // Add the multilib dirs llvm::Triple::ArchType arch = triple.getArch(); bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; if (is64bit) AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false); else AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false); // Add the backward dir AddPath(Base + "/backward", CXXSystem, false); } void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, StringRef Arch, StringRef Version) { AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", CXXSystem, false); AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, CXXSystem, false); AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", CXXSystem, false); } void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { // HLSL Change Starts - no standard include files for the HLSL/DXIL #if 1 return; #else llvm::Triple::OSType os = triple.getOS(); if (HSOpts.UseStandardSystemIncludes) { switch (os) { case llvm::Triple::CloudABI: case llvm::Triple::FreeBSD: case llvm::Triple::NetBSD: case llvm::Triple::OpenBSD: case llvm::Triple::Bitrig: case llvm::Triple::NaCl: break; case llvm::Triple::Win32: if (triple.getEnvironment() != llvm::Triple::Cygnus) break; default: // FIXME: temporary hack: hard-coded paths. AddPath("/usr/local/include", System, false); break; } } // Builtin includes use #include_next directives and should be positioned // just prior C include dirs. if (HSOpts.UseBuiltinIncludes) { // Ignore the sys root, we *always* look for clang headers relative to // supplied path. SmallString<128> P = StringRef(HSOpts.ResourceDir); llvm::sys::path::append(P, "include"); AddUnmappedPath(P, ExternCSystem, false); } // All remaining additions are for system include directories, early exit if // we aren't using them. if (!HSOpts.UseStandardSystemIncludes) return; // Add dirs specified via 'configure --with-c-include-dirs'. StringRef CIncludeDirs(C_INCLUDE_DIRS); if (CIncludeDirs != "") { SmallVector<StringRef, 5> dirs; CIncludeDirs.split(dirs, ":"); for (SmallVectorImpl<StringRef>::iterator i = dirs.begin(); i != dirs.end(); ++i) AddPath(*i, ExternCSystem, false); return; } switch (os) { case llvm::Triple::Linux: llvm_unreachable("Include management is handled in the driver."); case llvm::Triple::CloudABI: { // <sysroot>/<triple>/include SmallString<128> P = StringRef(HSOpts.ResourceDir); llvm::sys::path::append(P, "../../..", triple.str(), "include"); AddPath(P, System, false); break; } case llvm::Triple::Haiku: AddPath("/boot/common/include", System, false); AddPath("/boot/develop/headers/os", System, false); AddPath("/boot/develop/headers/os/app", System, false); AddPath("/boot/develop/headers/os/arch", System, false); AddPath("/boot/develop/headers/os/device", System, false); AddPath("/boot/develop/headers/os/drivers", System, false); AddPath("/boot/develop/headers/os/game", System, false); AddPath("/boot/develop/headers/os/interface", System, false); AddPath("/boot/develop/headers/os/kernel", System, false); AddPath("/boot/develop/headers/os/locale", System, false); AddPath("/boot/develop/headers/os/mail", System, false); AddPath("/boot/develop/headers/os/media", System, false); AddPath("/boot/develop/headers/os/midi", System, false); AddPath("/boot/develop/headers/os/midi2", System, false); AddPath("/boot/develop/headers/os/net", System, false); AddPath("/boot/develop/headers/os/storage", System, false); AddPath("/boot/develop/headers/os/support", System, false); AddPath("/boot/develop/headers/os/translation", System, false); AddPath("/boot/develop/headers/os/add-ons/graphics", System, false); AddPath("/boot/develop/headers/os/add-ons/input_server", System, false); AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false); AddPath("/boot/develop/headers/os/add-ons/tracker", System, false); AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false); AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false); AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false); AddPath("/boot/develop/headers/cpp", System, false); AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false); AddPath("/boot/develop/headers/3rdparty", System, false); AddPath("/boot/develop/headers/bsd", System, false); AddPath("/boot/develop/headers/glibc", System, false); AddPath("/boot/develop/headers/posix", System, false); AddPath("/boot/develop/headers", System, false); break; case llvm::Triple::RTEMS: break; case llvm::Triple::Win32: switch (triple.getEnvironment()) { default: llvm_unreachable("Include management is handled in the driver."); case llvm::Triple::Cygnus: AddPath("/usr/include/w32api", System, false); break; case llvm::Triple::GNU: break; } break; default: break; } switch (os) { case llvm::Triple::CloudABI: case llvm::Triple::RTEMS: case llvm::Triple::NaCl: break; default: AddPath("/usr/include", ExternCSystem, false); break; } #endif // HLSL Change Ends } void InitHeaderSearch:: AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { // HLSL Change Starts - no standard include files for the HLSL/DXIL #if 1 return; #else llvm::Triple::OSType os = triple.getOS(); // FIXME: temporary hack: hard-coded paths. if (triple.isOSDarwin()) { switch (triple.getArch()) { default: break; case llvm::Triple::ppc: case llvm::Triple::ppc64: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", "powerpc-apple-darwin10", "", "ppc64", triple); AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", "powerpc-apple-darwin10", "", "ppc64", triple); break; case llvm::Triple::x86: case llvm::Triple::x86_64: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", "i686-apple-darwin10", "", "x86_64", triple); AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", "i686-apple-darwin8", "", "", triple); break; case llvm::Triple::arm: case llvm::Triple::thumb: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", "arm-apple-darwin10", "v7", "", triple); AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", "arm-apple-darwin10", "v6", "", triple); break; case llvm::Triple::aarch64: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", "arm64-apple-darwin10", "", "", triple); break; } return; } switch (os) { case llvm::Triple::Linux: llvm_unreachable("Include management is handled in the driver."); break; case llvm::Triple::Win32: switch (triple.getEnvironment()) { default: llvm_unreachable("Include management is handled in the driver."); case llvm::Triple::Cygnus: // Cygwin-1.7 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3"); AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3"); AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); // g++-4 / Cygwin-1.5 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); break; } break; case llvm::Triple::DragonFly: if (llvm::sys::fs::exists("/usr/lib/gcc47")) AddPath("/usr/include/c++/4.7", CXXSystem, false); else AddPath("/usr/include/c++/4.4", CXXSystem, false); break; case llvm::Triple::OpenBSD: { std::string t = triple.getTriple(); if (t.substr(0, 6) == "x86_64") t.replace(0, 6, "amd64"); AddGnuCPlusPlusIncludePaths("/usr/include/g++", t, "", "", triple); break; } case llvm::Triple::Minix: AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3", "", "", "", triple); break; case llvm::Triple::Solaris: AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/", "i386-pc-solaris2.11", "", "", triple); break; default: break; } #endif // HLSL Change Ends } #endif void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang, const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { #if 1 // HLSL Change Starts return; #else // NB: This code path is going away. All of the logic is moving into the // driver which has the information necessary to do target-specific // selections of default include paths. Each target which moves there will be // exempted from this logic here until we can delete the entire pile of code. switch (triple.getOS()) { default: break; // Everything else continues to use this routine's logic. case llvm::Triple::Linux: return; case llvm::Triple::Win32: if (triple.getEnvironment() != llvm::Triple::Cygnus || triple.isOSBinFormatMachO()) return; break; } if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) { if (HSOpts.UseLibcxx) { if (triple.isOSDarwin()) { // On Darwin, libc++ may be installed alongside the compiler in // include/c++/v1. if (!HSOpts.ResourceDir.empty()) { // Remove version from foo/lib/clang/version StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir); // Remove clang from foo/lib/clang StringRef Lib = llvm::sys::path::parent_path(NoVer); // Remove lib from foo/lib SmallString<128> P = llvm::sys::path::parent_path(Lib); // Get foo/include/c++/v1 llvm::sys::path::append(P, "include", "c++", "v1"); AddUnmappedPath(P, CXXSystem, false); } } // On Solaris, include the support directory for things like xlocale and // fudged system headers. if (triple.getOS() == llvm::Triple::Solaris) AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false); AddPath("/usr/include/c++/v1", CXXSystem, false); } else { AddDefaultCPlusPlusIncludePaths(triple, HSOpts); } } AddDefaultCIncludePaths(triple, HSOpts); // Add the default framework include paths on Darwin. if (HSOpts.UseStandardSystemIncludes) { if (triple.isOSDarwin()) { AddPath("/System/Library/Frameworks", System, true); AddPath("/Library/Frameworks", System, true); } } #endif // HLSL Change Ends } /// RemoveDuplicates - If there are duplicate directory entries in the specified /// search list, remove the later (dead) ones. Returns the number of non-system /// headers removed, which is used to update NumAngled. static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, unsigned First, bool Verbose) { llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; unsigned NonSystemRemoved = 0; for (unsigned i = First; i != SearchList.size(); ++i) { unsigned DirToRemove = i; const DirectoryLookup &CurEntry = SearchList[i]; if (CurEntry.isNormalDir()) { // If this isn't the first time we've seen this dir, remove it. if (SeenDirs.insert(CurEntry.getDir()).second) continue; } else if (CurEntry.isFramework()) { // If this isn't the first time we've seen this framework dir, remove it. if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()).second) continue; } else { assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); // If this isn't the first time we've seen this headermap, remove it. if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()).second) continue; } // If we have a normal #include dir/framework/headermap that is shadowed // later in the chain by a system include location, we actually want to // ignore the user's request and drop the user dir... keeping the system // dir. This is weird, but required to emulate GCC's search path correctly. // // Since dupes of system dirs are rare, just rescan to find the original // that we're nuking instead of using a DenseMap. if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { // Find the dir that this is the same of. unsigned FirstDir; for (FirstDir = 0; ; ++FirstDir) { assert(FirstDir != i && "Didn't find dupe?"); const DirectoryLookup &SearchEntry = SearchList[FirstDir]; // If these are different lookup types, then they can't be the dupe. if (SearchEntry.getLookupType() != CurEntry.getLookupType()) continue; bool isSame; if (CurEntry.isNormalDir()) isSame = SearchEntry.getDir() == CurEntry.getDir(); else if (CurEntry.isFramework()) isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); else { assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); } if (isSame) break; } // If the first dir in the search path is a non-system dir, zap it // instead of the system one. if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) DirToRemove = FirstDir; } if (Verbose) { llvm::errs() << "ignoring duplicate directory \"" << CurEntry.getName() << "\"\n"; if (DirToRemove != i) llvm::errs() << " as it is a non-system directory that duplicates " << "a system directory\n"; } if (DirToRemove != i) ++NonSystemRemoved; // This is reached if the current entry is a duplicate. Remove the // DirToRemove (usually the current dir). SearchList.erase(SearchList.begin()+DirToRemove); --i; } return NonSystemRemoved; } void InitHeaderSearch::Realize(const LangOptions &Lang) { // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. std::vector<DirectoryLookup> SearchList; SearchList.reserve(IncludePath.size()); // Quoted arguments go first. for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); it != ie; ++it) { if (it->first == Quoted) SearchList.push_back(it->second); } // Deduplicate and remember index. RemoveDuplicates(SearchList, 0, Verbose); unsigned NumQuoted = SearchList.size(); for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); it != ie; ++it) { if (it->first == Angled || it->first == IndexHeaderMap) SearchList.push_back(it->second); } RemoveDuplicates(SearchList, NumQuoted, Verbose); unsigned NumAngled = SearchList.size(); for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); it != ie; ++it) { if (it->first == System || it->first == ExternCSystem || (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) || (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) || (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) || (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem)) SearchList.push_back(it->second); } for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); it != ie; ++it) { if (it->first == After) SearchList.push_back(it->second); } // Remove duplicates across both the Angled and System directories. GCC does // this and failing to remove duplicates across these two groups breaks // #include_next. unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose); NumAngled -= NonSystemRemoved; bool DontSearchCurDir = false; // TODO: set to true if -I- is set? Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir); Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes); // If verbose, print the list of directories that will be searched. if (Verbose) { llvm::errs() << "#include \"...\" search starts here:\n"; for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { if (i == NumQuoted) llvm::errs() << "#include <...> search starts here:\n"; const char *Name = SearchList[i].getName(); const char *Suffix; if (SearchList[i].isNormalDir()) Suffix = ""; else if (SearchList[i].isFramework()) Suffix = " (framework directory)"; else { assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); Suffix = " (headermap)"; } llvm::errs() << " " << Name << Suffix << "\n"; } llvm::errs() << "End of search list.\n"; } } void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, const HeaderSearchOptions &HSOpts, const LangOptions &Lang, const llvm::Triple &Triple) { InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); // Add the user defined entries. for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; if (E.IgnoreSysRoot) { Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework); } else { Init.AddPath(E.Path, E.Group, E.IsFramework); } } Init.AddDefaultIncludePaths(Lang, Triple, HSOpts); for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i) Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix, HSOpts.SystemHeaderPrefixes[i].IsSystemHeader); if (HSOpts.UseBuiltinIncludes) { // Set up the builtin include directory in the module map. SmallString<128> P = StringRef(HSOpts.ResourceDir); llvm::sys::path::append(P, "include"); if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P)) HS.getModuleMap().setBuiltinIncludeDir(Dir); } Init.Realize(Lang); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/CompilerInvocation.cpp
//===--- CompilerInvocation.cpp -------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/CompilerInvocation.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/Version.h" #include "clang/Config/config.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/Util.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/LangStandard.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include <atomic> #include <memory> #include <sys/stat.h> #include <system_error> using namespace clang; //===----------------------------------------------------------------------===// // Initialization. //===----------------------------------------------------------------------===// CompilerInvocationBase::CompilerInvocationBase() : LangOpts(new LangOptions()), TargetOpts(new TargetOptions()), DiagnosticOpts(new DiagnosticOptions()), HeaderSearchOpts(new HeaderSearchOptions()), PreprocessorOpts(new PreprocessorOptions()) {} CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X) : RefCountedBase<CompilerInvocation>(), LangOpts(new LangOptions(*X.getLangOpts())), TargetOpts(new TargetOptions(X.getTargetOpts())), DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())), HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())), PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {} CompilerInvocationBase::~CompilerInvocationBase() {} //===----------------------------------------------------------------------===// // Deserialization (from args) //===----------------------------------------------------------------------===// using namespace clang::driver; using namespace clang::driver::options; using namespace llvm::opt; // static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, DiagnosticsEngine &Diags) { unsigned DefaultOpt = 0; if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable)) DefaultOpt = 2; if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { if (A->getOption().matches(options::OPT_O0)) return 0; if (A->getOption().matches(options::OPT_Ofast)) return 3; assert (A->getOption().matches(options::OPT_O)); StringRef S(A->getValue()); if (S == "s" || S == "z" || S.empty()) return 2; return getLastArgIntValue(Args, OPT_O, DefaultOpt, Diags); } return DefaultOpt; } static unsigned getOptimizationLevelSize(ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { if (A->getOption().matches(options::OPT_O)) { switch (A->getValue()[0]) { default: return 0; case 's': return 1; case 'z': return 2; } } } return 0; } static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group, OptSpecifier GroupWithValue, std::vector<std::string> &Diagnostics) { for (Arg *A : Args.filtered(Group)) { if (A->getOption().getKind() == Option::FlagClass) { // The argument is a pure flag (such as OPT_Wall or OPT_Wdeprecated). Add // its name (minus the "W" or "R" at the beginning) to the warning list. Diagnostics.push_back(A->getOption().getName().drop_front(1)); } else if (A->getOption().matches(GroupWithValue)) { // This is -Wfoo= or -Rfoo=, where foo is the name of the diagnostic group. Diagnostics.push_back(A->getOption().getName().drop_front(1).rtrim("=-")); } else { // Otherwise, add its value (for OPT_W_Joined and similar). for (const char *Arg : A->getValues()) Diagnostics.emplace_back(Arg); } } } static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags) { using namespace options; bool Success = true; if (Arg *A = Args.getLastArg(OPT_analyzer_store)) { StringRef Name = A->getValue(); AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name) #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \ .Case(CMDFLAG, NAME##Model) #include "clang/StaticAnalyzer/Core/Analyses.def" .Default(NumStores); if (Value == NumStores) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; Success = false; } else { Opts.AnalysisStoreOpt = Value; } } if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) { StringRef Name = A->getValue(); AnalysisConstraints Value = llvm::StringSwitch<AnalysisConstraints>(Name) #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \ .Case(CMDFLAG, NAME##Model) #include "clang/StaticAnalyzer/Core/Analyses.def" .Default(NumConstraints); if (Value == NumConstraints) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; Success = false; } else { Opts.AnalysisConstraintsOpt = Value; } } if (Arg *A = Args.getLastArg(OPT_analyzer_output)) { StringRef Name = A->getValue(); AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name) #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) \ .Case(CMDFLAG, PD_##NAME) #include "clang/StaticAnalyzer/Core/Analyses.def" .Default(NUM_ANALYSIS_DIAG_CLIENTS); if (Value == NUM_ANALYSIS_DIAG_CLIENTS) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; Success = false; } else { Opts.AnalysisDiagOpt = Value; } } if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) { StringRef Name = A->getValue(); AnalysisPurgeMode Value = llvm::StringSwitch<AnalysisPurgeMode>(Name) #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \ .Case(CMDFLAG, NAME) #include "clang/StaticAnalyzer/Core/Analyses.def" .Default(NumPurgeModes); if (Value == NumPurgeModes) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; Success = false; } else { Opts.AnalysisPurgeOpt = Value; } } if (Arg *A = Args.getLastArg(OPT_analyzer_inlining_mode)) { StringRef Name = A->getValue(); AnalysisInliningMode Value = llvm::StringSwitch<AnalysisInliningMode>(Name) #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) \ .Case(CMDFLAG, NAME) #include "clang/StaticAnalyzer/Core/Analyses.def" .Default(NumInliningModes); if (Value == NumInliningModes) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; Success = false; } else { Opts.InliningMode = Value; } } Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help); Opts.DisableAllChecks = Args.hasArg(OPT_analyzer_disable_all_checks); Opts.visualizeExplodedGraphWithGraphViz = Args.hasArg(OPT_analyzer_viz_egraph_graphviz); Opts.visualizeExplodedGraphWithUbiGraph = Args.hasArg(OPT_analyzer_viz_egraph_ubigraph); Opts.NoRetryExhausted = Args.hasArg(OPT_analyzer_disable_retry_exhausted); Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers); Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress); Opts.AnalyzeNestedBlocks = Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks); Opts.eagerlyAssumeBinOpBifurcation = Args.hasArg(OPT_analyzer_eagerly_assume); Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function); Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG); Opts.TrimGraph = Args.hasArg(OPT_trim_egraph); Opts.maxBlockVisitOnPath = getLastArgIntValue(Args, OPT_analyzer_max_loop, 4, Diags); Opts.PrintStats = Args.hasArg(OPT_analyzer_stats); Opts.InlineMaxStackDepth = getLastArgIntValue(Args, OPT_analyzer_inline_max_stack_depth, Opts.InlineMaxStackDepth, Diags); Opts.CheckersControlList.clear(); for (const Arg *A : Args.filtered(OPT_analyzer_checker, OPT_analyzer_disable_checker)) { A->claim(); bool enable = (A->getOption().getID() == OPT_analyzer_checker); // We can have a list of comma separated checker names, e.g: // '-analyzer-checker=cocoa,unix' StringRef checkerList = A->getValue(); SmallVector<StringRef, 4> checkers; checkerList.split(checkers, ","); for (StringRef checker : checkers) Opts.CheckersControlList.emplace_back(checker, enable); } // Go through the analyzer configuration options. for (const Arg *A : Args.filtered(OPT_analyzer_config)) { A->claim(); // We can have a list of comma separated config names, e.g: // '-analyzer-config key1=val1,key2=val2' StringRef configList = A->getValue(); SmallVector<StringRef, 4> configVals; configList.split(configVals, ","); for (unsigned i = 0, e = configVals.size(); i != e; ++i) { StringRef key, val; std::tie(key, val) = configVals[i].split("="); if (val.empty()) { Diags.Report(SourceLocation(), diag::err_analyzer_config_no_value) << configVals[i]; Success = false; break; } if (val.find('=') != StringRef::npos) { Diags.Report(SourceLocation(), diag::err_analyzer_config_multiple_values) << configVals[i]; Success = false; break; } Opts.Config[key] = val; } } return Success; } static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) { Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error); Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal); return true; } static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) { Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands); Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments); } static StringRef getCodeModel(ArgList &Args, DiagnosticsEngine &Diags) { if (Arg *A = Args.getLastArg(OPT_mcode_model)) { StringRef Value = A->getValue(); if (Value == "small" || Value == "kernel" || Value == "medium" || Value == "large") return Value; Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Value; } return "default"; } /// \brief Create a new Regex instance out of the string value in \p RpassArg. /// It returns a pointer to the newly generated Regex instance. static std::shared_ptr<llvm::Regex> GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args, Arg *RpassArg) { StringRef Val = RpassArg->getValue(); std::string RegexError; std::shared_ptr<llvm::Regex> Pattern = std::make_shared<llvm::Regex>(Val); if (!Pattern->isValid(RegexError)) { Diags.Report(diag::err_drv_optimization_remark_pattern) << RegexError << RpassArg->getAsString(Args); Pattern.reset(); } return Pattern; } static bool parseDiagnosticLevelMask(StringRef FlagName, const std::vector<std::string> &Levels, DiagnosticsEngine *Diags, DiagnosticLevelMask &M) { bool Success = true; for (const auto &Level : Levels) { DiagnosticLevelMask const PM = llvm::StringSwitch<DiagnosticLevelMask>(Level) .Case("note", DiagnosticLevelMask::Note) .Case("remark", DiagnosticLevelMask::Remark) .Case("warning", DiagnosticLevelMask::Warning) .Case("error", DiagnosticLevelMask::Error) .Default(DiagnosticLevelMask::None); if (PM == DiagnosticLevelMask::None) { Success = false; if (Diags) Diags->Report(diag::err_drv_invalid_value) << FlagName << Level; } M = M | PM; } return Success; } static void parseSanitizerKinds(StringRef FlagName, const std::vector<std::string> &Sanitizers, DiagnosticsEngine &Diags, SanitizerSet &S) { for (const auto &Sanitizer : Sanitizers) { SanitizerMask K = parseSanitizerValue(Sanitizer, /*AllowGroups=*/false); if (K == 0) Diags.Report(diag::err_drv_invalid_value) << FlagName << Sanitizer; else S.set(K, true); } } static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags, const TargetOptions &TargetOpts) { using namespace options; bool Success = true; unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags); // TODO: This could be done in Driver unsigned MaxOptLevel = 3; if (OptimizationLevel > MaxOptLevel) { // If the optimization level is not supported, fall back on the default // optimization Diags.Report(diag::warn_drv_optimization_value) << Args.getLastArg(OPT_O)->getAsString(Args) << "-O" << MaxOptLevel; OptimizationLevel = MaxOptLevel; } Opts.OptimizationLevel = OptimizationLevel; // We must always run at least the always inlining pass. Opts.setInlining( (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining : CodeGenOptions::OnlyAlwaysInlining); // -fno-inline-functions overrides OptimizationLevel > 1. Opts.NoInline = Args.hasArg(OPT_fno_inline); Opts.setInlining(Args.hasArg(OPT_fno_inline_functions) ? CodeGenOptions::OnlyAlwaysInlining : Opts.getInlining()); if (Arg *A = Args.getLastArg(OPT_fveclib)) { StringRef Name = A->getValue(); if (Name == "Accelerate") Opts.setVecLib(CodeGenOptions::Accelerate); else if (Name == "none") Opts.setVecLib(CodeGenOptions::NoLibrary); else Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; } if (Args.hasArg(OPT_gline_tables_only)) { Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly); } else if (Args.hasArg(OPT_g_Flag) || Args.hasArg(OPT_gdwarf_2) || Args.hasArg(OPT_gdwarf_3) || Args.hasArg(OPT_gdwarf_4)) { bool Default = false; // Until dtrace (via CTF) and LLDB can deal with distributed debug info, // Darwin and FreeBSD default to standalone/full debug info. if (llvm::Triple(TargetOpts.Triple).isOSDarwin() || llvm::Triple(TargetOpts.Triple).isOSFreeBSD()) Default = true; if (Args.hasFlag(OPT_fstandalone_debug, OPT_fno_standalone_debug, Default)) Opts.setDebugInfo(CodeGenOptions::FullDebugInfo); else Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo); } Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info); Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); if (Args.hasArg(OPT_gdwarf_2)) Opts.DwarfVersion = 2; else if (Args.hasArg(OPT_gdwarf_3)) Opts.DwarfVersion = 3; else if (Args.hasArg(OPT_gdwarf_4)) Opts.DwarfVersion = 4; else if (Opts.getDebugInfo() != CodeGenOptions::NoDebugInfo) // Default Dwarf version is 4 if we are generating debug information. Opts.DwarfVersion = 4; if (const Arg *A = Args.getLastArg(OPT_emit_llvm_uselists, OPT_no_emit_llvm_uselists)) Opts.EmitLLVMUseLists = A->getOption().getID() == OPT_emit_llvm_uselists; Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); Opts.UseRegisterSizedBitfieldAccess = Args.hasArg( OPT_fuse_register_sized_bitfield_access); Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing); Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa); Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants); Opts.NoCommon = Args.hasArg(OPT_fno_common); Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float); Opts.OptimizeSize = getOptimizationLevelSize(Args); Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) || Args.hasArg(OPT_ffreestanding)); Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) || Args.hasArg(OPT_fprofile_instr_generate_EQ); Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ); Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ); Opts.CoverageMapping = Args.hasArg(OPT_fcoverage_mapping); Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping); Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit); Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases); Opts.CodeModel = getCodeModel(Args, Diags); Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass); Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim); Opts.DisableFree = Args.hasArg(OPT_disable_free); Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls); Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable); Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) || Args.hasArg(OPT_cl_finite_math_only) || Args.hasArg(OPT_cl_fast_relaxed_math)); Opts.NoNaNsFPMath = (Args.hasArg(OPT_menable_no_nans) || Args.hasArg(OPT_cl_unsafe_math_optimizations) || Args.hasArg(OPT_cl_finite_math_only) || Args.hasArg(OPT_cl_fast_relaxed_math)); Opts.NoSignedZeros = Args.hasArg(OPT_fno_signed_zeros); Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math); Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option); Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags); Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); Opts.EnableSegmentedStacks = Args.hasArg(OPT_split_stacks); Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); Opts.SoftFloat = Args.hasArg(OPT_msoft_float); Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums); Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) || Args.hasArg(OPT_cl_unsafe_math_optimizations) || Args.hasArg(OPT_cl_fast_relaxed_math); Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); Opts.ThreadModel = Args.getLastArgValue(OPT_mthread_model, "posix"); if (Opts.ThreadModel != "posix" && Opts.ThreadModel != "single") Diags.Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_mthread_model)->getAsString(Args) << Opts.ThreadModel; Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ); Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array); Opts.FunctionSections = Args.hasFlag(OPT_ffunction_sections, OPT_fno_function_sections, false); Opts.DataSections = Args.hasFlag(OPT_fdata_sections, OPT_fno_data_sections, false); Opts.UniqueSectionNames = Args.hasFlag(OPT_funique_section_names, OPT_fno_unique_section_names, true); Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions); Opts.PrepareForLTO = Args.hasArg(OPT_flto); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive); Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops); Opts.VectorizeSLP = Args.hasArg(OPT_vectorize_slp); Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier); Opts.DisableGCov = Args.hasArg(OPT_test_coverage); Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); if (Opts.EmitGcovArcs || Opts.EmitGcovNotes) { Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); Opts.CoverageExtraChecksum = Args.hasArg(OPT_coverage_cfg_checksum); Opts.CoverageNoFunctionNamesInData = Args.hasArg(OPT_coverage_no_function_names_in_data); Opts.CoverageExitBlockBeforeBody = Args.hasArg(OPT_coverage_exit_block_before_body); if (Args.hasArg(OPT_coverage_version_EQ)) { StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ); if (CoverageVersion.size() != 4) { Diags.Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_coverage_version_EQ)->getAsString(Args) << CoverageVersion; } else { memcpy(Opts.CoverageVersion, CoverageVersion.data(), 4); } } } Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); Opts.CompressDebugSections = Args.hasArg(OPT_compress_debug_sections); Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file); Opts.SanitizeCoverageType = getLastArgIntValue(Args, OPT_fsanitize_coverage_type, 0, Diags); Opts.SanitizeCoverageIndirectCalls = Args.hasArg(OPT_fsanitize_coverage_indirect_calls); Opts.SanitizeCoverageTraceBB = Args.hasArg(OPT_fsanitize_coverage_trace_bb); Opts.SanitizeCoverageTraceCmp = Args.hasArg(OPT_fsanitize_coverage_trace_cmp); Opts.SanitizeCoverage8bitCounters = Args.hasArg(OPT_fsanitize_coverage_8bit_counters); Opts.SanitizeMemoryTrackOrigins = getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, Diags); Opts.SanitizeMemoryUseAfterDtor = Args.hasArg(OPT_fsanitize_memory_use_after_dtor); Opts.SSPBufferSize = getLastArgIntValue(Args, OPT_stack_protector_buffer_size, 8, Diags); Opts.StackRealignment = Args.hasArg(OPT_mstackrealign); if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) { StringRef Val = A->getValue(); unsigned StackAlignment = Opts.StackAlignment; Val.getAsInteger(10, StackAlignment); Opts.StackAlignment = StackAlignment; } if (Arg *A = Args.getLastArg(OPT_mstack_probe_size)) { StringRef Val = A->getValue(); unsigned StackProbeSize = Opts.StackProbeSize; Val.getAsInteger(0, StackProbeSize); Opts.StackProbeSize = StackProbeSize; } if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { StringRef Name = A->getValue(); unsigned Method = llvm::StringSwitch<unsigned>(Name) .Case("legacy", CodeGenOptions::Legacy) .Case("non-legacy", CodeGenOptions::NonLegacy) .Case("mixed", CodeGenOptions::Mixed) .Default(~0U); if (Method == ~0U) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; Success = false; } else { Opts.setObjCDispatchMethod( static_cast<CodeGenOptions::ObjCDispatchMethodKind>(Method)); } } if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) { StringRef Name = A->getValue(); unsigned Model = llvm::StringSwitch<unsigned>(Name) .Case("global-dynamic", CodeGenOptions::GeneralDynamicTLSModel) .Case("local-dynamic", CodeGenOptions::LocalDynamicTLSModel) .Case("initial-exec", CodeGenOptions::InitialExecTLSModel) .Case("local-exec", CodeGenOptions::LocalExecTLSModel) .Default(~0U); if (Model == ~0U) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; Success = false; } else { Opts.setDefaultTLSModel(static_cast<CodeGenOptions::TLSModel>(Model)); } } if (Arg *A = Args.getLastArg(OPT_ffp_contract)) { StringRef Val = A->getValue(); if (Val == "fast") Opts.setFPContractMode(CodeGenOptions::FPC_Fast); else if (Val == "on") Opts.setFPContractMode(CodeGenOptions::FPC_On); else if (Val == "off") Opts.setFPContractMode(CodeGenOptions::FPC_Off); else Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } if (Arg *A = Args.getLastArg(OPT_fpcc_struct_return, OPT_freg_struct_return)) { if (A->getOption().matches(OPT_fpcc_struct_return)) { Opts.setStructReturnConvention(CodeGenOptions::SRCK_OnStack); } else { assert(A->getOption().matches(OPT_freg_struct_return)); Opts.setStructReturnConvention(CodeGenOptions::SRCK_InRegs); } } Opts.DependentLibraries = Args.getAllArgValues(OPT_dependent_lib); bool NeedLocTracking = false; if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) { Opts.OptimizationRemarkPattern = GenerateOptimizationRemarkRegex(Diags, Args, A); NeedLocTracking = true; } if (Arg *A = Args.getLastArg(OPT_Rpass_missed_EQ)) { Opts.OptimizationRemarkMissedPattern = GenerateOptimizationRemarkRegex(Diags, Args, A); NeedLocTracking = true; } if (Arg *A = Args.getLastArg(OPT_Rpass_analysis_EQ)) { Opts.OptimizationRemarkAnalysisPattern = GenerateOptimizationRemarkRegex(Diags, Args, A); NeedLocTracking = true; } // If the user requested to use a sample profile for PGO, then the // backend will need to track source location information so the profile // can be incorporated into the IR. if (!Opts.SampleProfileFile.empty()) NeedLocTracking = true; // If the user requested a flag that requires source locations available in // the backend, make sure that the backend tracks source location information. if (NeedLocTracking && Opts.getDebugInfo() == CodeGenOptions::NoDebugInfo) Opts.setDebugInfo(CodeGenOptions::LocTrackingOnly); Opts.RewriteMapFiles = Args.getAllArgValues(OPT_frewrite_map_file); // Parse -fsanitize-recover= arguments. // FIXME: Report unrecoverable sanitizers incorrectly specified here. parseSanitizerKinds("-fsanitize-recover=", Args.getAllArgValues(OPT_fsanitize_recover_EQ), Diags, Opts.SanitizeRecover); parseSanitizerKinds("-fsanitize-trap=", Args.getAllArgValues(OPT_fsanitize_trap_EQ), Diags, Opts.SanitizeTrap); Opts.CudaGpuBinaryFileNames = Args.getAllArgValues(OPT_fcuda_include_gpubinary); Opts.HLSLEntryFunction = Args.getLastArgValue(OPT_hlsl_entry); return Success; } static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, ArgList &Args) { using namespace options; Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file); Opts.Targets = Args.getAllArgValues(OPT_MT); Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps); Opts.IncludeModuleFiles = Args.hasArg(OPT_module_file_deps); Opts.UsePhonyTargets = Args.hasArg(OPT_MP); Opts.ShowHeaderIncludes = Args.hasArg(OPT_H); Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file); Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG); Opts.PrintShowIncludes = Args.hasArg(OPT_show_includes); Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot); Opts.ModuleDependencyOutputDir = Args.getLastArgValue(OPT_module_dependency_dir); if (Args.hasArg(OPT_MV)) Opts.OutputFormat = DependencyOutputFormat::NMake; } bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, DiagnosticsEngine *Diags) { using namespace options; bool Success = true; Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file); if (Arg *A = Args.getLastArg(OPT_diagnostic_serialized_file, OPT__serialize_diags)) Opts.DiagnosticSerializationFile = A->getValue(); Opts.IgnoreWarnings = Args.hasArg(OPT_w); Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros); Opts.Pedantic = Args.hasArg(OPT_pedantic); Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors); Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics); Opts.ShowColors = Args.hasArg(OPT_fcolor_diagnostics); Opts.ShowColumn = Args.hasFlag(OPT_fshow_column, OPT_fno_show_column, /*Default=*/true); Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); #ifdef MSFT_SUPPORTS_ANSI_ESCAPE_CODES llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes)); #endif // Default behavior is to not to show note include stacks. Opts.ShowNoteIncludeStack = false; if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack, OPT_fno_diagnostics_show_note_include_stack)) if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack)) Opts.ShowNoteIncludeStack = true; StringRef ShowOverloads = Args.getLastArgValue(OPT_fshow_overloads_EQ, "all"); if (ShowOverloads == "best") Opts.setShowOverloads(Ovl_Best); else if (ShowOverloads == "all") Opts.setShowOverloads(Ovl_All); else { Success = false; if (Diags) Diags->Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args) << ShowOverloads; } StringRef ShowCategory = Args.getLastArgValue(OPT_fdiagnostics_show_category, "none"); if (ShowCategory == "none") Opts.ShowCategories = 0; else if (ShowCategory == "id") Opts.ShowCategories = 1; else if (ShowCategory == "name") Opts.ShowCategories = 2; else { Success = false; if (Diags) Diags->Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) << ShowCategory; } StringRef Format = Args.getLastArgValue(OPT_fdiagnostics_format, "clang"); if (Format == "clang") Opts.setFormat(DiagnosticOptions::Clang); else if (Format == "msvc") Opts.setFormat(DiagnosticOptions::MSVC); else if (Format == "msvc-fallback") { Opts.setFormat(DiagnosticOptions::MSVC); Opts.CLFallbackMode = true; } else if (Format == "vi") Opts.setFormat(DiagnosticOptions::Vi); else { Success = false; if (Diags) Diags->Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) << Format; } Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location); Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); DiagnosticLevelMask DiagMask = DiagnosticLevelMask::None; Success &= parseDiagnosticLevelMask("-verify-ignore-unexpected=", Args.getAllArgValues(OPT_verify_ignore_unexpected_EQ), Diags, DiagMask); if (Args.hasArg(OPT_verify_ignore_unexpected)) DiagMask = DiagnosticLevelMask::All; Opts.setVerifyIgnoreUnexpected(DiagMask); Opts.ElideType = !Args.hasArg(OPT_fno_elide_type); Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree); Opts.ErrorLimit = getLastArgIntValue(Args, OPT_ferror_limit, 0, Diags); Opts.MacroBacktraceLimit = getLastArgIntValue(Args, OPT_fmacro_backtrace_limit, DiagnosticOptions::DefaultMacroBacktraceLimit, Diags); Opts.TemplateBacktraceLimit = getLastArgIntValue( Args, OPT_ftemplate_backtrace_limit, DiagnosticOptions::DefaultTemplateBacktraceLimit, Diags); Opts.ConstexprBacktraceLimit = getLastArgIntValue( Args, OPT_fconstexpr_backtrace_limit, DiagnosticOptions::DefaultConstexprBacktraceLimit, Diags); Opts.SpellCheckingLimit = getLastArgIntValue( Args, OPT_fspell_checking_limit, DiagnosticOptions::DefaultSpellCheckingLimit, Diags); Opts.TabStop = getLastArgIntValue(Args, OPT_ftabstop, DiagnosticOptions::DefaultTabStop, Diags); if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) { Opts.TabStop = DiagnosticOptions::DefaultTabStop; if (Diags) Diags->Report(diag::warn_ignoring_ftabstop_value) << Opts.TabStop << DiagnosticOptions::DefaultTabStop; } Opts.MessageLength = getLastArgIntValue(Args, OPT_fmessage_length, 0, Diags); addDiagnosticArgs(Args, OPT_W_Group, OPT_W_value_Group, Opts.Warnings); addDiagnosticArgs(Args, OPT_R_Group, OPT_R_value_Group, Opts.Remarks); return Success; } static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) { Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory); } static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags) { using namespace options; Opts.ProgramAction = frontend::ParseSyntaxOnly; if (const Arg *A = Args.getLastArg(OPT_Action_Group)) { switch (A->getOption().getID()) { default: llvm_unreachable("Invalid option in group!"); case OPT_ast_list: Opts.ProgramAction = frontend::ASTDeclList; break; case OPT_ast_dump: case OPT_ast_dump_lookups: Opts.ProgramAction = frontend::ASTDump; break; case OPT_ast_print: Opts.ProgramAction = frontend::ASTPrint; break; case OPT_ast_view: Opts.ProgramAction = frontend::ASTView; break; case OPT_dump_raw_tokens: Opts.ProgramAction = frontend::DumpRawTokens; break; case OPT_dump_tokens: Opts.ProgramAction = frontend::DumpTokens; break; case OPT_S: Opts.ProgramAction = frontend::EmitAssembly; break; case OPT_emit_llvm_bc: Opts.ProgramAction = frontend::EmitBC; break; case OPT_emit_html: Opts.ProgramAction = frontend::EmitHTML; break; case OPT_emit_llvm: Opts.ProgramAction = frontend::EmitLLVM; break; case OPT_emit_llvm_only: Opts.ProgramAction = frontend::EmitLLVMOnly; break; case OPT_emit_codegen_only: Opts.ProgramAction = frontend::EmitCodeGenOnly; break; case OPT_emit_obj: Opts.ProgramAction = frontend::EmitObj; break; case OPT_fixit_EQ: Opts.FixItSuffix = A->getValue(); LLVM_FALLTHROUGH; // HLSL Change case OPT_fixit: Opts.ProgramAction = frontend::FixIt; break; case OPT_emit_module: Opts.ProgramAction = frontend::GenerateModule; break; case OPT_emit_pch: Opts.ProgramAction = frontend::GeneratePCH; break; case OPT_emit_pth: Opts.ProgramAction = frontend::GeneratePTH; break; case OPT_init_only: Opts.ProgramAction = frontend::InitOnly; break; case OPT_fsyntax_only: Opts.ProgramAction = frontend::ParseSyntaxOnly; break; case OPT_module_file_info: Opts.ProgramAction = frontend::ModuleFileInfo; break; case OPT_verify_pch: Opts.ProgramAction = frontend::VerifyPCH; break; case OPT_print_decl_contexts: Opts.ProgramAction = frontend::PrintDeclContext; break; case OPT_print_preamble: Opts.ProgramAction = frontend::PrintPreamble; break; case OPT_E: Opts.ProgramAction = frontend::PrintPreprocessedInput; break; case OPT_rewrite_macros: Opts.ProgramAction = frontend::RewriteMacros; break; case OPT_rewrite_objc: Opts.ProgramAction = frontend::RewriteObjC; break; case OPT_rewrite_test: Opts.ProgramAction = frontend::RewriteTest; break; case OPT_analyze: Opts.ProgramAction = frontend::RunAnalysis; break; case OPT_migrate: Opts.ProgramAction = frontend::MigrateSource; break; case OPT_Eonly: Opts.ProgramAction = frontend::RunPreprocessorOnly; break; } } if (const Arg* A = Args.getLastArg(OPT_plugin)) { Opts.Plugins.emplace_back(A->getValue(0)); Opts.ProgramAction = frontend::PluginAction; Opts.ActionName = A->getValue(); for (const Arg *AA : Args.filtered(OPT_plugin_arg)) if (AA->getValue(0) == Opts.ActionName) Opts.PluginArgs.emplace_back(AA->getValue(1)); } Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin); Opts.AddPluginArgs.resize(Opts.AddPluginActions.size()); for (int i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) for (const Arg *A : Args.filtered(OPT_plugin_arg)) if (A->getValue(0) == Opts.AddPluginActions[i]) Opts.AddPluginArgs[i].emplace_back(A->getValue(1)); if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) { Opts.CodeCompletionAt = ParsedSourceLocation::FromString(A->getValue()); if (Opts.CodeCompletionAt.FileName.empty()) Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); } Opts.DisableFree = Args.hasArg(OPT_disable_free); Opts.OutputFile = Args.getLastArgValue(OPT_o); Opts.Plugins = Args.getAllArgValues(OPT_load); Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch); Opts.ShowHelp = Args.hasArg(OPT_help); Opts.ShowStats = Args.hasArg(OPT_print_stats); Opts.ShowTimers = Args.hasArg(OPT_ftime_report); // HLSL Change Begin - Support hierarchial time tracing. Opts.TimeTrace = Args.hasArg(OPT_ftime_trace); // HLSL Change End - Support hierarchial time tracing. Opts.ShowVersion = Args.hasArg(OPT_version); Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge); Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can); Opts.FixOnlyWarnings = Args.hasArg(OPT_fix_only_warnings); Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile); Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp); Opts.ASTDumpDecls = Args.hasArg(OPT_ast_dump); Opts.ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter); Opts.ASTDumpLookups = Args.hasArg(OPT_ast_dump_lookups); Opts.UseGlobalModuleIndex = !Args.hasArg(OPT_fno_modules_global_index); Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex; Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file); Opts.ModuleFiles = Args.getAllArgValues(OPT_fmodule_file); Opts.CodeCompleteOpts.IncludeMacros = Args.hasArg(OPT_code_completion_macros); Opts.CodeCompleteOpts.IncludeCodePatterns = Args.hasArg(OPT_code_completion_patterns); Opts.CodeCompleteOpts.IncludeGlobals = !Args.hasArg(OPT_no_code_completion_globals); Opts.CodeCompleteOpts.IncludeBriefComments = Args.hasArg(OPT_code_completion_brief_comments); Opts.OverrideRecordLayoutsFile = Args.getLastArgValue(OPT_foverride_record_layout_EQ); if (const Arg *A = Args.getLastArg(OPT_arcmt_check, OPT_arcmt_modify, OPT_arcmt_migrate)) { switch (A->getOption().getID()) { default: llvm_unreachable("missed a case"); case OPT_arcmt_check: Opts.ARCMTAction = FrontendOptions::ARCMT_Check; break; case OPT_arcmt_modify: Opts.ARCMTAction = FrontendOptions::ARCMT_Modify; break; case OPT_arcmt_migrate: Opts.ARCMTAction = FrontendOptions::ARCMT_Migrate; break; } } Opts.MTMigrateDir = Args.getLastArgValue(OPT_mt_migrate_directory); Opts.ARCMTMigrateReportOut = Args.getLastArgValue(OPT_arcmt_migrate_report_output); Opts.ARCMTMigrateEmitARCErrors = Args.hasArg(OPT_arcmt_migrate_emit_arc_errors); if (Args.hasArg(OPT_objcmt_migrate_literals)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Literals; if (Args.hasArg(OPT_objcmt_migrate_subscripting)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Subscripting; if (Args.hasArg(OPT_objcmt_migrate_property_dot_syntax)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_PropertyDotSyntax; if (Args.hasArg(OPT_objcmt_migrate_property)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Property; if (Args.hasArg(OPT_objcmt_migrate_readonly_property)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReadonlyProperty; if (Args.hasArg(OPT_objcmt_migrate_readwrite_property)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReadwriteProperty; if (Args.hasArg(OPT_objcmt_migrate_annotation)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Annotation; if (Args.hasArg(OPT_objcmt_returns_innerpointer_property)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReturnsInnerPointerProperty; if (Args.hasArg(OPT_objcmt_migrate_instancetype)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Instancetype; if (Args.hasArg(OPT_objcmt_migrate_nsmacros)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_NsMacros; if (Args.hasArg(OPT_objcmt_migrate_protocol_conformance)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ProtocolConformance; if (Args.hasArg(OPT_objcmt_atomic_property)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_AtomicProperty; if (Args.hasArg(OPT_objcmt_ns_nonatomic_iosonly)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_NsAtomicIOSOnlyProperty; if (Args.hasArg(OPT_objcmt_migrate_designated_init)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_DesignatedInitializer; if (Args.hasArg(OPT_objcmt_migrate_all)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_MigrateDecls; Opts.ObjCMTWhiteListPath = Args.getLastArgValue(OPT_objcmt_whitelist_dir_path); if (Opts.ARCMTAction != FrontendOptions::ARCMT_None && Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) { Diags.Report(diag::err_drv_argument_not_allowed_with) << "ARC migration" << "ObjC migration"; } InputKind DashX = IK_None; if (const Arg *A = Args.getLastArg(OPT_x)) { DashX = llvm::StringSwitch<InputKind>(A->getValue()) .Case("c", IK_C) .Case("cl", IK_OpenCL) .Case("cuda", IK_CUDA) .Case("c++", IK_CXX) .Case("objective-c", IK_ObjC) .Case("objective-c++", IK_ObjCXX) .Case("cpp-output", IK_PreprocessedC) .Case("assembler-with-cpp", IK_Asm) .Case("c++-cpp-output", IK_PreprocessedCXX) .Case("cuda-cpp-output", IK_PreprocessedCuda) .Case("objective-c-cpp-output", IK_PreprocessedObjC) .Case("objc-cpp-output", IK_PreprocessedObjC) .Case("objective-c++-cpp-output", IK_PreprocessedObjCXX) .Case("objc++-cpp-output", IK_PreprocessedObjCXX) .Case("c-header", IK_C) .Case("cl-header", IK_OpenCL) .Case("objective-c-header", IK_ObjC) .Case("c++-header", IK_CXX) .Case("objective-c++-header", IK_ObjCXX) .Cases("ast", "pcm", IK_AST) .Case("ir", IK_LLVM_IR) .Case("hlsl", IK_HLSL) // HLSL Change: Default File extension for hlsl files .Default(IK_None); if (DashX == IK_None) Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); } // '-' is the default input if none is given. std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT); Opts.Inputs.clear(); if (Inputs.empty()) Inputs.push_back("-"); for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { InputKind IK = DashX; if (IK == IK_None) { IK = FrontendOptions::getInputKindForExtension( StringRef(Inputs[i]).rsplit('.').second); // FIXME: Remove this hack. if (i == 0) DashX = IK; } Opts.Inputs.emplace_back(std::move(Inputs[i]), IK); } return DashX; } std::string CompilerInvocation::GetResourcesPath(const char *Argv0, void *MainAddr) { std::string ClangExecutable = llvm::sys::fs::getMainExecutable(Argv0, MainAddr); StringRef Dir = llvm::sys::path::parent_path(ClangExecutable); // Compute the path to the resource directory. StringRef ClangResourceDir(CLANG_RESOURCE_DIR); SmallString<128> P(Dir); if (ClangResourceDir != "") { llvm::sys::path::append(P, ClangResourceDir); } else { StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX); llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang", CLANG_VERSION_STRING); } return P.str(); } static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { using namespace options; Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/"); Opts.Verbose = Args.hasArg(OPT_v); Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc); Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc); Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx); if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ)) Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0); Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir); Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodules_cache_path); Opts.ModuleUserBuildPath = Args.getLastArgValue(OPT_fmodules_user_build_path); Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash); Opts.ImplicitModuleMaps = Args.hasArg(OPT_fimplicit_module_maps); Opts.ModuleMapFileHomeIsCwd = Args.hasArg(OPT_fmodule_map_file_home_is_cwd); Opts.ModuleCachePruneInterval = getLastArgIntValue(Args, OPT_fmodules_prune_interval, 7 * 24 * 60 * 60); Opts.ModuleCachePruneAfter = getLastArgIntValue(Args, OPT_fmodules_prune_after, 31 * 24 * 60 * 60); Opts.ModulesValidateOncePerBuildSession = Args.hasArg(OPT_fmodules_validate_once_per_build_session); Opts.BuildSessionTimestamp = getLastArgUInt64Value(Args, OPT_fbuild_session_timestamp, 0); Opts.ModulesValidateSystemHeaders = Args.hasArg(OPT_fmodules_validate_system_headers); if (const Arg *A = Args.getLastArg(OPT_fmodule_format_EQ)) Opts.ModuleFormat = A->getValue(); for (const Arg *A : Args.filtered(OPT_fmodules_ignore_macro)) { StringRef MacroDef = A->getValue(); Opts.ModulesIgnoreMacros.insert(MacroDef.split('=').first); } // Add -I..., -F..., and -index-header-map options in order. bool IsIndexHeaderMap = false; for (const Arg *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) { if (A->getOption().matches(OPT_index_header_map)) { // -index-header-map applies to the next -I or -F. IsIndexHeaderMap = true; continue; } frontend::IncludeDirGroup Group = IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled; Opts.AddPath(A->getValue(), Group, /*IsFramework=*/A->getOption().matches(OPT_F), true); IsIndexHeaderMap = false; } // Add -iprefix/-iwithprefix/-iwithprefixbefore options. StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. for (const Arg *A : Args.filtered(OPT_iprefix, OPT_iwithprefix, OPT_iwithprefixbefore)) { if (A->getOption().matches(OPT_iprefix)) Prefix = A->getValue(); else if (A->getOption().matches(OPT_iwithprefix)) Opts.AddPath(Prefix.str() + A->getValue(), frontend::After, false, true); else Opts.AddPath(Prefix.str() + A->getValue(), frontend::Angled, false, true); } for (const Arg *A : Args.filtered(OPT_idirafter)) Opts.AddPath(A->getValue(), frontend::After, false, true); for (const Arg *A : Args.filtered(OPT_iquote)) Opts.AddPath(A->getValue(), frontend::Quoted, false, true); for (const Arg *A : Args.filtered(OPT_isystem, OPT_iwithsysroot)) Opts.AddPath(A->getValue(), frontend::System, false, !A->getOption().matches(OPT_iwithsysroot)); for (const Arg *A : Args.filtered(OPT_iframework)) Opts.AddPath(A->getValue(), frontend::System, true, true); // Add the paths for the various language specific isystem flags. for (const Arg *A : Args.filtered(OPT_c_isystem)) Opts.AddPath(A->getValue(), frontend::CSystem, false, true); for (const Arg *A : Args.filtered(OPT_cxx_isystem)) Opts.AddPath(A->getValue(), frontend::CXXSystem, false, true); for (const Arg *A : Args.filtered(OPT_objc_isystem)) Opts.AddPath(A->getValue(), frontend::ObjCSystem, false,true); for (const Arg *A : Args.filtered(OPT_objcxx_isystem)) Opts.AddPath(A->getValue(), frontend::ObjCXXSystem, false, true); // Add the internal paths from a driver that detects standard include paths. for (const Arg *A : Args.filtered(OPT_internal_isystem, OPT_internal_externc_isystem)) { frontend::IncludeDirGroup Group = frontend::System; if (A->getOption().matches(OPT_internal_externc_isystem)) Group = frontend::ExternCSystem; Opts.AddPath(A->getValue(), Group, false, true); } // Add the path prefixes which are implicitly treated as being system headers. for (const Arg *A : Args.filtered(OPT_system_header_prefix, OPT_no_system_header_prefix)) Opts.AddSystemHeaderPrefix( A->getValue(), A->getOption().matches(OPT_system_header_prefix)); for (const Arg *A : Args.filtered(OPT_ivfsoverlay)) Opts.AddVFSOverlayFile(A->getValue()); } void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, LangStandard::Kind LangStd) { // Set some properties which depend solely on the input kind; it would be nice // to move these to the language standard, and have the driver resolve the // input kind + language standard. #ifdef MS_SUPPORT_VARIABLE_LANGOPTS if (IK == IK_Asm) { Opts.AsmPreprocessor = 1; } else if (IK == IK_ObjC || IK == IK_ObjCXX || IK == IK_PreprocessedObjC || IK == IK_PreprocessedObjCXX) { Opts.ObjC1 = Opts.ObjC2 = 1; } if (LangStd == LangStandard::lang_unspecified) { // Based on the base language, pick one. switch (IK) { case IK_None: case IK_AST: case IK_LLVM_IR: llvm_unreachable("Invalid input kind!"); case IK_OpenCL: LangStd = LangStandard::lang_opencl; break; case IK_CUDA: case IK_PreprocessedCuda: LangStd = LangStandard::lang_cuda; break; case IK_Asm: case IK_C: case IK_PreprocessedC: case IK_ObjC: case IK_PreprocessedObjC: LangStd = LangStandard::lang_gnu11; break; case IK_CXX: case IK_PreprocessedCXX: case IK_ObjCXX: case IK_PreprocessedObjCXX: LangStd = LangStandard::lang_gnucxx98; break; case IK_HLSL: // HLSL Change: LangStandard for Input Kind files for HLSL LangStd = LangStandard::lang_hlsl; break; } } const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); Opts.LineComment = Std.hasLineComments(); Opts.C99 = Std.isC99(); Opts.C11 = Std.isC11(); Opts.CPlusPlus = Std.isCPlusPlus(); Opts.CPlusPlus11 = Std.isCPlusPlus11(); Opts.CPlusPlus14 = Std.isCPlusPlus14(); Opts.CPlusPlus1z = Std.isCPlusPlus1z(); Opts.Digraphs = Std.hasDigraphs(); Opts.GNUMode = Std.isGNUMode(); Opts.GNUInline = Std.isC89(); Opts.HexFloats = Std.hasHexFloats(); Opts.ImplicitInt = Std.hasImplicitInt(); // Set OpenCL Version. Opts.OpenCL = LangStd == LangStandard::lang_opencl || IK == IK_OpenCL; if (LangStd == LangStandard::lang_opencl) Opts.OpenCLVersion = 100; else if (LangStd == LangStandard::lang_opencl11) Opts.OpenCLVersion = 110; else if (LangStd == LangStandard::lang_opencl12) Opts.OpenCLVersion = 120; else if (LangStd == LangStandard::lang_opencl20) Opts.OpenCLVersion = 200; // OpenCL has some additional defaults. if (Opts.OpenCL) { Opts.AltiVec = 0; Opts.ZVector = 0; Opts.CXXOperatorNames = 1; Opts.LaxVectorConversions = 0; Opts.DefaultFPContract = 1; Opts.NativeHalfType = 1; } Opts.HLSL = IK == IK_HLSL || LangStd == LangStandard::lang_hlsl; // HLSL Change: Langstandard for HLSL Opts.CUDA = IK == IK_CUDA || IK == IK_PreprocessedCuda || LangStd == LangStandard::lang_cuda; // OpenCL and C++ both have bool, true, false keywords. Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; // OpenCL has half keyword Opts.Half = Opts.OpenCL; // C++ has wchar_t keyword. Opts.WChar = Opts.CPlusPlus; Opts.GNUKeywords = Opts.GNUMode; Opts.CXXOperatorNames = Opts.CPlusPlus; Opts.DollarIdents = !Opts.AsmPreprocessor; #endif } #ifdef MS_SUPPORT_VARIABLE_LANGOPTS /// Attempt to parse a visibility value out of the given argument. static Visibility parseVisibility(Arg *arg, ArgList &args, DiagnosticsEngine &diags) { StringRef value = arg->getValue(); if (value == "default") { return DefaultVisibility; } else if (value == "hidden") { return HiddenVisibility; } else if (value == "protected") { // FIXME: diagnose if target does not support protected visibility return ProtectedVisibility; } diags.Report(diag::err_drv_invalid_value) << arg->getAsString(args) << value; return DefaultVisibility; } #endif // MS_SUPPORT_VARIABLE_LANGOPTS static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags) { #ifdef MS_SUPPORT_VARIABLE_LANGOPTS // FIXME: Cleanup per-file based stuff. LangStandard::Kind LangStd = LangStandard::lang_unspecified; if (const Arg *A = Args.getLastArg(OPT_std_EQ)) { LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) #define LANGSTANDARD(id, name, desc, features) \ .Case(name, LangStandard::lang_##id) #include "clang/Frontend/LangStandards.def" .Default(LangStandard::lang_unspecified); if (LangStd == LangStandard::lang_unspecified) Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); else { // Valid standard, check to make sure language and standard are // compatible. const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); switch (IK) { case IK_C: case IK_ObjC: case IK_PreprocessedC: case IK_PreprocessedObjC: if (!(Std.isC89() || Std.isC99())) Diags.Report(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "C/ObjC"; break; case IK_CXX: case IK_ObjCXX: case IK_PreprocessedCXX: case IK_PreprocessedObjCXX: if (!Std.isCPlusPlus()) Diags.Report(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "C++/ObjC++"; break; case IK_OpenCL: if (!Std.isC99()) Diags.Report(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "OpenCL"; break; case IK_CUDA: case IK_PreprocessedCuda: if (!Std.isCPlusPlus()) Diags.Report(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) << "CUDA"; break; default: break; } } } // -cl-std only applies for OpenCL language standards. // Override the -std option in this case. if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { LangStandard::Kind OpenCLLangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) .Case("CL", LangStandard::lang_opencl) .Case("CL1.1", LangStandard::lang_opencl11) .Case("CL1.2", LangStandard::lang_opencl12) .Case("CL2.0", LangStandard::lang_opencl20) .Default(LangStandard::lang_unspecified); if (OpenCLLangStd == LangStandard::lang_unspecified) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); } else LangStd = OpenCLLangStd; } CompilerInvocation::setLangDefaults(Opts, IK, LangStd); // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension // keywords. This behavior is provided by GCC's poorly named '-fasm' flag, // while a subset (the non-C++ GNU keywords) is provided by GCC's // '-fgnu-keywords'. Clang conflates the two for simplicity under the single // name, as it doesn't seem a useful distinction. Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords, Opts.GNUKeywords); if (Args.hasArg(OPT_fno_operator_names)) Opts.CXXOperatorNames = 0; if (Args.hasArg(OPT_fcuda_is_device)) Opts.CUDAIsDevice = 1; if (Args.hasArg(OPT_fcuda_allow_host_calls_from_host_device)) Opts.CUDAAllowHostCallsFromHostDevice = 1; if (Args.hasArg(OPT_fcuda_disable_target_call_checks)) Opts.CUDADisableTargetCallChecks = 1; if (Opts.ObjC1) { if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) { StringRef value = arg->getValue(); if (Opts.ObjCRuntime.tryParse(value)) Diags.Report(diag::err_drv_unknown_objc_runtime) << value; } if (Args.hasArg(OPT_fobjc_gc_only)) Opts.setGC(LangOptions::GCOnly); else if (Args.hasArg(OPT_fobjc_gc)) Opts.setGC(LangOptions::HybridGC); else if (Args.hasArg(OPT_fobjc_arc)) { Opts.ObjCAutoRefCount = 1; if (!Opts.ObjCRuntime.allowsARC()) Diags.Report(diag::err_arc_unsupported_on_runtime); // Only set ObjCARCWeak if ARC is enabled. if (Args.hasArg(OPT_fobjc_runtime_has_weak)) Opts.ObjCARCWeak = 1; else Opts.ObjCARCWeak = Opts.ObjCRuntime.allowsWeak(); } if (Args.hasArg(OPT_fno_objc_infer_related_result_type)) Opts.ObjCInferRelatedResultType = 0; if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime)) Opts.ObjCSubscriptingLegacyRuntime = (Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX); } if (Args.hasArg(OPT_fgnu89_inline)) { if (Opts.CPlusPlus) Diags.Report(diag::err_drv_argument_not_allowed_with) << "-fgnu89-inline" << "C++/ObjC++"; else Opts.GNUInline = 1; } if (Args.hasArg(OPT_fapple_kext)) { if (!Opts.CPlusPlus) Diags.Report(diag::warn_c_kext); else Opts.AppleKext = 1; } if (Args.hasArg(OPT_print_ivar_layout)) Opts.ObjCGCBitmapPrint = 1; if (Args.hasArg(OPT_fno_constant_cfstrings)) Opts.NoConstantCFStrings = 1; if (Args.hasArg(OPT_faltivec)) Opts.AltiVec = 1; if (Args.hasArg(OPT_fzvector)) Opts.ZVector = 1; if (Args.hasArg(OPT_pthread)) Opts.POSIXThreads = 1; // The value-visibility mode defaults to "default". if (Arg *visOpt = Args.getLastArg(OPT_fvisibility)) { Opts.setValueVisibilityMode(parseVisibility(visOpt, Args, Diags)); } else { Opts.setValueVisibilityMode(DefaultVisibility); } // The type-visibility mode defaults to the value-visibility mode. if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) { Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags)); } else { Opts.setTypeVisibilityMode(Opts.getValueVisibilityMode()); } if (Args.hasArg(OPT_fvisibility_inlines_hidden)) Opts.InlineVisibilityHidden = 1; if (Args.hasArg(OPT_ftrapv)) { Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping); // Set the handler, if one is specified. Opts.OverflowHandler = Args.getLastArgValue(OPT_ftrapv_handler); } else if (Args.hasArg(OPT_fwrapv)) Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined); Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility); Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions); Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt; Opts.MSCompatibilityVersion = 0; if (const Arg *A = Args.getLastArg(OPT_fms_compatibility_version)) { VersionTuple VT; if (VT.tryParse(A->getValue())) Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); Opts.MSCompatibilityVersion = VT.getMajor() * 10000000 + VT.getMinor().getValueOr(0) * 100000 + VT.getSubminor().getValueOr(0); } // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs // is specified, or -std is set to a conforming mode. // Trigraphs are disabled by default in c++1z onwards. Opts.Trigraphs = !Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus1z; Opts.Trigraphs = Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs); Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, OPT_fno_dollars_in_identifiers, Opts.DollarIdents); Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); Opts.VtorDispMode = getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags); Opts.Borland = Args.hasArg(OPT_fborland_extensions); Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings, Opts.ConstStrings); if (Args.hasArg(OPT_fno_lax_vector_conversions)) Opts.LaxVectorConversions = 0; if (Args.hasArg(OPT_fno_threadsafe_statics)) Opts.ThreadsafeStatics = 0; Opts.Exceptions = Args.hasArg(OPT_fexceptions); Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions); Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions); Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp); Opts.RTTI = !Args.hasArg(OPT_fno_rtti); Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data); Opts.Blocks = Args.hasArg(OPT_fblocks); Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); Opts.Modules = Args.hasArg(OPT_fmodules); Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse); Opts.ModulesDeclUse = Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse; Opts.ModulesLocalVisibility = Args.hasArg(OPT_fmodules_local_submodule_visibility); Opts.ModulesHideInternalLinkage = !Args.hasArg(OPT_fno_modules_hide_internal_linkage); Opts.ModulesSearchAll = Opts.Modules && !Args.hasArg(OPT_fno_modules_search_all) && Args.hasArg(OPT_fmodules_search_all); Opts.ModulesErrorRecovery = !Args.hasArg(OPT_fno_modules_error_recovery); Opts.ImplicitModules = !Args.hasArg(OPT_fno_implicit_modules); Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char); Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar); Opts.ShortWChar = Args.hasFlag(OPT_fshort_wchar, OPT_fno_short_wchar, false); Opts.ShortEnums = Args.hasArg(OPT_fshort_enums); Opts.Freestanding = Args.hasArg(OPT_ffreestanding); Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; Opts.NoMathBuiltin = Args.hasArg(OPT_fno_math_builtin); Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); Opts.SizedDeallocation = Args.hasArg(OPT_fsized_deallocation); Opts.ConceptsTS = Args.hasArg(OPT_fconcepts_ts); Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); Opts.AccessControl = !Args.hasArg(OPT_fno_access_control); Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); Opts.MathErrno = !Opts.OpenCL && Args.hasArg(OPT_fmath_errno); Opts.InstantiationDepth = getLastArgIntValue(Args, OPT_ftemplate_depth, 256, Diags); Opts.ArrowDepth = getLastArgIntValue(Args, OPT_foperator_arrow_depth, 256, Diags); Opts.ConstexprCallDepth = getLastArgIntValue(Args, OPT_fconstexpr_depth, 512, Diags); Opts.ConstexprStepLimit = getLastArgIntValue(Args, OPT_fconstexpr_steps, 1048576, Diags); Opts.BracketDepth = getLastArgIntValue(Args, OPT_fbracket_depth, 256, Diags); Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing); Opts.NumLargeByValueCopy = getLastArgIntValue(Args, OPT_Wlarge_by_value_copy_EQ, 0, Diags); Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields); Opts.ObjCConstantStringClass = Args.getLastArgValue(OPT_fconstant_string_class); Opts.ObjCDefaultSynthProperties = !Args.hasArg(OPT_disable_objc_default_synthesize_properties); Opts.EncodeExtendedBlockSig = Args.hasArg(OPT_fencode_extended_block_signature); Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags); Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, Diags); Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); Opts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags); Opts.Static = Args.hasArg(OPT_static_define); Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple); Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple || Args.hasArg(OPT_fdump_record_layouts); Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts); Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking); Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); Opts.MRTD = Args.hasArg(OPT_mrtd); Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat); Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map); Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype); Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support); Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id); Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal); Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack); Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); Opts.AppExt = Args.hasArg(OPT_fapplication_extension); Opts.ImplementationOfModule = Args.getLastArgValue(OPT_fmodule_implementation_of); Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature); std::sort(Opts.ModuleFeatures.begin(), Opts.ModuleFeatures.end()); Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type); Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns); Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm); if (!Opts.CurrentModule.empty() && !Opts.ImplementationOfModule.empty() && Opts.CurrentModule != Opts.ImplementationOfModule) { Diags.Report(diag::err_conflicting_module_names) << Opts.CurrentModule << Opts.ImplementationOfModule; } // For now, we only support local submodule visibility in C++ (because we // heavily depend on the ODR for merging redefinitions). if (Opts.ModulesLocalVisibility && !Opts.CPlusPlus) Diags.Report(diag::err_drv_argument_not_allowed_with) << "-fmodules-local-submodule-visibility" << "C"; if (Arg *A = Args.getLastArg(OPT_faddress_space_map_mangling_EQ)) { switch (llvm::StringSwitch<unsigned>(A->getValue()) .Case("target", LangOptions::ASMM_Target) .Case("no", LangOptions::ASMM_Off) .Case("yes", LangOptions::ASMM_On) .Default(255)) { default: Diags.Report(diag::err_drv_invalid_value) << "-faddress-space-map-mangling=" << A->getValue(); break; case LangOptions::ASMM_Target: Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Target); break; case LangOptions::ASMM_On: Opts.setAddressSpaceMapMangling(LangOptions::ASMM_On); break; case LangOptions::ASMM_Off: Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Off); break; } } if (Arg *A = Args.getLastArg(OPT_fms_memptr_rep_EQ)) { LangOptions::PragmaMSPointersToMembersKind InheritanceModel = llvm::StringSwitch<LangOptions::PragmaMSPointersToMembersKind>( A->getValue()) .Case("single", LangOptions::PPTMK_FullGeneralitySingleInheritance) .Case("multiple", LangOptions::PPTMK_FullGeneralityMultipleInheritance) .Case("virtual", LangOptions::PPTMK_FullGeneralityVirtualInheritance) .Default(LangOptions::PPTMK_BestCase); if (InheritanceModel == LangOptions::PPTMK_BestCase) Diags.Report(diag::err_drv_invalid_value) << "-fms-memptr-rep=" << A->getValue(); Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel); } // Check if -fopenmp is specified. Opts.OpenMP = Args.hasArg(options::OPT_fopenmp); Opts.OpenMPUseTLS = Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls); // Record whether the __DEPRECATED define was requested. Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro, OPT_fno_deprecated_macro, Opts.Deprecated); // FIXME: Eliminate this dependency. unsigned Opt = getOptimizationLevel(Args, IK, Diags), OptSize = getOptimizationLevelSize(Args); Opts.Optimize = Opt != 0; Opts.OptimizeSize = OptSize != 0; // This is the __NO_INLINE__ define, which just depends on things like the // optimization level and -fno-inline, not actually whether the backend has // inlining enabled. Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline); Opts.FastMath = Args.hasArg(OPT_ffast_math) || Args.hasArg(OPT_cl_fast_relaxed_math); Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only) || Args.hasArg(OPT_cl_finite_math_only) || Args.hasArg(OPT_cl_fast_relaxed_math); Opts.RetainCommentsFromSystemHeaders = Args.hasArg(OPT_fretain_comments_from_system_headers); unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags); switch (SSP) { default: Diags.Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; break; case 0: Opts.setStackProtector(LangOptions::SSPOff); break; case 1: Opts.setStackProtector(LangOptions::SSPOn); break; case 2: Opts.setStackProtector(LangOptions::SSPStrong); break; case 3: Opts.setStackProtector(LangOptions::SSPReq); break; } // Parse -fsanitize= arguments. parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ), Diags, Opts.Sanitize); // -fsanitize-address-field-padding=N has to be a LangOpt, parse it here. Opts.SanitizeAddressFieldPadding = getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags); Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist); #else llvm::StringRef ver = Args.getLastArgValue(OPT_hlsl_version); if (ver.empty()) { Opts.HLSLVersion = hlsl::LangStd::vLatest; } // Default to latest else { Opts.HLSLVersion = hlsl::parseHLSLVersion(ver); if (Opts.HLSLVersion == hlsl::LangStd::vError) { Diags.Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_hlsl_version)->getAsString(Args) << ver; } } // Enable low precision for HLSL 2018 // TODO: should we tie low precision to HLSL2018 only? Opts.UseMinPrecision = !Args.hasArg(options::OPT_enable_16bit_types); #endif // #ifdef MS_SUPPORT_VARIABLE_LANGOPTS } static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, FileManager &FileMgr, DiagnosticsEngine &Diags) { using namespace options; Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch); Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth); if (const Arg *A = Args.getLastArg(OPT_token_cache)) Opts.TokenCache = A->getValue(); else Opts.TokenCache = Opts.ImplicitPTHInclude; Opts.UsePredefines = !Args.hasArg(OPT_undef); Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch); Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls); for (const Arg *A : Args.filtered(OPT_error_on_deserialized_pch_decl)) Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue()); if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) { StringRef Value(A->getValue()); size_t Comma = Value.find(','); unsigned Bytes = 0; unsigned EndOfLine = 0; if (Comma == StringRef::npos || Value.substr(0, Comma).getAsInteger(10, Bytes) || Value.substr(Comma + 1).getAsInteger(10, EndOfLine)) Diags.Report(diag::err_drv_preamble_format); else { Opts.PrecompiledPreambleBytes.first = Bytes; Opts.PrecompiledPreambleBytes.second = (EndOfLine != 0); } } // Add macros from the command line. for (const Arg *A : Args.filtered(OPT_D, OPT_U)) { if (A->getOption().matches(OPT_D)) Opts.addMacroDef(A->getValue()); else Opts.addMacroUndef(A->getValue()); } Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros); // Add the ordered list of -includes. for (const Arg *A : Args.filtered(OPT_include)) Opts.Includes.emplace_back(A->getValue()); for (const Arg *A : Args.filtered(OPT_chain_include)) Opts.ChainedIncludes.emplace_back(A->getValue()); // Include 'altivec.h' if -faltivec option present if (Args.hasArg(OPT_faltivec)) Opts.Includes.emplace_back("altivec.h"); for (const Arg *A : Args.filtered(OPT_remap_file)) { std::pair<StringRef, StringRef> Split = StringRef(A->getValue()).split(';'); if (Split.second.empty()) { Diags.Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args); continue; } Opts.addRemappedFile(Split.first, Split.second); } if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) { StringRef Name = A->getValue(); unsigned Library = llvm::StringSwitch<unsigned>(Name) .Case("libc++", ARCXX_libcxx) .Case("libstdc++", ARCXX_libstdcxx) .Case("none", ARCXX_nolib) .Default(~0U); if (Library == ~0U) Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; else Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library; } } static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, ArgList &Args, frontend::ActionKind Action) { using namespace options; switch (Action) { case frontend::ASTDeclList: case frontend::ASTDump: case frontend::ASTPrint: case frontend::ASTView: case frontend::EmitAssembly: case frontend::EmitBC: case frontend::EmitHTML: case frontend::EmitLLVM: case frontend::EmitLLVMOnly: case frontend::EmitCodeGenOnly: case frontend::EmitObj: case frontend::FixIt: case frontend::GenerateModule: case frontend::GeneratePCH: case frontend::GeneratePTH: case frontend::ParseSyntaxOnly: case frontend::ModuleFileInfo: case frontend::VerifyPCH: case frontend::PluginAction: case frontend::PrintDeclContext: case frontend::RewriteObjC: case frontend::RewriteTest: case frontend::RunAnalysis: case frontend::MigrateSource: Opts.ShowCPP = 0; break; case frontend::DumpRawTokens: case frontend::DumpTokens: case frontend::InitOnly: case frontend::PrintPreamble: case frontend::PrintPreprocessedInput: case frontend::RewriteMacros: case frontend::RunPreprocessorOnly: Opts.ShowCPP = !Args.hasArg(OPT_dM); break; } Opts.ShowComments = Args.hasArg(OPT_C); Opts.ShowLineMarkers = !Args.hasArg(OPT_P); Opts.ShowMacroComments = Args.hasArg(OPT_CC); Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD); Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes); Opts.UseLineDirectives = Args.hasArg(OPT_fuse_line_directives); } static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { using namespace options; Opts.ABI = Args.getLastArgValue(OPT_target_abi); Opts.CPU = Args.getLastArgValue(OPT_target_cpu); Opts.FPMath = Args.getLastArgValue(OPT_mfpmath); Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature); Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version); Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ); // Use the default target triple if unspecified. if (Opts.Triple.empty()) Opts.Triple = llvm::sys::getDefaultTargetTriple(); } bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, const char *const *ArgBegin, const char *const *ArgEnd, DiagnosticsEngine &Diags) { bool Success = true; // Parse the arguments. std::unique_ptr<OptTable> Opts(createDriverOptTable()); // HLSL Change: change IncludedFlagsBitmask from options::CC1Option to 0 // (meaning everything should be included). // This is used for internal testing and to drive some libclang scenarios, // where we have a dxc-based command-line. We choose to accept additional // options even if they don't get applied. const unsigned IncludedFlagsBitmask = 0; #ifdef _WIN32 const unsigned ExcludedFlagsBitmask = 0; #else // Exception: Exclude cl.exe like arguments that can trip up Unix systems const unsigned ExcludedFlagsBitmask = options::CLOption; #endif // End HLSL Change unsigned MissingArgIndex, MissingArgCount; InputArgList Args = Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex, MissingArgCount, IncludedFlagsBitmask, ExcludedFlagsBitmask); // Check for missing argument error. if (MissingArgCount) { Diags.Report(diag::err_drv_missing_argument) << Args.getArgString(MissingArgIndex) << MissingArgCount; Success = false; } // Issue errors on unknown arguments. for (const Arg *A : Args.filtered(OPT_UNKNOWN)) { Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args); Success = false; } Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags); Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args); ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args); Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags); ParseCommentArgs(Res.getLangOpts()->CommentOpts, Args); ParseFileSystemArgs(Res.getFileSystemOpts(), Args); // FIXME: We shouldn't have to pass the DashX option around here InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags); ParseTargetArgs(Res.getTargetOpts(), Args); Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags, Res.getTargetOpts()); ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args); if (DashX != IK_AST && DashX != IK_LLVM_IR) { ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags); #ifdef MS_SUPPORT_VARIABLE_LANGOPTS if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC) Res.getLangOpts()->ObjCExceptions = 1; #endif } // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of // PCH file and find the original header name. Remove the need to do that in // ParsePreprocessorArgs and remove the FileManager // parameters from the function and the "FileManager.h" #include. FileManager FileMgr(Res.getFileSystemOpts()); ParsePreprocessorArgs(Res.getPreprocessorOpts(), Args, FileMgr, Diags); ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), Args, Res.getFrontendOpts().ProgramAction); return Success; } namespace { class ModuleSignature { SmallVector<uint64_t, 16> Data; unsigned CurBit; uint64_t CurValue; public: ModuleSignature() : CurBit(0), CurValue(0) { } void add(uint64_t Value, unsigned Bits); void add(StringRef Value); void flush(); llvm::APInt getAsInteger() const; }; } void ModuleSignature::add(uint64_t Value, unsigned int NumBits) { CurValue |= Value << CurBit; if (CurBit + NumBits < 64) { CurBit += NumBits; return; } // Add the current word. Data.push_back(CurValue); if (CurBit) CurValue = Value >> (64-CurBit); else CurValue = 0; CurBit = (CurBit+NumBits) & 63; } void ModuleSignature::flush() { if (CurBit == 0) return; Data.push_back(CurValue); CurBit = 0; CurValue = 0; } void ModuleSignature::add(StringRef Value) { for (StringRef::iterator I = Value.begin(), IEnd = Value.end(); I != IEnd;++I) add(*I, 8); } llvm::APInt ModuleSignature::getAsInteger() const { return llvm::APInt(Data.size() * 64, Data); } std::string CompilerInvocation::getModuleHash() const { #ifdef MSFT_SUPPORTS_MODULES // Note: For QoI reasons, the things we use as a hash here should all be // dumped via the -module-info flag. using llvm::hash_code; using llvm::hash_value; using llvm::hash_combine; // Start the signature with the compiler version. // FIXME: We'd rather use something more cryptographically sound than // CityHash, but this will do for now. hash_code code = hash_value(getClangFullRepositoryVersion()); // Extend the signature with the language options #define LANGOPT(Name, Bits, Default, Description) \ code = hash_combine(code, LangOpts->Name); #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name())); #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.fixed.def" for (StringRef Feature : LangOpts->ModuleFeatures) code = hash_combine(code, Feature); // Extend the signature with the target options. code = hash_combine(code, TargetOpts->Triple, TargetOpts->CPU, TargetOpts->ABI); for (unsigned i = 0, n = TargetOpts->FeaturesAsWritten.size(); i != n; ++i) code = hash_combine(code, TargetOpts->FeaturesAsWritten[i]); // Extend the signature with preprocessor options. const PreprocessorOptions &ppOpts = getPreprocessorOpts(); const HeaderSearchOptions &hsOpts = getHeaderSearchOpts(); code = hash_combine(code, ppOpts.UsePredefines, ppOpts.DetailedRecord); for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator I = getPreprocessorOpts().Macros.begin(), IEnd = getPreprocessorOpts().Macros.end(); I != IEnd; ++I) { // If we're supposed to ignore this macro for the purposes of modules, // don't put it into the hash. if (!hsOpts.ModulesIgnoreMacros.empty()) { // Check whether we're ignoring this macro. StringRef MacroDef = I->first; if (hsOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first)) continue; } code = hash_combine(code, I->first, I->second); } // Extend the signature with the sysroot. code = hash_combine(code, hsOpts.Sysroot, hsOpts.UseBuiltinIncludes, hsOpts.UseStandardSystemIncludes, hsOpts.UseStandardCXXIncludes, hsOpts.UseLibcxx); code = hash_combine(code, hsOpts.ResourceDir); // Extend the signature with the user build path. code = hash_combine(code, hsOpts.ModuleUserBuildPath); // Darwin-specific hack: if we have a sysroot, use the contents and // modification time of // $sysroot/System/Library/CoreServices/SystemVersion.plist // as part of the module hash. if (!hsOpts.Sysroot.empty()) { SmallString<128> systemVersionFile; systemVersionFile += hsOpts.Sysroot; llvm::sys::path::append(systemVersionFile, "System"); llvm::sys::path::append(systemVersionFile, "Library"); llvm::sys::path::append(systemVersionFile, "CoreServices"); llvm::sys::path::append(systemVersionFile, "SystemVersion.plist"); llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer = llvm::MemoryBuffer::getFile(systemVersionFile); if (buffer) { code = hash_combine(code, buffer.get()->getBuffer()); struct stat statBuf; if (stat(systemVersionFile.c_str(), &statBuf) == 0) code = hash_combine(code, statBuf.st_mtime); } } return llvm::APInt(64, code).toString(36, /*Signed=*/false); #else return std::string(); #endif // MSFT_SUPPORTS_MODULES } namespace clang { template<typename IntTy> static IntTy getLastArgIntValueImpl(const ArgList &Args, OptSpecifier Id, IntTy Default, DiagnosticsEngine *Diags) { IntTy Res = Default; if (Arg *A = Args.getLastArg(Id)) { if (StringRef(A->getValue()).getAsInteger(10, Res)) { if (Diags) Diags->Report(diag::err_drv_invalid_int_value) << A->getAsString(Args) << A->getValue(); } } return Res; } // Declared in clang/Frontend/Utils.h. int getLastArgIntValue(const ArgList &Args, OptSpecifier Id, int Default, DiagnosticsEngine *Diags) { return getLastArgIntValueImpl<int>(Args, Id, Default, Diags); } uint64_t getLastArgUInt64Value(const ArgList &Args, OptSpecifier Id, uint64_t Default, DiagnosticsEngine *Diags) { return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags); } void BuryPointer(const void *Ptr) { // This function may be called only a small fixed amount of times per each // invocation, otherwise we do actually have a leak which we want to report. // If this function is called more than kGraveYardMaxSize times, the pointers // will not be properly buried and a leak detector will report a leak, which // is what we want in such case. static const size_t kGraveYardMaxSize = 16; LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize]; static std::atomic<unsigned> GraveYardSize; unsigned Idx = GraveYardSize++; if (Idx >= kGraveYardMaxSize) return; GraveYard[Idx] = Ptr; } IntrusiveRefCntPtr<vfs::FileSystem> createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags) { if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) return vfs::getRealFileSystem(); IntrusiveRefCntPtr<vfs::OverlayFileSystem> Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem())); // earlier vfs files are on the bottom for (const std::string &File : CI.getHeaderSearchOpts().VFSOverlayFiles) { llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer = llvm::MemoryBuffer::getFile(File); if (!Buffer) { Diags.Report(diag::err_missing_vfs_overlay_file) << File; return IntrusiveRefCntPtr<vfs::FileSystem>(); } IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getVFSFromYAML(std::move(Buffer.get()), /*DiagHandler*/ nullptr); if (!FS.get()) { Diags.Report(diag::err_invalid_vfs_overlay) << File; return IntrusiveRefCntPtr<vfs::FileSystem>(); } Overlay->pushOverlay(FS); } return Overlay; } } // end namespace clang
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/CMakeLists.txt
add_subdirectory(Rewrite) set(LLVM_LINK_COMPONENTS BitReader Option Support ) # HLSL Change - add ignored sources set(HLSL_IGNORE_SOURCES ChainedIncludesSource.cpp) add_clang_library(clangFrontend ASTConsumers.cpp ASTMerge.cpp ASTUnit.cpp CacheTokens.cpp ChainedDiagnosticConsumer.cpp # ChainedIncludesSource.cpp # HLSL Change CodeGenOptions.cpp CompilerInstance.cpp CompilerInvocation.cpp CreateInvocationFromCommandLine.cpp DependencyFile.cpp DependencyGraph.cpp DiagnosticRenderer.cpp FrontendAction.cpp FrontendActions.cpp FrontendOptions.cpp HeaderIncludeGen.cpp InitHeaderSearch.cpp InitPreprocessor.cpp LangStandards.cpp LayoutOverrideSource.cpp LogDiagnosticPrinter.cpp ModuleDependencyCollector.cpp MultiplexConsumer.cpp PCHContainerOperations.cpp PrintPreprocessedOutput.cpp SerializedDiagnosticPrinter.cpp SerializedDiagnosticReader.cpp TextDiagnostic.cpp TextDiagnosticBuffer.cpp TextDiagnosticPrinter.cpp VerifyDiagnosticConsumer.cpp DEPENDS ClangDriverOptions TablegenHLSLOptions hlsl_dxcversion_autogen # HLSL Change LINK_LIBS clangAST clangBasic clangDriver clangEdit clangLex clangParse clangSema # clangSerialization # HLSL Change ) target_include_directories(clangFrontend PUBLIC ${HLSL_VERSION_LOCATION}) # HLSL Change
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/CompilerInstance.cpp
//===--- CompilerInstance.cpp ---------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/CompilerInstance.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Version.h" #include "clang/Config/config.h" #include "clang/Frontend/ChainedDiagnosticConsumer.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/LogDiagnosticPrinter.h" #include "clang/Frontend/SerializedDiagnosticPrinter.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" #include "clang/Frontend/VerifyDiagnosticConsumer.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/PTHManager.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Sema/Sema.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/GlobalModuleIndex.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Errc.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/LockFileManager.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TimeProfiler.h" // HLSL Change #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include <sys/stat.h> #include <system_error> #include <time.h> using namespace clang; CompilerInstance::CompilerInstance( std::shared_ptr<PCHContainerOperations> PCHContainerOps, bool BuildingModule) #if 1 // HLSL Change Starts - no support for modules : Invocation(new CompilerInvocation()), ThePCHContainerOperations(PCHContainerOps) {} #else : ModuleLoader(BuildingModule), Invocation(new CompilerInvocation()), ModuleManager(nullptr), ThePCHContainerOperations(PCHContainerOps), BuildGlobalModuleIndex(false), HaveFullGlobalModuleIndex(false), ModuleBuildFailed(false) {} #endif // HLSL Change Ends - no support for modules CompilerInstance::~CompilerInstance() { // TODO: harden output file cleanup so there are no additional allocations/exceptions clearOutputFiles(/* EraseFiles */ false); // HLSL Change - might happen when destroying under exception assert(OutputFiles.empty() && "Still output files in flight?"); } void CompilerInstance::setInvocation(CompilerInvocation *Value) { Invocation = Value; } bool CompilerInstance::shouldBuildGlobalModuleIndex() const { #if 1 // HLSL Change Starts - no support for modules return false; #else return (BuildGlobalModuleIndex || (ModuleManager && ModuleManager->isGlobalIndexUnavailable() && getFrontendOpts().GenerateGlobalModuleIndex)) && !ModuleBuildFailed; #endif // HLSL Change Ends - no support for modules } void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) { Diagnostics = Value; } void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; } void CompilerInstance::setFileManager(FileManager *Value) { FileMgr = Value; if (Value) VirtualFileSystem = Value->getVirtualFileSystem(); else VirtualFileSystem.reset(); } void CompilerInstance::setSourceManager(SourceManager *Value) { SourceMgr = Value; } void CompilerInstance::setPreprocessor(Preprocessor *Value) { PP = Value; } void CompilerInstance::setASTContext(ASTContext *Value) { Context = Value; } void CompilerInstance::setSema(Sema *S) { TheSema.reset(S); } void CompilerInstance::setASTConsumer(std::unique_ptr<ASTConsumer> Value) { Consumer = std::move(Value); } void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) { CompletionConsumer.reset(Value); } std::unique_ptr<Sema> CompilerInstance::takeSema() { return std::move(TheSema); } #if 0 // HLSL Change Ends - no support for modules IntrusiveRefCntPtr<ASTReader> CompilerInstance::getModuleManager() const { return ModuleManager; } void CompilerInstance::setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader) { ModuleManager = Reader; } std::shared_ptr<ModuleDependencyCollector> CompilerInstance::getModuleDepCollector() const { return ModuleDepCollector; } void CompilerInstance::setModuleDepCollector( std::shared_ptr<ModuleDependencyCollector> Collector) { ModuleDepCollector = Collector; } #endif // HLSL Change Ends - no support for modules // Diagnostics static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts, const CodeGenOptions *CodeGenOpts, DiagnosticsEngine &Diags) { std::error_code EC; std::unique_ptr<raw_ostream> StreamOwner; raw_ostream *OS = &llvm::errs(); if (DiagOpts->DiagnosticLogFile != "-") { // Create the output stream. auto FileOS = llvm::make_unique<llvm::raw_fd_ostream>( DiagOpts->DiagnosticLogFile, EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text); if (EC) { Diags.Report(diag::warn_fe_cc_log_diagnostics_failure) << DiagOpts->DiagnosticLogFile << EC.message(); } else { FileOS->SetUnbuffered(); FileOS->SetUseAtomicWrites(true); OS = FileOS.get(); StreamOwner = std::move(FileOS); } } // Chain in the diagnostic client which will log the diagnostics. auto Logger = llvm::make_unique<LogDiagnosticPrinter>(*OS, DiagOpts, std::move(StreamOwner)); if (CodeGenOpts) Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags); assert(Diags.ownsClient()); Diags.setClient( new ChainedDiagnosticConsumer(Diags.takeClient(), std::move(Logger))); } static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts, DiagnosticsEngine &Diags, StringRef OutputFile) { auto SerializedConsumer = clang::serialized_diags::create(OutputFile, DiagOpts); if (Diags.ownsClient()) { Diags.setClient(new ChainedDiagnosticConsumer( Diags.takeClient(), std::move(SerializedConsumer))); } else { Diags.setClient(new ChainedDiagnosticConsumer( Diags.getClient(), std::move(SerializedConsumer))); } } void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client, bool ShouldOwnClient) { Diagnostics = createDiagnostics(&getDiagnosticOpts(), Client, ShouldOwnClient, &getCodeGenOpts()); } IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(DiagnosticOptions *Opts, DiagnosticConsumer *Client, bool ShouldOwnClient, const CodeGenOptions *CodeGenOpts) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); IntrusiveRefCntPtr<DiagnosticsEngine> Diags(new DiagnosticsEngine(DiagID, Opts)); // Create the diagnostic client for reporting errors or for // implementing -verify. if (Client) { Diags->setClient(Client, ShouldOwnClient); } else Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts)); // Chain in -verify checker, if requested. if (Opts->VerifyDiagnostics) Diags->setClient(new VerifyDiagnosticConsumer(*Diags)); // Chain in -diagnostic-log-file dumper, if requested. if (!Opts->DiagnosticLogFile.empty()) SetUpDiagnosticLog(Opts, CodeGenOpts, *Diags); if (!Opts->DiagnosticSerializationFile.empty()) SetupSerializedDiagnostics(Opts, *Diags, Opts->DiagnosticSerializationFile); // Configure our handling of diagnostics. ProcessWarningOptions(*Diags, *Opts); return Diags; } // File Manager void CompilerInstance::createFileManager() { if (!hasVirtualFileSystem()) { // TODO: choose the virtual file system based on the CompilerInvocation. setVirtualFileSystem(vfs::getRealFileSystem()); } FileMgr = new FileManager(getFileSystemOpts(), VirtualFileSystem); } // Source Manager void CompilerInstance::createSourceManager(FileManager &FileMgr) { SourceMgr = new SourceManager(getDiagnostics(), FileMgr); } // Initialize the remapping of files to alternative contents, e.g., // those specified through other files. static void InitializeFileRemapping(DiagnosticsEngine &Diags, SourceManager &SourceMgr, FileManager &FileMgr, const PreprocessorOptions &InitOpts) { // Remap files in the source manager (with buffers). for (const auto &RB : InitOpts.RemappedFileBuffers) { // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = FileMgr.getVirtualFile(RB.first, RB.second->getBufferSize(), 0); if (!FromFile) { Diags.Report(diag::err_fe_remap_missing_from_file) << RB.first; if (!InitOpts.RetainRemappedFileBuffers) delete RB.second; continue; } // Override the contents of the "from" file with the contents of // the "to" file. SourceMgr.overrideFileContents(FromFile, RB.second, InitOpts.RetainRemappedFileBuffers); } // Remap files in the source manager (with other files). for (const auto &RF : InitOpts.RemappedFiles) { // Find the file that we're mapping to. const FileEntry *ToFile = FileMgr.getFile(RF.second); if (!ToFile) { Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second; continue; } // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = FileMgr.getVirtualFile(RF.first, ToFile->getSize(), 0); if (!FromFile) { Diags.Report(diag::err_fe_remap_missing_from_file) << RF.first; continue; } // Override the contents of the "from" file with the contents of // the "to" file. SourceMgr.overrideFileContents(FromFile, ToFile); } SourceMgr.setOverridenFilesKeepOriginalName( InitOpts.RemappedFilesKeepOriginalName); } // Preprocessor void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { const PreprocessorOptions &PPOpts = getPreprocessorOpts(); if (HlslLangExtensions) HlslLangExtensions->SetupPreprocessorOptions(getPreprocessorOpts()); // HLSL Change // Create a PTH manager if we are using some form of a token cache. PTHManager *PTHMgr = nullptr; if (!PPOpts.TokenCache.empty()) PTHMgr = PTHManager::Create(PPOpts.TokenCache, getDiagnostics()); // Create the Preprocessor. std::unique_ptr<HeaderSearch> HeaderInfo ( // HLSL Change - make unique_ptr and free new HeaderSearch(&getHeaderSearchOpts(), getSourceManager(), getDiagnostics(), getLangOpts(), &getTarget())); PP = new Preprocessor(&getPreprocessorOpts(), getDiagnostics(), getLangOpts(), getSourceManager(), *HeaderInfo.get(), *this, PTHMgr, /*OwnsHeaderSearch=*/true, TUKind); HeaderInfo.release(); // HLSL Change - Preprocessor has ownership at this point PP->Initialize(getTarget()); // Note that this is different then passing PTHMgr to Preprocessor's ctor. // That argument is used as the IdentifierInfoLookup argument to // IdentifierTable's ctor. if (PTHMgr) { PTHMgr->setPreprocessor(&*PP); PP->setPTHManager(PTHMgr); } if (PPOpts.DetailedRecord) PP->createPreprocessingRecord(); // Apply remappings to the source manager. InitializeFileRemapping(PP->getDiagnostics(), PP->getSourceManager(), PP->getFileManager(), PPOpts); // Predefine macros and configure the preprocessor. InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(), getFrontendOpts()); // Initialize the header search object. ApplyHeaderSearchOptions(PP->getHeaderSearchInfo(), getHeaderSearchOpts(), PP->getLangOpts(), PP->getTargetInfo().getTriple()); PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP); // HLSL Change Starts - no support for modules if (PP->getLangOpts().Modules) PP->getHeaderSearchInfo().setModuleCachePath(getSpecificModuleCachePath()); // HLSL Change Ends - no support for modules // Handle generating dependencies, if requested. const DependencyOutputOptions &DepOpts = getDependencyOutputOpts(); if (!DepOpts.OutputFile.empty()) TheDependencyFileGenerator.reset( DependencyFileGenerator::CreateAndAttachToPreprocessor(*PP, DepOpts)); if (!DepOpts.DOTOutputFile.empty()) AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile, getHeaderSearchOpts().Sysroot); for (auto &Listener : DependencyCollectors) Listener->attachToPreprocessor(*PP); #if 0 // HLSL Change Starts - no support for modules // If we don't have a collector, but we are collecting module dependencies, // then we're the top level compiler instance and need to create one. if (!ModuleDepCollector && !DepOpts.ModuleDependencyOutputDir.empty()) ModuleDepCollector = std::make_shared<ModuleDependencyCollector>( DepOpts.ModuleDependencyOutputDir); #endif // HLSL Change Ends - no support for modules // Handle generating header include information, if requested. if (DepOpts.ShowHeaderIncludes) AttachHeaderIncludeGen(*PP); if (!DepOpts.HeaderIncludeOutputFile.empty()) { StringRef OutputPath = DepOpts.HeaderIncludeOutputFile; if (OutputPath == "-") OutputPath = ""; AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/true, OutputPath, /*ShowDepth=*/false); } if (DepOpts.PrintShowIncludes) { AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/false, /*OutputPath=*/"", /*ShowDepth=*/true, /*MSStyle=*/true); } } std::string CompilerInstance::getSpecificModuleCachePath() { // Set up the module path, including the hash for the // module-creation options. #if 1 // HLSL Change Starts - no support for modules return std::string(); #else SmallString<256> SpecificModuleCache( getHeaderSearchOpts().ModuleCachePath); if (!getHeaderSearchOpts().DisableModuleHash) llvm::sys::path::append(SpecificModuleCache, getInvocation().getModuleHash()); return SpecificModuleCache.str(); #endif // HLSL Change Ends - no support for modules } // ASTContext void CompilerInstance::createASTContext() { Preprocessor &PP = getPreprocessor(); Context = new ASTContext(getLangOpts(), PP.getSourceManager(), PP.getIdentifierTable(), PP.getSelectorTable(), PP.getBuiltinInfo()); Context->InitBuiltinTypes(getTarget()); } // ExternalASTSource void CompilerInstance::createPCHExternalASTSource( StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener) { #if 0 // HLSL Change Starts - no support for PCH bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; ModuleManager = createPCHExternalASTSource( Path, getHeaderSearchOpts().Sysroot, DisablePCHValidation, AllowPCHWithCompilerErrors, getPreprocessor(), getASTContext(), getPCHContainerReader(), DeserializationListener, OwnDeserializationListener, Preamble, getFrontendOpts().UseGlobalModuleIndex); #endif // HLSL Change Ends - no support for PCH } IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource( StringRef Path, StringRef Sysroot, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context, const PCHContainerReader &PCHContainerRdr, void *DeserializationListener, bool OwnDeserializationListener, bool Preamble, bool UseGlobalModuleIndex) { #if 0 // HLSL Change Starts - no support for PCH HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); IntrusiveRefCntPtr<ASTReader> Reader(new ASTReader( PP, Context, PCHContainerRdr, Sysroot.empty() ? "" : Sysroot.data(), DisablePCHValidation, AllowPCHWithCompilerErrors, /*AllowConfigurationMismatch*/ false, HSOpts.ModulesValidateSystemHeaders, UseGlobalModuleIndex)); // We need the external source to be set up before we read the AST, because // eagerly-deserialized declarations may use it. Context.setExternalSource(Reader.get()); Reader->setDeserializationListener( static_cast<ASTDeserializationListener *>(DeserializationListener), /*TakeOwnership=*/OwnDeserializationListener); switch (Reader->ReadAST(Path, Preamble ? serialization::MK_Preamble : serialization::MK_PCH, SourceLocation(), ASTReader::ARR_None)) { case ASTReader::Success: // Set the predefines buffer as suggested by the PCH reader. Typically, the // predefines buffer will be empty. PP.setPredefines(Reader->getSuggestedPredefines()); return Reader; case ASTReader::Failure: // Unrecoverable failure: don't even try to process the input file. break; case ASTReader::Missing: case ASTReader::OutOfDate: case ASTReader::VersionMismatch: case ASTReader::ConfigurationMismatch: case ASTReader::HadErrors: // No suitable PCH file could be found. Return an error. break; } Context.setExternalSource(nullptr); #endif // HLSL Change Starts - no support for PCH return nullptr; } // Code Completion static bool EnableCodeCompletion(Preprocessor &PP, const std::string &Filename, unsigned Line, unsigned Column) { // Tell the source manager to chop off the given file at a specific // line and column. const FileEntry *Entry = PP.getFileManager().getFile(Filename); if (!Entry) { PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file) << Filename; return true; } // Truncate the named file at the given line/column. PP.SetCodeCompletionPoint(Entry, Line, Column); return false; } void CompilerInstance::createCodeCompletionConsumer() { const ParsedSourceLocation &Loc = getFrontendOpts().CodeCompletionAt; if (!CompletionConsumer) { setCodeCompletionConsumer( createCodeCompletionConsumer(getPreprocessor(), Loc.FileName, Loc.Line, Loc.Column, getFrontendOpts().CodeCompleteOpts, llvm::outs())); if (!CompletionConsumer) return; } else if (EnableCodeCompletion(getPreprocessor(), Loc.FileName, Loc.Line, Loc.Column)) { setCodeCompletionConsumer(nullptr); return; } if (CompletionConsumer->isOutputBinary() && llvm::sys::ChangeStdoutToBinary()) { getPreprocessor().getDiagnostics().Report(diag::err_fe_stdout_binary); setCodeCompletionConsumer(nullptr); } } void CompilerInstance::createFrontendTimer() { FrontendTimerGroup.reset(new llvm::TimerGroup("Clang front-end time report")); FrontendTimer.reset( new llvm::Timer("Clang front-end timer", *FrontendTimerGroup)); } CodeCompleteConsumer * CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column, const CodeCompleteOptions &Opts, raw_ostream &OS) { if (EnableCodeCompletion(PP, Filename, Line, Column)) return nullptr; // Set up the creation routine for code-completion. return new PrintingCodeCompleteConsumer(Opts, OS); } void CompilerInstance::createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer) { TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(), TUKind, CompletionConsumer)); if (HlslLangExtensions) HlslLangExtensions->SetupSema(getSema()); // HLSL Change } // Output Files void CompilerInstance::addOutputFile(OutputFile &&OutFile) { assert(OutFile.OS && "Attempt to add empty stream to output list!"); OutputFiles.push_back(std::move(OutFile)); } void CompilerInstance::clearOutputFiles(bool EraseFiles) { bool errorsFound = false; // HLSL Change - track this, but try to clean up everything anyway for (OutputFile &OF : OutputFiles) { // Manually close the stream before we rename it. // HLSL Change Starts - call explicitly to have it throw on error during regular flow (rather than .dtor) if (OF.OS.get()) { OF.OS->close(); errorsFound = errorsFound || OF.OS->has_error(); OF.OS->clear_error(); } // HLSL Change Ends OF.OS.reset(); if (!OF.TempFilename.empty()) { if (EraseFiles) { llvm::sys::fs::remove(OF.TempFilename); } else { SmallString<128> NewOutFile(OF.Filename); // If '-working-directory' was passed, the output filename should be // relative to that. FileMgr->FixupRelativePath(NewOutFile); if (std::error_code ec = llvm::sys::fs::rename(OF.TempFilename, NewOutFile)) { getDiagnostics().Report(diag::err_unable_to_rename_temp) << OF.TempFilename << OF.Filename << ec.message(); llvm::sys::fs::remove(OF.TempFilename); } } } else if (!OF.Filename.empty() && EraseFiles) llvm::sys::fs::remove(OF.Filename); } OutputFiles.clear(); NonSeekStream.reset(); if (errorsFound) throw std::runtime_error("errors when processing output"); // HLSL Change } raw_pwrite_stream * CompilerInstance::createDefaultOutputFile(bool Binary, StringRef InFile, StringRef Extension) { return createOutputFile(getFrontendOpts().OutputFile, Binary, /*RemoveFileOnSignal=*/true, InFile, Extension, /*UseTemporary=*/!WriteDefaultOutputDirectly); // HLSL Change } llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() { auto OS = llvm::make_unique<llvm::raw_null_ostream>(); llvm::raw_null_ostream *Ret = OS.get(); addOutputFile(OutputFile("", "", std::move(OS))); return Ret; } raw_pwrite_stream * CompilerInstance::createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, StringRef InFile, StringRef Extension, bool UseTemporary, bool CreateMissingDirectories) { std::string OutputPathName, TempPathName; std::error_code EC; std::unique_ptr<raw_pwrite_stream> OS = createOutputFile( OutputPath, EC, Binary, RemoveFileOnSignal, InFile, Extension, UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName); if (!OS) { getDiagnostics().Report(diag::err_fe_unable_to_open_output) << OutputPath << EC.message(); return nullptr; } raw_pwrite_stream *Ret = OS.get(); // Add the output file -- but don't try to remove "-", since this means we are // using stdin. addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "", TempPathName, std::move(OS))); return Ret; } std::unique_ptr<llvm::raw_pwrite_stream> CompilerInstance::createOutputFile( StringRef OutputPath, std::error_code &Error, bool Binary, bool RemoveFileOnSignal, StringRef InFile, StringRef Extension, bool UseTemporary, bool CreateMissingDirectories, std::string *ResultPathName, std::string *TempPathName) { assert((!CreateMissingDirectories || UseTemporary) && "CreateMissingDirectories is only allowed when using temporary files"); std::string OutFile, TempFile; if (!OutputPath.empty()) { OutFile = OutputPath; } else if (InFile == "-") { OutFile = "-"; } else if (!Extension.empty()) { SmallString<128> Path(InFile); llvm::sys::path::replace_extension(Path, Extension); OutFile = Path.str(); } else { OutFile = "-"; } std::unique_ptr<llvm::raw_fd_ostream> OS; std::string OSFile; if (UseTemporary) { if (OutFile == "-") UseTemporary = false; else { llvm::sys::fs::file_status Status; llvm::sys::fs::status(OutputPath, Status); if (llvm::sys::fs::exists(Status)) { // Fail early if we can't write to the final destination. if (!llvm::sys::fs::can_write(OutputPath)) return nullptr; // Don't use a temporary if the output is a special file. This handles // things like '-o /dev/null' if (!llvm::sys::fs::is_regular_file(Status)) UseTemporary = false; } } } if (UseTemporary) { // Create a temporary file. SmallString<128> TempPath; TempPath = OutFile; TempPath += "-%%%%%%%%"; int fd; std::error_code EC = llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath); if (CreateMissingDirectories && EC == llvm::errc::no_such_file_or_directory) { StringRef Parent = llvm::sys::path::parent_path(OutputPath); EC = llvm::sys::fs::create_directories(Parent); if (!EC) { EC = llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath); } } if (!EC) { OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true)); OSFile = TempFile = TempPath.str(); } // If we failed to create the temporary, fallback to writing to the file // directly. This handles the corner case where we cannot write to the // directory, but can write to the file. } if (!OS) { OSFile = OutFile; OS.reset(new llvm::raw_fd_ostream( OSFile, Error, (Binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text))); if (Error) return nullptr; } // Make sure the out stream file gets removed if we crash. if (RemoveFileOnSignal) llvm::sys::RemoveFileOnSignal(OSFile); if (ResultPathName) *ResultPathName = OutFile; if (TempPathName) *TempPathName = TempFile; if (!Binary || OS->supportsSeeking()) return std::move(OS); auto B = llvm::make_unique<llvm::buffer_ostream>(*OS); assert(!NonSeekStream); NonSeekStream = std::move(OS); return std::move(B); } // Initialization Utilities bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input){ return InitializeSourceManager(Input, getDiagnostics(), getFileManager(), getSourceManager(), getFrontendOpts()); } bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, DiagnosticsEngine &Diags, FileManager &FileMgr, SourceManager &SourceMgr, const FrontendOptions &Opts) { SrcMgr::CharacteristicKind Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User; if (Input.isBuffer()) { SourceMgr.setMainFileID(SourceMgr.createFileID( std::unique_ptr<llvm::MemoryBuffer>(Input.getBuffer()), Kind)); assert(!SourceMgr.getMainFileID().isInvalid() && "Couldn't establish MainFileID!"); return true; } StringRef InputFile = Input.getFile(); // Figure out where to get and map in the main file. if (InputFile != "-") { const FileEntry *File = FileMgr.getFile(InputFile, /*OpenFile=*/true); if (!File) { Diags.Report(diag::err_fe_error_reading) << InputFile; return false; } // The natural SourceManager infrastructure can't currently handle named // pipes, but we would at least like to accept them for the main // file. Detect them here, read them with the volatile flag so FileMgr will // pick up the correct size, and simply override their contents as we do for // STDIN. if (File->isNamedPipe()) { auto MB = FileMgr.getBufferForFile(File, /*isVolatile=*/true); if (MB) { // Create a new virtual file that will have the correct size. File = FileMgr.getVirtualFile(InputFile, (*MB)->getBufferSize(), 0); SourceMgr.overrideFileContents(File, std::move(*MB)); } else { Diags.Report(diag::err_cannot_open_file) << InputFile << MB.getError().message(); return false; } } SourceMgr.setMainFileID( SourceMgr.createFileID(File, SourceLocation(), Kind)); } else { llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> SBOrErr = llvm::MemoryBuffer::getSTDIN(); if (std::error_code EC = SBOrErr.getError()) { Diags.Report(diag::err_fe_error_reading_stdin) << EC.message(); return false; } std::unique_ptr<llvm::MemoryBuffer> SB = std::move(SBOrErr.get()); const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(), SB->getBufferSize(), 0); SourceMgr.setMainFileID( SourceMgr.createFileID(File, SourceLocation(), Kind)); SourceMgr.overrideFileContents(File, std::move(SB)); } assert(!SourceMgr.getMainFileID().isInvalid() && "Couldn't establish MainFileID!"); return true; } // High-Level Operations bool CompilerInstance::ExecuteAction(FrontendAction &Act) { assert(hasDiagnostics() && "Diagnostics engine is not initialized!"); assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!"); assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!"); // FIXME: Take this as an argument, once all the APIs we used have moved to // taking it as an input instead of hard-coding llvm::errs. raw_ostream &OS = llvm::errs(); // Create the target instance. setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), getInvocation().TargetOpts)); if (!hasTarget()) return false; // Inform the target of the language options. // // FIXME: We shouldn't need to do this, the target should be immutable once // created. This complexity should be lifted elsewhere. getTarget().adjust(getLangOpts()); // rewriter project will change target built-in bool type from its default. if (getFrontendOpts().ProgramAction == frontend::RewriteObjC) getTarget().noSignedCharForObjCBool(); // Validate/process some options. if (getHeaderSearchOpts().Verbose) OS << "clang -cc1 version " CLANG_VERSION_STRING << " based upon " << BACKEND_PACKAGE_STRING << " default target " << llvm::sys::getDefaultTargetTriple() << "\n"; if (getFrontendOpts().ShowTimers) createFrontendTimer(); if (getFrontendOpts().ShowStats) llvm::EnableStatistics(); for (unsigned i = 0, e = getFrontendOpts().Inputs.size(); i != e; ++i) { // Reset the ID tables if we are reusing the SourceManager and parsing // regular files. if (hasSourceManager() && !Act.isModelParsingAction()) getSourceManager().clearIDTables(); if (Act.BeginSourceFile(*this, getFrontendOpts().Inputs[i])) { Act.Execute(); Act.EndSourceFile(); } } // Notify the diagnostic client that all files were processed. getDiagnostics().getClient()->finish(); if (getDiagnosticOpts().ShowCarets) { // We can have multiple diagnostics sharing one diagnostic client. // Get the total number of warnings/errors from the client. unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings(); unsigned NumErrors = getDiagnostics().getClient()->getNumErrors(); if (NumWarnings) OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s"); if (NumWarnings && NumErrors) OS << " and "; if (NumErrors) OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s"); if (NumWarnings || NumErrors) OS << " generated.\n"; } if (getFrontendOpts().ShowStats && hasFileManager()) { getFileManager().PrintStats(); OS << "\n"; } return !getDiagnostics().getClient()->getNumErrors(); } #if 1 // HLSL Change Starts - no support for modules bool CompilerInstance::lookupMissingImports(StringRef, SourceLocation) { return false; } GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(SourceLocation) { return nullptr; } void CompilerInstance::makeModuleVisible(Module *, Module::NameVisibilityKind, SourceLocation) { } ModuleLoadResult CompilerInstance::loadModule(SourceLocation, ModuleIdPath, Module::NameVisibilityKind, bool) { return ModuleLoadResult(); } bool CompilerInstance::loadModuleFile(StringRef) { return false; } void CompilerInstance::createModuleManager() { } #else /// \brief Determine the appropriate source input kind based on language /// options. static InputKind getSourceInputKindFromOptions(const LangOptions &LangOpts) { if (LangOpts.HLSL) // HLSL Change: HLSL specific input kind return IK_HLSL; if (LangOpts.OpenCL) return IK_OpenCL; if (LangOpts.CUDA) return IK_CUDA; if (LangOpts.ObjC1) return LangOpts.CPlusPlus? IK_ObjCXX : IK_ObjC; return LangOpts.CPlusPlus? IK_CXX : IK_C; } /// \brief Compile a module file for the given module, using the options /// provided by the importing compiler instance. Returns true if the module /// was built without errors. static bool compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName) { ModuleMap &ModMap = ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); // Construct a compiler invocation for creating this module. IntrusiveRefCntPtr<CompilerInvocation> Invocation (new CompilerInvocation(ImportingInstance.getInvocation())); PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts(); // For any options that aren't intended to affect how a module is built, // reset them to their default values. Invocation->getLangOpts()->resetNonModularOptions(); PPOpts.resetNonModularOptions(); // Remove any macro definitions that are explicitly ignored by the module. // They aren't supposed to affect how the module is built anyway. const HeaderSearchOptions &HSOpts = Invocation->getHeaderSearchOpts(); PPOpts.Macros.erase( std::remove_if(PPOpts.Macros.begin(), PPOpts.Macros.end(), [&HSOpts](const std::pair<std::string, bool> &def) { StringRef MacroDef = def.first; return HSOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first) > 0; }), PPOpts.Macros.end()); // Note the name of the module we're building. Invocation->getLangOpts()->CurrentModule = Module->getTopLevelModuleName(); // Make sure that the failed-module structure has been allocated in // the importing instance, and propagate the pointer to the newly-created // instance. PreprocessorOptions &ImportingPPOpts = ImportingInstance.getInvocation().getPreprocessorOpts(); if (!ImportingPPOpts.FailedModules) ImportingPPOpts.FailedModules = new PreprocessorOptions::FailedModulesSet; PPOpts.FailedModules = ImportingPPOpts.FailedModules; // If there is a module map file, build the module using the module map. // Set up the inputs/outputs so that we build the module from its umbrella // header. FrontendOptions &FrontendOpts = Invocation->getFrontendOpts(); FrontendOpts.OutputFile = ModuleFileName.str(); FrontendOpts.DisableFree = false; FrontendOpts.GenerateGlobalModuleIndex = false; FrontendOpts.Inputs.clear(); InputKind IK = getSourceInputKindFromOptions(*Invocation->getLangOpts()); // Don't free the remapped file buffers; they are owned by our caller. PPOpts.RetainRemappedFileBuffers = true; Invocation->getDiagnosticOpts().VerifyDiagnostics = 0; assert(ImportingInstance.getInvocation().getModuleHash() == Invocation->getModuleHash() && "Module hash mismatch!"); // Construct a compiler instance that will be used to actually create the // module. CompilerInstance Instance(ImportingInstance.getPCHContainerOperations(), /*BuildingModule=*/true); Instance.setInvocation(&*Invocation); Instance.createDiagnostics(new ForwardingDiagnosticConsumer( ImportingInstance.getDiagnosticClient()), /*ShouldOwnClient=*/true); Instance.setVirtualFileSystem(&ImportingInstance.getVirtualFileSystem()); // Note that this module is part of the module build stack, so that we // can detect cycles in the module graph. Instance.setFileManager(&ImportingInstance.getFileManager()); Instance.createSourceManager(Instance.getFileManager()); SourceManager &SourceMgr = Instance.getSourceManager(); SourceMgr.setModuleBuildStack( ImportingInstance.getSourceManager().getModuleBuildStack()); SourceMgr.pushModuleBuildStack(Module->getTopLevelModuleName(), FullSourceLoc(ImportLoc, ImportingInstance.getSourceManager())); // If we're collecting module dependencies, we need to share a collector // between all of the module CompilerInstances. Instance.setModuleDepCollector(ImportingInstance.getModuleDepCollector()); // Get or create the module map that we'll use to build this module. std::string InferredModuleMapContent; if (const FileEntry *ModuleMapFile = ModMap.getContainingModuleMapFile(Module)) { // Use the module map where this module resides. FrontendOpts.Inputs.emplace_back(ModuleMapFile->getName(), IK); } else { SmallString<128> FakeModuleMapFile(Module->Directory->getName()); llvm::sys::path::append(FakeModuleMapFile, "__inferred_module.map"); FrontendOpts.Inputs.emplace_back(FakeModuleMapFile, IK); llvm::raw_string_ostream OS(InferredModuleMapContent); Module->print(OS); OS.flush(); std::unique_ptr<llvm::MemoryBuffer> ModuleMapBuffer = llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent); ModuleMapFile = Instance.getFileManager().getVirtualFile( FakeModuleMapFile, InferredModuleMapContent.size(), 0); SourceMgr.overrideFileContents(ModuleMapFile, std::move(ModuleMapBuffer)); } // Construct a module-generating action. Passing through the module map is // safe because the FileManager is shared between the compiler instances. GenerateModuleAction CreateModuleAction( ModMap.getModuleMapFileForUniquing(Module), Module->IsSystem); ImportingInstance.getDiagnostics().Report(ImportLoc, diag::remark_module_build) << Module->Name << ModuleFileName; // Execute the action to actually build the module in-place. Use a separate // thread so that we get a stack large enough. const unsigned ThreadStackSize = 8 << 20; llvm::CrashRecoveryContext CRC; CRC.RunSafelyOnThread([&]() { Instance.ExecuteAction(CreateModuleAction); }, ThreadStackSize); ImportingInstance.getDiagnostics().Report(ImportLoc, diag::remark_module_build_done) << Module->Name; // Delete the temporary module map file. // FIXME: Even though we're executing under crash protection, it would still // be nice to do this with RemoveFileOnSignal when we can. However, that // doesn't make sense for all clients, so clean this up manually. Instance.clearOutputFiles(/*EraseFiles=*/true); // We've rebuilt a module. If we're allowed to generate or update the global // module index, record that fact in the importing compiler instance. if (ImportingInstance.getFrontendOpts().GenerateGlobalModuleIndex) { ImportingInstance.setBuildGlobalModuleIndex(true); } return !Instance.getDiagnostics().hasErrorOccurred(); } static bool compileAndLoadModule(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName) { DiagnosticsEngine &Diags = ImportingInstance.getDiagnostics(); auto diagnoseBuildFailure = [&] { Diags.Report(ModuleNameLoc, diag::err_module_not_built) << Module->Name << SourceRange(ImportLoc, ModuleNameLoc); }; // FIXME: have LockFileManager return an error_code so that we can // avoid the mkdir when the directory already exists. StringRef Dir = llvm::sys::path::parent_path(ModuleFileName); llvm::sys::fs::create_directories(Dir); while (1) { unsigned ModuleLoadCapabilities = ASTReader::ARR_Missing; llvm::LockFileManager Locked(ModuleFileName); switch (Locked) { case llvm::LockFileManager::LFS_Error: Diags.Report(ModuleNameLoc, diag::err_module_lock_failure) << Module->Name; return false; case llvm::LockFileManager::LFS_Owned: // We're responsible for building the module ourselves. if (!compileModuleImpl(ImportingInstance, ModuleNameLoc, Module, ModuleFileName)) { diagnoseBuildFailure(); return false; } break; case llvm::LockFileManager::LFS_Shared: // Someone else is responsible for building the module. Wait for them to // finish. switch (Locked.waitForUnlock()) { case llvm::LockFileManager::Res_Success: ModuleLoadCapabilities |= ASTReader::ARR_OutOfDate; break; case llvm::LockFileManager::Res_OwnerDied: continue; // try again to get the lock. case llvm::LockFileManager::Res_Timeout: Diags.Report(ModuleNameLoc, diag::err_module_lock_timeout) << Module->Name; // Clear the lock file so that future invokations can make progress. Locked.unsafeRemoveLockFile(); return false; } break; } // Try to read the module file, now that we've compiled it. ASTReader::ASTReadResult ReadResult = ImportingInstance.getModuleManager()->ReadAST( ModuleFileName, serialization::MK_ImplicitModule, ImportLoc, ModuleLoadCapabilities); if (ReadResult == ASTReader::OutOfDate && Locked == llvm::LockFileManager::LFS_Shared) { // The module may be out of date in the presence of file system races, // or if one of its imports depends on header search paths that are not // consistent with this ImportingInstance. Try again... continue; } else if (ReadResult == ASTReader::Missing) { diagnoseBuildFailure(); } else if (ReadResult != ASTReader::Success && !Diags.hasErrorOccurred()) { // The ASTReader didn't diagnose the error, so conservatively report it. diagnoseBuildFailure(); } return ReadResult == ASTReader::Success; } } /// \brief Diagnose differences between the current definition of the given /// configuration macro and the definition provided on the command line. static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro, Module *Mod, SourceLocation ImportLoc) { IdentifierInfo *Id = PP.getIdentifierInfo(ConfigMacro); SourceManager &SourceMgr = PP.getSourceManager(); // If this identifier has never had a macro definition, then it could // not have changed. if (!Id->hadMacroDefinition()) return; auto *LatestLocalMD = PP.getLocalMacroDirectiveHistory(Id); // Find the macro definition from the command line. MacroInfo *CmdLineDefinition = nullptr; for (auto *MD = LatestLocalMD; MD; MD = MD->getPrevious()) { // We only care about the predefines buffer. FileID FID = SourceMgr.getFileID(MD->getLocation()); if (FID.isInvalid() || FID != PP.getPredefinesFileID()) continue; if (auto *DMD = dyn_cast<DefMacroDirective>(MD)) CmdLineDefinition = DMD->getMacroInfo(); break; } auto *CurrentDefinition = PP.getMacroInfo(Id); if (CurrentDefinition == CmdLineDefinition) { // Macro matches. Nothing to do. } else if (!CurrentDefinition) { // This macro was defined on the command line, then #undef'd later. // Complain. PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) << true << ConfigMacro << Mod->getFullModuleName(); auto LatestDef = LatestLocalMD->getDefinition(); assert(LatestDef.isUndefined() && "predefined macro went away with no #undef?"); PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here) << true; return; } else if (!CmdLineDefinition) { // There was no definition for this macro in the predefines buffer, // but there was a local definition. Complain. PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) << false << ConfigMacro << Mod->getFullModuleName(); PP.Diag(CurrentDefinition->getDefinitionLoc(), diag::note_module_def_undef_here) << false; } else if (!CurrentDefinition->isIdenticalTo(*CmdLineDefinition, PP, /*Syntactically=*/true)) { // The macro definitions differ. PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) << false << ConfigMacro << Mod->getFullModuleName(); PP.Diag(CurrentDefinition->getDefinitionLoc(), diag::note_module_def_undef_here) << false; } } /// \brief Write a new timestamp file with the given path. static void writeTimestampFile(StringRef TimestampFile) { std::error_code EC; llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::F_None); } /// \brief Prune the module cache of modules that haven't been accessed in /// a long time. static void pruneModuleCache(const HeaderSearchOptions &HSOpts) { struct stat StatBuf; llvm::SmallString<128> TimestampFile; TimestampFile = HSOpts.ModuleCachePath; llvm::sys::path::append(TimestampFile, "modules.timestamp"); // Try to stat() the timestamp file. if (::stat(TimestampFile.c_str(), &StatBuf)) { // If the timestamp file wasn't there, create one now. if (errno == ENOENT) { writeTimestampFile(TimestampFile); } return; } // Check whether the time stamp is older than our pruning interval. // If not, do nothing. time_t TimeStampModTime = StatBuf.st_mtime; time_t CurrentTime = time(nullptr); if (CurrentTime - TimeStampModTime <= time_t(HSOpts.ModuleCachePruneInterval)) return; // Write a new timestamp file so that nobody else attempts to prune. // There is a benign race condition here, if two Clang instances happen to // notice at the same time that the timestamp is out-of-date. writeTimestampFile(TimestampFile); // Walk the entire module cache, looking for unused module files and module // indices. std::error_code EC; SmallString<128> ModuleCachePathNative; llvm::sys::path::native(HSOpts.ModuleCachePath, ModuleCachePathNative); for (llvm::sys::fs::directory_iterator Dir(ModuleCachePathNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { // If we don't have a directory, there's nothing to look into. if (!llvm::sys::fs::is_directory(Dir->path())) continue; // Walk all of the files within this directory. for (llvm::sys::fs::directory_iterator File(Dir->path(), EC), FileEnd; File != FileEnd && !EC; File.increment(EC)) { // We only care about module and global module index files. StringRef Extension = llvm::sys::path::extension(File->path()); if (Extension != ".pcm" && Extension != ".timestamp" && llvm::sys::path::filename(File->path()) != "modules.idx") continue; // Look at this file. If we can't stat it, there's nothing interesting // there. if (::stat(File->path().c_str(), &StatBuf)) continue; // If the file has been used recently enough, leave it there. time_t FileAccessTime = StatBuf.st_atime; if (CurrentTime - FileAccessTime <= time_t(HSOpts.ModuleCachePruneAfter)) { continue; } // Remove the file. llvm::sys::fs::remove(File->path()); // Remove the timestamp file. std::string TimpestampFilename = File->path() + ".timestamp"; llvm::sys::fs::remove(TimpestampFilename); } // If we removed all of the files in the directory, remove the directory // itself. if (llvm::sys::fs::directory_iterator(Dir->path(), EC) == llvm::sys::fs::directory_iterator() && !EC) llvm::sys::fs::remove(Dir->path()); } } void CompilerInstance::createModuleManager() { if (!ModuleManager) { if (!hasASTContext()) createASTContext(); // If we're implicitly building modules but not currently recursively // building a module, check whether we need to prune the module cache. if (getLangOpts().ImplicitModules && getSourceManager().getModuleBuildStack().empty() && getHeaderSearchOpts().ModuleCachePruneInterval > 0 && getHeaderSearchOpts().ModuleCachePruneAfter > 0) { pruneModuleCache(getHeaderSearchOpts()); } HeaderSearchOptions &HSOpts = getHeaderSearchOpts(); std::string Sysroot = HSOpts.Sysroot; const PreprocessorOptions &PPOpts = getPreprocessorOpts(); std::unique_ptr<llvm::Timer> ReadTimer; if (FrontendTimerGroup) ReadTimer = llvm::make_unique<llvm::Timer>("Reading modules", *FrontendTimerGroup); ModuleManager = new ASTReader( getPreprocessor(), *Context, getPCHContainerReader(), Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation, /*AllowASTWithCompilerErrors=*/false, /*AllowConfigurationMismatch=*/false, HSOpts.ModulesValidateSystemHeaders, getFrontendOpts().UseGlobalModuleIndex, std::move(ReadTimer)); if (hasASTConsumer()) { ModuleManager->setDeserializationListener( getASTConsumer().GetASTDeserializationListener()); getASTContext().setASTMutationListener( getASTConsumer().GetASTMutationListener()); } getASTContext().setExternalSource(ModuleManager); if (hasSema()) ModuleManager->InitializeSema(getSema()); if (hasASTConsumer()) ModuleManager->StartTranslationUnit(&getASTConsumer()); } } bool CompilerInstance::loadModuleFile(StringRef FileName) { llvm::Timer Timer; if (FrontendTimerGroup) Timer.init("Preloading " + FileName.str(), *FrontendTimerGroup); llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr); // Helper to recursively read the module names for all modules we're adding. // We mark these as known and redirect any attempt to load that module to // the files we were handed. struct ReadModuleNames : ASTReaderListener { CompilerInstance &CI; std::vector<StringRef> ModuleFileStack; std::vector<StringRef> ModuleNameStack; bool Failed; bool TopFileIsModule; ReadModuleNames(CompilerInstance &CI) : CI(CI), Failed(false), TopFileIsModule(false) {} bool needsImportVisitation() const override { return true; } void visitImport(StringRef FileName) override { if (!CI.ExplicitlyLoadedModuleFiles.insert(FileName).second) { if (ModuleFileStack.size() == 0) TopFileIsModule = true; return; } ModuleFileStack.push_back(FileName); ModuleNameStack.push_back(StringRef()); if (ASTReader::readASTFileControlBlock(FileName, CI.getFileManager(), CI.getPCHContainerReader(), *this)) { CI.getDiagnostics().Report( SourceLocation(), CI.getFileManager().getBufferForFile(FileName) ? diag::err_module_file_invalid : diag::err_module_file_not_found) << FileName; for (int I = ModuleFileStack.size() - 2; I >= 0; --I) CI.getDiagnostics().Report(SourceLocation(), diag::note_module_file_imported_by) << ModuleFileStack[I] << !ModuleNameStack[I].empty() << ModuleNameStack[I]; Failed = true; } ModuleNameStack.pop_back(); ModuleFileStack.pop_back(); } void ReadModuleName(StringRef ModuleName) override { if (ModuleFileStack.size() == 1) TopFileIsModule = true; ModuleNameStack.back() = ModuleName; auto &ModuleFile = CI.ModuleFileOverrides[ModuleName]; if (!ModuleFile.empty() && CI.getFileManager().getFile(ModuleFile) != CI.getFileManager().getFile(ModuleFileStack.back())) CI.getDiagnostics().Report(SourceLocation(), diag::err_conflicting_module_files) << ModuleName << ModuleFile << ModuleFileStack.back(); ModuleFile = ModuleFileStack.back(); } } RMN(*this); // If we don't already have an ASTReader, create one now. if (!ModuleManager) createModuleManager(); // Tell the module manager about this module file. if (getModuleManager()->getModuleManager().addKnownModuleFile(FileName)) { getDiagnostics().Report(SourceLocation(), diag::err_module_file_not_found) << FileName; return false; } // Build our mapping of module names to module files from this file // and its imports. RMN.visitImport(FileName); if (RMN.Failed) return false; // If we never found a module name for the top file, then it's not a module, // it's a PCH or preamble or something. if (!RMN.TopFileIsModule) { getDiagnostics().Report(SourceLocation(), diag::err_module_file_not_module) << FileName; return false; } return true; } ModuleLoadResult CompilerInstance::loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) { // Determine what file we're searching from. StringRef ModuleName = Path[0].first->getName(); SourceLocation ModuleNameLoc = Path[0].second; // If we've already handled this import, just return the cached result. // This one-element cache is important to eliminate redundant diagnostics // when both the preprocessor and parser see the same import declaration. if (!ImportLoc.isInvalid() && LastModuleImportLoc == ImportLoc) { // Make the named module visible. if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule && ModuleName != getLangOpts().ImplementationOfModule) ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility, ImportLoc); return LastModuleImportResult; } clang::Module *Module = nullptr; // If we don't already have information on this module, load the module now. llvm::DenseMap<const IdentifierInfo *, clang::Module *>::iterator Known = KnownModules.find(Path[0].first); if (Known != KnownModules.end()) { // Retrieve the cached top-level module. Module = Known->second; } else if (ModuleName == getLangOpts().CurrentModule || ModuleName == getLangOpts().ImplementationOfModule) { // This is the module we're building. Module = PP->getHeaderSearchInfo().lookupModule(ModuleName); Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first; } else { // Search for a module with the given name. Module = PP->getHeaderSearchInfo().lookupModule(ModuleName); if (!Module) { getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found) << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); ModuleBuildFailed = true; return ModuleLoadResult(); } auto Override = ModuleFileOverrides.find(ModuleName); bool Explicit = Override != ModuleFileOverrides.end(); if (!Explicit && !getLangOpts().ImplicitModules) { getDiagnostics().Report(ModuleNameLoc, diag::err_module_build_disabled) << ModuleName; ModuleBuildFailed = true; return ModuleLoadResult(); } std::string ModuleFileName = Explicit ? Override->second : PP->getHeaderSearchInfo().getModuleFileName(Module); // If we don't already have an ASTReader, create one now. if (!ModuleManager) createModuleManager(); if (TheDependencyFileGenerator) TheDependencyFileGenerator->AttachToASTReader(*ModuleManager); if (ModuleDepCollector) ModuleDepCollector->attachToASTReader(*ModuleManager); for (auto &Listener : DependencyCollectors) Listener->attachToASTReader(*ModuleManager); llvm::Timer Timer; if (FrontendTimerGroup) Timer.init("Loading " + ModuleFileName, *FrontendTimerGroup); llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr); // Try to load the module file. unsigned ARRFlags = Explicit ? 0 : ASTReader::ARR_OutOfDate | ASTReader::ARR_Missing; switch (ModuleManager->ReadAST(ModuleFileName, Explicit ? serialization::MK_ExplicitModule : serialization::MK_ImplicitModule, ImportLoc, ARRFlags)) { case ASTReader::Success: break; case ASTReader::OutOfDate: case ASTReader::Missing: { if (Explicit) { // ReadAST has already complained for us. ModuleLoader::HadFatalFailure = true; KnownModules[Path[0].first] = nullptr; return ModuleLoadResult(); } // The module file is missing or out-of-date. Build it. assert(Module && "missing module file"); // Check whether there is a cycle in the module graph. ModuleBuildStack ModPath = getSourceManager().getModuleBuildStack(); ModuleBuildStack::iterator Pos = ModPath.begin(), PosEnd = ModPath.end(); for (; Pos != PosEnd; ++Pos) { if (Pos->first == ModuleName) break; } if (Pos != PosEnd) { SmallString<256> CyclePath; for (; Pos != PosEnd; ++Pos) { CyclePath += Pos->first; CyclePath += " -> "; } CyclePath += ModuleName; getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle) << ModuleName << CyclePath; return ModuleLoadResult(); } // Check whether we have already attempted to build this module (but // failed). if (getPreprocessorOpts().FailedModules && getPreprocessorOpts().FailedModules->hasAlreadyFailed(ModuleName)) { getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_built) << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); ModuleBuildFailed = true; return ModuleLoadResult(); } // Try to compile and then load the module. if (!compileAndLoadModule(*this, ImportLoc, ModuleNameLoc, Module, ModuleFileName)) { assert(getDiagnostics().hasErrorOccurred() && "undiagnosed error in compileAndLoadModule"); if (getPreprocessorOpts().FailedModules) getPreprocessorOpts().FailedModules->addFailed(ModuleName); KnownModules[Path[0].first] = nullptr; ModuleBuildFailed = true; return ModuleLoadResult(); } // Okay, we've rebuilt and now loaded the module. break; } case ASTReader::VersionMismatch: case ASTReader::ConfigurationMismatch: case ASTReader::HadErrors: ModuleLoader::HadFatalFailure = true; // FIXME: The ASTReader will already have complained, but can we showhorn // that diagnostic information into a more useful form? KnownModules[Path[0].first] = nullptr; return ModuleLoadResult(); case ASTReader::Failure: ModuleLoader::HadFatalFailure = true; // Already complained, but note now that we failed. KnownModules[Path[0].first] = nullptr; ModuleBuildFailed = true; return ModuleLoadResult(); } // Cache the result of this top-level module lookup for later. Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first; } // If we never found the module, fail. if (!Module) return ModuleLoadResult(); // Verify that the rest of the module path actually corresponds to // a submodule. if (Path.size() > 1) { for (unsigned I = 1, N = Path.size(); I != N; ++I) { StringRef Name = Path[I].first->getName(); clang::Module *Sub = Module->findSubmodule(Name); if (!Sub) { // Attempt to perform typo correction to find a module name that works. SmallVector<StringRef, 2> Best; unsigned BestEditDistance = (std::numeric_limits<unsigned>::max)(); for (clang::Module::submodule_iterator J = Module->submodule_begin(), JEnd = Module->submodule_end(); J != JEnd; ++J) { unsigned ED = Name.edit_distance((*J)->Name, /*AllowReplacements=*/true, BestEditDistance); if (ED <= BestEditDistance) { if (ED < BestEditDistance) { Best.clear(); BestEditDistance = ED; } Best.push_back((*J)->Name); } } // If there was a clear winner, user it. if (Best.size() == 1) { getDiagnostics().Report(Path[I].second, diag::err_no_submodule_suggest) << Path[I].first << Module->getFullModuleName() << Best[0] << SourceRange(Path[0].second, Path[I-1].second) << FixItHint::CreateReplacement(SourceRange(Path[I].second), Best[0]); Sub = Module->findSubmodule(Best[0]); } } if (!Sub) { // No submodule by this name. Complain, and don't look for further // submodules. getDiagnostics().Report(Path[I].second, diag::err_no_submodule) << Path[I].first << Module->getFullModuleName() << SourceRange(Path[0].second, Path[I-1].second); break; } Module = Sub; } } // Don't make the module visible if we are in the implementation. if (ModuleName == getLangOpts().ImplementationOfModule) return ModuleLoadResult(Module, false); // Make the named module visible, if it's not already part of the module // we are parsing. if (ModuleName != getLangOpts().CurrentModule) { if (!Module->IsFromModuleFile) { // We have an umbrella header or directory that doesn't actually include // all of the headers within the directory it covers. Complain about // this missing submodule and recover by forgetting that we ever saw // this submodule. // FIXME: Should we detect this at module load time? It seems fairly // expensive (and rare). getDiagnostics().Report(ImportLoc, diag::warn_missing_submodule) << Module->getFullModuleName() << SourceRange(Path.front().second, Path.back().second); return ModuleLoadResult(nullptr, true); } // Check whether this module is available. clang::Module::Requirement Requirement; clang::Module::UnresolvedHeaderDirective MissingHeader; if (!Module->isAvailable(getLangOpts(), getTarget(), Requirement, MissingHeader)) { if (MissingHeader.FileNameLoc.isValid()) { getDiagnostics().Report(MissingHeader.FileNameLoc, diag::err_module_header_missing) << MissingHeader.IsUmbrella << MissingHeader.FileName; } else { getDiagnostics().Report(ImportLoc, diag::err_module_unavailable) << Module->getFullModuleName() << Requirement.second << Requirement.first << SourceRange(Path.front().second, Path.back().second); } LastModuleImportLoc = ImportLoc; LastModuleImportResult = ModuleLoadResult(); return ModuleLoadResult(); } ModuleManager->makeModuleVisible(Module, Visibility, ImportLoc); } // Check for any configuration macros that have changed. clang::Module *TopModule = Module->getTopLevelModule(); for (unsigned I = 0, N = TopModule->ConfigMacros.size(); I != N; ++I) { checkConfigMacro(getPreprocessor(), TopModule->ConfigMacros[I], Module, ImportLoc); } LastModuleImportLoc = ImportLoc; LastModuleImportResult = ModuleLoadResult(Module, false); return LastModuleImportResult; } void CompilerInstance::makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, SourceLocation ImportLoc) { if (!ModuleManager) createModuleManager(); if (!ModuleManager) return; ModuleManager->makeModuleVisible(Mod, Visibility, ImportLoc); } GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex( SourceLocation TriggerLoc) { if (!ModuleManager) createModuleManager(); // Can't do anything if we don't have the module manager. if (!ModuleManager) return nullptr; // Get an existing global index. This loads it if not already // loaded. ModuleManager->loadGlobalIndex(); GlobalModuleIndex *GlobalIndex = ModuleManager->getGlobalIndex(); // If the global index doesn't exist, create it. if (!GlobalIndex && shouldBuildGlobalModuleIndex() && hasFileManager() && hasPreprocessor()) { llvm::sys::fs::create_directories( getPreprocessor().getHeaderSearchInfo().getModuleCachePath()); GlobalModuleIndex::writeIndex( getFileManager(), getPCHContainerReader(), getPreprocessor().getHeaderSearchInfo().getModuleCachePath()); ModuleManager->resetForReload(); ModuleManager->loadGlobalIndex(); GlobalIndex = ModuleManager->getGlobalIndex(); } // For finding modules needing to be imported for fixit messages, // we need to make the global index cover all modules, so we do that here. if (!HaveFullGlobalModuleIndex && GlobalIndex && !buildingModule()) { ModuleMap &MMap = getPreprocessor().getHeaderSearchInfo().getModuleMap(); bool RecreateIndex = false; for (ModuleMap::module_iterator I = MMap.module_begin(), E = MMap.module_end(); I != E; ++I) { Module *TheModule = I->second; const FileEntry *Entry = TheModule->getASTFile(); if (!Entry) { SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path; Path.push_back(std::make_pair( getPreprocessor().getIdentifierInfo(TheModule->Name), TriggerLoc)); std::reverse(Path.begin(), Path.end()); // Load a module as hidden. This also adds it to the global index. loadModule(TheModule->DefinitionLoc, Path, Module::Hidden, false); RecreateIndex = true; } } if (RecreateIndex) { GlobalModuleIndex::writeIndex( getFileManager(), getPCHContainerReader(), getPreprocessor().getHeaderSearchInfo().getModuleCachePath()); ModuleManager->resetForReload(); ModuleManager->loadGlobalIndex(); GlobalIndex = ModuleManager->getGlobalIndex(); } HaveFullGlobalModuleIndex = true; } return GlobalIndex; } // Check global module index for missing imports. bool CompilerInstance::lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) { // Look for the symbol in non-imported modules, but only if an error // actually occurred. if (!buildingModule()) { // Load global module index, or retrieve a previously loaded one. GlobalModuleIndex *GlobalIndex = loadGlobalModuleIndex( TriggerLoc); // Only if we have a global index. if (GlobalIndex) { GlobalModuleIndex::HitSet FoundModules; // Find the modules that reference the identifier. // Note that this only finds top-level modules. // We'll let diagnoseTypo find the actual declaration module. if (GlobalIndex->lookupIdentifier(Name, FoundModules)) return true; } } return false; } #endif // HLSL Change Ends - no support for modules void CompilerInstance::resetAndLeakSema() { BuryPointer(takeSema()); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/ChainedDiagnosticConsumer.cpp
//===- ChainedDiagnosticConsumer.cpp - Chain Diagnostic Clients -----------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/ChainedDiagnosticConsumer.h" using namespace clang; void ChainedDiagnosticConsumer::anchor() { }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/FrontendActions.cpp
//===--- FrontendActions.cpp ----------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/FrontendActions.h" #include "clang/AST/ASTConsumer.h" #include "clang/Basic/FileManager.h" #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HLSLMacroExpander.h" #include "clang/Lex/Pragma.h" #include "clang/Lex/Preprocessor.h" #include "clang/Parse/Parser.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/ASTWriter.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include <memory> #include <system_error> // HLSL Change Begin. #include "dxc/DxilRootSignature/DxilRootSignature.h" #include "clang/Parse/ParseHLSL.h" // HLSL Change End. using namespace clang; //===----------------------------------------------------------------------===// // Custom Actions //===----------------------------------------------------------------------===// std::unique_ptr<ASTConsumer> InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return llvm::make_unique<ASTConsumer>(); } void InitOnlyAction::ExecuteAction() { } //===----------------------------------------------------------------------===// // AST Consumer Actions //===----------------------------------------------------------------------===// std::unique_ptr<ASTConsumer> ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile)) return CreateASTPrinter(OS, CI.getFrontendOpts().ASTDumpFilter); return nullptr; } std::unique_ptr<ASTConsumer> ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateASTDumper(CI.getOutStream(), // HLSL Change - explicit out stream CI.getFrontendOpts().ASTDumpFilter, CI.getFrontendOpts().ASTDumpDecls, CI.getFrontendOpts().ASTDumpLookups); } std::unique_ptr<ASTConsumer> ASTDeclListAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateASTDeclNodeLister(); } std::unique_ptr<ASTConsumer> ASTViewAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateASTViewer(); } std::unique_ptr<ASTConsumer> DeclContextPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateDeclContextPrinter(); } #if 0 // HLSL Change Starts - no support for modules or PCH std::unique_ptr<ASTConsumer> GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::string Sysroot; std::string OutputFile; raw_pwrite_stream *OS = ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile); if (!OS) return nullptr; if (!CI.getFrontendOpts().RelocatablePCH) Sysroot.clear(); auto Buffer = std::make_shared<PCHBuffer>(); std::vector<std::unique_ptr<ASTConsumer>> Consumers; Consumers.push_back(llvm::make_unique<PCHGenerator>( CI.getPreprocessor(), OutputFile, nullptr, Sysroot, Buffer)); Consumers.push_back( CI.getPCHContainerWriter().CreatePCHContainerGenerator( CI.getDiagnostics(), CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(), InFile, OutputFile, OS, Buffer)); return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); } raw_pwrite_stream *GeneratePCHAction::ComputeASTConsumerArguments( CompilerInstance &CI, StringRef InFile, std::string &Sysroot, std::string &OutputFile) { Sysroot = CI.getHeaderSearchOpts().Sysroot; if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) { CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot); return nullptr; } // We use createOutputFile here because this is exposed via libclang, and we // must disable the RemoveFileOnSignal behavior. // We use a temporary to avoid race conditions. raw_pwrite_stream *OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, /*RemoveFileOnSignal=*/false, InFile, /*Extension=*/"", /*useTemporary=*/true); if (!OS) return nullptr; OutputFile = CI.getFrontendOpts().OutputFile; return OS; } std::unique_ptr<ASTConsumer> GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::string Sysroot; std::string OutputFile; raw_pwrite_stream *OS = ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile); if (!OS) return nullptr; auto Buffer = std::make_shared<PCHBuffer>(); std::vector<std::unique_ptr<ASTConsumer>> Consumers; Consumers.push_back(llvm::make_unique<PCHGenerator>( CI.getPreprocessor(), OutputFile, Module, Sysroot, Buffer)); Consumers.push_back( CI.getPCHContainerWriter().CreatePCHContainerGenerator( CI.getDiagnostics(), CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(), InFile, OutputFile, OS, Buffer)); return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); } static SmallVectorImpl<char> & operator+=(SmallVectorImpl<char> &Includes, StringRef RHS) { Includes.append(RHS.begin(), RHS.end()); return Includes; } static std::error_code addHeaderInclude(StringRef HeaderName, SmallVectorImpl<char> &Includes, const LangOptions &LangOpts, bool IsExternC) { if (IsExternC && LangOpts.CPlusPlus) Includes += "extern \"C\" {\n"; if (LangOpts.ObjC1) Includes += "#import \""; else Includes += "#include \""; Includes += HeaderName; Includes += "\"\n"; if (IsExternC && LangOpts.CPlusPlus) Includes += "}\n"; return std::error_code(); } /// \brief Collect the set of header includes needed to construct the given /// module and update the TopHeaders file set of the module. /// /// \param Module The module we're collecting includes from. /// /// \param Includes Will be augmented with the set of \#includes or \#imports /// needed to load all of the named headers. static std::error_code collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, ModuleMap &ModMap, clang::Module *Module, SmallVectorImpl<char> &Includes) { // Don't collect any headers for unavailable modules. if (!Module->isAvailable()) return std::error_code(); // Add includes for each of these headers. for (Module::Header &H : Module->Headers[Module::HK_Normal]) { Module->addTopHeader(H.Entry); // Use the path as specified in the module map file. We'll look for this // file relative to the module build directory (the directory containing // the module map file) so this will find the same file that we found // while parsing the module map. if (std::error_code Err = addHeaderInclude(H.NameAsWritten, Includes, LangOpts, Module->IsExternC)) return Err; } // Note that Module->PrivateHeaders will not be a TopHeader. if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) { Module->addTopHeader(UmbrellaHeader.Entry); if (Module->Parent) { // Include the umbrella header for submodules. if (std::error_code Err = addHeaderInclude(UmbrellaHeader.NameAsWritten, Includes, LangOpts, Module->IsExternC)) return Err; } } else if (Module::DirectoryName UmbrellaDir = Module->getUmbrellaDir()) { // Add all of the headers we find in this subdirectory. std::error_code EC; SmallString<128> DirNative; llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative); for (llvm::sys::fs::recursive_directory_iterator Dir(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { // Check whether this entry has an extension typically associated with // headers. if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path())) .Cases(".h", ".H", ".hh", ".hpp", true) .Default(false)) continue; const FileEntry *Header = FileMgr.getFile(Dir->path()); // FIXME: This shouldn't happen unless there is a file system race. Is // that worth diagnosing? if (!Header) continue; // If this header is marked 'unavailable' in this module, don't include // it. if (ModMap.isHeaderUnavailableInModule(Header, Module)) continue; // Compute the relative path from the directory to this file. SmallVector<StringRef, 16> Components; auto PathIt = llvm::sys::path::rbegin(Dir->path()); for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt) Components.push_back(*PathIt); SmallString<128> RelativeHeader(UmbrellaDir.NameAsWritten); for (auto It = Components.rbegin(), End = Components.rend(); It != End; ++It) llvm::sys::path::append(RelativeHeader, *It); // Include this header as part of the umbrella directory. Module->addTopHeader(Header); if (std::error_code Err = addHeaderInclude(RelativeHeader, Includes, LangOpts, Module->IsExternC)) return Err; } if (EC) return EC; } // Recurse into submodules. for (clang::Module::submodule_iterator Sub = Module->submodule_begin(), SubEnd = Module->submodule_end(); Sub != SubEnd; ++Sub) if (std::error_code Err = collectModuleHeaderIncludes( LangOpts, FileMgr, ModMap, *Sub, Includes)) return Err; return std::error_code(); } bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) { // Find the module map file. const FileEntry *ModuleMap = CI.getFileManager().getFile(Filename); if (!ModuleMap) { CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename; return false; } // Parse the module map file. HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo(); if (HS.loadModuleMapFile(ModuleMap, IsSystem)) return false; if (CI.getLangOpts().CurrentModule.empty()) { CI.getDiagnostics().Report(diag::err_missing_module_name); // FIXME: Eventually, we could consider asking whether there was just // a single module described in the module map, and use that as a // default. Then it would be fairly trivial to just "compile" a module // map with a single module (the common case). return false; } // If we're being run from the command-line, the module build stack will not // have been filled in yet, so complete it now in order to allow us to detect // module cycles. SourceManager &SourceMgr = CI.getSourceManager(); if (SourceMgr.getModuleBuildStack().empty()) SourceMgr.pushModuleBuildStack(CI.getLangOpts().CurrentModule, FullSourceLoc(SourceLocation(), SourceMgr)); // Dig out the module definition. Module = HS.lookupModule(CI.getLangOpts().CurrentModule, /*AllowSearch=*/false); if (!Module) { CI.getDiagnostics().Report(diag::err_missing_module) << CI.getLangOpts().CurrentModule << Filename; return false; } // Check whether we can build this module at all. clang::Module::Requirement Requirement; clang::Module::UnresolvedHeaderDirective MissingHeader; if (!Module->isAvailable(CI.getLangOpts(), CI.getTarget(), Requirement, MissingHeader)) { if (MissingHeader.FileNameLoc.isValid()) { CI.getDiagnostics().Report(MissingHeader.FileNameLoc, diag::err_module_header_missing) << MissingHeader.IsUmbrella << MissingHeader.FileName; } else { CI.getDiagnostics().Report(diag::err_module_unavailable) << Module->getFullModuleName() << Requirement.second << Requirement.first; } return false; } if (ModuleMapForUniquing && ModuleMapForUniquing != ModuleMap) { Module->IsInferred = true; HS.getModuleMap().setInferredModuleAllowedBy(Module, ModuleMapForUniquing); } else { ModuleMapForUniquing = ModuleMap; } FileManager &FileMgr = CI.getFileManager(); // Collect the set of #includes we need to build the module. SmallString<256> HeaderContents; std::error_code Err = std::error_code(); if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) Err = addHeaderInclude(UmbrellaHeader.NameAsWritten, HeaderContents, CI.getLangOpts(), Module->IsExternC); if (!Err) Err = collectModuleHeaderIncludes( CI.getLangOpts(), FileMgr, CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(), Module, HeaderContents); if (Err) { CI.getDiagnostics().Report(diag::err_module_cannot_create_includes) << Module->getFullModuleName() << Err.message(); return false; } // Inform the preprocessor that includes from within the input buffer should // be resolved relative to the build directory of the module map file. CI.getPreprocessor().setMainFileDir(Module->Directory); std::unique_ptr<llvm::MemoryBuffer> InputBuffer = llvm::MemoryBuffer::getMemBufferCopy(HeaderContents, Module::getModuleInputBufferName()); // Ownership of InputBuffer will be transferred to the SourceManager. setCurrentInput(FrontendInputFile(InputBuffer.release(), getCurrentFileKind(), Module->IsSystem)); return true; } raw_pwrite_stream *GenerateModuleAction::ComputeASTConsumerArguments( CompilerInstance &CI, StringRef InFile, std::string &Sysroot, std::string &OutputFile) { // If no output file was provided, figure out where this module would go // in the module cache. if (CI.getFrontendOpts().OutputFile.empty()) { HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo(); CI.getFrontendOpts().OutputFile = HS.getModuleFileName(CI.getLangOpts().CurrentModule, ModuleMapForUniquing->getName()); } // We use createOutputFile here because this is exposed via libclang, and we // must disable the RemoveFileOnSignal behavior. // We use a temporary to avoid race conditions. raw_pwrite_stream *OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, /*RemoveFileOnSignal=*/false, InFile, /*Extension=*/"", /*useTemporary=*/true, /*CreateMissingDirectories=*/true); if (!OS) return nullptr; OutputFile = CI.getFrontendOpts().OutputFile; return OS; } #endif // HLSL Change Ends - no support for modules or PCH std::unique_ptr<ASTConsumer> SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return llvm::make_unique<ASTConsumer>(); } #if 0 // HLSL Change Starts - no support for modules or PCH std::unique_ptr<ASTConsumer> DumpModuleInfoAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return llvm::make_unique<ASTConsumer>(); } std::unique_ptr<ASTConsumer> VerifyPCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return llvm::make_unique<ASTConsumer>(); } void VerifyPCHAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot; std::unique_ptr<ASTReader> Reader(new ASTReader( CI.getPreprocessor(), CI.getASTContext(), CI.getPCHContainerReader(), Sysroot.empty() ? "" : Sysroot.c_str(), /*DisableValidation*/ false, /*AllowPCHWithCompilerErrors*/ false, /*AllowConfigurationMismatch*/ true, /*ValidateSystemInputs*/ true)); Reader->ReadAST(getCurrentFile(), Preamble ? serialization::MK_Preamble : serialization::MK_PCH, SourceLocation(), ASTReader::ARR_ConfigurationMismatch); } namespace { /// \brief AST reader listener that dumps module information for a module /// file. class DumpModuleInfoListener : public ASTReaderListener { llvm::raw_ostream &Out; public: DumpModuleInfoListener(llvm::raw_ostream &Out) : Out(Out) { } #define DUMP_BOOLEAN(Value, Text) \ Out.indent(4) << Text << ": " << (Value? "Yes" : "No") << "\n" bool ReadFullVersionInformation(StringRef FullVersion) override { Out.indent(2) << "Generated by " << (FullVersion == getClangFullRepositoryVersion()? "this" : "a different") << " Clang: " << FullVersion << "\n"; return ASTReaderListener::ReadFullVersionInformation(FullVersion); } void ReadModuleName(StringRef ModuleName) override { Out.indent(2) << "Module name: " << ModuleName << "\n"; } void ReadModuleMapFile(StringRef ModuleMapPath) override { Out.indent(2) << "Module map file: " << ModuleMapPath << "\n"; } bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override { Out.indent(2) << "Language options:\n"; #define LANGOPT(Name, Bits, Default, Description) \ DUMP_BOOLEAN(LangOpts.Name, Description); #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ Out.indent(4) << Description << ": " \ << static_cast<unsigned>(LangOpts.get##Name()) << "\n"; #define VALUE_LANGOPT(Name, Bits, Default, Description) \ Out.indent(4) << Description << ": " << LangOpts.Name << "\n"; #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.fixed.def" // HLSL Change if (!LangOpts.ModuleFeatures.empty()) { Out.indent(4) << "Module features:\n"; for (StringRef Feature : LangOpts.ModuleFeatures) Out.indent(6) << Feature << "\n"; } return false; } bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override { Out.indent(2) << "Target options:\n"; Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n"; Out.indent(4) << " CPU: " << TargetOpts.CPU << "\n"; Out.indent(4) << " ABI: " << TargetOpts.ABI << "\n"; if (!TargetOpts.FeaturesAsWritten.empty()) { Out.indent(4) << "Target features:\n"; for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { Out.indent(6) << TargetOpts.FeaturesAsWritten[I] << "\n"; } } return false; } bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) override { Out.indent(2) << "Diagnostic options:\n"; #define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name); #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n"; #define VALUE_DIAGOPT(Name, Bits, Default) \ Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n"; #include "clang/Basic/DiagnosticOptions.def" Out.indent(4) << "Diagnostic flags:\n"; for (const std::string &Warning : DiagOpts->Warnings) Out.indent(6) << "-W" << Warning << "\n"; for (const std::string &Remark : DiagOpts->Remarks) Out.indent(6) << "-R" << Remark << "\n"; return false; } bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override { Out.indent(2) << "Header search options:\n"; Out.indent(4) << "System root [-isysroot=]: '" << HSOpts.Sysroot << "'\n"; Out.indent(4) << "Module Cache: '" << SpecificModuleCachePath << "'\n"; DUMP_BOOLEAN(HSOpts.UseBuiltinIncludes, "Use builtin include directories [-nobuiltininc]"); DUMP_BOOLEAN(HSOpts.UseStandardSystemIncludes, "Use standard system include directories [-nostdinc]"); DUMP_BOOLEAN(HSOpts.UseStandardCXXIncludes, "Use standard C++ include directories [-nostdinc++]"); DUMP_BOOLEAN(HSOpts.UseLibcxx, "Use libc++ (rather than libstdc++) [-stdlib=]"); return false; } bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override { Out.indent(2) << "Preprocessor options:\n"; DUMP_BOOLEAN(PPOpts.UsePredefines, "Uses compiler/target-specific predefines [-undef]"); DUMP_BOOLEAN(PPOpts.DetailedRecord, "Uses detailed preprocessing record (for indexing)"); if (!PPOpts.Macros.empty()) { Out.indent(4) << "Predefined macros:\n"; } for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator I = PPOpts.Macros.begin(), IEnd = PPOpts.Macros.end(); I != IEnd; ++I) { Out.indent(6); if (I->second) Out << "-U"; else Out << "-D"; Out << I->first << "\n"; } return false; } #undef DUMP_BOOLEAN }; } void DumpModuleInfoAction::ExecuteAction() { // Set up the output file. std::unique_ptr<llvm::raw_fd_ostream> OutFile; StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile; if (!OutputFileName.empty() && OutputFileName != "-") { std::error_code EC; OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC, llvm::sys::fs::F_Text)); } llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs(); Out << "Information for module file '" << getCurrentFile() << "':\n"; DumpModuleInfoListener Listener(Out); ASTReader::readASTFileControlBlock( getCurrentFile(), getCompilerInstance().getFileManager(), getCompilerInstance().getPCHContainerReader(), Listener); } #endif // HLSL Change Ends - no support for modules or PCH //===----------------------------------------------------------------------===// // Preprocessor Actions //===----------------------------------------------------------------------===// void DumpRawTokensAction::ExecuteAction() { Preprocessor &PP = getCompilerInstance().getPreprocessor(); SourceManager &SM = PP.getSourceManager(); // Start lexing the specified input file. const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID()); Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOpts()); RawLex.SetKeepWhitespaceMode(true); Token RawTok; RawLex.LexFromRawLexer(RawTok); while (RawTok.isNot(tok::eof)) { PP.DumpToken(RawTok, true); llvm::errs() << "\n"; RawLex.LexFromRawLexer(RawTok); } } void DumpTokensAction::ExecuteAction() { Preprocessor &PP = getCompilerInstance().getPreprocessor(); // Start preprocessing the specified input file. Token Tok; PP.EnterMainSourceFile(); do { PP.Lex(Tok); PP.DumpToken(Tok, true); llvm::errs() << "\n"; } while (Tok.isNot(tok::eof)); } void GeneratePTHAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); raw_pwrite_stream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); if (!OS) return; CacheTokens(CI.getPreprocessor(), OS); } void PreprocessOnlyAction::ExecuteAction() { Preprocessor &PP = getCompilerInstance().getPreprocessor(); // Ignore unknown pragmas. PP.IgnorePragmas(); Token Tok; // Start parsing the specified input file. PP.EnterMainSourceFile(); do { PP.Lex(Tok); } while (Tok.isNot(tok::eof)); } void PrintPreprocessedAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); // Output file may need to be set to 'Binary', to avoid converting Unix style // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>). // // Look to see what type of line endings the file uses. If there's a // CRLF, then we won't open the file up in binary mode. If there is // just an LF or CR, then we will open the file up in binary mode. // In this fashion, the output format should match the input format, unless // the input format has inconsistent line endings. // // This should be a relatively fast operation since most files won't have // all of their source code on a single line. However, that is still a // concern, so if we scan for too long, we'll just assume the file should // be opened in binary mode. bool BinaryMode = true; bool InvalidFile = false; const SourceManager& SM = CI.getSourceManager(); const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(), &InvalidFile); if (!InvalidFile) { const char *cur = Buffer->getBufferStart(); const char *end = Buffer->getBufferEnd(); const char *next = (cur != end) ? cur + 1 : end; // Limit ourselves to only scanning 256 characters into the source // file. This is mostly a sanity check in case the file has no // newlines whatsoever. if (end - cur > 256) end = cur + 256; while (next < end) { if (*cur == 0x0D) { // CR if (*next == 0x0A) // CRLF BinaryMode = false; break; } else if (*cur == 0x0A) // LF break; ++cur, ++next; } } raw_ostream *OS = CI.createDefaultOutputFile(BinaryMode, getCurrentFile()); if (!OS) return; DoPrintPreprocessedInput(CI.getPreprocessor(), OS, CI.getPreprocessorOutputOpts()); } // HLSL Change Begin. HLSLRootSignatureAction::HLSLRootSignatureAction(StringRef rootSigMacro, unsigned major, unsigned minor) : HLSLRootSignatureMacro(rootSigMacro), rootSigMajor(major), rootSigMinor(minor) { rootSigHandle = llvm::make_unique<hlsl::RootSignatureHandle>(); } void HLSLRootSignatureAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); Preprocessor &PP = CI.getPreprocessor(); // Ignore unknown pragmas. PP.IgnorePragmas(); // Scans and ignores all tokens in the files. PP.EnterMainSourceFile(); Token Tok; do PP.Lex(Tok); while (Tok.isNot(tok::eof)); hlsl::DxilRootSignatureVersion rootSigVer; if (rootSigMinor == 0) { rootSigVer = hlsl::DxilRootSignatureVersion::Version_1_0; } else { assert(rootSigMinor == 1 && "else HLSLRootSignatureAction Constructor needs to be updated"); rootSigVer = hlsl::DxilRootSignatureVersion::Version_1_1; } assert(rootSigMajor == 1 && "else HLSLRootSignatureAction Constructor needs to be updated"); (void)rootSigMajor; // Try to find HLSLRootSignatureMacro in macros. MacroInfo *rootSigMacro = hlsl::MacroExpander::FindMacroInfo(PP, HLSLRootSignatureMacro); DiagnosticsEngine &Diags = CI.getDiagnostics(); if (!rootSigMacro) { std::string cannotFindMacro = "undeclared identifier " + HLSLRootSignatureMacro; SourceLocation SLoc = Tok.getLocation(); ReportHLSLRootSigError(Diags, SLoc, cannotFindMacro.c_str(), cannotFindMacro.size()); return; } // Expand HLSLRootSignatureMacro. SourceLocation SLoc = rootSigMacro->getDefinitionLoc(); std::string rootSigString; hlsl::MacroExpander expander(PP, hlsl::MacroExpander::STRIP_QUOTES); if (!expander.ExpandMacro(rootSigMacro, &rootSigString)) { StringRef error("error expanding root signature macro"); ReportHLSLRootSigError(Diags, SLoc, error.data(), error.size()); return; } // Compile the expanded root signature. clang::CompileRootSignature(rootSigString, Diags, SLoc, rootSigVer, hlsl::DxilRootSignatureCompilationFlags::None, rootSigHandle.get()); } std::unique_ptr<hlsl::RootSignatureHandle> HLSLRootSignatureAction::takeRootSigHandle() { return std::move(rootSigHandle); } // HLSL Change End. void PrintPreambleAction::ExecuteAction() { switch (getCurrentFileKind()) { case IK_C: case IK_CXX: case IK_ObjC: case IK_ObjCXX: case IK_OpenCL: case IK_CUDA: break; case IK_None: case IK_Asm: case IK_PreprocessedC: case IK_PreprocessedCuda: case IK_PreprocessedCXX: case IK_PreprocessedObjC: case IK_PreprocessedObjCXX: case IK_AST: case IK_LLVM_IR: case IK_HLSL: // HLSL Change // We can't do anything with these. return; } CompilerInstance &CI = getCompilerInstance(); auto Buffer = CI.getFileManager().getBufferForFile(getCurrentFile()); if (Buffer) { unsigned Preamble = Lexer::ComputePreamble((*Buffer)->getBuffer(), CI.getLangOpts()).first; llvm::outs().write((*Buffer)->getBufferStart(), Preamble); } }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/PCHContainerOperations.cpp
//===--- Frontend/PCHContainerOperations.cpp - PCH Containers ---*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file defines PCHContainerOperations and RawPCHContainerOperation. // //===----------------------------------------------------------------------===// #include "clang/Frontend/PCHContainerOperations.h" #include "clang/AST/ASTConsumer.h" #include "llvm/Bitcode/BitstreamReader.h" #include "llvm/Support/raw_ostream.h" #include "clang/Lex/ModuleLoader.h" using namespace clang; namespace { /// \brief A PCHContainerGenerator that writes out the PCH to a flat file. class RawPCHContainerGenerator : public ASTConsumer { std::shared_ptr<PCHBuffer> Buffer; raw_pwrite_stream *OS; public: RawPCHContainerGenerator(DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO, const PreprocessorOptions &PPO, const TargetOptions &TO, const LangOptions &LO, const std::string &MainFileName, const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, std::shared_ptr<PCHBuffer> Buffer) : Buffer(Buffer), OS(OS) {} virtual ~RawPCHContainerGenerator() {} void HandleTranslationUnit(ASTContext &Ctx) override { if (Buffer->IsComplete) { // Make sure it hits disk now. *OS << Buffer->Data; OS->flush(); } // Free the space of the temporary buffer. llvm::SmallVector<char, 0> Empty; Buffer->Data = std::move(Empty); } }; } std::unique_ptr<ASTConsumer> RawPCHContainerWriter::CreatePCHContainerGenerator( DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO, const PreprocessorOptions &PPO, const TargetOptions &TO, const LangOptions &LO, const std::string &MainFileName, const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, std::shared_ptr<PCHBuffer> Buffer) const { return llvm::make_unique<RawPCHContainerGenerator>( Diags, HSO, PPO, TO, LO, MainFileName, OutputFileName, OS, Buffer); } void RawPCHContainerReader::ExtractPCH( llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const { StreamFile.init((const unsigned char *)Buffer.getBufferStart(), (const unsigned char *)Buffer.getBufferEnd()); } PCHContainerOperations::PCHContainerOperations() { registerWriter(llvm::make_unique<RawPCHContainerWriter>()); registerReader(llvm::make_unique<RawPCHContainerReader>()); }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/TextDiagnostic.cpp
//===--- TextDiagnostic.cpp - Text Diagnostic Pretty-Printing -------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/TextDiagnostic.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Locale.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> using namespace clang; static const enum raw_ostream::Colors noteColor = raw_ostream::BLACK; static const enum raw_ostream::Colors remarkColor = raw_ostream::BLUE; static const enum raw_ostream::Colors fixitColor = raw_ostream::GREEN; static const enum raw_ostream::Colors caretColor = raw_ostream::GREEN; static const enum raw_ostream::Colors warningColor = raw_ostream::MAGENTA; static const enum raw_ostream::Colors templateColor = raw_ostream::CYAN; static const enum raw_ostream::Colors errorColor = raw_ostream::RED; static const enum raw_ostream::Colors fatalColor = raw_ostream::RED; // Used for changing only the bold attribute. static const enum raw_ostream::Colors savedColor = raw_ostream::SAVEDCOLOR; /// \brief Add highlights to differences in template strings. static void applyTemplateHighlighting(raw_ostream &OS, StringRef Str, bool &Normal, bool Bold) { while (1) { size_t Pos = Str.find(ToggleHighlight); OS << Str.slice(0, Pos); if (Pos == StringRef::npos) break; Str = Str.substr(Pos + 1); if (Normal) OS.changeColor(templateColor, true); else { OS.resetColor(); if (Bold) OS.changeColor(savedColor, true); } Normal = !Normal; } } /// \brief Number of spaces to indent when word-wrapping. const unsigned WordWrapIndentation = 6; static int bytesSincePreviousTabOrLineBegin(StringRef SourceLine, size_t i) { int bytes = 0; while (0<i) { if (SourceLine[--i]=='\t') break; ++bytes; } return bytes; } /// \brief returns a printable representation of first item from input range /// /// This function returns a printable representation of the next item in a line /// of source. If the next byte begins a valid and printable character, that /// character is returned along with 'true'. /// /// Otherwise, if the next byte begins a valid, but unprintable character, a /// printable, escaped representation of the character is returned, along with /// 'false'. Otherwise a printable, escaped representation of the next byte /// is returned along with 'false'. /// /// \note The index is updated to be used with a subsequent call to /// printableTextForNextCharacter. /// /// \param SourceLine The line of source /// \param i Pointer to byte index, /// \param TabStop used to expand tabs /// \return pair(printable text, 'true' iff original text was printable) /// static std::pair<SmallString<16>, bool> printableTextForNextCharacter(StringRef SourceLine, size_t *i, unsigned TabStop) { assert(i && "i must not be null"); assert(*i<SourceLine.size() && "must point to a valid index"); if (SourceLine[*i]=='\t') { assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop && "Invalid -ftabstop value"); unsigned col = bytesSincePreviousTabOrLineBegin(SourceLine, *i); unsigned NumSpaces = TabStop - col%TabStop; assert(0 < NumSpaces && NumSpaces <= TabStop && "Invalid computation of space amt"); ++(*i); SmallString<16> expandedTab; expandedTab.assign(NumSpaces, ' '); return std::make_pair(expandedTab, true); } unsigned char const *begin, *end; begin = reinterpret_cast<unsigned char const *>(&*(SourceLine.begin() + *i)); end = begin + (SourceLine.size() - *i); if (isLegalUTF8Sequence(begin, end)) { UTF32 c; UTF32 *cptr = &c; unsigned char const *original_begin = begin; unsigned char const *cp_end = begin+getNumBytesForUTF8(SourceLine[*i]); ConversionResult res = ConvertUTF8toUTF32(&begin, cp_end, &cptr, cptr+1, strictConversion); (void)res; assert(conversionOK==res); assert(0 < begin-original_begin && "we must be further along in the string now"); *i += begin-original_begin; if (!llvm::sys::locale::isPrint(c)) { // If next character is valid UTF-8, but not printable SmallString<16> expandedCP("<U+>"); while (c) { expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(c%16)); c/=16; } while (expandedCP.size() < 8) expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(0)); return std::make_pair(expandedCP, false); } // If next character is valid UTF-8, and printable return std::make_pair(SmallString<16>(original_begin, cp_end), true); } // If next byte is not valid UTF-8 (and therefore not printable) SmallString<16> expandedByte("<XX>"); unsigned char byte = SourceLine[*i]; expandedByte[1] = llvm::hexdigit(byte / 16); expandedByte[2] = llvm::hexdigit(byte % 16); ++(*i); return std::make_pair(expandedByte, false); } static void expandTabs(std::string &SourceLine, unsigned TabStop) { size_t i = SourceLine.size(); while (i>0) { i--; if (SourceLine[i]!='\t') continue; size_t tmp_i = i; std::pair<SmallString<16>,bool> res = printableTextForNextCharacter(SourceLine, &tmp_i, TabStop); SourceLine.replace(i, 1, res.first.c_str()); } } /// This function takes a raw source line and produces a mapping from the bytes /// of the printable representation of the line to the columns those printable /// characters will appear at (numbering the first column as 0). /// /// If a byte 'i' corresponds to multiple columns (e.g. the byte contains a tab /// character) then the array will map that byte to the first column the /// tab appears at and the next value in the map will have been incremented /// more than once. /// /// If a byte is the first in a sequence of bytes that together map to a single /// entity in the output, then the array will map that byte to the appropriate /// column while the subsequent bytes will be -1. /// /// The last element in the array does not correspond to any byte in the input /// and instead is the number of columns needed to display the source /// /// example: (given a tabstop of 8) /// /// "a \t \u3042" -> {0,1,2,8,9,-1,-1,11} /// /// (\\u3042 is represented in UTF-8 by three bytes and takes two columns to /// display) static void byteToColumn(StringRef SourceLine, unsigned TabStop, SmallVectorImpl<int> &out) { out.clear(); if (SourceLine.empty()) { out.resize(1u,0); return; } out.resize(SourceLine.size()+1, -1); int columns = 0; size_t i = 0; while (i<SourceLine.size()) { out[i] = columns; std::pair<SmallString<16>,bool> res = printableTextForNextCharacter(SourceLine, &i, TabStop); columns += llvm::sys::locale::columnWidth(res.first); } out.back() = columns; } /// This function takes a raw source line and produces a mapping from columns /// to the byte of the source line that produced the character displaying at /// that column. This is the inverse of the mapping produced by byteToColumn() /// /// The last element in the array is the number of bytes in the source string /// /// example: (given a tabstop of 8) /// /// "a \t \u3042" -> {0,1,2,-1,-1,-1,-1,-1,3,4,-1,7} /// /// (\\u3042 is represented in UTF-8 by three bytes and takes two columns to /// display) static void columnToByte(StringRef SourceLine, unsigned TabStop, SmallVectorImpl<int> &out) { out.clear(); if (SourceLine.empty()) { out.resize(1u, 0); return; } int columns = 0; size_t i = 0; while (i<SourceLine.size()) { out.resize(columns+1, -1); out.back() = i; std::pair<SmallString<16>,bool> res = printableTextForNextCharacter(SourceLine, &i, TabStop); columns += llvm::sys::locale::columnWidth(res.first); } out.resize(columns+1, -1); out.back() = i; } namespace { struct SourceColumnMap { SourceColumnMap(StringRef SourceLine, unsigned TabStop) : m_SourceLine(SourceLine) { ::byteToColumn(SourceLine, TabStop, m_byteToColumn); ::columnToByte(SourceLine, TabStop, m_columnToByte); assert(m_byteToColumn.size()==SourceLine.size()+1); assert(0 < m_byteToColumn.size() && 0 < m_columnToByte.size()); assert(m_byteToColumn.size() == static_cast<unsigned>(m_columnToByte.back()+1)); assert(static_cast<unsigned>(m_byteToColumn.back()+1) == m_columnToByte.size()); } int columns() const { return m_byteToColumn.back(); } int bytes() const { return m_columnToByte.back(); } /// \brief Map a byte to the column which it is at the start of, or return -1 /// if it is not at the start of a column (for a UTF-8 trailing byte). int byteToColumn(int n) const { assert(0<=n && n<static_cast<int>(m_byteToColumn.size())); return m_byteToColumn[n]; } /// \brief Map a byte to the first column which contains it. int byteToContainingColumn(int N) const { assert(0 <= N && N < static_cast<int>(m_byteToColumn.size())); while (m_byteToColumn[N] == -1) --N; return m_byteToColumn[N]; } /// \brief Map a column to the byte which starts the column, or return -1 if /// the column the second or subsequent column of an expanded tab or similar /// multi-column entity. int columnToByte(int n) const { assert(0<=n && n<static_cast<int>(m_columnToByte.size())); return m_columnToByte[n]; } /// \brief Map from a byte index to the next byte which starts a column. int startOfNextColumn(int N) const { assert(0 <= N && N < static_cast<int>(m_byteToColumn.size() - 1)); while (byteToColumn(++N) == -1) {} return N; } /// \brief Map from a byte index to the previous byte which starts a column. int startOfPreviousColumn(int N) const { assert(0 < N && N < static_cast<int>(m_byteToColumn.size())); while (byteToColumn(--N) == -1) {} return N; } StringRef getSourceLine() const { return m_SourceLine; } private: const std::string m_SourceLine; SmallVector<int,200> m_byteToColumn; SmallVector<int,200> m_columnToByte; }; } // end anonymous namespace /// \brief When the source code line we want to print is too long for /// the terminal, select the "interesting" region. static void selectInterestingSourceRegion(std::string &SourceLine, std::string &CaretLine, std::string &FixItInsertionLine, unsigned Columns, const SourceColumnMap &map) { unsigned CaretColumns = CaretLine.size(); unsigned FixItColumns = llvm::sys::locale::columnWidth(FixItInsertionLine); unsigned MaxColumns = std::max(static_cast<unsigned>(map.columns()), std::max(CaretColumns, FixItColumns)); // if the number of columns is less than the desired number we're done if (MaxColumns <= Columns) return; // No special characters are allowed in CaretLine. assert(CaretLine.end() == std::find_if(CaretLine.begin(), CaretLine.end(), [](char c) { return c < ' ' || '~' < c; })); // Find the slice that we need to display the full caret line // correctly. unsigned CaretStart = 0, CaretEnd = CaretLine.size(); for (; CaretStart != CaretEnd; ++CaretStart) if (!isWhitespace(CaretLine[CaretStart])) break; for (; CaretEnd != CaretStart; --CaretEnd) if (!isWhitespace(CaretLine[CaretEnd - 1])) break; // caret has already been inserted into CaretLine so the above whitespace // check is guaranteed to include the caret // If we have a fix-it line, make sure the slice includes all of the // fix-it information. if (!FixItInsertionLine.empty()) { unsigned FixItStart = 0, FixItEnd = FixItInsertionLine.size(); for (; FixItStart != FixItEnd; ++FixItStart) if (!isWhitespace(FixItInsertionLine[FixItStart])) break; for (; FixItEnd != FixItStart; --FixItEnd) if (!isWhitespace(FixItInsertionLine[FixItEnd - 1])) break; // We can safely use the byte offset FixItStart as the column offset // because the characters up until FixItStart are all ASCII whitespace // characters. unsigned FixItStartCol = FixItStart; unsigned FixItEndCol = llvm::sys::locale::columnWidth(FixItInsertionLine.substr(0, FixItEnd)); CaretStart = std::min(FixItStartCol, CaretStart); CaretEnd = std::max(FixItEndCol, CaretEnd); } // CaretEnd may have been set at the middle of a character // If it's not at a character's first column then advance it past the current // character. while (static_cast<int>(CaretEnd) < map.columns() && -1 == map.columnToByte(CaretEnd)) ++CaretEnd; assert((static_cast<int>(CaretStart) > map.columns() || -1!=map.columnToByte(CaretStart)) && "CaretStart must not point to a column in the middle of a source" " line character"); assert((static_cast<int>(CaretEnd) > map.columns() || -1!=map.columnToByte(CaretEnd)) && "CaretEnd must not point to a column in the middle of a source line" " character"); // CaretLine[CaretStart, CaretEnd) contains all of the interesting // parts of the caret line. While this slice is smaller than the // number of columns we have, try to grow the slice to encompass // more context. unsigned SourceStart = map.columnToByte(std::min<unsigned>(CaretStart, map.columns())); unsigned SourceEnd = map.columnToByte(std::min<unsigned>(CaretEnd, map.columns())); unsigned CaretColumnsOutsideSource = CaretEnd-CaretStart - (map.byteToColumn(SourceEnd)-map.byteToColumn(SourceStart)); char const *front_ellipse = " ..."; char const *front_space = " "; char const *back_ellipse = "..."; unsigned ellipses_space = strlen(front_ellipse) + strlen(back_ellipse); unsigned TargetColumns = Columns; // Give us extra room for the ellipses // and any of the caret line that extends past the source if (TargetColumns > ellipses_space+CaretColumnsOutsideSource) TargetColumns -= ellipses_space+CaretColumnsOutsideSource; while (SourceStart>0 || SourceEnd<SourceLine.size()) { bool ExpandedRegion = false; if (SourceStart>0) { unsigned NewStart = map.startOfPreviousColumn(SourceStart); // Skip over any whitespace we see here; we're looking for // another bit of interesting text. // FIXME: Detect non-ASCII whitespace characters too. while (NewStart && isWhitespace(SourceLine[NewStart])) NewStart = map.startOfPreviousColumn(NewStart); // Skip over this bit of "interesting" text. while (NewStart) { unsigned Prev = map.startOfPreviousColumn(NewStart); if (isWhitespace(SourceLine[Prev])) break; NewStart = Prev; } assert(map.byteToColumn(NewStart) != -1); unsigned NewColumns = map.byteToColumn(SourceEnd) - map.byteToColumn(NewStart); if (NewColumns <= TargetColumns) { SourceStart = NewStart; ExpandedRegion = true; } } if (SourceEnd<SourceLine.size()) { unsigned NewEnd = map.startOfNextColumn(SourceEnd); // Skip over any whitespace we see here; we're looking for // another bit of interesting text. // FIXME: Detect non-ASCII whitespace characters too. while (NewEnd < SourceLine.size() && isWhitespace(SourceLine[NewEnd])) NewEnd = map.startOfNextColumn(NewEnd); // Skip over this bit of "interesting" text. while (NewEnd < SourceLine.size() && isWhitespace(SourceLine[NewEnd])) NewEnd = map.startOfNextColumn(NewEnd); assert(map.byteToColumn(NewEnd) != -1); unsigned NewColumns = map.byteToColumn(NewEnd) - map.byteToColumn(SourceStart); if (NewColumns <= TargetColumns) { SourceEnd = NewEnd; ExpandedRegion = true; } } if (!ExpandedRegion) break; } CaretStart = map.byteToColumn(SourceStart); CaretEnd = map.byteToColumn(SourceEnd) + CaretColumnsOutsideSource; // [CaretStart, CaretEnd) is the slice we want. Update the various // output lines to show only this slice, with two-space padding // before the lines so that it looks nicer. assert(CaretStart!=(unsigned)-1 && CaretEnd!=(unsigned)-1 && SourceStart!=(unsigned)-1 && SourceEnd!=(unsigned)-1); assert(SourceStart <= SourceEnd); assert(CaretStart <= CaretEnd); unsigned BackColumnsRemoved = map.byteToColumn(SourceLine.size())-map.byteToColumn(SourceEnd); unsigned FrontColumnsRemoved = CaretStart; unsigned ColumnsKept = CaretEnd-CaretStart; // We checked up front that the line needed truncation assert(FrontColumnsRemoved+ColumnsKept+BackColumnsRemoved > Columns); // The line needs some truncation, and we'd prefer to keep the front // if possible, so remove the back if (BackColumnsRemoved > strlen(back_ellipse)) SourceLine.replace(SourceEnd, std::string::npos, back_ellipse); // If that's enough then we're done if (FrontColumnsRemoved+ColumnsKept <= Columns) return; // Otherwise remove the front as well if (FrontColumnsRemoved > strlen(front_ellipse)) { SourceLine.replace(0, SourceStart, front_ellipse); CaretLine.replace(0, CaretStart, front_space); if (!FixItInsertionLine.empty()) FixItInsertionLine.replace(0, CaretStart, front_space); } } /// \brief Skip over whitespace in the string, starting at the given /// index. /// /// \returns The index of the first non-whitespace character that is /// greater than or equal to Idx or, if no such character exists, /// returns the end of the string. static unsigned skipWhitespace(unsigned Idx, StringRef Str, unsigned Length) { while (Idx < Length && isWhitespace(Str[Idx])) ++Idx; return Idx; } /// \brief If the given character is the start of some kind of /// balanced punctuation (e.g., quotes or parentheses), return the /// character that will terminate the punctuation. /// /// \returns The ending punctuation character, if any, or the NULL /// character if the input character does not start any punctuation. static inline char findMatchingPunctuation(char c) { switch (c) { case '\'': return '\''; case '`': return '\''; case '"': return '"'; case '(': return ')'; case '[': return ']'; case '{': return '}'; default: break; } return 0; } /// \brief Find the end of the word starting at the given offset /// within a string. /// /// \returns the index pointing one character past the end of the /// word. static unsigned findEndOfWord(unsigned Start, StringRef Str, unsigned Length, unsigned Column, unsigned Columns) { assert(Start < Str.size() && "Invalid start position!"); unsigned End = Start + 1; // If we are already at the end of the string, take that as the word. if (End == Str.size()) return End; // Determine if the start of the string is actually opening // punctuation, e.g., a quote or parentheses. char EndPunct = findMatchingPunctuation(Str[Start]); if (!EndPunct) { // This is a normal word. Just find the first space character. while (End < Length && !isWhitespace(Str[End])) ++End; return End; } // We have the start of a balanced punctuation sequence (quotes, // parentheses, etc.). Determine the full sequence is. SmallString<16> PunctuationEndStack; PunctuationEndStack.push_back(EndPunct); while (End < Length && !PunctuationEndStack.empty()) { if (Str[End] == PunctuationEndStack.back()) PunctuationEndStack.pop_back(); else if (char SubEndPunct = findMatchingPunctuation(Str[End])) PunctuationEndStack.push_back(SubEndPunct); ++End; } // Find the first space character after the punctuation ended. while (End < Length && !isWhitespace(Str[End])) ++End; unsigned PunctWordLength = End - Start; if (// If the word fits on this line Column + PunctWordLength <= Columns || // ... or the word is "short enough" to take up the next line // without too much ugly white space PunctWordLength < Columns/3) return End; // Take the whole thing as a single "word". // The whole quoted/parenthesized string is too long to print as a // single "word". Instead, find the "word" that starts just after // the punctuation and use that end-point instead. This will recurse // until it finds something small enough to consider a word. return findEndOfWord(Start + 1, Str, Length, Column + 1, Columns); } /// \brief Print the given string to a stream, word-wrapping it to /// some number of columns in the process. /// /// \param OS the stream to which the word-wrapping string will be /// emitted. /// \param Str the string to word-wrap and output. /// \param Columns the number of columns to word-wrap to. /// \param Column the column number at which the first character of \p /// Str will be printed. This will be non-zero when part of the first /// line has already been printed. /// \param Bold if the current text should be bold /// \param Indentation the number of spaces to indent any lines beyond /// the first line. /// \returns true if word-wrapping was required, or false if the /// string fit on the first line. static bool printWordWrapped(raw_ostream &OS, StringRef Str, unsigned Columns, unsigned Column = 0, bool Bold = false, unsigned Indentation = WordWrapIndentation) { const unsigned Length = std::min(Str.find('\n'), Str.size()); bool TextNormal = true; // The string used to indent each line. SmallString<16> IndentStr; IndentStr.assign(Indentation, ' '); bool Wrapped = false; for (unsigned WordStart = 0, WordEnd; WordStart < Length; WordStart = WordEnd) { // Find the beginning of the next word. WordStart = skipWhitespace(WordStart, Str, Length); if (WordStart == Length) break; // Find the end of this word. WordEnd = findEndOfWord(WordStart, Str, Length, Column, Columns); // Does this word fit on the current line? unsigned WordLength = WordEnd - WordStart; if (Column + WordLength < Columns) { // This word fits on the current line; print it there. if (WordStart) { OS << ' '; Column += 1; } applyTemplateHighlighting(OS, Str.substr(WordStart, WordLength), TextNormal, Bold); Column += WordLength; continue; } // This word does not fit on the current line, so wrap to the next // line. OS << '\n'; OS.write(&IndentStr[0], Indentation); applyTemplateHighlighting(OS, Str.substr(WordStart, WordLength), TextNormal, Bold); Column = Indentation + WordLength; Wrapped = true; } // Append any remaning text from the message with its existing formatting. applyTemplateHighlighting(OS, Str.substr(Length), TextNormal, Bold); assert(TextNormal && "Text highlighted at end of diagnostic message."); return Wrapped; } TextDiagnostic::TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts, DiagnosticOptions *DiagOpts) : DiagnosticRenderer(LangOpts, DiagOpts), OS(OS) {} TextDiagnostic::~TextDiagnostic() {} void TextDiagnostic::emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<clang::CharSourceRange> Ranges, const SourceManager *SM, DiagOrStoredDiag D) { uint64_t StartOfLocationInfo = OS.tell(); // Emit the location of this particular diagnostic. if (Loc.isValid()) emitDiagnosticLoc(Loc, PLoc, Level, Ranges, *SM); if (DiagOpts->ShowColors) OS.resetColor(); printDiagnosticLevel(OS, Level, DiagOpts->ShowColors, DiagOpts->CLFallbackMode); printDiagnosticMessage(OS, /*IsSupplemental*/ Level == DiagnosticsEngine::Note, Message, OS.tell() - StartOfLocationInfo, DiagOpts->MessageLength, DiagOpts->ShowColors); } /*static*/ void TextDiagnostic::printDiagnosticLevel(raw_ostream &OS, DiagnosticsEngine::Level Level, bool ShowColors, bool CLFallbackMode) { if (ShowColors) { // Print diagnostic category in bold and color switch (Level) { case DiagnosticsEngine::Ignored: llvm_unreachable("Invalid diagnostic type"); case DiagnosticsEngine::Note: OS.changeColor(noteColor, true); break; case DiagnosticsEngine::Remark: OS.changeColor(remarkColor, true); break; case DiagnosticsEngine::Warning: OS.changeColor(warningColor, true); break; case DiagnosticsEngine::Error: OS.changeColor(errorColor, true); break; case DiagnosticsEngine::Fatal: OS.changeColor(fatalColor, true); break; } } switch (Level) { case DiagnosticsEngine::Ignored: llvm_unreachable("Invalid diagnostic type"); case DiagnosticsEngine::Note: OS << "note"; break; case DiagnosticsEngine::Remark: OS << "remark"; break; case DiagnosticsEngine::Warning: OS << "warning"; break; case DiagnosticsEngine::Error: OS << "error"; break; case DiagnosticsEngine::Fatal: OS << "fatal error"; break; } // In clang-cl /fallback mode, print diagnostics as "error(clang):". This // makes it more clear whether a message is coming from clang or cl.exe, // and it prevents MSBuild from concluding that the build failed just because // there is an "error:" in the output. if (CLFallbackMode) OS << "(clang)"; OS << ": "; if (ShowColors) OS.resetColor(); } /*static*/ void TextDiagnostic::printDiagnosticMessage(raw_ostream &OS, bool IsSupplemental, StringRef Message, unsigned CurrentColumn, unsigned Columns, bool ShowColors) { bool Bold = false; if (ShowColors && !IsSupplemental) { // Print primary diagnostic messages in bold and without color, to visually // indicate the transition from continuation notes and other output. OS.changeColor(savedColor, true); Bold = true; } if (Columns) printWordWrapped(OS, Message, Columns, CurrentColumn, Bold); else { bool Normal = true; applyTemplateHighlighting(OS, Message, Normal, Bold); assert(Normal && "Formatting should have returned to normal"); } if (ShowColors) OS.resetColor(); OS << '\n'; } /// \brief Print out the file/line/column information and include trace. /// /// This method handlen the emission of the diagnostic location information. /// This includes extracting as much location information as is present for /// the diagnostic and printing it, as well as any include stack or source /// ranges necessary. void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, ArrayRef<CharSourceRange> Ranges, const SourceManager &SM) { if (PLoc.isInvalid()) { // At least print the file name if available: FileID FID = SM.getFileID(Loc); if (!FID.isInvalid()) { const FileEntry* FE = SM.getFileEntryForID(FID); if (FE && FE->isValid()) { OS << FE->getName(); if (FE->isInPCH()) OS << " (in PCH)"; OS << ": "; } } return; } unsigned LineNo = PLoc.getLine(); if (!DiagOpts->ShowLocation) return; if (DiagOpts->ShowColors) OS.changeColor(savedColor, true); OS << PLoc.getFilename(); switch (DiagOpts->getFormat()) { case DiagnosticOptions::Clang: OS << ':' << LineNo; break; case DiagnosticOptions::MSVC: OS << '(' << LineNo; break; case DiagnosticOptions::Vi: OS << " +" << LineNo; break; } if (DiagOpts->ShowColumn) // Compute the column number. if (unsigned ColNo = PLoc.getColumn()) { if (DiagOpts->getFormat() == DiagnosticOptions::MSVC) { OS << ','; // Visual Studio 2010 or earlier expects column number to be off by one if (LangOpts.MSCompatibilityVersion && !LangOpts.isCompatibleWithMSVC(LangOptions::MSVC2012)) ColNo--; } else OS << ':'; OS << ColNo; } switch (DiagOpts->getFormat()) { case DiagnosticOptions::Clang: case DiagnosticOptions::Vi: OS << ':'; break; case DiagnosticOptions::MSVC: OS << ") : "; break; } if (DiagOpts->ShowSourceRanges && !Ranges.empty()) { FileID CaretFileID = SM.getFileID(SM.getExpansionLoc(Loc)); bool PrintedRange = false; for (ArrayRef<CharSourceRange>::const_iterator RI = Ranges.begin(), RE = Ranges.end(); RI != RE; ++RI) { // Ignore invalid ranges. if (!RI->isValid()) continue; SourceLocation B = SM.getExpansionLoc(RI->getBegin()); SourceLocation E = SM.getExpansionLoc(RI->getEnd()); // If the End location and the start location are the same and are a // macro location, then the range was something that came from a // macro expansion or _Pragma. If this is an object-like macro, the // best we can do is to highlight the range. If this is a // function-like macro, we'd also like to highlight the arguments. if (B == E && RI->getEnd().isMacroID()) E = SM.getExpansionRange(RI->getEnd()).second; std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B); std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E); // If the start or end of the range is in another file, just discard // it. if (BInfo.first != CaretFileID || EInfo.first != CaretFileID) continue; // Add in the length of the token, so that we cover multi-char // tokens. unsigned TokSize = 0; if (RI->isTokenRange()) TokSize = Lexer::MeasureTokenLength(E, SM, LangOpts); OS << '{' << SM.getLineNumber(BInfo.first, BInfo.second) << ':' << SM.getColumnNumber(BInfo.first, BInfo.second) << '-' << SM.getLineNumber(EInfo.first, EInfo.second) << ':' << (SM.getColumnNumber(EInfo.first, EInfo.second)+TokSize) << '}'; PrintedRange = true; } if (PrintedRange) OS << ':'; } OS << ' '; } void TextDiagnostic::emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, const SourceManager &SM) { if (DiagOpts->ShowLocation) OS << "In file included from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; else OS << "In included file:\n"; } void TextDiagnostic::emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, StringRef ModuleName, const SourceManager &SM) { if (DiagOpts->ShowLocation) OS << "In module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; else OS << "In module " << ModuleName << "':\n"; } void TextDiagnostic::emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, StringRef ModuleName, const SourceManager &SM) { if (DiagOpts->ShowLocation && PLoc.getFilename()) OS << "While building module '" << ModuleName << "' imported from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; else OS << "While building module '" << ModuleName << "':\n"; } /// \brief Highlight a SourceRange (with ~'s) for any characters on LineNo. static void highlightRange(const CharSourceRange &R, unsigned LineNo, FileID FID, const SourceColumnMap &map, std::string &CaretLine, const SourceManager &SM, const LangOptions &LangOpts) { if (!R.isValid()) return; SourceLocation Begin = R.getBegin(); SourceLocation End = R.getEnd(); unsigned StartLineNo = SM.getExpansionLineNumber(Begin); if (StartLineNo > LineNo || SM.getFileID(Begin) != FID) return; // No intersection. unsigned EndLineNo = SM.getExpansionLineNumber(End); if (EndLineNo < LineNo || SM.getFileID(End) != FID) return; // No intersection. // Compute the column number of the start. unsigned StartColNo = 0; if (StartLineNo == LineNo) { StartColNo = SM.getExpansionColumnNumber(Begin); if (StartColNo) --StartColNo; // Zero base the col #. } // Compute the column number of the end. unsigned EndColNo = map.getSourceLine().size(); if (EndLineNo == LineNo) { EndColNo = SM.getExpansionColumnNumber(End); if (EndColNo) { --EndColNo; // Zero base the col #. // Add in the length of the token, so that we cover multi-char tokens if // this is a token range. if (R.isTokenRange()) EndColNo += Lexer::MeasureTokenLength(End, SM, LangOpts); } else { EndColNo = CaretLine.size(); } } assert(StartColNo <= EndColNo && "Invalid range!"); // Check that a token range does not highlight only whitespace. if (R.isTokenRange()) { // Pick the first non-whitespace column. while (StartColNo < map.getSourceLine().size() && (map.getSourceLine()[StartColNo] == ' ' || map.getSourceLine()[StartColNo] == '\t')) StartColNo = map.startOfNextColumn(StartColNo); // Pick the last non-whitespace column. if (EndColNo > map.getSourceLine().size()) EndColNo = map.getSourceLine().size(); while (EndColNo && (map.getSourceLine()[EndColNo-1] == ' ' || map.getSourceLine()[EndColNo-1] == '\t')) EndColNo = map.startOfPreviousColumn(EndColNo); // If the start/end passed each other, then we are trying to highlight a // range that just exists in whitespace, which must be some sort of other // bug. assert(StartColNo <= EndColNo && "Trying to highlight whitespace??"); } assert(StartColNo <= map.getSourceLine().size() && "Invalid range!"); assert(EndColNo <= map.getSourceLine().size() && "Invalid range!"); // Fill the range with ~'s. StartColNo = map.byteToContainingColumn(StartColNo); EndColNo = map.byteToContainingColumn(EndColNo); assert(StartColNo <= EndColNo && "Invalid range!"); if (CaretLine.size() < EndColNo) CaretLine.resize(EndColNo,' '); std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~'); } static std::string buildFixItInsertionLine(unsigned LineNo, const SourceColumnMap &map, ArrayRef<FixItHint> Hints, const SourceManager &SM, const DiagnosticOptions *DiagOpts) { std::string FixItInsertionLine; if (Hints.empty() || !DiagOpts->ShowFixits) return FixItInsertionLine; unsigned PrevHintEndCol = 0; for (ArrayRef<FixItHint>::iterator I = Hints.begin(), E = Hints.end(); I != E; ++I) { if (!I->CodeToInsert.empty()) { // We have an insertion hint. Determine whether the inserted // code contains no newlines and is on the same line as the caret. std::pair<FileID, unsigned> HintLocInfo = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin()); if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) && StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) { // Insert the new code into the line just below the code // that the user wrote. // Note: When modifying this function, be very careful about what is a // "column" (printed width, platform-dependent) and what is a // "byte offset" (SourceManager "column"). unsigned HintByteOffset = SM.getColumnNumber(HintLocInfo.first, HintLocInfo.second) - 1; // The hint must start inside the source or right at the end assert(HintByteOffset < static_cast<unsigned>(map.bytes())+1); unsigned HintCol = map.byteToContainingColumn(HintByteOffset); // If we inserted a long previous hint, push this one forwards, and add // an extra space to show that this is not part of the previous // completion. This is sort of the best we can do when two hints appear // to overlap. // // Note that if this hint is located immediately after the previous // hint, no space will be added, since the location is more important. if (HintCol < PrevHintEndCol) HintCol = PrevHintEndCol + 1; // This should NOT use HintByteOffset, because the source might have // Unicode characters in earlier columns. unsigned NewFixItLineSize = FixItInsertionLine.size() + (HintCol - PrevHintEndCol) + I->CodeToInsert.size(); if (NewFixItLineSize > FixItInsertionLine.size()) FixItInsertionLine.resize(NewFixItLineSize, ' '); std::copy(I->CodeToInsert.begin(), I->CodeToInsert.end(), FixItInsertionLine.end() - I->CodeToInsert.size()); PrevHintEndCol = HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert); } else { FixItInsertionLine.clear(); break; } } } expandTabs(FixItInsertionLine, DiagOpts->TabStop); return FixItInsertionLine; } /// \brief Emit a code snippet and caret line. /// /// This routine emits a single line's code snippet and caret line.. /// /// \param Loc The location for the caret. /// \param Ranges The underlined ranges for this code snippet. /// \param Hints The FixIt hints active for this diagnostic. void TextDiagnostic::emitSnippetAndCaret( SourceLocation Loc, DiagnosticsEngine::Level Level, SmallVectorImpl<CharSourceRange>& Ranges, ArrayRef<FixItHint> Hints, const SourceManager &SM) { assert(!Loc.isInvalid() && "must have a valid source location here"); assert(Loc.isFileID() && "must have a file location here"); // If caret diagnostics are enabled and we have location, we want to // emit the caret. However, we only do this if the location moved // from the last diagnostic, if the last diagnostic was a note that // was part of a different warning or error diagnostic, or if the // diagnostic has ranges. We don't want to emit the same caret // multiple times if one loc has multiple diagnostics. if (!DiagOpts->ShowCarets) return; if (Loc == LastLoc && Ranges.empty() && Hints.empty() && (LastLevel != DiagnosticsEngine::Note || Level == LastLevel)) return; // Decompose the location into a FID/Offset pair. std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc); FileID FID = LocInfo.first; unsigned FileOffset = LocInfo.second; // Get information about the buffer it points into. bool Invalid = false; const char *BufStart = SM.getBufferData(FID, &Invalid).data(); if (Invalid) return; unsigned LineNo = SM.getLineNumber(FID, FileOffset); unsigned ColNo = SM.getColumnNumber(FID, FileOffset); // Arbitrarily stop showing snippets when the line is too long. static const size_t MaxLineLengthToPrint = 4096; if (ColNo > MaxLineLengthToPrint) return; // Rewind from the current position to the start of the line. const char *TokPtr = BufStart+FileOffset; const char *LineStart = TokPtr-ColNo+1; // Column # is 1-based. // Compute the line end. Scan forward from the error position to the end of // the line. const char *LineEnd = TokPtr; while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0') ++LineEnd; // Arbitrarily stop showing snippets when the line is too long. if (size_t(LineEnd - LineStart) > MaxLineLengthToPrint) return; // Copy the line of code into an std::string for ease of manipulation. std::string SourceLine(LineStart, LineEnd); // Build the byte to column map. const SourceColumnMap sourceColMap(SourceLine, DiagOpts->TabStop); // Create a line for the caret that is filled with spaces that is the same // number of columns as the line of source code. std::string CaretLine(sourceColMap.columns(), ' '); // Highlight all of the characters covered by Ranges with ~ characters. for (SmallVectorImpl<CharSourceRange>::iterator I = Ranges.begin(), E = Ranges.end(); I != E; ++I) highlightRange(*I, LineNo, FID, sourceColMap, CaretLine, SM, LangOpts); // Next, insert the caret itself. ColNo = sourceColMap.byteToContainingColumn(ColNo-1); if (CaretLine.size()<ColNo+1) CaretLine.resize(ColNo+1, ' '); CaretLine[ColNo] = '^'; std::string FixItInsertionLine = buildFixItInsertionLine(LineNo, sourceColMap, Hints, SM, DiagOpts.get()); // If the source line is too long for our terminal, select only the // "interesting" source region within that line. unsigned Columns = DiagOpts->MessageLength; if (Columns) selectInterestingSourceRegion(SourceLine, CaretLine, FixItInsertionLine, Columns, sourceColMap); // If we are in -fdiagnostics-print-source-range-info mode, we are trying // to produce easily machine parsable output. Add a space before the // source line and the caret to make it trivial to tell the main diagnostic // line from what the user is intended to see. if (DiagOpts->ShowSourceRanges) { SourceLine = ' ' + SourceLine; CaretLine = ' ' + CaretLine; } // Finally, remove any blank spaces from the end of CaretLine. while (CaretLine[CaretLine.size()-1] == ' ') CaretLine.erase(CaretLine.end()-1); // Emit what we have computed. emitSnippet(SourceLine); if (DiagOpts->ShowColors) OS.changeColor(caretColor, true); OS << CaretLine << '\n'; if (DiagOpts->ShowColors) OS.resetColor(); if (!FixItInsertionLine.empty()) { if (DiagOpts->ShowColors) // Print fixit line in color OS.changeColor(fixitColor, false); if (DiagOpts->ShowSourceRanges) OS << ' '; OS << FixItInsertionLine << '\n'; if (DiagOpts->ShowColors) OS.resetColor(); } // Print out any parseable fixit information requested by the options. emitParseableFixits(Hints, SM); } void TextDiagnostic::emitSnippet(StringRef line) { if (line.empty()) return; size_t i = 0; std::string to_print; bool print_reversed = false; while (i<line.size()) { std::pair<SmallString<16>,bool> res = printableTextForNextCharacter(line, &i, DiagOpts->TabStop); bool was_printable = res.second; if (DiagOpts->ShowColors && was_printable == print_reversed) { if (print_reversed) OS.reverseColor(); OS << to_print; to_print.clear(); if (DiagOpts->ShowColors) OS.resetColor(); } print_reversed = !was_printable; to_print += res.first.str(); } if (print_reversed && DiagOpts->ShowColors) OS.reverseColor(); OS << to_print; if (print_reversed && DiagOpts->ShowColors) OS.resetColor(); OS << '\n'; } void TextDiagnostic::emitParseableFixits(ArrayRef<FixItHint> Hints, const SourceManager &SM) { if (!DiagOpts->ShowParseableFixits) return; // We follow FixItRewriter's example in not (yet) handling // fix-its in macros. for (ArrayRef<FixItHint>::iterator I = Hints.begin(), E = Hints.end(); I != E; ++I) { if (I->RemoveRange.isInvalid() || I->RemoveRange.getBegin().isMacroID() || I->RemoveRange.getEnd().isMacroID()) return; } for (ArrayRef<FixItHint>::iterator I = Hints.begin(), E = Hints.end(); I != E; ++I) { SourceLocation BLoc = I->RemoveRange.getBegin(); SourceLocation ELoc = I->RemoveRange.getEnd(); std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(BLoc); std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(ELoc); // Adjust for token ranges. if (I->RemoveRange.isTokenRange()) EInfo.second += Lexer::MeasureTokenLength(ELoc, SM, LangOpts); // We specifically do not do word-wrapping or tab-expansion here, // because this is supposed to be easy to parse. PresumedLoc PLoc = SM.getPresumedLoc(BLoc); if (PLoc.isInvalid()) break; OS << "fix-it:\""; OS.write_escaped(PLoc.getFilename()); OS << "\":{" << SM.getLineNumber(BInfo.first, BInfo.second) << ':' << SM.getColumnNumber(BInfo.first, BInfo.second) << '-' << SM.getLineNumber(EInfo.first, EInfo.second) << ':' << SM.getColumnNumber(EInfo.first, EInfo.second) << "}:\""; OS.write_escaped(I->CodeToInsert); OS << "\"\n"; } }
0
repos/DirectXShaderCompiler/tools/clang/lib
repos/DirectXShaderCompiler/tools/clang/lib/Frontend/SerializedDiagnosticReader.cpp
//===--- SerializedDiagnosticReader.cpp - Reads diagnostics ---------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "clang/Frontend/SerializedDiagnosticReader.h" #include "clang/Basic/FileManager.h" #include "clang/Frontend/SerializedDiagnostics.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" using namespace clang; using namespace clang::serialized_diags; std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) { // Open the diagnostics file. FileSystemOptions FO; FileManager FileMgr(FO); auto Buffer = FileMgr.getBufferForFile(File); if (!Buffer) return SDError::CouldNotLoad; llvm::BitstreamReader StreamFile; StreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(), (const unsigned char *)(*Buffer)->getBufferEnd()); llvm::BitstreamCursor Stream(StreamFile); // Sniff for the signature. if (Stream.Read(8) != 'D' || Stream.Read(8) != 'I' || Stream.Read(8) != 'A' || Stream.Read(8) != 'G') return SDError::InvalidSignature; // Read the top level blocks. while (!Stream.AtEndOfStream()) { if (Stream.ReadCode() != llvm::bitc::ENTER_SUBBLOCK) return SDError::InvalidDiagnostics; std::error_code EC; switch (Stream.ReadSubBlockID()) { case llvm::bitc::BLOCKINFO_BLOCK_ID: if (Stream.ReadBlockInfoBlock()) return SDError::MalformedBlockInfoBlock; continue; case BLOCK_META: if ((EC = readMetaBlock(Stream))) return EC; continue; case BLOCK_DIAG: if ((EC = readDiagnosticBlock(Stream))) return EC; continue; default: if (!Stream.SkipBlock()) return SDError::MalformedTopLevelBlock; continue; } } return std::error_code(); } enum class SerializedDiagnosticReader::Cursor { Record = 1, BlockEnd, BlockBegin }; llvm::ErrorOr<SerializedDiagnosticReader::Cursor> SerializedDiagnosticReader::skipUntilRecordOrBlock( llvm::BitstreamCursor &Stream, unsigned &BlockOrRecordID) { BlockOrRecordID = 0; while (!Stream.AtEndOfStream()) { unsigned Code = Stream.ReadCode(); switch ((llvm::bitc::FixedAbbrevIDs)Code) { case llvm::bitc::ENTER_SUBBLOCK: BlockOrRecordID = Stream.ReadSubBlockID(); return Cursor::BlockBegin; case llvm::bitc::END_BLOCK: if (Stream.ReadBlockEnd()) return SDError::InvalidDiagnostics; return Cursor::BlockEnd; case llvm::bitc::DEFINE_ABBREV: Stream.ReadAbbrevRecord(); continue; case llvm::bitc::UNABBREV_RECORD: return SDError::UnsupportedConstruct; default: // We found a record. BlockOrRecordID = Code; return Cursor::Record; } } return SDError::InvalidDiagnostics; } std::error_code SerializedDiagnosticReader::readMetaBlock(llvm::BitstreamCursor &Stream) { if (Stream.EnterSubBlock(clang::serialized_diags::BLOCK_META)) return SDError::MalformedMetadataBlock; bool VersionChecked = false; while (true) { unsigned BlockOrCode = 0; llvm::ErrorOr<Cursor> Res = skipUntilRecordOrBlock(Stream, BlockOrCode); if (!Res) Res.getError(); switch (Res.get()) { case Cursor::Record: break; case Cursor::BlockBegin: if (Stream.SkipBlock()) return SDError::MalformedMetadataBlock; LLVM_FALLTHROUGH; // HLSL Change case Cursor::BlockEnd: if (!VersionChecked) return SDError::MissingVersion; return std::error_code(); } SmallVector<uint64_t, 1> Record; unsigned RecordID = Stream.readRecord(BlockOrCode, Record); if (RecordID == RECORD_VERSION) { if (Record.size() < 1) return SDError::MissingVersion; if (Record[0] > VersionNumber) return SDError::VersionMismatch; VersionChecked = true; } } } std::error_code SerializedDiagnosticReader::readDiagnosticBlock(llvm::BitstreamCursor &Stream) { if (Stream.EnterSubBlock(clang::serialized_diags::BLOCK_DIAG)) return SDError::MalformedDiagnosticBlock; std::error_code EC; if ((EC = visitStartOfDiagnostic())) return EC; SmallVector<uint64_t, 16> Record; while (true) { unsigned BlockOrCode = 0; llvm::ErrorOr<Cursor> Res = skipUntilRecordOrBlock(Stream, BlockOrCode); if (!Res) Res.getError(); switch (Res.get()) { case Cursor::BlockBegin: // The only blocks we care about are subdiagnostics. if (BlockOrCode == serialized_diags::BLOCK_DIAG) { if ((EC = readDiagnosticBlock(Stream))) return EC; } else if (!Stream.SkipBlock()) return SDError::MalformedSubBlock; continue; case Cursor::BlockEnd: if ((EC = visitEndOfDiagnostic())) return EC; return std::error_code(); case Cursor::Record: break; } // Read the record. Record.clear(); StringRef Blob; unsigned RecID = Stream.readRecord(BlockOrCode, Record, &Blob); if (RecID < serialized_diags::RECORD_FIRST || RecID > serialized_diags::RECORD_LAST) continue; switch ((RecordIDs)RecID) { case RECORD_CATEGORY: // A category has ID and name size. if (Record.size() != 2) return SDError::MalformedDiagnosticRecord; if ((EC = visitCategoryRecord(Record[0], Blob))) return EC; continue; case RECORD_DIAG: // A diagnostic has severity, location (4), category, flag, and message // size. if (Record.size() != 8) return SDError::MalformedDiagnosticRecord; if ((EC = visitDiagnosticRecord( Record[0], Location(Record[1], Record[2], Record[3], Record[4]), Record[5], Record[6], Blob))) return EC; continue; case RECORD_DIAG_FLAG: // A diagnostic flag has ID and name size. if (Record.size() != 2) return SDError::MalformedDiagnosticRecord; if ((EC = visitDiagFlagRecord(Record[0], Blob))) return EC; continue; case RECORD_FILENAME: // A filename has ID, size, timestamp, and name size. The size and // timestamp are legacy fields that are always zero these days. if (Record.size() != 4) return SDError::MalformedDiagnosticRecord; if ((EC = visitFilenameRecord(Record[0], Record[1], Record[2], Blob))) return EC; continue; case RECORD_FIXIT: // A fixit has two locations (4 each) and message size. if (Record.size() != 9) return SDError::MalformedDiagnosticRecord; if ((EC = visitFixitRecord( Location(Record[0], Record[1], Record[2], Record[3]), Location(Record[4], Record[5], Record[6], Record[7]), Blob))) return EC; continue; case RECORD_SOURCE_RANGE: // A source range is two locations (4 each). if (Record.size() != 8) return SDError::MalformedDiagnosticRecord; if ((EC = visitSourceRangeRecord( Location(Record[0], Record[1], Record[2], Record[3]), Location(Record[4], Record[5], Record[6], Record[7])))) return EC; continue; case RECORD_VERSION: // A version is just a number. if (Record.size() != 1) return SDError::MalformedDiagnosticRecord; if ((EC = visitVersionRecord(Record[0]))) return EC; continue; } } } namespace { class SDErrorCategoryType final : public std::error_category { const char *name() const LLVM_NOEXCEPT override { return "clang.serialized_diags"; } std::string message(int IE) const override { SDError E = static_cast<SDError>(IE); switch (E) { case SDError::CouldNotLoad: return "Failed to open diagnostics file"; case SDError::InvalidSignature: return "Invalid diagnostics signature"; case SDError::InvalidDiagnostics: return "Parse error reading diagnostics"; case SDError::MalformedTopLevelBlock: return "Malformed block at top-level of diagnostics"; case SDError::MalformedSubBlock: return "Malformed sub-block in a diagnostic"; case SDError::MalformedBlockInfoBlock: return "Malformed BlockInfo block"; case SDError::MalformedMetadataBlock: return "Malformed Metadata block"; case SDError::MalformedDiagnosticBlock: return "Malformed Diagnostic block"; case SDError::MalformedDiagnosticRecord: return "Malformed Diagnostic record"; case SDError::MissingVersion: return "No version provided in diagnostics"; case SDError::VersionMismatch: return "Unsupported diagnostics version"; case SDError::UnsupportedConstruct: return "Bitcode constructs that are not supported in diagnostics appear"; case SDError::HandlerFailed: return "Generic error occurred while handling a record"; } llvm_unreachable("Unknown error type!"); } }; } static llvm::ManagedStatic<SDErrorCategoryType> ErrorCategory; const std::error_category &clang::serialized_diags::SDErrorCategory() { return *ErrorCategory; }