xref: /XiangShan/src/main/scala/xiangshan/backend/fu/fpu/FliTable.scala (revision e1d5ffc2d93873b72146e78c8f6a904926de8590)
1package xiangshan.backend.fu.fpu
2
3import chisel3._
4import chisel3.util._
5import chisel3.util.experimental.decode._
6
7class FliTable(table: Seq[Int]) extends Module {
8  val src = IO(Input(UInt(5.W)))
9  val out = IO(Output(UInt(16.W)))
10
11  out := chisel3.util.experimental.decode.decoder(src,
12    TruthTable(table.zipWithIndex.map { case(data, in) =>
13      (BitPat(in.U(5.W)), BitPat(data.U(16.W)))
14    },
15      BitPat.N(16)
16    )
17  )
18}
19
20class FliHTable extends FliTable(
21  Seq(
22    0xBC00, // -1.0
23    0x0400, // minimum positive normal
24    0x0100, // 1.0 * 2^-16
25    0x0200, // 1.0 * 2^-15
26    0x1C00, // 1.0 * 2^-8
27    0x2000, // 1.0 * 2^-7
28    0x2C00, // 1.0 * 2^-4
29    0x3000, // 1.0 * 2^-3
30    0x3400, // 0.25
31    0x3500, // 0.3125
32    0x3600, // 0.375
33    0x3700, // 0.4375
34    0x3800, // 0.5
35    0x3900, // 0.625
36    0x3A00, // 0.75
37    0x3B00, // 0.875
38    0x3C00, // 1.0
39    0x3D00, // 1.25
40    0x3E00, // 1.5
41    0x3F00, // 1.75
42    0x4000, // 2.0
43    0x4100, // 2.5
44    0x4200, // 3
45    0x4400, // 4
46    0x4800, // 8
47    0x4C00, // 16
48    0x5800, // 2^7
49    0x5C00, // 2^8
50    0x7800, // 2^15
51    0x7C00, // +inf(2^16 is not expressible)
52    0x7C00, // +inf
53    0x7E00  // CNaN
54  )
55)
56
57class FliSTable extends FliTable(
58  Seq(
59    0xBF80, // -1.0
60    0x0080, // minimum positive normal
61    0x3780, // 1.0 * 2^-16
62    0x3800, // 1.0 * 2^-15
63    0x3B80, // 1.0 * 2^-8
64    0x3C00, // 1.0 * 2^-7
65    0x3D80, // 1.0 * 2^-4
66    0x3E00, // 1.0 * 2^-3
67    0x3E80, // 0.25
68    0x3EA0, // 0.3125
69    0x3EC0, // 0.375
70    0x3EE0, // 0.4375
71    0x3F00, // 0.5
72    0x3F20, // 0.625
73    0x3F40, // 0.75
74    0x3F60, // 0.875
75    0x3F80, // 1.0
76    0x3FA0, // 1.25
77    0x3FC0, // 1.5
78    0x3FE0, // 1.75
79    0x4000, // 2.0
80    0x4020, // 2.5
81    0x4040, // 3
82    0x4080, // 4
83    0x4100, // 8
84    0x4180, // 16
85    0x4300, // 2^7
86    0x4380, // 2^8
87    0x4700, // 2^15
88    0x4780, // 2^16
89    0x7F80, // +inf
90    0x7FC0  // CNaN
91  )
92)
93
94class FliDTable extends FliTable(
95  Seq(
96    0xBFF0, // -1.0
97    0x0010, // minimum positive normal
98    0x3EF0, // 1.0 * 2^-16
99    0x3F00, // 1.0 * 2^-15
100    0x3F70, // 1.0 * 2^-8
101    0x3F80, // 1.0 * 2^-7
102    0x3FB0, // 1.0 * 2^-4
103    0x3FC0, // 1.0 * 2^-3
104    0x3FD0, // 0.25
105    0x3FD4, // 0.3125
106    0x3FD8, // 0.375
107    0x3FDC, // 0.4375
108    0x3FE0, // 0.5
109    0x3FE4, // 0.625
110    0x3FE8, // 0.75
111    0x3FEC, // 0.875
112    0x3FF0, // 1.0
113    0x3FF4, // 1.25
114    0x3FF8, // 1.5
115    0x3FFC, // 1.75
116    0x4000, // 2.0
117    0x4004, // 2.5
118    0x4008, // 3
119    0x4010, // 4
120    0x4020, // 8
121    0x4030, // 16
122    0x4060, // 2^7
123    0x4070, // 2^8
124    0x40E0, // 2^15
125    0x40F0, // 2^16
126    0x7FF0, // +inf
127    0x7FF8  // CNaN
128  )
129)