add div inst

Signed-off-by: Blue Liang <liangkangnan@163.com>
pull/1/head
Blue Liang 2020-01-13 08:26:41 +08:00
parent af74c11db8
commit 9420b85796
31 changed files with 1053 additions and 7 deletions

View File

@ -29,6 +29,12 @@
`define ChipDisable 1'b0 `define ChipDisable 1'b0
`define JumpEnable 1'b1 `define JumpEnable 1'b1
`define JumpDisable 1'b0 `define JumpDisable 1'b0
`define DivResultNotReady 1'b0
`define DivResultReady 1'b1
`define DivStart 1'b1
`define DivStop 1'b0
`define HoldEnable 1'b1
`define HoldDisable 1'b0
// I type inst // I type inst
`define INST_TYPE_I 7'b0010011 `define INST_TYPE_I 7'b0010011
@ -71,6 +77,10 @@
`define INST_MULH 3'b001 `define INST_MULH 3'b001
`define INST_MULHSU 3'b010 `define INST_MULHSU 3'b010
`define INST_MULHU 3'b011 `define INST_MULHU 3'b011
`define INST_DIV 3'b100
`define INST_DIVU 3'b101
`define INST_REM 3'b110
`define INST_REMU 3'b111
// J type inst // J type inst
`define INST_JAL 7'b1101111 `define INST_JAL 7'b1101111

131
rtl/div.v Normal file
View File

@ -0,0 +1,131 @@
`include "defines.v"
module div (
input wire clk,
input wire rst,
input wire[`RegBus] dividend_i,
input wire[`RegBus] divisor_i,
input wire start_i,
output reg[`DoubleRegBus] result_o,
output reg ready_o
);
parameter STATE_IDLE = 0;
parameter STATE_START = 1;
parameter STATE_REVERT = 2;
parameter STATE_END = 3;
reg[`RegBus] dividend_temp;
reg[`RegBus] divisor_temp;
reg[1:0] state;
reg[6:0] count;
reg[`RegBus] div_result;
reg[`RegBus] div_remain;
reg[`RegBus] minuend;
reg[`RegBus] divisor_zero_result;
always @ (posedge clk) begin
if (rst == `RstEnable) begin
state <= STATE_IDLE;
ready_o <= `DivResultNotReady;
result_o <= {`ZeroWord, `ZeroWord};
div_result <= `ZeroWord;
div_remain <= `ZeroWord;
divisor_zero_result <= ~32'b00000001 + 1'b1;
end else begin
case (state)
STATE_IDLE: begin
if (start_i == `DivStart) begin
if (divisor_i == `ZeroWord) begin
ready_o <= `DivResultReady;
result_o <= {`ZeroWord, divisor_zero_result};
end else begin
count <= 7'd31;
state <= STATE_START;
if (dividend_i[31] == 1'b1) begin
dividend_temp <= ~dividend_i + 1;
minuend <= ((~dividend_i + 1) >> 7'd31) & 1'b1;
end else begin
dividend_temp <= dividend_i;
minuend <= (dividend_i >> 7'd31) & 1'b1;
end
if (divisor_i[31] == 1'b1) begin
divisor_temp <= ~divisor_i + 1;
end else begin
divisor_temp <= divisor_i;
end
div_result <= `ZeroWord;
div_remain <= `ZeroWord;
end
end else begin
ready_o <= `DivResultNotReady;
result_o <= {`ZeroWord, `ZeroWord};
end
end
STATE_START: begin
if (start_i == `DivStart) begin
if (count >= 7'd1) begin
if (minuend >= divisor_temp) begin
div_result <= (div_result << 1'b1) | 1'b1;
minuend <= ((minuend - divisor_temp) << 1'b1) | ((dividend_temp >> (count - 1'b1)) & 1'b1);
end else begin
div_result <= (div_result << 1'b1) | 1'b0;
minuend <= (minuend << 1'b1) | ((dividend_temp >> (count - 1'b1)) & 1'b1);
end
count <= count - 1'b1;
end else begin
state <= STATE_REVERT;
if (minuend >= divisor_temp) begin
div_result <= (div_result << 1'b1) | 1'b1;
div_remain <= minuend - divisor_temp;
end else begin
div_result <= (div_result << 1'b1) | 1'b0;
div_remain <= minuend;
end
end
end else begin
ready_o <= `DivResultReady;
result_o <= {`ZeroWord, `ZeroWord};
state <= STATE_IDLE;
end
end
STATE_REVERT: begin
if (start_i == `DivStart) begin
if (dividend_i[31] ^ divisor_i[31] == 1'b1) begin
div_result <= ~div_result + 1'b1;
end
if (((dividend_i[31] == 1'b1) && (div_remain >= 0)) || ((dividend_i[31] == 1'b0) && (div_remain < 0))) begin
div_remain <= ~div_remain + 1'b1;
end
state <= STATE_END;
end else begin
ready_o <= `DivResultReady;
result_o <= {`ZeroWord, `ZeroWord};
state <= STATE_IDLE;
end
end
STATE_END: begin
if (start_i == `DivStart) begin
ready_o <= `DivResultReady;
result_o <= {div_remain, div_result};
end else begin
state <= STATE_IDLE;
ready_o <= `DivResultNotReady;
end
end
endcase
end
end
endmodule

132
rtl/ex.v
View File

@ -26,6 +26,8 @@ module ex (
input wire[`SramBus] inst_i, // inst content input wire[`SramBus] inst_i, // inst content
input wire inst_valid_i, input wire inst_valid_i,
input wire[`SramAddrBus] inst_addr_i, // inst addr input wire[`SramAddrBus] inst_addr_i, // inst addr
input wire reg_we_i,
input wire[`RegAddrBus] reg_waddr_i,
// from regs // from regs
input wire[`RegBus] reg1_rdata_i, // reg1 read data input wire[`RegBus] reg1_rdata_i, // reg1 read data
@ -34,6 +36,10 @@ module ex (
// from sram // from sram
input wire[`SramBus] sram_rdata_i, // ram read data input wire[`SramBus] sram_rdata_i, // ram read data
// from div
input wire div_ready_i,
input wire[`DoubleRegBus] div_result_i,
// to sram // to sram
output reg[`SramBus] sram_wdata_o, // ram write data output reg[`SramBus] sram_wdata_o, // ram write data
output reg[`SramAddrBus] sram_raddr_o, // ram read addr output reg[`SramAddrBus] sram_raddr_o, // ram read addr
@ -41,6 +47,17 @@ module ex (
// to regs // to regs
output reg[`RegBus] reg_wdata_o, // reg write data output reg[`RegBus] reg_wdata_o, // reg write data
output reg reg_we_o, // reg write enable
output reg[`RegAddrBus] reg_waddr_o, // reg write addr
// to div
output reg[`RegBus] div_dividend_o,
output reg[`RegBus] div_divisor_o,
output reg div_start_o,
// to pc_reg
output reg hold_flag_o,
output reg[`RegBus] hold_addr_o,
// to pc_reg // to pc_reg
output reg jump_flag_o, // if jump or not flag output reg jump_flag_o, // if jump or not flag
@ -59,10 +76,16 @@ module ex (
wire[`DoubleRegBus] mulhsu_temp_invert; wire[`DoubleRegBus] mulhsu_temp_invert;
wire[`RegBus] op1_mul; wire[`RegBus] op1_mul;
wire[`RegBus] op2_mul; wire[`RegBus] op2_mul;
reg div_starting;
reg is_jumping;
reg div_reg_we;
reg[4:0] div_rd_reg;
reg[2:0] div_funct3;
wire[6:0] opcode = inst_i[6:0]; wire[6:0] opcode = inst_i[6:0];
wire[2:0] funct3 = inst_i[14:12]; wire[2:0] funct3 = inst_i[14:12];
wire[6:0] funct7 = inst_i[31:25]; wire[6:0] funct7 = inst_i[31:25];
wire[4:0] rd = inst_i[11:7];
assign sign_extend_tmp = {{20{inst_i[31]}}, inst_i[31:20]}; assign sign_extend_tmp = {{20{inst_i[31]}}, inst_i[31:20]};
assign shift_bits = inst_i[24:20]; assign shift_bits = inst_i[24:20];
@ -79,13 +102,66 @@ module ex (
if (rst == `RstEnable) begin if (rst == `RstEnable) begin
sram_raddr_o <= `ZeroWord; sram_raddr_o <= `ZeroWord;
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
hold_flag_o <= `HoldDisable;
sram_raddr_index <= 2'b0; sram_raddr_index <= 2'b0;
sram_waddr_index <= 2'b0; sram_waddr_index <= 2'b0;
div_starting <= `DivStop;
is_jumping <= `False;
div_reg_we <= `WriteDisable;
div_start_o <= `DivStop;
end end
end end
always @ (*) begin always @ (*) begin
if (inst_valid_i == `InstValid) begin div_dividend_o <= reg1_rdata_i;
div_divisor_o <= reg2_rdata_i;
end
always @ (*) begin
reg_we_o <= reg_we_i | div_reg_we;
end
always @ (*) begin
if ((is_jumping == `False) && (div_starting == `DivStart)) begin
if (div_ready_i == `DivResultReady) begin
case (div_funct3)
`INST_DIV: begin
div_reg_we <= `WriteEnable;
reg_waddr_o <= div_rd_reg;
reg_wdata_o <= div_result_i[31:0];
div_starting <= `DivStop;
div_start_o <= `DivStop;
hold_flag_o <= `HoldDisable;
end
`INST_DIVU: begin
div_reg_we <= `WriteEnable;
reg_waddr_o <= div_rd_reg;
reg_wdata_o <= div_result_i[31:0];
div_starting <= `DivStop;
div_start_o <= `DivStop;
hold_flag_o <= `HoldDisable;
end
`INST_REM: begin
div_reg_we <= `WriteEnable;
reg_waddr_o <= div_rd_reg;
reg_wdata_o <= div_result_i[63:32];
div_starting <= `DivStop;
div_start_o <= `DivStop;
hold_flag_o <= `HoldDisable;
end
`INST_REMU: begin
div_reg_we <= `WriteEnable;
reg_waddr_o <= div_rd_reg;
reg_wdata_o <= div_result_i[63:32];
div_starting <= `DivStop;
div_start_o <= `DivStop;
hold_flag_o <= `HoldDisable;
end
endcase
end
end else if (inst_valid_i == `InstValid) begin
div_reg_we <= `WriteDisable;
reg_waddr_o <= reg_waddr_i;
case (opcode) case (opcode)
`INST_TYPE_I: begin `INST_TYPE_I: begin
case (funct3) case (funct3)
@ -265,6 +341,42 @@ module ex (
reg_wdata_o <= mulhsu_temp[63:32]; reg_wdata_o <= mulhsu_temp[63:32];
end end
end end
`INST_DIV: begin
jump_flag_o <= `JumpDisable;
hold_flag_o <= `HoldEnable;
div_start_o <= `DivStart;
div_starting <= `DivStart;
div_rd_reg <= rd;
div_funct3 <= funct3;
hold_addr_o <= inst_addr_i + 4'h4;
end
`INST_DIVU: begin
jump_flag_o <= `JumpDisable;
hold_flag_o <= `HoldEnable;
div_start_o <= `DivStart;
div_starting <= `DivStart;
div_rd_reg <= rd;
div_funct3 <= funct3;
hold_addr_o <= inst_addr_i + 4'h4;
end
`INST_REM: begin
jump_flag_o <= `JumpDisable;
hold_flag_o <= `HoldEnable;
div_start_o <= `DivStart;
div_starting <= `DivStart;
div_rd_reg <= rd;
div_funct3 <= funct3;
hold_addr_o <= inst_addr_i + 4'h4;
end
`INST_REMU: begin
jump_flag_o <= `JumpDisable;
hold_flag_o <= `HoldEnable;
div_start_o <= `DivStart;
div_starting <= `DivStart;
div_rd_reg <= rd;
div_funct3 <= funct3;
hold_addr_o <= inst_addr_i + 4'h4;
end
endcase endcase
end end
end end
@ -323,6 +435,7 @@ module ex (
`INST_BEQ: begin `INST_BEQ: begin
if (reg1_rdata_i == reg2_rdata_i) begin if (reg1_rdata_i == reg2_rdata_i) begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end else begin end else begin
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
@ -331,6 +444,7 @@ module ex (
`INST_BNE: begin `INST_BNE: begin
if (reg1_rdata_i != reg2_rdata_i) begin if (reg1_rdata_i != reg2_rdata_i) begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end else begin end else begin
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
@ -339,12 +453,14 @@ module ex (
`INST_BLT: begin `INST_BLT: begin
if (reg1_rdata_i[31] == 1'b1 && reg2_rdata_i[31] == 1'b0) begin if (reg1_rdata_i[31] == 1'b1 && reg2_rdata_i[31] == 1'b0) begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end else if (reg1_rdata_i[31] == 1'b1 && reg2_rdata_i[31] == 1'b1) begin end else if (reg1_rdata_i[31] == 1'b1 && reg2_rdata_i[31] == 1'b1) begin
if (reg1_rdata_i >= reg2_rdata_i) begin if (reg1_rdata_i >= reg2_rdata_i) begin
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin
@ -352,6 +468,7 @@ module ex (
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else begin end else begin
@ -361,12 +478,14 @@ module ex (
`INST_BGE: begin `INST_BGE: begin
if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b1) begin if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b1) begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end else if (reg1_rdata_i[31] == 1'b1 && reg2_rdata_i[31] == 1'b1) begin end else if (reg1_rdata_i[31] == 1'b1 && reg2_rdata_i[31] == 1'b1) begin
if (reg1_rdata_i < reg2_rdata_i) begin if (reg1_rdata_i < reg2_rdata_i) begin
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin
@ -374,6 +493,7 @@ module ex (
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else begin end else begin
@ -388,6 +508,7 @@ module ex (
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin
@ -395,10 +516,12 @@ module ex (
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end end
@ -410,6 +533,7 @@ module ex (
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin end else if (reg1_rdata_i[31] == 1'b0 && reg2_rdata_i[31] == 1'b0) begin
@ -417,10 +541,12 @@ module ex (
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end else begin end else begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0}; jump_addr_o <= inst_addr_i + {{20{inst_i[31]}}, inst_i[7], inst_i[30:25], inst_i[11:8], 1'b0};
end end
end end
@ -428,11 +554,13 @@ module ex (
end end
`INST_JAL: begin `INST_JAL: begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + {{12{inst_i[31]}}, inst_i[19:12], inst_i[20], inst_i[30:21], 1'b0}; jump_addr_o <= inst_addr_i + {{12{inst_i[31]}}, inst_i[19:12], inst_i[20], inst_i[30:21], 1'b0};
reg_wdata_o <= inst_addr_i + 4'h4; reg_wdata_o <= inst_addr_i + 4'h4;
end end
`INST_JALR: begin `INST_JALR: begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= (reg1_rdata_i + {{20{inst_i[31]}}, inst_i[31:20]}) & (32'hfffffffe); jump_addr_o <= (reg1_rdata_i + {{20{inst_i[31]}}, inst_i[31:20]}) & (32'hfffffffe);
reg_wdata_o <= inst_addr_i + 4'h4; reg_wdata_o <= inst_addr_i + 4'h4;
end end
@ -446,9 +574,11 @@ module ex (
end end
`INST_NOP: begin `INST_NOP: begin
jump_flag_o <= `JumpDisable; jump_flag_o <= `JumpDisable;
is_jumping <= `False;
end end
`INST_FENCE: begin `INST_FENCE: begin
jump_flag_o <= `JumpEnable; jump_flag_o <= `JumpEnable;
is_jumping <= `True;
jump_addr_o <= inst_addr_i + 4'h4; jump_addr_o <= inst_addr_i + 4'h4;
end end
default: begin default: begin

View File

@ -24,6 +24,7 @@ module id (
input wire[`SramBus] inst_i, // inst content input wire[`SramBus] inst_i, // inst content
input wire[`SramAddrBus] inst_addr_i, // inst addr input wire[`SramAddrBus] inst_addr_i, // inst addr
input wire jump_flag_ex_i, input wire jump_flag_ex_i,
input wire hold_flag_ex_i,
// to regs // to regs
output reg reg1_re_o, // reg1 read enable output reg reg1_re_o, // reg1 read enable
@ -66,6 +67,11 @@ module id (
sram_we_o <= `WriteDisable; sram_we_o <= `WriteDisable;
reg_we_o <= `WriteDisable; reg_we_o <= `WriteDisable;
inst_o <= `INST_NOP; inst_o <= `INST_NOP;
end else if (hold_flag_ex_i == `HoldEnable) begin
inst_valid_o <= `InstValid;
sram_we_o <= `WriteDisable;
reg_we_o <= `WriteDisable;
inst_o <= `INST_NOP;
end else begin end else begin
inst_o <= inst_i; inst_o <= inst_i;
inst_addr_o <= inst_addr_i; inst_addr_o <= inst_addr_i;
@ -271,6 +277,46 @@ module id (
reg2_raddr_o <= rs2; reg2_raddr_o <= rs2;
sram_we_o <= `WriteDisable; sram_we_o <= `WriteDisable;
end end
`INST_DIV: begin
inst_valid_o <= `InstValid;
reg_we_o <= `WriteDisable;
reg_waddr_o <= rd;
reg1_re_o <= `ReadEnable;
reg1_raddr_o <= rs1;
reg2_re_o <= `ReadEnable;
reg2_raddr_o <= rs2;
sram_we_o <= `WriteDisable;
end
`INST_DIVU: begin
inst_valid_o <= `InstValid;
reg_we_o <= `WriteDisable;
reg_waddr_o <= rd;
reg1_re_o <= `ReadEnable;
reg1_raddr_o <= rs1;
reg2_re_o <= `ReadEnable;
reg2_raddr_o <= rs2;
sram_we_o <= `WriteDisable;
end
`INST_REM: begin
inst_valid_o <= `InstValid;
reg_we_o <= `WriteDisable;
reg_waddr_o <= rd;
reg1_re_o <= `ReadEnable;
reg1_raddr_o <= rs1;
reg2_re_o <= `ReadEnable;
reg2_raddr_o <= rs2;
sram_we_o <= `WriteDisable;
end
`INST_REMU: begin
inst_valid_o <= `InstValid;
reg_we_o <= `WriteDisable;
reg_waddr_o <= rd;
reg1_re_o <= `ReadEnable;
reg1_raddr_o <= rs1;
reg2_re_o <= `ReadEnable;
reg2_raddr_o <= rs2;
sram_we_o <= `WriteDisable;
end
default: begin default: begin
inst_valid_o <= `InstInvalid; inst_valid_o <= `InstInvalid;
end end

View File

@ -26,6 +26,7 @@ module if_id (
input wire[`SramAddrBus] inst_addr_i, // inst addr input wire[`SramAddrBus] inst_addr_i, // inst addr
input wire jump_flag_ex_i, input wire jump_flag_ex_i,
input wire hold_flag_ex_i,
output reg[`SramBus] inst_o, output reg[`SramBus] inst_o,
output reg[`SramAddrBus] inst_addr_o output reg[`SramAddrBus] inst_addr_o
@ -39,6 +40,9 @@ module if_id (
end else if (jump_flag_ex_i == `JumpEnable) begin end else if (jump_flag_ex_i == `JumpEnable) begin
inst_o <= `INST_NOP; inst_o <= `INST_NOP;
inst_addr_o <= `ZeroWord; inst_addr_o <= `ZeroWord;
end else if (hold_flag_ex_i == `HoldEnable) begin
inst_o <= `INST_NOP;
inst_addr_o <= `ZeroWord;
end else begin end else begin
inst_o <= inst_i; inst_o <= inst_i;
inst_addr_o <= inst_addr_i; inst_addr_o <= inst_addr_i;

View File

@ -53,6 +53,13 @@ module openriscv_core (
wire[`SramAddrBus] ex_sram_waddr_o; wire[`SramAddrBus] ex_sram_waddr_o;
wire ex_jump_flag_o; wire ex_jump_flag_o;
wire[`RegBus] ex_jump_addr_o; wire[`RegBus] ex_jump_addr_o;
wire[`RegBus] ex_div_dividend_o;
wire[`RegBus] ex_div_divisor_o;
wire ex_div_start_o;
wire ex_hold_flag_o;
wire[`RegBus] ex_hold_addr_o;
wire ex_reg_we_o;
wire[`RegAddrBus] ex_reg_waddr_o;
// regs // regs
wire[`RegBus] regs_rdata1_o; wire[`RegBus] regs_rdata1_o;
@ -62,6 +69,10 @@ module openriscv_core (
wire[`SramBus] ram_pc_rdata_o; wire[`SramBus] ram_pc_rdata_o;
wire[`SramBus] ram_ex_rdata_o; wire[`SramBus] ram_ex_rdata_o;
// div
wire[`DoubleRegBus] div_result_o;
wire div_ready_o;
sim_ram u_sim_ram( sim_ram u_sim_ram(
.clk(clk), .clk(clk),
.rst(rst), .rst(rst),
@ -81,6 +92,8 @@ module openriscv_core (
.rst(rst), .rst(rst),
.pc_o(pc_pc_o), .pc_o(pc_pc_o),
.re_o(pc_re_o), .re_o(pc_re_o),
.hold_flag_ex_i(ex_hold_flag_o),
.hold_addr_ex_i(ex_hold_addr_o),
.jump_flag_ex_i(ex_jump_flag_o), .jump_flag_ex_i(ex_jump_flag_o),
.jump_addr_ex_i(ex_jump_addr_o) .jump_addr_ex_i(ex_jump_addr_o)
); );
@ -88,8 +101,8 @@ module openriscv_core (
regs u_regs( regs u_regs(
.clk(clk), .clk(clk),
.rst(rst), .rst(rst),
.we(id_reg_we_o), .we(ex_reg_we_o),
.waddr(id_reg_waddr_o), .waddr(ex_reg_waddr_o),
.wdata(ex_reg_wdata_o), .wdata(ex_reg_wdata_o),
.re1(id_reg1_re_o), .re1(id_reg1_re_o),
.raddr1(id_reg1_raddr_o), .raddr1(id_reg1_raddr_o),
@ -106,7 +119,8 @@ module openriscv_core (
.inst_addr_i(pc_pc_o), .inst_addr_i(pc_pc_o),
.inst_o(if_inst_o), .inst_o(if_inst_o),
.inst_addr_o(if_inst_addr_o), .inst_addr_o(if_inst_addr_o),
.jump_flag_ex_i(ex_jump_flag_o) .jump_flag_ex_i(ex_jump_flag_o),
.hold_flag_ex_i(ex_hold_flag_o)
); );
id u_id( id u_id(
@ -116,6 +130,7 @@ module openriscv_core (
.inst_addr_o(id_inst_addr_o), .inst_addr_o(id_inst_addr_o),
.inst_addr_i(if_inst_addr_o), .inst_addr_i(if_inst_addr_o),
.jump_flag_ex_i(ex_jump_flag_o), .jump_flag_ex_i(ex_jump_flag_o),
.hold_flag_ex_i(ex_hold_flag_o),
.reg1_re_o(id_reg1_re_o), .reg1_re_o(id_reg1_re_o),
.reg1_raddr_o(id_reg1_raddr_o), .reg1_raddr_o(id_reg1_raddr_o),
.reg2_re_o(id_reg2_re_o), .reg2_re_o(id_reg2_re_o),
@ -134,15 +149,36 @@ module openriscv_core (
.inst_i(id_inst_o), .inst_i(id_inst_o),
.inst_addr_i(id_inst_addr_o), .inst_addr_i(id_inst_addr_o),
.inst_valid_i(id_inst_valid_o), .inst_valid_i(id_inst_valid_o),
.reg_we_i(id_reg_we_o),
.reg_waddr_i(id_reg_waddr_o),
.reg1_rdata_i(regs_rdata1_o), .reg1_rdata_i(regs_rdata1_o),
.reg2_rdata_i(regs_rdata2_o), .reg2_rdata_i(regs_rdata2_o),
.reg_wdata_o(ex_reg_wdata_o), .reg_wdata_o(ex_reg_wdata_o),
.reg_we_o(ex_reg_we_o),
.reg_waddr_o(ex_reg_waddr_o),
.sram_rdata_i(ram_ex_rdata_o), .sram_rdata_i(ram_ex_rdata_o),
.sram_wdata_o(ex_sram_wdata_o), .sram_wdata_o(ex_sram_wdata_o),
.sram_raddr_o(ex_sram_raddr_o), .sram_raddr_o(ex_sram_raddr_o),
.sram_waddr_o(ex_sram_waddr_o), .sram_waddr_o(ex_sram_waddr_o),
.div_dividend_o(ex_div_dividend_o),
.div_divisor_o(ex_div_divisor_o),
.div_ready_i(div_ready_o),
.div_result_i(div_result_o),
.div_start_o(ex_div_start_o),
.hold_flag_o(ex_hold_flag_o),
.hold_addr_o(ex_hold_addr_o),
.jump_flag_o(ex_jump_flag_o), .jump_flag_o(ex_jump_flag_o),
.jump_addr_o(ex_jump_addr_o) .jump_addr_o(ex_jump_addr_o)
); );
div u_div(
.clk(clk),
.rst(rst),
.dividend_i(ex_div_dividend_o),
.divisor_i(ex_div_divisor_o),
.start_i(ex_div_start_o),
.result_o(div_result_o),
.ready_o(div_ready_o)
);
endmodule endmodule

View File

@ -25,6 +25,9 @@ module pc_reg (
input wire jump_flag_ex_i, input wire jump_flag_ex_i,
input wire[`RegBus] jump_addr_ex_i, input wire[`RegBus] jump_addr_ex_i,
input wire hold_flag_ex_i,
input wire[`RegBus] hold_addr_ex_i,
output reg[`SramAddrBus] pc_o, output reg[`SramAddrBus] pc_o,
output reg re_o output reg re_o
@ -39,6 +42,9 @@ module pc_reg (
end else if (jump_flag_ex_i == `JumpEnable) begin end else if (jump_flag_ex_i == `JumpEnable) begin
pc_o <= jump_addr_ex_i; pc_o <= jump_addr_ex_i;
offset <= jump_addr_ex_i + 4'h4; offset <= jump_addr_ex_i + 4'h4;
end else if (hold_flag_ex_i == `HoldEnable) begin
pc_o <= hold_addr_ex_i;
offset <= hold_addr_ex_i;
end else begin end else begin
pc_o <= offset; pc_o <= offset;
offset <= offset + 4'h4; offset <= offset + 4'h4;

View File

@ -53,7 +53,7 @@ module openriscv_core_tb;
// sim timeout // sim timeout
initial begin initial begin
#100000 #5000000
$display("Time Out."); $display("Time Out.");
$finish; $finish;
end end

View File

@ -1,2 +1,2 @@
iverilog -s openriscv_core_tb -o out.vvp -I ..\rtl openriscv_core_tb.v ..\rtl\defines.v ..\rtl\ex.v ..\rtl\id.v ..\rtl\openriscv_core.v ..\rtl\pc_reg.v ..\rtl\regs.v ..\rtl\sim_ram.v ..\rtl\if_id.v iverilog -s openriscv_core_tb -o out.vvp -I ..\rtl openriscv_core_tb.v ..\rtl\defines.v ..\rtl\ex.v ..\rtl\id.v ..\rtl\openriscv_core.v ..\rtl\pc_reg.v ..\rtl\regs.v ..\rtl\sim_ram.v ..\rtl\if_id.v ..\rtl\div.v
vvp out.vvp vvp out.vvp

View File

@ -1,3 +1,3 @@
..\tools\BinToMem_CLI.exe %1 %2 ..\tools\BinToMem_CLI.exe %1 %2
iverilog -s openriscv_core_tb -o out.vvp -I ..\rtl openriscv_core_tb.v ..\rtl\defines.v ..\rtl\ex.v ..\rtl\id.v ..\rtl\openriscv_core.v ..\rtl\pc_reg.v ..\rtl\regs.v ..\rtl\sim_ram.v ..\rtl\if_id.v iverilog -s openriscv_core_tb -o out.vvp -I ..\rtl openriscv_core_tb.v ..\rtl\defines.v ..\rtl\ex.v ..\rtl\id.v ..\rtl\openriscv_core.v ..\rtl\pc_reg.v ..\rtl\regs.v ..\rtl\sim_ram.v ..\rtl\if_id.v ..\rtl\div.v
vvp out.vvp vvp out.vvp

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,105 @@
generated/rv32um-p-div: file format elf32-littleriscv
Disassembly of section .text.init:
00000000 <_start>:
0: 00000d13 li s10,0
4: 00000d93 li s11,0
00000008 <test_2>:
8: 01400093 li ra,20
c: 00600113 li sp,6
10: 0220cf33 div t5,ra,sp
14: 00300e93 li t4,3
18: 00200193 li gp,2
1c: 0ddf1463 bne t5,t4,e4 <fail>
00000020 <test_3>:
20: fec00093 li ra,-20
24: 00600113 li sp,6
28: 0220cf33 div t5,ra,sp
2c: ffd00e93 li t4,-3
30: 00300193 li gp,3
34: 0bdf1863 bne t5,t4,e4 <fail>
00000038 <test_4>:
38: 01400093 li ra,20
3c: ffa00113 li sp,-6
40: 0220cf33 div t5,ra,sp
44: ffd00e93 li t4,-3
48: 00400193 li gp,4
4c: 09df1c63 bne t5,t4,e4 <fail>
00000050 <test_5>:
50: fec00093 li ra,-20
54: ffa00113 li sp,-6
58: 0220cf33 div t5,ra,sp
5c: 00300e93 li t4,3
60: 00500193 li gp,5
64: 09df1063 bne t5,t4,e4 <fail>
00000068 <test_6>:
68: 00000093 li ra,0
6c: 00100113 li sp,1
70: 0220cf33 div t5,ra,sp
74: 00000e93 li t4,0
78: 00600193 li gp,6
7c: 07df1463 bne t5,t4,e4 <fail>
00000080 <test_7>:
80: 00000093 li ra,0
84: fff00113 li sp,-1
88: 0220cf33 div t5,ra,sp
8c: 00000e93 li t4,0
90: 00700193 li gp,7
94: 05df1863 bne t5,t4,e4 <fail>
00000098 <test_8>:
98: 00000093 li ra,0
9c: 00000113 li sp,0
a0: 0220cf33 div t5,ra,sp
a4: fff00e93 li t4,-1
a8: 00800193 li gp,8
ac: 03df1c63 bne t5,t4,e4 <fail>
000000b0 <test_9>:
b0: 00100093 li ra,1
b4: 00000113 li sp,0
b8: 0220cf33 div t5,ra,sp
bc: fff00e93 li t4,-1
c0: 00900193 li gp,9
c4: 03df1063 bne t5,t4,e4 <fail>
000000c8 <test_10>:
c8: 00000093 li ra,0
cc: 00000113 li sp,0
d0: 0220cf33 div t5,ra,sp
d4: fff00e93 li t4,-1
d8: 00a00193 li gp,10
dc: 01df1463 bne t5,t4,e4 <fail>
e0: 00301863 bne zero,gp,f0 <pass>
000000e4 <fail>:
e4: 00100d13 li s10,1
e8: 00000d93 li s11,0
000000ec <loop_fail>:
ec: 0000006f j ec <loop_fail>
000000f0 <pass>:
f0: 00100d13 li s10,1
f4: 00100d93 li s11,1
000000f8 <loop_pass>:
f8: 0000006f j f8 <loop_pass>
...
Disassembly of section .tohost:
00000140 <tohost>:
...
00000180 <fromhost>:
...

View File

@ -0,0 +1,24 @@
@00000000
13 0D 00 00 93 0D 00 00 93 00 40 01 13 01 60 00
33 CF 20 02 93 0E 30 00 93 01 20 00 63 14 DF 0D
93 00 C0 FE 13 01 60 00 33 CF 20 02 93 0E D0 FF
93 01 30 00 63 18 DF 0B 93 00 40 01 13 01 A0 FF
33 CF 20 02 93 0E D0 FF 93 01 40 00 63 1C DF 09
93 00 C0 FE 13 01 A0 FF 33 CF 20 02 93 0E 30 00
93 01 50 00 63 10 DF 09 93 00 00 00 13 01 10 00
33 CF 20 02 93 0E 00 00 93 01 60 00 63 14 DF 07
93 00 00 00 13 01 F0 FF 33 CF 20 02 93 0E 00 00
93 01 70 00 63 18 DF 05 93 00 00 00 13 01 00 00
33 CF 20 02 93 0E F0 FF 93 01 80 00 63 1C DF 03
93 00 10 00 13 01 00 00 33 CF 20 02 93 0E F0 FF
93 01 90 00 63 10 DF 03 93 00 00 00 13 01 00 00
33 CF 20 02 93 0E F0 FF 93 01 A0 00 63 14 DF 01
63 18 30 00 13 0D 10 00 93 0D 00 00 6F 00 00 00
13 0D 10 00 93 0D 10 00 6F 00 00 00 00 00 00 00
00 00 00 00
@00000140
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,107 @@
generated/rv32um-p-divu: file format elf32-littleriscv
Disassembly of section .text.init:
00000000 <_start>:
0: 00000d13 li s10,0
4: 00000d93 li s11,0
00000008 <test_2>:
8: 01400093 li ra,20
c: 00600113 li sp,6
10: 0220df33 divu t5,ra,sp
14: 00300e93 li t4,3
18: 00200193 li gp,2
1c: 0ddf1663 bne t5,t4,e8 <fail>
00000020 <test_3>:
20: fec00093 li ra,-20
24: 00600113 li sp,6
28: 0220df33 divu t5,ra,sp
2c: 2aaabeb7 lui t4,0x2aaab
30: aa7e8e93 addi t4,t4,-1369 # 2aaaaaa7 <begin_signature+0x2aaa9aa7>
34: 00300193 li gp,3
38: 0bdf1863 bne t5,t4,e8 <fail>
0000003c <test_4>:
3c: 01400093 li ra,20
40: ffa00113 li sp,-6
44: 0220df33 divu t5,ra,sp
48: 00000e93 li t4,0
4c: 00400193 li gp,4
50: 09df1c63 bne t5,t4,e8 <fail>
00000054 <test_5>:
54: fec00093 li ra,-20
58: ffa00113 li sp,-6
5c: 0220df33 divu t5,ra,sp
60: 00000e93 li t4,0
64: 00500193 li gp,5
68: 09df1063 bne t5,t4,e8 <fail>
0000006c <test_6>:
6c: 800000b7 lui ra,0x80000
70: 00100113 li sp,1
74: 0220df33 divu t5,ra,sp
78: 80000eb7 lui t4,0x80000
7c: 00600193 li gp,6
80: 07df1463 bne t5,t4,e8 <fail>
00000084 <test_7>:
84: 800000b7 lui ra,0x80000
88: fff00113 li sp,-1
8c: 0220df33 divu t5,ra,sp
90: 00000e93 li t4,0
94: 00700193 li gp,7
98: 05df1863 bne t5,t4,e8 <fail>
0000009c <test_8>:
9c: 800000b7 lui ra,0x80000
a0: 00000113 li sp,0
a4: 0220df33 divu t5,ra,sp
a8: fff00e93 li t4,-1
ac: 00800193 li gp,8
b0: 03df1c63 bne t5,t4,e8 <fail>
000000b4 <test_9>:
b4: 00100093 li ra,1
b8: 00000113 li sp,0
bc: 0220df33 divu t5,ra,sp
c0: fff00e93 li t4,-1
c4: 00900193 li gp,9
c8: 03df1063 bne t5,t4,e8 <fail>
000000cc <test_10>:
cc: 00000093 li ra,0
d0: 00000113 li sp,0
d4: 0220df33 divu t5,ra,sp
d8: fff00e93 li t4,-1
dc: 00a00193 li gp,10
e0: 01df1463 bne t5,t4,e8 <fail>
e4: 00301863 bne zero,gp,f4 <pass>
000000e8 <fail>:
e8: 00100d13 li s10,1
ec: 00000d93 li s11,0
000000f0 <loop_fail>:
f0: 0000006f j f0 <loop_fail>
000000f4 <pass>:
f4: 00100d13 li s10,1
f8: 00100d93 li s11,1
000000fc <loop_pass>:
fc: 0000006f j fc <loop_pass>
100: 0000 unimp
...
Disassembly of section .tohost:
00000140 <tohost>:
...
00000180 <fromhost>:
...

View File

@ -0,0 +1,24 @@
@00000000
13 0D 00 00 93 0D 00 00 93 00 40 01 13 01 60 00
33 DF 20 02 93 0E 30 00 93 01 20 00 63 16 DF 0D
93 00 C0 FE 13 01 60 00 33 DF 20 02 B7 BE AA 2A
93 8E 7E AA 93 01 30 00 63 18 DF 0B 93 00 40 01
13 01 A0 FF 33 DF 20 02 93 0E 00 00 93 01 40 00
63 1C DF 09 93 00 C0 FE 13 01 A0 FF 33 DF 20 02
93 0E 00 00 93 01 50 00 63 10 DF 09 B7 00 00 80
13 01 10 00 33 DF 20 02 B7 0E 00 80 93 01 60 00
63 14 DF 07 B7 00 00 80 13 01 F0 FF 33 DF 20 02
93 0E 00 00 93 01 70 00 63 18 DF 05 B7 00 00 80
13 01 00 00 33 DF 20 02 93 0E F0 FF 93 01 80 00
63 1C DF 03 93 00 10 00 13 01 00 00 33 DF 20 02
93 0E F0 FF 93 01 90 00 63 10 DF 03 93 00 00 00
13 01 00 00 33 DF 20 02 93 0E F0 FF 93 01 A0 00
63 14 DF 01 63 18 30 00 13 0D 10 00 93 0D 00 00
6F 00 00 00 13 0D 10 00 93 0D 10 00 6F 00 00 00
00 00 00 00
@00000140
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,105 @@
generated/rv32um-p-rem: file format elf32-littleriscv
Disassembly of section .text.init:
00000000 <_start>:
0: 00000d13 li s10,0
4: 00000d93 li s11,0
00000008 <test_2>:
8: 01400093 li ra,20
c: 00600113 li sp,6
10: 0220ef33 rem t5,ra,sp
14: 00200e93 li t4,2
18: 00200193 li gp,2
1c: 0ddf1463 bne t5,t4,e4 <fail>
00000020 <test_3>:
20: fec00093 li ra,-20
24: 00600113 li sp,6
28: 0220ef33 rem t5,ra,sp
2c: ffe00e93 li t4,-2
30: 00300193 li gp,3
34: 0bdf1863 bne t5,t4,e4 <fail>
00000038 <test_4>:
38: 01400093 li ra,20
3c: ffa00113 li sp,-6
40: 0220ef33 rem t5,ra,sp
44: 00200e93 li t4,2
48: 00400193 li gp,4
4c: 09df1c63 bne t5,t4,e4 <fail>
00000050 <test_5>:
50: fec00093 li ra,-20
54: ffa00113 li sp,-6
58: 0220ef33 rem t5,ra,sp
5c: ffe00e93 li t4,-2
60: 00500193 li gp,5
64: 09df1063 bne t5,t4,e4 <fail>
00000068 <test_6>:
68: 00000093 li ra,0
6c: 00100113 li sp,1
70: 0220ef33 rem t5,ra,sp
74: 00000e93 li t4,0
78: 00600193 li gp,6
7c: 07df1463 bne t5,t4,e4 <fail>
00000080 <test_7>:
80: 00000093 li ra,0
84: fff00113 li sp,-1
88: 0220ef33 rem t5,ra,sp
8c: 00000e93 li t4,0
90: 00700193 li gp,7
94: 05df1863 bne t5,t4,e4 <fail>
00000098 <test_8>:
98: 00000093 li ra,0
9c: 00000113 li sp,0
a0: 0220ef33 rem t5,ra,sp
a4: 00000e93 li t4,0
a8: 00800193 li gp,8
ac: 03df1c63 bne t5,t4,e4 <fail>
000000b0 <test_9>:
b0: 00100093 li ra,1
b4: 00000113 li sp,0
b8: 0220ef33 rem t5,ra,sp
bc: 00100e93 li t4,1
c0: 00900193 li gp,9
c4: 03df1063 bne t5,t4,e4 <fail>
000000c8 <test_10>:
c8: 00000093 li ra,0
cc: 00000113 li sp,0
d0: 0220ef33 rem t5,ra,sp
d4: 00000e93 li t4,0
d8: 00a00193 li gp,10
dc: 01df1463 bne t5,t4,e4 <fail>
e0: 00301863 bne zero,gp,f0 <pass>
000000e4 <fail>:
e4: 00100d13 li s10,1
e8: 00000d93 li s11,0
000000ec <loop_fail>:
ec: 0000006f j ec <loop_fail>
000000f0 <pass>:
f0: 00100d13 li s10,1
f4: 00100d93 li s11,1
000000f8 <loop_pass>:
f8: 0000006f j f8 <loop_pass>
...
Disassembly of section .tohost:
00000140 <tohost>:
...
00000180 <fromhost>:
...

View File

@ -0,0 +1,24 @@
@00000000
13 0D 00 00 93 0D 00 00 93 00 40 01 13 01 60 00
33 EF 20 02 93 0E 20 00 93 01 20 00 63 14 DF 0D
93 00 C0 FE 13 01 60 00 33 EF 20 02 93 0E E0 FF
93 01 30 00 63 18 DF 0B 93 00 40 01 13 01 A0 FF
33 EF 20 02 93 0E 20 00 93 01 40 00 63 1C DF 09
93 00 C0 FE 13 01 A0 FF 33 EF 20 02 93 0E E0 FF
93 01 50 00 63 10 DF 09 93 00 00 00 13 01 10 00
33 EF 20 02 93 0E 00 00 93 01 60 00 63 14 DF 07
93 00 00 00 13 01 F0 FF 33 EF 20 02 93 0E 00 00
93 01 70 00 63 18 DF 05 93 00 00 00 13 01 00 00
33 EF 20 02 93 0E 00 00 93 01 80 00 63 1C DF 03
93 00 10 00 13 01 00 00 33 EF 20 02 93 0E 10 00
93 01 90 00 63 10 DF 03 93 00 00 00 13 01 00 00
33 EF 20 02 93 0E 00 00 93 01 A0 00 63 14 DF 01
63 18 30 00 13 0D 10 00 93 0D 00 00 6F 00 00 00
13 0D 10 00 93 0D 10 00 6F 00 00 00 00 00 00 00
00 00 00 00
@00000140
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,105 @@
generated/rv32um-p-remu: file format elf32-littleriscv
Disassembly of section .text.init:
00000000 <_start>:
0: 00000d13 li s10,0
4: 00000d93 li s11,0
00000008 <test_2>:
8: 01400093 li ra,20
c: 00600113 li sp,6
10: 0220ff33 remu t5,ra,sp
14: 00200e93 li t4,2
18: 00200193 li gp,2
1c: 0ddf1463 bne t5,t4,e4 <fail>
00000020 <test_3>:
20: fec00093 li ra,-20
24: 00600113 li sp,6
28: 0220ff33 remu t5,ra,sp
2c: 00200e93 li t4,2
30: 00300193 li gp,3
34: 0bdf1863 bne t5,t4,e4 <fail>
00000038 <test_4>:
38: 01400093 li ra,20
3c: ffa00113 li sp,-6
40: 0220ff33 remu t5,ra,sp
44: 01400e93 li t4,20
48: 00400193 li gp,4
4c: 09df1c63 bne t5,t4,e4 <fail>
00000050 <test_5>:
50: fec00093 li ra,-20
54: ffa00113 li sp,-6
58: 0220ff33 remu t5,ra,sp
5c: fec00e93 li t4,-20
60: 00500193 li gp,5
64: 09df1063 bne t5,t4,e4 <fail>
00000068 <test_6>:
68: 00000093 li ra,0
6c: 00100113 li sp,1
70: 0220ff33 remu t5,ra,sp
74: 00000e93 li t4,0
78: 00600193 li gp,6
7c: 07df1463 bne t5,t4,e4 <fail>
00000080 <test_7>:
80: 00000093 li ra,0
84: fff00113 li sp,-1
88: 0220ff33 remu t5,ra,sp
8c: 00000e93 li t4,0
90: 00700193 li gp,7
94: 05df1863 bne t5,t4,e4 <fail>
00000098 <test_8>:
98: 00000093 li ra,0
9c: 00000113 li sp,0
a0: 0220ff33 remu t5,ra,sp
a4: 00000e93 li t4,0
a8: 00800193 li gp,8
ac: 03df1c63 bne t5,t4,e4 <fail>
000000b0 <test_9>:
b0: 00100093 li ra,1
b4: 00000113 li sp,0
b8: 0220ff33 remu t5,ra,sp
bc: 00100e93 li t4,1
c0: 00900193 li gp,9
c4: 03df1063 bne t5,t4,e4 <fail>
000000c8 <test_10>:
c8: 00000093 li ra,0
cc: 00000113 li sp,0
d0: 0220ff33 remu t5,ra,sp
d4: 00000e93 li t4,0
d8: 00a00193 li gp,10
dc: 01df1463 bne t5,t4,e4 <fail>
e0: 00301863 bne zero,gp,f0 <pass>
000000e4 <fail>:
e4: 00100d13 li s10,1
e8: 00000d93 li s11,0
000000ec <loop_fail>:
ec: 0000006f j ec <loop_fail>
000000f0 <pass>:
f0: 00100d13 li s10,1
f4: 00100d93 li s11,1
000000f8 <loop_pass>:
f8: 0000006f j f8 <loop_pass>
...
Disassembly of section .tohost:
00000140 <tohost>:
...
00000180 <fromhost>:
...

View File

@ -0,0 +1,24 @@
@00000000
13 0D 00 00 93 0D 00 00 93 00 40 01 13 01 60 00
33 FF 20 02 93 0E 20 00 93 01 20 00 63 14 DF 0D
93 00 C0 FE 13 01 60 00 33 FF 20 02 93 0E 20 00
93 01 30 00 63 18 DF 0B 93 00 40 01 13 01 A0 FF
33 FF 20 02 93 0E 40 01 93 01 40 00 63 1C DF 09
93 00 C0 FE 13 01 A0 FF 33 FF 20 02 93 0E C0 FE
93 01 50 00 63 10 DF 09 93 00 00 00 13 01 10 00
33 FF 20 02 93 0E 00 00 93 01 60 00 63 14 DF 07
93 00 00 00 13 01 F0 FF 33 FF 20 02 93 0E 00 00
93 01 70 00 63 18 DF 05 93 00 00 00 13 01 00 00
33 FF 20 02 93 0E 00 00 93 01 80 00 63 1C DF 03
93 00 10 00 13 01 00 00 33 FF 20 02 93 0E 10 00
93 01 90 00 63 10 DF 03 93 00 00 00 13 01 00 00
33 FF 20 02 93 0E 00 00 93 01 A0 00 63 14 DF 01
63 18 30 00 13 0D 10 00 93 0D 00 00 6F 00 00 00
13 0D 10 00 93 0D 10 00 6F 00 00 00 00 00 00 00
00 00 00 00
@00000140
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00

View File

@ -4,6 +4,7 @@
rv32um_sc_tests = \ rv32um_sc_tests = \
mul mulh mulhsu mulhu \ mul mulh mulhsu mulhu \
div divu rem remu
rv32um_p_tests = $(addprefix rv32um-p-, $(rv32um_sc_tests)) rv32um_p_tests = $(addprefix rv32um-p-, $(rv32um_sc_tests))

41
tests/isa/rv32um/div.S Normal file
View File

@ -0,0 +1,41 @@
# See LICENSE for license details.
#*****************************************************************************
# div.S
#-----------------------------------------------------------------------------
#
# Test div instruction.
#
#include "riscv_test.h"
#include "test_macros.h"
RVTEST_RV32U
RVTEST_CODE_BEGIN
#-------------------------------------------------------------
# Arithmetic tests
#-------------------------------------------------------------
TEST_RR_OP( 2, div, 3, 20, 6 );
TEST_RR_OP( 3, div, -3, -20, 6 );
TEST_RR_OP( 4, div, -3, 20, -6 );
TEST_RR_OP( 5, div, 3, -20, -6 );
TEST_RR_OP( 6, div, -1<<63, -1<<63, 1 );
TEST_RR_OP( 7, div, -1<<63, -1<<63, -1 );
TEST_RR_OP( 8, div, -1, -1<<63, 0 );
TEST_RR_OP( 9, div, -1, 1, 0 );
TEST_RR_OP(10, div, -1, 0, 0 );
TEST_PASSFAIL
RVTEST_CODE_END
.data
RVTEST_DATA_BEGIN
TEST_DATA
RVTEST_DATA_END

41
tests/isa/rv32um/divu.S Normal file
View File

@ -0,0 +1,41 @@
# See LICENSE for license details.
#*****************************************************************************
# divu.S
#-----------------------------------------------------------------------------
#
# Test divu instruction.
#
#include "riscv_test.h"
#include "test_macros.h"
RVTEST_RV32U
RVTEST_CODE_BEGIN
#-------------------------------------------------------------
# Arithmetic tests
#-------------------------------------------------------------
TEST_RR_OP( 2, divu, 3, 20, 6 );
TEST_RR_OP( 3, divu, 715827879, -20, 6 );
TEST_RR_OP( 4, divu, 0, 20, -6 );
TEST_RR_OP( 5, divu, 0, -20, -6 );
TEST_RR_OP( 6, divu, -1<<31, -1<<31, 1 );
TEST_RR_OP( 7, divu, 0, -1<<31, -1 );
TEST_RR_OP( 8, divu, -1, -1<<31, 0 );
TEST_RR_OP( 9, divu, -1, 1, 0 );
TEST_RR_OP(10, divu, -1, 0, 0 );
TEST_PASSFAIL
RVTEST_CODE_END
.data
RVTEST_DATA_BEGIN
TEST_DATA
RVTEST_DATA_END

41
tests/isa/rv32um/rem.S Normal file
View File

@ -0,0 +1,41 @@
# See LICENSE for license details.
#*****************************************************************************
# rem.S
#-----------------------------------------------------------------------------
#
# Test rem instruction.
#
#include "riscv_test.h"
#include "test_macros.h"
RVTEST_RV32U
RVTEST_CODE_BEGIN
#-------------------------------------------------------------
# Arithmetic tests
#-------------------------------------------------------------
TEST_RR_OP( 2, rem, 2, 20, 6 );
TEST_RR_OP( 3, rem, -2, -20, 6 );
TEST_RR_OP( 4, rem, 2, 20, -6 );
TEST_RR_OP( 5, rem, -2, -20, -6 );
TEST_RR_OP( 6, rem, 0, -1<<63, 1 );
TEST_RR_OP( 7, rem, 0, -1<<63, -1 );
TEST_RR_OP( 8, rem, -1<<63, -1<<63, 0 );
TEST_RR_OP( 9, rem, 1, 1, 0 );
TEST_RR_OP(10, rem, 0, 0, 0 );
TEST_PASSFAIL
RVTEST_CODE_END
.data
RVTEST_DATA_BEGIN
TEST_DATA
RVTEST_DATA_END

41
tests/isa/rv32um/remu.S Normal file
View File

@ -0,0 +1,41 @@
# See LICENSE for license details.
#*****************************************************************************
# remu.S
#-----------------------------------------------------------------------------
#
# Test remu instruction.
#
#include "riscv_test.h"
#include "test_macros.h"
RVTEST_RV32U
RVTEST_CODE_BEGIN
#-------------------------------------------------------------
# Arithmetic tests
#-------------------------------------------------------------
TEST_RR_OP( 2, remu, 2, 20, 6 );
TEST_RR_OP( 3, remu, 2, -20, 6 );
TEST_RR_OP( 4, remu, 20, 20, -6 );
TEST_RR_OP( 5, remu, -20, -20, -6 );
TEST_RR_OP( 6, remu, 0, -1<<63, 1 );
TEST_RR_OP( 7, remu, -1<<63, -1<<63, -1 );
TEST_RR_OP( 8, remu, -1<<63, -1<<63, 0 );
TEST_RR_OP( 9, remu, 1, 1, 0 );
TEST_RR_OP(10, remu, 0, 0, 0 );
TEST_PASSFAIL
RVTEST_CODE_END
.data
RVTEST_DATA_BEGIN
TEST_DATA
RVTEST_DATA_END