Windows NT 4.0 source code leak
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.

90 lines
2.0 KiB

4 years ago
  1. /***
  2. *rotr.c - rotate an unsigned integer right
  3. *
  4. * Copyright (c) 1989-1991, 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. * 03-09-94 RDL Enable #pragma function for i386 _WIN32_ builds too.
  19. *
  20. *******************************************************************************/
  21. #ifndef _POSIX_
  22. #include <cruntime.h>
  23. #include <stdlib.h>
  24. #include <limits.h>
  25. #ifdef _MSC_VER
  26. #pragma function(_lrotr,_rotr)
  27. #endif
  28. #if UINT_MAX != 0xffffffff
  29. #error This module assumes 32-bit integers
  30. #endif
  31. #if (UINT_MAX != ULONG_MAX)
  32. #error This module assumes sizeof(int) == sizeof(long)
  33. #endif
  34. /***
  35. *unsigned _rotr(val, shift) - int rotate right
  36. *
  37. *Purpose:
  38. * Performs a rotate right on an unsigned integer.
  39. *
  40. * [Note: The _lrotl entry is based on the assumption
  41. * that sizeof(int) == sizeof(long).]
  42. *Entry:
  43. * unsigned val: value to rotate
  44. * int shift: number of bits to shift by
  45. *
  46. *Exit:
  47. * returns rotated values
  48. *
  49. *Exceptions:
  50. * None.
  51. *
  52. *******************************************************************************/
  53. unsigned long _CALLTYPE1 _lrotr (
  54. unsigned long val,
  55. int shift
  56. )
  57. {
  58. return( (unsigned long) _rotr((unsigned) val, shift) );
  59. }
  60. unsigned _CALLTYPE1 _rotr (
  61. unsigned val,
  62. int shift
  63. )
  64. {
  65. register unsigned lobit; /* non-zero means lo bit set */
  66. register unsigned num = val; /* number to rotate */
  67. shift &= 0x1f; /* modulo 32 -- this will also make
  68. negative shifts work */
  69. while (shift--) {
  70. lobit = num & 1; /* get high bit */
  71. num >>= 1; /* shift right one bit */
  72. if (lobit)
  73. num |= 0x80000000; /* set hi bit if lo bit was set */
  74. }
  75. return num;
  76. }
  77. #endif