diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2017-01-12 12:36:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-12 12:36:04 +0100 |
| commit | 632f95b8ce745ef77ecb9f46054c1964ddc59e3e (patch) | |
| tree | e49f319ca48901fe107c92308175397fcf3f9230 /miasm2/jitter/llvmconvert.py | |
| parent | edf8a67791cd7e3255cce048f2deb1bea436485c (diff) | |
| parent | ccf94648a6f8d3634b8fa707f01fa9e33ad5043b (diff) | |
| download | miasm-632f95b8ce745ef77ecb9f46054c1964ddc59e3e.tar.gz miasm-632f95b8ce745ef77ecb9f46054c1964ddc59e3e.zip | |
Merge pull request #472 from commial/feature/faster-parity
Feature/faster parity
Diffstat (limited to '')
| -rw-r--r-- | miasm2/jitter/llvmconvert.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py index 4031d8f2..32d4764c 100644 --- a/miasm2/jitter/llvmconvert.py +++ b/miasm2/jitter/llvmconvert.py @@ -197,10 +197,11 @@ class LLVMContext_JIT(LLVMContext): def add_op(self): "Add operations functions" - p8 = llvm_ir.PointerType(LLVMType.IntType(8)) + i8 = LLVMType.IntType(8) + p8 = llvm_ir.PointerType(i8) itype = LLVMType.IntType(64) - self.add_fc({"parity": {"ret": LLVMType.IntType(1), - "args": [itype]}}) + self.add_fc({"llvm.ctpop.i8": {"ret": i8, + "args": [i8]}}) self.add_fc({"rot_left": {"ret": itype, "args": [itype, itype, @@ -381,8 +382,7 @@ class LLVMFunction(): # Operation translation ## Basics - op_translate = {'parity': 'parity', - 'cpuid': 'cpuid', + op_translate = {'cpuid': 'cpuid', } ## Add the size as first argument op_translate_with_size = {'<<<': 'rot_left', @@ -711,6 +711,16 @@ class LLVMFunction(): self.update_cache(expr, ret) return ret + if op == "parity": + assert len(expr.args) == 1 + arg = self.add_ir(expr.args[0]) + truncated = builder.trunc(arg, LLVMType.IntType(8)) + bitcount = builder.call(self.mod.get_global("llvm.ctpop.i8"), + [truncated]) + ret = builder.not_(builder.trunc(bitcount, LLVMType.IntType(1))) + self.update_cache(expr, ret) + return ret + if op == "segm": fc_ptr = self.mod.get_global("segm2addr") |