1
0
mirror of https://github.com/bitdefender/bddisasm.git synced 2024-11-25 08:58:09 +00:00

Replace ND_SIGN_EX with less branchy version

This commit is contained in:
Turo Lamminen 2024-08-06 19:13:06 +03:00
parent 8bc44ae145
commit 56bbcca4cf

View File

@ -353,15 +353,14 @@ typedef ND_UINT32 ND_REG_SIZE;
#define ND_SIGN_EX_16(x) (((x) & 0x00008000) ? (0xFFFFFFFFFFFF0000 | (x)) : ((x) & 0xFFFF)) #define ND_SIGN_EX_16(x) (((x) & 0x00008000) ? (0xFFFFFFFFFFFF0000 | (x)) : ((x) & 0xFFFF))
// Sign extend 32 bit to 64 bit. // Sign extend 32 bit to 64 bit.
#define ND_SIGN_EX_32(x) (((x) & 0x80000000) ? (0xFFFFFFFF00000000 | (x)) : ((x) & 0xFFFFFFFF)) #define ND_SIGN_EX_32(x) (((x) & 0x80000000) ? (0xFFFFFFFF00000000 | (x)) : ((x) & 0xFFFFFFFF))
// Wrapper for for ND_SIGN_EX_8/ND_SIGN_EX_16/ND_SIGN_EX_32. Sign extend sz bytes to 64 bits. // Sign extend to 64 bit, with minimal branches
#define ND_SIGN_EX(sz, x) ((sz) == 1 ? ND_SIGN_EX_8(x) : (sz) == 2 ? ND_SIGN_EX_16(x) : \ #define ND_SIGN_EX(sz, x) (((x) & ND_SIZE_TO_MASK(sz)) | (~ND_SIZE_TO_MASK(sz) * ND_GET_SIGN(sz, x)))
(sz) == 4 ? ND_SIGN_EX_32(x) : (x))
// Trim 64 bits to sz bytes. // Trim 64 bits to sz bytes.
#define ND_TRIM(sz, x) ((sz) == 1 ? (x) & 0xFF : (sz) == 2 ? (x) & 0xFFFF : \ #define ND_TRIM(sz, x) ((sz) == 1 ? (x) & 0xFF : (sz) == 2 ? (x) & 0xFFFF : \
(sz) == 4 ? (x) & 0xFFFFFFFF : (x)) (sz) == 4 ? (x) & 0xFFFFFFFF : (x))
// Returns most significant bit, given size in bytes sz. // Returns most significant bit, given size in bytes sz.
#define ND_MSB(sz, x) ((sz) == 1 ? ((x) >> 7) & 1 : (sz) == 2 ? ((x) >> 15) & 1 : \ #define ND_MSB(sz, x) (((x) >> ( (sz) * 8 - 1)) & 1)
(sz) == 4 ? ((x) >> 31) & 1 : ((x) >> 63) & 1)
// Returns least significant bit. // Returns least significant bit.
#define ND_LSB(sz, x) ((x) & 1) #define ND_LSB(sz, x) ((x) & 1)
// Convert a size in bytes to a bitmask. // Convert a size in bytes to a bitmask.