-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminimize.sh
More file actions
executable file
·42 lines (31 loc) · 1.18 KB
/
minimize.sh
File metadata and controls
executable file
·42 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# minimizes an AIG
# uses aigtoaig and ABC
# exit on error
set -e
# break when pipe fails
set -o pipefail
INPUT=$1
echo "Minimizing $INPUT"
# temporary files
BASE_FILE=$(basename ${INPUT%.aag})
AIG_FILE=/tmp/$BASE_FILE.aig
MIN_AIG_FILE=/tmp/$BASE_FILE.min.aig
OUTPUT=/tmp/$BASE_FILE.min.aag
compress2rs="balance -l; resub -K 6 -l; rewrite -l; resub -K 6 -N 2; refactor -l; resub -K 8 -l; balance -l; resub -K 8 -N 2 -l; rewrite -l; resub -K 10 -l; rewrite -z -l; resub -K 10 -N 2 -l; balance -l; resub -K 12 -l; refactor -z -l; resub -K 12 -N 2 -l; balance -l; rewrite -z -l; balance -l"
drwsat2="drw; balance -l; drw; drf; ifraig -C 20; drw; balance -l; drw; drf"
lutpack="if -K 2; lutpack -S 3 -L 10 -z; strash"
commands="$lutpack;$compress2rs;$drwsat2"
aigtoaig $INPUT $AIG_FILE
echo -e "read_aiger $AIG_FILE\n$commands\nwrite_aiger -s $MIN_AIG_FILE" | ~/local/abc/abc >/dev/null
aigtoaig $MIN_AIG_FILE $OUTPUT
and_old=$(head -n 1 $INPUT | cut -d' ' -f6);
and_new=$(head -n 1 $OUTPUT | cut -d' ' -f6);
if [ $and_new -lt $and_old ]; then
echo "Minimized $INPUT from $and_old to $and_new";
cp $OUTPUT $INPUT
fi
# clean temporary files
rm $AIG_FILE
rm $MIN_AIG_FILE
rm $OUTPUT