sawg: adapt to int32/int64 change

This commit is contained in:
Robert Jördens 2016-11-22 11:57:34 +01:00
parent 5e900cf42a
commit 6799bb097a
2 changed files with 10 additions and 16 deletions

View File

@ -1,3 +1,4 @@
from numpy import int32, int64
from artiq.language.core import kernel, now_mu, portable from artiq.language.core import kernel, now_mu, portable
from artiq.coredevice.rtio import rtio_output, rtio_output_list from artiq.coredevice.rtio import rtio_output, rtio_output_list
from artiq.language.types import TInt32, TInt64, TFloat, TList from artiq.language.types import TInt32, TInt64, TFloat, TList
@ -25,8 +26,8 @@ class Spline:
@portable(flags=["fast-math"]) @portable(flags=["fast-math"])
def to_mu64(self, value: TFloat) -> TList(TInt32): def to_mu64(self, value: TFloat) -> TList(TInt32):
v = int(round(value*self.scale), width=64) v = int64(round(value*self.scale))
return [int(v, width=32), int(v >> 32, width=32)] return [int32(v), int32(v >> 32)]
@kernel @kernel
def set_mu(self, value: TInt32): def set_mu(self, value: TInt32):
@ -68,7 +69,7 @@ class Spline:
j = 0 j = 0
for i, vi in enumerate(value): for i, vi in enumerate(value):
w = self.width + i*self.time_width w = self.width + i*self.time_width
vi = int(round(vi*(self.scale*self.time_scale**i)), width=64) vi = int64(round(vi*(self.scale*self.time_scale**i)))
for k in range(0, w, 16): for k in range(0, w, 16):
wi = (vi >> k) & 0xffff wi = (vi >> k) & 0xffff
v[j//2] += wi << (16 * ((j + 1)//2 - j//2)) v[j//2] += wi << (16 * ((j + 1)//2 - j//2))

View File

@ -1,5 +1,6 @@
import unittest import unittest
import numpy as np import numpy as np
from numpy import int32, int64
import migen as mg import migen as mg
@ -19,18 +20,10 @@ class RTIOManager:
def rtio_output_list(self, *args, **kwargs): def rtio_output_list(self, *args, **kwargs):
self.rtio_output(*args, **kwargs) self.rtio_output(*args, **kwargs)
def int(self, value, width=32):
if width == 32:
return np.int32(value)
elif width == 64:
return np.int64(value)
else:
raise ValueError(width)
def patch(self, mod): def patch(self, mod):
assert not getattr(mod, "_saved", None) assert not getattr(mod, "_saved", None)
mod._saved = {} mod._saved = {}
for name in "rtio_output rtio_output_list int".split(): for name in "rtio_output rtio_output_list".split():
mod._saved[name] = getattr(mod, name, None) mod._saved[name] = getattr(mod, name, None)
setattr(mod, name, getattr(self, name)) setattr(mod, name, getattr(self, name))
@ -47,7 +40,7 @@ class SAWGTest(unittest.TestCase):
self.core = sim_devices.Core({}) self.core = sim_devices.Core({})
self.core.coarse_ref_period = 8 self.core.coarse_ref_period = 8
self.channel = mg.ClockDomainsRenamer({"rio_phy": "sys"})( self.channel = mg.ClockDomainsRenamer({"rio_phy": "sys"})(
Channel(width=16, parallelism=4)) Channel(width=16, parallelism=2))
self.driver = sawg.SAWG({"core": self.core}, channel_base=0, self.driver = sawg.SAWG({"core": self.core}, channel_base=0,
parallelism=self.channel.parallelism) parallelism=self.channel.parallelism)
@ -68,9 +61,9 @@ class SAWGTest(unittest.TestCase):
self.rtio_manager.outputs, [ self.rtio_manager.outputs, [
(0, 1, 0, int(round( (0, 1, 0, int(round(
(1 << self.driver.offset.width - 1)*.9))), (1 << self.driver.offset.width - 1)*.9))),
(2*8, 8, 0, [0, int(round( (2*8, 8, 0, [int(round(
(1 << self.driver.frequency0.width - 1) * (1 << self.driver.frequency0.width) /
self.channel.parallelism*.1))]), self.channel.parallelism*.1)), 0]),
(4*8, 1, 0, 0), (4*8, 1, 0, 0),
]) ])