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 | |
| 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 | ||||
| -rw-r--r-- | miasm2/jitter/vm_mngr.c | 5 | ||||
| -rw-r--r-- | miasm2/jitter/vm_mngr.h | 3 |
3 files changed, 16 insertions, 12 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") diff --git a/miasm2/jitter/vm_mngr.c b/miasm2/jitter/vm_mngr.c index 42f91f72..c48ba334 100644 --- a/miasm2/jitter/vm_mngr.c +++ b/miasm2/jitter/vm_mngr.c @@ -76,11 +76,6 @@ const uint8_t parity_table[256] = { 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P, }; -uint8_t parity(uint64_t a) { - return parity_table[(a) & 0xFF]; -} - - // #define DEBUG_MIASM_AUTOMOD_CODE void memory_access_list_init(struct memory_access_list * access) diff --git a/miasm2/jitter/vm_mngr.h b/miasm2/jitter/vm_mngr.h index 88ecf34d..912b105e 100644 --- a/miasm2/jitter/vm_mngr.h +++ b/miasm2/jitter/vm_mngr.h @@ -193,8 +193,7 @@ int vm_write_mem(vm_mngr_t* vm_mngr, uint64_t addr, char *buffer, uint64_t size) #define CC_P 1 extern const uint8_t parity_table[256]; - -uint8_t parity(uint64_t a); +#define parity(a) parity_table[(a) & 0xFF] unsigned int my_imul08(unsigned int a, unsigned int b); |