User mode Cross platform APIs for intrinsic functions (x86 instructions).
More...
Go to the source code of this file.
User mode Cross platform APIs for intrinsic functions (x86 instructions).
- Author
- Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
- Version
- 0.19
- Date
- 2026-05-06
- Copyright
- This project is released under the GNU Public License v3.
◆ CpuCpuId()
| VOID CpuCpuId |
( |
INT32 * | CpuInfo, |
|
|
INT32 | FunctionId ) |
|
inline |
Execute CPUID.
- Parameters
-
256{
257#if defined(_WIN32) || defined(_WIN64)
258 __cpuid(CpuInfo, FunctionId);
259#elif defined(__linux__)
260 __asm__ __volatile__("cpuid" : "=a"(CpuInfo[0]), "=b"(CpuInfo[1]), "=c"(CpuInfo[2]), "=d"(CpuInfo[3]) : "a"(FunctionId), "c"(0));
261#else
262# error "Unsupported platform"
263#endif
264}
◆ CpuCpuIdEx()
Execute CPUID with sub-leaf.
- Parameters
-
| CpuInfo | |
| FunctionId | |
| SubFunctionId | |
275{
276#if defined(_WIN32) || defined(_WIN64)
277 __cpuidex(CpuInfo, FunctionId, SubFunctionId);
278#elif defined(__linux__)
279 __asm__ __volatile__("cpuid" : "=a"(CpuInfo[0]), "=b"(CpuInfo[1]), "=c"(CpuInfo[2]), "=d"(CpuInfo[3]) : "a"(FunctionId), "c"(SubFunctionId));
280#else
281# error "Unsupported platform"
282#endif
283}
◆ CpuInterlockedBitTestAndSet()
| UCHAR CpuInterlockedBitTestAndSet |
( |
volatile LONG * | Base, |
|
|
LONG | Bit ) |
191{
192#if defined(_WIN32) || defined(_WIN64)
193 return _interlockedbittestandset(Base, Bit);
194#elif defined(__linux__)
195 LONG Mask = (1L << Bit);
196 LONG Old = __atomic_fetch_or(Base, Mask, __ATOMIC_SEQ_CST);
197 return (
UCHAR)((Old >> Bit) & 1);
198#else
199# error "Unsupported platform"
200#endif
201}
◆ CpuInterlockedCompareExchange64()
| INT64 CpuInterlockedCompareExchange64 |
( |
INT64 volatile * | Destination, |
|
|
INT64 | ExChange, |
|
|
INT64 | Comparand ) |
|
inline |
Atomic 64-bit compare-exchange.
397{
398#if defined(_WIN32) || defined(_WIN64)
399 return InterlockedCompareExchange64(Destination, ExChange, Comparand);
400#elif defined(__linux__)
401 INT64 Expected = Comparand;
402 __atomic_compare_exchange_n(Destination, &Expected, ExChange, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
403 return Expected;
404#else
405# error "Unsupported platform"
406#endif
407}
◆ CpuInterlockedDecrement64()
| INT64 CpuInterlockedDecrement64 |
( |
INT64 volatile * | Addend | ) |
|
|
inline |
Atomic 64-bit decrement.
382{
383#if defined(_WIN32) || defined(_WIN64)
384 return InterlockedDecrement64(Addend);
385#elif defined(__linux__)
386 return __atomic_sub_fetch(Addend, 1LL, __ATOMIC_SEQ_CST);
387#else
388# error "Unsupported platform"
389#endif
390}
◆ CpuInterlockedExchange64()
| INT64 CpuInterlockedExchange64 |
( |
INT64 volatile * | Target, |
|
|
INT64 | Value ) |
|
inline |
Atomic 64-bit exchange.
337{
338#if defined(_WIN32) || defined(_WIN64)
339 return InterlockedExchange64(Target,
Value);
340#elif defined(__linux__)
341 return __atomic_exchange_n(Target,
Value, __ATOMIC_SEQ_CST);
342#else
343# error "Unsupported platform"
344#endif
345}
RequestedActionOfThePacket Value(0x1) 00000000
◆ CpuInterlockedExchangeAdd64()
| INT64 CpuInterlockedExchangeAdd64 |
( |
INT64 volatile * | Addend, |
|
|
INT64 | Value ) |
|
inline |
Atomic 64-bit exchange-add.
352{
353#if defined(_WIN32) || defined(_WIN64)
354 return InterlockedExchangeAdd64(Addend,
Value);
355#elif defined(__linux__)
356 return __atomic_fetch_add(Addend,
Value, __ATOMIC_SEQ_CST);
357#else
358# error "Unsupported platform"
359#endif
360}
◆ CpuInterlockedIncrement64()
| INT64 CpuInterlockedIncrement64 |
( |
INT64 volatile * | Addend | ) |
|
|
inline |
Atomic 64-bit increment.
367{
368#if defined(_WIN32) || defined(_WIN64)
369 return InterlockedIncrement64(Addend);
370#elif defined(__linux__)
371 return __atomic_add_fetch(Addend, 1LL, __ATOMIC_SEQ_CST);
372#else
373# error "Unsupported platform"
374#endif
375}
◆ CpuPause()
Execute PAUSE (spin-wait hint).
524{
525#if defined(_WIN32) || defined(_WIN64)
526 _mm_pause();
527#elif defined(__linux__)
528 __asm__ __volatile__("pause");
529#else
530# error "Unsupported platform"
531#endif
532}
◆ CpuReadTsc()
| UINT64 CpuReadTsc |
( |
VOID | | ) |
|
|
inline |
Read Time-Stamp Counter.
- Returns
- UINT64
296{
297#if defined(_WIN32) || defined(_WIN64)
298 return __rdtsc();
299#elif defined(__linux__)
301 __asm__ __volatile__("rdtsc" : "=a"(__lo), "=d"(__hi));
302 return ((UINT64)__hi << 32) | __lo;
303#else
304# error "Unsupported platform"
305#endif
306}
◆ CpuReadTscp()
| UINT64 CpuReadTscp |
( |
UINT32 * | Aux | ) |
|
|
inline |
Read Time-Stamp Counter and Processor ID.
- Parameters
-
- Returns
- UINT64
316{
317#if defined(_WIN32) || defined(_WIN64)
318 return __rdtscp(Aux);
319#elif defined(__linux__)
321 __asm__ __volatile__("rdtscp" : "=a"(__lo), "=d"(__hi), "=c"(*Aux));
322 return ((UINT64)__hi << 32) | __lo;
323#else
324# error "Unsupported platform"
325#endif
326}