Developer Guide and Reference

ID 767253
Date 10/31/2024
Public
Document Table of Contents

Addition and Subtraction Operators

The addition and subtraction operators return the class of the nearest common ancestor when the right-side operands are of different signs. The following code snippets show examples of usage and miscellaneous exceptions.

  • Return nearest common ancestor type, I16vec4:
    Is16vec4 A;
    Iu16vec4 B;
    I16vec4 C;
    
    C = A + B;
    
  • Returns type left-hand operand type:
    Is16vec4 A;
    Iu16vec4 B;
    
    A += B;
    B -= A;
    
  • Explicitly convert B to Is16vec4:
    Is16vec4 A,C;
    Iu32vec24 B;
    
    C = A + C;
    C = A + (Is16vec4)B;
    

The following table lists addition and subtraction operators with their corresponding intrinsics:

Operation

Symbols

Syntax

Corresponding Intrinsics

Addition

+
+=

R = A + B
R += A

_mm_add_epi64
_mm_add_epi32
_mm_add_epi16
_mm_add_epi8
_mm_add_pi32
_mm_add_pi16
_mm_add_pi8

Subtraction

-
-=

R = A - B
R -= A

_mm_sub_epi64
_mm_sub_epi32
_mm_sub_epi16
_mm_sub_epi8
_mm_sub_pi32
_mm_sub_pi16
_mm_sub_pi8

Addition and Subtraction Operator Overloading

The following table lists addition and subtraction return values for combinations of classes when the right side operands are of different signedness. The two operands must be the same size, otherwise you must explicitly indicate the typecasting.

Return Value

Add

Sub

Right Side Operand (A)

Right Side Operand (B)

I64vec2 R

+

-

I[s|u]64vec2 A

I[s|u]64vec2 B

I32vec4 R

+

-

I[s|u]32vec4 A

I[s|u]32vec4 B

I32vec2 R

+

-

I[s|u]32vec2 A

I[s|u]32vec2 B

I16vec8 R

+

-

I[s|u]16vec8 A

I[s|u]16vec8 B

I16vec4 R

+

-

I[s|u]16vec4 A

I[s|u]16vec4 B

I8vec8 R

+

-

I[s|u]8vec8 A

I[s|u]8vec8 B

I8vec16 R

+

-

I[s|u]8vec2 A

I[s|u]8vec16 B

Addition and Subtraction with Assignment

The following table lists the return data type values for operands of the addition and subtraction operators with assignment. The left side operand determines the size and signedness of the return value. The right side operand must be the same size as the left operand; otherwise, you must use an explicit typecast.

Return Value

Left Side Operand

Add

Sub

Right Side Operand

I[x]32vec4

I[x]32vec2 R

+=

-=

I[s|u]32vec4 A;

I[x]32vec2 R

I[x]32vec2 R

+=

-=

I[s|u]32vec2 A;

I[x]16vec8

I[x]16vec8

+=

-=

I[s|u]16vec8 A;

I[x]16vec4

I[x]16vec4

+=

-=

I[s|u]16vec4 A;

I[x]8vec16

I[x]8vec16

+=

-=

I[s|u]8vec16 A;

I[x]8vec8

I[x]8vec8

+=

-=

I[s|u]8vec8 A;