swab.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #ifndef _UAPI_BLACKFIN_SWAB_H
  7. #define _UAPI_BLACKFIN_SWAB_H
  8. #include <linux/types.h>
  9. #include <asm-generic/swab.h>
  10. #ifdef __GNUC__
  11. static __inline__ __attribute_const__ __u32 __arch_swahb32(__u32 xx)
  12. {
  13. __u32 tmp;
  14. __asm__("%1 = %0 >> 8 (V);\n\t"
  15. "%0 = %0 << 8 (V);\n\t"
  16. "%0 = %0 | %1;\n\t"
  17. : "+d"(xx), "=&d"(tmp));
  18. return xx;
  19. }
  20. #define __arch_swahb32 __arch_swahb32
  21. static __inline__ __attribute_const__ __u32 __arch_swahw32(__u32 xx)
  22. {
  23. __u32 rv;
  24. __asm__("%0 = PACK(%1.L, %1.H);\n\t": "=d"(rv): "d"(xx));
  25. return rv;
  26. }
  27. #define __arch_swahw32 __arch_swahw32
  28. static __inline__ __attribute_const__ __u32 __arch_swab32(__u32 xx)
  29. {
  30. return __arch_swahb32(__arch_swahw32(xx));
  31. }
  32. #define __arch_swab32 __arch_swab32
  33. static __inline__ __attribute_const__ __u16 __arch_swab16(__u16 xx)
  34. {
  35. __u32 xw = xx;
  36. __asm__("%0 <<= 8;\n %0.L = %0.L + %0.H (NS);\n": "+d"(xw));
  37. return (__u16)xw;
  38. }
  39. #define __arch_swab16 __arch_swab16
  40. #endif /* __GNUC__ */
  41. #endif /* _UAPI_BLACKFIN_SWAB_H */