├── .DS_Store ├── README.md ├── abs_diff ├── .DS_Store ├── abs_diff.v ├── abs_diff_approx.v ├── abs_diff_qor.py └── abs_diff_test.v ├── adder32 ├── adder32.v ├── adder32_approx.v ├── adder32_qor.py └── adder32_test.v ├── buttfly ├── buttfly.v ├── buttfly_approx.v ├── buttfly_qor.py └── buttfly_test.v ├── classifier ├── classifier.v ├── classifier_approx.v ├── classifier_qor.py ├── classifier_test.v ├── init_alpha.txt ├── init_input.txt └── init_weight.txt ├── fft ├── fft.v ├── fft_approx.v ├── fft_qor.py ├── fft_test.v └── infft.txt ├── mac ├── mac.v ├── mac_approx.v ├── mac_qor.py └── mac_test.v ├── mult16 ├── mult16.v ├── mult16_approx.v ├── mult16_qor.py └── mult16_test.v ├── mult8 ├── mult8.v ├── mult8_approx.v ├── mult8u_qor.py └── mult8u_test.v ├── regression_test └── x2 ├── x2.v ├── x2_approx.v ├── x2_qor.py └── x2_test.v /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scale-lab/BACS/7b4279019a15caef2b678e0237e5e26aaa13790c/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BACS: Benchmarks for Approximate Circuit Synthesis (version 1.0) 2 | 3 | These benchmarks are released as part of the following accepted publication. 4 | 5 | I. Scarabottolo, G. Ansaloni, G. A. Constantinides, L. Pozzi and S. Reda "Approximate Logic Synthesis: A Survey" **under-review** in Proceedings of the IEEE. 6 | 7 | The included benchmarks are 8 | 9 | - **x2:** small benchmark from LGSynth 91. Metric: Hamming Distance (HD). Approximate design generated using BLASYS. 10 | - **mac:** multiply-add arithmetic circuit. Approximate design generated using BLASYS. 11 | - **buttfly:** butterfly structure. Metric: Mean Absolute Error (MAE). Approximate design is same as exact. 12 | - **abs_diff:** absolute difference arithmetic circuit. Metric: Mean Absolute Error (MAE). Approximate design is generated using Circuit Carving (CC) technique. 13 | - **mult16:** 16-bit unsigned multiplier. Metric: Mean Absolute Error (MAE). Approximate design generatered using DRUM. 14 | - **mult8:** 8-bit unsigned multiplier. Metric: Mean Absolute Error (MAE). Approximate design generatered using EvoApproxLib. 15 | - **adder32:** 32-bit adder. Metric: Mean Absolute Error (MAE). Approximate design generatered manually. 16 | - **fft:** 8-point fast fourier transform sequential circuit from ABACUS release. Metric: Mean Square Error (MSE). Approximate design generated using ABACUS. 17 | - **classifier:** A support vector machine classifier sequential circuit from ABACUS release. Metric: misclassified labels (%). Approximate design generated using ABACUS. 18 | 19 | 20 | Each benchmark circuit comes in its own folder with four files: 21 | 22 | - bench/bench.v original design in Verilog 23 | - bench/bench_test.v testbench for the design in Verilog 24 | - bench/bench_approx.v an example of an approximate design for the original design 25 | - bench/bench_qor.py a python function to evaluate QoR results of approximate design against original design 26 | 27 | **Requirements:** 28 | - iverilog for simulation 29 | - Python3 30 | 31 | 32 | **Usage:** 33 | To produce the accurate results for each benchmark: 34 | 35 | iverilog bench_test.v bench.v 36 | 37 | ./a.out > res_accurate 38 | 39 | To produce the approximate results for each benchmark: 40 | 41 | iverilog bench_test.v bench_approx.v 42 | 43 | ./a.out > res_approx 44 | 45 | To compare the results: 46 | 47 | python3 ./bench_qor res_accurate res_approx 48 | 49 | regression_test is a test script that sweeps across all benchmarks. 50 | 51 | -------------------------------------------------------------------------------- /abs_diff/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scale-lab/BACS/7b4279019a15caef2b678e0237e5e26aaa13790c/abs_diff/.DS_Store -------------------------------------------------------------------------------- /abs_diff/abs_diff.v: -------------------------------------------------------------------------------- 1 | 2 | module abs_diff(in_0, in_1, res); 3 | wire _000_; 4 | wire _001_; 5 | wire _002_; 6 | wire _003_; 7 | wire _004_; 8 | wire _005_; 9 | wire _006_; 10 | wire _007_; 11 | wire _008_; 12 | wire _009_; 13 | wire _010_; 14 | wire _011_; 15 | wire _012_; 16 | wire _013_; 17 | wire _014_; 18 | wire _015_; 19 | wire _016_; 20 | wire _017_; 21 | wire _018_; 22 | wire _019_; 23 | wire _020_; 24 | wire _021_; 25 | wire _022_; 26 | wire _023_; 27 | wire _024_; 28 | wire _025_; 29 | wire _026_; 30 | wire _027_; 31 | wire _028_; 32 | wire _029_; 33 | wire _030_; 34 | wire _031_; 35 | wire _032_; 36 | wire _033_; 37 | wire _034_; 38 | wire _035_; 39 | wire _036_; 40 | wire _037_; 41 | wire _038_; 42 | wire _039_; 43 | wire _040_; 44 | wire _041_; 45 | wire _042_; 46 | wire _043_; 47 | wire _044_; 48 | wire _045_; 49 | wire _046_; 50 | wire _047_; 51 | wire _048_; 52 | wire _049_; 53 | wire _050_; 54 | wire _051_; 55 | wire _052_; 56 | wire _053_; 57 | wire _054_; 58 | wire _055_; 59 | wire _056_; 60 | wire _057_; 61 | wire _058_; 62 | wire _059_; 63 | wire _060_; 64 | wire _061_; 65 | wire _062_; 66 | wire _063_; 67 | wire _064_; 68 | wire _065_; 69 | wire _066_; 70 | wire _067_; 71 | wire _068_; 72 | wire _069_; 73 | wire _070_; 74 | wire _071_; 75 | wire _072_; 76 | wire _073_; 77 | wire _074_; 78 | wire _075_; 79 | wire _076_; 80 | wire _077_; 81 | wire \U42.O ; 82 | wire \U45.O ; 83 | wire \U48.O ; 84 | wire \U51.O ; 85 | wire \U54.O ; 86 | wire \U57.O ; 87 | wire \U60.O ; 88 | wire \U63.O ; 89 | wire \U64.O ; 90 | input [7:0] in_0; 91 | input [7:0] in_1; 92 | output [8:0] res; 93 | wire \sub_19/U129.I ; 94 | wire \sub_19/U130.I1 ; 95 | wire \sub_19/U131.I ; 96 | wire \sub_19/U133.I2 ; 97 | wire \sub_19/U134.I2 ; 98 | wire \sub_19/U135.I2 ; 99 | wire \sub_19/U136.I ; 100 | wire \sub_19/U137.I2 ; 101 | wire \sub_19/U138.I ; 102 | wire \sub_19/U139.I2 ; 103 | wire \sub_19/U140.I2 ; 104 | wire \sub_19/U141.I ; 105 | wire \sub_19/U142.I2 ; 106 | wire \sub_19/U143.I ; 107 | wire \sub_19/U144.I2 ; 108 | wire \sub_19/U146.I ; 109 | wire \sub_19/U150.I ; 110 | wire \sub_19/U151.I ; 111 | wire \sub_19/U152.I ; 112 | wire \sub_19/U153.I ; 113 | wire \sub_19/U154.I ; 114 | wire \sub_19/U155.I ; 115 | wire \sub_19/U156.I ; 116 | wire \sub_19/U230.I1 ; 117 | wire \sub_19/U231.I ; 118 | wire \sub_19/U232.I1 ; 119 | wire \sub_19/U233.I ; 120 | wire \sub_19/U50.I2 ; 121 | wire \sub_19/U60.I1 ; 122 | wire \sub_19/U73.I1 ; 123 | wire \sub_19/U74.I2 ; 124 | wire \sub_19/U80.I1 ; 125 | wire \sub_19/U81.I2 ; 126 | wire \sub_19/U84.I1 ; 127 | wire \sub_19/U85.I2 ; 128 | wire \sub_19/U90.I2 ; 129 | wire \sub_19/U93.I1 ; 130 | wire \sub_19/U99.I2 ; 131 | assign _012_ = in_0[2] | ~(in_1[2]); 132 | assign _013_ = in_0[3] | ~(in_1[3]); 133 | assign _014_ = ~(_013_ & _012_); 134 | assign _015_ = in_0[2] & ~(in_1[2]); 135 | assign _016_ = in_0[3] & ~(in_1[3]); 136 | assign _017_ = ~((_015_ & _013_) | _016_); 137 | assign _018_ = in_0[1] | ~(in_1[1]); 138 | assign _019_ = in_0[0] | ~(in_1[0]); 139 | assign _020_ = in_0[1] & ~(in_1[1]); 140 | assign _021_ = ~((_019_ & _018_) | _020_); 141 | assign _022_ = ~((_021_ | _014_) & _017_); 142 | assign _023_ = in_0[6] | ~(in_1[6]); 143 | assign _024_ = in_0[7] & ~(in_1[7]); 144 | assign _025_ = _023_ & ~(_024_); 145 | assign _026_ = in_0[5] | ~(in_1[5]); 146 | assign _027_ = in_0[4] | ~(in_1[4]); 147 | assign _028_ = ~(_027_ & _026_); 148 | assign _029_ = _025_ & ~(_028_); 149 | assign _030_ = ~(_029_ & _022_); 150 | assign _031_ = ~_025_; 151 | assign _032_ = ~_024_; 152 | assign _033_ = in_1[7] & ~(in_0[7]); 153 | assign _034_ = in_0[6] & ~(in_1[6]); 154 | assign _035_ = ~((_034_ & _032_) | _033_); 155 | assign _036_ = in_0[4] & ~(in_1[4]); 156 | assign _037_ = in_0[5] & ~(in_1[5]); 157 | assign _038_ = ~((_036_ & _026_) | _037_); 158 | assign _039_ = ~((_038_ | _031_) & _035_); 159 | assign _040_ = _030_ & ~(_039_); 160 | assign \U42.O = in_0[0] ^ in_1[0]; 161 | assign _041_ = _018_ & ~(_020_); 162 | assign _042_ = _041_ ^ _019_; 163 | assign _043_ = _042_ ^ \U42.O ; 164 | assign \U45.O = _040_ ? _043_ : _042_; 165 | assign _044_ = in_1[1] & ~(in_0[1]); 166 | assign _045_ = in_1[0] & ~(in_0[0]); 167 | assign _046_ = in_1[1] | ~(in_0[1]); 168 | assign _047_ = ~((_045_ | _044_) & _046_); 169 | assign _048_ = _012_ & ~(_015_); 170 | assign _049_ = _048_ ^ _047_; 171 | assign _050_ = _042_ | \U42.O ; 172 | assign _051_ = _050_ ^ _049_; 173 | assign \U48.O = _040_ ? _051_ : _049_; 174 | assign _052_ = ~((_047_ & _012_) | _015_); 175 | assign _053_ = _013_ & ~(_016_); 176 | assign _054_ = ~(_053_ ^ _052_); 177 | assign _055_ = _050_ | _049_; 178 | assign _056_ = _055_ ^ _054_; 179 | assign \U51.O = _040_ ? _056_ : _054_; 180 | assign _057_ = _027_ & ~(_036_); 181 | assign _058_ = _057_ ^ _022_; 182 | assign _059_ = _055_ | _054_; 183 | assign _060_ = _058_ ^ _059_; 184 | assign \U54.O = _040_ ? _060_ : _058_; 185 | assign _061_ = ~((_027_ & _022_) | _036_); 186 | assign _062_ = _026_ & ~(_037_); 187 | assign _063_ = ~(_062_ ^ _061_); 188 | assign _064_ = _058_ | _054_; 189 | assign _065_ = _064_ | _055_; 190 | assign _066_ = _065_ ^ _063_; 191 | assign \U57.O = _040_ ? _066_ : _063_; 192 | assign _067_ = in_1[3] & ~(in_0[3]); 193 | assign _068_ = _012_ & ~(_067_); 194 | assign _069_ = in_1[2] | ~(in_0[2]); 195 | assign _070_ = in_1[3] | ~(in_0[3]); 196 | assign _071_ = ~((_069_ | _067_) & _070_); 197 | assign _072_ = ~((_047_ & _068_) | _071_); 198 | assign _073_ = ~((_028_ | _072_) & _038_); 199 | assign _074_ = _023_ & ~(_034_); 200 | assign _075_ = _074_ ^ _073_; 201 | assign _076_ = _065_ | _063_; 202 | assign _077_ = _075_ ^ _076_; 203 | assign \U60.O = _040_ ? _077_ : _075_; 204 | assign _000_ = ~_023_; 205 | assign _001_ = ~_034_; 206 | assign _002_ = ~((_038_ | _000_) & _001_); 207 | assign _003_ = _023_ & ~(_028_); 208 | assign _004_ = ~((_003_ & _022_) | _002_); 209 | assign _005_ = ~(_033_ | _024_); 210 | assign _006_ = ~(_005_ ^ _004_); 211 | assign _007_ = _075_ | _063_; 212 | assign _008_ = _007_ | _065_; 213 | assign _009_ = _008_ ^ _006_; 214 | assign \U63.O = _040_ ? _009_ : _006_; 215 | assign _010_ = _006_ | _065_; 216 | assign _011_ = _010_ | _007_; 217 | assign \U64.O = _040_ & ~(_011_); 218 | assign \sub_19/U90.I2 = in_0[3]; 219 | assign \sub_19/U80.I1 = in_0[5]; 220 | assign \sub_19/U156.I = in_1[6]; 221 | assign \sub_19/U155.I = in_1[5]; 222 | assign \sub_19/U154.I = in_1[4]; 223 | assign \sub_19/U153.I = in_1[3]; 224 | assign \sub_19/U152.I = in_1[2]; 225 | assign \sub_19/U151.I = in_1[1]; 226 | assign \sub_19/U150.I = in_0[7]; 227 | assign \sub_19/U74.I2 = in_0[6]; 228 | assign \sub_19/U85.I2 = in_0[4]; 229 | assign \sub_19/U146.I = in_0[0]; 230 | assign \sub_19/U81.I2 = in_0[5]; 231 | assign \sub_19/U144.I2 = in_1[0]; 232 | assign \sub_19/U143.I = in_0[3]; 233 | assign \sub_19/U142.I2 = in_1[3]; 234 | assign \sub_19/U141.I = in_0[1]; 235 | assign \sub_19/U140.I2 = in_1[1]; 236 | assign \sub_19/U93.I1 = in_0[2]; 237 | assign \sub_19/U139.I2 = in_1[0]; 238 | assign \sub_19/U138.I = in_1[2]; 239 | assign \sub_19/U233.I = in_1[0]; 240 | assign \sub_19/U137.I2 = in_0[2]; 241 | assign \sub_19/U136.I = in_0[1]; 242 | assign \sub_19/U135.I2 = in_1[1]; 243 | assign \sub_19/U134.I2 = in_1[3]; 244 | assign \sub_19/U133.I2 = in_1[3]; 245 | assign \sub_19/U60.I1 = in_1[7]; 246 | assign \sub_19/U131.I = in_0[2]; 247 | assign \sub_19/U130.I1 = in_1[2]; 248 | assign \sub_19/U129.I = in_0[3]; 249 | assign \sub_19/U232.I1 = in_0[0]; 250 | assign \sub_19/U84.I1 = in_0[4]; 251 | assign \sub_19/U99.I2 = in_0[1]; 252 | assign res = { \U64.O , \U63.O , \U60.O , \U57.O , \U54.O , \U51.O , \U48.O , \U45.O , \U42.O }; 253 | assign \sub_19/U231.I = in_0[0]; 254 | assign \sub_19/U50.I2 = in_1[7]; 255 | assign \sub_19/U73.I1 = in_0[6]; 256 | assign \sub_19/U230.I1 = in_1[0]; 257 | endmodule 258 | -------------------------------------------------------------------------------- /abs_diff/abs_diff_approx.v: -------------------------------------------------------------------------------- 1 | module abs_diff ( 2 | a, b, r); 3 | input [7:0] a; 4 | input [7:0] b; 5 | output [8:0] r; 6 | 7 | circuit DUT( 8 | .g0(a[7]), 9 | .g1(a[6]), 10 | .g2(a[5]), 11 | .g3(a[4]), 12 | .g4(a[3]), 13 | .g5(a[2]), 14 | .g6(a[1]), 15 | .g7(a[0]), 16 | 17 | .g8(b[7]), 18 | .g9(b[6]), 19 | .g10(b[5]), 20 | .g11(b[4]), 21 | .g12(b[3]), 22 | .g13(b[2]), 23 | .g14(b[1]), 24 | .g15(b[0]), 25 | 26 | .g253(r[8]), 27 | .g252(r[7]), 28 | .g251(r[6]), 29 | .g250(r[5]), 30 | .g249(r[4]), 31 | .g248(r[3]), 32 | .g247(r[2]), 33 | .g246(r[1]), 34 | .g245(r[0]) 35 | ); 36 | 37 | endmodule 38 | 39 | 40 | 41 | // Benchmark "circuit" written by ABC on Thu Apr 23 17:40:54 2020 42 | 43 | module circuit ( 44 | g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15, 45 | g253, g252, g251, g250, g249, g248, g247, g246, g245 ); 46 | input g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, 47 | g15; 48 | output g253, g252, g251, g250, g249, g248, g247, g246, g245; 49 | wire g16, g17, g18, g19, g20, g21, g22, g23, g24, g25, g26, g27, g28, g29, 50 | g30, g31, g32, g33, g34, g35, g36, g37, g38, g39, g40, g41, g42, g43, 51 | g44, g45, g46, g47, g48, g49, g50, g51, g52, g53, g54, g55, g56, g57, 52 | g58, g59, g60, g61, g62, g63, g64, g65, g66, g67, g68, g69, g70, g71, 53 | g72, g73, g74, g75, g76, g77, g78, g79, g80, g81, g82, g83, g84, g85, 54 | g86, g87, g88, g89, g90, g91, g92, g93, g94, g95, g96, g97, g98, g99, 55 | g100, g101, g102, g103, g104, g105, g106, g107, g108, g109, g110, g111, 56 | g112, g113, g114, g115, g116, g121, g122, g123, g124, g125, g126, g127, 57 | g128, g129, g130, g131, g132, g133, g134, g135, g136, g137, g138, g139, 58 | g140, g141, g142, g143, g149, g150, g151, g152, g153, g154, g155, g156, 59 | g157, g158, g159, g160, g161, g162, g163, g164, g165, g166, g167, g168, 60 | g170, g171, g172, g173, g174, g176, g178, g179, g180, g181, g182, g184, 61 | g191, g192, g193, g194, g195, g199, g200, g201, g202, g203, g204, g205, 62 | g206, g207, g209, g210, g212, g214, g215, g216, g217, g218, g219, g220, 63 | g222, g223, g224, g228, g229, g230, g235, g240, g241, g242, g243, \0 ; 64 | assign g16 = ~g15; 65 | assign g17 = ~g7 | ~g16; 66 | assign g18 = ~g7; 67 | assign g19 = ~g15 | ~g18; 68 | assign g20 = ~g17 | ~g19; 69 | assign g21 = ~g9; 70 | assign g22 = ~g10; 71 | assign g23 = ~g11; 72 | assign g24 = ~g12; 73 | assign g25 = ~g13; 74 | assign g26 = ~g14; 75 | assign g27 = ~g0; 76 | assign g28 = ~g7; 77 | assign g29 = ~g15 | ~g28; 78 | assign g30 = ~g4; 79 | assign g31 = ~g12 | ~g30; 80 | assign g32 = ~g6; 81 | assign g33 = ~g15 | ~g18; 82 | assign g34 = ~g13; 83 | assign g35 = ~g5 | ~g34; 84 | assign g36 = ~g6; 85 | assign g37 = ~g14 | ~g32; 86 | assign g38 = ~g12 | ~g30; 87 | assign g39 = ~g5; 88 | assign g40 = ~g13 & ~g39; 89 | assign g41 = ~g4; 90 | assign g42 = ~g6 | ~g26; 91 | assign g43 = ~g37 | ~g42; 92 | assign g44 = ~g5 & ~g25; 93 | assign g45 = ~g4 | ~g24; 94 | assign g46 = ~g3 | ~g23; 95 | assign g47 = ~g3 & ~g23; 96 | assign g48 = ~g2 | ~g22; 97 | assign g49 = ~g2 & ~g22; 98 | assign g50 = ~g47 & ~g49; 99 | assign g51 = ~g1 | ~g21; 100 | assign g52 = ~g1 & ~g21; 101 | assign g53 = ~g8 | ~g27; 102 | assign g54 = ~g8 & ~g27; 103 | assign g55 = ~g52 & ~g54; 104 | assign g56 = ~g50 | ~g55; 105 | assign g57 = ~g20; 106 | assign g58 = ~g33 | ~g43; 107 | assign g59 = ~g43; 108 | assign g60 = ~g44; 109 | assign g61 = ~g31 | ~g40; 110 | assign g62 = ~g45 | ~g61; 111 | assign g63 = ~g62; 112 | assign g64 = ~g47; 113 | assign g65 = ~g49; 114 | assign g66 = ~g46; 115 | assign g67 = ~g65 | ~g66; 116 | assign g68 = ~g48 | ~g67; 117 | assign g69 = ~g68; 118 | assign g70 = ~g51 | ~g52; 119 | assign g71 = ~g54; 120 | assign g72 = ~g51; 121 | assign g73 = ~g71 | ~g72; 122 | assign g74 = ~g53 | ~g73; 123 | assign g75 = ~g74; 124 | assign g76 = ~g55; 125 | assign g77 = ~g75 | ~g76; 126 | assign g78 = ~g69 | ~g75; 127 | assign g79 = ~g77 | ~g78; 128 | assign g80 = ~g56; 129 | assign g81 = ~g52; 130 | assign g82 = ~g33; 131 | assign g83 = ~g14 | ~g36; 132 | assign g84 = ~g12 | ~g41; 133 | assign g85 = ~g29 | ~g83; 134 | assign g86 = ~g51 | ~g69; 135 | assign g87 = ~g38 | ~g60; 136 | assign g88 = ~g35 | ~g60; 137 | assign g89 = ~g45 | ~g84; 138 | assign g90 = ~g46 | ~g64; 139 | assign g91 = ~g48 | ~g65; 140 | assign g92 = ~g51 | ~g81; 141 | assign g93 = ~g50 | ~g81; 142 | assign g94 = ~g53 | ~g71; 143 | assign g95 = ~g59 | ~g82; 144 | assign g96 = ~g58 | ~g95; 145 | assign g97 = ~g29 | ~g83; 146 | assign g98 = ~g42 | ~g85; 147 | assign g99 = ~g98; 148 | assign g100 = ~g88; 149 | assign g101 = ~g89; 150 | assign g102 = ~g63 | ~g99; 151 | assign g103 = ~g63 | ~g87; 152 | assign g104 = ~g102 | ~g103; 153 | assign g105 = ~g90; 154 | assign g106 = ~g91; 155 | assign g107 = ~g92; 156 | assign g108 = ~g70 | ~g86; 157 | assign g109 = ~g93; 158 | assign g110 = ~g94; 159 | assign g111 = ~g102 | ~g103; 160 | assign g112 = ~g42 | ~g97; 161 | assign g113 = ~g104; 162 | assign g114 = ~g112; 163 | assign g115 = ~g104; 164 | assign g116 = ~g96; 165 | assign g121 = ~g57 | ~g116; 166 | assign g122 = ~g100 | ~g114; 167 | assign g123 = ~g88 | ~g112; 168 | assign g124 = ~g122 | ~g123; 169 | assign g125 = ~g60 | ~g112; 170 | assign g126 = ~g35 | ~g125; 171 | assign g127 = ~g126; 172 | assign g128 = ~g101 | ~g127; 173 | assign g129 = ~g89 | ~g126; 174 | assign g130 = ~g128 | ~g129; 175 | assign g131 = ~g105 | ~g115; 176 | assign g132 = ~g90 | ~g111; 177 | assign g133 = ~g131 | ~g132; 178 | assign g134 = ~g133; 179 | assign g135 = ~g64 | ~g113; 180 | assign g136 = ~g46 | ~g135; 181 | assign g137 = ~g136; 182 | assign g138 = ~g106 | ~g137; 183 | assign g139 = ~g91 | ~g136; 184 | assign g140 = ~g138 | ~g139; 185 | assign g141 = ~g50 | ~g113; 186 | assign g142 = ~g111; 187 | assign g143 = ~g69 | ~g141; 188 | assign g149 = ~g130; 189 | assign g150 = ~g134; 190 | assign g151 = ~g140; 191 | assign g152 = ~g149; 192 | assign g153 = ~g150; 193 | assign g154 = ~g121 & ~g124; 194 | assign g155 = ~g130 & ~g134; 195 | assign g156 = ~g154 | ~g155; 196 | assign g157 = ~g92 | ~g143; 197 | assign g158 = ~g109 | ~g142; 198 | assign g159 = ~g108 | ~g158; 199 | assign g160 = ~g159; 200 | assign g161 = ~g110 | ~g160; 201 | assign g162 = ~g94 | ~g159; 202 | assign g163 = ~g161 | ~g162; 203 | assign g164 = ~g80 | ~g142; 204 | assign g165 = ~g79 | ~g164; 205 | assign g166 = ~g165; 206 | assign g167 = ~g143; 207 | assign g168 = ~g154; 208 | assign g170 = ~g156; 209 | assign g171 = ~g163; 210 | assign g172 = ~g156; 211 | assign g173 = ~g151; 212 | assign g174 = ~g170; 213 | assign g176 = ~g151 | ~g170; 214 | assign g178 = ~g152 & ~g168; 215 | assign g179 = ~g166; 216 | assign g180 = ~g179; 217 | assign g181 = ~g179; 218 | assign g182 = ~g179; 219 | assign g184 = ~g182; 220 | assign g191 = ~g134 | ~g184; 221 | assign g192 = ~g140 | ~g184; 222 | assign g193 = ~g163 | ~g184; 223 | assign g194 = ~g107 | ~g167; 224 | assign g195 = ~g157 | ~g194; 225 | assign g199 = ~g178; 226 | assign g200 = ~g153 | ~g199; 227 | assign g201 = ~g150 | ~g178; 228 | assign g202 = ~g200 | ~g201; 229 | assign g203 = ~g202; 230 | assign g204 = ~g170 | ~g173; 231 | assign g205 = ~g151 | ~g174; 232 | assign g206 = ~g204 | ~g205; 233 | assign g207 = ~g195; 234 | assign g209 = ~g207; 235 | assign g210 = ~g176; 236 | assign g212 = ~g140 & ~g195; 237 | assign g214 = ~g181 | ~g203; 238 | assign g215 = ~g180 | ~g206; 239 | assign g216 = ~g184 | ~g195; 240 | assign g217 = ~g176 | ~g209; 241 | assign g218 = ~g207 | ~g210; 242 | assign g219 = ~g217 | ~g218; 243 | assign g220 = ~g219; 244 | assign g222 = ~g172 | ~g212; 245 | assign g223 = ~g180 | ~g220; 246 | assign g224 = ~g163 | ~g222; 247 | assign g228 = ~g171 | ~\0 ; 248 | assign g229 = ~g224 | ~g228; 249 | assign g230 = ~g229; 250 | assign g235 = ~g181 | ~g230; 251 | assign g240 = ~g191 | ~g214; 252 | assign g241 = ~g192 | ~g215; 253 | assign g242 = ~g216 | ~g223; 254 | assign g243 = ~g193 | ~g235; 255 | assign g245 = \0 ; 256 | assign g246 = \0 ; 257 | assign g247 = \0 ; 258 | assign g248 = \0 ; 259 | assign g249 = g240; 260 | assign g250 = g241; 261 | assign g251 = g242; 262 | assign g252 = g243; 263 | assign g253 = \0 ; 264 | assign \0 = 1'b0; 265 | endmodule 266 | 267 | 268 | -------------------------------------------------------------------------------- /abs_diff/abs_diff_qor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import math 4 | import numpy 5 | import sys 6 | 7 | def dataCompare(Groundtruth, Modified): 8 | if (os.path.exists(Modified)): 9 | data = open(Modified) 10 | Modified_data = data.readlines() 11 | if (os.path.exists(Groundtruth)): 12 | data = open(Groundtruth) 13 | Ground_truth = data.readlines() 14 | L = min (len(Modified_data), len(Ground_truth)) 15 | temp = 0 16 | for i in range(0, L): 17 | temp = temp + abs(float(Modified_data[i-1]) - float(Ground_truth[i-1]))/(2**8-1) 18 | print('MAE %', 100*temp/L) 19 | return temp/L 20 | 21 | dataCompare(sys.argv[1], sys.argv[2]) 22 | -------------------------------------------------------------------------------- /abs_diff/abs_diff_test.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns/1ps 2 | module bench_tb(); 3 | 4 | parameter PERIOD = 1; 5 | parameter INPUT_SIZE = 1000; 6 | 7 | parameter INPUT_WIDTH = 8; 8 | parameter OUTPUT_WIDTH = 9; 9 | 10 | integer i,f, seed; 11 | 12 | reg [INPUT_WIDTH-1:0] a, b; 13 | wire [OUTPUT_WIDTH-1:0] r; 14 | 15 | abs_diff DUT (.in_0(a),.in_1(b),.res(r)); 16 | 17 | initial 18 | begin 19 | seed = 0; 20 | a = 0; 21 | b = 0; 22 | #(PERIOD/2); 23 | 24 | for(i=0; i= thresh): 79 | print ("fail") 80 | return 81 | fft_accuracy = 100 - fft_mse 82 | return fft_accuracy 83 | 84 | FFT_QOR(sys.argv[1], sys.argv[2]) 85 | #print(qor) 86 | -------------------------------------------------------------------------------- /fft/fft_test.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns/1ps 2 | 3 | module filetest; 4 | parameter LEN=8; 5 | reg enable,wt, clk; 6 | integer j,f; 7 | reg signed[LEN*32-1:0] d; 8 | wire signed[LEN*32-1:0] dataout; 9 | reg signed[31:0]data[0:LEN-1]; 10 | 11 | always #(10) clk = ~clk; 12 | 13 | initial begin 14 | #0 enable = 0; 15 | #0 wt = 0; 16 | #0 clk = 0; 17 | $readmemh("infft.txt",data); 18 | 19 | for (j = 0; j < LEN; j = j+1) begin 20 | d[32*j+:32]=data[j]; 21 | end 22 | 23 | #20 enable = 1; 24 | #200 wt = 1; 25 | #10 26 | $finish; 27 | end 28 | 29 | fft DUT(clk, enable,d,dataout); 30 | 31 | reg signed[15:0]datr[LEN-1:0]; 32 | reg signed[15:0]dati[LEN-1:0]; 33 | 34 | always@(posedge wt) begin 35 | for (j = 0; j 5)?k1-5:0; 51 | assign q=(k2>5)?k2-5:0; 52 | assign mm=(k1>5)?({1'b1,m,1'b1}):a[5:0]; 53 | assign nn=(k2>5)?({1'b1,n,1'b1}):b[5:0]; 54 | assign tmp=mm*nn; 55 | assign sum=p+q; 56 | 57 | Barrel_Shifter u7(.in_a(tmp), .count(sum), .out_a(r)); 58 | 59 | endmodule 60 | //------------------------------------------------------------ 61 | module LOD (in_a, out_a); 62 | input [15:0]in_a; 63 | output reg [15:0]out_a; 64 | 65 | integer k,j; 66 | reg [15:0]w; 67 | 68 | always @(*) 69 | begin 70 | out_a[15]=in_a[15]; 71 | w[15]=in_a[15]?0:1; 72 | for (k=14;k>=0;k=k-1) 73 | begin 74 | w[k]=in_a[k]?0:w[k+1]; 75 | out_a[k]=w[k+1]&in_a[k]; 76 | end 77 | end 78 | 79 | endmodule 80 | //-------------------------------- 81 | module P_Encoder (in_a, out_a); 82 | input [15:0]in_a; 83 | output reg [3:0]out_a; 84 | 85 | always @(*) 86 | begin 87 | case(in_a) 88 | 16'h0001: out_a=4'h0; 89 | 16'h0002: out_a=4'h1; 90 | 16'h0004: out_a=4'h2; 91 | 16'h0008: out_a=4'h3; 92 | 16'h0010: out_a=4'h4; 93 | 16'h0020: out_a=4'h5; 94 | 16'h0040: out_a=4'h6; 95 | 16'h0080: out_a=4'h7; 96 | 16'h0100: out_a=4'h8; 97 | 16'h0200: out_a=4'h9; 98 | 16'h0400: out_a=4'ha; 99 | 16'h0800: out_a=4'hb; 100 | 16'h1000: out_a=4'hc; 101 | 16'h2000: out_a=4'hd; 102 | 16'h4000: out_a=4'he; 103 | 16'h8000: out_a=4'hf; 104 | default: out_a=4'h0; 105 | endcase 106 | end 107 | 108 | endmodule 109 | //-------------------------------- 110 | module Barrel_Shifter (in_a, count, out_a); 111 | input [4:0]count; 112 | input [11:0]in_a; 113 | output [31:0]out_a; 114 | 115 | assign out_a=(in_a< acc_res 8 | iverilog ${cir}_test.v ${cir}_approx.v 9 | ./a.out > approx_res 10 | python3 ${cir}_qor.py acc_res approx_res 11 | rm a.out 12 | rm *res* 13 | cd .. 14 | done 15 | -------------------------------------------------------------------------------- /x2/x2.v: -------------------------------------------------------------------------------- 1 | 2 | module x2(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q); 3 | input a, b, c, d, e, f, g, h, i, j; 4 | output k, l, m, n, o, p, q; 5 | wire 6 | \[7] , 7 | \[9] , 8 | \[0] , 9 | \[1] , 10 | \[2] , 11 | \[3] , 12 | \[4] , 13 | \[5] , 14 | \[6] ; 15 | assign 16 | \[7] = (j & (i & (~h & f))) | ~g, 17 | \[9] = b | a, 18 | \[0] = j | (~i | ~h), 19 | \[1] = (~j & h) | ((j & ~h) | i), 20 | k = \[0] , 21 | l = \[1] , 22 | m = \[2] , 23 | n = \[3] , 24 | o = \[4] , 25 | p = \[5] , 26 | q = \[6] , 27 | \[2] = ~j & (~i & ~h), 28 | \[3] = \[9] | (\[2] | (j | (h | c))), 29 | \[4] = (j & i) | (~h | ~g), 30 | \[5] = (~\[9] & (\[1] & (\[0] & (h & c)))) | ((~\[9] & (\[1] & (~i & c))) | ((~\[0] & (~e & d)) | ((~j & ~i) | \[7] ))), 31 | \[6] = (~\[9] & (\[4] & (h & ~c))) | ((~\[0] & (e & d)) | (\[7] | ~\[1] )); 32 | endmodule 33 | 34 | -------------------------------------------------------------------------------- /x2/x2_approx.v: -------------------------------------------------------------------------------- 1 | /* Generated by Yosys 0.8+634 (git sha1 3414ee1, clang 3.8.0-2ubuntu4 -fPIC -Os) */ 2 | 3 | module x2(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q); 4 | wire _00_; 5 | wire _01_; 6 | wire _02_; 7 | wire _03_; 8 | wire _04_; 9 | wire _05_; 10 | wire _06_; 11 | wire _07_; 12 | wire _08_; 13 | wire _09_; 14 | wire _10_; 15 | wire _11_; 16 | wire _12_; 17 | wire _13_; 18 | wire _14_; 19 | wire _15_; 20 | wire _16_; 21 | wire _17_; 22 | wire _18_; 23 | wire _19_; 24 | wire _20_; 25 | wire _21_; 26 | wire _22_; 27 | wire _23_; 28 | wire _24_; 29 | wire _25_; 30 | wire _26_; 31 | wire _27_; 32 | wire _28_; 33 | wire _29_; 34 | wire _30_; 35 | wire _31_; 36 | wire _32_; 37 | wire _33_; 38 | wire _34_; 39 | input a; 40 | input b; 41 | input c; 42 | input d; 43 | input e; 44 | input f; 45 | input g; 46 | input h; 47 | input i; 48 | input j; 49 | output k; 50 | output l; 51 | output m; 52 | output n; 53 | output o; 54 | output p; 55 | output q; 56 | assign _00_ = ~g; 57 | assign _01_ = ~j; 58 | assign _02_ = ~(d & e); 59 | assign _03_ = _01_ & ~(_02_); 60 | assign _04_ = j & f; 61 | assign _05_ = h ? _03_ : _04_; 62 | assign _06_ = ~(j ^ h); 63 | assign _07_ = i ? _05_ : _06_; 64 | assign _08_ = _07_ | _00_; 65 | assign _09_ = b | c; 66 | assign _10_ = _09_ | a; 67 | assign _11_ = _10_ | _01_; 68 | assign _12_ = h & ~(_11_); 69 | assign q = _12_ | _08_; 70 | assign _13_ = h | ~(j); 71 | assign _14_ = h & ~(j); 72 | assign _15_ = _14_ | ~(_13_); 73 | assign l = _15_ | i; 74 | assign _16_ = ~(b | a); 75 | assign _17_ = ~(_16_ & c); 76 | assign _18_ = j & ~(_17_); 77 | assign _19_ = ~(i ^ h); 78 | assign _20_ = ~i; 79 | assign _21_ = d & ~(e); 80 | assign _22_ = _21_ | _20_; 81 | assign _23_ = ~((_22_ & _14_) | (_19_ & _18_)); 82 | assign _24_ = g & ~(_23_); 83 | assign p = _24_ ^ q; 84 | assign _25_ = ~(_04_ | h); 85 | assign _26_ = ~c; 86 | assign _27_ = ~(j & h); 87 | assign _28_ = ~((_16_ & _26_) | _27_); 88 | assign _29_ = ~((_28_ | _25_) & i); 89 | assign _30_ = _13_ | i; 90 | assign _31_ = ~((_30_ & _29_) | _00_); 91 | assign o = _31_ ^ q; 92 | assign _32_ = ~(h & g); 93 | assign _33_ = _32_ | j; 94 | assign _34_ = _20_ & ~(_33_); 95 | assign k = _34_ ^ o; 96 | assign m = 1'h0; 97 | assign n = k; 98 | endmodule 99 | -------------------------------------------------------------------------------- /x2/x2_qor.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import sys 3 | 4 | def HD(original_path, approximate_path): 5 | with open(original_path, 'r') as fo: 6 | org = fo.readlines() 7 | with open(approximate_path, 'r') as fa: 8 | app = fa.readlines() 9 | 10 | org = [list(filter(lambda a: a != ' ', list(i[:-1]))) for i in org] 11 | app = [list(filter(lambda a: a != ' ', list(i[:-1]))) for i in app] 12 | 13 | if len(org) != len(app): 14 | print('ERROR! sizes of input files are not equal! Aborting...') 15 | return -1 16 | org = np.array(org) 17 | app = np.array(app) 18 | total = org.size 19 | HD = np.sum(org != app) 20 | return HD/total 21 | 22 | hd=HD(sys.argv[1], sys.argv[2]) 23 | print('HD % ',100*hd) 24 | --------------------------------------------------------------------------------