#include "harp1.h" const dw = 8, aw = 14; const de = (1 << dw), ae = (1 << aw); void main(chan(in) STDIN : dw, chan(out) STDOUT : dw, eram data[ae] = harp1lram : dw, eram hist[de] = harp1hram : aw) { int accu, temp; int extended_addr : aw + 1; int extended_x : dw + 1; int x() = extended_x <- dw; int x_nz() = (extended_x \\ dw) != 1; int addr() = extended_addr <- aw; int addr_nz() = (extended_addr \\ aw) != 1; void increment_address() { extended_addr = (0 @ addr()) + 1; } void input_to_x() { par { STDIN ? any; extended_x = 0 @ STDIN; } } void hist_x_to_temp() { temp = hist[x()]; } void input_and_histogram() { input_to_x(); do par { { delay; input_to_x(); } { data[addr()] = x(); increment_address(); } { hist_x_to_temp(); hist[x()] = temp + 1; } } while (addr_nz()); } void accumulate_histogram() { extended_x = 0; do { hist_x_to_temp(); hist[x()], accu, extended_x = accu, accu + temp, (0 @ x()) + 1; } while (x_nz()); } void equalise_and_output() { do par { STDOUT ! hist[data[addr()]] \\ (aw - dw); increment_address(); } while (addr_nz()); } /* Main program */ input_and_histogram(); accumulate_histogram(); equalise_and_output(); }