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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [rtl/] [cpu/] [cpudefs.v] - Blame information for rev 46

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

Line No. Rev Author Line
1 46 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 2 dgisselq
//
3
// Filename:    cpudefs.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     Some architectures have some needs, others have other needs.
8
//              Some of my projects need a Zip CPU with pipelining, others
9
//      can't handle the timing required to get the answer from the ALU
10
//      back into the input for the ALU.  As each different projects has
11
//      different needs, I can either 1) reconfigure my entire baseline prior
12
//      to building each project, or 2) host a configuration file which contains
13
//      the information regarding each baseline.  This file is that
14
//      configuration file.  It controls how the CPU (not the system,
15
//      peripherals, or other) is defined and implemented.  Several options
16
//      are available within here, making the Zip CPU pipelined or not,
17
//      able to handle a faster clock with more stalls or a slower clock with
18
//      no stalls, etc.
19
//
20
//      This file encapsulates those control options.
21
//
22
//      The number of LUTs the Zip CPU uses varies dramatically with the
23
//      options defined in this file.
24
//
25
//
26
// Creator:     Dan Gisselquist, Ph.D.
27
//              Gisselquist Technology, LLC
28
//
29 46 dgisselq
////////////////////////////////////////////////////////////////////////////////
30 2 dgisselq
//
31 46 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
32 2 dgisselq
//
33
// This program is free software (firmware): you can redistribute it and/or
34
// modify it under the terms of  the GNU General Public License as published
35
// by the Free Software Foundation, either version 3 of the License, or (at
36
// your option) any later version.
37
//
38
// This program is distributed in the hope that it will be useful, but WITHOUT
39
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
40
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
41
// for more details.
42
//
43 46 dgisselq
// You should have received a copy of the GNU General Public License along
44
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
45
// target there if the PDF file isn't present.)  If not, see
46
// <http://www.gnu.org/licenses/> for a copy.
47
//
48 2 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
49
//              http://www.gnu.org/licenses/gpl.html
50
//
51
//
52 46 dgisselq
////////////////////////////////////////////////////////////////////////////////
53
//
54
//
55 2 dgisselq
`ifndef CPUDEFS_H
56
`define CPUDEFS_H
57
//
58
//
59
// The first couple options control the Zip CPU instruction set, and how
60
// it handles various instructions within the set:
61
//
62
//
63
// OPT_ILLEGAL_INSTRUCTION is part of a new section of code that is supposed
64
// to recognize illegal instructions and interrupt the CPU whenever one such
65
// instruction is encountered.  The goal is to create a soft floating point
66
// unit via this approach, that can then be replaced with a true floating point
67
// unit.  As I'm not there yet, it just catches illegal instructions and
68
// interrupts the CPU on any such instruction--when defined.  Otherwise,
69
// illegal instructions are quietly ignored and their behaviour is ...
70
// undefined. (Many get treated like NOOPs ...)
71
//
72 46 dgisselq
// I recommend setting this flag so highly, that I'm likely going to remove
73
// the option to turn this off in future versions of this CPU.
74 2 dgisselq
//
75
`define OPT_ILLEGAL_INSTRUCTION
76
//
77
//
78
//
79
// OPT_MULTIPLY controls whether or not the multiply is built and included
80
// in the ALU by default.  Set this option and a parameter will be set that
81
// includes the multiply.  (This parameter may still be overridden, as with
82
// any parameter ...)  If the multiply is not included and
83
// OPT_ILLEGAL_INSTRUCTION is set, then the multiply will create an illegal
84
// instruction that will then trip the illegal instruction trap.
85
//
86 46 dgisselq
// Either not defining this value, or defining it to zero will disable the
87
// hardware multiply.  A value of '1' will cause the multiply to occurr in one
88
// clock cycle only--often at the expense of the rest of the CPUs speed.
89
// A value of 2 will cause the multiply to have a single delay cycle, 3 will
90
// have two delay cycles, and 4 (or more) will have 3 delay cycles.
91 2 dgisselq
//
92
//
93 46 dgisselq
`define OPT_MULTIPLY    4
94 2 dgisselq
//
95
//
96 46 dgisselq
//
97 2 dgisselq
// OPT_DIVIDE controls whether or not the divide instruction is built and
98
// included into the ZipCPU by default.  Set this option and a parameter will
99
// be set that causes the divide unit to be included.  (This parameter may
100
// still be overridden, as with any parameter ...)  If the divide is not
101
// included and OPT_ILLEGAL_INSTRUCTION is set, then the multiply will create
102
// an illegal instruction exception that will send the CPU into supervisor
103
// mode.
104
//
105
//
106
// `define      OPT_DIVIDE
107
//
108
//
109
//
110
// OPT_IMPLEMENT_FPU will (one day) control whether or not the floating point
111
// unit (once I have one) is built and included into the ZipCPU by default. 
112
// At that time, if this option is set then a parameter will be set that
113
// causes the floating point unit to be included.  (This parameter may
114
// still be overridden, as with any parameter ...)  If the floating point unit
115
// is not included and OPT_ILLEGAL_INSTRUCTION is set, then as with the
116
// multiply and divide any floating point instruction will result in an illegal
117
// instruction exception that will send the CPU into supervisor mode.
118
//
119
//
120
// `define      OPT_IMPLEMENT_FPU
121
//
122
//
123
//
124
//
125 46 dgisselq
// The instruction set defines an optional compressed instruction set (CIS)
126
// complement.  These were at one time erroneously called Very Long Instruction
127
// Words.  They are more appropriately referred to as compressed instructions.
128
// The compressed instruction format allows two instructions to be packed into
129
// the same instruction word.  Some instructions can be compressed, not all.
130
// Compressed instructions take the same time to complete.  Set OPT_CIS to
131
// include these double instructions as part of the instruction set.  These
132
// instructions are designed to get more code density from the instruction set,
133
// and to hopefully take some pain off of the performance of the pre-fetch and
134
// instruction cache.
135 2 dgisselq
//
136 46 dgisselq
// These new instructions, however, also necessitate a change in the Zip
137
// CPU--the Zip CPU can no longer execute instructions atomically.  It must
138
// now execute non-CIS instructions, or CIS instruction pairs, atomically. 
139
// This logic has been added into the ZipCPU, but it has not (yet) been
140
// tested thoroughly.
141 2 dgisselq
//
142 46 dgisselq
// Oh, and the debugger and the simulator also need to be updated as well
143
// to properly handle these.
144 2 dgisselq
//
145 46 dgisselq
// `define OPT_CIS      // Adds about 80 LUTs on a Spartan 6
146 2 dgisselq
//
147
//
148
//
149
//
150
// OPT_SINGLE_FETCH controls whether or not the prefetch has a cache, and 
151
// whether or not it can issue one instruction per clock.  When set, the
152
// prefetch has no cache, and only one instruction is fetched at a time.
153
// This effectively sets the CPU so that only one instruction is ever 
154
// in the pipeline at once, and hence you may think of this as a "kill 
155
// pipeline" option.  However, since the pipelined fetch component uses so
156
// much area on the FPGA, this is an important option to use in trimming down
157
// used area if necessary.  Hence, it needs to be maintained for that purpose.
158
// Be aware, though, it will drop your performance by a factor between 2x and
159
// 3x.
160
//
161
// We can either pipeline our fetches, or issue one fetch at a time.  Pipelined
162
// fetches are more complicated and therefore use more FPGA resources, while
163
// single fetches will cause the CPU to stall for about 5 stalls each 
164
// instruction cycle, effectively reducing the instruction count per clock to
165
// about 0.2.  However, the area cost may be worth it.  Consider:
166
//
167
//      Slice LUTs              ZipSystem       ZipCPU
168
//      Single Fetching         2521            1734
169
//      Pipelined fetching      2796            2046
170
//      (These numbers may be dated, but should still be representative ...)
171
//
172
// I recommend only defining this if you "need" to, if area is tight and
173
// speed isn't as important.  Otherwise, just leave this undefined.
174
//
175
`define OPT_SINGLE_FETCH
176
//
177
//
178
//
179
// The next several options are pipeline optimization options.  They make no
180
// sense in a single instruction fetch mode, hence we #ifndef them so they
181
// are only defined if we are in a full pipelined mode (i.e. OPT_SINGLE_FETCH
182
// is not defined).
183
//
184
`ifndef OPT_SINGLE_FETCH
185
//
186
//
187
//
188
// OPT_PIPELINED is the natural result and opposite of using the single 
189
// instruction fetch unit.  If you are not using that unit, the ZipCPU will
190
// be pipelined.  The option is defined here more for readability than 
191
// anything else, since OPT_PIPELINED makes more sense than OPT_SINGLE_FETCH,
192
// well ... that and it does a better job of explaining what is going on.
193
//
194
// In other words, leave this define alone--lest you break the ZipCPU.
195
//
196
`define OPT_PIPELINED
197
//
198
//
199
//
200
// OPT_TRADITIONAL_PFCACHE allows you to switch between one of two prefetch
201
// caches.  If enabled, a more traditional cache is implemented.  This more
202
// traditional cache (currently) uses many more LUTs, but it also reduces
203
// the stall count tremendously over the alternative hacked pipeline cache.
204
// (The traditional pfcache is also pipelined, whereas the pipeline cache
205
// implements a windowed approach to caching.)
206
//
207
// If you have the fabric to support this option, I recommend including it.
208
//
209
// `define      OPT_TRADITIONAL_PFCACHE
210
//
211
//
212
//
213
// OPT_EARLY_BRANCHING is an attempt to execute a BRA statement as early
214
// as possible, to avoid as many pipeline stalls on a branch as possible.
215
// It's not tremendously successful yet--BRA's still suffer stalls,
216
// but I intend to keep working on this approach until the number of stalls
217
// gets down to one or (ideally) zero.  (With the OPT_TRADITIONAL_PFCACHE, this
218
// gets down to a single stall cycle ...)  That way a "BRA" can be used as the
219
// compiler's branch prediction optimizer: BRA's barely stall, while branches
220
// on conditions will always suffer about 4 stall cycles or so.
221
//
222
// I recommend setting this flag, so as to turn early branching on.
223
//
224
`define OPT_EARLY_BRANCHING
225
//
226
//
227
//
228
// OPT_PIPELINED_BUS_ACCESS controls whether or not LOD/STO instructions
229
// can take advantaged of pipelined bus instructions.  To be eligible, the
230
// operations must be identical (cannot pipeline loads and stores, just loads
231
// only or stores only), and the addresses must either be identical or one up
232
// from the previous address.  Further, the load/store string must all have
233
// the same conditional.  This approach gains the must use, in my humble
234
// opinion, when saving registers to or restoring registers from the stack
235
// at the beginning/end of a procedure, or when doing a context swap.
236
//
237
// I recommend setting this flag, for performance reasons, especially if your
238
// wishbone bus can handle pipelined bus accesses.
239
//
240
`define OPT_PIPELINED_BUS_ACCESS
241
//
242
//
243
//
244
//
245
//
246
//
247
//
248
`endif  // OPT_SINGLE_FETCH
249
//
250
//
251
//
252
// Now let's talk about peripherals for a moment.  These next two defines
253
// control whether the DMA controller is included in the Zip System, and
254
// whether or not the 8 accounting timers are also included.  Set these to
255
// include the respective peripherals, comment them out not to.
256
//
257
// `define      INCLUDE_DMA_CONTROLLER
258
// `define      INCLUDE_ACCOUNTING_COUNTERS
259
//
260
//
261 16 dgisselq
`define DEBUG_SCOPE
262 2 dgisselq
//
263
`endif  // CPUDEFS_H

powered by: WebSVN 2.1.0

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