Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

IEEE 1076 standard.VHDL language reference manual.2000

.pdf
Скачиваний:
47
Добавлен:
23.08.2013
Размер:
1.53 Mб
Скачать

IEEE

 

Std 1076, 2000 Edition

IEEE STANDARD VHDL

6.5 Slice names

A slice name denotes a one-dimensional array composed of a sequence of consecutive elements of another

190one-dimensional array. A slice of a signal is a signal; a slice of a variable is a variable; a slice of a constant is a constant; a slice of a value is a value.

slice_name ::= prefix ( discrete_range )

The prefix of a slice must be appropriate for a one-dimensional array object. The base type of this array type is the type of the slice.

195The bounds of the discrete range define those of the slice and must be of the type of the index of the array. The slice is a null slice if the discrete range is a null range. It is an error if the direction of the discrete range is not the same as that of the index range of the array denoted by the prefix of the slice name.

For the evaluation of a name that is a slice, the prefix and the discrete range are evaluated. It is an error if either of the bounds of the discrete range does not belong to the index range of the prefixing array, unless the

200slice is a null slice. (The bounds of a null slice need not belong to the subtype of the index.)

Examples:

signal R15:

BIT_VECTOR (0 to 31) ;

constant

DATA: BIT_VECTOR (31 downto 0) ;

R15(0 to 7)

205 DATA(24 downto 1) DATA(1 downto 24) DATA(24 to 25)

--A slice with an ascending range.

--A slice with a descending range.

--A null slice.

--An error.

NOTE—If A is a one-dimensional array of objects, the name A(N to N) or A(N downto N) is a slice that contains one element; its type is the base type of A. On the other hand, A(N) is an element of the array A and has the corresponding

210 element type.

6.6 Attribute names

An attribute name denotes a value, function, type, range, signal, or constant associated with a named entity.

attribute_name ::=

prefix [ signature ] ' attribute_designator [ ( expression ) ]

attribute_designator ::= attribute_simple_name

215The applicable attribute designators depend on the prefix plus the signature, if any. The meaning of the prefix of an attribute must be determinable independently of the attribute designator and independently of the fact that it is the prefix of an attribute.

A signature may follow the prefix if and only if the prefix denotes a subprogram or enumeration literal, or an alias thereof. In this case, the signature is required to match (see 2.3.2) the parameter and result type profile

220of exactly one visible subprogram or enumeration literal, as is appropriate to the prefix.

If the attribute designator denotes a predefined attribute, the expressions either must or may appear, depending upon the definition of that attribute (see Clause 14); otherwise, they must not be present.

92

Copyright © 2000 IEEE. All rights reserved.

 

IEEE

LANGUAGE REFERENCE MANUAL

Std 1076, 2000 Edition

If the prefix of an attribute name denotes an alias, then the attribute name denotes an attribute of the aliased name and not the alias itself, except when the attribute designator denotes any of the predefined attributes

225'SIMPLE_NAME, 'PATH_NAME, or 'INSTANCE_NAME. If the prefix of an attribute name denotes an alias and the attribute designator denotes any of the predefined attributes SIMPLE_NAME, 'PATH_NAME, or 'INSTANCE_NAME, then the attribute name denotes the attribute of the alias and not of the aliased name.

If the attribute designator denotes a user-defined attribute, the prefix cannot denote a subelement or a slice of an object.

230

Examples:

 

 

REG'LEFT(1)

-- The leftmost index bound of array REG

 

INPUT_PIN'PATH_NAME

-- The hierarchical path name of the port INPUT_PIN

 

CLK'DELAYED(5 ns)

-- The signal CLK delayed by 5 ns

Copyright © 2000 IEEE. All rights reserved.

93

IEEE

 

Std 1076, 2000 Edition

IEEE STANDARD VHDL

94

Copyright © 2000 IEEE. All rights reserved.

 

IEEE

LANGUAGE REFERENCE MANUAL

Std 1076, 2000 Edition

 

7. Expressions

 

The rules applicable to the different forms of expression, and to their evaluation, are given in this clause.

 

7.1 Rules for expressions

 

An expression is a formula that defines the computation of a value.

 

expression ::=

 

relation { and relation }

5

| relation { or relation }

 

| relation { xor relation }

 

| relation [ nand relation ]

 

| relation [ nor relation ]

 

| relation { xnor relation }

10

relation ::=

 

shift_expression [ relational_operator shift_expression ]

 

shift_expression ::=

 

simple_expression [ shift_operator simple_expression ]

 

simple_expression ::=

15

[ sign ] term { adding_operator term }

 

term ::=

 

factor { multiplying_operator factor }

 

factor ::=

 

primary [ ** primary ]

20

| abs primary

 

| not primary

 

primary ::=

 

name

 

| literal

25

| aggregate

 

| function_call

 

| qualified_expression

 

| type_conversion

 

| allocator

30

| ( expression )

Each primary has a value and a type. The only names allowed as primaries are attributes that yield values and names denoting objects or values. In the case of names denoting objects, the value of the primary is the value of the object.

The type of an expression depends only upon the types of its operands and on the operators applied; for an

35overloaded operand or operator, the determination of the operand type, or the identification of the overloaded operator, depends on the context (see 10.5). For each predefined operator, the operand and result types are given in the following subclause.

NOTE—The syntax for an expression involving logical operators allows a sequence of and, or, xor, or xnor operators (whether predefined or user-defined), since the corresponding predefined operations are associative. For the operators

40nand and nor (whether predefined or user-defined), however, such a sequence is not allowed, since the corresponding predefined operations are not associative.

Copyright © 2000 IEEE. All rights reserved.

95

IEEE

 

Std 1076, 2000 Edition

IEEE STANDARD VHDL

7.2 Operators

The operators that may be used in expressions are defined below. Each operator belongs to a class of operators, all of which have the same precedence level; the classes of operators are listed in order of increasing precedence.

45

logical_operator

::=

and

|

or

|

nand

|

nor

|

xor

|

xnor

 

relational_operator

::=

=

|

/=

|

<

|

<=

|

>

|

>=

 

shift_operator

::=

sll

|

srl

|

sla

|

sra

|

rol

|

ror

 

adding_operator

::=

+

|

|

&

 

 

 

 

 

 

 

sign

::=

+

|

 

 

 

 

 

 

 

 

50

multiplying_operator

::=

*

|

/

|

mod

|

rem

 

 

 

 

 

miscellaneous_operator

::=

**

|

abs

|

not

 

 

 

 

 

 

Operators of higher precedence are associated with their operands before operators of lower precedence. Where the language allows a sequence of operators, operators with the same precedence level are associated with their operands in textual order, from left to right. The precedence of an operator is fixed and may not be

55changed by the user, but parentheses can be used to control the association of operators and operands.

In general, operands in an expression are evaluated before being associated with operators. For certain operations, however, the right-hand operand is evaluated if and only if the left-hand operand has a certain value. These operations are called short-circuit operations. The logical operations and, or, nand, and nor defined for operands of types BIT and BOOLEAN are all short-circuit operations; furthermore, these are the

60only short-circuit operations.

Every predefined operator is a pure function (see 2.1). No predefined operators have named formal parameters; therefore, named association (see 4.3.2.2) may not be used when invoking a predefined operation.

NOTES

1—The predefined operators for the standard types are declared in package STANDARD as shown in 14.2.

652—The operator not is classified as a miscellaneous operator for the purposes of defining precedence, but is otherwise classified as a logical operator.

7.2.1 Logical operators

The logical operators and, or, nand, nor, xor, xnor, and not are defined for predefined types BIT and BOOLEAN. They are also defined for any one-dimensional array type whose element type is BIT or BOOLEAN. For the binary operators and, or, nand, nor, xor, and xnor, the operands must be of the same

70base type. Moreover, for the binary operators and, or, nand, nor, xor, and xnor defined on one-dimensional array types, the operands must be arrays of the same length, the operation is performed on matching elements of the arrays, and the result is an array with the same index range as the left operand. For the unary operator not defined on one-dimensional array types, the operation is performed on each element of the operand, and the result is an array with the same index range as the operand.

96

Copyright © 2000 IEEE. All rights reserved.

 

IEEE

LANGUAGE REFERENCE MANUAL

Std 1076, 2000 Edition

75The effects of the logical operators are defined in the following tables. The symbol T represents TRUE for type BOOLEAN, '1' for type BIT; the symbol F represents FALSE for type BOOLEAN, '0' for type BIT.

 

A

B

A and B

A

B

A or B

A

B

A xor B

 

T

T

T

T

T

T

T

T

F

 

T

F

F

T

F

T

T

F

T

80

F

T

F

F

T

T

F

T

T

 

F

F

F

F

F

F

F

F

F

 

A

B

A nand B

A

B

A nor B

A

B

A xnor B

 

T

T

F

T

T

F

T

T

T

 

T

F

T

T

F

F

T

F

F

85

F

T

T

F

T

F

F

T

F

 

F

F

T

F

F

T

F

F

T

Anot A

TF

FT

90For the short-circuit operations and, or, nand, and nor on types BIT and BOOLEAN, the right operand is evaluated only if the value of the left operand is not sufficient to determine the result of the operation. For operations and and nand, the right operand is evaluated only if the value of the left operand is T; for operations or and nor, the right operand is evaluated only if the value of the left operand is F.

NOTE—All of the binary logical operators belong to the class of operators with the lowest precedence. The unary

95logical operator not belongs to the class of operators with the highest precedence.

7.2.2 Relational operators

Relational operators include tests for equality, inequality, and ordering of operands. The operands of each relational operator must be of the same type. The result type of each relational operator is the predefined type BOOLEAN.

 

Operator

Operation

Operand type

Result type

100

 

 

 

 

=

Equality

Any type, other

BOOLEAN

 

 

 

than a file type or a

 

 

 

 

protected type

 

 

 

 

 

 

 

/=

Inequality

Any type, other

BOOLEAN

 

 

 

than a file type or a

 

105

 

 

protected type

 

 

 

 

 

 

 

<

Ordering

Any scalar type or

BOOLEAN

 

<=

 

discrete array type

 

 

>

 

 

 

 

>=

 

 

 

 

 

 

 

 

110The equality and inequality operators (= and /=) are defined for all types other than file types and protected types. The equality operator returns the value TRUE if the two operands are equal and returns the value FALSE otherwise. The inequality operator returns the value FALSE if the two operands are equal and returns the value TRUE otherwise.

Copyright © 2000 IEEE. All rights reserved.

97

IEEE

 

Std 1076, 2000 Edition

IEEE STANDARD VHDL

Two scalar values of the same type are equal if and only if the values are the same. Two composite values of

115the same type are equal if and only if for each element of the left operand there is a matching element of the right operand and vice versa, and the values of matching elements are equal, as given by the predefined equality operator for the element type. In particular, two null arrays of the same type are always equal. Two values of an access type are equal if and only if they both designate the same object or they both are equal to the null value for the access type.

120For two record values, matching elements are those that have the same element identifier. For two onedimensional array values, matching elements are those (if any) whose index values match in the following sense: the left bounds of the index ranges are defined to match; if two elements match, the elements immediately to their right are also defined to match. For two multidimensional array values, matching elements are those whose indices match in successive positions.

125The ordering operators are defined for any scalar type and for any discrete array type. A discrete array is a one-dimensional array whose elements are of a discrete type. Each operator returns TRUE if the corresponding relation is satisfied; otherwise, the operator returns FALSE.

For scalar types, ordering is defined in terms of the relative values. For discrete array types, the relation < (less than) is defined such that the left operand is less than the right operand if and only if the left operand is

130a null array and the right operand is a nonnull array.

Otherwise, both operands are nonnull arrays, and one of the following conditions is satisfied:

a)The leftmost element of the left operand is less than that of the right, or

b)The leftmost element of the left operand is equal to that of the right, and the tail of the left operand is less than that of the right (the tail consists of the remaining elements to the right of the leftmost

135

element and can be null).

The relation <= (less than or equal) for discrete array types is defined to be the inclusive disjunction of the results of the < and = operators for the same two operands. The relations > (greater than) and >= (greater than or equal) are defined to be the complements of the <= and < operators, respectively, for the same two operands.

7.2.3 Shift operators

140The shift operators sll, srl, sla, sra, rol, and ror are defined for any one-dimensional array type whose element type is either of the predefined types BIT or BOOLEAN.

 

Operator

Operation

Left operand type

Right operand type

Result type

 

 

 

 

 

 

 

sll

Shift left

Any one-dimensional array type whose

INTEGER

Same as left

 

 

logical

element type is BIT or BOOLEAN

 

 

 

 

 

 

 

 

145

srl

Shift right

Any one-dimensional array type whose

INTEGER

Same as left

 

 

logical

element type is BIT or BOOLEAN

 

 

 

 

 

 

 

 

 

sla

Shift left

Any one-dimensional array type whose

INTEGER

Same as left

 

 

arithmetic

element type is BIT or BOOLEAN

 

 

 

 

 

 

 

 

 

sra

Shift right

Any one-dimensional array type whose

INTEGER

Same as left

150

 

arithmetic

element type is BIT or BOOLEAN

 

 

 

 

 

 

 

 

 

rol

Rotate left

Any one-dimensional array type whose

INTEGER

Same as left

 

 

logical

element type is BIT or BOOLEAN

 

 

 

 

 

 

 

 

 

ror

Rotate right

Any one-dimensional array type whose

INTEGER

Same as left

 

 

logical

element type is BIT or BOOLEAN

 

 

 

 

 

 

 

 

98

Copyright © 2000 IEEE. All rights reserved.

 

IEEE

LANGUAGE REFERENCE MANUAL

Std 1076, 2000 Edition

155The index subtypes of the return values of all shift operators are the same as the index subtypes of their left arguments.

The values returned by the shift operators are defined as follows. In the remainder of this clause, the values of their leftmost arguments are referred to as L and the values of their rightmost arguments are referred to as R.

The sll operator returns a value that is L logically shifted left by R index positions. That is, if R is 0

160or if L is a null array, the return value is L. Otherwise, a basic shift operation replaces L with a value that is the result of a concatenation whose left argument is the rightmost (L'Length – 1) elements of L and whose right argument is T'Left, where T is the element type of L. If R is positive, this basic shift operation is repeated R times to form the result. If R is negative, then the return value is the value of the expression L srl –R.

165— The srl operator returns a value that is L logically shifted right by R index positions. That is, if R is 0 or if L is a null array, the return value is L. Otherwise, a basic shift operation replaces L with a value that is the result of a concatenation whose right argument is the leftmost (L'Length – 1) elements of L and whose left argument is T'Left, where T is the element type of L. If R is positive, this basic shift operation is repeated R times to form the result. If R is negative, then the return value is the value of

170

the expression L sll –R.

The sla operator returns a value that is L arithmetically shifted left by R index positions. That is, if R is 0 or if L is a null array, the return value is L. Otherwise, a basic shift operation replaces L with a value that is the result of a concatenation whose left argument is the rightmost (L'Length – 1) elements of L and whose right argument is L(L'Right). If R is positive, this basic shift operation is

175repeated R times to form the result. If R is negative, then the return value is the value of the expression L sra –R.

The sra operator returns a value that is L arithmetically shifted right by R index positions. That is, if R is 0 or if L is a null array, the return value is L. Otherwise, a basic shift operation replaces L with a value that is the result of a concatenation whose right argument is the leftmost (L'Length – 1) elements

180of L and whose left argument is L(L'Left). If R is positive, this basic shift operation is repeated R times to form the result. If R is negative, then the return value is the value of the expression L sla –R.

The rol operator returns a value that is L rotated left by R index positions. That is, if R is 0 or if L is a null array, the return value is L. Otherwise, a basic rotate operation replaces L with a value that is the result of a concatenation whose left argument is the rightmost (L'Length – 1) elements of L and

185whose right argument is L(L'Left). If R is positive, this basic rotate operation is repeated R times to form the result. If R is negative, then the return value is the value of the expression L ror –R.

The ror operator returns a value that is L rotated right by R index positions. That is, if R is 0 or if L is a null array, the return value is L. Otherwise, a basic rotate operation replaces L with a value that is

the result of a concatenation whose right argument is the leftmost (L'Length – 1) elements of L and

190whose left argument is L(L'Right). If R is positive, this basic rotate operation is repeated R times to form the result. If R is negative, then the return value is the value of the expression L rol –R.

NOTES

1—The logical operators may be overloaded, for example, to disallow negative integers as the second argument. 2—The subtype of the result of a shift operator is the same as that of the left operand.

Copyright © 2000 IEEE. All rights reserved.

99

IEEE

 

Std 1076, 2000 Edition

IEEE STANDARD VHDL

7.2.4 Adding operators

195The adding operators + and – are predefined for any numeric type and have their conventional mathematical meaning. The concatenation operator & is predefined for any one-dimensional array type.

 

Operator

Operation

Left operand type

Right operand type

Result type

 

 

 

 

 

 

 

+

Addition

Any numeric type

Same type

Same type

 

 

 

 

 

 

 

Subtraction

Any numeric type

Same type

Same type

200

 

 

 

 

 

&

Concatenation

Any array type

Same array type

Same array type

 

 

 

 

 

 

 

 

 

Any array type

The element type

Same array type

 

 

 

 

 

 

 

 

 

The element type

Any array type

Same array type

 

 

 

 

 

 

 

 

 

The element type

The element type

Any array type

 

 

 

 

 

 

For concatenation, there are three mutually exclusive cases, as follows:

205a) If both operands are one-dimensional arrays of the same type, the result of the concatenation is a one-dimensional array of this same type whose length is the sum of the lengths of its operands, and whose elements consist of the elements of the left operand (in left-to-right order) followed by the elements of the right operand (in left-to-right order). The direction of the result is the direction of the left operand, unless the left operand is a null array, in which case the direction of the result is that of

210the right operand.

If both operands are null arrays, then the result of the concatenation is the right operand. Otherwise, the direction and bounds of the result are determined as follows: Let S be the index subtype of the base type of the result. The direction of the result of the concatenation is the direction of S, and the left bound of the result is S'LEFT.

215b) If one of the operands is a one-dimensional array and the type of the other operand is the element type of this aforementioned one-dimensional array, the result of the concatenation is given by the

rules in case a, using in place of the other operand an implicit array having this operand as its only element.

c)If both operands are of the same type and it is the element type of some one-dimensional array type,

220the type of the result must be known from the context and is this one-dimensional array type. In this case, each operand is treated as the one element of an implicit array, and the result of the concatenation is determined as in case a) above.

In all cases, it is an error if either bound of the index subtype of the result does not belong to the index subtype of the type of the result, unless the result is a null array. It is also an error if any element of the result

225does not belong to the element subtype of the type of the result.

Examples:

subtype BYTE is BIT_VECTOR (7 downto 0);

type MEMORY is array (Natural range <>) of BYTE;

-- The following concatenation accepts two BIT_VECTORs and returns a BIT_VECTOR

230-- [case a)]:

constant ZERO: BYTE := "0000" & "0000";

100

Copyright © 2000 IEEE. All rights reserved.

 

IEEE

LANGUAGE REFERENCE MANUAL

Std 1076, 2000 Edition

--The next two examples show that the same expression can represent either case a) or

--case c), depending on the context of the expression.

--The following concatenation accepts two BIT_VECTORS and returns a BIT_VECTOR

235-- [case a)]:

constant C1: BIT_VECTOR := ZERO & ZERO;

--The following concatenation accepts two BIT_VECTORs and returns a MEMORY

--[case c)]:

constant C2: MEMORY := ZERO & ZERO;

240-- The following concatenation accepts a BIT_VECTOR and a MEMORY, returning a -- MEMORY [case b)]:

 

constant C3: MEMORY := ZERO & C2;

 

-- The following concatenation accepts a MEMORY and a BIT_VECTOR, returning a

 

-- MEMORY [case b)]:

245

constant C4: MEMORY := C2 & ZERO;

 

-- The following concatenation accepts two MEMORYs and returns a MEMORY [case a)]:

 

constant C5: MEMORY := C2 & C3;

type R1 is 0 to 7; type R2 is 7 downto 0;

250type T1 is array (R1 range <>) of Bit; type T2 is array (R2 range <>) of Bit;

subtype S1 is T1(R1); subtype S2 is T2(R2);

 

constant K1: S1 := (others => '0');

 

255

constant K2: T1 := K1(1 to 3) & K1(3 to 4);

-- K2'Left = 0 and K2'Right = 4

 

constant K3: T1 := K1(5 to 7) & K1(1 to 2);

-- K3'Left = 0 and K3'Right = 4

 

constant K4: T1 := K1(2 to 1) & K1(1 to 2);

-- K4'Left = 0 and K4'Right = 1

 

constant K5: S2 := (others => '0');

 

 

constant K6: T2 := K5(3 downto 1) & K5(4 downto 3);

-- K6'Left = 7 and K6'Right = 3

260

constant K7: T2 := K5(7 downto 5) & K5(2 downto 1);

-- K7'Left = 7 and K7'Right = 3

 

constant K8: T2 := K5(1 downto 2) & K5(2 downto 1);

-- K8'Left = 7 and K8'Right = 6

NOTES

1—For a given concatenation whose operands are of the same type, there may be visible more than one array type that could be the result type according to the rules of case c). The concatenation is ambiguous and therefore an error if, using

265the overload resolution rules of 2.3 and 10.5, the type of the result is not uniquely determined.

2—Additionally, for a given concatenation, there may be visible array types that allow both case a) and case c) to apply. The concatenation is again ambiguous and therefore an error if the overload resolution rules cannot be used to determine a result type uniquely.

Copyright © 2000 IEEE. All rights reserved.

101

Соседние файлы в предмете Электротехника