1 //
2 // rotr.cpp
3 //
4 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // Defines _lrotl(), _rotl(), and _rotl64(), which perform a rotate-right on an
7 // integer.
8 //
9 #include <stdlib.h>
10 #include <limits.h>
11
12
13
14 #pragma function(_lrotr, _rotr, _rotr64)
15
16 #if UINT_MAX != 0xffffffff
17 #error This source file assumes 32-bit integers
18 #endif
19
20 #if UINT_MAX != ULONG_MAX
21 #error This source file assumes sizeof(int) == sizeof(long)
22 #endif
23
24
25
_lrotr(unsigned long value,int shift)26 extern "C" unsigned long __cdecl _lrotr(unsigned long value, int shift)
27 {
28 shift &= 0x1f;
29 value = (value << (0x20 - shift)) | (value >> shift);
30 return value;
31 }
32
_rotr(unsigned value,int shift)33 extern "C" unsigned __cdecl _rotr(unsigned value, int shift)
34 {
35 shift &= 0x1f;
36 value = (value << (0x20 - shift)) | (value >> shift);
37 return value;
38 }
39
_rotr64(unsigned __int64 value,int shift)40 extern "C" unsigned __int64 __cdecl _rotr64(unsigned __int64 value, int shift)
41 {
42 shift &= 0x3f;
43 value = (value << (0x40 - shift)) | (value >> shift);
44 return value;
45 }
46