-
Notifications
You must be signed in to change notification settings - Fork 3
/
data_bitmanip_compress.txt
60 lines (56 loc) · 1.83 KB
/
data_bitmanip_compress.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
I BDECOMPRESS BDECOMPRESS 0100100----------110-----0110011 bcompress Zbe
I BCOMPRESS BCOMPRESS 0000100----------110-----0110011 bcompress Zbe
S BCOMPRESS "fun_compress1(input(SRC1), input(SRC2))"
T BCOMPRESS 53 "fun_compress2"
S BDECOMPRESS "fun_decompress1(input(SRC1), input(SRC2))"
T BDECOMPRESS 69 "fun_decompress2"
P """
def fun_compress1(rs1:Bits, rs2: Bits) : Bits = {
var r = B"16'x0000"
var j = (B"5'b00000").asUInt
for (i <- 0 to 15) {
val rs2i = rs2(i).asUInt
val rs1i = rs2(i) & rs1(i)
r = r | (rs1i.asBits << j).resize(16)
j = j + rs2i
}
j.asBits.resize(5) ## r ## rs1(31 downto 16) ## rs2(31 downto 16)// return value
}
def fun_compress2(x:Bits) : Bits = {
val rs2 = x(15 downto 0)
val rs1 = x(31 downto 16)
var r = B"16'x0000" ## x(47 downto 32)
var j = x(52 downto 48).asUInt
for (i <- 0 to 15) {
val rs2i = rs2(i).asUInt
val rs1i = rs2(i) & rs1(i)
r = r | (rs1i.asBits << j).resize(32)
j = j + rs2i
}
r(31 downto 0) // return value
}
def fun_decompress1(rs1:Bits, rs2: Bits) : Bits = {
var r = B"16'x0000"
var j = (B"5'b00000").asUInt
for (i <- 0 to 15) {
val rs2i = rs2(i).asUInt
val rs1j = rs2(i) & (rs1 >> j)(0)
r = r | (rs1j.asBits << i).resize(16)
j = j + rs2i
}
j.asBits.resize(5) ## r ## rs1(31 downto 0) ## rs2(31 downto 16)// return value
}
def fun_decompress2(x:Bits) : Bits = {
val rs2 = x(15 downto 0)
val rs1 = x(47 downto 16)
var r = B"16'x0000" ## x(63 downto 48)
var j = x(68 downto 64).asUInt
for (i <- 0 to 15) {
val rs2i = rs2(i).asUInt
val rs1j = rs2(i) & (rs1 >> j)(0)
r = r | (rs1j.asBits << (i+16)).asBits.resize(32)
j = j + rs2i
}
r(31 downto 0) // return value
}
"""