forked from M-Labs/artiq
compiler: in codegen for delay(), round fp instead of truncating.
Consider delay(8*us). It results in the following computation... >>> 8*1e-06/1e-09 7999.999999999999 with the result promptly getting truncated to 7999. Fixes #706.
This commit is contained in:
parent
6342829e68
commit
c33f9637c1
|
@ -1725,7 +1725,7 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
||||||
if len(node.args) == 1 and len(node.keywords) == 0:
|
if len(node.args) == 1 and len(node.keywords) == 0:
|
||||||
arg = self.visit(node.args[0])
|
arg = self.visit(node.args[0])
|
||||||
arg_mu_float = self.append(ir.Arith(ast.Div(loc=None), arg, self.ref_period))
|
arg_mu_float = self.append(ir.Arith(ast.Div(loc=None), arg, self.ref_period))
|
||||||
arg_mu = self.append(ir.Coerce(arg_mu_float, builtins.TInt64()))
|
arg_mu = self.append(ir.Builtin("round", [arg_mu_float], builtins.TInt64()))
|
||||||
return self.append(ir.Builtin("delay_mu", [arg_mu], builtins.TNone()))
|
return self.append(ir.Builtin("delay_mu", [arg_mu], builtins.TNone()))
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
|
|
@ -249,6 +249,19 @@ class Handover(EnvExperiment):
|
||||||
self.k("t2")
|
self.k("t2")
|
||||||
|
|
||||||
|
|
||||||
|
class Rounding(EnvExperiment):
|
||||||
|
def build(self):
|
||||||
|
self.setattr_device("core")
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
|
t1 = now_mu()
|
||||||
|
delay(8*us)
|
||||||
|
t2 = now_mu()
|
||||||
|
self.set_dataset("delta", t2 - t1)
|
||||||
|
|
||||||
|
|
||||||
class DummyException(Exception):
|
class DummyException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -353,6 +366,11 @@ class CoredeviceTest(ExperimentCase):
|
||||||
self.assertEqual(self.dataset_mgr.get("t1") + 1234,
|
self.assertEqual(self.dataset_mgr.get("t1") + 1234,
|
||||||
self.dataset_mgr.get("t2"))
|
self.dataset_mgr.get("t2"))
|
||||||
|
|
||||||
|
def test_rounding(self):
|
||||||
|
self.execute(Rounding)
|
||||||
|
dt = self.dataset_mgr.get("delta")
|
||||||
|
self.assertEqual(dt, 8000)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RPCTiming(EnvExperiment):
|
class RPCTiming(EnvExperiment):
|
||||||
|
|
Loading…
Reference in New Issue