@@ -127,7 +127,7 @@ def test_basic_signed_gte(self):
127
127
self .check_trace ('o 0 0 0 0 0 1 1 1 \n ' )
128
128
129
129
130
- class TestSignedAddBasicOperations (unittest .TestCase ):
130
+ class TestSignedArithBasicOperations (unittest .TestCase ):
131
131
def setUp (self ):
132
132
pyrtl .reset_working_block ()
133
133
# test with '101' in binary, which should be
@@ -152,3 +152,38 @@ def test_basic_signed_add(self):
152
152
self .o <<= pyrtl .signed_add (self .r , self .c )
153
153
# 0 1 2 3 -4 -3 -2 -1
154
154
self .check_trace ('-3 -2 -1 0 -7 -6 -5 -4' )
155
+
156
+ def test_basic_signed_add (self ):
157
+ self .o <<= pyrtl .signed_add (self .r , Const (- 3 , signed = True ))
158
+ self .check_trace ('-3 -2 -1 0 -7 -6 -5 -4' )
159
+
160
+ def test_basic_signed_add (self ):
161
+ self .o <<= pyrtl .signed_add (self .r , - 3 )
162
+ self .check_trace ('-3 -2 -1 0 -7 -6 -5 -4' )
163
+
164
+ def test_basic_signed_mult (self ):
165
+ self .o <<= pyrtl .signed_mult (self .r , self .c )
166
+ # 0 1 2 3 -4 -3 -2 -1
167
+ self .check_trace ('0 -3 -6 7 -4 -7 6 3' )
168
+ # the above numbers don't look like multiplication but when you sign
169
+ # extend the inputs, truncate to the last 4 digits and then sign extend,
170
+ # the output I assure that they are indeed correct. :)
171
+
172
+ def test_basic_signed_mult (self ):
173
+ self .o <<= pyrtl .signed_mult (self .r , pyrtl .Const (- 2 , bitwidth = 3 ))
174
+ # 0 1 2 3 -4 -3 -2 -1
175
+ self .check_trace ('0 -2 -4 -6 -8 6 4 2' )
176
+ # this one is multiplies by -2 and the trend is easier to see (-4 x -3 does
177
+ # overflow the 4 bits though).
178
+
179
+ def test_basic_signed_mult (self ):
180
+ self .o <<= pyrtl .signed_mult (self .r , pyrtl .Const (- 2 , signed = True ))
181
+ self .check_trace ('0 -2 -4 -6 -8 6 4 2' )
182
+
183
+ def test_basic_signed_mult (self ):
184
+ self .o <<= pyrtl .signed_mult (self .r , - 2 )
185
+ self .check_trace ('0 -2 -4 -6 -8 6 4 2' )
186
+
187
+ def test_basic_signed_mult (self ):
188
+ self .o <<= pyrtl .signed_mult (- 2 , self .r )
189
+ self .check_trace ('0 -2 -4 -6 -8 6 4 2' )
0 commit comments