Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.3 KiB

  1. /***
  2. *rotr.c - rotate an unsigned integer right
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _rotr() - performs a rotate right on an unsigned integer.
  8. *
  9. *Revision History:
  10. * 06-02-89 PHG Module created
  11. * 11-03-89 JCR Added _lrotl
  12. * 03-15-90 GJF Made calling type _CALLTYPE1, added #include
  13. * <cruntime.h> and fixed the copyright. Also, cleaned
  14. * up the formatting a bit.
  15. * 10-04-90 GJF New-style function declarators.
  16. * 04-01-91 SRW Enable #pragma function for i386 _WIN32_ builds too.
  17. * 09-02-92 GJF Don't build for POSIX.
  18. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  19. * No _CRTIMP for CRT DLL model due to intrinsic
  20. * 12-03-93 GJF Turn on #pragma function for all MS front-ends (esp.,
  21. * Alpha compiler).
  22. * 01-04-01 GB Rewrote rotr functions and added __int64 version.
  23. *
  24. *******************************************************************************/
  25. #ifndef _POSIX_
  26. #include <cruntime.h>
  27. #include <stdlib.h>
  28. #include <limits.h>
  29. #ifdef _MSC_VER
  30. #pragma function(_lrotr,_rotr, _rotr64)
  31. #endif
  32. #if UINT_MAX != 0xffffffff /*IFSTRIP=IGN*/
  33. #error This module assumes 32-bit integers
  34. #endif
  35. #if UINT_MAX != ULONG_MAX /*IFSTRIP=IGN*/
  36. #error This module assumes sizeof(int) == sizeof(long)
  37. #endif
  38. /***
  39. *unsigned _rotr(val, shift) - int rotate right
  40. *
  41. *Purpose:
  42. * Performs a rotate right on an unsigned integer.
  43. *
  44. * [Note: The _lrotl entry is based on the assumption
  45. * that sizeof(int) == sizeof(long).]
  46. *Entry:
  47. * unsigned val: value to rotate
  48. * int shift: number of bits to shift by
  49. *
  50. *Exit:
  51. * returns rotated value
  52. *
  53. *Exceptions:
  54. * None.
  55. *
  56. *******************************************************************************/
  57. unsigned long __cdecl _lrotr (
  58. unsigned long val,
  59. int shift
  60. )
  61. {
  62. shift &= 0x1f;
  63. val = (val<<(0x20 - shift)) | (val >> shift);
  64. return val;
  65. }
  66. unsigned __cdecl _rotr (
  67. unsigned val,
  68. int shift
  69. )
  70. {
  71. shift &= 0x1f;
  72. val = (val<<(0x20 - shift)) | (val >> shift);
  73. return val;
  74. }
  75. unsigned __int64 __cdecl _rotr64 (
  76. unsigned __int64 val,
  77. int shift
  78. )
  79. {
  80. shift &= 0x3f;
  81. val = (val<<(0x40 - shift)) | (val >> shift);
  82. return val;
  83. }
  84. #endif