The following table lists the arithmetic operators of the Fvec classes and generic syntax. The operators have been divided into standard and advanced operations, which are described in more detail later in this section.
Category | Operation | Operators | Generic Syntax |
---|---|---|---|
Standard |
Addition |
+ |
R = A +
B; |
Subtraction |
- |
R = A -
B; | |
Multiplication |
* |
R = A *
B; | |
Division |
/ |
R = A / B; R /= A; | |
Advanced |
Square Root |
sqrt |
R = sqrt(A); |
Reciprocal |
rcp |
R = rcp(A); | |
Reciprocal
Square Root |
rsqrt |
R = rsqrt(A); |
The following two tables show the return values for each class of the standard arithmetic operators, which use the syntax styles described earlier in the Return Value Notation section.
R | A | Operators | B | F32vec4 | F64vec2 | F32vec1 | |||
---|---|---|---|---|---|---|---|---|---|
R0:= |
A0 |
+ |
- |
* |
/ |
B0 |
|
|
|
R1:= |
A1 |
+ |
- |
* |
/ |
B1 |
|
|
N/A |
R2:= |
A2 |
+ |
- |
* |
/ |
B2 |
|
N/A |
N/A |
R3:= |
A3 |
+ |
- |
* |
/ |
B3 |
|
N/A |
N/A |
R | Operators | A | F32vec4 | F64vec2 | F32vec1 | |||
---|---|---|---|---|---|---|---|---|
R0:= |
+= |
-= |
*= |
/= |
A0 |
|
|
|
R1:= |
+= |
-= |
*= |
/= |
A1 |
|
|
N/A |
R2:= |
+= |
-= |
*= |
/= |
A2 |
|
N/A |
N/A |
R3:= |
+= |
-= |
*= |
/= |
A3 |
|
N/A |
N/A |
The table below lists standard arithmetic operator syntax and intrinsics.
Operation | Returns | Example Syntax Usage | Intrinsic |
---|---|---|---|
Addition |
4 floats |
F32vec4 R = F32vec4 A + F32vec4 B; F32vec4 R += F32vec4 A; |
_mm_add_ps |
|
2 doubles |
F64vec2 R = F64vec2 A + F32vec2 B; F64vec2 R += F64vec2 A; |
_mm_add_pd |
|
1 float |
F32vec1 R = F32vec1 A + F32vec1 B; F32vec1 R += F32vec1 A; |
_mm_add_ss |
Subtraction |
4 floats |
F32vec4 R = F32vec4 A - F32vec4 B; F32vec4 R -= F32vec4 A; |
_mm_sub_ps |
|
2 doubles |
F64vec2 R - F64vec2 A + F32vec2 B; F64vec2 R -= F64vec2 A; |
_mm_sub_pd |
|
1 float |
F32vec1
R = F32vec1 A - F32vec1 B; |
_mm_sub_ss |
Multiplication |
4 floats |
F32vec4
R = F32vec4 A * F32vec4 B; |
_mm_mul_ps |
|
2 doubles |
F64vec2
R = F64vec2 A * F364vec2 B; |
_mm_mul_pd |
|
1 float |
F32vec1
R = F32vec1 A * F32vec1 B; |
_mm_mul_ss |
Division |
4 floats |
F32vec4
R = F32vec4 A / F32vec4 B; |
_mm_div_ps |
|
2 doubles |
F64vec2
R = F64vec2 A / F64vec2 B; |
_mm_div_pd |
|
1 float |
F32vec1
R = F32vec1 A / F32vec1 B; |
_mm_div_ss |
The following table shows the return values classes of the advanced arithmetic operators, which use the syntax styles described earlier in the Return Value Notation section.
R | Operators | A | F32vec4 | F64vec2 | F32vec1 | ||||
---|---|---|---|---|---|---|---|---|---|
R0:= |
sqrt |
rcp |
rsqrt |
rcp_nr |
rsqrt_nr |
A0 |
|
|
|
R1:= |
sqrt |
rcp |
rsqrt |
rcp_nr |
rsqrt_nr |
A1 |
|
|
N/A |
R2:= |
sqrt |
rcp |
rsqrt |
rcp_nr |
rsqrt_nr |
A2 |
|
N/A |
N/A |
R3:= |
sqrt |
rcp |
rsqrt |
rcp_nr |
rsqrt_nr |
A3 |
|
N/A |
N/A |
f := |
add_horizontal |
(A0 + A1 + A2 + A3) |
|
N/A |
N/A | ||||
d := |
add_horizontal |
(A0 + A1) |
N/A |
|
N/A |
The table below shows examples for advanced arithmetic operators.
Returns | Example Syntax Usage | Intrinsic |
---|---|---|
Square Root | ||
4 floats |
F32vec4 R = sqrt(F32vec4 A); |
_mm_sqrt_ps |
2 doubles |
F64vec2 R = sqrt(F64vec2 A); |
_mm_sqrt_pd |
1 float |
F32vec1 R = sqrt(F32vec1 A); |
_mm_sqrt_ss |
Reciprocal | ||
4 floats |
F32vec4 R = rcp(F32vec4 A); |
_mm_rcp_ps |
2 doubles |
F64vec2 R = rcp(F64vec2 A); |
_mm_rcp_pd |
1 float |
F32vec1 R = rcp(F32vec1 A); |
_mm_rcp_ss |
Reciprocal Square Root | ||
4 floats |
F32vec4 R = rsqrt(F32vec4 A); |
_mm_rsqrt_ps |
2 doubles |
F64vec2 R = rsqrt(F64vec2 A); |
_mm_rsqrt_pd |
1 float |
F32vec1 R = rsqrt(F32vec1 A); |
_mm_rsqrt_ss |
Reciprocal Newton Raphson | ||
4 floats |
F32vec4 R = rcp_nr(F32vec4 A); |
_mm_sub_ps |
2 doubles |
F64vec2 R = rcp_nr(F64vec2 A); |
_mm_sub_pd |
1 float |
F32vec1 R = rcp_nr(F32vec1 A); |
_mm_sub_ss |
Reciprocal Square Root Newton Raphson | ||
4 float |
F32vec4 R = rsqrt_nr(F32vec4 A); |
_mm_sub_pd |
2 doubles |
F64vec2 R = rsqrt_nr(F64vec2 A); |
_mm_sub_pd |
1 float |
F32vec1 R = rsqrt_nr(F32vec1 A); |
_mm_sub_ss |
Horizontal Add | ||
1 float |
float f = add_horizontal(F32vec4 A); |
_mm_add_ss |
1 double |
double d = add_horizontal(F64vec2 A); |
_mm_add_sd _mm_shuffle_sd |