From 3ed10221d8760c0b27ee64800036f6ffa5920dd0 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 13 Sep 2021 13:40:24 +0800 Subject: [PATCH] compiler: remove big-endian support. Closes #1590 --- artiq/compiler/targets.py | 8 ------- .../compiler/transforms/llvm_ir_generator.py | 24 +++++++++---------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/artiq/compiler/targets.py b/artiq/compiler/targets.py index 38e15b6cc..e908ce38a 100644 --- a/artiq/compiler/targets.py +++ b/artiq/compiler/targets.py @@ -77,9 +77,6 @@ class Target: :var print_function: (string) Name of a formatted print functions (with the signature of ``printf``) provided by the target, e.g. ``"printf"``. - :var little_endian: (boolean) - Whether the code will be executed on a little-endian machine. This cannot be always - determined from data_layout due to JIT. :var now_pinning: (boolean) Whether the target implements the now-pinning RTIO optimization. """ @@ -87,7 +84,6 @@ class Target: data_layout = "" features = [] print_function = "printf" - little_endian = False now_pinning = True tool_ld = "ld.lld" @@ -255,15 +251,12 @@ class NativeTarget(Target): super().__init__() self.triple = llvm.get_default_triple() host_data_layout = str(llvm.targets.Target.from_default_triple().create_target_machine().target_data) - assert host_data_layout[0] in "eE" - self.little_endian = host_data_layout[0] == "e" class RISCVTarget(Target): triple = "riscv32-unknown-linux" data_layout = "e-m:e-p:32:32-i64:64-n32-S128" features = ["m", "a"] print_function = "core_log" - little_endian = True now_pinning = True tool_ld = "ld.lld" @@ -276,7 +269,6 @@ class CortexA9Target(Target): data_layout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" features = ["dsp", "fp16", "neon", "vfp3"] print_function = "core_log" - little_endian = True now_pinning = False tool_ld = "ld.lld" diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index 970ade340..61f66599c 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -1095,15 +1095,12 @@ class LLVMIRGenerator: return self.map(insn.operands[0]) elif insn.op == "now_mu": if self.target.now_pinning: - # Word swap now.old for little endian target + # Word swap now.old as CPU is little endian # Most significant word is stored in lower address (see generated csr.rs) - if self.target.little_endian: - llnow_raw = self.llbuilder.load(self.llbuiltin("now"), name=insn.name) - llnow_lo = self.llbuilder.shl(llnow_raw, ll.Constant(lli64, 32)) - llnow_hi = self.llbuilder.lshr(llnow_raw, ll.Constant(lli64, 32)) - return self.llbuilder.or_(llnow_lo, llnow_hi) - else: - return self.llbuilder.load(self.llbuiltin("now"), name=insn.name) + llnow_raw = self.llbuilder.load(self.llbuiltin("now"), name=insn.name) + llnow_lo = self.llbuilder.shl(llnow_raw, ll.Constant(lli64, 32)) + llnow_hi = self.llbuilder.lshr(llnow_raw, ll.Constant(lli64, 32)) + return self.llbuilder.or_(llnow_lo, llnow_hi) else: return self.llbuilder.call(self.llbuiltin("now_mu"), []) elif insn.op == "at_mu": @@ -1125,12 +1122,13 @@ class LLVMIRGenerator: if self.target.now_pinning: llnowptr = self.llbuiltin("now") llnow = self.llbuilder.load(llnowptr, name="now.old") - # Word swap now.old for little endian target + + # Word swap now.old as CPU is little endian # Most significant word is stored in lower address (see generated csr.rs) - if self.target.little_endian: - llnow_lo = self.llbuilder.shl(llnow, ll.Constant(lli64, 32)) - llnow_hi = self.llbuilder.lshr(llnow, ll.Constant(lli64, 32)) - llnow = self.llbuilder.or_(llnow_lo, llnow_hi) + llnow_lo = self.llbuilder.shl(llnow, ll.Constant(lli64, 32)) + llnow_hi = self.llbuilder.lshr(llnow, ll.Constant(lli64, 32)) + llnow = self.llbuilder.or_(llnow_lo, llnow_hi) + lladjusted = self.llbuilder.add(llnow, llinterval, name="now.new") lladjusted_hi = self.llbuilder.trunc(self.llbuilder.lshr(lladjusted, ll.Constant(lli64, 32)), lli32) lladjusted_lo = self.llbuilder.trunc(lladjusted, lli32)