# 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] .

### Example Syntax Usage for Shift Operators

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

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