The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/include/asm-alpha/unaligned.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #ifndef __ALPHA_UNALIGNED_H
    2 #define __ALPHA_UNALIGNED_H
    3 
    4 /* 
    5  * The main single-value unaligned transfer routines.
    6  */
    7 #define get_unaligned(ptr) \
    8         ((__typeof__(*(ptr)))__get_unaligned((ptr), sizeof(*(ptr))))
    9 #define put_unaligned(x,ptr) \
   10         __put_unaligned((unsigned long)(x), (ptr), sizeof(*(ptr)))
   11 
   12 /*
   13  * This is a silly but good way to make sure that
   14  * the get/put functions are indeed always optimized,
   15  * and that we use the correct sizes.
   16  */
   17 extern void bad_unaligned_access_length(void);
   18 
   19 /*
   20  * EGCS 1.1 knows about arbitrary unaligned loads.  Define some
   21  * packed structures to talk about such things with.
   22  */
   23 
   24 struct __una_u64 { __u64 x __attribute__((packed)); };
   25 struct __una_u32 { __u32 x __attribute__((packed)); };
   26 struct __una_u16 { __u16 x __attribute__((packed)); };
   27 
   28 /*
   29  * Elemental unaligned loads 
   30  */
   31 
   32 extern inline unsigned long __uldq(const unsigned long * r11)
   33 {
   34         const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
   35         return ptr->x;
   36 }
   37 
   38 extern inline unsigned long __uldl(const unsigned int * r11)
   39 {
   40         const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
   41         return ptr->x;
   42 }
   43 
   44 extern inline unsigned long __uldw(const unsigned short * r11)
   45 {
   46         const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
   47         return ptr->x;
   48 }
   49 
   50 /*
   51  * Elemental unaligned stores 
   52  */
   53 
   54 extern inline void __ustq(unsigned long r5, unsigned long * r11)
   55 {
   56         struct __una_u64 *ptr = (struct __una_u64 *) r11;
   57         ptr->x = r5;
   58 }
   59 
   60 extern inline void __ustl(unsigned long r5, unsigned int * r11)
   61 {
   62         struct __una_u32 *ptr = (struct __una_u32 *) r11;
   63         ptr->x = r5;
   64 }
   65 
   66 extern inline void __ustw(unsigned long r5, unsigned short * r11)
   67 {
   68         struct __una_u16 *ptr = (struct __una_u16 *) r11;
   69         ptr->x = r5;
   70 }
   71 
   72 extern inline unsigned long __get_unaligned(const void *ptr, size_t size)
   73 {
   74         unsigned long val;
   75         switch (size) {
   76               case 1:
   77                 val = *(const unsigned char *)ptr;
   78                 break;
   79               case 2:
   80                 val = __uldw((const unsigned short *)ptr);
   81                 break;
   82               case 4:
   83                 val = __uldl((const unsigned int *)ptr);
   84                 break;
   85               case 8:
   86                 val = __uldq((const unsigned long *)ptr);
   87                 break;
   88               default:
   89                 bad_unaligned_access_length();
   90         }
   91         return val;
   92 }
   93 
   94 extern inline void __put_unaligned(unsigned long val, void *ptr, size_t size)
   95 {
   96         switch (size) {
   97               case 1:
   98                 *(unsigned char *)ptr = (val);
   99                 break;
  100               case 2:
  101                 __ustw(val, (unsigned short *)ptr);
  102                 break;
  103               case 4:
  104                 __ustl(val, (unsigned int *)ptr);
  105                 break;
  106               case 8:
  107                 __ustq(val, (unsigned long *)ptr);
  108                 break;
  109               default:
  110                 bad_unaligned_access_length();
  111         }
  112 }
  113 
  114 #endif

Cache object: 70ba0041ee5c06216d85f53a7971ae16


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.