diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-01-15 08:13:09 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-01-15 08:13:09 +0100 |
| commit | e8a12bea1445afd764f4ef7075075a773fe84677 (patch) | |
| tree | 4cbe00760c2b888255e273d3ce7adbf1b0599918 | |
| parent | 056ef4cd26c98cd8b9c121f2a791c01c5a7052a8 (diff) | |
| download | miasm-e8a12bea1445afd764f4ef7075075a773fe84677.tar.gz miasm-e8a12bea1445afd764f4ef7075075a773fe84677.zip | |
Rename idiv/imod into sdiv/smod
| -rw-r--r-- | miasm2/arch/aarch64/sem.py | 2 | ||||
| -rw-r--r-- | miasm2/arch/arm/sem.py | 2 | ||||
| -rw-r--r-- | miasm2/arch/mips32/sem.py | 4 | ||||
| -rw-r--r-- | miasm2/arch/ppc/sem.py | 2 | ||||
| -rw-r--r-- | miasm2/arch/x86/sem.py | 4 | ||||
| -rw-r--r-- | miasm2/expression/expression_helper.py | 2 | ||||
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 6 | ||||
| -rw-r--r-- | miasm2/ir/translators/C.py | 2 | ||||
| -rw-r--r-- | miasm2/ir/translators/smt2.py | 4 | ||||
| -rw-r--r-- | miasm2/ir/translators/z3_ir.py | 10 | ||||
| -rw-r--r-- | miasm2/jitter/bn.c | 6 | ||||
| -rw-r--r-- | miasm2/jitter/bn.h | 4 | ||||
| -rw-r--r-- | miasm2/jitter/llvmconvert.py | 6 | ||||
| -rw-r--r-- | miasm2/jitter/op_semantics.c | 18 | ||||
| -rw-r--r-- | miasm2/jitter/op_semantics.h | 24 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 4 |
16 files changed, 50 insertions, 50 deletions
diff --git a/miasm2/arch/aarch64/sem.py b/miasm2/arch/aarch64/sem.py index 8451d3e9..0a03a151 100644 --- a/miasm2/arch/aarch64/sem.py +++ b/miasm2/arch/aarch64/sem.py @@ -809,7 +809,7 @@ def udiv(arg1, arg2, arg3): @sbuild.parse def sdiv(arg1, arg2, arg3): if arg3: - arg1 = ExprOp('idiv', arg2, arg3) + arg1 = ExprOp('sdiv', arg2, arg3) else: exception_flags = ExprInt(EXCEPT_DIV_BY_ZERO, exception_flags.size) diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py index b5ab60d0..64403206 100644 --- a/miasm2/arch/arm/sem.py +++ b/miasm2/arch/arm/sem.py @@ -592,7 +592,7 @@ def sdiv(ir, instr, a, b, c=None): - r = ExprOp("idiv", b, c) + r = ExprOp("sdiv", b, c) do_div = [] do_div.append(ExprAssign(a, r)) dst = get_dst(a) diff --git a/miasm2/arch/mips32/sem.py b/miasm2/arch/mips32/sem.py index a57d2200..62a85355 100644 --- a/miasm2/arch/mips32/sem.py +++ b/miasm2/arch/mips32/sem.py @@ -393,8 +393,8 @@ def multu(arg1, arg2): @sbuild.parse def div(arg1, arg2): """Divide (signed) @arg1 by @arg2 and stores the remaining/result in $R_HI/$R_LO""" - R_LO = ExprOp('idiv' ,arg1, arg2) - R_HI = ExprOp('imod', arg1, arg2) + R_LO = ExprOp('sdiv' ,arg1, arg2) + R_HI = ExprOp('smod', arg1, arg2) @sbuild.parse def divu(arg1, arg2): diff --git a/miasm2/arch/ppc/sem.py b/miasm2/arch/ppc/sem.py index 969a8002..44895624 100644 --- a/miasm2/arch/ppc/sem.py +++ b/miasm2/arch/ppc/sem.py @@ -165,7 +165,7 @@ def mn_do_div(ir, instr, rd, ra, rb): if has_u: op = 'udiv' else: - op = 'idiv' + op = 'sdiv' rvalue = ExprOp(op, ra, rb) diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index 244aff30..e01adcbc 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -1754,8 +1754,8 @@ def idiv(ir, instr, src1): else: raise ValueError('div arg not impl', src1) - c_d = m2_expr.ExprOp('idiv', src2, src1.signExtend(src2.size)) - c_r = m2_expr.ExprOp('imod', src2, src1.signExtend(src2.size)) + c_d = m2_expr.ExprOp('sdiv', src2, src1.signExtend(src2.size)) + c_r = m2_expr.ExprOp('smod', src2, src1.signExtend(src2.size)) # if 8 bit div, only ax is affected if size == 8: diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py index c503ebfc..8065df9b 100644 --- a/miasm2/expression/expression_helper.py +++ b/miasm2/expression/expression_helper.py @@ -80,7 +80,7 @@ def merge_sliceto_slice(expr): op_propag_cst = ['+', '*', '^', '&', '|', '>>', '<<', "a>>", ">>>", "<<<", - "/", "%", 'idiv', 'imod', 'umod', 'udiv','**'] + "/", "%", 'sdiv', 'smod', 'umod', 'udiv','**'] def is_pure_int(e): diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 6f0eb34a..ab0f7ad9 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -73,12 +73,12 @@ def simp_cst_propagation(e_s, expr): out = int1.arg / int2.arg elif op_name == '%': out = int1.arg % int2.arg - elif op_name == 'idiv': + elif op_name == 'sdiv': assert int2.arg.arg tmp1 = mod_size2int[int1.arg.size](int1.arg) tmp2 = mod_size2int[int2.arg.size](int2.arg) out = mod_size2uint[int1.arg.size](tmp1 / tmp2) - elif op_name == 'imod': + elif op_name == 'smod': assert int2.arg.arg tmp1 = mod_size2int[int1.arg.size](int1.arg) tmp2 = mod_size2int[int2.arg.size](int2.arg) @@ -143,7 +143,7 @@ def simp_cst_propagation(e_s, expr): # op A => A if op_name in ['+', '*', '^', '&', '|', '>>', '<<', - 'a>>', '<<<', '>>>', 'idiv', 'imod', 'umod', 'udiv'] and len(args) == 1: + 'a>>', '<<<', '>>>', 'sdiv', 'smod', 'umod', 'udiv'] and len(args) == 1: return args[0] # A-B => A + (-B) diff --git a/miasm2/ir/translators/C.py b/miasm2/ir/translators/C.py index a5453745..a239383b 100644 --- a/miasm2/ir/translators/C.py +++ b/miasm2/ir/translators/C.py @@ -372,7 +372,7 @@ class TranslatorC(Translator): - elif expr.op in ['idiv', 'imod']: + elif expr.op in ['sdiv', 'smod']: arg0 = self.from_expr(expr.args[0]) arg1 = self.from_expr(expr.args[1]) diff --git a/miasm2/ir/translators/smt2.py b/miasm2/ir/translators/smt2.py index eda24bb7..81d86798 100644 --- a/miasm2/ir/translators/smt2.py +++ b/miasm2/ir/translators/smt2.py @@ -198,13 +198,13 @@ class TranslatorSMT2(Translator): res = bvmul(res, arg) elif expr.op == "/": res = bvsdiv(res, arg) - elif expr.op == "idiv": + elif expr.op == "sdiv": res = bvsdiv(res, arg) elif expr.op == "udiv": res = bvudiv(res, arg) elif expr.op == "%": res = bvsmod(res, arg) - elif expr.op == "imod": + elif expr.op == "smod": res = bvsmod(res, arg) elif expr.op == "umod": res = bvurem(res, arg) diff --git a/miasm2/ir/translators/z3_ir.py b/miasm2/ir/translators/z3_ir.py index d43468ef..2572ac74 100644 --- a/miasm2/ir/translators/z3_ir.py +++ b/miasm2/ir/translators/z3_ir.py @@ -171,7 +171,7 @@ class TranslatorZ3(Translator): def _abs(self, z3_value): return z3.If(z3_value >= 0,z3_value,-z3_value) - def _idivC(self, num, den): + def _sdivC(self, num, den): """Divide (signed) @num by @den (z3 values) as C would See modint.__div__ for implementation choice """ @@ -197,12 +197,12 @@ class TranslatorZ3(Translator): res = z3.RotateLeft(res, arg) elif expr.op == ">>>": res = z3.RotateRight(res, arg) - elif expr.op == "idiv": - res = self._idivC(res, arg) + elif expr.op == "sdiv": + res = self._sdivC(res, arg) elif expr.op == "udiv": res = z3.UDiv(res, arg) - elif expr.op == "imod": - res = res - (arg * (self._idivC(res, arg))) + elif expr.op == "smod": + res = res - (arg * (self._sdivC(res, arg))) elif expr.op == "umod": res = z3.URem(res, arg) elif expr.op == "==": diff --git a/miasm2/jitter/bn.c b/miasm2/jitter/bn.c index 96e66f4d..c621d102 100644 --- a/miasm2/jitter/bn.c +++ b/miasm2/jitter/bn.c @@ -796,7 +796,7 @@ int bignum_cnttrailzeros(bn_t n, int size) -bn_t bignum_idiv(bn_t a, bn_t b, int size) +bn_t bignum_sdiv(bn_t a, bn_t b, int size) { require(size, "size must be greater than 0"); require(size <= BN_BIT_SIZE, "size must be below bignum max size"); @@ -832,14 +832,14 @@ bn_t bignum_idiv(bn_t a, bn_t b, int size) -bn_t bignum_imod(bn_t a, bn_t b, int size) +bn_t bignum_smod(bn_t a, bn_t b, int size) { require(size, "size must be greater than 0"); require(size <= BN_BIT_SIZE, "size must be below bignum max size"); bn_t c; - c = bignum_idiv(a, b, size); + c = bignum_sdiv(a, b, size); c = bignum_mul(c, b); c = bignum_sub(a, c); c = bignum_mask(c, size); diff --git a/miasm2/jitter/bn.h b/miasm2/jitter/bn.h index 67d20a77..f0a13b53 100644 --- a/miasm2/jitter/bn.h +++ b/miasm2/jitter/bn.h @@ -116,8 +116,8 @@ _MIASM_EXPORT bn_t bignum_sub(bn_t a, bn_t b); /* c = a - b */ _MIASM_EXPORT bn_t bignum_mul(bn_t a, bn_t b); /* c = a * b */ _MIASM_EXPORT bn_t bignum_udiv(bn_t a, bn_t b); /* c = a / b */ _MIASM_EXPORT bn_t bignum_umod(bn_t a, bn_t b); /* c = a % b */ -_MIASM_EXPORT bn_t bignum_idiv(bn_t a, bn_t b, int size); -_MIASM_EXPORT bn_t bignum_imod(bn_t a, bn_t b, int size); +_MIASM_EXPORT bn_t bignum_sdiv(bn_t a, bn_t b, int size); +_MIASM_EXPORT bn_t bignum_smod(bn_t a, bn_t b, int size); //void bignum_udivmod(struct bn* a, struct bn* b, struct bn* c, struct bn* d); /* c = a/b, d = a%b */ diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py index 37ce8d52..5230bdbe 100644 --- a/miasm2/jitter/llvmconvert.py +++ b/miasm2/jitter/llvmconvert.py @@ -874,15 +874,15 @@ class LLVMFunction(object): self.update_cache(expr, ret) return ret - if op in ["imod", "idiv", "umod", "udiv"]: + if op in ["smod", "sdiv", "umod", "udiv"]: assert len(expr.args) == 2 arg_b = self.add_ir(expr.args[1]) arg_a = self.add_ir(expr.args[0]) - if op == "imod": + if op == "smod": callback = builder.srem - elif op == "idiv": + elif op == "sdiv": callback = builder.sdiv elif op == "umod": callback = builder.urem diff --git a/miasm2/jitter/op_semantics.c b/miasm2/jitter/op_semantics.c index 091da87f..46e6cca1 100644 --- a/miasm2/jitter/op_semantics.c +++ b/miasm2/jitter/op_semantics.c @@ -738,12 +738,12 @@ UMOD(16) UMOD(32) UMOD(64) -IDIV(8) -IDIV(16) -IDIV(32) -IDIV(64) - -IMOD(8) -IMOD(16) -IMOD(32) -IMOD(64) +SDIV(8) +SDIV(16) +SDIV(32) +SDIV(64) + +SMOD(8) +SMOD(16) +SMOD(32) +SMOD(64) diff --git a/miasm2/jitter/op_semantics.h b/miasm2/jitter/op_semantics.h index 921c9b9e..690cfb35 100644 --- a/miasm2/jitter/op_semantics.h +++ b/miasm2/jitter/op_semantics.h @@ -66,8 +66,8 @@ _MIASM_EXPORT unsigned int cnttrailzeros(uint64_t size, uint64_t src); } -#define IDIV(sizeA) \ - int ## sizeA ## _t idiv ## sizeA (int ## sizeA ## _t a, int ## sizeA ## _t b) \ +#define SDIV(sizeA) \ + int ## sizeA ## _t sdiv ## sizeA (int ## sizeA ## _t a, int ## sizeA ## _t b) \ { \ int ## sizeA ## _t r; \ if (b == 0) { \ @@ -79,8 +79,8 @@ _MIASM_EXPORT unsigned int cnttrailzeros(uint64_t size, uint64_t src); } -#define IMOD(sizeA) \ - int ## sizeA ## _t imod ## sizeA (int ## sizeA ## _t a, int ## sizeA ## _t b) \ +#define SMOD(sizeA) \ + int ## sizeA ## _t smod ## sizeA (int ## sizeA ## _t a, int ## sizeA ## _t b) \ { \ int ## sizeA ## _t r; \ if (b == 0) { \ @@ -93,23 +93,23 @@ _MIASM_EXPORT unsigned int cnttrailzeros(uint64_t size, uint64_t src); _MIASM_EXPORT uint64_t udiv64(uint64_t a, uint64_t b); _MIASM_EXPORT uint64_t umod64(uint64_t a, uint64_t b); -_MIASM_EXPORT int64_t idiv64(int64_t a, int64_t b); -_MIASM_EXPORT int64_t imod64(int64_t a, int64_t b); +_MIASM_EXPORT int64_t sdiv64(int64_t a, int64_t b); +_MIASM_EXPORT int64_t smod64(int64_t a, int64_t b); _MIASM_EXPORT uint32_t udiv32(uint32_t a, uint32_t b); _MIASM_EXPORT uint32_t umod32(uint32_t a, uint32_t b); -_MIASM_EXPORT int32_t idiv32(int32_t a, int32_t b); -_MIASM_EXPORT int32_t imod32(int32_t a, int32_t b); +_MIASM_EXPORT int32_t sdiv32(int32_t a, int32_t b); +_MIASM_EXPORT int32_t smod32(int32_t a, int32_t b); _MIASM_EXPORT uint16_t udiv16(uint16_t a, uint16_t b); _MIASM_EXPORT uint16_t umod16(uint16_t a, uint16_t b); -_MIASM_EXPORT int16_t idiv16(int16_t a, int16_t b); -_MIASM_EXPORT int16_t imod16(int16_t a, int16_t b); +_MIASM_EXPORT int16_t sdiv16(int16_t a, int16_t b); +_MIASM_EXPORT int16_t smod16(int16_t a, int16_t b); _MIASM_EXPORT uint8_t udiv8(uint8_t a, uint8_t b); _MIASM_EXPORT uint8_t umod8(uint8_t a, uint8_t b); -_MIASM_EXPORT int8_t idiv8(int8_t a, int8_t b); -_MIASM_EXPORT int8_t imod8(int8_t a, int8_t b); +_MIASM_EXPORT int8_t sdiv8(int8_t a, int8_t b); +_MIASM_EXPORT int8_t smod8(int8_t a, int8_t b); _MIASM_EXPORT unsigned int x86_cpuid(unsigned int a, unsigned int reg_num); diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 364456c6..cc3606e4 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -401,9 +401,9 @@ to_test = [(ExprInt(1, 32) - ExprInt(1, 32), ExprInt(0, 32)), (expr_is_signed_greater(ExprInt(-10, 32), ExprInt(-5, 32)), ExprInt(0, 1)), - (ExprOp("idiv", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], + (ExprOp("sdiv", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], ExprInt(0xc6, 8)), - (ExprOp("imod", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], + (ExprOp("smod", ExprInt(0x0123, 16), ExprInt(0xfffb, 16))[:8], ExprInt(0x01, 8)), (ExprOp("cnttrailzeros", ExprInt(0x2, 32)), ExprInt(0x1, 32)), |