Add Intel encodings for popcnt.
Change the result type for the bit-counting instructions from a fixed i8 to the iB type variable which is the type of the input. This matches the convention in WebAssembly, and at least Intel's instructions will set a full register's worth of count result, even if it is always < 64. Duplicate the Intel 'ur' encoding recipe into 'umr' and 'urm' variants corresponding to the RM and MR encoding variants. The difference is which register is encoded as 'reg' and which is 'r/m' in the ModR/M byte. A 'mov' register copy uses the MR variant, a unary popcnt uses the RM variant.
This commit is contained in:
@@ -217,6 +217,13 @@ ebb0:
|
||||
; asm: movsbl -50000(%esi), %edx
|
||||
[-,%rdx] v129 = sload8.i32 v2-50000 ; bin: 0f be 96 ffff3cb0
|
||||
|
||||
; Bit-counting instructions.
|
||||
|
||||
; asm: popcntl %esi, %ecx
|
||||
[-,%rcx] v200 = popcnt v2 ; bin: f3 0f b8 ce
|
||||
; asm: popcntl %ecx, %esi
|
||||
[-,%rsi] v201 = popcnt v1 ; bin: f3 0f b8 f1
|
||||
|
||||
; asm: call foo
|
||||
call fn0() ; bin: e8 PCRel4(fn0) 00000000
|
||||
|
||||
|
||||
@@ -145,6 +145,15 @@ ebb0:
|
||||
; asm: movq %rcx, %r10
|
||||
[-,%r10] v112 = copy v1 ; bin: 49 89 ca
|
||||
|
||||
; Bit-counting instructions.
|
||||
|
||||
; asm: popcntq %rsi, %rcx
|
||||
[-,%rcx] v200 = popcnt v2 ; bin: f3 48 0f b8 ce
|
||||
; asm: popcntq %r10, %rsi
|
||||
[-,%rsi] v201 = popcnt v3 ; bin: f3 49 0f b8 f2
|
||||
; asm: popcntq %rcx, %r10
|
||||
[-,%r10] v202 = popcnt v1 ; bin: f3 4c 0f b8 d1
|
||||
|
||||
return ; bin: c3
|
||||
}
|
||||
|
||||
@@ -290,5 +299,14 @@ ebb0:
|
||||
; asm: movl %ecx, %r10d
|
||||
[-,%r10] v112 = copy v1 ; bin: 41 89 ca
|
||||
|
||||
; Bit-counting instructions.
|
||||
|
||||
; asm: popcntl %esi, %ecx
|
||||
[-,%rcx] v200 = popcnt v2 ; bin: f3 40 0f b8 ce
|
||||
; asm: popcntl %r10d, %esi
|
||||
[-,%rsi] v201 = popcnt v3 ; bin: f3 41 0f b8 f2
|
||||
; asm: popcntl %ecx, %r10d
|
||||
[-,%r10] v202 = popcnt v1 ; bin: f3 44 0f b8 d1
|
||||
|
||||
return ; bin: c3
|
||||
}
|
||||
|
||||
@@ -19,7 +19,12 @@ ebb0:
|
||||
|
||||
; function %i32_clz(i32) -> i32
|
||||
; function %i32_ctz(i32) -> i32
|
||||
; function %i32_popcnt(i32) -> i32
|
||||
|
||||
function %i32_popcnt(i32) -> i32 {
|
||||
ebb0(v0: i32):
|
||||
v1 = popcnt v0
|
||||
return v1
|
||||
}
|
||||
|
||||
; Binary operations.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user