/* hunpack.c, (c) MPA 1995 */ #include "harp1.h" void main(chan(in) STDIN : 8, chan(out) STDOUT : 8, eram dictionary[32768] = harp1lram : 9) { chan bitstream; int lo, hi; int code, data; int i : 8; bool c, flag; /* Read dictionary */ do { STDIN ? lo; STDIN ? hi; dictionary[(hi @ lo) <- 15], i = true @ i, i + 1; } while (i != 0); par { /* Create bitstream from 8-bit packed input */ while (1) { /* Crufty hack to stop program if no more data to be input */ par { { STDIN ? lo; flag = 0; } { flag = 1; delay; if (flag) stop; } } bitstream ! (lo \\ 7) <- 1; bitstream ! (lo \\ 6) <- 1; bitstream ! (lo \\ 5) <- 1; bitstream ! (lo \\ 4) <- 1; bitstream ! (lo \\ 3) <- 1; bitstream ! (lo \\ 2) <- 1; bitstream ! (lo \\ 1) <- 1; bitstream ! (lo \\ 0) <- 1; } /* Unpack and output */ code = 1; while (1) { do { bitstream ? c; code, data = (code <- 14) @ c, dictionary[(code <- 14) @ c]; } while (~(data \\ 8)); par { STDOUT ! (data <- 8); code = 1; } } } } /* Normal optimisation: After compilation : 98 LATCHES, 414 GATES, 28 INVERTERS; SIZE 612 After netlist optimisations : 87 LATCHES, 231 GATES, 12 INVERTERS; SIZE 349 After fan-in adjustment : 87 LATCHES, 237 GATES, 12 INVERTERS; SIZE 349 >108999 cycles */