Re: Howto Lookup-Table

Christopher Felton <[email protected]> Thu, 21 Jan 2016 08:28:11 -0600
Newsgroups gmane.comp.python.myhdl
Message-ID <[email protected]>
On 1/21/2016 5:07 AM, Marcel Hellwig wrote:
> Hello everyone,
>
> for my current project I need some kind of lookup-table.
> Setting:
>      I have different CPU Modes and depending on the mode, I need to
> access certain registerbanks (yeah, it's an arm-ripof)
>
> My intentional idea was to create a dictionary where the keys are the
> modes and the values are the register numbers, e.g.
>
>>
>> regbank = {
>>      cpumode_User : (R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11,
>> R12, R13, R14, PC, CPSR),
>>      ..... }
>>
>> registers = [Signal(intbv(0)[32:]) for _ in range(37)]
>
>
> and then access them via registers[regbank[mode][rd]] whereas mode is
> the mode (just an Signal(int)) and rd is the destionation register. R0,
> R1, ... etc are ints as well
>
> This leads to:
>> Object type is not supported in this context: regbank, <type 'dict'>
>

Yes, as you discovered dictionaries are not directly
convertible.  The convertible types are described
here:
http://docs.myhdl.org/en/stable/manual/conversion.html#supported-types

This doesn't mean you can't use dicts to manage the
information in your design it just means you are limited
to using dicts in elaboration (outside the myhdl
generators).


> Okay, I thought, then I will just outsource the tuples to variables and
> make a "big" if/elif switch-case. But that don't work either :/
>

I am not sure I am following but I think you need this
simple change

     offset = USER[rd]
     regs[offset].next = din

When using a tuple-of-ints (ROM) the values can't be
accessed directly in an expression, you first have to
get the value and then use it in an expression.

The above is a FAQ, we should add it do the documentation
in the following section:

http://docs.myhdl.org/en/stable/manual/conversion_examples.html#rom-inference


Regards,
Chris




------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140