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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [cpudefs.v] - Blame information for rev 209

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 56 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 69 dgisselq
//              Gisselquist Technology, LLC
28 56 dgisselq
//
29 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
30 56 dgisselq
//
31 209 dgisselq
// Copyright (C) 2015-2019, Gisselquist Technology, LLC
32 56 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 201 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 56 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
49
//              http://www.gnu.org/licenses/gpl.html
50
//
51
//
52 201 dgisselq
////////////////////////////////////////////////////////////////////////////////
53
//
54
//
55 56 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
//
64
// OPT_MULTIPLY controls whether or not the multiply is built and included
65
// in the ALU by default.  Set this option and a parameter will be set that
66
// includes the multiply.  (This parameter may still be overridden, as with
67
// any parameter ...)  If the multiply is not included and
68
// OPT_ILLEGAL_INSTRUCTION is set, then the multiply will create an illegal
69
// instruction that will then trip the illegal instruction trap.
70
//
71 193 dgisselq
// Either not defining this value, or defining it to zero will disable the
72
// hardware multiply.  A value of '1' will cause the multiply to occurr in one
73
// clock cycle only--often at the expense of the rest of the CPUs speed.
74
// A value of 2 will cause the multiply to have a single delay cycle, 3 will
75
// have two delay cycles, and 4 (or more) will have 3 delay cycles.
76 56 dgisselq
//
77
//
78 193 dgisselq
`define OPT_MULTIPLY    3
79 56 dgisselq
//
80
//
81 193 dgisselq
//
82 69 dgisselq
// OPT_DIVIDE controls whether or not the divide instruction is built and
83
// included into the ZipCPU by default.  Set this option and a parameter will
84
// be set that causes the divide unit to be included.  (This parameter may
85
// still be overridden, as with any parameter ...)  If the divide is not
86
// included and OPT_ILLEGAL_INSTRUCTION is set, then the multiply will create
87
// an illegal instruction exception that will send the CPU into supervisor
88
// mode.
89
//
90
//
91
`define OPT_DIVIDE
92
//
93
//
94
//
95
// OPT_IMPLEMENT_FPU will (one day) control whether or not the floating point
96 201 dgisselq
// unit (once I have one) is built and included into the ZipCPU by default.
97 69 dgisselq
// At that time, if this option is set then a parameter will be set that
98
// causes the floating point unit to be included.  (This parameter may
99
// still be overridden, as with any parameter ...)  If the floating point unit
100
// is not included and OPT_ILLEGAL_INSTRUCTION is set, then as with the
101
// multiply and divide any floating point instruction will result in an illegal
102
// instruction exception that will send the CPU into supervisor mode.
103
//
104
//
105
// `define      OPT_IMPLEMENT_FPU
106
//
107
//
108
//
109
//
110 201 dgisselq
// OPT_SINGLE_FETCH controls whether or not the prefetch has a cache, and
111 56 dgisselq
// whether or not it can issue one instruction per clock.  When set, the
112
// prefetch has no cache, and only one instruction is fetched at a time.
113 201 dgisselq
// This effectively sets the CPU so that only one instruction is ever
114
// in the pipeline at once, and hence you may think of this as a "kill
115 56 dgisselq
// pipeline" option.  However, since the pipelined fetch component uses so
116
// much area on the FPGA, this is an important option to use in trimming down
117
// used area if necessary.  Hence, it needs to be maintained for that purpose.
118
// Be aware, though, it will drop your performance by a factor between 2x and
119
// 3x.
120
//
121 64 dgisselq
// We can either pipeline our fetches, or issue one fetch at a time.  Pipelined
122
// fetches are more complicated and therefore use more FPGA resources, while
123 201 dgisselq
// single fetches will cause the CPU to stall for about 5 stalls each
124 64 dgisselq
// instruction cycle, effectively reducing the instruction count per clock to
125
// about 0.2.  However, the area cost may be worth it.  Consider:
126
//
127
//      Slice LUTs              ZipSystem       ZipCPU
128
//      Single Fetching         2521            1734
129
//      Pipelined fetching      2796            2046
130
//      (These numbers may be dated, but should still be representative ...)
131
//
132 56 dgisselq
// I recommend only defining this if you "need" to, if area is tight and
133
// speed isn't as important.  Otherwise, just leave this undefined.
134
//
135
// `define      OPT_SINGLE_FETCH
136
//
137
//
138 205 dgisselq
// OPT_DOUBLE_FETCH is an alternative to OPT_SINGLE_FETCH.  It is designed to
139
// increase performance primarily when using an instruction memory which has
140
// one cost for a random access, and a second (lower) cost for sequential
141
// access.  The driving example behind this implementation was flash memory
142
// with 34 clocks for an initial access and 16 clocks for any subsequent access,
143
// but SDRAM memory with 27 clocks for an initial access and 1 clock for a
144
// subsequent access is also a good example.  Even block RAM might be a good
145
// example, if there were any bus delays in getting to the RAM device.  Using
146
// OPT_DOUBLE_FETCH also increases the pipeline speed, as it allows CIS
147
// instructions and therefore partial pipelining.  (No work is done to resolve
148
// pipeline conflicts past the decode stage, as is the case with full pipeline
149
// mode.
150 56 dgisselq
//
151 205 dgisselq
// Do not define OPT_DOUBLE_FETCH if you wish to fully pipeline the CPU.  Do
152
// not define both OPT_DOUBLE_FETCH and OPT_SINGLE_FETCH (the ifndef below
153
// should prevent that).
154
//
155
//
156
`ifndef OPT_SINGLE_FETCH
157
// `define      OPT_DOUBLE_FETCH
158
`endif
159
//
160
//
161
//
162
// The ZipCPU ISA defines an optional compressed instruction set (CIS)
163
// complement.  This compressed instruction format allows two instructions to
164
// be packed into the same instruction word.  Some instructions can be so
165
// compressed, although not all.  Compressed instructions take the same time to
166
// complete--they are just compressed within memory to spare troubles with the
167
// prefetch.  Set OPT_CIS to include these compressed instructions as part of
168
// the instruction set.
169
//
170
`define OPT_CIS         // COST: about 87 LUTs
171
//
172
//
173
//
174
//
175
// OPT_EARLY_BRANCHING is an attempt to execute a BRA statement as early
176
// as possible, to avoid as many pipeline stalls on a branch as possible.
177
// With the OPT_TRADITIONAL_PFCACHE, BRA instructions cost only a single
178
// extra stall cycle, while LJMP instructions cost two (assuming the target is
179
// in the cache).  Indeed, the result is that a BRA instruction can be used as
180
// the compiler's branch prediction optimizer: BRA's barely stall, while
181
// conditional branches will always suffer about 4 stall cycles or so.
182
//
183
// I recommend setting this flag, so as to turn early branching on---if you
184
// have the LUTs available to afford it.
185
//
186
`define OPT_EARLY_BRANCHING
187
//
188
//
189
//
190
//
191 56 dgisselq
// The next several options are pipeline optimization options.  They make no
192
// sense in a single instruction fetch mode, hence we #ifndef them so they
193
// are only defined if we are in a full pipelined mode (i.e. OPT_SINGLE_FETCH
194
// is not defined).
195
//
196
`ifndef OPT_SINGLE_FETCH
197 205 dgisselq
`ifndef OPT_DOUBLE_FETCH
198 56 dgisselq
//
199
//
200
//
201 201 dgisselq
// OPT_PIPELINED is the natural result and opposite of using the single
202 69 dgisselq
// instruction fetch unit.  If you are not using that unit, the ZipCPU will
203 201 dgisselq
// be pipelined.  The option is defined here more for readability than
204 69 dgisselq
// anything else, since OPT_PIPELINED makes more sense than OPT_SINGLE_FETCH,
205
// well ... that and it does a better job of explaining what is going on.
206 56 dgisselq
//
207 69 dgisselq
// In other words, leave this define alone--lest you break the ZipCPU.
208 56 dgisselq
//
209 69 dgisselq
`define OPT_PIPELINED
210 56 dgisselq
//
211
//
212
//
213 69 dgisselq
// OPT_TRADITIONAL_PFCACHE allows you to switch between one of two prefetch
214
// caches.  If enabled, a more traditional cache is implemented.  This more
215
// traditional cache (currently) uses many more LUTs, but it also reduces
216
// the stall count tremendously over the alternative hacked pipeline cache.
217
// (The traditional pfcache is also pipelined, whereas the pipeline cache
218
// implements a windowed approach to caching.)
219
//
220
// If you have the fabric to support this option, I recommend including it.
221
//
222
`define OPT_TRADITIONAL_PFCACHE
223
//
224
//
225
//
226 56 dgisselq
//
227 209 dgisselq
// OPT_DCACHE enables a CPU data cache for (hopefully) better performance
228
// in terms of speed.  It requires telling the CPU which parts of memory
229
// can be cachable in terms of three separate address regions: one for the
230
// SDRAM, one for the flash, and another for the block RAM.
231
//
232
`define OPT_DCACHE
233
//
234
//
235
//
236 56 dgisselq
// OPT_PIPELINED_BUS_ACCESS controls whether or not LOD/STO instructions
237
// can take advantaged of pipelined bus instructions.  To be eligible, the
238
// operations must be identical (cannot pipeline loads and stores, just loads
239
// only or stores only), and the addresses must either be identical or one up
240
// from the previous address.  Further, the load/store string must all have
241
// the same conditional.  This approach gains the must use, in my humble
242
// opinion, when saving registers to or restoring registers from the stack
243
// at the beginning/end of a procedure, or when doing a context swap.
244
//
245
// I recommend setting this flag, for performance reasons, especially if your
246
// wishbone bus can handle pipelined bus accesses.
247
//
248
`define OPT_PIPELINED_BUS_ACCESS
249
//
250
//
251
//
252
//
253
//
254 205 dgisselq
`endif  // OPT_DOUBLE_FETCH
255 56 dgisselq
`endif  // OPT_SINGLE_FETCH
256
//
257
//
258 209 dgisselq
// [EXPERIMENTAL--and not (yet) finished]
259
// OPT_MMU determines whether or not an MMU will be included in the ZipSystem
260
// containing the ZipCPU.  When set, the ZipCPU will route all memory accesses
261
// through the MMU as an address translator, creating a form of Virtual memory.
262 69 dgisselq
//
263 209 dgisselq
// `define      OPT_MMU
264
//
265 69 dgisselq
// Now let's talk about peripherals for a moment.  These next two defines
266
// control whether the DMA controller is included in the Zip System, and
267
// whether or not the 8 accounting timers are also included.  Set these to
268
// include the respective peripherals, comment them out not to.
269
//
270
`define INCLUDE_DMA_CONTROLLER
271
`define INCLUDE_ACCOUNTING_COUNTERS
272
//
273
//
274
// `define      DEBUG_SCOPE
275
//
276 56 dgisselq
`endif  // CPUDEFS_H

powered by: WebSVN 2.1.0

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