byteswap.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Macros to swap the order of bytes in integer values.
  2. Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _ASM_BITS_BYTESWAP_H
  16. #define _ASM_BITS_BYTESWAP_H 1
  17. #define __bswap_non_constant_16(x) \
  18. (__extension__ \
  19. ({ register unsigned short int __v; \
  20. __asm__ __volatile__ ("shl %0 = %1, 48 ;;" \
  21. "mux1 %0 = %0, @rev ;;" \
  22. : "=r" (__v) \
  23. : "r" ((unsigned short int) (x))); \
  24. __v; }))
  25. #define __bswap_non_constant_32(x) \
  26. (__extension__ \
  27. ({ register unsigned int __v; \
  28. __asm__ __volatile__ ("shl %0 = %1, 32 ;;" \
  29. "mux1 %0 = %0, @rev ;;" \
  30. : "=r" (__v) \
  31. : "r" ((unsigned int) (x))); \
  32. __v; }))
  33. #define __bswap_non_constant_64(x) \
  34. (__extension__ \
  35. ({ register unsigned long int __v; \
  36. __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \
  37. : "=r" (__v) \
  38. : "r" ((unsigned long int) (x))); \
  39. __v; }))
  40. #endif
  41. #include <bits/byteswap-common.h>