From 8a42a00d1392d882d4241ae92fbf7845f6791c5f Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Tue, 13 Nov 2018 20:41:25 +0000 Subject: CPU add adder16 --- cpu8/cpu_adder16bit/Makefile | 12 ++ cpu8/cpu_adder16bit/cpu_adder16bit.cpp | 205 +++++++++++++++++++++++++++++++++ cpu8/cpu_adder16bit/cpu_adder16bit.hpp | 73 ++++++++++++ 3 files changed, 290 insertions(+) create mode 100644 cpu8/cpu_adder16bit/Makefile create mode 100644 cpu8/cpu_adder16bit/cpu_adder16bit.cpp create mode 100644 cpu8/cpu_adder16bit/cpu_adder16bit.hpp diff --git a/cpu8/cpu_adder16bit/Makefile b/cpu8/cpu_adder16bit/Makefile new file mode 100644 index 0000000..7b8eee6 --- /dev/null +++ b/cpu8/cpu_adder16bit/Makefile @@ -0,0 +1,12 @@ +SYSTEMC_PATH=/home/fam/downloads/source/systemc/systemc-2.3.2 +SYSTEMC_INC=$(SYSTEMC_PATH)/src +SYSTEMC_LIB=$(SYSTEMC_PATH)/src/.libs + +PROJECT=cpu_adder16bit + +make: + g++ $(PROJECT).cpp -I$(SYSTEMC_INC) -L$(SYSTEMC_LIB) -Wl,-rpath=$(SYSTEMC_LIB)\ + -o $(PROJECT) -lsystemc -lm + + + diff --git a/cpu8/cpu_adder16bit/cpu_adder16bit.cpp b/cpu8/cpu_adder16bit/cpu_adder16bit.cpp new file mode 100644 index 0000000..723fb47 --- /dev/null +++ b/cpu8/cpu_adder16bit/cpu_adder16bit.cpp @@ -0,0 +1,205 @@ +#include +#include + +#include "systemc.h" +#include "systemc" +#include +#include + +#include "cpu_adder16bit.hpp" + +#define N 16 + +void write_signal_port_out(sc_out *port_a, uint16_t d) +{ + int i; + //printf("%x\n",d); + for (i=0;i>i)&0x01; + //print(bit); + port_a[i]->write(bit); + } + //exit(0); +} + +SC_MODULE(test_cpu_adder16bit) +{ + sc_out a[N],b[N],carry; + sc_in clk; + + void test_cpu_adder16bit_stim() + { + wait(); + a[0].write(0); + a[1].write(0); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(0); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(0); + a[1].write(1); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(0); + a[1].write(0); + b[0].write(1); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(0); + a[1].write(0); + b[0].write(1); + b[1].write(1); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(0); + b[0].write(1); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(1); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(1); + b[1].write(1); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(0); + b[1].write(1); + carry.write(0); + + wait(); + write_signal_port_out(a,0x0001); + write_signal_port_out(b,0x0000); + + wait(); + write_signal_port_out(a,0x0001); + write_signal_port_out(b,0x0001); + + wait(); + write_signal_port_out(a,0xFFFF); + write_signal_port_out(b,0x0000); + + wait(); + write_signal_port_out(a,0x0000); + write_signal_port_out(b,0xFFFF); + + wait(); + write_signal_port_out(a,0x0F0F); + write_signal_port_out(b,0x0F0F); + + wait(); + write_signal_port_out(a,0xF0F0); + write_signal_port_out(b,0xF0F0); + + wait(); + write_signal_port_out(a,0xFFFF); + write_signal_port_out(b,0x0001); + + wait(); + write_signal_port_out(a,0xFFFF); + write_signal_port_out(b,0x0000); + carry.write(1); + + wait(); + write_signal_port_out(a,0xFFFE); + write_signal_port_out(b,0x0001); + carry.write(0); + + wait(); + + sc_stop(); + } + + SC_CTOR(test_cpu_adder16bit) + { + SC_THREAD(test_cpu_adder16bit_stim); + sensitive << clk.pos(); + + } +}; + + +int sc_main(int argc, char **argv) { + int i; + sc_signal sig_in_a[N], sig_in_b[N],sig_out_c[N],sig_out_sum[N],sig_in_carry,sig_out_carry; + sc_clock TestClk("TestClk", 10, SC_NS, 0.5, 1, SC_NS); + + test_cpu_adder16bit Stim1("Stimulus"); + Stim1.carry(sig_in_carry); + Stim1.clk(TestClk); + for (i=0;i in_a[ADD_N]; + sc_in in_b[ADD_N]; + sc_in in_carry; + sc_out out_sum[ADD_N]; + sc_out out_carry; + + cpu_full_adder *fulladder[ADD_N]; + + sc_signal sig_fadd[ADD_N-1]; + + void do_adder16bit() + { + /* + if (in_sel.read() == 0) + { + out_c.write(in_a.read()); + } + if (in_sel.read() == 1) + { + out_c.write(in_b.read()); + } + */ + } + + SC_CTOR(cpu_adder16bit) + { + + int i; + for (i=0;i<16;i++) + { + const int sz=16; + char *s=(char *)malloc(sz); //need to free s? + snprintf(s,sz,"FULLADD%02d",i); + fulladder[i] = new cpu_full_adder(s); + } + + for (i=0;i<16;i++) + { + fulladder[i]->in_a(in_a[i]); + fulladder[i]->in_b(in_b[i]); + fulladder[i]->out_sum(out_sum[i]); + } + + fulladder[0]->in_c(in_carry); + fulladder[ADD_N-1]->out_carry(out_carry); + for (i=1;iin_c(sig_fadd[i-1]); + fulladder[i-1]->out_carry(sig_fadd[i-1]); + } + + //SC_METHOD(do_dmux); + //sensitive << in_a << in_b << in_sel; + } + +}; + +#endif \ No newline at end of file -- cgit v1.2.3