Skip to content

Commit d525e2b

Browse files
authored
[Headers][X86] Add more descriptions to ia32intrin.h and immintrin.h (#77686)
ia32intrin.h gets descriptions for all remaining non-privileged intrinsic functions; the macros providing alternate names are not described. immintrin.h ditto, except for the InterlockedExchange functions.
1 parent 4ea1994 commit d525e2b

File tree

2 files changed

+227
-2
lines changed

2 files changed

+227
-2
lines changed

clang/lib/Headers/ia32intrin.h

Lines changed: 170 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ __bsrd(int __A) {
5858
return 31 - __builtin_clz((unsigned int)__A);
5959
}
6060

61-
/// Swaps the bytes in the input. Converting little endian to big endian or
61+
/// Swaps the bytes in the input, converting little endian to big endian or
6262
/// vice versa.
6363
///
6464
/// \headerfile <x86intrin.h>
@@ -73,6 +73,16 @@ __bswapd(int __A) {
7373
return (int)__builtin_bswap32((unsigned int)__A);
7474
}
7575

76+
/// Swaps the bytes in the input, converting little endian to big endian or
77+
/// vice versa.
78+
///
79+
/// \headerfile <x86intrin.h>
80+
///
81+
/// This intrinsic corresponds to the \c BSWAP instruction.
82+
///
83+
/// \param __A
84+
/// A 32-bit integer operand.
85+
/// \returns A 32-bit integer containing the swapped bytes.
7686
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
7787
_bswap(int __A) {
7888
return (int)__builtin_bswap32((unsigned int)__A);
@@ -173,25 +183,59 @@ __popcntq(unsigned long long __A)
173183
#endif /* __x86_64__ */
174184

175185
#ifdef __x86_64__
186+
/// Returns the program status and control \c RFLAGS register with the \c VM
187+
/// and \c RF flags cleared.
188+
///
189+
/// \headerfile <x86intrin.h>
190+
///
191+
/// This intrinsic corresponds to the \c PUSHFQ + \c POP instruction sequence.
192+
///
193+
/// \returns The 64-bit value of the RFLAGS register.
176194
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
177195
__readeflags(void)
178196
{
179197
return __builtin_ia32_readeflags_u64();
180198
}
181199

200+
/// Writes the specified value to the program status and control \c RFLAGS
201+
/// register. Reserved bits are not affected.
202+
///
203+
/// \headerfile <x86intrin.h>
204+
///
205+
/// This intrinsic corresponds to the \c PUSH + \c POPFQ instruction sequence.
206+
///
207+
/// \param __f
208+
/// The 64-bit value to write to \c RFLAGS.
182209
static __inline__ void __DEFAULT_FN_ATTRS
183210
__writeeflags(unsigned long long __f)
184211
{
185212
__builtin_ia32_writeeflags_u64(__f);
186213
}
187214

188215
#else /* !__x86_64__ */
216+
/// Returns the program status and control \c EFLAGS register with the \c VM
217+
/// and \c RF flags cleared.
218+
///
219+
/// \headerfile <x86intrin.h>
220+
///
221+
/// This intrinsic corresponds to the \c PUSHFD + \c POP instruction sequence.
222+
///
223+
/// \returns The 32-bit value of the EFLAGS register.
189224
static __inline__ unsigned int __DEFAULT_FN_ATTRS
190225
__readeflags(void)
191226
{
192227
return __builtin_ia32_readeflags_u32();
193228
}
194229

230+
/// Writes the specified value to the program status and control \c EFLAGS
231+
/// register. Reserved bits are not affected.
232+
///
233+
/// \headerfile <x86intrin.h>
234+
///
235+
/// This intrinsic corresponds to the \c PUSH + \c POPFD instruction sequence.
236+
///
237+
/// \param __f
238+
/// The 32-bit value to write to \c EFLAGS.
195239
static __inline__ void __DEFAULT_FN_ATTRS
196240
__writeeflags(unsigned int __f)
197241
{
@@ -341,12 +385,32 @@ __crc32q(unsigned long long __C, unsigned long long __D)
341385
}
342386
#endif /* __x86_64__ */
343387

388+
/// Reads the specified performance monitoring counter. Refer to your
389+
/// processor's documentation to determine which performance counters are
390+
/// supported.
391+
///
392+
/// \headerfile <x86intrin.h>
393+
///
394+
/// This intrinsic corresponds to the \c RDPMC instruction.
395+
///
396+
/// \param __A
397+
/// The performance counter to read.
398+
/// \returns The 64-bit value read from the performance counter.
344399
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
345400
__rdpmc(int __A) {
346401
return __builtin_ia32_rdpmc(__A);
347402
}
348403

349-
/* __rdtscp */
404+
/// Reads the processor's time stamp counter and the \c IA32_TSC_AUX MSR
405+
/// \c (0xc0000103).
406+
///
407+
/// \headerfile <x86intrin.h>
408+
///
409+
/// This intrinsic corresponds to the \c RDTSCP instruction.
410+
///
411+
/// \param __A
412+
/// Address of where to store the 32-bit \c IA32_TSC_AUX value.
413+
/// \returns The 64-bit value of the time stamp counter.
350414
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
351415
__rdtscp(unsigned int *__A) {
352416
return __builtin_ia32_rdtscp(__A);
@@ -361,42 +425,146 @@ _wbinvd(void) {
361425
__builtin_ia32_wbinvd();
362426
}
363427

428+
/// Rotates an 8-bit value to the left by the specified number of bits.
429+
/// This operation is undefined if the number of bits exceeds the size of
430+
/// the value.
431+
///
432+
/// \headerfile <x86intrin.h>
433+
///
434+
/// This intrinsic corresponds to the \c ROL instruction.
435+
///
436+
/// \param __X
437+
/// The unsigned 8-bit value to be rotated.
438+
/// \param __C
439+
/// The number of bits to rotate the value.
440+
/// \returns The rotated value.
364441
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
365442
__rolb(unsigned char __X, int __C) {
366443
return __builtin_rotateleft8(__X, __C);
367444
}
368445

446+
/// Rotates an 8-bit value to the right by the specified number of bits.
447+
/// This operation is undefined if the number of bits exceeds the size of
448+
/// the value.
449+
///
450+
/// \headerfile <x86intrin.h>
451+
///
452+
/// This intrinsic corresponds to the \c ROR instruction.
453+
///
454+
/// \param __X
455+
/// The unsigned 8-bit value to be rotated.
456+
/// \param __C
457+
/// The number of bits to rotate the value.
458+
/// \returns The rotated value.
369459
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
370460
__rorb(unsigned char __X, int __C) {
371461
return __builtin_rotateright8(__X, __C);
372462
}
373463

464+
/// Rotates a 16-bit value to the left by the specified number of bits.
465+
/// This operation is undefined if the number of bits exceeds the size of
466+
/// the value.
467+
///
468+
/// \headerfile <x86intrin.h>
469+
///
470+
/// This intrinsic corresponds to the \c ROL instruction.
471+
///
472+
/// \param __X
473+
/// The unsigned 16-bit value to be rotated.
474+
/// \param __C
475+
/// The number of bits to rotate the value.
476+
/// \returns The rotated value.
374477
static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR
375478
__rolw(unsigned short __X, int __C) {
376479
return __builtin_rotateleft16(__X, __C);
377480
}
378481

482+
/// Rotates a 16-bit value to the right by the specified number of bits.
483+
/// This operation is undefined if the number of bits exceeds the size of
484+
/// the value.
485+
///
486+
/// \headerfile <x86intrin.h>
487+
///
488+
/// This intrinsic corresponds to the \c ROR instruction.
489+
///
490+
/// \param __X
491+
/// The unsigned 16-bit value to be rotated.
492+
/// \param __C
493+
/// The number of bits to rotate the value.
494+
/// \returns The rotated value.
379495
static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR
380496
__rorw(unsigned short __X, int __C) {
381497
return __builtin_rotateright16(__X, __C);
382498
}
383499

500+
/// Rotates a 32-bit value to the left by the specified number of bits.
501+
/// This operation is undefined if the number of bits exceeds the size of
502+
/// the value.
503+
///
504+
/// \headerfile <x86intrin.h>
505+
///
506+
/// This intrinsic corresponds to the \c ROL instruction.
507+
///
508+
/// \param __X
509+
/// The unsigned 32-bit value to be rotated.
510+
/// \param __C
511+
/// The number of bits to rotate the value.
512+
/// \returns The rotated value.
384513
static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
385514
__rold(unsigned int __X, int __C) {
386515
return __builtin_rotateleft32(__X, (unsigned int)__C);
387516
}
388517

518+
/// Rotates a 32-bit value to the right by the specified number of bits.
519+
/// This operation is undefined if the number of bits exceeds the size of
520+
/// the value.
521+
///
522+
/// \headerfile <x86intrin.h>
523+
///
524+
/// This intrinsic corresponds to the \c ROR instruction.
525+
///
526+
/// \param __X
527+
/// The unsigned 32-bit value to be rotated.
528+
/// \param __C
529+
/// The number of bits to rotate the value.
530+
/// \returns The rotated value.
389531
static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
390532
__rord(unsigned int __X, int __C) {
391533
return __builtin_rotateright32(__X, (unsigned int)__C);
392534
}
393535

394536
#ifdef __x86_64__
537+
/// Rotates a 64-bit value to the left by the specified number of bits.
538+
/// This operation is undefined if the number of bits exceeds the size of
539+
/// the value.
540+
///
541+
/// \headerfile <x86intrin.h>
542+
///
543+
/// This intrinsic corresponds to the \c ROL instruction.
544+
///
545+
/// \param __X
546+
/// The unsigned 64-bit value to be rotated.
547+
/// \param __C
548+
/// The number of bits to rotate the value.
549+
/// \returns The rotated value.
395550
static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR
396551
__rolq(unsigned long long __X, int __C) {
397552
return __builtin_rotateleft64(__X, (unsigned long long)__C);
398553
}
399554

555+
/// Rotates a 64-bit value to the right by the specified number of bits.
556+
/// This operation is undefined if the number of bits exceeds the size of
557+
/// the value.
558+
///
559+
/// \headerfile <x86intrin.h>
560+
///
561+
/// This intrinsic corresponds to the \c ROR instruction.
562+
///
563+
/// \param __X
564+
/// The unsigned 64-bit value to be rotated.
565+
/// \param __C
566+
/// The number of bits to rotate the value.
567+
/// \returns The rotated value.
400568
static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR
401569
__rorq(unsigned long long __X, int __C) {
402570
return __builtin_rotateright64(__X, (unsigned long long)__C);

clang/lib/Headers/immintrin.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,15 @@ _writegsbase_u64(unsigned long long __V)
490490
* field inside of it.
491491
*/
492492

493+
/// Load a 16-bit value from memory and swap its bytes.
494+
///
495+
/// \headerfile <x86intrin.h>
496+
///
497+
/// This intrinsic corresponds to the MOVBE instruction.
498+
///
499+
/// \param __P
500+
/// A pointer to the 16-bit value to load.
501+
/// \returns The byte-swapped value.
493502
static __inline__ short __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
494503
_loadbe_i16(void const * __P) {
495504
struct __loadu_i16 {
@@ -498,6 +507,16 @@ _loadbe_i16(void const * __P) {
498507
return (short)__builtin_bswap16(((const struct __loadu_i16*)__P)->__v);
499508
}
500509

510+
/// Swap the bytes of a 16-bit value and store it to memory.
511+
///
512+
/// \headerfile <x86intrin.h>
513+
///
514+
/// This intrinsic corresponds to the MOVBE instruction.
515+
///
516+
/// \param __P
517+
/// A pointer to the memory for storing the swapped value.
518+
/// \param __D
519+
/// The 16-bit value to be byte-swapped.
501520
static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
502521
_storebe_i16(void * __P, short __D) {
503522
struct __storeu_i16 {
@@ -506,6 +525,15 @@ _storebe_i16(void * __P, short __D) {
506525
((struct __storeu_i16*)__P)->__v = __builtin_bswap16((unsigned short)__D);
507526
}
508527

528+
/// Load a 32-bit value from memory and swap its bytes.
529+
///
530+
/// \headerfile <x86intrin.h>
531+
///
532+
/// This intrinsic corresponds to the MOVBE instruction.
533+
///
534+
/// \param __P
535+
/// A pointer to the 32-bit value to load.
536+
/// \returns The byte-swapped value.
509537
static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
510538
_loadbe_i32(void const * __P) {
511539
struct __loadu_i32 {
@@ -514,6 +542,16 @@ _loadbe_i32(void const * __P) {
514542
return (int)__builtin_bswap32(((const struct __loadu_i32*)__P)->__v);
515543
}
516544

545+
/// Swap the bytes of a 32-bit value and store it to memory.
546+
///
547+
/// \headerfile <x86intrin.h>
548+
///
549+
/// This intrinsic corresponds to the MOVBE instruction.
550+
///
551+
/// \param __P
552+
/// A pointer to the memory for storing the swapped value.
553+
/// \param __D
554+
/// The 32-bit value to be byte-swapped.
517555
static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
518556
_storebe_i32(void * __P, int __D) {
519557
struct __storeu_i32 {
@@ -523,6 +561,15 @@ _storebe_i32(void * __P, int __D) {
523561
}
524562

525563
#ifdef __x86_64__
564+
/// Load a 64-bit value from memory and swap its bytes.
565+
///
566+
/// \headerfile <x86intrin.h>
567+
///
568+
/// This intrinsic corresponds to the MOVBE instruction.
569+
///
570+
/// \param __P
571+
/// A pointer to the 64-bit value to load.
572+
/// \returns The byte-swapped value.
526573
static __inline__ long long __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
527574
_loadbe_i64(void const * __P) {
528575
struct __loadu_i64 {
@@ -531,6 +578,16 @@ _loadbe_i64(void const * __P) {
531578
return (long long)__builtin_bswap64(((const struct __loadu_i64*)__P)->__v);
532579
}
533580

581+
/// Swap the bytes of a 64-bit value and store it to memory.
582+
///
583+
/// \headerfile <x86intrin.h>
584+
///
585+
/// This intrinsic corresponds to the MOVBE instruction.
586+
///
587+
/// \param __P
588+
/// A pointer to the memory for storing the swapped value.
589+
/// \param __D
590+
/// The 64-bit value to be byte-swapped.
534591
static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("movbe")))
535592
_storebe_i64(void * __P, long long __D) {
536593
struct __storeu_i64 {

0 commit comments

Comments
 (0)