Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > newbie question

Reply
Thread Tools

newbie question

 
 
JohnP
Guest
Posts: n/a
 
      05-05-2004
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 ?
 
Reply With Quote
 
 
 
 
Peter Ashenden
Guest
Posts: n/a
 
      05-06-2004
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 http://www.velocityreviews.com/forums/(E-Mail 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


"JohnP" <(E-Mail Removed)> wrote in message
news:40996fa7$(E-Mail Removed)...
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 ?


 
Reply With Quote
 
 
 
 
JohnP
Guest
Posts: n/a
 
      05-06-2004
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

"Peter Ashenden" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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 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
>
>
> "JohnP" <(E-Mail Removed)> wrote in message
> news:40996fa7$(E-Mail Removed)...
> 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 ?
>
>

 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      05-07-2004
JohnP wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments