@tannergooding and I were having a discussion and these examples were brought up.
public class C {
static uint SetBit(int position, uint bits)
{
return bits | (1u << position);
}
static uint ToggleBit(int position, uint bits)
{
return bits ^ (1u << position);
}
static uint ResetBit(int position, uint bits)
{
return bits & ~(1u << position);
}
}
These examples currently emit:
C.SetBit(Int32, UInt32)
L0000: mov eax, 1
L0005: shlx eax, eax, ecx
L000a: or eax, edx
L000c: ret
C.ToggleBit(Int32, UInt32)
L0000: mov eax, 1
L0005: shlx eax, eax, ecx
L000a: xor eax, edx
L000c: ret
C.ResetBit(Int32, UInt32)
L0000: mov eax, 1
L0005: shlx eax, eax, ecx
L000a: andn eax, eax, edx
L000f: ret
They could emit:
SetBit(int, unsigned int): # @SetBit(int, unsigned int)
mov eax, ecx
bts eax, edx
ret
ToggleBit(int, unsigned int): # @ToggleBit(int, unsigned int)
mov eax, ecx
btc eax, edx
ret
ResetBit(int, unsigned int): # @ResetBit(int, unsigned int)
mov eax, ecx
btr eax, edx
ret
In XARCH LIR, we have a GT_BT already, we can just add three more GT_BTS, GT_BTC, GT_BTR and recognize the patterns above to transform to those ops in lowering.
Related: #27382
@tannergooding and I were having a discussion and these examples were brought up.
These examples currently emit:
They could emit:
In XARCH LIR, we have a
GT_BTalready, we can just add three moreGT_BTS,GT_BTC,GT_BTRand recognize the patterns above to transform to those ops in lowering.Related: #27382