We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.


Visual Studio 2010

Visual Studio 2010 SP1 is required.

Microsoft Specific

Generates the XOP instruction vpshaq to do an arithmetic shift of each of the quadwords in its first source by an amount specified in the second.

__m128i _mm_sha_epi64 (
   __m128i src,
   __m128i counts

[in] src

A 128-bit parameter that contains two 64-bit signed integers.

[in] counts

A 128-bit parameter that contains sixteen 8-bit signed integers.

A 128-bit result r that contains two 64-bit signed integers.

r[i] := (counts[8*i] >= 0) ? src[i] << counts[8*i] :
                             src[i] >> -counts[8*i]);





Header file <intrin.h>

Each 64-bit signed integer value in src is shifted by the number of bits specified by the value in the byte of counts corresponding to its low-order byte, and the 64-bit signed integer result is stored as the corresponding value in the destination. If the value in counts is positive, the shift is to the left (toward the most significant bit) and zeros are shifted in at the right end; otherwise, it is to the right and zeros are shifted in at the left end. If a shift count is greater than 63 the corresponding result value is 0; if a shift count is less than -63, the result is -1 if the value in src is negative, 0 otherwise. The other values in counts are ignored.

The vpshaq instruction is part of the XOP family of instructions. Before you use this intrinsic, you must ensure that the processor supports this instruction. To determine hardware support for this instruction, call the __cpuid intrinsic with InfoType = 0x80000001 and check bit 11 of CPUInfo[2] (ECX). This bit is 1 when the instruction is supported, and 0 otherwise.

#include <stdio.h>
#include <intrin.h>
int main()
    __m128i a, b, d;
    int i, j;
    unsigned __int64 temp;
    for (i = 0; i < 2; i++) {
        temp = 0;
        for (j = 0; j < 16; j++) {
            temp = temp << 4 | (8*i + j + 7) % 16;
        a.m128i_u64[i] = temp;
        b.m128i_i8[8*i] = 21*i - 11;
    d = _mm_sha_epi64(a, b);
    printf_s("data:       ");
    for (i = 0; i < 2; i++) printf_s(" %016I64x", a.m128i_u64[i]);
    printf_s("\nshifted by  ");
    for (i = 0; i < 2; i++) printf_s(" %16d", b.m128i_i8[8*i]);
    printf_s("\ngives       ");
    for (i = 0; i < 2; i++) printf_s(" %016I64x", d.m128i_u64[i]);
data:        789abcdef0123456 f0123456789abcde
shifted by                -11               10
gives        000f13579bde0246 48d159e26af37800