// // TT CTOV Illux example test suite. // // This C source file contains examples from the manual. // // These examples can be run using the makefile provided. The output is provided in objdir. // #include "cxctypes.h" // E1. A combinatorial function: inverter void e1(u1 *op, u1 i) { *op = !i; } void e1a(u1 *o, u1 i) { *o = !i; } // // The difference between E1 and E1A is the text name of the output variable. E1A does not // obey the default naming policy for outputs, and so "_actual" appears in the generated file. // Note that clk and cx_reset are added even to combinatorial modules. // //-------------------------------------------------------------------------------------------- // E2. A simple 3 bit counter void e2a(u1 clk, u1 cx_reset, u3 *outp) { *outp = *outp + 1; cx_barrier(); } // Here the thread exits but the output signal is updated before the barrier // with no updates afterwards. According to Tenos rules, this generates a registered // function. This design does not work though, since there is no actual register // to hold the count value in the C code. We modifiy it as follows void e2b(u1 clk, u1 cx_reset, u3 *outp) { static u3 reg; reg += 1; *outp = reg; cx_barrier(); } // We can add reset as follows, taking advantage of the static delcaration of reg where the // value assigned will only be stored when cx_reset is true: void e2c(u1 clk, u1 cx_reset, u3 *outp) { static u3 reg = 0; reg += 1; *outp = reg; cx_barrier(); } // Of course, we could also add an explicit reset using a conditional expression if // desired, as shown in e2d void e2d(u1 clk, u1 cx_reset, u3 *outp) { static u3 reg; reg = (cx_reset) ? 0: reg +1; *outp = reg; cx_barrier(); } // Or with an if statement void e2e(u1 clk, u1 cx_reset, u3 *outp) { static u3 reg; if (cx_reset) reg = 0; else reg++; *outp = reg; cx_barrier(); } // The variations in the object files generated by these examples show that output optimisation // is not very good in the current CTOV release. However, the subsequent Verilog tools will // optimise and thus remove the variations. //-------------------------------------------------------------------------------------------- // E3. Another 3 bit counter, using the process loop Tenos semantic void e3(u1 clk, u1 cx_reset, u3 *outp) { u3 reg = 4; while(1) { reg += 1; *outp = reg; cx_barrier(); } } // Here the thread does not exit, but the function is just the same as // E2. Note that the call to cx_barrier() is needed inside the body of // the loop and the compiler will put one in automatically if it is // missing. This action can be seen in the report file. The exception // is when compile time unroll of the loop is specified (TODO say how), // but compile time unroll of an infinite loop is not possible. //-------------------------------------------------------------------------------------------- // E4. Another 3 bit counter void e4(u1 clk, u1 cx_reset, u3 *outp) { u3 reg; while(1) { reg ++; *outp = reg; cx_barrier(); reg ++; *outp = reg; cx_barrier(); } } // This produces the same behaviour as E2 and E3, but the compiler may not // always optimise away the statereg variable which it generates to // represent which barrier statement is current. //-------------------------------------------------------------------------------------------- // E5. An output that depends on state and is updated after the last barrier // Here the thread exits, thus enabling combinatorial outputs to be // produced, but we also have some state. void e5(u1 clk, u1 cx_reset, u1 x, u1 c, u1 *yp) { static u3 reg; reg = reg + c; cx_barrier(); *yp = x ^ (reg & 1); // combinatorial route from x to y. } //-------------------------------------------------------------------------------------------- // Examples Using Memories // M1. Simple RAM access // Define an array with more locations than "minarraysize" and it // will automatically be converted to a single-ported synchronous // RAM memory. #ifdef REGRESSION_MEMS u5 mem[10000]; #endif void m1(u1 clk, u1 cx_reset, u1 x, u1 *yp) { mem[100+x] = mem[105-x]; *yp = mem[22]; cx_barrier(); } // End of TT regression.c