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.

70 lines
1.5 KiB

  1. /***
  2. *rotl.c - rotate an unsigned integer left
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _byteswap() - performs a byteswap on an unsigned integer.
  8. *
  9. *Revision History:
  10. * 09-06-00 GB Module created
  11. *
  12. *******************************************************************************/
  13. #include <cruntime.h>
  14. #include <stdlib.h>
  15. #ifdef _MSC_VER
  16. #pragma function(_byteswap_ulong, _byteswap_uint64, _byteswap_ushort)
  17. #endif
  18. /***
  19. *unsigned long _byteswap_ulong(i) - long byteswap
  20. *
  21. *Purpose:
  22. * Performs a byte swap on an unsigned integer.
  23. *
  24. *Entry:
  25. * unsigned long i: value to swap
  26. *
  27. *Exit:
  28. * returns swaped
  29. *
  30. *Exceptions:
  31. * None.
  32. *
  33. *******************************************************************************/
  34. unsigned long __cdecl _byteswap_ulong(unsigned long i)
  35. {
  36. unsigned int j;
  37. j = (i << 24);
  38. j += (i << 8) & 0x00FF0000;
  39. j += (i >> 8) & 0x0000FF00;
  40. j += (i >> 24);
  41. return j;
  42. }
  43. unsigned short __cdecl _byteswap_ushort(unsigned short i)
  44. {
  45. unsigned short j;
  46. j = (i << 8) ;
  47. j += (i >> 8) ;
  48. return j;
  49. }
  50. unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64 i)
  51. {
  52. unsigned __int64 j;
  53. j = (i << 56);
  54. j += (i << 40)&0x00FF000000000000;
  55. j += (i << 24)&0x0000FF0000000000;
  56. j += (i << 8)&0x000000FF00000000;
  57. j += (i >> 8)&0x00000000FF000000;
  58. j += (i >> 24)&0x0000000000FF0000;
  59. j += (i >> 40)&0x000000000000FF00;
  60. j += (i >> 56);
  61. return j;
  62. }