3

我正在尝试在 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]);}

但是,当我将widthof更改uInt为任意数字<= 64时,不会出现此类问题并且代码可以正常工作。是否有另一种方法可以在 Chisel 中创建我上面指定的大小的 LUT?或者我在上面的代码中做错了什么?请帮忙。

4

1 回答 1

2

在当前版本 chisel3 中,它的构造会有所不同。VecInit使用而不是 ROM 我建议创建一个中间值 lut 来保存创建的 rom,buildLookupTable 因为每次调用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
  ...
}

我不知道你的长度有什么问题,但我已经UInt用宽度为 500 的 s 测试了上面的内容,它工作正常。

于 2020-01-17T17:38:40.180 回答