在CHISEL中创建查找表

问题描述 投票:3回答:1

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

但是,当我将widthuInt更改为任何数字<= 64时,不会出现此类问题,并且代码可以正常工作。有没有其他方法可以在Chisel中创建我指定的大小以上的LUT?还是我在上面的代码中做错了什么?请帮助。

scala hdl lookup-tables file-read chisel
1个回答
1
投票

在当前版本的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测试了上面的内容,并且效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.