linux-bk/include/asm-parisc/byteorder.h
<<
>>
Prefs
   1#ifndef _PARISC_BYTEORDER_H
   2#define _PARISC_BYTEORDER_H
   3
   4#include <asm/types.h>
   5#include <linux/compiler.h>
   6
   7#ifdef __GNUC__
   8
   9static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
  10{
  11        __asm__("dep %0, 15, 8, %0\n\t"         /* deposit 00ab -> 0bab */
  12                "shd %%r0, %0, 8, %0"           /* shift 000000ab -> 00ba */
  13                : "=r" (x)
  14                : "0" (x));
  15        return x;
  16}
  17
  18static __inline__ __attribute_const__ __u32 ___arch__swab24(__u32 x)
  19{
  20        __asm__("shd %0, %0, 8, %0\n\t"         /* shift xabcxabc -> cxab */
  21                "dep %0, 15, 8, %0\n\t"         /* deposit cxab -> cbab */
  22                "shd %%r0, %0, 8, %0"           /* shift 0000cbab -> 0cba */
  23                : "=r" (x)
  24                : "0" (x));
  25        return x;
  26}
  27
  28static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  29{
  30        unsigned int temp;
  31        __asm__("shd %0, %0, 16, %1\n\t"        /* shift abcdabcd -> cdab */
  32                "dep %1, 15, 8, %1\n\t"         /* deposit cdab -> cbab */
  33                "shd %0, %1, 8, %0"             /* shift abcdcbab -> dcba */
  34                : "=r" (x), "=&r" (temp)
  35                : "0" (x));
  36        return x;
  37}
  38
  39
  40#if BITS_PER_LONG > 32
  41/*
  42** From "PA-RISC 2.0 Architecture", HP Professional Books.
  43** See Appendix I page 8 , "Endian Byte Swapping".
  44**
  45** Pretty cool algorithm: (* == zero'd bits)
  46**      PERMH   01234567 -> 67452301 into %0
  47**      HSHL    67452301 -> 7*5*3*1* into %1
  48**      HSHR    67452301 -> *6*4*2*0 into %0
  49**      OR      %0 | %1  -> 76543210 into %0 (all done!)
  50*/
  51static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x) {
  52        __u64 temp;
  53        __asm__("permh,3210 %0, %0\n\t"
  54                "hshl %0, 8, %1\n\t"
  55                "hshr,u %0, 8, %0\n\t"
  56                "or %1, %0, %0"
  57                : "=r" (x), "=&r" (temp)
  58                : "0" (x));
  59        return x;
  60}
  61#define __arch__swab64(x) ___arch__swab64(x)
  62#define __BYTEORDER_HAS_U64__
  63#elif !defined(__STRICT_ANSI__)
  64static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x)
  65{
  66        __u32 t1 = ___arch__swab32((__u32) x);
  67        __u32 t2 = ___arch__swab32((__u32) (x >> 32));
  68        return (((__u64) t1 << 32) | t2);
  69}
  70#define __arch__swab64(x) ___arch__swab64(x)
  71#define __BYTEORDER_HAS_U64__
  72#endif
  73
  74#define __arch__swab16(x) ___arch__swab16(x)
  75#define __arch__swab24(x) ___arch__swab24(x)
  76#define __arch__swab32(x) ___arch__swab32(x)
  77
  78#endif /* __GNUC__ */
  79
  80#include <linux/byteorder/big_endian.h>
  81
  82#endif /* _PARISC_BYTEORDER_H */
  83
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.