diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-01-03 12:07:46 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-01-03 12:07:46 +0100 |
commit | c46fe12e47c405fbb03f0c93121402d873bc470e (patch) | |
tree | bc9cb3f5ffb5f130106e80d2777da41058d81d3a | |
parent | f2b28b4124015718dc4b392e00f4aade4eedc11c (diff) | |
download | SystDigit-Projet-c46fe12e47c405fbb03f0c93121402d873bc470e.tar.gz SystDigit-Projet-c46fe12e47c405fbb03f0c93121402d873bc470e.zip |
Implement lw/sw/lwr/swr ; optimize simplification pass order ; add comments in ROM files
-rw-r--r-- | cpu/cpu.ml | 54 | ||||
-rw-r--r-- | cpu/netlist_gen.ml | 2 | ||||
-rw-r--r-- | cpu/prog_rom0.rom | 4 | ||||
-rw-r--r-- | csim/load.c | 16 | ||||
-rw-r--r-- | sched/simplify.ml | 12 |
5 files changed, 73 insertions, 15 deletions
@@ -45,7 +45,7 @@ let cpu_get_reg i = let a03 = mux (i ** 0) r6 r7 in let a10 = mux (i ** 1) a00 a01 in let a11 = mux (i ** 1) a02 a03 in - mux (i ** 2) a10 a00 + mux (i ** 2) a10 a11 let save_cpu_regs wr wd = let next_r1 = mux (eq_c 3 wr 1) r1 wd in @@ -127,6 +127,7 @@ let rl, rh, i, ex, exf, pc = let instr_incri = exec ^& eq_c 5 i_i 0b00110 in let wr = mux instr_incri wr i_r in let rwd = mux instr_incri rwd (nadder_nocarry 16 v_r (sign_extend 8 16 i_id)) in + (* instruction : j *) let instr_j = exec ^& eq_c 5 i_i 0b01000 in let next_pc = mux instr_j next_pc (nadder_nocarry 16 pc (sign_extend 11 16 i_jd)) in @@ -142,11 +143,42 @@ let rl, rh, i, ex, exf, pc = let instr_jalxx = instr_jalxx ^| (instr_jxxr ^& instr_jalr) in let cond_jxxr = instr_jxxr ^& (alu_comparer 16 f0 i_f v_ra v_rb ^| instr_jr ^| instr_jalr) in let next_pc = mux cond_jxxr next_pc v_r in - (* prologue for jal/jalr *) let wr = mux instr_jalxx wr (const "011") in let rwd = mux instr_jalxx rwd next_pc in + (* instruction : lw/lwr/sw/swr *) + let instr_lsw = eq_c 4 (i_i % (1, 4)) 0b1000 in + let instr_lswr = eq_c 4 (i_i % (1, 4)) 0b1010 in + let instr_lswx = instr_lsw ^| instr_lswr in + let instr_swx = instr_lswx ^& (i_i ** 0) in + let instr_lwx = instr_lswx ^& (not (i_i ** 0)) in + + let lswx_d = mux instr_lswr (sign_extend 5 16 i_kd) v_rb in + let lswx_addr_lo = reg 16 (nadder_nocarry 16 v_ra lswx_d) in + let lswx_addr_hi = let a, b = nadder 16 v_ra lswx_d (const "1") in b ^. reg 16 a in + + let lwx_load_lo = reg 1 (exec ^& instr_lwx) in + let lwx_load_hi = reg 1 lwx_load_lo in + let ra = mux lwx_load_lo ra lswx_addr_lo in + let lwx_lo = reg 8 (mux lwx_load_lo (zeroes 8) ram_read) in + let ra = mux lwx_load_hi ra lswx_addr_hi in + let lwx_hi = mux lwx_load_hi (zeroes 8) ram_read in + let wr = mux lwx_load_hi wr i_r in + let rwd = mux lwx_load_hi rwd (lwx_lo ++ lwx_hi) in + let exec_finished = mux instr_lwx exec_finished lwx_load_hi in + + let swx_save_lo = reg 1 (exec ^& instr_swx) in + let swx_save_hi = reg 1 swx_save_lo in + let we = we ^| swx_save_lo in + let wa = mux swx_save_lo wa lswx_addr_lo in + let d = mux swx_save_lo d (v_r % (0, 7)) in + let we = we ^| swx_save_hi in + let wa = mux swx_save_hi wa lswx_addr_hi in + let d = mux swx_save_hi d (v_r % (8, 15)) in + let exec_finished = mux instr_lwx exec_finished swx_save_hi in + + save_cpu_regs wr rwd ^. save_ram_read (cpu_ram ra we wa d) ^. save_next_read exec_finished ^. @@ -159,18 +191,18 @@ let p = [ "read_ilow", 1, rl; "read_ihi", 1, rh; - "instruction", 16, i; "exec_instr", 1, ex; "exec_finished", 1, exf; + "instruction", 16, i; "pc", 16, pc; - "r0", 16, r0; - "r1", 16, r1; - "r2", 16, r2; - "r3", 16, r3; - "r4", 16, r4; - "r5", 16, r5; - "r6", 16, r6; - "r7", 16, r7; + "r0_Z", 16, r0; + "r1_A", 16, r1; + "r2_B", 16, r2; + "r3_C", 16, r3; + "r4_D", 16, r4; + "r5_E", 16, r5; + "r6_F", 16, r6; + "r7_G", 16, r7; ] let () = Netlist_gen.print stdout p diff --git a/cpu/netlist_gen.ml b/cpu/netlist_gen.ml index 0c38b6f..1aad452 100644 --- a/cpu/netlist_gen.ml +++ b/cpu/netlist_gen.ml @@ -198,7 +198,7 @@ let program entries outputs = { p_inputs = p.p_inputs; p_eqs = p.p_eqs; p_vars = p.p_vars; - p_outputs = outputs } + p_outputs = List.rev outputs } (* Netlist printer *) diff --git a/cpu/prog_rom0.rom b/cpu/prog_rom0.rom index 0e93de2..1321436 100644 --- a/cpu/prog_rom0.rom +++ b/cpu/prog_rom0.rom @@ -1,3 +1,3 @@ 4 8 -/1 10001100 -01111111 11100010 +/1 10001100 # incri A 1 +01111111 11100010 # j -2 (ie jump to address 0) diff --git a/csim/load.c b/csim/load.c index bb77a0e..485a743 100644 --- a/csim/load.c +++ b/csim/load.c @@ -13,6 +13,19 @@ t_rom *roms = NULL; +void eat_comment(FILE *file) { + while (1) { + char c = fgetc(file); + if (isspace(c)) continue; + if (c == '#') { + while (fgetc(file) != '\n'); + continue; + } + ungetc(c, file); + break; + } +} + void add_rom(const char *prefix, FILE *file) { int i; @@ -20,11 +33,12 @@ void add_rom(const char *prefix, FILE *file) { rom->prefix = prefix; // Load ROM file + eat_comment(file); fscanf(file, "%d %d\n", &(rom->words_defined), &(rom->word_size)); rom->data = malloc(rom->words_defined * sizeof(t_value)); for (i = 0; i < rom->words_defined; i++) { - fscanf(file, " "); + eat_comment(file); if (fscanf(file, "/%lu", &(rom->data[i]))) { // ok, value is read } else if (fscanf(file, "x%x", &(rom->data[i]))) { diff --git a/sched/simplify.ml b/sched/simplify.ml index c0cd07e..c68fe66 100644 --- a/sched/simplify.ml +++ b/sched/simplify.ml @@ -336,6 +336,18 @@ let simplify p = topo_sort, "topo_sort"; cascade_slices, "cascade_slices"; pass_concat, "pass_concat"; + select_to_id, "select_to_id"; + arith_simplify, "arith_simplify"; + ] p in + let p = simplify_with [ + arith_simplify, "arith_simplify"; + same_eq_simplify, "same_eq_simplify"; + eliminate_id, "eliminate_id"; + ] p in + let p = simplify_with [ + topo_sort, "topo_sort"; + cascade_slices, "cascade_slices"; + pass_concat, "pass_concat"; arith_simplify, "arith_simplify"; select_to_id, "select_to_id"; same_eq_simplify, "same_eq_simplify"; |