swab.h 706 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef _ASM_X86_SWAB_H
  2. #define _ASM_X86_SWAB_H
  3. #include <linux/types.h>
  4. #include <linux/compiler.h>
  5. static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
  6. {
  7. asm("bswapl %0" : "=r" (val) : "0" (val));
  8. return val;
  9. }
  10. #define __arch_swab32 __arch_swab32
  11. static inline __attribute_const__ __u64 __arch_swab64(__u64 val)
  12. {
  13. #ifdef __i386__
  14. union {
  15. struct {
  16. __u32 a;
  17. __u32 b;
  18. } s;
  19. __u64 u;
  20. } v;
  21. v.u = val;
  22. asm("bswapl %0 ; bswapl %1 ; xchgl %0,%1"
  23. : "=r" (v.s.a), "=r" (v.s.b)
  24. : "0" (v.s.a), "1" (v.s.b));
  25. return v.u;
  26. #else /* __i386__ */
  27. asm("bswapq %0" : "=r" (val) : "0" (val));
  28. return val;
  29. #endif
  30. }
  31. #define __arch_swab64 __arch_swab64
  32. #endif /* _ASM_X86_SWAB_H */