Visual Studio 2010

Visual Studio 2010 SP1 is required.

Microsoft Specific

Generates the XOP instruction vprotw to rotate each of the words in its first source by the amount specified in the second.

__m128i _mm_roti_epi16 (
   __m128i src,
   int count

[in] src

A 128-bit parameter that contains eight 16-bit unsigned integers.

[in] count

An integer rotation count, preferably constant.

A 128-bit result r that contains eight 16-bit unsigned integers.

r[i] := (count > 0) ? rotate_left(src[i], count) : 
                      rotate_right(src[i], -count);





Header file <intrin.h>

Each 16-bit unsigned integer value in src is rotated by the number of bits specified in count, and the 16-bit unsigned integer result is stored as the corresponding value in the destination. If the value in count is positive, the rotation is to the left (toward the most significant bit); otherwise, it is to the right.

The vprotw instruction has one form for constant arguments, another for non-constant arguments. If the value of count cannot be determined to be constant at compile time, the compiler will generate extra code to set up and use the non-constant version of vprotw. The constant version of vprotw is faster.

The vprotw 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, d;
    int i;
    for (i = 0; i < 8; i++) {
        a.m128i_u16[i] = (2*(i+1)) << 12 | (15 - 2*(i+1)) << 8 |
                          2*i << 4 | (15 - 2*i);
    d = _mm_roti_epi16(a, 12);
    printf_s("data:              ");
    for (i = 0; i < 8; i++) printf_s(" %04x", a.m128i_u16[i]);
    printf_s("\nrotated by 12 gives");
    for (i = 0; i < 8; i++) printf_s(" %04x", d.m128i_u16[i]);
data:               2d0f 4b2d 694b 8769 a587 c3a5 e1c3 ffe1
rotated by 12 gives f2d0 d4b2 b694 9876 7a58 5c3a 3e1c 1ffe

Community Additions