direct-io.hg

view xen/include/acm/acm_endian.h @ 5517:10e9028c8e3d

bitkeeper revision 1.1718.1.10 (42b7b19aqOS_1M8I4pIOFjiTPYWV-g)

Merge bk://xenbits.xensource.com/xen-unstable.bk
into spot.cl.cam.ac.uk:C:/Documents and Settings/iap10/xen-unstable.bk
author iap10@spot.cl.cam.ac.uk
date Tue Jun 21 06:20:10 2005 +0000 (2005-06-21)
parents aa52b853c28b
children 649cd37aa1ab
line source
1 /****************************************************************
2 * acm_endian.h
3 *
4 * Copyright (C) 2005 IBM Corporation
5 *
6 * Author:
7 * Stefan Berger <stefanb@watson.ibm.com>
8 *
9 * Contributions:
10 * Reiner Sailer <sailer@watson.ibm.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation, version 2 of the
15 * License.
16 *
17 * sHype header file defining endian-dependent functions for the
18 * big-endian policy interface
19 *
20 */
21 #ifndef _ACM_ENDIAN_H
22 #define _ACM_ENDIAN_H
24 /* don't use these functions in performance critical sections! */
26 /* set during initialization by testing */
27 extern u8 little_endian;
29 static inline u32 ntohl(u32 x)
30 {
31 if (little_endian)
32 return
33 ( (((x) >> 24) & 0xff )|
34 (((x) >> 8) & 0xff00 )|
35 (((x) << 8) & 0xff0000 )|
36 (((x) << 24) & 0xff000000) );
37 else
38 return x;
39 }
41 static inline u16 ntohs(u16 x)
42 {
43 if (little_endian)
44 return
45 ( (((x) >> 8) & 0xff )|
46 (((x) << 8) & 0xff00 ) );
47 else
48 return x;
49 }
51 #define htonl(x) ntohl(x)
52 #define htons(x) ntohs(x)
54 static inline void arrcpy16(u16 *dest, const u16 *src, size_t n)
55 {
56 unsigned int i = 0;
57 while (i < n) {
58 dest[i] = htons(src[i]);
59 i++;
60 }
61 }
63 static inline void arrcpy32(u32 *dest, const u32 *src, size_t n)
64 {
65 unsigned int i = 0;
66 while (i < n) {
67 dest[i] = htonl(src[i]);
68 i++;
69 }
70 }
72 static inline void arrcpy(void *dest, const void *src, unsigned int elsize, size_t n)
73 {
74 switch (elsize) {
75 case sizeof(u16):
76 arrcpy16((u16 *)dest, (u16 *)src, n);
77 break;
79 case sizeof(u32):
80 arrcpy32((u32 *)dest, (u32 *)src, n);
81 break;
83 default:
84 memcpy(dest, src, elsize*n);
85 }
86 }
88 #endif