@@ -315,7 +315,87 @@ def test_slice_net_removal_4(self):
315315 block = pyrtl .working_block ()
316316 self .num_net_of_type ('s' , 1 , block )
317317 self .num_net_of_type ('w' , 2 , block )
318+
319+ def test_remove_double_inverts_1_invert (self ):
320+ inwire = pyrtl .Input (bitwidth = 1 )
321+ outwire = pyrtl .Output (bitwidth = 1 )
322+ outwire <<= ~ inwire
323+ pyrtl .optimize ()
324+ block = pyrtl .working_block ()
325+ self .assert_num_net (2 , block )
326+ self .assert_num_wires (3 , block )
327+
328+ def test_remove_double_inverts_3_inverts (self ):
329+ inwire = pyrtl .Input (bitwidth = 1 )
330+ outwire = pyrtl .Output (bitwidth = 1 )
331+ outwire <<= ~ (~ (~ inwire ))
332+ pyrtl .optimize ()
333+ block = pyrtl .working_block ()
334+ self .assert_num_net (2 , block )
335+ self .assert_num_wires (3 , block )
336+
337+ def test_remove_double_inverts_5_inverts (self ):
338+ inwire = pyrtl .Input (bitwidth = 1 )
339+ outwire = pyrtl .Output (bitwidth = 1 )
340+ outwire <<= ~ (~ (~ (~ (~ inwire ))))
341+ pyrtl .optimize ()
342+ block = pyrtl .working_block ()
343+ self .assert_num_net (2 , block )
344+ self .assert_num_wires (3 , block )
345+
346+ def test_remove_double_inverts_2_inverts (self ):
347+ inwire = pyrtl .Input (bitwidth = 1 )
348+ outwire = pyrtl .Output (bitwidth = 1 )
349+ outwire <<= ~ (~ inwire )
350+ pyrtl .optimize ()
351+ block = pyrtl .working_block ()
352+ self .assert_num_net (1 , block )
353+ self .assert_num_wires (2 , block )
318354
355+ def test_remove_double_inverts_4_inverts (self ):
356+ inwire = pyrtl .Input (bitwidth = 1 )
357+ outwire = pyrtl .Output (bitwidth = 1 )
358+ outwire <<= ~ (~ (~ (~ inwire )))
359+ pyrtl .optimize ()
360+ block = pyrtl .working_block ()
361+ self .assert_num_net (1 , block )
362+ self .assert_num_wires (2 , block )
363+
364+ def test_remove_double_inverts_6_inverts (self ):
365+ inwire = pyrtl .Input (bitwidth = 1 )
366+ outwire = pyrtl .Output (bitwidth = 1 )
367+ outwire <<= ~ (~ (~ (~ (~ (~ inwire )))))
368+ pyrtl .optimize ()
369+ block = pyrtl .working_block ()
370+ self .assert_num_net (1 , block )
371+ self .assert_num_wires (2 , block )
372+
373+ def test_dont_remove_double_inverts_another_user (self ):
374+ inwire = pyrtl .Input (bitwidth = 1 )
375+ outwire = pyrtl .Output (bitwidth = 1 )
376+ outwire2 = pyrtl .Output (bitwidth = 1 )
377+ tempwire = pyrtl .WireVector ()
378+ tempwire <<= ~ inwire
379+ outwire <<= ~ tempwire
380+ outwire2 <<= tempwire
381+ pyrtl .optimize ()
382+ block = pyrtl .working_block ()
383+ self .assert_num_net (4 , block )
384+ self .assert_num_wires (5 , block )
385+
386+ def test_multiple_double_invert_chains (self ):
387+ # _remove_double_inverts removes double inverts by chains,
388+ # so it is useful to make sure it can remove
389+ # double inverts from multiple chains
390+ inwire = pyrtl .Input (bitwidth = 1 )
391+ outwire = pyrtl .Output (bitwidth = 1 )
392+ outwire2 = pyrtl .Output (bitwidth = 1 )
393+ outwire <<= ~ (~ inwire )
394+ outwire2 <<= ~ (~ (~ (~ (inwire ))))
395+ pyrtl .optimize ()
396+ block = pyrtl .working_block ()
397+ self .assert_num_net (2 , block )
398+ self .assert_num_wires (3 , block )
319399
320400class TestConstFolding (NetWireNumTestCases ):
321401 def setUp (self ):
0 commit comments