calyx 0.7.1

Compiler Infrastructure for Hardware Accelerator Generation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# Core Library

This library defines a standard set of components used in most Calyx programs
such as registers and basic bitwise operations.

## Contents

- [Numerical Operators]#numerical-operators
- [Logical Operators]#logical-operators
- [Comparison Operators]#comparison-operators
- [Memories]#memories

---

## Numerical Operators

### `std_reg<WIDTH>`

A `WIDTH`-wide register.

**Inputs:**

- `in: WIDTH` - An input value to the register `WIDTH`-bits.
- `write_en: 1` - The one bit write enabled signal. Indicates that the register
  should store the value on the `in` wire.

**Outputs:**

- `out: WIDTH` - The value contained in the register.
- `done: 1` - The register's done signal. Set high for one cycle after writing a
  new value.

---

### `std_const<WIDTH,VAL>`

A constant WIDTH-bit value with value VAL.

**Inputs:** None

**Outputs:**

- `out: WIDTH` - The value of the constant (i.e. `VAL`)

---

### `std_lsh<WIDTH>`

A left bit shift. Performs `left << right`. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit value to be shifted
- `right: WIDTH` - A WIDTH-bit value representing the shift amount

**Outputs:**

- `out: WIDTH` - A WIDTH-bit value equivalent to `left << right`

---

### `std_rsh<WIDTH>`

A right bit shift. Performs `left >> right`. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit value to be shifted
- `right: WIDTH` - A WIDTH-bit value representing the shift amount

**Outputs:**

- `out: WIDTH` - A WIDTH-bit value equivalent to `left >> right`

---

### `std_add<WIDTH>`

Bitwise addition without a carry flag. Performs `left + right`. This component
is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit value
- `right: WIDTH` - A WIDTH-bit value

**Outputs:**

- `out: WIDTH` - A WIDTH-bit value equivalent to `left + right`

---

### `std_sub<WIDTH>`

Bitwise subtraction. Performs `left - right`. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit value
- `right: WIDTH` - A WIDTH-bit value

**Outputs:**

- `out: WIDTH` - A WIDTH-bit value equivalent to `left - right`

---

### `std_slice<IN_WIDTH, OUT_WIDTH>`

Slice out the lower OUT_WIDTH bits of an IN_WIDTH-bit value. Computes
`in[OUT_WIDTH - 1 : 0]`. This component is combinational.

**Inputs:**

- `in: IN_WIDTH` - An IN_WIDTH-bit value

**Outputs:**

- `out: OUT_WIDTH` - The lower OUT_WIDTH bits of `in`

---
### `std_bit_slice<IN_WIDTH, START_IDX, END_IDX, OUT_WIDTH>`
Extract the bit-string starting at `START_IDX` and ending at `END_IDX - 1` from `in`. 
This is computed as `in[END_IDX:START_IDX]`.`OUT_WIDTH` must be specified to 
be `END_WIDTH - START_WITH` wide when instantiating the module.


**Inputs:**
- `in: IN_WIDTH` - An IN_WIDTH-bit value
  
**Outputs:**

- `out: OUT_WIDTH` - The value of the bit-string `in[START_IDX:END_IDX]`
---
### `std_pad<IN_WIDTH, OUT_WIDTH>`

Given an IN_WIDTH-bit input, zero pad from the left to an output of
OUT_WIDTH-bits. This component is combinational.

**Inputs:**

- `in: IN_WIDTH` - An IN_WIDTH-bit value to be padded

**Outputs:**

- `out: OUT_WIDTH` - The padded value

---

## Logical Operators

### `std_not<WIDTH>`

Bitwise NOT. This component is combinational.

**Inputs:**

- `in: WIDTH` - A WIDTH-bit input.

**Outputs:**

- `out: WIDTH` - The bitwise NOT of the input (`~in`)

---

### `std_and<WIDTH>`

Bitwise AND. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: WIDTH` - The bitwise AND of the arguments (`left & right`)

---

### `std_or<WIDTH>`

Bitwise OR. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: WIDTH` - The bitwise OR of the arguments (`left | right`)

---

### `std_xor<WIDTH>`

Bitwise XOR. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: WIDTH` - The bitwise XOR of the arguments (`left ^ right`)

---

## Comparison Operators

### `std_gt<WIDTH>`

Greater than. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: 1` - A single bit output. 1 if `left > right` else 0.

---

### `std_lt<WIDTH>`

Less than. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: 1` - A single bit output. 1 if `left < right` else 0.

---

### `std_eq<WIDTH>`

Equality comparison. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: 1` - A single bit output. 1 if `left = right` else 0.

---

### `std_neq<WIDTH>`

Not equal. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: 1` - A single bit output. 1 if `left != right` else 0.

---

### `std_ge<WIDTH>`

Greater than or equal. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: 1` - A single bit output. 1 if `left >= right` else 0.

---

### `std_le<WIDTH>`

Less than or equal. This component is combinational.

**Inputs:**

- `left: WIDTH` - A WIDTH-bit argument
- `right: WIDTH` - A WIDTH-bit argument

**Outputs:**

- `out: 1` - A single bit output. 1 if `left <= right` else 0.

---

## Memories

### `comb_mem_d1`

A one-dimensional memory.

**Parameters:**

- `WIDTH` - Size of an individual memory slot.
- `SIZE` - Number of slots in the memory.
- `IDX_SIZE` - The width of the index given to the memory.

**Inputs:**

- `addr0: IDX_SIZE` - The index to be accessed or updated
- `write_data: WIDTH` - Data to be written to the selected memory slot
- `write_en: 1` - One bit write enabled signal, causes the memory to write `write_data` to the slot indexed by `addr0`

**Outputs:**

- `read_data: WIDTH` - The value stored at `addr0`. This value is combinational with respect to `addr0`.
- `done: 1`: The done signal for the memory. This signal goes high for one cycle after finishing a write to the memory.

---

### `comb_mem_d2`

A two-dimensional memory.

**Parameters:**

- `WIDTH` - Size of an individual memory slot.
- `D0_SIZE` - Number of memory slots for the first index.
- `D1_SIZE` - Number of memory slots for the second index.
- `D0_IDX_SIZE` - The width of the first index.
- `D1_IDX_SIZE` - The width of the second index.

**Inputs:**

- `addr0: D0_IDX_SIZE` - The first index into the memory
- `addr1: D1_IDX_SIZE` - The second index into the memory
- `write_data: WIDTH` - Data to be written to the selected memory slot
- `write_en: 1` - One bit write enabled signal, causes the memory to write `write_data` to the slot indexed by `addr0` and `addr1`

**Outputs:**

- `read_data: WIDTH` - The value stored at `mem[addr0][addr1]`. This value is combinational with respect to `addr0` and `addr1`.
- `done: 1`: The done signal for the memory. This signal goes high for one cycle after finishing a write to the memory.

---

### `comb_mem_d3`

A three-dimensional memory.

**Parameters:**

- `WIDTH` - Size of an individual memory slot.
- `D0_SIZE` - Number of memory slots for the first index.
- `D1_SIZE` - Number of memory slots for the second index.
- `D2_SIZE` - Number of memory slots for the third index.
- `D0_IDX_SIZE` - The width of the first index.
- `D1_IDX_SIZE` - The width of the second index.
- `D2_IDX_SIZE` - The width of the third index.

**Inputs:**

- `addr0: D0_IDX_SIZE` - The first index into the memory
- `addr1: D1_IDX_SIZE` - The second index into the memory
- `addr2: D2_IDX_SIZE` - The third index into the memory
- `write_data: WIDTH` - Data to be written to the selected memory slot
- `write_en: 1` - One bit write enabled signal, causes the memory to write `write_data` to the slot indexed by `addr0`, `addr1`, and `addr2`

**Outputs:**

- `read_data: WIDTH` - The value stored at `mem[addr0][addr1][addr2]`. This value is combinational with respect to `addr0`, `addr1`, and `addr2`.
- `done: 1`: The done signal for the memory. This signal goes high for one cycle after finishing a write to the memory.

---

### `comb_mem_d4`

A four-dimensional memory.

**Parameters:**

- `WIDTH` - Size of an individual memory slot.
- `D0_SIZE` - Number of memory slots for the first index.
- `D1_SIZE` - Number of memory slots for the second index.
- `D2_SIZE` - Number of memory slots for the third index.
- `D3_SIZE` - Number of memory slots for the fourth index.
- `D0_IDX_SIZE` - The width of the first index.
- `D1_IDX_SIZE` - The width of the second index.
- `D2_IDX_SIZE` - The width of the third index.
- `D3_IDX_SIZE` - The width of the fourth index.

**Inputs:**

- `addr0: D0_IDX_SIZE` - The first index into the memory
- `addr1: D1_IDX_SIZE` - The second index into the memory
- `addr2: D2_IDX_SIZE` - The third index into the memory
- `addr3: D3_IDX_SIZE` - The fourth index into the memory
- `write_data: WIDTH` - Data to be written to the selected memory slot
- `write_en: 1` - One bit write enabled signal, causes the memory to write `write_data` to the slot indexed by `addr0`, `addr1`, `addr2`, and `addr3`

**Outputs:**

- `read_data: WIDTH` - The value stored at `mem[addr0][addr1][addr2][addr3]`. This value is combinational with respect to `addr0`, `addr1`, `addr2`, and `addr3`.
- `done: 1`: The done signal for the memory. This signal goes high for one cycle after finishing a write to the memory.