newbie question

Discussion in 'VHDL' started by JohnP, May 5, 2004.

  1. JohnP

    JohnP Guest

    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 ?
     
    JohnP, May 5, 2004
    #1
    1. Advertising

  2. 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
    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" <> wrote in message
    news:40996fa7$...
    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 ?
     
    Peter Ashenden, May 6, 2004
    #2
    1. Advertising

  3. JohnP

    JohnP Guest

    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" <> wrote in message news:...
    > 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
    > 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" <> wrote in message
    > news:40996fa7$...
    > 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 ?
    >
    >
     
    JohnP, May 6, 2004
    #3
  4. 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
     
    Mike Treseler, May 7, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry C.
    Replies:
    8
    Views:
    258
    Uri Guttman
    Nov 23, 2003
  2. Kruno Saho
    Replies:
    0
    Views:
    150
    Kruno Saho
    Apr 7, 2013
  3. Dave Angel
    Replies:
    0
    Views:
    130
    Dave Angel
    Apr 7, 2013
  4. rusi
    Replies:
    0
    Views:
    118
  5. Miki Tebeka
    Replies:
    0
    Views:
    89
    Miki Tebeka
    Apr 7, 2013
Loading...

Share This Page