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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [core/] [cpuops.v] - Diff between revs 56 and 62

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

Rev 56 Rev 62
Line 39... Line 39...
        output  reg     [31:0]   o_c;
        output  reg     [31:0]   o_c;
        output  wire    [3:0]    o_f;
        output  wire    [3:0]    o_f;
        output  reg             o_valid;
        output  reg             o_valid;
        output  wire            o_illegal;
        output  wire            o_illegal;
 
 
 
        // Rotate-left pre-logic
        wire    [63:0]   w_rol_tmp;
        wire    [63:0]   w_rol_tmp;
        assign  w_rol_tmp = { i_a, i_a } << i_b[4:0];
        assign  w_rol_tmp = { i_a, i_a } << i_b[4:0];
        wire    [31:0]   w_rol_result;
        wire    [31:0]   w_rol_result;
        assign  w_rol_result = w_rol_tmp[63:32]; // Won't set flags
        assign  w_rol_result = w_rol_tmp[63:32]; // Won't set flags
`ifndef NEW_NOT_OLD_CODE
 
        wire    [33:0]           w_lsr_result, w_asr_result;
        // Shift register pre-logic
        wire    signed  [33:0]   w_ia_input;
 
        assign  w_ia_input = { i_a[31], i_a, 1'b0 };
 
        assign  w_asr_result = (|i_b[31:5])? {(34){i_a[31]}}
 
                                : ( w_ia_input >>> (i_b[4:0]) );// ASR
 
        assign  w_lsr_result = (|i_b[31:5])? 34'h00
 
                                : { 1'b0, i_a, 1'b0 } >> (i_b[4:0]);// LSR
 
`else
 
        wire    [32:0]           w_lsr_result, w_asr_result;
        wire    [32:0]           w_lsr_result, w_asr_result;
        assign  w_asr_result = (|i_b[31:5])? {(33){i_a[31]}}
        assign  w_asr_result = (|i_b[31:5])? {(33){i_a[31]}}
                                : ( {i_a, 1'b0 } >>> (i_b[4:0]) );// ASR
                                : ( {i_a, 1'b0 } >>> (i_b[4:0]) );// ASR
        assign  w_lsr_result = (|i_b[31:5])? 33'h00
        assign  w_lsr_result = (|i_b[31:5])? 33'h00
                                : ( { i_a, 1'b0 } >> (i_b[4:0]) );// LSR
                                : ( { i_a, 1'b0 } >> (i_b[4:0]) );// LSR
`endif
 
 
 
 
 
        wire    z, n, v;
        wire    z, n, v;
        reg     c, pre_sign, set_ovfl;
        reg     c, pre_sign, set_ovfl;
        always @(posedge i_clk)
        always @(posedge i_clk)
Line 70... Line 63...
                                                &&(i_a[31] != i_b[31]))
                                                &&(i_a[31] != i_b[31]))
                                ||((i_op==4'ha)&&(i_a[31] == i_b[31])) // ADD
                                ||((i_op==4'ha)&&(i_a[31] == i_b[31])) // ADD
                                ||(i_op == 4'hd) // LSL
                                ||(i_op == 4'hd) // LSL
                                ||(i_op == 4'hf)); // LSR
                                ||(i_op == 4'hf)); // LSR
 
 
 
 
 
        // A 4-way multiplexer can be done in one 6-LUT.
 
        // A 16-way multiplexer can therefore be done in 4x 6-LUT's with
 
        //      the Xilinx multiplexer fabric that follows. 
 
        // Given that we wish to apply this multiplexer approach to 33-bits,
 
        // this will cost a minimum of 132 6-LUTs.
        generate
        generate
        if (IMPLEMENT_MPY == 0)
        if (IMPLEMENT_MPY == 0)
        begin
        begin
                always @(posedge i_clk)
                always @(posedge i_clk)
                if (i_ce)
                if (i_ce)
                begin
                begin
                        pre_sign <= (i_a[31]);
                        pre_sign <= (i_a[31]);
                        c <= 1'b0;
                        c <= 1'b0;
                        casez(i_op)
                        casez(i_op)
                        4'b?000:{c,o_c } <= {(i_b>i_a),i_a - i_b};// CMP/SUB
                        4'b?000:{c,o_c } <= {1'b0,i_a} - {1'b0,i_b};// CMP/SUB
                        4'b?001:   o_c   <= i_a & i_b;          // BTST/And
                        4'b?001:   o_c   <= i_a & i_b;          // BTST/And
 
                        // 4'h3: There's a hole here for the unimplemented MPYU,
 
                        // 4'h4: and here for the unimplemented MPYS
                        4'h5:      o_c   <= w_rol_result;       // ROL
                        4'h5:      o_c   <= w_rol_result;       // ROL
                        4'h6:      o_c   <= { i_a[31:16], i_b[15:0] }; // LODILO
                        4'h6:      o_c   <= { i_a[31:16], i_b[15:0] }; // LODILO
                        4'h7:      o_c   <= { i_b[15:0], i_a[15:0] }; // LODIHI
                        4'h7:      o_c   <= { i_b[15:0], i_a[15:0] }; // LODIHI
                        4'ha: { c, o_c } <= i_a + i_b;          // Add
                        4'ha: { c, o_c } <= i_a + i_b;          // Add
                        4'hb:      o_c   <= i_a | i_b;          // Or
                        4'hb:      o_c   <= i_a | i_b;          // Or
Line 94... Line 95...
                        4'hf: { o_c, c } <= w_lsr_result[32:0];// LSR
                        4'hf: { o_c, c } <= w_lsr_result[32:0];// LSR
                        default:   o_c   <=       i_b;          // MOV, LDI
                        default:   o_c   <=       i_b;          // MOV, LDI
                        endcase
                        endcase
                end
                end
        end else begin
        end else begin
 
                //
 
                // Multiply pre-logic
 
                //
                wire    signed  [16:0]   w_mpy_a_input, w_mpy_b_input;
                wire    signed  [16:0]   w_mpy_a_input, w_mpy_b_input;
                wire    signed  [33:0]   w_mpy_result;
                wire    signed  [33:0]   w_mpy_result;
                assign  w_mpy_a_input = { ((i_a[15])&&(i_op[2])), i_a[15:0] };
                assign  w_mpy_a_input = { ((i_a[15])&&(i_op[2])), i_a[15:0] };
                assign  w_mpy_b_input = { ((i_b[15])&&(i_op[2])), i_b[15:0] };
                assign  w_mpy_b_input = { ((i_b[15])&&(i_op[2])), i_b[15:0] };
                assign  w_mpy_result  = w_mpy_a_input * w_mpy_b_input;
                assign  w_mpy_result  = w_mpy_a_input * w_mpy_b_input;
 
 
 
 
 
                //
 
                // The master ALU case statement
 
                //
                always @(posedge i_clk)
                always @(posedge i_clk)
                if (i_ce)
                if (i_ce)
                begin
                begin
                        pre_sign <= (i_a[31]);
                        pre_sign <= (i_a[31]);
                        c <= 1'b0;
                        c <= 1'b0;
                        casez(i_op)
                        casez(i_op)
                        4'b?000:{c,o_c } <= {(i_b>i_a),i_a - i_b};// CMP/SUB
                        4'b?000:{c,o_c } <= {1'b0,i_a} - {1'b0,i_b};// CMP/SUB
                        4'b?001:   o_c   <= i_a & i_b;          // BTST/And
                        4'b?001:   o_c   <= i_a & i_b;          // BTST/And
                        4'h3: { c, o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYU/S
                        4'h3: { c, o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYU
                        4'h4: { c, o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYU/S
                        4'h4: { c, o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYS
                        4'h5:      o_c   <= w_rol_result;       // ROL
                        4'h5:      o_c   <= w_rol_result;       // ROL
                        4'h6:      o_c   <= { i_a[31:16], i_b[15:0] }; // LODILO
                        4'h6:      o_c   <= { i_a[31:16], i_b[15:0] }; // LODILO
                        4'h7:      o_c   <= { i_b[15:0], i_a[15:0] }; // LODIHI
                        4'h7:      o_c   <= { i_b[15:0], i_a[15:0] }; // LODIHI
                        4'ha: { c, o_c } <= i_a + i_b;          // Add
                        4'ha: { c, o_c } <= i_a + i_b;          // Add
                        4'hb:      o_c   <= i_a | i_b;          // Or
                        4'hb:      o_c   <= i_a | i_b;          // Or
Line 129... Line 137...
        generate
        generate
        if (IMPLEMENT_MPY == 0)
        if (IMPLEMENT_MPY == 0)
        begin
        begin
                reg     r_illegal;
                reg     r_illegal;
                always @(posedge i_clk)
                always @(posedge i_clk)
                        r_illegal <= (i_op == 4'h3)||(i_op == 4'h4);
                        r_illegal <= (i_ce)&&((i_op == 4'h3)||(i_op == 4'h4));
                assign o_illegal = r_illegal;
                assign o_illegal = r_illegal;
        end else
        end else
                assign o_illegal = 1'b0;
                assign o_illegal = 1'b0;
        endgenerate
        endgenerate
 
 

powered by: WebSVN 2.1.0

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