hdl.ast: simplify {bit,word}_select with constant offset.
We don't have any other convenient shortcut for x[off*w:(off+1)*w], but using word_select to extract a single static range would result in severe bloat of emitted code through expansion to dead branches. Recognize and simplify this pattern.
This commit is contained in:
parent
61e6267daf
commit
51269ad4a0
2 changed files with 21 additions and 0 deletions
|
|
@ -533,15 +533,23 @@ class BitSelectTestCase(FHDLTestCase):
|
|||
|
||||
def test_shape(self):
|
||||
s1 = self.c.bit_select(self.s, 2)
|
||||
self.assertIsInstance(s1, Part)
|
||||
self.assertEqual(s1.shape(), unsigned(2))
|
||||
self.assertIsInstance(s1.shape(), Shape)
|
||||
s2 = self.c.bit_select(self.s, 0)
|
||||
self.assertIsInstance(s2, Part)
|
||||
self.assertEqual(s2.shape(), unsigned(0))
|
||||
|
||||
def test_stride(self):
|
||||
s1 = self.c.bit_select(self.s, 2)
|
||||
self.assertIsInstance(s1, Part)
|
||||
self.assertEqual(s1.stride, 1)
|
||||
|
||||
def test_const(self):
|
||||
s1 = self.c.bit_select(1, 2)
|
||||
self.assertIsInstance(s1, Slice)
|
||||
self.assertRepr(s1, """(slice (const 8'd0) 1:3)""")
|
||||
|
||||
def test_width_wrong(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self.c.bit_select(self.s, -1)
|
||||
|
|
@ -558,13 +566,20 @@ class WordSelectTestCase(FHDLTestCase):
|
|||
|
||||
def test_shape(self):
|
||||
s1 = self.c.word_select(self.s, 2)
|
||||
self.assertIsInstance(s1, Part)
|
||||
self.assertEqual(s1.shape(), unsigned(2))
|
||||
self.assertIsInstance(s1.shape(), Shape)
|
||||
|
||||
def test_stride(self):
|
||||
s1 = self.c.word_select(self.s, 2)
|
||||
self.assertIsInstance(s1, Part)
|
||||
self.assertEqual(s1.stride, 2)
|
||||
|
||||
def test_const(self):
|
||||
s1 = self.c.word_select(1, 2)
|
||||
self.assertIsInstance(s1, Slice)
|
||||
self.assertRepr(s1, """(slice (const 8'd0) 2:4)""")
|
||||
|
||||
def test_width_wrong(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self.c.word_select(self.s, 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue