Skip to content

Commit d9cb37c

Browse files
authored
[Headers][X86] Add macro descriptions to ia32intrin.h (#78613)
These are largely copy-pasted from the corresponding function descriptions. Updated _rdtsc definition because it was just plain wrong.
1 parent 69fedaf commit d9cb37c

File tree

1 file changed

+269
-3
lines changed

1 file changed

+269
-3
lines changed

clang/lib/Headers/ia32intrin.h

Lines changed: 269 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/// \param __A
3838
/// A 32-bit integer operand.
3939
/// \returns A 32-bit integer containing the bit number.
40+
/// \see _bit_scan_forward
4041
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
4142
__bsfd(int __A) {
4243
return __builtin_ctz((unsigned int)__A);
@@ -53,6 +54,7 @@ __bsfd(int __A) {
5354
/// \param __A
5455
/// A 32-bit integer operand.
5556
/// \returns A 32-bit integer containing the bit number.
57+
/// \see _bit_scan_reverse
5658
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
5759
__bsrd(int __A) {
5860
return 31 - __builtin_clz((unsigned int)__A);
@@ -88,7 +90,40 @@ _bswap(int __A) {
8890
return (int)__builtin_bswap32((unsigned int)__A);
8991
}
9092

93+
/// Find the first set bit starting from the lsb. Result is undefined if
94+
/// input is 0.
95+
///
96+
/// \headerfile <x86intrin.h>
97+
///
98+
/// \code
99+
/// int _bit_scan_forward(int A);
100+
/// \endcode
101+
///
102+
/// This intrinsic corresponds to the \c BSF instruction or the
103+
/// \c TZCNT instruction.
104+
///
105+
/// \param A
106+
/// A 32-bit integer operand.
107+
/// \returns A 32-bit integer containing the bit number.
108+
/// \see __bsfd
91109
#define _bit_scan_forward(A) __bsfd((A))
110+
111+
/// Find the first set bit starting from the msb. Result is undefined if
112+
/// input is 0.
113+
///
114+
/// \headerfile <x86intrin.h>
115+
///
116+
/// \code
117+
/// int _bit_scan_reverse(int A);
118+
/// \endcode
119+
///
120+
/// This intrinsic corresponds to the \c BSR instruction or the
121+
/// \c LZCNT instruction and an \c XOR.
122+
///
123+
/// \param A
124+
/// A 32-bit integer operand.
125+
/// \returns A 32-bit integer containing the bit number.
126+
/// \see __bsrd
92127
#define _bit_scan_reverse(A) __bsrd((A))
93128

94129
#ifdef __x86_64__
@@ -134,13 +169,29 @@ __bsrq(long long __A) {
134169
/// \param __A
135170
/// A 64-bit integer operand.
136171
/// \returns A 64-bit integer containing the swapped bytes.
172+
/// \see _bswap64
137173
static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
138174
__bswapq(long long __A) {
139175
return (long long)__builtin_bswap64((unsigned long long)__A);
140176
}
141177

178+
/// Swaps the bytes in the input. Converting little endian to big endian or
179+
/// vice versa.
180+
///
181+
/// \headerfile <x86intrin.h>
182+
///
183+
/// \code
184+
/// long long _bswap64(long long A);
185+
/// \endcode
186+
///
187+
/// This intrinsic corresponds to the \c BSWAP instruction.
188+
///
189+
/// \param A
190+
/// A 64-bit integer operand.
191+
/// \returns A 64-bit integer containing the swapped bytes.
192+
/// \see __bswapq
142193
#define _bswap64(A) __bswapq((A))
143-
#endif
194+
#endif /* __x86_64__ */
144195

145196
/// Counts the number of bits in the source operand having a value of 1.
146197
///
@@ -153,12 +204,29 @@ __bswapq(long long __A) {
153204
/// An unsigned 32-bit integer operand.
154205
/// \returns A 32-bit integer containing the number of bits with value 1 in the
155206
/// source operand.
207+
/// \see _popcnt32
156208
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
157209
__popcntd(unsigned int __A)
158210
{
159211
return __builtin_popcount(__A);
160212
}
161213

214+
/// Counts the number of bits in the source operand having a value of 1.
215+
///
216+
/// \headerfile <x86intrin.h>
217+
///
218+
/// \code
219+
/// int _popcnt32(int A);
220+
/// \endcode
221+
///
222+
/// This intrinsic corresponds to the \c POPCNT instruction or a
223+
/// a sequence of arithmetic and logic ops to calculate it.
224+
///
225+
/// \param A
226+
/// An unsigned 32-bit integer operand.
227+
/// \returns A 32-bit integer containing the number of bits with value 1 in the
228+
/// source operand.
229+
/// \see __popcntd
162230
#define _popcnt32(A) __popcntd((A))
163231

164232
#ifdef __x86_64__
@@ -173,12 +241,29 @@ __popcntd(unsigned int __A)
173241
/// An unsigned 64-bit integer operand.
174242
/// \returns A 64-bit integer containing the number of bits with value 1 in the
175243
/// source operand.
244+
/// \see _popcnt64
176245
static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
177246
__popcntq(unsigned long long __A)
178247
{
179248
return __builtin_popcountll(__A);
180249
}
181250

251+
/// Counts the number of bits in the source operand having a value of 1.
252+
///
253+
/// \headerfile <x86intrin.h>
254+
///
255+
/// \code
256+
/// long long _popcnt64(unsigned long long A);
257+
/// \endcode
258+
///
259+
/// This intrinsic corresponds to the \c POPCNT instruction or a
260+
/// a sequence of arithmetic and logic ops to calculate it.
261+
///
262+
/// \param A
263+
/// An unsigned 64-bit integer operand.
264+
/// \returns A 64-bit integer containing the number of bits with value 1 in the
265+
/// source operand.
266+
/// \see __popcntq
182267
#define _popcnt64(A) __popcntq((A))
183268
#endif /* __x86_64__ */
184269

@@ -396,6 +481,7 @@ __crc32q(unsigned long long __C, unsigned long long __D)
396481
/// \param __A
397482
/// The performance counter to read.
398483
/// \returns The 64-bit value read from the performance counter.
484+
/// \see _rdpmc
399485
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
400486
__rdpmc(int __A) {
401487
return __builtin_ia32_rdpmc(__A);
@@ -416,8 +502,35 @@ __rdtscp(unsigned int *__A) {
416502
return __builtin_ia32_rdtscp(__A);
417503
}
418504

505+
/// Reads the processor's time stamp counter.
506+
///
507+
/// \headerfile <x86intrin.h>
508+
///
509+
/// \code
510+
/// unsigned long long _rdtsc();
511+
/// \endcode
512+
///
513+
/// This intrinsic corresponds to the \c RDTSC instruction.
514+
///
515+
/// \returns The 64-bit value of the time stamp counter.
419516
#define _rdtsc() __rdtsc()
420517

518+
/// Reads the specified performance monitoring counter. Refer to your
519+
/// processor's documentation to determine which performance counters are
520+
/// supported.
521+
///
522+
/// \headerfile <x86intrin.h>
523+
///
524+
/// \code
525+
/// unsigned long long _rdpmc(int A);
526+
/// \endcode
527+
///
528+
/// This intrinsic corresponds to the \c RDPMC instruction.
529+
///
530+
/// \param A
531+
/// The performance counter to read.
532+
/// \returns The 64-bit value read from the performance counter.
533+
/// \see __rdpmc
421534
#define _rdpmc(A) __rdpmc(A)
422535

423536
static __inline__ void __DEFAULT_FN_ATTRS
@@ -474,6 +587,7 @@ __rorb(unsigned char __X, int __C) {
474587
/// \param __C
475588
/// The number of bits to rotate the value.
476589
/// \returns The rotated value.
590+
/// \see _rotwl
477591
static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR
478592
__rolw(unsigned short __X, int __C) {
479593
return __builtin_rotateleft16(__X, __C);
@@ -492,6 +606,7 @@ __rolw(unsigned short __X, int __C) {
492606
/// \param __C
493607
/// The number of bits to rotate the value.
494608
/// \returns The rotated value.
609+
/// \see _rotwr
495610
static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR
496611
__rorw(unsigned short __X, int __C) {
497612
return __builtin_rotateright16(__X, __C);
@@ -510,6 +625,7 @@ __rorw(unsigned short __X, int __C) {
510625
/// \param __C
511626
/// The number of bits to rotate the value.
512627
/// \returns The rotated value.
628+
/// \see _rotl
513629
static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
514630
__rold(unsigned int __X, int __C) {
515631
return __builtin_rotateleft32(__X, (unsigned int)__C);
@@ -528,6 +644,7 @@ __rold(unsigned int __X, int __C) {
528644
/// \param __C
529645
/// The number of bits to rotate the value.
530646
/// \returns The rotated value.
647+
/// \see _rotr
531648
static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
532649
__rord(unsigned int __X, int __C) {
533650
return __builtin_rotateright32(__X, (unsigned int)__C);
@@ -575,18 +692,167 @@ __rorq(unsigned long long __X, int __C) {
575692
/* These are already provided as builtins for MSVC. */
576693
/* Select the correct function based on the size of long. */
577694
#ifdef __LP64__
695+
/// Rotates a 64-bit value to the left by the specified number of bits.
696+
/// This operation is undefined if the number of bits exceeds the size of
697+
/// the value.
698+
///
699+
/// \headerfile <x86intrin.h>
700+
///
701+
/// \code
702+
/// unsigned long long _lrotl(unsigned long long a, int b);
703+
/// \endcode
704+
///
705+
/// This intrinsic corresponds to the \c ROL instruction.
706+
///
707+
/// \param a
708+
/// The unsigned 64-bit value to be rotated.
709+
/// \param b
710+
/// The number of bits to rotate the value.
711+
/// \returns The rotated value.
712+
/// \see __rolq
578713
#define _lrotl(a,b) __rolq((a), (b))
714+
715+
/// Rotates a 64-bit value to the right by the specified number of bits.
716+
/// This operation is undefined if the number of bits exceeds the size of
717+
/// the value.
718+
///
719+
/// \headerfile <x86intrin.h>
720+
///
721+
/// \code
722+
/// unsigned long long _lrotr(unsigned long long a, int b);
723+
/// \endcode
724+
///
725+
/// This intrinsic corresponds to the \c ROR instruction.
726+
///
727+
/// \param a
728+
/// The unsigned 64-bit value to be rotated.
729+
/// \param b
730+
/// The number of bits to rotate the value.
731+
/// \returns The rotated value.
732+
/// \see __rorq
579733
#define _lrotr(a,b) __rorq((a), (b))
580-
#else
734+
#else // __LP64__
735+
/// Rotates a 32-bit value to the left by the specified number of bits.
736+
/// This operation is undefined if the number of bits exceeds the size of
737+
/// the value.
738+
///
739+
/// \headerfile <x86intrin.h>
740+
///
741+
/// \code
742+
/// unsigned int _lrotl(unsigned int a, int b);
743+
/// \endcode
744+
///
745+
/// This intrinsic corresponds to the \c ROL instruction.
746+
///
747+
/// \param a
748+
/// The unsigned 32-bit value to be rotated.
749+
/// \param b
750+
/// The number of bits to rotate the value.
751+
/// \returns The rotated value.
752+
/// \see __rold
581753
#define _lrotl(a,b) __rold((a), (b))
754+
755+
/// Rotates a 32-bit value to the right by the specified number of bits.
756+
/// This operation is undefined if the number of bits exceeds the size of
757+
/// the value.
758+
///
759+
/// \headerfile <x86intrin.h>
760+
///
761+
/// \code
762+
/// unsigned int _lrotr(unsigned int a, int b);
763+
/// \endcode
764+
///
765+
/// This intrinsic corresponds to the \c ROR instruction.
766+
///
767+
/// \param a
768+
/// The unsigned 32-bit value to be rotated.
769+
/// \param b
770+
/// The number of bits to rotate the value.
771+
/// \returns The rotated value.
772+
/// \see __rord
582773
#define _lrotr(a,b) __rord((a), (b))
583-
#endif
774+
#endif // __LP64__
775+
776+
/// Rotates a 32-bit value to the left by the specified number of bits.
777+
/// This operation is undefined if the number of bits exceeds the size of
778+
/// the value.
779+
///
780+
/// \headerfile <x86intrin.h>
781+
///
782+
/// \code
783+
/// unsigned int _rotl(unsigned int a, int b);
784+
/// \endcode
785+
///
786+
/// This intrinsic corresponds to the \c ROL instruction.
787+
///
788+
/// \param a
789+
/// The unsigned 32-bit value to be rotated.
790+
/// \param b
791+
/// The number of bits to rotate the value.
792+
/// \returns The rotated value.
793+
/// \see __rold
584794
#define _rotl(a,b) __rold((a), (b))
795+
796+
/// Rotates a 32-bit value to the right by the specified number of bits.
797+
/// This operation is undefined if the number of bits exceeds the size of
798+
/// the value.
799+
///
800+
/// \headerfile <x86intrin.h>
801+
///
802+
/// \code
803+
/// unsigned int _rotr(unsigned int a, int b);
804+
/// \endcode
805+
///
806+
/// This intrinsic corresponds to the \c ROR instruction.
807+
///
808+
/// \param a
809+
/// The unsigned 32-bit value to be rotated.
810+
/// \param b
811+
/// The number of bits to rotate the value.
812+
/// \returns The rotated value.
813+
/// \see __rord
585814
#define _rotr(a,b) __rord((a), (b))
586815
#endif // _MSC_VER
587816

588817
/* These are not builtins so need to be provided in all modes. */
818+
/// Rotates a 16-bit value to the left by the specified number of bits.
819+
/// This operation is undefined if the number of bits exceeds the size of
820+
/// the value.
821+
///
822+
/// \headerfile <x86intrin.h>
823+
///
824+
/// \code
825+
/// unsigned short _rotwl(unsigned short a, int b);
826+
/// \endcode
827+
///
828+
/// This intrinsic corresponds to the \c ROL instruction.
829+
///
830+
/// \param a
831+
/// The unsigned 16-bit value to be rotated.
832+
/// \param b
833+
/// The number of bits to rotate the value.
834+
/// \returns The rotated value.
835+
/// \see __rolw
589836
#define _rotwl(a,b) __rolw((a), (b))
837+
838+
/// Rotates a 16-bit value to the right by the specified number of bits.
839+
/// This operation is undefined if the number of bits exceeds the size of
840+
/// the value.
841+
///
842+
/// \headerfile <x86intrin.h>
843+
///
844+
/// \code
845+
/// unsigned short _rotwr(unsigned short a, int b);
846+
/// \endcode
847+
///
848+
/// This intrinsic corresponds to the \c ROR instruction.
849+
///
850+
/// \param a
851+
/// The unsigned 16-bit value to be rotated.
852+
/// \param b
853+
/// The number of bits to rotate the value.
854+
/// \returns The rotated value.
855+
/// \see __rorw
590856
#define _rotwr(a,b) __rorw((a), (b))
591857

592858
#undef __DEFAULT_FN_ATTRS

0 commit comments

Comments
 (0)