-
Notifications
You must be signed in to change notification settings - Fork 3
/
data_Zpn.txt
667 lines (580 loc) · 31.3 KB
/
data_Zpn.txt
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
//for vX.Y of P
// BPICK -> B CMIX
// CLZ32 -> B CLZ
// MAXW -> B MAX
// MINW -> B MIN
// PKBB16 -> B PACK
// PKTT16 -> B PACKU
// PKBB32 -> B PACK
// PKTT32 -> B PACKU
// so far instructions using OV flag unsupported
I ADD8 ADD8 0100100----------000-----1110111 pdpiadd8 Zpn
I ADD16 ADD16 0100000----------000-----1110111 pdpiadd16 Zpn
I AVE AVE 1110000----------000-----1110111 pdpiadd32 Zpn
I BITREV BITREV 1110011----------000-----1110111 pdpibit Zpn
I BITREVI BITREV 1110010----------000-----1110111 pdpibit Zpn
I CLRS8 CLRS8 101011100000-----000-----1110111 pdpibit Zpn
//I CLRS16 CLRS16 101011101000-----000-----1110111 pdpibit Zpn
//I CLRS32 CLRS32 101011111000-----000-----1110111 pdpibit Zpn
I CLO8 CLO8 101011100011-----000-----1110111 pdpibit Zpn
//I CLO16 CLO16 101011101011-----000-----1110111 pdpibit Zpn
//I CLO32 CLO32 101011111011-----000-----1110111 pdpibit Zpn
I CLZ8 CLZ8 101011100001-----000-----1110111 pdpibit Zpn
//I CLZ16 CLZ16 101011101001-----000-----1110111 pdpibit Zpn
//I CLZ32 CLZ32 101011111001-----000-----1110111 pdpibit Zpn
I CMPEQ8 CMPEQ8 0100111----------000-----1110111 pdpicmp Zpn
I CMPEQ16 CMPEQ16 0100110----------000-----1110111 pdpicmp Zpn
I PKxx16 PKxx16 00--111----------001-----1110111 pdpicpct Zpn
I RADD8 RADD8 0000100----------000-----1110111 pdpiadd8 Zpn
I RADD16 RADD16 0000000----------000-----1110111 pdpiadd16 Zpn
I RADDW RADDW 0010000----------001-----1110111 pdpiadd32 Zpn
I RSUB8 RSUB8 0000101----------000-----1110111 pdpiadd8 Zpn
I RSUB16 RSUB16 0000001----------000-----1110111 pdpiadd16 Zpn
I RSUBW RSUBW 0010001----------001-----1110111 pdpiadd32 Zpn
//I CRAS16 CRAS16 0100010----------000-----1110111 pdpisubadd Zpn
//I CRSA16 CRSA16 0100011----------000-----1110111 pdpisubadd Zpn
//I RCRAS16 RCRAS16 0000010----------000-----1110111 pdpisubadd Zpn
//I RCRSA16 RCRSA16 0000011----------000-----1110111 pdpisubadd Zpn
//I RSTAS16 RCRAS16 1011010----------000-----1110111 pdpisubadd Zpn
//I RSTSA16 RCRSA16 1011011----------000-----1110111 pdpisubadd Zpn
//I STAS16 STAS16 1111010----------010-----1110111 pdpisubadd Zpn
//I STSA16 STSA16 1111011----------010-----1110111 pdpisubadd Zpn
I SCMPLE8 SCMPLE8 0001111----------000-----1110111 pdpicmp Zpn
I SCMPLE16 SCMPLE16 0001110----------000-----1110111 pdpicmp Zpn
I SCMPLT8 SCMPLT8 0000111----------000-----1110111 pdpicmp Zpn
I SCMPLT16 SCMPLT16 0000110----------000-----1110111 pdpicmp Zpn
I SLL8 SLL8 0101110----------000-----1110111 pdpishift Zpn
I SLLI8 SLL8 011111000--------000-----1110111 pdpishift Zpn
I SRL8 SRL8 0101101----------000-----1110111 pdpishift Zpn
I SRLI8 SRL8 011110100--------000-----1110111 pdpishift Zpn
I SRA8 SRA8 0101100----------000-----1110111 pdpishift Zpn
I SRAI8 SRA8 011110000--------000-----1110111 pdpishift Zpn
I SLL16 SLL16 0101010----------000-----1110111 pdpishift Zpn
I SLLI16 SLL16 01110100---------000-----1110111 pdpishift Zpn
I SRL16 SRL16 0101001----------000-----1110111 pdpishift Zpn
I SRLI16 SRL16 01110010---------000-----1110111 pdpishift Zpn
I SRA16 SRA16 0101000----------000-----1110111 pdpishift Zpn
I SRAI16 SRA16 01110000---------000-----1110111 pdpishift Zpn
I SMAX8 SMAX8 1000101----------000-----1110111 pdpicmp Zpn
I SMAX16 SMAX16 1000001----------000-----1110111 pdpicmp Zpn
I SMIN8 SMIN8 1000100----------000-----1110111 pdpicmp Zpn
I SMIN16 SMIN16 1000000----------000-----1110111 pdpicmp Zpn
I SUB8 SUB8 0100101----------000-----1110111 pdpiadd8 Zpn
I SUB16 SUB16 0100001----------000-----1110111 pdpiadd16 Zpn
I SUNPKD810 SUNPKD8 101011001000-----000-----1110111 pdpicpct Zpn
I SUNPKD820 SUNPKD8 101011001001-----000-----1110111 pdpicpct Zpn
I SUNPKD830 SUNPKD8 101011001010-----000-----1110111 pdpicpct Zpn
I SUNPKD831 SUNPKD8 101011001011-----000-----1110111 pdpicpct Zpn
I SUNPKD832 SUNPKD8 101011010011-----000-----1110111 pdpicpct Zpn
I SWAP8 SWAP8 101011011000-----000-----1110111 pdpibit Zpn
I SWAP16 SWAP16 101011011001-----000-----1110111 pdpibit Zpn
I UCMPLE8 UCMPLE8 0011111----------000-----1110111 pdpicmp Zpn
I UCMPLE16 UCMPLE16 0011110----------000-----1110111 pdpicmp Zpn
I UCMPLT8 UCMPLT8 0010111----------000-----1110111 pdpicmp Zpn
I UCMPLT16 UCMPLT16 0010110----------000-----1110111 pdpicmp Zpn
I UMAX8 UMAX8 1001101----------000-----1110111 pdpicmp Zpn
I UMAX16 UMAX16 1001001----------000-----1110111 pdpicmp Zpn
I UMIN8 UMIN8 1001100----------000-----1110111 pdpicmp Zpn
I UMIN16 UMIN16 1001000----------000-----1110111 pdpicmp Zpn
I URADD8 URADD8 0010100----------000-----1110111 pdpiadd8 Zpn
I URADD16 URADD16 0010000----------000-----1110111 pdpiadd16 Zpn
I URADDW URADDW 0011000----------001-----1110111 pdpiadd32 Zpn
I URSUB8 URSUB8 0010101----------000-----1110111 pdpiadd8 Zpn
I URSUB16 URSUB16 0010001----------000-----1110111 pdpiadd16 Zpn
I URSUBW URSUBW 0011001----------001-----1110111 pdpiadd32 Zpn
I ZUNPKD810 ZUNPKD8 101011001100-----000-----1110111 pdpicpct Zpn
I ZUNPKD820 ZUNPKD8 101011001101-----000-----1110111 pdpicpct Zpn
I ZUNPKD830 ZUNPKD8 101011001110-----000-----1110111 pdpicpct Zpn
I ZUNPKD831 ZUNPKD8 101011001111-----000-----1110111 pdpicpct Zpn
I ZUNPKD832 ZUNPKD8 101011010111-----000-----1110111 pdpicpct Zpn
// the following needs to read Rd, so need a patch to VexRiscv
//INSB need the I in the name to get the immediate from the tool
I INSBI INSBI 101011000--------000-----1110111 pdpibit Zpn
//I MADDR32 MADDR32 1100010----------001-----1110111 pdpimac Zpn
//I MSUBR32 MSUBR32 1100011----------001-----1110111 pdpimac Zpn
// ternary
I SMAQA SMAQA 1100100----------000----01110111 pdpiumul8 Zpnslow
I UMAQA UMAQA 1100110----------000----01110111 pdpismul8 Zpnslow
// ternary + binary (bit 25)
I PBSADx PBSADx 111111-----------000-----1110111 pdpipsad Zpn
// Saturating, currently doesn't set the CSR
I KADD8 KADD8 0001100----------000-----1110111 pdpikadd8 Zpn
I UKADD8 UKADD8 0011100----------000-----1110111 pdpikadd8 Zpn
I KSUB8 KSUB8 0001101----------000-----1110111 pdpikadd8 Zpn
I UKSUB8 UKSUB8 0011101----------000-----1110111 pdpikadd8 Zpn
// binary
S ADD8 "fun_add8(input(SRC1), input(SRC2))"
S ADD16 "fun_add16(input(SRC1), input(SRC2))"
S AVE "fun_ave(input(SRC1), input(SRC2))"
S BITREV "fun_bitrev(input(SRC1), input(SRC2))"
S CMPEQ8 "fun_cmpeq8(input(SRC1), input(SRC2))"
S CMPEQ16 "fun_cmpeq16(input(SRC1), input(SRC2))"
S PKxx16 "fun_pkbbtt16(input(SRC1), input(SRC2), input(INSTRUCTION)(29).asUInt, input(INSTRUCTION)(28).asUInt)"
S RADD8 "fun_radd8(input(SRC1), input(SRC2))"
S RADD16 "fun_radd16(input(SRC1), input(SRC2))"
S RADDW "fun_radd32(input(SRC1), input(SRC2))"
S RSUB8 "fun_rsub8(input(SRC1), input(SRC2))"
S RSUB16 "fun_rsub16(input(SRC1), input(SRC2))"
S RSUBW "fun_rsub32(input(SRC1), input(SRC2))"
S SCMPLE8 "fun_scmple8(input(SRC1), input(SRC2))"
S SCMPLE16 "fun_scmple16(input(SRC1), input(SRC2))"
S SCMPLT8 "fun_scmplt8(input(SRC1), input(SRC2))"
S SCMPLT16 "fun_scmplt16(input(SRC1), input(SRC2))"
S SLL8 "fun_sll8(input(SRC1), input(SRC2))"
S SRL8 "fun_srl8(input(SRC1), input(SRC2))"
S SRA8 "fun_sra8(input(SRC1), input(SRC2))"
S SLL16 "fun_sll16(input(SRC1), input(SRC2))"
S SRL16 "fun_srl16(input(SRC1), input(SRC2))"
S SRA16 "fun_sra16(input(SRC1), input(SRC2))"
S SMAX8 "fun_smax8(input(SRC1), input(SRC2))"
S SMAX16 "fun_smax16(input(SRC1), input(SRC2))"
S SMIN8 "fun_smin8(input(SRC1), input(SRC2))"
S SMIN16 "fun_smin16(input(SRC1), input(SRC2))"
S SUB8 "fun_sub8(input(SRC1), input(SRC2))"
S SUB16 "fun_sub16(input(SRC1), input(SRC2))"
S UCMPLE8 "fun_ucmple8(input(SRC1), input(SRC2))"
S UCMPLE16 "fun_ucmple16(input(SRC1), input(SRC2))"
S UCMPLT8 "fun_ucmplt8(input(SRC1), input(SRC2))"
S UCMPLT16 "fun_ucmplt16(input(SRC1), input(SRC2))"
S UMAX8 "fun_umax8(input(SRC1), input(SRC2))"
S UMAX16 "fun_umax16(input(SRC1), input(SRC2))"
S UMIN8 "fun_umin8(input(SRC1), input(SRC2))"
S UMIN16 "fun_umin16(input(SRC1), input(SRC2))"
S URADD8 "fun_uradd8(input(SRC1), input(SRC2))"
S URADD16 "fun_uradd16(input(SRC1), input(SRC2))"
S URADDW "fun_uradd32(input(SRC1), input(SRC2))"
S URSUB8 "fun_ursub8(input(SRC1), input(SRC2))"
S URSUB16 "fun_ursub16(input(SRC1), input(SRC2))"
S URSUBW "fun_ursub32(input(SRC1), input(SRC2))"
// unary
S CLRS8 "fun_clrs8(input(SRC1))"
S CLO8 "fun_clo8(input(SRC1))"
S CLZ8 "fun_clz8(input(SRC1))"
S SWAP8 "fun_swap8(input(SRC1))"
S SWAP16 "fun_swap16(input(SRC1))"
S SUNPKD8 "fun_sunpkd8(input(RS1), input(INSTRUCTION)(24 downto 23) ## input(INSTRUCTION)(21 downto 20))"
S ZUNPKD8 "fun_zunpkd8(input(RS1), input(INSTRUCTION)(24 downto 23) ## input(INSTRUCTION)(21 downto 20))"
// ternary
S PBSADx "fun_pbsada(input(SRC1), input(SRC2), (input(INSTRUCTION)(25).asUInt === 0) ? U(0, 32 bits).asBits | input(SRC3))"
S INSBI "fun_insb(input(SRC1), input(SRC2), input(SRC3))"
S SMAQA "fun_smaqa(input(SRC1), input(SRC2), input(SRC3))"
S UMAQA "fun_umaqa(input(SRC1), input(SRC2), input(SRC3))"
// saturating, fixme for csr
S KADD8 "fun_kadd8(input(SRC1), input(SRC2))"
S UKADD8 "fun_ukadd8(input(SRC1), input(SRC2))"
S KSUB8 "fun_ksub8(input(SRC1), input(SRC2))"
S UKSUB8 "fun_uksub8(input(SRC1), input(SRC2))"
P """
def fun_add8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt + rs2( 7 downto 0).asUInt).asBits.resize(8)
val b1 = (rs1(15 downto 8).asUInt + rs2(15 downto 8).asUInt).asBits.resize(8)
val b2 = (rs1(23 downto 16).asUInt + rs2(23 downto 16).asUInt).asBits.resize(8)
val b3 = (rs1(31 downto 24).asUInt + rs2(31 downto 24).asUInt).asBits.resize(8)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_radd8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = ((rs1( 7) ## rs1( 7 downto 0)).asSInt + (rs2( 7) ## rs2( 7 downto 0)).asSInt).asBits.resize(9)
val b1 = ((rs1(15) ## rs1(15 downto 8)).asSInt + (rs2(15) ## rs2(15 downto 8)).asSInt).asBits.resize(9)
val b2 = ((rs1(23) ## rs1(23 downto 16)).asSInt + (rs2(23) ## rs2(23 downto 16)).asSInt).asBits.resize(9)
val b3 = ((rs1(31) ## rs1(31 downto 24)).asSInt + (rs2(31) ## rs2(31 downto 24)).asSInt).asBits.resize(9)
b3(8 downto 1) ## b2(8 downto 1) ## b1(8 downto 1) ## b0(8 downto 1) // return value
}
def fun_rsub8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = ((rs1( 7) ## rs1( 7 downto 0)).asSInt - (rs2( 7) ## rs2( 7 downto 0)).asSInt).asBits.resize(9)
val b1 = ((rs1(15) ## rs1(15 downto 8)).asSInt - (rs2(15) ## rs2(15 downto 8)).asSInt).asBits.resize(9)
val b2 = ((rs1(23) ## rs1(23 downto 16)).asSInt - (rs2(23) ## rs2(23 downto 16)).asSInt).asBits.resize(9)
val b3 = ((rs1(31) ## rs1(31 downto 24)).asSInt - (rs2(31) ## rs2(31 downto 24)).asSInt).asBits.resize(9)
b3(8 downto 1) ## b2(8 downto 1) ## b1(8 downto 1) ## b0(8 downto 1) // return value
}
def fun_add16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asUInt + rs2(15 downto 0).asUInt).asBits.resize(16)
val h1 = (rs1(31 downto 16).asUInt + rs2(31 downto 16).asUInt).asBits.resize(16)
h1 ## h0 // return value
}
def fun_radd16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = ((rs1(15) ## rs1(15 downto 0)).asSInt + (rs2(15) ## rs2(15 downto 0)).asSInt).asBits.resize(17)
val h1 = ((rs1(31) ## rs1(31 downto 16)).asSInt + (rs2(31) ## rs2(31 downto 16)).asSInt).asBits.resize(17)
h1(16 downto 1) ## h0(16 downto 1) // return value
}
def fun_rsub16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = ((rs1(15) ## rs1(15 downto 0)).asSInt - (rs2(15) ## rs2(15 downto 0)).asSInt).asBits.resize(17)
val h1 = ((rs1(31) ## rs1(31 downto 16)).asSInt - (rs2(31) ## rs2(31 downto 16)).asSInt).asBits.resize(17)
h1(16 downto 1) ## h0(16 downto 1) // return value
}
def fun_radd32(rs1: Bits, rs2: Bits) : Bits = {
val s = ((rs1(31) ## rs1).asSInt + (rs2(31) ## rs2).asSInt).asBits.resize(33)
s(32 downto 1) // return value
}
def fun_rsub32(rs1: Bits, rs2: Bits) : Bits = {
val s = ((rs1(31) ## rs1).asSInt - (rs2(31) ## rs2).asSInt).asBits.resize(33)
s(32 downto 1) // return value
}
def fun_ave(rs1: Bits, rs2: Bits) : Bits = {
val inter = (1 + (rs1 ## B"1'b0").asUInt + (rs2 ## B"1'b0").asUInt).asBits.resize(33)
inter(32 downto 1) // return value
}
def fun_bitrev(rs1: Bits, rs2: Bits) : Bits = {
val msb = rs2(4 downto 0).asUInt
val rs1r = rs1(0) ## rs1(1) ## rs1(2) ## rs1(3) ## rs1(4) ## rs1(5) ## rs1(6) ## rs1(7) ## rs1(8) ## rs1(9) ## rs1(10) ## rs1(11) ## rs1(12) ## rs1(13) ## rs1(14) ## rs1(15) ## rs1(16) ## rs1(17) ## rs1(18) ## rs1(19) ## rs1(20) ## rs1(21) ## rs1(22) ## rs1(23) ## rs1(24) ## rs1(25) ## rs1(26) ## rs1(27) ## rs1(28) ## rs1(29) ## rs1(30) ## rs1(31)
val rs1rs = rs1r |>> (31-msb)
rs1rs // return value
}
// this is trying to look like DOI 10.2478/jee-2015-0054
def fun_clz_NLCi(x:Bits): Bits = {
val r2 = (~(x(0) | x(1) | x(2) | x(3)))
val r1 = (~(x(2) | x(3)))
val r0 = (~(x(3) | (x(1) & ~x(2))))
val r = r2 ## r1 ## r0
r // return value
}
def fun_clz_byte(in: Bits): Bits = {
val nlc1 = fun_clz_NLCi(in( 7 downto 4))
val nlc0 = fun_clz_NLCi(in( 3 downto 0))
val x = ((nlc1(2).asUInt === 1) ? (4 + nlc0(1 downto 0).asUInt) | (nlc1(1 downto 0).asUInt))
val y = B"8'x08"
((nlc0(2).asUInt === 1) && (nlc1(2).asUInt === 1)) ? y | x.asBits.resize(8) // return value
}
def fun_clrs8(rs1: Bits) : Bits = {
val b0 = rs1( 7 downto 0)
val b1 = rs1(15 downto 8)
val b2 = rs1(23 downto 16)
val b3 = rs1(31 downto 24)
val b0s = (b0(7).asUInt === 1) ? (~b0) | (b0)
val b1s = (b1(7).asUInt === 1) ? (~b1) | (b1)
val b2s = (b2(7).asUInt === 1) ? (~b2) | (b2)
val b3s = (b3(7).asUInt === 1) ? (~b3) | (b3)
val c0 = fun_clz_byte(b0s).asUInt - 1
val c1 = fun_clz_byte(b1s).asUInt - 1
val c2 = fun_clz_byte(b2s).asUInt - 1
val c3 = fun_clz_byte(b3s).asUInt - 1
c3.asBits.resize(8) ## c2.asBits.resize(8) ## c1.asBits.resize(8) ## c0.asBits.resize(8) // return value
}
def fun_clo8(rs1: Bits) : Bits = {
val b0 = rs1( 7 downto 0)
val b1 = rs1(15 downto 8)
val b2 = rs1(23 downto 16)
val b3 = rs1(31 downto 24)
val c0 = fun_clz_byte(~b0)
val c1 = fun_clz_byte(~b1)
val c2 = fun_clz_byte(~b2)
val c3 = fun_clz_byte(~b3)
c3 ## c2 ## c1 ## c0 // return value
}
def fun_clz8(rs1: Bits) : Bits = {
val b0 = rs1( 7 downto 0)
val b1 = rs1(15 downto 8)
val b2 = rs1(23 downto 16)
val b3 = rs1(31 downto 24)
val c0 = fun_clz_byte(b0)
val c1 = fun_clz_byte(b1)
val c2 = fun_clz_byte(b2)
val c3 = fun_clz_byte(b3)
c3 ## c2 ## c1 ## c0 // return value
}
def fun_swap8(rs1: Bits) : Bits = {
val b0 = rs1( 7 downto 0)
val b1 = rs1(15 downto 8)
val b2 = rs1(23 downto 16)
val b3 = rs1(31 downto 24)
b2 ## b3 ## b0 ## b1 // return value
}
def fun_swap16(rs1: Bits) : Bits = {
val h0 = rs1(15 downto 0)
val h1 = rs1(31 downto 16)
h0 ## h1 // return value
}
def fun_cmpeq8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt === rs2( 7 downto 0).asUInt) ? B"8'xFF" | B"8'x00"
val b1 = (rs1(15 downto 8).asUInt === rs2(15 downto 8).asUInt) ? B"8'xFF" | B"8'x00"
val b2 = (rs1(23 downto 16).asUInt === rs2(23 downto 16).asUInt) ? B"8'xFF" | B"8'x00"
val b3 = (rs1(31 downto 24).asUInt === rs2(31 downto 24).asUInt) ? B"8'xFF" | B"8'x00"
b3 ## b2 ## b1 ## b0 // return value
}
def fun_cmpeq16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asUInt === rs2(15 downto 0).asUInt) ? B"16'xFFFF" | B"16'x0000"
val h1 = (rs1(31 downto 16).asUInt === rs2(31 downto 16).asUInt) ? B"16'xFFFF" | B"16'x0000"
h1 ## h0 // return value
}
def fun_pkbbtt16(rs1: Bits, rs2: Bits, h:UInt, l:UInt) : Bits = {
val hr = (h === 0) ? rs1(15 downto 0) | rs1(31 downto 16)
val hl = (l === 0) ? rs2(15 downto 0) | rs2(31 downto 16)
hr ## hl // return value
}
def fun_scmple8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asSInt <= rs2( 7 downto 0).asSInt) ? B"8'xFF" | B"8'x00"
val b1 = (rs1(15 downto 8).asSInt <= rs2(15 downto 8).asSInt) ? B"8'xFF" | B"8'x00"
val b2 = (rs1(23 downto 16).asSInt <= rs2(23 downto 16).asSInt) ? B"8'xFF" | B"8'x00"
val b3 = (rs1(31 downto 24).asSInt <= rs2(31 downto 24).asSInt) ? B"8'xFF" | B"8'x00"
b3 ## b2 ## b1 ## b0 // return value
}
def fun_scmple16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asSInt <= rs2(15 downto 0).asSInt) ? B"16'xFFFF" | B"16'x0000"
val h1 = (rs1(31 downto 16).asSInt <= rs2(31 downto 16).asSInt) ? B"16'xFFFF" | B"16'x0000"
h1 ## h0 // return value
}
def fun_scmplt8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asSInt < rs2( 7 downto 0).asSInt) ? B"8'xFF" | B"8'x00"
val b1 = (rs1(15 downto 8).asSInt < rs2(15 downto 8).asSInt) ? B"8'xFF" | B"8'x00"
val b2 = (rs1(23 downto 16).asSInt < rs2(23 downto 16).asSInt) ? B"8'xFF" | B"8'x00"
val b3 = (rs1(31 downto 24).asSInt < rs2(31 downto 24).asSInt) ? B"8'xFF" | B"8'x00"
b3 ## b2 ## b1 ## b0 // return value
}
def fun_scmplt16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asSInt < rs2(15 downto 0).asSInt) ? B"16'xFFFF" | B"16'x0000"
val h1 = (rs1(31 downto 16).asSInt < rs2(31 downto 16).asSInt) ? B"16'xFFFF" | B"16'x0000"
h1 ## h0 // return value
}
def fun_ucmple8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt <= rs2( 7 downto 0).asUInt) ? B"8'xFF" | B"8'x00"
val b1 = (rs1(15 downto 8).asUInt <= rs2(15 downto 8).asUInt) ? B"8'xFF" | B"8'x00"
val b2 = (rs1(23 downto 16).asUInt <= rs2(23 downto 16).asUInt) ? B"8'xFF" | B"8'x00"
val b3 = (rs1(31 downto 24).asUInt <= rs2(31 downto 24).asUInt) ? B"8'xFF" | B"8'x00"
b3 ## b2 ## b1 ## b0 // return value
}
def fun_ucmple16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asUInt <= rs2(15 downto 0).asUInt) ? B"16'xFFFF" | B"16'x0000"
val h1 = (rs1(31 downto 16).asUInt <= rs2(31 downto 16).asUInt) ? B"16'xFFFF" | B"16'x0000"
h1 ## h0 // return value
}
def fun_ucmplt8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt < rs2( 7 downto 0).asUInt) ? B"8'xFF" | B"8'x00"
val b1 = (rs1(15 downto 8).asUInt < rs2(15 downto 8).asUInt) ? B"8'xFF" | B"8'x00"
val b2 = (rs1(23 downto 16).asUInt < rs2(23 downto 16).asUInt) ? B"8'xFF" | B"8'x00"
val b3 = (rs1(31 downto 24).asUInt < rs2(31 downto 24).asUInt) ? B"8'xFF" | B"8'x00"
b3 ## b2 ## b1 ## b0 // return value
}
def fun_ucmplt16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asUInt < rs2(15 downto 0).asUInt) ? B"16'xFFFF" | B"16'x0000"
val h1 = (rs1(31 downto 16).asUInt < rs2(31 downto 16).asUInt) ? B"16'xFFFF" | B"16'x0000"
h1 ## h0 // return value
}
def fun_sll8(rs1: Bits, rs2: Bits) : Bits = {
val o = rs2(2 downto 0).asUInt
val b0 = rs1( 7 downto 0).asUInt |<< o
val b1 = rs1(15 downto 8).asUInt |<< o
val b2 = rs1(23 downto 16).asUInt |<< o
val b3 = rs1(31 downto 24).asUInt |<< o
b3 ## b2 ## b1 ## b0 // return value
}
def fun_srl8(rs1: Bits, rs2: Bits) : Bits = {
val o = rs2(2 downto 0).asUInt
val b0 = rs1( 7 downto 0).asUInt |>> o
val b1 = rs1(15 downto 8).asUInt |>> o
val b2 = rs1(23 downto 16).asUInt |>> o
val b3 = rs1(31 downto 24).asUInt |>> o
b3 ## b2 ## b1 ## b0 // return value
}
def fun_sra8(rs1: Bits, rs2: Bits) : Bits = {
val o = rs2(2 downto 0).asUInt
val b0 = rs1( 7 downto 0).asSInt |>> o
val b1 = rs1(15 downto 8).asSInt |>> o
val b2 = rs1(23 downto 16).asSInt |>> o
val b3 = rs1(31 downto 24).asSInt |>> o
b3 ## b2 ## b1 ## b0 // return value
}
def fun_sll16(rs1: Bits, rs2: Bits) : Bits = {
val o = rs2(3 downto 0).asUInt
val h0 = rs1(15 downto 0).asUInt |<< o
val h1 = rs1(31 downto 16).asUInt |<< o
h1 ## h0 // return value
}
def fun_srl16(rs1: Bits, rs2: Bits) : Bits = {
val o = rs2(3 downto 0).asUInt
val h0 = rs1(15 downto 0).asUInt |>> o
val h1 = rs1(31 downto 16).asUInt |>> o
h1 ## h0 // return value
}
def fun_sra16(rs1: Bits, rs2: Bits) : Bits = {
val o = rs2(3 downto 0).asUInt
val h0 = rs1(15 downto 0).asSInt |>> o
val h1 = rs1(31 downto 16).asSInt |>> o
h1 ## h0 // return value
}
def fun_smax8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asSInt >= rs2( 7 downto 0).asSInt) ? rs1( 7 downto 0) | rs2( 7 downto 0)
val b1 = (rs1(15 downto 8).asSInt >= rs2(15 downto 8).asSInt) ? rs1(15 downto 8) | rs2(15 downto 8)
val b2 = (rs1(23 downto 16).asSInt >= rs2(23 downto 16).asSInt) ? rs1(23 downto 16) | rs2(23 downto 16)
val b3 = (rs1(31 downto 24).asSInt >= rs2(31 downto 24).asSInt) ? rs1(31 downto 24) | rs2(31 downto 24)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_smax16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asSInt >= rs2(15 downto 0).asSInt) ? rs1(15 downto 0) | rs2(15 downto 0)
val h1 = (rs1(31 downto 16).asSInt >= rs2(31 downto 16).asSInt) ? rs1(31 downto 16) | rs2(31 downto 16)
h1 ## h0 // return value
}
def fun_smin8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asSInt <= rs2( 7 downto 0).asSInt) ? rs1( 7 downto 0) | rs2( 7 downto 0)
val b1 = (rs1(15 downto 8).asSInt <= rs2(15 downto 8).asSInt) ? rs1(15 downto 8) | rs2(15 downto 8)
val b2 = (rs1(23 downto 16).asSInt <= rs2(23 downto 16).asSInt) ? rs1(23 downto 16) | rs2(23 downto 16)
val b3 = (rs1(31 downto 24).asSInt <= rs2(31 downto 24).asSInt) ? rs1(31 downto 24) | rs2(31 downto 24)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_smin16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asSInt <= rs2(15 downto 0).asSInt) ? rs1(15 downto 0) | rs2(15 downto 0)
val h1 = (rs1(31 downto 16).asSInt <= rs2(31 downto 16).asSInt) ? rs1(31 downto 16) | rs2(31 downto 16)
h1 ## h0 // return value
}
def fun_umax8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt >= rs2( 7 downto 0).asUInt) ? rs1( 7 downto 0) | rs2( 7 downto 0)
val b1 = (rs1(15 downto 8).asUInt >= rs2(15 downto 8).asUInt) ? rs1(15 downto 8) | rs2(15 downto 8)
val b2 = (rs1(23 downto 16).asUInt >= rs2(23 downto 16).asUInt) ? rs1(23 downto 16) | rs2(23 downto 16)
val b3 = (rs1(31 downto 24).asUInt >= rs2(31 downto 24).asUInt) ? rs1(31 downto 24) | rs2(31 downto 24)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_umax16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asUInt >= rs2(15 downto 0).asUInt) ? rs1(15 downto 0) | rs2(15 downto 0)
val h1 = (rs1(31 downto 16).asUInt >= rs2(31 downto 16).asUInt) ? rs1(31 downto 16) | rs2(31 downto 16)
h1 ## h0 // return value
}
def fun_umin8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt <= rs2( 7 downto 0).asUInt) ? rs1( 7 downto 0) | rs2( 7 downto 0)
val b1 = (rs1(15 downto 8).asUInt <= rs2(15 downto 8).asUInt) ? rs1(15 downto 8) | rs2(15 downto 8)
val b2 = (rs1(23 downto 16).asUInt <= rs2(23 downto 16).asUInt) ? rs1(23 downto 16) | rs2(23 downto 16)
val b3 = (rs1(31 downto 24).asUInt <= rs2(31 downto 24).asUInt) ? rs1(31 downto 24) | rs2(31 downto 24)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_umin16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asUInt <= rs2(15 downto 0).asUInt) ? rs1(15 downto 0) | rs2(15 downto 0)
val h1 = (rs1(31 downto 16).asUInt <= rs2(31 downto 16).asUInt) ? rs1(31 downto 16) | rs2(31 downto 16)
h1 ## h0 // return value
}
def fun_sub8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt - rs2( 7 downto 0).asUInt).asBits.resize(8)
val b1 = (rs1(15 downto 8).asUInt - rs2(15 downto 8).asUInt).asBits.resize(8)
val b2 = (rs1(23 downto 16).asUInt - rs2(23 downto 16).asUInt).asBits.resize(8)
val b3 = (rs1(31 downto 24).asUInt - rs2(31 downto 24).asUInt).asBits.resize(8)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_sub16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = (rs1(15 downto 0).asUInt - rs2(15 downto 0).asUInt).asBits.resize(16)
val h1 = (rs1(31 downto 16).asUInt - rs2(31 downto 16).asUInt).asBits.resize(16)
h1 ## h0 // return value
}
def fun_uradd8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = ((B"1'b0" ## rs1( 7 downto 0)).asUInt + (B"1'b0" ## rs2( 7 downto 0)).asUInt).asBits.resize(9)
val b1 = ((B"1'b0" ## rs1(15 downto 8)).asUInt + (B"1'b0" ## rs2(15 downto 8)).asUInt).asBits.resize(9)
val b2 = ((B"1'b0" ## rs1(23 downto 16)).asUInt + (B"1'b0" ## rs2(23 downto 16)).asUInt).asBits.resize(9)
val b3 = ((B"1'b0" ## rs1(31 downto 24)).asUInt + (B"1'b0" ## rs2(31 downto 24)).asUInt).asBits.resize(9)
b3(8 downto 1) ## b2(8 downto 1) ## b1(8 downto 1) ## b0(8 downto 1) // return value
}
def fun_ursub8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = ((B"1'b0" ## rs1( 7 downto 0)).asUInt - (B"1'b0" ## rs2( 7 downto 0)).asUInt).asBits.resize(9)
val b1 = ((B"1'b0" ## rs1(15 downto 8)).asUInt - (B"1'b0" ## rs2(15 downto 8)).asUInt).asBits.resize(9)
val b2 = ((B"1'b0" ## rs1(23 downto 16)).asUInt - (B"1'b0" ## rs2(23 downto 16)).asUInt).asBits.resize(9)
val b3 = ((B"1'b0" ## rs1(31 downto 24)).asUInt - (B"1'b0" ## rs2(31 downto 24)).asUInt).asBits.resize(9)
b3(8 downto 1) ## b2(8 downto 1) ## b1(8 downto 1) ## b0(8 downto 1) // return value
}
def fun_uradd16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = ((B"1'b0" ## rs1(15 downto 0)).asUInt + (B"1'b0" ## rs2(15 downto 0)).asUInt).asBits.resize(17)
val h1 = ((B"1'b0" ## rs1(31 downto 16)).asUInt + (B"1'b0" ## rs2(31 downto 16)).asUInt).asBits.resize(17)
h1(16 downto 1) ## h0(16 downto 1) // return value
}
def fun_ursub16(rs1: Bits, rs2: Bits) : Bits = {
val h0 = ((B"1'b0" ## rs1(15 downto 0)).asUInt - (B"1'b0" ## rs2(15 downto 0)).asUInt).asBits.resize(17)
val h1 = ((B"1'b0" ## rs1(31 downto 16)).asUInt - (B"1'b0" ## rs2(31 downto 16)).asUInt).asBits.resize(17)
h1(16 downto 1) ## h0(16 downto 1) // return value
}
def fun_uradd32(rs1: Bits, rs2: Bits) : Bits = {
val s = ((B"1'b0" ## rs1).asUInt + (B"1'b0" ## rs2).asUInt).asBits.resize(33)
s(32 downto 1) // return value
}
def fun_ursub32(rs1: Bits, rs2: Bits) : Bits = {
val s = ((B"1'b0" ## rs1).asUInt - (B"1'b0" ## rs2).asUInt).asBits.resize(33)
s(32 downto 1) // return value
}
def fun_pbsada(rs1: Bits, rs2: Bits, rs3: Bits) : Bits = {
// zero-extend to handle as unsigned
val b0 = ((B"1'b0" ## rs1( 7 downto 0)).asSInt - (B"1'b0" ## rs2( 7 downto 0)).asSInt)
val b1 = ((B"1'b0" ## rs1(15 downto 8)).asSInt - (B"1'b0" ## rs2(15 downto 8)).asSInt)
val b2 = ((B"1'b0" ## rs1(23 downto 16)).asSInt - (B"1'b0" ## rs2(23 downto 16)).asSInt)
val b3 = ((B"1'b0" ## rs1(31 downto 24)).asSInt - (B"1'b0" ## rs2(31 downto 24)).asSInt)
val sum = rs3.asUInt + b0.abs + b1.abs + b2.abs + b3.abs
sum.asBits.resize(32) // return value
}
def fun_insb(rs1: Bits, rs2: Bits, rs3: Bits) : Bits = {
val idx = rs2(1 downto 0).asUInt
val b = rs1(7 downto 0)
val r = (idx).mux(
0 -> rs3(31 downto 8) ## b,
1 -> rs3(31 downto 16) ## b ## rs3( 7 downto 0),
2 -> rs3(31 downto 24) ## b ## rs3(15 downto 0),
3 -> b ## rs3(23 downto 0)
)
r // return value
}
def fun_smaqa(rs1: Bits, rs2: Bits, rs3: Bits) : Bits = {
val h0 = (rs1( 7 downto 0).asSInt * rs2( 7 downto 0).asSInt).resize(18)
val h1 = (rs1(15 downto 8).asSInt * rs2(15 downto 8).asSInt).resize(18)
val h2 = (rs1(23 downto 16).asSInt * rs2(23 downto 16).asSInt).resize(18)
val h3 = (rs1(31 downto 24).asSInt * rs2(31 downto 24).asSInt).resize(18)
val r = rs3.asSInt + (h0 + h1 + h2 + h3)
r.asBits.resize(32) // return value
}
def fun_umaqa(rs1: Bits, rs2: Bits, rs3: Bits) : Bits = {
// 18 bits needed so that intermediate sums don't overflow
val h0 = (rs1( 7 downto 0).asUInt * rs2( 7 downto 0).asUInt).resize(18)
val h1 = (rs1(15 downto 8).asUInt * rs2(15 downto 8).asUInt).resize(18)
val h2 = (rs1(23 downto 16).asUInt * rs2(23 downto 16).asUInt).resize(18)
val h3 = (rs1(31 downto 24).asUInt * rs2(31 downto 24).asUInt).resize(18)
val r = rs3.asUInt + (h0 + h1 + h2 + h3)
r.asBits.resize(32) // return value
}
def fun_zunpkd8(rs1: Bits, ctrl: Bits) : Bits = {
val r = (ctrl).mux(
default -> rs1(15 downto 8).resize(16) ## rs1( 7 downto 0).resize(16), // B"4'b0100"
B"4'b0101" -> rs1(23 downto 16).resize(16) ## rs1( 7 downto 0).resize(16),
B"4'b0110" -> rs1(31 downto 24).resize(16) ## rs1( 7 downto 0).resize(16),
B"4'b0111" -> rs1(31 downto 24).resize(16) ## rs1(15 downto 8).resize(16),
B"4'b1011" -> rs1(31 downto 24).resize(16) ## rs1(23 downto 16).resize(16)
)
r // return value
}
def fun_sunpkd8(rs1: Bits, ctrl: Bits) : Bits = {
val r = (ctrl).mux(
default -> rs1(15 downto 8).asSInt.resize(16).asBits ## rs1( 7 downto 0).asSInt.resize(16).asBits, // B"4'b0100"
B"4'b0101" -> rs1(23 downto 16).asSInt.resize(16).asBits ## rs1( 7 downto 0).asSInt.resize(16).asBits,
B"4'b0110" -> rs1(31 downto 24).asSInt.resize(16).asBits ## rs1( 7 downto 0).asSInt.resize(16).asBits,
B"4'b0111" -> rs1(31 downto 24).asSInt.resize(16).asBits ## rs1(15 downto 8).asSInt.resize(16).asBits,
B"4'b1011" -> rs1(31 downto 24).asSInt.resize(16).asBits ## rs1(23 downto 16).asSInt.resize(16).asBits
)
r // return value
}
// saturating, csr is missing
// it seems sat() (and its shortcut +| and -|) in SpinalHDL don't do what I need
// for unsigned substraction (no way to tell the difference between overflow
// and underflow unless going signed, I think)
def fun_satsub8u(a: Bits, b: Bits) : Bits = {
val s = (B"1'b0" ## a).asSInt -^ (B"1'b0" ## b).asSInt // -^ will keep 10 bits
// if sign bit set -> underflow, else if bit eight set -> overflow
val r = ((s(9).asUInt === 1) ? (B"8'x00") | ((s(8).asUInt === 1) ? (B"8'xFF") | (s(7 downto 0).asBits)))
r // return value
}
def fun_kadd8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asSInt +| rs2( 7 downto 0).asSInt).asBits.resize(8)
val b1 = (rs1(15 downto 8).asSInt +| rs2(15 downto 8).asSInt).asBits.resize(8)
val b2 = (rs1(23 downto 16).asSInt +| rs2(23 downto 16).asSInt).asBits.resize(8)
val b3 = (rs1(31 downto 24).asSInt +| rs2(31 downto 24).asSInt).asBits.resize(8)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_ukadd8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asUInt +| rs2( 7 downto 0).asUInt).asBits.resize(8)
val b1 = (rs1(15 downto 8).asUInt +| rs2(15 downto 8).asUInt).asBits.resize(8)
val b2 = (rs1(23 downto 16).asUInt +| rs2(23 downto 16).asUInt).asBits.resize(8)
val b3 = (rs1(31 downto 24).asUInt +| rs2(31 downto 24).asUInt).asBits.resize(8)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_ksub8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = (rs1( 7 downto 0).asSInt -| rs2( 7 downto 0).asSInt).asBits.resize(8)
val b1 = (rs1(15 downto 8).asSInt -| rs2(15 downto 8).asSInt).asBits.resize(8)
val b2 = (rs1(23 downto 16).asSInt -| rs2(23 downto 16).asSInt).asBits.resize(8)
val b3 = (rs1(31 downto 24).asSInt -| rs2(31 downto 24).asSInt).asBits.resize(8)
b3 ## b2 ## b1 ## b0 // return value
}
def fun_uksub8(rs1: Bits, rs2: Bits) : Bits = {
val b0 = fun_satsub8u(rs1( 7 downto 0), rs2( 7 downto 0)).asBits
val b1 = fun_satsub8u(rs1(15 downto 8), rs2(15 downto 8)).asBits
val b2 = fun_satsub8u(rs1(23 downto 16), rs2(23 downto 16)).asBits
val b3 = fun_satsub8u(rs1(31 downto 24), rs2(31 downto 24)).asBits
b3 ## b2 ## b1 ## b0 // return value
}
"""