mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-24 06:25:18 +00:00
Add bswap intrinsics as documented in the Language Reference
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25309 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -58,19 +58,21 @@ namespace Intrinsic {
|
||||
dbg_func_start, // Start of a function
|
||||
dbg_declare, // Declare a local object
|
||||
|
||||
|
||||
// Standard libc functions.
|
||||
// Standard C library intrinsics.
|
||||
memcpy, // Copy non-overlapping memory blocks
|
||||
memmove, // Copy potentially overlapping memory blocks
|
||||
memset, // Fill memory with a byte value
|
||||
|
||||
// libm related functions.
|
||||
isunordered, // Return true if either argument is a NaN
|
||||
ctpop, //count population
|
||||
ctlz, //count leading zeros
|
||||
cttz, //count trailing zeros
|
||||
sqrt, //square root
|
||||
sqrt, // Square root
|
||||
|
||||
// Bit manipulation instrinsics.
|
||||
bswap_i16, // Byteswap 16 bits
|
||||
bswap_i32, // Byteswap 32 bits
|
||||
bswap_i64, // Byteswap 64 bits
|
||||
ctpop, // Count population
|
||||
ctlz, // Count leading zeros
|
||||
cttz, // Count trailing zeros
|
||||
|
||||
// Input/Output intrinsics.
|
||||
readport,
|
||||
writeport,
|
||||
|
@@ -79,6 +79,32 @@ inline bool isPowerOf2_64(uint64_t Value) {
|
||||
return Value && !(Value & (Value - 1LL));
|
||||
}
|
||||
|
||||
// ByteSwap_16 - This function returns a byte-swapped representation of the
|
||||
// 16-bit argument, Value.
|
||||
inline unsigned short ByteSwap_16(unsigned short Value) {
|
||||
unsigned short Hi = Value << 8;
|
||||
unsigned short Lo = Value >> 8;
|
||||
return Hi | Lo;
|
||||
}
|
||||
|
||||
// ByteSwap_32 - This function returns a byte-swapped representation of the
|
||||
// 32-bit argument, Value.
|
||||
inline unsigned ByteSwap_32(unsigned Value) {
|
||||
unsigned Byte0 = Value & 0x000000FF;
|
||||
unsigned Byte1 = Value & 0x0000FF00;
|
||||
unsigned Byte2 = Value & 0x00FF0000;
|
||||
unsigned Byte3 = Value & 0xFF000000;
|
||||
return (Byte0 << 24) | (Byte1 << 8) | (Byte2 >> 8) | (Byte3 >> 24);
|
||||
}
|
||||
|
||||
// ByteSwap_64 - This function returns a byte-swapped representation of the
|
||||
// 64-bit argument, Value.
|
||||
inline uint64_t ByteSwap_64(uint64_t Value) {
|
||||
uint64_t Hi = ByteSwap_32(Value);
|
||||
uint64_t Lo = ByteSwap_32(Value >> 32);
|
||||
return (Hi << 32) | Lo;
|
||||
}
|
||||
|
||||
// CountLeadingZeros_32 - this function performs the platform optimal form of
|
||||
// counting the number of zeros from the most significant bit to the first one
|
||||
// bit. Ex. CountLeadingZeros_32(0x00F000FF) == 8.
|
||||
|
Reference in New Issue
Block a user