mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-22 20:53:44 +02:00
9cafe23fb8
We now generate the operator map algorithmically, which is a bit less classy than solving the logical equations, but easier to get right. Also renamed the somewhat vague "redundant" to "unreachable".
72 lines
1.5 KiB
Raku
Executable File
72 lines
1.5 KiB
Raku
Executable File
#!/usr/bin/perl
|
|
#
|
|
# genredmap.pl - Redundacy detector map generator
|
|
#
|
|
# Copyright 2012 by Werner Almesberger
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
|
|
#
|
|
# This script finds the relational operators op = f(opa, opb), for which
|
|
# the following is true:
|
|
#
|
|
# forall A, B: (A op B) -> forall X: !(X opa A) -> !(X opa B)
|
|
#
|
|
# In other words: if, with X a variable and A and B constants, we have a
|
|
# cascade of the form
|
|
#
|
|
# if (X opa A) ...;
|
|
# else if (X opa B) ...;
|
|
#
|
|
# and A op B is true, then the second branch will never be taken.
|
|
#
|
|
|
|
%op = (
|
|
"lt" => sub { $_[0] < $_[1] },
|
|
"le" => sub { $_[0] <= $_[1] },
|
|
"eq" => sub { $_[0] == $_[1] },
|
|
"ge" => sub { $_[0] >= $_[1] },
|
|
"gt" => sub { $_[0] > $_[1] },
|
|
|
|
);
|
|
|
|
@ops = ("lt", "le", "eq", "ge", "gt");
|
|
|
|
$always = 0;
|
|
|
|
$a = 2;
|
|
@v = (0, 1, 2, 3, 4);
|
|
|
|
for $opa (@ops) {
|
|
#next unless $opa eq "lt";
|
|
for $opb (@ops) {
|
|
#next unless $opb eq "lt";
|
|
$best = 0;
|
|
OP: for $op (@ops) {
|
|
$hit = 0;
|
|
for $b (@v) {
|
|
#print "($opa, $opb) $a $op $b\n";
|
|
next unless $op{$op}->($a, $b);
|
|
for $x (@v) {
|
|
#print " A: $x $opa $a\n";
|
|
next if $op{$opa}->($x, $a);
|
|
#print " B: $x $opb $b\n";
|
|
next OP
|
|
if $op{$opb}->($x, $b) != $always;
|
|
$hit++;
|
|
#print " HIT ($hit)\n";
|
|
}
|
|
}
|
|
if ($hit > $best) {
|
|
$best = $hit;
|
|
$best_op = $op;
|
|
}
|
|
}
|
|
print "\t[idx_$opa][idx_$opb] = rel_$best_op,\n" if $best;
|
|
}
|
|
}
|