fixed a bug in subcircuit library with cells that have connections to itself
[yosys.git] / libs / subcircuit / test_perm.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 # let "macc" implement a function like Y = (A*B) + (C*D)
6 #
7 # the following permutations of the input pins exist:
8 #
9 # g01 | A B C D | match
10 # g02 | A B D C | match
11 # g03 | A C B D | not
12 # g04 | A C D B | not
13 # g05 | A D B C | not
14 # g06 | A D C B | not
15 # g07 | B A C D | match
16 # g08 | B A D C | match
17 # g09 | B C A D | not
18 # g10 | B C D A | not
19 # g11 | B D A C | not
20 # g12 | B D C A | not
21 # g13 | C A B D | not
22 # g14 | C A D B | not
23 # g15 | C B A D | not
24 # g16 | C B D A | not
25 # g17 | C D A B | match
26 # g18 | C D B A | match
27 # g19 | D A B C | not
28 # g20 | D A C B | not
29 # g21 | D B A C | not
30 # g22 | D B C A | not
31 # g23 | D C A B | match
32 # g24 | D C B A | match
33
34 my @matches = qw/g01 g02 g07 g08 g17 g18 g23 g24/;
35 my @non_matches = qw/g03 g04 g05 g06 g09 g10 g11 g12 g13 g14 g15 g16 g19 g20 g21 g22/;
36
37 print "\n";
38
39 for my $i (0..3) {
40 for my $j (0..2) {
41 for my $k (0..1) {
42 my @t = qw/A B C D/;
43 print "# ";
44 print splice(@t,$i,1),splice(@t,$j,1),splice(@t,$k,1),$t[0];
45 print "\n";
46 }}}
47
48 print "\n";
49
50 my $iter = 1;
51 for my $i (0..3) {
52 for my $j (0..2) {
53 for my $k (0..1) {
54 my @t = qw/A B C D/;
55 printf "graph g%02d\n", $iter++;
56 printf " node input input A 32 1 B 32 1 C 32 1 D 32 1\n";
57 printf " node macc macc A 32 1 B 32 1 C 32 1 D 32 1\n";
58 printf " connect input A macc %s\n", splice(@t,$i,1);
59 printf " connect input B macc %s\n", splice(@t,$j,1);
60 printf " connect input C macc %s\n", splice(@t,$k,1);
61 printf " connect input D macc %s\n", splice(@t,0,1);
62 printf "endgraph\n";
63 printf "\n";
64 }}}
65
66 $iter = 1;
67 printf "graph gXL\n";
68 for my $i (0..3) {
69 for my $j (0..2) {
70 for my $k (0..1) {
71 my $id = sprintf "_%02d", $iter++;
72 my @t = qw/A B C D/;
73 printf " node input$id input A 16 B 16 C 16 D 16\n";
74 printf " node macc$id macc A 16 B 16 C 16 D 16\n";
75 printf " connect input$id A macc$id %s\n", splice(@t,$i,1);
76 printf " connect input$id B macc$id %s\n", splice(@t,$j,1);
77 printf " connect input$id C macc$id %s\n", splice(@t,$k,1);
78 printf " connect input$id D macc$id %s\n", splice(@t,0,1);
79 }}}
80 printf "endgraph\n";
81 printf "\n";
82
83
84 printf "swapgroup macc A B\n";
85 printf "swapgroup macc C D\n";
86 printf "swapperm macc A B C D : C D A B\n";
87
88 for my $i (@matches) {
89 for my $j (@non_matches) {
90 printf "solve %s %s\n", $i, $j;
91 }}
92 printf "expect 0\n\n";
93
94 for my $i (@matches) {
95 for my $j (@matches) {
96 printf "solve %s %s\n", $i, $j;
97 }}
98 printf "expect %d\n\n", @matches*@matches;
99
100 printf "solve g01 gXL false\n";
101 printf "expect 8\n";
102
103 printf "solve g03 gXL false\n";
104 printf "expect 8\n";
105
106 printf "solve g04 gXL false\n";
107 printf "expect 8\n";
108