clang  19.0.0git
pmmintrin.h
Go to the documentation of this file.
1 /*===---- pmmintrin.h - Implementation of SSE3 intrinsics on PowerPC -------===
2  *
3  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4  * See https://llvm.org/LICENSE.txt for license information.
5  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
10 /* Implemented from the specification included in the Intel C++ Compiler
11  User Guide and Reference, version 9.0. */
12 
13 #ifndef NO_WARN_X86_INTRINSICS
14 /* This header is distributed to simplify porting x86_64 code that
15  makes explicit use of Intel intrinsics to powerpc64le.
16  It is the user's responsibility to determine if the results are
17  acceptable and make additional changes as necessary.
18  Note that much code that uses Intel intrinsics can be rewritten in
19  standard C or GNU C extensions, which are more portable and better
20  optimized across multiple targets.
21 
22  In the specific case of X86 SSE3 intrinsics, the PowerPC VMX/VSX ISA
23  is a good match for most SIMD operations. However the Horizontal
24  add/sub requires the data pairs be permuted into a separate
25  registers with vertical even/odd alignment for the operation.
26  And the addsub operation requires the sign of only the even numbered
27  elements be flipped (xored with -0.0).
28  For larger blocks of code using these intrinsic implementations,
29  the compiler be should be able to schedule instructions to avoid
30  additional latency.
31 
32  In the specific case of the monitor and mwait instructions there are
33  no direct equivalent in the PowerISA at this time. So those
34  intrinsics are not implemented. */
35 #error \
36  "Please read comment above. Use -DNO_WARN_X86_INTRINSICS to disable this warning."
37 #endif
38 
39 #ifndef PMMINTRIN_H_
40 #define PMMINTRIN_H_
41 
42 #if defined(__powerpc64__) && \
43  (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
44 
45 /* We need definitions from the SSE2 and SSE header files*/
46 #include <emmintrin.h>
47 
48 extern __inline __m128
49  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
50  _mm_addsub_ps(__m128 __X, __m128 __Y) {
51  const __v4sf __even_n0 = {-0.0, 0.0, -0.0, 0.0};
52  __v4sf __even_neg_Y = vec_xor(__Y, __even_n0);
53  return (__m128)vec_add(__X, __even_neg_Y);
54 }
55 
56 extern __inline __m128d
57  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
58  _mm_addsub_pd(__m128d __X, __m128d __Y) {
59  const __v2df __even_n0 = {-0.0, 0.0};
60  __v2df __even_neg_Y = vec_xor(__Y, __even_n0);
61  return (__m128d)vec_add(__X, __even_neg_Y);
62 }
63 
64 extern __inline __m128
65  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
66  _mm_hadd_ps(__m128 __X, __m128 __Y) {
67  __vector unsigned char __xform2 = {0x00, 0x01, 0x02, 0x03, 0x08, 0x09,
68  0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13,
69  0x18, 0x19, 0x1A, 0x1B};
70  __vector unsigned char __xform1 = {0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D,
71  0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17,
72  0x1C, 0x1D, 0x1E, 0x1F};
73  return (__m128)vec_add(vec_perm((__v4sf)__X, (__v4sf)__Y, __xform2),
74  vec_perm((__v4sf)__X, (__v4sf)__Y, __xform1));
75 }
76 
77 extern __inline __m128
78  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
79  _mm_hsub_ps(__m128 __X, __m128 __Y) {
80  __vector unsigned char __xform2 = {0x00, 0x01, 0x02, 0x03, 0x08, 0x09,
81  0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13,
82  0x18, 0x19, 0x1A, 0x1B};
83  __vector unsigned char __xform1 = {0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D,
84  0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17,
85  0x1C, 0x1D, 0x1E, 0x1F};
86  return (__m128)vec_sub(vec_perm((__v4sf)__X, (__v4sf)__Y, __xform2),
87  vec_perm((__v4sf)__X, (__v4sf)__Y, __xform1));
88 }
89 
90 extern __inline __m128d
91  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
92  _mm_hadd_pd(__m128d __X, __m128d __Y) {
93  return (__m128d)vec_add(vec_mergeh((__v2df)__X, (__v2df)__Y),
94  vec_mergel((__v2df)__X, (__v2df)__Y));
95 }
96 
97 extern __inline __m128d
98  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
99  _mm_hsub_pd(__m128d __X, __m128d __Y) {
100  return (__m128d)vec_sub(vec_mergeh((__v2df)__X, (__v2df)__Y),
101  vec_mergel((__v2df)__X, (__v2df)__Y));
102 }
103 
104 #ifdef _ARCH_PWR8
105 extern __inline __m128
106  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
107  _mm_movehdup_ps(__m128 __X) {
108  return (__m128)vec_mergeo((__v4su)__X, (__v4su)__X);
109 }
110 #endif
111 
112 #ifdef _ARCH_PWR8
113 extern __inline __m128
114  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
115  _mm_moveldup_ps(__m128 __X) {
116  return (__m128)vec_mergee((__v4su)__X, (__v4su)__X);
117 }
118 #endif
119 
120 extern __inline __m128d
121  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
122  _mm_loaddup_pd(double const *__P) {
123  return (__m128d)vec_splats(*__P);
124 }
125 
126 extern __inline __m128d
127  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
128  _mm_movedup_pd(__m128d __X) {
129  return _mm_shuffle_pd(__X, __X, _MM_SHUFFLE2(0, 0));
130 }
131 
132 extern __inline __m128i
133  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
134  _mm_lddqu_si128(__m128i const *__P) {
135  return (__m128i)(vec_vsx_ld(0, (signed int const *)__P));
136 }
137 
138 /* POWER8 / POWER9 have no equivalent for _mm_monitor nor _mm_wait. */
139 
140 #else
141 #include_next <pmmintrin.h>
142 #endif /* defined(__powerpc64__) && \
143  * (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX)) */
144 
145 #endif /* PMMINTRIN_H_ */
_Float16 __2f16 __attribute__((ext_vector_type(2)))
Zeroes the upper 128 bits (bits 255:128) of all YMM registers.
static __inline__ vector signed char __ATTRS_o_ai vec_splats(signed char __a)
Definition: altivec.h:14737
static __inline__ vector signed char __ATTRS_o_ai vec_mergel(vector signed char __a, vector signed char __b)
Definition: altivec.h:5361
static __inline__ vector signed char __ATTRS_o_ai vec_perm(vector signed char __a, vector signed char __b, vector unsigned char __c)
Definition: altivec.h:7962
static __inline__ vector signed char __ATTRS_o_ai vec_mergeh(vector signed char __a, vector signed char __b)
Definition: altivec.h:5091
static __inline__ vector signed char __ATTRS_o_ai vec_add(vector signed char __a, vector signed char __b)
Definition: altivec.h:200
static __inline__ vector unsigned char __ATTRS_o_ai vec_xor(vector unsigned char __a, vector unsigned char __b)
Definition: altivec.h:13207
static __inline__ vector signed char __ATTRS_o_ai vec_sub(vector signed char __a, vector signed char __b)
Definition: altivec.h:11869
#define _MM_SHUFFLE2(x, y)
Definition: emmintrin.h:4895
#define _mm_shuffle_pd(a, b, i)
Constructs a 128-bit floating-point vector of [2 x double] from two 128-bit vector parameters of [2 x...
Definition: emmintrin.h:4710
static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_hadd_pd(__m128d __a, __m128d __b)
Horizontally adds the pairs of values contained in two 128-bit vectors of [2 x double].
Definition: pmmintrin.h:189
static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_movedup_pd(__m128d __a)
Moves and duplicates the double-precision value in the lower bits of a 128-bit vector of [2 x double]...
Definition: pmmintrin.h:248
static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_hadd_ps(__m128 __a, __m128 __b)
Horizontally adds the adjacent pairs of values contained in two 128-bit vectors of [4 x float].
Definition: pmmintrin.h:81
#define _mm_loaddup_pd(dp)
Moves and duplicates one double-precision value to double-precision values stored in a 128-bit vector...
Definition: pmmintrin.h:232
static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_addsub_pd(__m128d __a, __m128d __b)
Adds the even-indexed values and subtracts the odd-indexed values of two 128-bit vectors of [2 x doub...
Definition: pmmintrin.h:166
static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_hsub_pd(__m128d __a, __m128d __b)
Horizontally subtracts the pairs of values contained in two 128-bit vectors of [2 x double].
Definition: pmmintrin.h:212
static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_movehdup_ps(__m128 __a)
Moves and duplicates odd-indexed values from a 128-bit vector of [4 x float] to float values stored i...
Definition: pmmintrin.h:126
static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_moveldup_ps(__m128 __a)
Duplicates even-indexed values from a 128-bit vector of [4 x float] to float values stored in a 128-b...
Definition: pmmintrin.h:147
static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_addsub_ps(__m128 __a, __m128 __b)
Adds the even-indexed values and subtracts the odd-indexed values of two 128-bit vectors of [4 x floa...
Definition: pmmintrin.h:58
static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_hsub_ps(__m128 __a, __m128 __b)
Horizontally subtracts the adjacent pairs of values contained in two 128-bit vectors of [4 x float].
Definition: pmmintrin.h:104
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_lddqu_si128(__m128i_u const *__p)
Loads data from an unaligned memory location to elements in a 128-bit vector.
Definition: pmmintrin.h:39
__inline unsigned int unsigned int unsigned int * __P
Definition: bmi2intrin.h:25
__inline unsigned int unsigned int __Y
Definition: bmi2intrin.h:19