From 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 24 May 2018 01:37:55 -0700 Subject: systemc: Import tests from the Accellera systemc distribution. Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini Maintainer: Gabe Black --- .../systemc/examples/updown/golden/updown.log | 20 +++ .../tests/systemc/examples/updown/updown.cpp | 134 +++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/systemc/tests/systemc/examples/updown/golden/updown.log create mode 100644 src/systemc/tests/systemc/examples/updown/updown.cpp (limited to 'src/systemc/tests/systemc/examples/updown') diff --git a/src/systemc/tests/systemc/examples/updown/golden/updown.log b/src/systemc/tests/systemc/examples/updown/golden/updown.log new file mode 100644 index 000000000..983d78412 --- /dev/null +++ b/src/systemc/tests/systemc/examples/updown/golden/updown.log @@ -0,0 +1,20 @@ +SystemC Simulation +clock up down data_in parity_out carry_out borrow_out count_out + 1 0 0 200 1 0 0 200 + 2 1 0 0 1 0 0 203 + 3 1 0 0 1 0 0 206 + 4 0 1 0 0 0 0 201 + 5 0 1 0 1 0 0 196 + 6 0 1 0 1 0 0 191 + 7 1 1 0 1 0 0 191 + 8 1 1 0 1 0 0 191 + 9 1 1 0 1 0 0 191 + 10 0 0 200 1 0 0 200 + 11 1 1 0 1 0 0 200 + 12 1 1 0 1 0 0 200 + 13 0 1 0 0 0 0 195 + 14 0 0 2 1 0 0 2 + 15 0 1 0 0 0 1 509 + 16 0 0 511 1 0 0 511 + 17 1 0 0 1 1 0 2 + 17 1 0 0 1 1 0 2 diff --git a/src/systemc/tests/systemc/examples/updown/updown.cpp b/src/systemc/tests/systemc/examples/updown/updown.cpp new file mode 100644 index 000000000..f6c6046cb --- /dev/null +++ b/src/systemc/tests/systemc/examples/updown/updown.cpp @@ -0,0 +1,134 @@ +#include "systemc.h" +#include "specialized_signals/scx_signal_int.h" +#include "specialized_signals/scx_signal_signed.h" +#include "specialized_signals/scx_signal_uint.h" +#include "specialized_signals/scx_signal_unsigned.h" + +SC_MODULE(up_down) +{ + sc_in_clk clk; + sc_in > up; + sc_in > down; + sc_in > data_in; + sc_inout > parity_out; + sc_inout > carry_out; + sc_inout > borrow_out; + sc_inout > count_out; + + sc_uint<10> cnt_dn; + sc_uint<10> cnt_up; + sc_uint<9> count_nxt; + sc_uint<1> load; + + SC_CTOR(up_down) + { + SC_METHOD(run); + sensitive << clk.pos(); + } + + void run() + { + cnt_dn = count_out - 5; + cnt_up = count_out + 3; + + load = 1; + switch( (unsigned int )(up,down) ) { + case(0): + count_nxt = data_in; + break; + case(1): + count_nxt = cnt_dn; + break; + case(2): + count_nxt = cnt_up; + break; + case(3): + load = 0; + break; + } + + if( load) { + parity_out = count_nxt.xor_reduce(); + carry_out = up&cnt_up[9]; + borrow_out = down&cnt_dn[9]; + count_out = count_nxt; + } + } +}; + + +#define UP_DOWN(up, down) up, down + +struct stimulus { + int up; + int down; + int data_in; +} s[] = { + { UP_DOWN(0, 0), 200 }, /* load 200 */ + { UP_DOWN(1, 0), 0 }, /* inc */ + { UP_DOWN(1, 0), 0 }, /* inc */ + { UP_DOWN(0, 1), 0 }, /* dec */ + { UP_DOWN(0, 1), 0 }, /* dec */ + { UP_DOWN(0, 1), 0 }, /* dec */ + { UP_DOWN(1, 1), 0 }, /* hold */ + { UP_DOWN(1, 1), 0 }, /* hold */ + { UP_DOWN(1, 1), 0 }, /* hold */ + { UP_DOWN(0, 0), 200 }, /* load 200 */ + { UP_DOWN(1, 1), 0 }, /* hold */ + { UP_DOWN(1, 1), 0 }, /* hold */ + { UP_DOWN(0, 1), 0 }, /* dec */ + { UP_DOWN(0, 0), 2 }, /* load 2 */ + { UP_DOWN(0, 1), 0 }, /* dec */ + { UP_DOWN(0, 0), 0x1ff},/* load 0x1ff */ + { UP_DOWN(1, 0), 0 }, /* inc */ +}; + + +int sc_main(int argc, char* argv[]) +{ + sc_signal > borrow_out; + sc_signal > carry_out; + sc_clock clock; + sc_signal > count_out; + sc_signal > data_in; + sc_signal > down; + unsigned int i; + sc_signal > parity_out; + sc_signal > up; + + up_down up_down_0("up_down_0"); + up_down_0.borrow_out(borrow_out); + up_down_0.carry_out(carry_out); + up_down_0.data_in(data_in); + up_down_0.clk(clock); + up_down_0.count_out(count_out); + up_down_0.down(down); + up_down_0.parity_out(parity_out); + up_down_0.up(up); + + printf("%5s %2s %4s %7s %10s %8s %10s %9s\n", + "clock", "up", "down", "data_in", "parity_out", + "carry_out", "borrow_out", "count_out"); + + for( i = 0; i < sizeof s/sizeof(struct stimulus); i++) { + up = s[i].up; + down = s[i].down; + data_in = s[i].data_in; + + sc_start(1, SC_NS); + + printf("%5d %2d %4d %7d %10d %8d %10d %9d\n", + (int)sc_time_stamp().to_double()/1000, (int)up, (int)down, + (int)data_in, (int)parity_out, (int)carry_out, (int)borrow_out, + (int)count_out); + } + + /* get last register values */ + printf("%5d %2d %4d %7d %10d %8d %10d %9d\n", + (int)sc_time_stamp().to_double()/1000, (int)up, (int)down, + (int)data_in, (int)parity_out, (int)carry_out, (int)borrow_out, + (int)count_out); + + return 0; +} + -- cgit v1.2.3