Metal Shading Language Specification



Yüklə 4,82 Kb.
Pdf görüntüsü
səhifə15/51
tarix25.05.2018
ölçüsü4,82 Kb.
#45967
1   ...   11   12   13   14   15   16   17   18   ...   51

4. The arithmetic post- and pre-increment and decrement operators (-- and ++) operate on 
scalar and vector integer types. All unary operators work component-wise on their 
operands. The result is the same type they operated on. For post- and pre-increment 
and decrement, the expression must be one that could be assigned to (an l-value). Pre-
increment and pre-decrement add or subtract 1 to the contents of the expression they 
operate on, and the value of the pre-increment or pre-decrement expression is the 
resulting value of that modification. Post-increment and post-decrement expressions 
add or subtract 1 to the contents of the expression they operate on, but the resulting 
expression has the expression’s value before the post-increment or post-decrement was 
executed.  
5. The relational operators greater than (>), less than (<), greater than or equal (>=), and 
less than or equal (<=) operate on scalar and vector, integer and floating-point types. 
The result is a Boolean (
bool
 type) scalar or vector. After operand type conversion, the 
following cases are valid: 
• The two operands are scalars. In this case, the operation is applied, resulting in a 
bool

• One operand is a scalar, and the other is a vector. In this case, the scalar is converted to 
the element type used by the vector operand. The scalar type is then widened to a vector 
that has the same number of components as the vector operand. The operation is 
performed component-wise, which results in a Boolean vector. 
• The two operands are vectors of the same type. In this case, the operation is performed 
component-wise, which results in a Boolean vector. 
The relational operators always return 
false
 if either argument is a NaN. To test a relational 
operation on any or all elements of a vector, use the 
any
 and 
all
 built-in functions (defined 
in section 5.4) in the context of an 
if(…) 
statement. 
6. The equality operators, equal (==) and not equal (!=), operate on scalar and vector, 
integer and floating-point types. All equality operators result in a Boolean (
bool
 type) 
scalar or vector. After operand type conversion, the following cases are valid: 
• The two operands are scalars. In this case, the operation is applied, resulting in a 
bool

• One operand is a scalar, and the other is a vector. In this case, the scalar is converted to 
the element type used by the vector operand. The scalar type is then widened to a vector 
that has the same number of components as the vector operand. The operation is 
performed component-wise, resulting in a Boolean vector.  
• The two operands are vectors of the same type. In this case, the operation is performed 
component-wise resulting in a same size Boolean vector. 
All other cases of implicit conversions are illegal. If one or both arguments is “Not a 
Number” (NaN), the equality operator equal (==) returns 
false
. If one or both arguments is 
“Not a Number” (NaN), the equality operator not equal (!=) returns 
true

7. The bitwise operators and (&), or (|), exclusive or (^), not (~) operate on all scalar and 
vector built-in types except the built-in scalar and vector floating-point types. For built-
in vector types, the operators are applied component-wise. If one operand is a scalar and 
the other is a vector, the scalar is converted to the element type used by the vector 
operand. The scalar type is then widened to a vector that has the same number of 
 
2017-9-12   |  Copyright © 2017 Apple Inc. All Rights Reserved.  
Page    of  
47
174


components as the vector operand. The operation is performed component-wise 
resulting in a same size vector. 
8. The logical operators and (&&), or (||) operate on two Boolean expressions. The result is a 
scalar or vector Boolean. 
9. The logical unary operator not (!) operates on a Boolean expression. The result is a scalar 
or vector Boolean. 
10. The ternary selection operator (?:) operates on three expressions (
exp1
 ? 
exp2
 : 
exp3
). 
This operator evaluates the first expression 
exp1
, which must result in a scalar Boolean. 
If the result is 
true
, it selects to evaluate the second expression; otherwise it evaluates 
the third expression. Only one of the second and third expressions is evaluated. The 
second and third expressions can be any type, as long their types match, or there is a 
conversion in section 2.11 that can be applied to one of the expressions to make their 
types match, or one is a vector and the other is a scalar in which case the scalar is 
widened to the same type as the vector type. This resulting matching type is the type of 
the entire expression. 
11. The ones’ complement operator (~). The operand must be of a scalar or vector integer 
type, and the result is the ones’ complement of its operand. 
The operators right-shift (>>), left-shift (<<) operate on all scalar and vector integer types. 
For built-in vector types, the operators are applied component-wise. For the right-shift (>>), 
left-shift (<<) operators, if the first operand is a scalar, the rightmost operand must be a 
scalar. If the first operand is a vector, the rightmost operand can be a vector or scalar. 


The result of 
E1 << E2
 is 
E1
 left-shifted by 
log2(N)
 least significant bits in 
E2
 viewed as an 
unsigned integer value, where 
N
 is the number of bits used to represent the data type of 
E1

if 
E1
 is a scalar, or the number of bits used to represent the type of 
E1
 elements, if 
E1
 is a 
vector. The vacated bits are filled with zeros. 


The result of 
E1 >> E2
 is 
E1
 right-shifted by 
log2(N)
 least significant bits in 
E2
 viewed as 
an unsigned integer value, where 
N
 is the number of bits used to represent the data type of 
E1
, if 
E1
 is a scalar, or the number of bits used to represent the type of  
E1
 elements, if 
E1
 is 
a vector. If 
E1
 has an unsigned type or if 
E1
 has a signed type and a nonnegative value, the 
vacated bits are filled with zeros. If 
E1
 has a signed type and a negative value, the vacated 
bits are filled with ones. 
12. The assignment operator behaves as described by the C++14 Specification. For the 
lvalue = expression
 assignment operation, if expression is a scalar type and lvalue is 
a vector type, the scalar is converted to the element type used by the vector operand. 
The scalar type is then widened to a vector that has the same number of components as 
the vector operand. The operation is performed component-wise, which results in a 
same size vector. 
NOTE:   
• Operators not described above that are supported by C++14 (such as 
sizeof(T)

unary (&) operator, and comma (,) operator) behave as described in the C++14 
Specification. 
 
2017-9-12   |  Copyright © 2017 Apple Inc. All Rights Reserved.  
Page    of  
48
174


Yüklə 4,82 Kb.

Dostları ilə paylaş:
1   ...   11   12   13   14   15   16   17   18   ...   51




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə