Skip to content

Commit d928fd8

Browse files
vk2sebgoekce
andauthored
lib/fixed: avoid unnecessary slicing on reshape()
Co-authored-by: Gökçe Aydos <18174744+goekce@users.noreply.github.com>
1 parent 5b87954 commit d928fd8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

amaranth/lib/fixed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ def reshape(self, f_bits):
130130
shape = hdl.Shape(self.i_bits + f_bits, signed=self.signed)
131131
if f_bits > self.f_bits:
132132
result = Shape(shape, f_bits)(hdl.Cat(hdl.Const(0, f_bits - self.f_bits), self.as_value()))
133-
else:
133+
elif f_bits < self.f_bits:
134134
result = Shape(shape, f_bits)(self.as_value()[self.f_bits - f_bits:])
135+
else:
136+
result = Shape(shape, f_bits)(self.as_value())
135137
return result
136138

137139
def truncate(self, f_bits=0):

0 commit comments

Comments
 (0)