Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Shift Operators

The right shift argument can be any integer or Ivec value, and is implicitly converted to a M64 data type. The first or left operand of a << can be of any type except I[s|u]8vec[8|16]. For example:

  • Automatic size and sign conversion:
    Is16vec4 A,C;
    Iu32vec2 B;
    
    C = A;
    
  • A&B returns I16vec4, which must be cast to Iu16vec4 to ensure logical shift, not arithmetic shift:
    Is16vec4 A, C;
    Iu16vec4 B, R;
    
    R = (Iu16vec4)(A & B) C;
    
  • A&B returns I16vec4, which must be cast to Is16vec4 to ensure arithmetic shift, not logical shift:
    R = (Is16vec4)(A & B) C;
    

Shift Operators with Corresponding Intrinsics

Operation

Symbols

Syntax Usage

Intrinsic

Shift Left

<<
&=

R = A << B
R &= A

_mm_sll_si64
_mm_slli_si64
_mm_sll_pi32
_mm_slli_pi32
_mm_sll_pi16
_mm_slli_pi16

Shift Right

>>

R = A >> B
R >>= A

_mm_srl_si64
_mm_srli_si64
_mm_srl_pi32
_mm_srli_pi32
_mm_srl_pi16
_mm_srli_pi16
_mm_sra_pi32
_mm_srai_pi32
_mm_sra_pi16
_mm_srai_pi16

Shift Operator Overloading

Right shift operations with signed data types use arithmetic shifts. All unsigned and intermediate classes correspond to logical shifts. The following table lists how the return type is determined by the first argument type:

Option

R

Right Shift Left Shift

A

B

Logical

I64vec1

>>

>>=

<<

<<=

I64vec1 A;

I64vec1 B;

Logical

I32vec2

>>

>>=

<<

<<=

I32vec2 A

I32vec2 B;

Arithmetic

Is32vec2

>>

>>=

<<

<<=

Is32vec2 A

I[s|u][N]vec[N] B;

Logical

Iu32vec2

>>

>>=

<<

<<=

Iu32vec2 A

I[s|u][N]vec[N] B;

Logical

I16vec4

>>

>>=

<<

<<=

I16vec4 A

I16vec4 B

Arithmetic

Is16vec4

>>

>>=

<<

<<=

Is16vec4 A

I[s|u][N]vec[N] B;

Logical

Iu16vec4

>>

>>=

<<

<<=

Iu16vec4 A

I[s|u][N]vec[N] B;