Skip to content

Commit

Permalink
Implement two-argument form of imul
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed May 25, 2018
1 parent d1a0ebb commit ef28790
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
50 changes: 25 additions & 25 deletions emu/gadgets-x86/math.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@
.macro _do_op op, arg, size, s, ss
.ifc \op,load
mov\ss \arg, %tmp\s
.exitm
.else; .ifc \op,store
mov\ss %tmp\s, \arg
.else
.ifin(\op, add,sub,adc,sbb)
mov\ss \arg, %r14\s
setf_a src=%r14\s, dst=%tmp\s, ss=\ss
.endifin
.ifin(\op, and,or,xor)
clearf_a
clearf_oc
.endifin
.ifin(\op, adc,sbb)
btw $0, CPU_cf(%_cpu)
.endifin
\op\ss \arg, %tmp\s
.ifin(\op, add,sub,adc,sbb)
setf_oc
.endifin
setf_zsp %tmp\s, \ss
.exitm
.endif; .endif

.ifin(\op, add,sub,adc,sbb)
mov\ss \arg, %r14\s
setf_a src=%r14\s, dst=%tmp\s, ss=\ss
.endifin
.ifin(\op, and,or,xor)
clearf_a
clearf_oc
.endifin
.ifin(\op, adc,sbb)
btw $0, CPU_cf(%_cpu)
.endifin
\op\ss \arg, %tmp\s
.ifin(\op, add,sub,adc,sbb)
setf_oc
.endifin
.ifnc \op,imul
setf_zsp %tmp\s, \ss
.endif
.endm
.macro do_op op, size, arg
ss \size, _do_op, \op, \arg
Expand Down Expand Up @@ -112,6 +116,9 @@
.endr
.gadget_array \op
.endr
do_op_size imul, 16
do_op_size imul, 32
.gadget_array imul

# unary operations (well, only one explicit operand)
.irp op, inc,dec
Expand All @@ -133,13 +140,6 @@
idiv\ss %r10\s
gret
.endm
.macro do_imul size, s, ss
.if \size != 8
.gadget imul_\size
imul\ss (%_ip), %r10\s
gret 1
.endif
.endm
.macro do_neg size, s, ss
.gadget neg_\size
setf_a src=$0 dst=%r10\s ss=\ss
Expand All @@ -154,7 +154,7 @@
gret
.endm

.irp op, idiv,div,imul,neg,not
.irp op, idiv,div,neg,not
.irp size, SIZE_LIST
ss \size, do_\op
.endr
Expand Down
4 changes: 2 additions & 2 deletions emu/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ static inline void gen_op(struct gen_state *state, gadget_t *gadgets, enum arg a
#define MUL18(val,z) UNDEFINED
#define MUL1(val,z) UNDEFINED
#define IMUL1(val,z) UNDEFINED
#define IMUL2(val, reg,z) UNDEFINED
#define IMUL3(imm, src, dst,z) load(src,z); gag(imul, sz(z), imm); store(dst,z)
#define IMUL2(val, reg,z) los(imul, val, reg, z)
#define IMUL3(imm, src, dst,z) load(src, z); op(imul, imm, z); store(dst, z)
#define DIV(val, z) load(val, z); ga(div, sz(z)); store(val, z)
#define IDIV(val, z) load(val, z); ga(idiv, sz(z)); store(val, z)

Expand Down

0 comments on commit ef28790

Please sign in to comment.