annotate gcc/config/rs6000/bmi2intrin.h @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1 /* Copyright (C) 2011-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 This file is part of GCC.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
7 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
8 any later version.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
13 GNU General Public License for more details.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
16 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
17 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
20 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
22 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 /* This header is distributed to simplify porting x86_64 code that
kono
parents:
diff changeset
25 makes explicit use of Intel intrinsics to powerpc64le.
kono
parents:
diff changeset
26 It is the user's responsibility to determine if the results are
kono
parents:
diff changeset
27 acceptable and make additional changes as necessary.
kono
parents:
diff changeset
28 Note that much code that uses Intel intrinsics can be rewritten in
kono
parents:
diff changeset
29 standard C or GNU C extensions, which are more portable and better
kono
parents:
diff changeset
30 optimized across multiple targets. */
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 #if !defined _X86INTRIN_H_INCLUDED
kono
parents:
diff changeset
33 # error "Never use <bmi2intrin.h> directly; include <x86intrin.h> instead."
kono
parents:
diff changeset
34 #endif
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 #ifndef _BMI2INTRIN_H_INCLUDED
kono
parents:
diff changeset
37 #define _BMI2INTRIN_H_INCLUDED
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 extern __inline unsigned int
kono
parents:
diff changeset
40 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
41 _bzhi_u32 (unsigned int __X, unsigned int __Y)
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 return ((__X << (32 - __Y)) >> (32 - __Y));
kono
parents:
diff changeset
44 }
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 extern __inline unsigned int
kono
parents:
diff changeset
47 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
48 _mulx_u32 (unsigned int __X, unsigned int __Y, unsigned int *__P)
kono
parents:
diff changeset
49 {
kono
parents:
diff changeset
50 unsigned long long __res = (unsigned long long) __X * __Y;
kono
parents:
diff changeset
51 *__P = (unsigned int) (__res >> 32);
kono
parents:
diff changeset
52 return (unsigned int) __res;
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 #ifdef __PPC64__
kono
parents:
diff changeset
56 extern __inline unsigned long long
kono
parents:
diff changeset
57 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
58 _bzhi_u64 (unsigned long long __X, unsigned long long __Y)
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 return ((__X << (64 - __Y)) >> (64 - __Y));
kono
parents:
diff changeset
61 }
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 /* __int128 requires base 64-bit. */
kono
parents:
diff changeset
64 extern __inline unsigned long long
kono
parents:
diff changeset
65 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
66 _mulx_u64 (unsigned long long __X, unsigned long long __Y,
kono
parents:
diff changeset
67 unsigned long long *__P)
kono
parents:
diff changeset
68 {
kono
parents:
diff changeset
69 unsigned __int128 __res = (unsigned __int128) __X * __Y;
kono
parents:
diff changeset
70 *__P = (unsigned long long) (__res >> 64);
kono
parents:
diff changeset
71 return (unsigned long long) __res;
kono
parents:
diff changeset
72 }
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 #ifdef _ARCH_PWR7
kono
parents:
diff changeset
75 /* popcount and bpermd require power7 minimum. */
kono
parents:
diff changeset
76 extern __inline unsigned long long
kono
parents:
diff changeset
77 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
78 _pdep_u64 (unsigned long long __X, unsigned long long __M)
kono
parents:
diff changeset
79 {
kono
parents:
diff changeset
80 unsigned long result = 0x0UL;
kono
parents:
diff changeset
81 const unsigned long mask = 0x8000000000000000UL;
kono
parents:
diff changeset
82 unsigned long m = __M;
kono
parents:
diff changeset
83 unsigned long c, t;
kono
parents:
diff changeset
84 unsigned long p;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 /* The pop-count of the mask gives the number of the bits from
kono
parents:
diff changeset
87 source to process. This is also needed to shift bits from the
kono
parents:
diff changeset
88 source into the correct position for the result. */
kono
parents:
diff changeset
89 p = 64 - __builtin_popcountl (__M);
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 /* The loop is for the number of '1' bits in the mask and clearing
kono
parents:
diff changeset
92 each mask bit as it is processed. */
kono
parents:
diff changeset
93 while (m != 0)
kono
parents:
diff changeset
94 {
kono
parents:
diff changeset
95 c = __builtin_clzl (m);
kono
parents:
diff changeset
96 t = __X << (p - c);
kono
parents:
diff changeset
97 m ^= (mask >> c);
kono
parents:
diff changeset
98 result |= (t & (mask >> c));
kono
parents:
diff changeset
99 p++;
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101 return (result);
kono
parents:
diff changeset
102 }
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 extern __inline unsigned long long
kono
parents:
diff changeset
105 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
106 _pext_u64 (unsigned long long __X, unsigned long long __M)
kono
parents:
diff changeset
107 {
kono
parents:
diff changeset
108 unsigned long p = 0x4040404040404040UL; // initial bit permute control
kono
parents:
diff changeset
109 const unsigned long mask = 0x8000000000000000UL;
kono
parents:
diff changeset
110 unsigned long m = __M;
kono
parents:
diff changeset
111 unsigned long c;
kono
parents:
diff changeset
112 unsigned long result;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 /* if the mask is constant and selects 8 bits or less we can use
kono
parents:
diff changeset
115 the Power8 Bit permute instruction. */
kono
parents:
diff changeset
116 if (__builtin_constant_p (__M) && (__builtin_popcountl (__M) <= 8))
kono
parents:
diff changeset
117 {
kono
parents:
diff changeset
118 /* Also if the pext mask is constant, then the popcount is
kono
parents:
diff changeset
119 constant, we can evaluate the following loop at compile
kono
parents:
diff changeset
120 time and use a constant bit permute vector. */
kono
parents:
diff changeset
121 for (long i = 0; i < __builtin_popcountl (__M); i++)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 c = __builtin_clzl (m);
kono
parents:
diff changeset
124 p = (p << 8) | c;
kono
parents:
diff changeset
125 m ^= (mask >> c);
kono
parents:
diff changeset
126 }
kono
parents:
diff changeset
127 result = __builtin_bpermd (p, __X);
kono
parents:
diff changeset
128 }
kono
parents:
diff changeset
129 else
kono
parents:
diff changeset
130 {
kono
parents:
diff changeset
131 p = 64 - __builtin_popcountl (__M);
kono
parents:
diff changeset
132 result = 0;
kono
parents:
diff changeset
133 /* We could a use a for loop here, but that combined with
kono
parents:
diff changeset
134 -funroll-loops can expand to a lot of code. The while
kono
parents:
diff changeset
135 loop avoids unrolling and the compiler commons the xor
kono
parents:
diff changeset
136 from clearing the mask bit with the (m != 0) test. The
kono
parents:
diff changeset
137 result is a more compact loop setup and body. */
kono
parents:
diff changeset
138 while (m != 0)
kono
parents:
diff changeset
139 {
kono
parents:
diff changeset
140 unsigned long t;
kono
parents:
diff changeset
141 c = __builtin_clzl (m);
kono
parents:
diff changeset
142 t = (__X & (mask >> c)) >> (p - c);
kono
parents:
diff changeset
143 m ^= (mask >> c);
kono
parents:
diff changeset
144 result |= (t);
kono
parents:
diff changeset
145 p++;
kono
parents:
diff changeset
146 }
kono
parents:
diff changeset
147 }
kono
parents:
diff changeset
148 return (result);
kono
parents:
diff changeset
149 }
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 /* these 32-bit implementations depend on 64-bit pdep/pext
kono
parents:
diff changeset
152 which depend on _ARCH_PWR7. */
kono
parents:
diff changeset
153 extern __inline unsigned int
kono
parents:
diff changeset
154 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
155 _pdep_u32 (unsigned int __X, unsigned int __Y)
kono
parents:
diff changeset
156 {
kono
parents:
diff changeset
157 return _pdep_u64 (__X, __Y);
kono
parents:
diff changeset
158 }
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 extern __inline unsigned int
kono
parents:
diff changeset
161 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
kono
parents:
diff changeset
162 _pext_u32 (unsigned int __X, unsigned int __Y)
kono
parents:
diff changeset
163 {
kono
parents:
diff changeset
164 return _pext_u64 (__X, __Y);
kono
parents:
diff changeset
165 }
kono
parents:
diff changeset
166 #endif /* _ARCH_PWR7 */
kono
parents:
diff changeset
167 #endif /* __PPC64__ */
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 #endif /* _BMI2INTRIN_H_INCLUDED */