stumped on syntax yet again!

Mike Treseler wrote:
rickman wrote:

function sllint (x, sh : natural) return natural is
begin
return x*(2**sh);
end sllint;

I am not clear on what happens when I shift the value of Addr left by
2 and significant bits extend beyond the defined range.

The function, as written, will return x*(2**sh)
up to the natural range. It knows nothing about
any other range unless you add a parameter
to to function.

I would use numeric_std.unsigned and the shift_left
function, and to_integer(my_uns, my_len) as needed.
function, and to_integer(my_uns) as needed.
-- Mike Treseler
 
On May 9, 3:57 pm, James Unterburger <jam...@europa.com> wrote:
Sorry, "reg_type" is not "really a subtype of SLV", it is a subtype
of a distinct type (an anonymous array type) whose element subtype
is the constrained array subtype "hwid_type".
The element *type* is still "std_logic_vector" however, and
overloading occurs using only base types, never subtypes.
Given that statement, how do I apply this when working with
constrained integers...

I have a function to perform a "shift" operation on an integer,

function sllint (x, sh : natural) return natural is
begin
return x*(2**sh);
end sllint;

I am using it with a constrained integer,

SIGNAL Addr : NibbInt;

where

subtype NibbInt is Integer range 0 to 2**4-1;

usage,

Addr <= sllint(Addr, CTPDATAWDTH) + to_nat(Scfg_Din);

where Scfg_Din is an SLV (1 downto 0) and CTPDATAWDTH is an integer
constant of 2.

I am not clear on what happens when I shift the value of Addr left by
2 and significant bits extend beyond the defined range. I thought
about defining an overloaded operator for shifting NibbInt which would
use the mod operator, but you say the subtype won't be used for
overloading. So it would just use the sllint operator defined for
integer anyway.

I don't want to have to pass into the function the range of the
parameter. The usage of the function just gets too messy. I guess I
could use an sllnib operator, but I would prefer not to have to pre-
select the function and the compiler select it as an overloaded
function.

How am I looking at this wrong? Shouldn't I be able to do this?

Rick
 
Mike Treseler a écrit :
Shannon wrote:

If "00" is a vague type in this case why can't I cast it to make the
error go away?

Declare it as a constant to give it a type.

That's good practice in any case.
I often declare zero constants for this:

RAM_addr <= my_adr_zero_c + data_in;

Declaring zero constants means declaring a constant for every possible
length (well, not actually every but still quite a lot)
I once had the idea of declaring a function for that (and I think it
worked quite well) :
function zero (n : natural) return std_logic_vector is
constant C_ZERO : std_logic_vector(n-1 downto 0) := (others => '0');
begin
return C_ZERO;
end function zero;

Nicolas
 

Welcome to EDABoard.com

Sponsor

Back
Top