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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [core/] [cpuops.v] - Blame information for rev 17

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    cpuops.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Tecnology, LLC
11
//
12
///////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// License:     GPL, v3, as defined and found on www.gnu.org,
27
//              http://www.gnu.org/licenses/gpl.html
28
//
29
//
30
///////////////////////////////////////////////////////////////////////////
31
//
32
module  cpuops(i_clk, i_rst, i_ce, i_valid, i_op, i_a, i_b, o_c, o_f, o_valid);
33
        input           i_clk, i_rst, i_ce;
34
        input           [3:0]    i_op;
35
        input           [31:0]   i_a, i_b;
36
        input                   i_valid;
37
        output  reg     [31:0]   o_c;
38
        output  wire    [3:0]    o_f;
39
        output  reg             o_valid;
40
 
41
        wire    [63:0]   w_rol_tmp;
42
        assign  w_rol_tmp = { i_a, i_a } << i_b[4:0];
43
        wire    [31:0]   w_rol_result;
44
        assign  w_rol_result = w_rol_tmp[63:32]; // Won't set flags
45 15 dgisselq
        wire    [33:0]           w_lsr_result, w_asr_result;
46
        wire    signed  [33:0]   w_ia_input;
47
        assign  w_ia_input = { i_a[31], i_a, 1'b0 };
48
        assign  w_asr_result = (|i_b[31:5])? {(34){i_a[31]}}
49
                                : ( w_ia_input >>> (i_b[4:0]) );// ASR
50
        assign  w_lsr_result = (|i_b[31:5])? 34'h00
51
                                : { 1'b0, i_a, 1'b0 } >> (i_b[4:0]);// LSR
52 2 dgisselq
 
53
        wire    z, n, v;
54
        reg     c, pre_sign, set_ovfl;
55
        always @(posedge i_clk)
56
                if (i_ce)
57
                        set_ovfl =((((i_op==4'h0)||(i_op==4'h8)) // SUB&CMP
58
                                                &&(i_a[31] != i_b[31]))
59
                                ||((i_op==4'ha)&&(i_a[31] == i_b[31])) // ADD
60
                                ||(i_op == 4'hd) // LSL
61
                                ||(i_op == 4'hf)); // LSR
62
        always @(posedge i_clk)
63
                if (i_ce)
64
                begin
65
                        pre_sign <= (i_a[31]);
66
                        c <= 1'b0;
67 3 dgisselq
                        casez(i_op)
68
                        4'b?000:{c,o_c } <= {(i_b>i_a),i_a - i_b};// CMP/SUB
69
                        4'b?001:   o_c   <= i_a & i_b;          // BTST/And
70 2 dgisselq
                        // 4'h4:   o_c   <= i_a[15:0] * i_b[15:0];
71
                        4'h5:      o_c   <= w_rol_result;       // ROL
72
                        4'h6:      o_c   <= { i_a[31:16], i_b[15:0] }; // LODILO
73
                        4'h7:      o_c   <= { i_b[15:0], i_a[15:0] }; // LODIHI
74
                        4'ha: { c, o_c } <= i_a + i_b;          // Add
75
                        4'hb:      o_c   <= i_a | i_b;          // Or
76
                        4'hc:      o_c   <= i_a ^ i_b;          // Xor
77 12 dgisselq
                        4'hd: { c, o_c } <= (|i_b[31:5])? 33'h00 : {1'b0, i_a } << i_b[4:0];     // LSL
78 15 dgisselq
                        4'he: { o_c, c } <= w_asr_result[32:0];// ASR
79
                        4'hf: { o_c, c } <= w_lsr_result[32:0];// LSR
80 2 dgisselq
                        default:   o_c   <=       i_b;          // MOV, LDI
81
                        endcase
82
                end
83
 
84
        assign  z = (o_c == 32'h0000);
85
        assign  n = (o_c[31]);
86
        assign  v = (set_ovfl)&&(pre_sign != o_c[31]);
87
 
88
        assign  o_f = { v, n, c, z };
89
 
90
        initial o_valid = 1'b0;
91
        always @(posedge i_clk)
92
                if (i_rst)
93
                        o_valid <= 1'b0;
94
                else if (i_ce)
95
                        o_valid <= i_valid;
96
                else if (~i_ce)
97
                        o_valid <= 1'b0;
98
endmodule

powered by: WebSVN 2.1.0

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