/* hunpack.c, (c) MPA 1995 */ #include "harp1.h" void main(chan(in) STDIN : 8, chan(out) STDOUT : 8, eram dictionary[256] = harp1lram : 16) { chan bitstream; int lo, hi; int code, data; int i : 8; bool bits_0, bits_1, bits_2, bits_3; bool bits_4, bits_5, bits_6, bits_7; bool flag; /* Read dictionary */ do { STDIN ? lo; STDIN ? hi; dictionary[i] = hi @ lo; i = i + 1; } while (i != 0); par { /* Create 8-bit packed output from bitstream */ while (1) { bitstream ? bits_0; bitstream ? bits_1; bitstream ? bits_2; bitstream ? bits_3; bitstream ? bits_4; bitstream ? bits_5; bitstream ? bits_6; bitstream ? bits_7; STDOUT ! bits_0 @ bits_1 @ bits_2 @ bits_3 @ bits_4 @ bits_5 @ bits_6 @ bits_7; } /* Pack input */ flag = 1; while (1) { /* A small cruft to kill the program when no more data is available - pretty nasty, huh? */ par { { STDIN ? data; flag = 0; } { delay; delay; if (flag) stop; } } code = dictionary[data]; if ((code \\ 15) <- 1) par { bitstream ! (code \\ 14) <- 1; flag = 1; } if (flag | ((code \\ 14) <- 1)) par { bitstream ! (code \\ 13) <- 1; flag = 1; } if (flag | ((code \\ 13) <- 1)) par { bitstream ! (code \\ 12) <- 1; flag = 1; } if (flag | ((code \\ 12) <- 1)) par { bitstream ! (code \\ 11) <- 1; flag = 1; } if (flag | ((code \\ 11) <- 1)) par { bitstream ! (code \\ 10) <- 1; flag = 1; } if (flag | ((code \\ 10) <- 1)) par { bitstream ! (code \\ 9) <- 1; flag = 1; } if (flag | ((code \\ 9) <- 1)) par { bitstream ! (code \\ 8) <- 1; flag = 1; } if (flag | ((code \\ 8) <- 1)) par { bitstream ! (code \\ 7) <- 1; flag = 1; } if (flag | ((code \\ 7) <- 1)) par { bitstream ! (code \\ 6) <- 1; flag = 1; } if (flag | ((code \\ 6) <- 1)) par { bitstream ! (code \\ 5) <- 1; flag = 1; } if (flag | ((code \\ 5) <- 1)) par { bitstream ! (code \\ 4) <- 1; flag = 1; } if (flag | ((code \\ 4) <- 1)) par { bitstream ! (code \\ 3) <- 1; flag = 1; } if (flag | ((code \\ 3) <- 1)) par { bitstream ! (code \\ 2) <- 1; flag = 1; } if (flag | ((code \\ 2) <- 1)) par { bitstream ! (code \\ 1) <- 1; flag = 1; } if (flag | ((code \\ 1) <- 1)) par { bitstream ! (code \\ 0) <- 1; flag = 1; } else stop; } } } /* Normal optimisation: After compilation : 148 LATCHES, 527 GATES, 54 INVERTERS; SIZE 779 After netlist optimisations : 125 LATCHES, 316 GATES, 26 INVERTERS; SIZE 520 After fan-in adjustment : 125 LATCHES, 337 GATES, 26 INVERTERS; SIZE 520 >82999 cycles */