diff options
author | FreeArtMan <dos21h@gmail.com> | 2018-11-13 20:41:25 +0000 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2018-11-13 20:41:25 +0000 |
commit | 8a42a00d1392d882d4241ae92fbf7845f6791c5f (patch) | |
tree | 8902bdbaab16fa32a8506a06ab129642105ffd0f /cpu8/cpu_adder16bit | |
parent | e268bca23dcd1ca0a6f966be761c2661c8c6a28b (diff) | |
download | cpu8-8a42a00d1392d882d4241ae92fbf7845f6791c5f.tar.gz cpu8-8a42a00d1392d882d4241ae92fbf7845f6791c5f.zip |
CPU add adder16
Diffstat (limited to 'cpu8/cpu_adder16bit')
-rw-r--r-- | cpu8/cpu_adder16bit/Makefile | 12 | ||||
-rw-r--r-- | cpu8/cpu_adder16bit/cpu_adder16bit.cpp | 205 | ||||
-rw-r--r-- | cpu8/cpu_adder16bit/cpu_adder16bit.hpp | 73 |
3 files changed, 290 insertions, 0 deletions
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 <iostream> +#include <iomanip> + +#include "systemc.h" +#include "systemc" +#include <sysc/tracing/sc_trace.h> +#include <sysc/tracing/sc_vcd_trace.h> + +#include "cpu_adder16bit.hpp" + +#define N 16 + +void write_signal_port_out(sc_out<bool> *port_a, uint16_t d) +{ + int i; + //printf("%x\n",d); + for (i=0;i<N;i++) + { + int bit = (d>>i)&0x01; + //print(bit); + port_a[i]->write(bit); + } + //exit(0); +} + +SC_MODULE(test_cpu_adder16bit) +{ + sc_out<bool> a[N],b[N],carry; + sc_in<bool> 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<bool> 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<N;i++) + { + Stim1.a[i](sig_in_a[i]); + Stim1.b[i](sig_in_b[i]); + } + + + cpu_adder16bit DUT("cpu_adder16bit"); + for (i=0;i<N;i++) + { + DUT.in_a[i](sig_in_a[i]); + DUT.in_b[i](sig_in_b[i]); + DUT.out_sum[i](sig_out_sum[i]); + } + + DUT.in_carry(sig_in_carry); + DUT.out_carry(sig_out_carry); + + + sc_trace_file *Tf; + + Tf = sc_create_vcd_trace_file("trace_cpu_adder16bit.dat"); + sc_trace(Tf, sig_in_carry, "IN_CARRY"); + sc_trace(Tf, sig_out_carry, "OUT_CARRY"); + for (i=0;i<N;i++) + { + const static int sz=16; + char *str_a = (char *)malloc(sz); + snprintf(str_a,sz,"IN_A%02d",i); + sc_trace(Tf, sig_in_a[i], str_a); + char *str_b = (char *)malloc(sz); + snprintf(str_b,sz,"IN_B%02d",i); + sc_trace(Tf, sig_in_b[i], str_b); + char *str_sum = (char *)malloc(sz); + snprintf(str_sum,sz,"OUT_SUM%02d",i); + sc_trace(Tf, sig_out_sum[i], str_sum); + } + + sc_start(); + sc_close_vcd_trace_file(Tf); + + return(0); +}
\ No newline at end of file diff --git a/cpu8/cpu_adder16bit/cpu_adder16bit.hpp b/cpu8/cpu_adder16bit/cpu_adder16bit.hpp new file mode 100644 index 0000000..a132665 --- /dev/null +++ b/cpu8/cpu_adder16bit/cpu_adder16bit.hpp @@ -0,0 +1,73 @@ +#ifndef __SYSC_CPU_ADDER16BIT_HPP +#define __SYSC_CPU_ADDER16BIT_HPP + +#include "systemc.h" +#include "../cpu_and/cpu_and.hpp" +#include "../cpu_or/cpu_or.hpp" +#include "../cpu_not/cpu_not.hpp" +#include "../cpu_full_adder/cpu_full_adder.hpp" + + +SC_MODULE (cpu_adder16bit) +{ + const static int ADD_N=16; + //Inputs + sc_in <bool> in_a[ADD_N]; + sc_in <bool> in_b[ADD_N]; + sc_in <bool> in_carry; + sc_out <bool> out_sum[ADD_N]; + sc_out <bool> out_carry; + + cpu_full_adder *fulladder[ADD_N]; + + sc_signal<bool> 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;i<ADD_N;i++) + { + + fulladder[i]->in_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 |