Fix the Intel encoding of band_not.

The andnps instruction inverts its first argument while band_not inverts
is second argument.

Use a swapped-operands "fax" encoding recipe.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-27 18:14:13 -07:00
parent 1d481d7897
commit a274cdf275
4 changed files with 27 additions and 16 deletions

View File

@@ -78,9 +78,9 @@ ebb0:
[-,%xmm2] v31 = band v11, v10 ; bin: 0f 54 d5 [-,%xmm2] v31 = band v11, v10 ; bin: 0f 54 d5
; asm: andnps %xmm2, %xmm5 ; asm: andnps %xmm2, %xmm5
[-,%xmm5] v32 = band_not v10, v11 ; bin: 0f 55 ea [-,%xmm5] v32 = band_not v11, v10 ; bin: 0f 55 ea
; asm: andnps %xmm5, %xmm2 ; asm: andnps %xmm5, %xmm2
[-,%xmm2] v33 = band_not v11, v10 ; bin: 0f 55 d5 [-,%xmm2] v33 = band_not v10, v11 ; bin: 0f 55 d5
; asm: orps %xmm2, %xmm5 ; asm: orps %xmm2, %xmm5
[-,%xmm5] v34 = bor v10, v11 ; bin: 0f 56 ea [-,%xmm5] v34 = bor v10, v11 ; bin: 0f 56 ea
@@ -281,9 +281,9 @@ ebb0:
[-,%xmm2] v31 = band v11, v10 ; bin: 0f 54 d5 [-,%xmm2] v31 = band v11, v10 ; bin: 0f 54 d5
; asm: andnps %xmm2, %xmm5 ; asm: andnps %xmm2, %xmm5
[-,%xmm5] v32 = band_not v10, v11 ; bin: 0f 55 ea [-,%xmm5] v32 = band_not v11, v10 ; bin: 0f 55 ea
; asm: andnps %xmm5, %xmm2 ; asm: andnps %xmm5, %xmm2
[-,%xmm2] v33 = band_not v11, v10 ; bin: 0f 55 d5 [-,%xmm2] v33 = band_not v10, v11 ; bin: 0f 55 d5
; asm: orps %xmm2, %xmm5 ; asm: orps %xmm2, %xmm5
[-,%xmm5] v34 = bor v10, v11 ; bin: 0f 56 ea [-,%xmm5] v34 = bor v10, v11 ; bin: 0f 56 ea

View File

@@ -77,9 +77,9 @@ ebb0:
[-,%xmm10] v31 = band v11, v10 ; bin: 44 0f 54 d5 [-,%xmm10] v31 = band v11, v10 ; bin: 44 0f 54 d5
; asm: andnps %xmm10, %xmm5 ; asm: andnps %xmm10, %xmm5
[-,%xmm5] v32 = band_not v10, v11 ; bin: 41 0f 55 ea [-,%xmm5] v32 = band_not v11, v10 ; bin: 41 0f 55 ea
; asm: andnps %xmm5, %xmm10 ; asm: andnps %xmm5, %xmm10
[-,%xmm10] v33 = band_not v11, v10 ; bin: 44 0f 55 d5 [-,%xmm10] v33 = band_not v10, v11 ; bin: 44 0f 55 d5
; asm: orps %xmm10, %xmm5 ; asm: orps %xmm10, %xmm5
[-,%xmm5] v34 = bor v10, v11 ; bin: 41 0f 56 ea [-,%xmm5] v34 = bor v10, v11 ; bin: 41 0f 56 ea
@@ -295,9 +295,9 @@ ebb0:
[-,%xmm10] v31 = band v11, v10 ; bin: 44 0f 54 d5 [-,%xmm10] v31 = band v11, v10 ; bin: 44 0f 54 d5
; asm: andnps %xmm10, %xmm5 ; asm: andnps %xmm10, %xmm5
[-,%xmm5] v32 = band_not v10, v11 ; bin: 41 0f 55 ea [-,%xmm5] v32 = band_not v11, v10 ; bin: 41 0f 55 ea
; asm: andnps %xmm5, %xmm10 ; asm: andnps %xmm5, %xmm10
[-,%xmm10] v33 = band_not v11, v10 ; bin: 44 0f 55 d5 [-,%xmm10] v33 = band_not v10, v11 ; bin: 44 0f 55 d5
; asm: orps %xmm10, %xmm5 ; asm: orps %xmm10, %xmm5
[-,%xmm5] v34 = bor v10, v11 ; bin: 41 0f 56 ea [-,%xmm5] v34 = bor v10, v11 ; bin: 41 0f 56 ea

View File

@@ -403,17 +403,20 @@ for inst, opc in [
(base.fdiv, 0x5e), (base.fdiv, 0x5e),
(x86.fmin, 0x5d), (x86.fmin, 0x5d),
(x86.fmax, 0x5f)]: (x86.fmax, 0x5f)]:
enc_flt(inst.f32, r.frm, 0xf3, 0x0f, opc) enc_flt(inst.f32, r.fa, 0xf3, 0x0f, opc)
enc_flt(inst.f64, r.frm, 0xf2, 0x0f, opc) enc_flt(inst.f64, r.fa, 0xf2, 0x0f, opc)
# Binary bitwise ops. # Binary bitwise ops.
for inst, opc in [ for inst, opc in [
(base.band, 0x54), (base.band, 0x54),
(base.band_not, 0x55),
(base.bor, 0x56), (base.bor, 0x56),
(base.bxor, 0x57)]: (base.bxor, 0x57)]:
enc_flt(inst.f32, r.frm, 0x0f, opc) enc_flt(inst.f32, r.fa, 0x0f, opc)
enc_flt(inst.f64, r.frm, 0x0f, opc) enc_flt(inst.f64, r.fa, 0x0f, opc)
# The `andnps(x,y)` instruction computes `~x&y`, while band_not(x,y)` is `x&~y.
enc_flt(base.band_not.f32, r.fax, 0x0f, 0x55)
enc_flt(base.band_not.f64, r.fax, 0x0f, 0x55)
# Comparisons. # Comparisons.
# #

View File

@@ -239,14 +239,22 @@ rrx = TailRecipe(
modrm_rr(in_reg1, in_reg0, sink); modrm_rr(in_reg1, in_reg0, sink);
''') ''')
# XX /r with FPR ins and outs. RM form. # XX /r with FPR ins and outs. A form.
frm = TailRecipe( fa = TailRecipe(
'frm', Binary, size=1, ins=(FPR, FPR), outs=0, 'fa', Binary, size=1, ins=(FPR, FPR), outs=0,
emit=''' emit='''
PUT_OP(bits, rex2(in_reg1, in_reg0), sink); PUT_OP(bits, rex2(in_reg1, in_reg0), sink);
modrm_rr(in_reg1, in_reg0, sink); modrm_rr(in_reg1, in_reg0, sink);
''') ''')
# XX /r with FPR ins and outs. A form with input operands swapped.
fax = TailRecipe(
'fax', Binary, size=1, ins=(FPR, FPR), outs=1,
emit='''
PUT_OP(bits, rex2(in_reg0, in_reg1), sink);
modrm_rr(in_reg0, in_reg1, sink);
''')
# XX /r, but for a unary operator with separate input/output register, like # XX /r, but for a unary operator with separate input/output register, like
# copies. MR form. # copies. MR form.
umr = TailRecipe( umr = TailRecipe(