newbie question

J

JohnP

This question relates to Ashenden's Designers Guide 2nd Ed. P233.
Ashenden describes a user defined package "cpu_types"
which contains these definitions:-

TYPE address IS blah . . blah
TYPE status_value IS (idle, fetch, mem_read, mem_write, etc ) -- enumerated type

cpu_types does not contain a definition of "="( value1 , value2 )

However the Math_Complex package contains a function:
"=" ( L: in COMPLEX_POLAR; R: in COMPLEX_POLAR ) return BOOLEAN;


Ashenden then gives an example of the use of objects in cpu_types :-

no "USE" statements . . . .

ENTITY address_decoder IS
PORT(addr : IN work.cpu_types.address ;
status : IN work.cpu_types.status_value ;
mem_sel : OUT BIT ) ;
END ENTITY address_decoder ;

ARCHITECTURE funct OF address_decoder IS
CONSTANT mem_low : work.cpu_types.address := x"00" ;

BEGIN
mem_decoder : mem_sel<= '1' when
(work.cpu_types."="(status, work.cpu_types.fetch) -- where does this come from ?
OR
work.cpu_types."="(status, work.cpu_types.mem_read) - and this?
OR
another boolean expression etc etc
.. . . .

Can somebody tell me
1. Is "="(status, work.cpu_types.fetch) the complex maths function ?
2. If it is then status and work.cpu_types.fetch are the wrong types
for the function
Or
3. What is going on with the example ?
 
P

Peter Ashenden

John,

Whenever you define a new type, you get a number of implicitly declared
operators for it, including "=". So in the cpu_types package, you get
implicitly declared "=" for the status_value type. This is the operator
that is referenced in the functional architecture. Later on in the chapter,
I show how you can include a use clause to use all of the declarations from
the cpu_types package. As well as making the explicitly declared items
visible, the use work.cpu_types.all clause makes the implicitly declared
items visible, allowing you to express the "=" operator with infix notation.

You mentioned that the math_complex package does explicitly declare the "="
operator for complex_polar. If it didn't, there would be an implict "="
that just compared the record elements. It would say that (1.0, pi) was not
equal to (1.0, 3*pi). Since adding 2*pi to the argument of a polar complex
number is supposed to give you the same complex number, this behavior would
be undesirable. Hence, the package declares an explicit "=" operator that
implements the correct behavior.

Hope this clears things up. Please let me know if not.

Cheers,

PA
--
Dr. Peter J. Ashenden (e-mail address removed)
Ashenden Designs Pty. Ltd. www.ashenden.com.au
PO Box 640 Ph: +61 8 8339 7532
Stirling, SA 5152 Fax: +61 8 8339 2616
Australia Mobile: +61 414 70 9106


This question relates to Ashenden's Designers Guide 2nd Ed. P233.
Ashenden describes a user defined package "cpu_types"
which contains these definitions:-

TYPE address IS blah . . blah
TYPE status_value IS (idle, fetch, mem_read, mem_write, etc ) --
enumerated type

cpu_types does not contain a definition of "="( value1 , value2 )

However the Math_Complex package contains a function:
"=" ( L: in COMPLEX_POLAR; R: in COMPLEX_POLAR ) return BOOLEAN;


Ashenden then gives an example of the use of objects in cpu_types :-

no "USE" statements . . . .

ENTITY address_decoder IS
PORT(addr : IN work.cpu_types.address ;
status : IN work.cpu_types.status_value ;
mem_sel : OUT BIT ) ;
END ENTITY address_decoder ;

ARCHITECTURE funct OF address_decoder IS
CONSTANT mem_low : work.cpu_types.address := x"00" ;

BEGIN
mem_decoder : mem_sel<= '1' when
(work.cpu_types."="(status, work.cpu_types.fetch) -- where does
this come from ?
OR
work.cpu_types."="(status, work.cpu_types.mem_read) - and this?
OR
another boolean expression etc etc
.. . . .

Can somebody tell me
1. Is "="(status, work.cpu_types.fetch) the complex maths function ?
2. If it is then status and work.cpu_types.fetch are the wrong types
for the function
Or
3. What is going on with the example ?
 
J

JohnP

Peter, thanks for the reply but I'm still confused.

Is "="(status, work.cpu_types.fetch) in your code a call
to an fictional function which overloads the = operator,
but which is not declared or defined anywhere ?.

I don't understand what you mean by "you get a number of
implicitly defined operators for a new type". Are these the
operators defined in the LRM, which will operate on the user's
defined type ?

John
 
M

Mike Treseler

JohnP said:
Is "="(status, work.cpu types.fetch) in your code a call
to an fictional function which overloads the = operator,
but which is not declared or defined anywhere ?.

No. It is a demonstration of how difficult it is
to make use of library subtypes without the USE clause.
Mr. Ashenden explains this at the top of page 234.
This line would be simplified to something like:

... when (status = fetch) ...

with a proper USE clause. See page 241.

... "you get a number of implicitly defined operators
for a new type". Are these the operators defined in the LRM,
which will operate on the user's defined type ?

Yes. A type enumeration for a machine state would not
be of much use if I could not test the value of the state.

Maybe part of the confusion here is the usage of
operators as functions. I came up with a few
examples below.

-- Mike Treseler

-------------------------------------------------------------------------------
-- Example usage for operators and functions
-- M.Treseler Fri May 7 11:08:46 2004

entity operators is
end operators;

architecture sim of operators is
begin
what : process is
function ave (arg1 : natural; arg2 : natural)
return natural is begin
return (arg1 + arg2) / 2;
end function ave;

function "<=" (arg1 : natural; arg2 : natural)
return natural is begin
return (arg1 + arg2) / 2;
end function "<=";

begin
-- Use vhdl operator "<"
assert 2<3; -- standard operator syntax
assert "<"(2,3); -- operator string literal as function is ok
-- assert < (2,3); -- syntax error; operator function must be string

-- Use local function "ave"
assert ave (4,6) = 5; -- standard function call
assert "ave"(4,6) = 5; -- function call as string literal is ok
-- assert (4 ave 6) = 5; -- syntax error, "ave" is not a VHDL operator

-- Use local function overloading "<="
assert (4 <= 6) = 5; -- Overloaded VHDL operator is ok
assert "<="(4, 6) = 5; -- operator as string literal function is ok
report("No assertions expected above.");
wait;
end process what;
end sim;

-- sample output:
--# vsim -do run -c operators
--# // ModelSim SE VHDL 5.7c Mar 1 2003 Linux 2.4.21-198-default
--# Loading work.operators(sim)
--# run
--# ** Note: No assertions expected above.
--# Time: 0 ns Iteration: 0 Instance: /operators
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top