From 843786a0919e8f1cc2724261e6f27abdee346d2b Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 1 Oct 2017 19:00:10 +0000 Subject: [PATCH] compiler: minor intrinsic refactoring. --- .../compiler/transforms/llvm_ir_generator.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index 17f30c804..1fdad4319 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -326,11 +326,11 @@ class LLVMIRGenerator: llty = ll.FunctionType(llptr, []) elif name == "llvm.stackrestore": llty = ll.FunctionType(llvoid, [llptr]) - elif name == "__py_modsi4": + elif name == "__py_modsi3": llty = ll.FunctionType(lli32, [lli32, lli32]) - elif name == "__py_moddi4": + elif name == "__py_moddi3": llty = ll.FunctionType(lli64, [lli64, lli64]) - elif name == "__py_moddf4": + elif name == "__py_moddf3": llty = ll.FunctionType(lldouble, [lldouble, lldouble]) elif name == self.target.print_function: llty = ll.FunctionType(llvoid, [llptr], var_arg=True) @@ -381,10 +381,10 @@ class LLVMIRGenerator: llbuilder = ll.IRBuilder() llbuilder.position_at_end(llfun.append_basic_block("entry")) - if name == "__py_modsi4" or name == "__py_moddi4": - if name == "__py_modsi4": + if name == "__py_modsi3" or name == "__py_moddi3": + if name == "__py_modsi3": llty = lli32 - elif name == "__py_moddi4": + elif name == "__py_moddi3": llty = lli64 else: assert False @@ -407,15 +407,14 @@ class LLVMIRGenerator: llxdivy = llbuilder.sdiv(llx, lly) llxremy = llbuilder.srem(llx, lly) - llxmodynonzero = llbuilder.icmp_signed('!=', llxremy, - ll.Constant(llty, 0)) - lldiffsign = llbuilder.icmp_signed('<', llbuilder.xor(lly, llxremy), - ll.Constant(llty, 0)) + llxmodynonzero = llbuilder.icmp_signed('!=', llxremy, ll.Constant(llty, 0)) + lldiffsign = llbuilder.icmp_signed('<', llbuilder.xor(llx, lly), ll.Constant(llty, 0)) + llcond = llbuilder.and_(llxmodynonzero, lldiffsign) with llbuilder.if_then(llcond): llbuilder.ret(llbuilder.add(llxremy, lly)) llbuilder.ret(llxremy) - elif name == "__py_moddf4": + elif name == "__py_moddf3": """ Reference Objects/floatobject.c mod = fmod(vx, wx); @@ -455,6 +454,8 @@ class LLVMIRGenerator: with llbuilder.if_then(llcond): llbuilder.ret(llbuilder.fadd(llrem, llw)) llbuilder.ret(llrem) + else: + assert False def get_function(self, typ, name): llfun = self.llmodule.get_global(name) @@ -995,11 +996,11 @@ class LLVMIRGenerator: elif isinstance(insn.op, ast.Mod): lllhs, llrhs = map(self.map, (insn.lhs(), insn.rhs())) if builtins.is_float(insn.type): - intrinsic = "__py_moddf4" + intrinsic = "__py_moddf3" elif builtins.is_int32(insn.type): - intrinsic = "__py_modsi4" + intrinsic = "__py_modsi3" elif builtins.is_int64(insn.type): - intrinsic = "__py_moddi4" + intrinsic = "__py_moddi3" return self.llbuilder.call(self.llbuiltin(intrinsic), [lllhs, llrhs], name=insn.name) elif isinstance(insn.op, ast.Pow):