OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_alu.v] - Diff between revs 640 and 642

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 640 Rev 642
Line 54... Line 54...
module or1200_alu(
module or1200_alu(
        a, b, mult_mac_result, macrc_op,
        a, b, mult_mac_result, macrc_op,
        alu_op, alu_op2, comp_op,
        alu_op, alu_op2, comp_op,
        cust5_op, cust5_limm,
        cust5_op, cust5_limm,
        result, flagforw, flag_we,
        result, flagforw, flag_we,
 
        ovforw, ov_we,
        cyforw, cy_we, carry, flag
        cyforw, cy_we, carry, flag
);
);
 
 
parameter width = `OR1200_OPERAND_WIDTH;
parameter width = `OR1200_OPERAND_WIDTH;
 
 
Line 76... Line 77...
output  [width-1:0]              result;
output  [width-1:0]              result;
output                          flagforw;
output                          flagforw;
output                          flag_we;
output                          flag_we;
output                          cyforw;
output                          cyforw;
output                          cy_we;
output                          cy_we;
 
output                          ovforw;
 
output                          ov_we;
input                           carry;
input                           carry;
input         flag;
input         flag;
 
 
//
//
// Internal wires and regs
// Internal wires and regs
Line 89... Line 92...
reg     [width-1:0]              extended;
reg     [width-1:0]              extended;
reg     [width-1:0]              result_cust5;
reg     [width-1:0]              result_cust5;
reg                             flagforw;
reg                             flagforw;
reg                             flagcomp;
reg                             flagcomp;
reg                             flag_we;
reg                             flag_we;
 
reg                             cyforw;
reg                             cy_we;
reg                             cy_we;
 
reg                             ovforw;
 
reg                             ov_we;
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_sum;
`ifdef OR1200_IMPL_ADDC
 
wire    [width-1:0]              result_csum;
 
wire                            cy_csum;
 
`endif
 
wire    [width-1:0]              result_and;
wire    [width-1:0]              result_and;
wire                            cy_sum;
wire                            cy_sum;
`ifdef OR1200_IMPL_SUB
`ifdef OR1200_IMPL_SUB
wire                            cy_sub;
wire                            cy_sub;
`endif
`endif
reg                             cyforw;
wire                            ov_sum;
 
wire    [width-1:0]              carry_in;
 
 
 
wire    [width-1:0]              b_mux;
 
 
 
 
 
 
//
//
// 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]};
Line 118... Line 125...
`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
`ifdef OR1200_IMPL_SUB
`ifdef OR1200_IMPL_SUB
assign cy_sub = a < b;
assign cy_sub = (comp_a < comp_b);
`endif
`endif
assign {cy_sum, result_sum} = a + b;
 
`ifdef OR1200_IMPL_ADDC
`ifdef OR1200_IMPL_ADDC
assign {cy_csum, result_csum} = a + b + {`OR1200_OPERAND_WIDTH'd0, carry};
assign carry_in = (alu_op==`OR1200_ALUOP_ADDC) ?
 
                  {{width-1{1'b0}},carry} : {width{1'b0}};
 
`else
 
assign carry_in = {width-1{1'b0}};
 
`endif
 
`ifdef OR1200_IMPL_SUB
 
assign b_mux = (alu_op==`OR1200_ALUOP_SUB) ? (~b)+1 : b;
 
`else
 
assign b_mux = b;
`endif
`endif
 
assign {cy_sum, result_sum} = (a + b_mux) + carry_in;
 
// Numbers either both +ve and bit 31 of result set
 
assign ov_sum = ((!a[width-1] & !b_mux[width-1]) & result_sum[width-1]) |
 
// or both -ve and bit 31 of result clear
 
                ((a[width-1] & b_mux[width-1]) & !result_sum[width-1]);
assign result_and = a & b;
assign result_and = a & b;
 
 
//
//
// Simulation check for bad ALU behavior
// Simulation check for bad ALU behavior
//
//
Line 143... Line 162...
//
//
// Central part of the ALU
// Central part of the ALU
//
//
always @(alu_op or alu_op2 or a or b or result_sum or result_and or macrc_op
always @(alu_op or alu_op2 or a or b or result_sum or result_and or macrc_op
         or shifted_rotated or mult_mac_result or flag or result_cust5 or carry
         or shifted_rotated or mult_mac_result or flag or result_cust5 or carry
`ifdef OR1200_IMPL_ADDC
 
         or result_csum
 
`endif
 
`ifdef OR1200_IMPL_ALU_EXT
`ifdef OR1200_IMPL_ALU_EXT
         or extended
         or extended
`endif
`endif
) begin
) begin
`ifdef OR1200_CASE_DEFAULT
`ifdef OR1200_CASE_DEFAULT
Line 180... Line 196...
                end
                end
`endif
`endif
                `OR1200_ALUOP_SHROT : begin
                `OR1200_ALUOP_SHROT : begin
                                result = shifted_rotated;
                                result = shifted_rotated;
                end
                end
                `OR1200_ALUOP_ADD : begin
 
                                result = result_sum;
 
                end
 
`ifdef OR1200_IMPL_ADDC
`ifdef OR1200_IMPL_ADDC
                `OR1200_ALUOP_ADDC : begin
                `OR1200_ALUOP_ADDC,
                                result = result_csum;
 
                end
 
`endif
`endif
`ifdef OR1200_IMPL_SUB
`ifdef OR1200_IMPL_SUB
                `OR1200_ALUOP_SUB : begin
                `OR1200_ALUOP_SUB,
                                result = a - b;
 
                end
 
`endif
`endif
 
                `OR1200_ALUOP_ADD : begin
 
                                result = result_sum;
 
                end
                `OR1200_ALUOP_XOR : begin
                `OR1200_ALUOP_XOR : begin
                                result = a ^ b;
                                result = a ^ b;
                end
                end
                `OR1200_ALUOP_OR  : begin
                `OR1200_ALUOP_OR  : begin
                                result = a | b;
                                result = a | b;
Line 243... Line 255...
 
 
//
//
// Generate flag and flag write enable
// Generate flag and flag write enable
//
//
always @(alu_op or result_sum or result_and or flagcomp
always @(alu_op or result_sum or result_and or flagcomp
`ifdef OR1200_IMPL_ADDC
 
         or result_csum
 
`endif
 
) begin
) begin
        casez (alu_op)          // synopsys parallel_case
        casez (alu_op)          // synopsys parallel_case
`ifdef OR1200_ADDITIONAL_FLAG_MODIFIERS
`ifdef OR1200_ADDITIONAL_FLAG_MODIFIERS
 
`ifdef OR1200_IMPL_ADDC
 
                `OR1200_ALUOP_ADDC,
 
`endif
                `OR1200_ALUOP_ADD : begin
                `OR1200_ALUOP_ADD : begin
                        flagforw = (result_sum == 32'h0000_0000);
                        flagforw = (result_sum == 32'h0000_0000);
                        flag_we = 1'b1;
                        flag_we = 1'b1;
                end
                end
`ifdef OR1200_IMPL_ADDC
 
                `OR1200_ALUOP_ADDC : begin
 
                        flagforw = (result_csum == 32'h0000_0000);
 
                        flag_we = 1'b1;
 
                end
 
`endif
 
                `OR1200_ALUOP_AND: begin
                `OR1200_ALUOP_AND: begin
                        flagforw = (result_and == 32'h0000_0000);
                        flagforw = (result_and == 32'h0000_0000);
                        flag_we = 1'b1;
                        flag_we = 1'b1;
                end
                end
`endif
`endif
Line 280... Line 286...
//
//
// Generate SR[CY] write enable
// Generate SR[CY] write enable
//
//
always @(alu_op or cy_sum
always @(alu_op or cy_sum
`ifdef OR1200_IMPL_CY
`ifdef OR1200_IMPL_CY
`ifdef OR1200_IMPL_ADDC
 
        or cy_csum
 
`endif
 
`ifdef OR1200_IMPL_SUB
`ifdef OR1200_IMPL_SUB
        or cy_sub
        or cy_sub
`endif
`endif
`endif
`endif
) begin
) begin
        casez (alu_op)          // synopsys parallel_case
        casez (alu_op)          // synopsys parallel_case
`ifdef OR1200_IMPL_CY
`ifdef OR1200_IMPL_CY
 
`ifdef OR1200_IMPL_ADDC
 
                `OR1200_ALUOP_ADDC,
 
`endif
                `OR1200_ALUOP_ADD : begin
                `OR1200_ALUOP_ADD : begin
                        cyforw = cy_sum;
                        cyforw = cy_sum;
                        cy_we = 1'b1;
                        cy_we = 1'b1;
                end
                end
`ifdef OR1200_IMPL_ADDC
 
                `OR1200_ALUOP_ADDC: begin
 
                        cyforw = cy_csum;
 
                        cy_we = 1'b1;
 
                end
 
`endif
 
`ifdef OR1200_IMPL_SUB
`ifdef OR1200_IMPL_SUB
                `OR1200_ALUOP_SUB: begin
                `OR1200_ALUOP_SUB: begin
                        cyforw = cy_sub;
                        cyforw = cy_sub;
                        cy_we = 1'b1;
                        cy_we = 1'b1;
                end
                end
Line 314... Line 314...
                        cy_we = 1'b0;
                        cy_we = 1'b0;
                end
                end
        endcase
        endcase
end
end
 
 
 
 
 
//
 
// Generate SR[OV] write enable
 
//
 
always @(alu_op or ov_sum) begin
 
        casez (alu_op)          // synopsys parallel_case
 
`ifdef OR1200_IMPL_OV
 
`ifdef OR1200_IMPL_ADDC
 
                `OR1200_ALUOP_ADDC,
 
`endif
 
`ifdef OR1200_IMPL_SUB
 
                `OR1200_ALUOP_SUB,
 
`endif
 
                `OR1200_ALUOP_ADD : begin
 
                        ovforw = ov_sum;
 
                        ov_we = 1'b1;
 
                end
 
`endif
 
                default: begin
 
                        ovforw = 1'b0;
 
                        ov_we = 1'b0;
 
                end
 
        endcase
 
end
 
 
//
//
// Shifts and rotation
// Shifts and rotation
//
//
always @(alu_op2 or a or b) begin
always @(alu_op2 or a or b) begin
        case (alu_op2)          // synopsys parallel_case
        case (alu_op2)          // synopsys parallel_case

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.