Line 42... |
Line 42... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.2 2002/01/14 06:18:22 lampret
|
|
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
|
|
//
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
//
|
//
|
// Revision 1.10 2001/11/12 01:45:40 lampret
|
// Revision 1.10 2001/11/12 01:45:40 lampret
|
// Moved flag bit into SR. Changed RF enable from constant enable to dynamic enable for read ports.
|
// Moved flag bit into SR. Changed RF enable from constant enable to dynamic enable for read ports.
|
Line 101... |
Line 104... |
// Internal wires and regs
|
// Internal wires and regs
|
//
|
//
|
reg [width-1:0] result;
|
reg [width-1:0] result;
|
reg [width-1:0] shifted_rotated;
|
reg [width-1:0] shifted_rotated;
|
reg flagforw;
|
reg flagforw;
|
|
reg flagcomp;
|
reg flag_we;
|
reg flag_we;
|
integer d1;
|
integer d1;
|
integer d2;
|
integer d2;
|
wire [width-1:0] comp_a;
|
wire [width-1:0] comp_a;
|
wire [width-1:0] comp_b;
|
wire [width-1:0] comp_b;
|
`ifdef OR1200_IMPL_ALU_COMP1
|
`ifdef OR1200_IMPL_ALU_COMP1
|
wire a_eq_b;
|
wire a_eq_b;
|
wire a_lt_b;
|
wire a_lt_b;
|
`endif
|
`endif
|
|
wire [width-1:0] result_sum;
|
|
wire [width-1:0] result_and;
|
|
|
//
|
//
|
// Combinatorial logic
|
// Combinatorial logic
|
//
|
//
|
assign comp_a = {a[width-1] ^ comp_op[3] , a[width-2:0]};
|
assign comp_a = {a[width-1] ^ comp_op[3] , a[width-2:0]};
|
assign comp_b = {b[width-1] ^ comp_op[3] , b[width-2:0]};
|
assign comp_b = {b[width-1] ^ comp_op[3] , b[width-2:0]};
|
`ifdef OR1200_IMPL_ALU_COMP1
|
`ifdef OR1200_IMPL_ALU_COMP1
|
assign a_eq_b = (comp_a == comp_b);
|
assign a_eq_b = (comp_a == comp_b);
|
assign a_lt_b = (comp_a < comp_b);
|
assign a_lt_b = (comp_a < comp_b);
|
`endif
|
`endif
|
|
assign result_sum = a + b;
|
|
assign result_and = a & b;
|
|
|
//
|
//
|
// Simulation check for bad ALU behavior
|
// Simulation check for bad ALU behavior
|
//
|
//
|
`ifdef OR1200_WARNINGS
|
`ifdef OR1200_WARNINGS
|
Line 136... |
Line 144... |
`endif
|
`endif
|
|
|
//
|
//
|
// Central part of the ALU
|
// Central part of the ALU
|
//
|
//
|
always @(alu_op or a or b or macrc_op or shifted_rotated or mult_mac_result) begin
|
always @(alu_op or a or b or result_sum or result_and or macrc_op or shifted_rotated or mult_mac_result) begin
|
casex (alu_op) // synopsys parallel_case full_case
|
casex (alu_op) // synopsys parallel_case full_case
|
`OR1200_ALUOP_SHROT : begin
|
`OR1200_ALUOP_SHROT : begin
|
result = shifted_rotated;
|
result = shifted_rotated;
|
flag_we = 1'b0;
|
|
end
|
end
|
`OR1200_ALUOP_ADD : begin
|
`OR1200_ALUOP_ADD : begin
|
result = a + b;
|
result = result_sum;
|
flag_we = 1'b0;
|
|
end
|
end
|
`OR1200_ALUOP_SUB : begin
|
`OR1200_ALUOP_SUB : begin
|
result = a - b;
|
result = a - b;
|
flag_we = 1'b0;
|
|
end
|
end
|
`OR1200_ALUOP_XOR : begin
|
`OR1200_ALUOP_XOR : begin
|
result = a ^ b;
|
result = a ^ b;
|
flag_we = 1'b0;
|
|
end
|
end
|
`OR1200_ALUOP_OR : begin
|
`OR1200_ALUOP_OR : begin
|
result = a | b;
|
result = a | b;
|
flag_we = 1'b0;
|
|
end
|
end
|
`OR1200_ALUOP_IMM : begin
|
`OR1200_ALUOP_IMM : begin
|
result = b;
|
result = b;
|
flag_we = 1'b0;
|
|
end
|
end
|
`OR1200_ALUOP_MOVHI : begin
|
`OR1200_ALUOP_MOVHI : begin
|
if (macrc_op) begin
|
if (macrc_op) begin
|
result = mult_mac_result;
|
result = mult_mac_result;
|
flag_we = 1'b0;
|
|
end
|
end
|
else begin
|
else begin
|
result = b << 16;
|
result = b << 16;
|
flag_we = 1'b0;
|
|
end
|
end
|
end
|
end
|
`OR1200_ALUOP_MUL : begin
|
`OR1200_ALUOP_MUL : begin
|
result = mult_mac_result;
|
result = mult_mac_result;
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: MUL operation: %h * %h = %h", $time, a, b, mult_mac_result);
|
$display("%t: MUL operation: %h * %h = %h", $time, a, b, mult_mac_result);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
flag_we = 1'b0;
|
|
end
|
end
|
// synopsys translate_off
|
// synopsys translate_off
|
`ifdef OR1200_SIM_ALU_DIV
|
`ifdef OR1200_SIM_ALU_DIV
|
`OR1200_ALUOP_DIV : begin
|
`OR1200_ALUOP_DIV : begin
|
d1 = a;
|
d1 = a;
|
Line 191... |
Line 190... |
$display("DIV operation: %d / %d = %d", d1, d2, d1/d2);
|
$display("DIV operation: %d / %d = %d", d1, d2, d1/d2);
|
if (d2)
|
if (d2)
|
result = d1 / d2;
|
result = d1 / d2;
|
else
|
else
|
result = 32'h00000000;
|
result = 32'h00000000;
|
flag_we = 1'b0;
|
|
end
|
end
|
`endif
|
`endif
|
`ifdef OR1200_SIM_ALU_DIVU
|
`ifdef OR1200_SIM_ALU_DIVU
|
`OR1200_ALUOP_DIVU : begin
|
`OR1200_ALUOP_DIVU : begin
|
if (b)
|
if (b)
|
result = a / b;
|
result = a / b;
|
else
|
else
|
result = 32'h00000000;
|
result = 32'h00000000;
|
flag_we = 1'b0;
|
|
end
|
end
|
`endif
|
`endif
|
// synopsys translate_on
|
// synopsys translate_on
|
|
`OR1200_ALUOP_COMP, `OR1200_ALUOP_AND: begin
|
|
result = result_and;
|
|
end
|
|
endcase
|
|
end
|
|
|
|
//
|
|
// Generate flag and flag write enable
|
|
//
|
|
always @(alu_op or result_sum or result_and or flagcomp) begin
|
|
casex (alu_op) // synopsys parallel_case full_case
|
|
`OR1200_ALUOP_ADD : begin
|
|
flagforw = (result_sum == 32'h0000_0000);
|
|
flag_we = 1'b0;
|
|
end
|
|
`OR1200_ALUOP_AND: begin
|
|
flagforw = (result_and == 32'h0000_0000);
|
|
flag_we = 1'b0;
|
|
end
|
`OR1200_ALUOP_COMP: begin
|
`OR1200_ALUOP_COMP: begin
|
|
flagforw = flagcomp;
|
flag_we = 1'b1;
|
flag_we = 1'b1;
|
result = 32'd0;
|
|
end
|
end
|
default : begin // `OR1200_ALUOP_AND
|
default: begin
|
result = a & b;
|
flagforw = 1'b0;
|
flag_we = 1'b0;
|
flag_we = 1'b0;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
|
|
Line 241... |
Line 257... |
//
|
//
|
`ifdef OR1200_IMPL_ALU_COMP1
|
`ifdef OR1200_IMPL_ALU_COMP1
|
always @(comp_op or a_eq_b or a_lt_b) begin
|
always @(comp_op or a_eq_b or a_lt_b) begin
|
case(comp_op[2:0]) // synopsys parallel_case full_case
|
case(comp_op[2:0]) // synopsys parallel_case full_case
|
`OR1200_COP_SFEQ:
|
`OR1200_COP_SFEQ:
|
flagforw = a_eq_b;
|
flagcomp = a_eq_b;
|
`OR1200_COP_SFNE:
|
`OR1200_COP_SFNE:
|
flagforw = ~a_eq_b;
|
flagcomp = ~a_eq_b;
|
`OR1200_COP_SFGT:
|
`OR1200_COP_SFGT:
|
flagforw = ~(a_eq_b | a_lt_b);
|
flagcomp = ~(a_eq_b | a_lt_b);
|
`OR1200_COP_SFGE:
|
`OR1200_COP_SFGE:
|
flagforw = ~a_lt_b;
|
flagcomp = ~a_lt_b;
|
`OR1200_COP_SFLT:
|
`OR1200_COP_SFLT:
|
flagforw = a_lt_b;
|
flagcomp = a_lt_b;
|
`OR1200_COP_SFLE:
|
`OR1200_COP_SFLE:
|
flagforw = a_eq_b | a_lt_b;
|
flagcomp = a_eq_b | a_lt_b;
|
// synopsys translate_off
|
|
default:
|
default:
|
flagforw = 1'bx;
|
flagcomp = 1'b0;
|
// synopsys translate_on
|
|
endcase
|
endcase
|
end
|
end
|
`endif
|
`endif
|
|
|
//
|
//
|
Line 267... |
Line 281... |
//
|
//
|
`ifdef OR1200_IMPL_ALU_COMP2
|
`ifdef OR1200_IMPL_ALU_COMP2
|
always @(comp_op or comp_a or comp_b) begin
|
always @(comp_op or comp_a or comp_b) begin
|
case(comp_op[2:0]) // synopsys parallel_case full_case
|
case(comp_op[2:0]) // synopsys parallel_case full_case
|
`OR1200_COP_SFEQ:
|
`OR1200_COP_SFEQ:
|
flagforw = (comp_a == comp_b);
|
flagcomp = (comp_a == comp_b);
|
`OR1200_COP_SFNE:
|
`OR1200_COP_SFNE:
|
flagforw = (comp_a != comp_b);
|
flagcomp = (comp_a != comp_b);
|
`OR1200_COP_SFGT:
|
`OR1200_COP_SFGT:
|
flagforw = (comp_a > comp_b);
|
flagcomp = (comp_a > comp_b);
|
`OR1200_COP_SFGE:
|
`OR1200_COP_SFGE:
|
flagforw = (comp_a >= comp_b);
|
flagcomp = (comp_a >= comp_b);
|
`OR1200_COP_SFLT:
|
`OR1200_COP_SFLT:
|
flagforw = (comp_a < comp_b);
|
flagcomp = (comp_a < comp_b);
|
`OR1200_COP_SFLE:
|
`OR1200_COP_SFLE:
|
flagforw = (comp_a <= comp_b);
|
flagcomp = (comp_a <= comp_b);
|
// synopsys translate_off
|
|
default:
|
default:
|
flagforw = 1'bx;
|
flagcomp = 1'b0;
|
// synopsys translate_on
|
|
endcase
|
endcase
|
end
|
end
|
`endif
|
`endif
|
|
|
endmodule
|
endmodule
|