Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Can't get to_integer to work

 
Thread Tools Search this Thread
Old 09-25-2003, 08:29 PM   #1
Default Can't get to_integer to work


I have an array that is supposed to act as a ROM-
lookup-table (actually a Rijndael G-box), and so I
want to give it a byte input and get a byte output.

The byte input, let's call it ADDR, is std_logic_vector(7 downto 0).
Sinse the indices of my "ROM"-array are integers, I need to convert
the ADDR vector to type integer. My "ROM"-array has 256 elements,
and the lookup should work something like this:

sub_byte <= ROM( 16*to_integer(ADDR(7 downto 4)) + to_integer(ADDR(3 downto
0)));

My problem is, no matter how I try, I can't get to_integer to work. I've
tried looking
at the FAQ, and I have search the net, and I have tried what has been
suggested, but
I can't seem to get it to work. So I need your help to convert ADDR from
being
a std_logic_vector(7 downto 0) into an integer.

Here is (part of) my code:

subbyte <= g_rom(addr) after lookup_delay;
type srd_array is array (0 to 255) of std_logic_vector(7 downto 0);
constant g_rom : srd_array := (

x"00",x"01",x"8D",x"F6",x"CB",x"52",x"7B",x"D1",x" E8",x"4F",x"29",x"C0",x"B0
",x"E1",x"E5",x"C7",

x"74",x"B4",x"AA",x"4B",x"99",x"2B",x"60",x"5F",x" 58",x"3F",x"FD",x"CC",x"FF
",x"40",x"EE",x"B2",

x"3A",x"6E",x"5A",x"F1",x"55",x"4D",x"A8",x"C9",x" C1",x"0A",x"98",x"15",x"30
",x"44",x"A2",x"C2",

x"2C",x"45",x"92",x"6C",x"F3",x"39",x"66",x"42",x" F2",x"35",x"20",x"6F",x"77
",x"BB",x"59",x"19",

x"1D",x"FE",x"37",x"67",x"2D",x"31",x"F5",x"69",x" A7",x"64",x"AB",x"13",x"54
",x"25",x"E9",x"09",

x"ED",x"5C",x"05",x"CA",x"4C",x"24",x"87",x"BF",x" 18",x"3E",x"22",x"F0",x"51
",x"EC",x"61",x"17",

x"16",x"5E",x"AF",x"D3",x"49",x"A6",x"36",x"43",x" F4",x"47",x"91",x"DF",x"33
",x"93",x"21",x"3B",

x"79",x"B7",x"97",x"85",x"10",x"B5",x"BA",x"3C",x" B6",x"70",x"D0",x"06",x"A1
",x"FA",x"81",x"82",

x"83",x"7E",x"7F",x"80",x"96",x"73",x"BE",x"56",x" 9B",x"9E",x"95",x"D9",x"F7
",x"02",x"B9",x"A4",

x"DE",x"6A",x"32",x"6D",x"D8",x"8A",x"84",x"72",x" 2A",x"14",x"9F",x"88",x"F9
",x"DC",x"89",x"9A",

x"FB",x"7C",x"2E",x"C3",x"8F",x"B8",x"65",x"48",x" 26",x"C8",x"12",x"4A",x"CE
",x"E7",x"D2",x"62",

x"0C",x"E0",x"1F",x"EF",x"11",x"75",x"78",x"71",x" A5",x"8E",x"76",x"3D",x"BD
",x"BC",x"86",x"57",

x"0B",x"28",x"2F",x"A3",x"DA",x"D4",x"E4",x"0F",x" A9",x"27",x"53",x"04",x"1B
",x"FC",x"AC",x"E6",

x"7A",x"07",x"AE",x"63",x"C5",x"DB",x"E2",x"EA",x" 94",x"8B",x"C4",x"D5",x"9D
",x"F8",x"90",x"6B",

x"B1",x"0D",x"D6",x"EB",x"C6",x"0E",x"CF",x"AD",x" 08",x"4E",x"D7",x"E3",x"5D
",x"50",x"1E",x"B3",

x"5B",x"23",x"38",x"34",x"68",x"46",x"03",x"8C",x" DD",x"9C",x"7D",x"A0",x"CD
",x"1A",x"41",x"1C"
);








Panic
  Reply With Quote
Old 09-25-2003, 08:37 PM   #2
Tim Hubberstey
 
Posts: n/a
Default Re: Can't get to_integer to work
Panic wrote:
>
> I have an array that is supposed to act as a ROM-
> lookup-table (actually a Rijndael G-box), and so I
> want to give it a byte input and get a byte output.
>
> The byte input, let's call it ADDR, is std_logic_vector(7 downto 0).
> Sinse the indices of my "ROM"-array are integers, I need to convert
> the ADDR vector to type integer. My "ROM"-array has 256 elements,
> and the lookup should work something like this:
>
> sub_byte <= ROM( 16*to_integer(ADDR(7 downto 4)) + to_integer(ADDR(3 downto
> 0)));


You can't convert std_logic_vector directly to integer. If you check the
function prototype, you'll find that to_integer only accepts signed or
unsigned as arguments. Try:

sub_byte <= ROM( 16*to_integer(unsigned(ADDR(7 downto 4))) +
to_integer(unsigned(ADDR(3 downto 0))));

I'm also not sure why you think you need to operate on slices of ADDR.
This should also work as long as ADDR is 31 bits or less:

sub_byte <= ROM(to_integer(unsigned(ADDR)));

--
Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com


Tim Hubberstey
  Reply With Quote
Old 09-25-2003, 08:59 PM   #3
Panic
 
Posts: n/a
Default Re: Can't get to_integer to work

> sub_byte <= ROM( 16*to_integer(unsigned(ADDR(7 downto 4))) +
> to_integer(unsigned(ADDR(3 downto 0))));


Tried thatone before. Didn't work. That what's baffles me, since I thought I
had understood how to_integer and unsigned works....

The error I get (for both unsigned and to_integer) is something about
element type mismatch.

> I'm also not sure why you think you need to operate on slices of ADDR.
> This should also work as long as ADDR is 31 bits or less:


ADDR is a byte, but the lookup is actually a matrix lookup. That's why I
need to do the calculation.




Panic
  Reply With Quote
Old 09-26-2003, 03:13 PM   #4
Ian Poole
 
Posts: n/a
Default Re: Can't get to_integer to work
What libraries are you using? Can you post some more code???

--
Ian Poole, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.


"Panic" <> wrote in message
news:AiHcb.32741$...
> I have an array that is supposed to act as a ROM-
> lookup-table (actually a Rijndael G-box), and so I
> want to give it a byte input and get a byte output.
>
> The byte input, let's call it ADDR, is std_logic_vector(7 downto 0).
> Sinse the indices of my "ROM"-array are integers, I need to convert
> the ADDR vector to type integer. My "ROM"-array has 256 elements,
> and the lookup should work something like this:
>
> sub_byte <= ROM( 16*to_integer(ADDR(7 downto 4)) + to_integer(ADDR(3

downto
> 0)));
>
> My problem is, no matter how I try, I can't get to_integer to work. I've
> tried looking
> at the FAQ, and I have search the net, and I have tried what has been
> suggested, but
> I can't seem to get it to work. So I need your help to convert ADDR from
> being
> a std_logic_vector(7 downto 0) into an integer.
>
> Here is (part of) my code:
>
> subbyte <= g_rom(addr) after lookup_delay;
> type srd_array is array (0 to 255) of std_logic_vector(7 downto 0);
> constant g_rom : srd_array := (
>
>

x"00",x"01",x"8D",x"F6",x"CB",x"52",x"7B",x"D1",x" E8",x"4F",x"29",x"C0",x"B0
> ",x"E1",x"E5",x"C7",
>
>

x"74",x"B4",x"AA",x"4B",x"99",x"2B",x"60",x"5F",x" 58",x"3F",x"FD",x"CC",x"FF
> ",x"40",x"EE",x"B2",
>
>

x"3A",x"6E",x"5A",x"F1",x"55",x"4D",x"A8",x"C9",x" C1",x"0A",x"98",x"15",x"30
> ",x"44",x"A2",x"C2",
>
>

x"2C",x"45",x"92",x"6C",x"F3",x"39",x"66",x"42",x" F2",x"35",x"20",x"6F",x"77
> ",x"BB",x"59",x"19",
>
>

x"1D",x"FE",x"37",x"67",x"2D",x"31",x"F5",x"69",x" A7",x"64",x"AB",x"13",x"54
> ",x"25",x"E9",x"09",
>
>

x"ED",x"5C",x"05",x"CA",x"4C",x"24",x"87",x"BF",x" 18",x"3E",x"22",x"F0",x"51
> ",x"EC",x"61",x"17",
>
>

x"16",x"5E",x"AF",x"D3",x"49",x"A6",x"36",x"43",x" F4",x"47",x"91",x"DF",x"33
> ",x"93",x"21",x"3B",
>
>

x"79",x"B7",x"97",x"85",x"10",x"B5",x"BA",x"3C",x" B6",x"70",x"D0",x"06",x"A1
> ",x"FA",x"81",x"82",
>
>

x"83",x"7E",x"7F",x"80",x"96",x"73",x"BE",x"56",x" 9B",x"9E",x"95",x"D9",x"F7
> ",x"02",x"B9",x"A4",
>
>

x"DE",x"6A",x"32",x"6D",x"D8",x"8A",x"84",x"72",x" 2A",x"14",x"9F",x"88",x"F9
> ",x"DC",x"89",x"9A",
>
>

x"FB",x"7C",x"2E",x"C3",x"8F",x"B8",x"65",x"48",x" 26",x"C8",x"12",x"4A",x"CE
> ",x"E7",x"D2",x"62",
>
>

x"0C",x"E0",x"1F",x"EF",x"11",x"75",x"78",x"71",x" A5",x"8E",x"76",x"3D",x"BD
> ",x"BC",x"86",x"57",
>
>

x"0B",x"28",x"2F",x"A3",x"DA",x"D4",x"E4",x"0F",x" A9",x"27",x"53",x"04",x"1B
> ",x"FC",x"AC",x"E6",
>
>

x"7A",x"07",x"AE",x"63",x"C5",x"DB",x"E2",x"EA",x" 94",x"8B",x"C4",x"D5",x"9D
> ",x"F8",x"90",x"6B",
>
>

x"B1",x"0D",x"D6",x"EB",x"C6",x"0E",x"CF",x"AD",x" 08",x"4E",x"D7",x"E3",x"5D
> ",x"50",x"1E",x"B3",
>
>

x"5B",x"23",x"38",x"34",x"68",x"46",x"03",x"8C",x" DD",x"9C",x"7D",x"A0",x"CD
> ",x"1A",x"41",x"1C"
> );
>
>
>
>
>
>





Ian Poole
  Reply With Quote
Old 09-26-2003, 04:46 PM   #5
Jim Lewis
 
Posts: n/a
Default Re: Can't get to_integer to work
What Tim said works if you are using package numeric_std:

use ieee.numeric_std.all ;


if instead you are using, std_logic_arith then use
conv_integer instead.

For new designs, you should be using numeric_std.

Cheers,
Jim

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
Jim Lewis
Director of Training private.php?do=newpm&u=
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~

Panic wrote:

>>sub_byte <= ROM( 16*to_integer(unsigned(ADDR(7 downto 4))) +
>> to_integer(unsigned(ADDR(3 downto 0))));

>
>
> Tried thatone before. Didn't work. That what's baffles me, since I thought I
> had understood how to_integer and unsigned works....
>
> The error I get (for both unsigned and to_integer) is something about
> element type mismatch.
>
>
>>I'm also not sure why you think you need to operate on slices of ADDR.
>>This should also work as long as ADDR is 31 bits or less:

>
>
> ADDR is a byte, but the lookup is actually a matrix lookup. That's why I
> need to do the calculation.
>
>




Jim Lewis
  Reply With Quote
Old 09-26-2003, 06:14 PM   #6
Tim Hubberstey
 
Posts: n/a
Default Re: Can't get to_integer to work
Panic wrote:
>
> > I'm also not sure why you think you need to operate on slices of ADDR.
> > This should also work as long as ADDR is 31 bits or less:

>
> ADDR is a byte, but the lookup is actually a matrix lookup. That's why I
> need to do the calculation.


You may think so but what you wrote (complete with errors):

sub_byte <= ROM( 16*to_integer(ADDR(7 downto 4)) + to_integer(ADDR(3
downto 0)));

is EXACTLY equivalent to:

sub_byte <= ROM(to_integer(unsigned(ADDR)));

Just check the arithmetic if you don't believe me. X*16 and X shifted
left by 4 are identical. You may have intended something else but what
you say doesn't jive with what you wrote.
--
Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com


Tim Hubberstey
  Reply With Quote
Old 09-28-2003, 07:01 PM   #7
Panic
 
Posts: n/a
Default Re: Can't get to_integer to work
I'm sertainly not gonna argue with you.
Thanks a lot




Panic
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any help for maintaining the work flow of the system………. Zachar Software 1 08-04-2008 06:49 AM
Back button doesn't work when it is a secure page returning to a non secure page Miss Mary General Help Related Topics 1 09-21-2007 10:32 AM
Identity Theft at Work @ A True Review Silverstrand Front Page News 0 06-27-2006 03:56 PM
Free S/W needed: Supplied PowerDVD doesn't work maggie_g47@hotmail.com DVD Video 6 09-20-2005 04:56 AM
Rumor - Lucas has "subtly" altered the original Star Wars trilogy Modemac DVD Video 213 10-09-2004 02:43 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46