我正在尝试在 Chisel 中创建一个宽度为 72 位和 1024 个条目的查找表。这 1024 个条目分别存储在一个文件中,我将其读入我的代码中。到目前为止我写的代码是:
import Chisel._
import scala.io.Source._
module mdlNm {
// function to read entries from file 'omega_i.dat'
def fileRead() = {
val fileIn = fromFile("omega_i.dat").getLines.toList
val num = fileIn.map(i => BigInt(i, 16)) // converting the hexadecimal entries from string to BigInt
val uInt = num.map(i => UInt(i, width = 72)) // converting BigInt entries to UInt of width 72
ROM (uInt) // Chisel construct for creating an LUT for fixed entries
}
// The above LUT is later read as follows:
val in = Bits("h123") // Any 10-bit input to the LUT
val lutOut = fileRead().read(in) // Value read from the LUT
}
上面的代码抛出了很多形式的错误:
cppBackend//sinCos.cpp:2407:23: error: ‘T1785’ was not declared in this scope
{ T425.put(1018, 0, T1785[0]); T425.put(1018, 1, T1785[1]);}
^
cppBackend//sinCos.cpp:2408:23: error: ‘T1786’ was not declared in this scope
{ T425.put(1019, 0, T1786[0]); T425.put(1019, 1, T1786[1]);}
^
cppBackend//sinCos.cpp:2409:23: error: ‘T1787’ was not declared in this scope
{ T425.put(1020, 0, T1787[0]); T425.put(1020, 1, T1787[1]);}
^
cppBackend//sinCos.cpp:2410:23: error: ‘T1788’ was not declared in this scope
{ T425.put(1021, 0, T1788[0]); T425.put(1021, 1, T1788[1]);}
^
cppBackend//sinCos.cpp:2411:23: error: ‘T1789’ was not declared in this scope
{ T425.put(1022, 0, T1789[0]); T425.put(1022, 1, T1789[1]);}
^
cppBackend//sinCos.cpp:2412:23: error: ‘T1790’ was not declared in this scope
{ T425.put(1023, 0, T1790[0]); T425.put(1023, 1, T1790[1]);}
但是,当我更改 width
的 uInt
任何号码<= 64
,不会出现此类问题并且代码可以正常工作。
有没有其他方法可以在 Chisel 中创建我上面指定大小的 LUT?或者我在上面的代码中做错了什么?
请帮忙。
最佳答案
在当前版本的 chisel3 中,它的构造略有不同。 VecInit
被用来代替 ROM
我建议创建一个中间值 lut 来保存 buildLookupTable
创建的 rom
因为每次调用 buildLookupTable
都会再次读取文件并创建另一个 rom。
import chisel3._
import chisel3.util._
import firrtl.FileUtils
class SomeModule extends MultiIOModule {
def buildLookupTable(): Vec[UInt] = {
VecInit(FileUtils.getLines("file1.dat").map { s => BigInt(s, 16).U })
}
val lut = buildLookupTable()
// The above LUT is later read as follows:
val in = 0x123.U // Any 10-bit input to the LUT
val lutOut = lut(in) // Value read from the LUT
// rest of module
...
}
我不知道你的长度有什么问题,但我已经用宽度为 500 的 UInt
测试了上面的内容,它工作正常。
关于scala - 在 CHISEL 中创建查找表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37526907/