-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata_bitmanip_ZbbOnly.txt
80 lines (73 loc) · 3.32 KB
/
data_bitmanip_ZbbOnly.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
// This is the specialized version of some more general instructions
// That are included by default in Zbb
// Those should not be combined with a plugin implementing the matching
// base instruction(s)
// base instructions implemented in B
//I PACK PACK 0000100----------100-----0110011 pack
//I GORCI GORC 00101------------101-----0010011 grevorc
//I GREVI GREV 01101------------101-----0010011 grevorc
//I SHFLI SHFL 0000100----------001-----0010011 shuffle
//I UNSHFLI UNSHFL 0000100----------101-----0010011 shuffle
// For Zbb
// ZEXT.H -> PACK w/ RS2 == 0
I ZEXTdotH ZEXTdotH 000010000000-----100-----0110011 signextend Zbb
// ORC.B -> GORCI w/ imm = 7 (0000111)
I ORCdotB ORCdotB 001010000111-----101-----0010011 grevorc Zbb
// REV8 -> GREVI w/ imm == 24 (0011000)
I REV8 REV8 011010011000-----101-----0010011 grevorc Zbb Zbkb
// those are for Zbkb only
// REVdotB -> GREVI w/ imm == 7 (0000111)
I REVdotB REVdotB 011010000111-----101-----0010011 grevorc Zbkb
// ZIP -> SHFLI w/ imm == 01111
I ZIP ZIP 000010001111-----001-----0010011 shuffle Zbkb
// UNZIP -> UNSHFLI w/ imm == 01111
I UNZIP UNZIP 000010001111-----101-----0010011 shuffle Zbkb
// SEMANTIC
S REV8 "fun_rev8(input(SRC1))"
S ORCdotB "fun_orcb(input(SRC1))"
S ZEXTdotH "(B"16'x0000" ## input(SRC1)(15 downto 0))"
S REVdotB "fun_revdotb(input(SRC1))"
S ZIP "fun_zip(input(SRC1))"
S UNZIP "fun_unzip(input(SRC1))"
// PROLOGUE
P """
def fun_rev8(a:Bits) : Bits = {
val r = a(7 downto 0) ## a(15 downto 8) ## a(23 downto 16) ## a(31 downto 24)
r // return value
}
def fun_orcb(a:Bits) : Bits = {
val x1 = (a | ((a & B"32'x55555555") |<< 1) | ((a & B"32'xAAAAAAAA") |>> 1))
val x2 = (x1 | ((x1 & B"32'x33333333") |<< 2) | ((x1 & B"32'xCCCCCCCC") |>> 2))
val x4 = (x2 | ((x2 & B"32'x0F0F0F0F") |<< 4) | ((x2 & B"32'xF0F0F0F0") |>> 4))
x4 // return value
}
def fun_revdotb(a:Bits) : Bits = {
val r = a(24) ## a(25) ## a(26) ## a(27) ## a(28) ## a(29) ## a(30) ## a(31) ##
a(16) ## a(17) ## a(18) ## a(19) ## a(20) ## a(21) ## a(22) ## a(23) ##
a( 8) ## a( 9) ## a(10) ## a(11) ## a(12) ## a(13) ## a(14) ## a(15) ##
a( 0) ## a( 1) ## a( 2) ## a( 3) ## a( 4) ## a( 5) ## a( 6) ## a( 7)
r // return value;
}
// helper function for the implementation of the generalized shuffles
def fun_shuffle32bis_stage(src:Bits, maskL:Bits, maskR:Bits, N:Int) : Bits = {
val x = src & ~(maskL | maskR)
val x2 = x | ((src |<< N) & maskL) | ((src |>> N) & maskR);
x2 // return value
}
def fun_zip(a:Bits) : Bits = {
val x = a;
val x1 = fun_shuffle32bis_stage(x , B"32'x00FF0000", B"32'x0000FF00", 8)
val x2 = fun_shuffle32bis_stage(x1, B"32'x0F000F00", B"32'x00F000F0", 4)
val x3 = fun_shuffle32bis_stage(x2, B"32'x30303030", B"32'x0C0C0C0C", 2)
val x4 = fun_shuffle32bis_stage(x3, B"32'x44444444", B"32'x22222222", 1)
x4 // return value
}
def fun_unzip(a:Bits) : Bits = {
val x = a;
val x1 = fun_shuffle32bis_stage(x , B"32'x44444444", B"32'x22222222", 1)
val x2 = fun_shuffle32bis_stage(x1, B"32'x30303030", B"32'x0C0C0C0C", 2)
val x3 = fun_shuffle32bis_stage(x2, B"32'x0F000F00", B"32'x00F000F0", 4)
val x4 = fun_shuffle32bis_stage(x3, B"32'x00FF0000", B"32'x0000FF00", 8)
x4 // return value
}
"""