ROOT  6.06/09
Reference Guide
Bswapcpy.h
Go to the documentation of this file.
1 /* @(#)root/base:$Id$ */
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 #ifndef ROOT_Bswapcpy
11 #define ROOT_Bswapcpy
12 
13 //////////////////////////////////////////////////////////////////////////
14 // //
15 // Bswapcpy //
16 // //
17 // Initial version: Apr 22, 2000 //
18 // //
19 // A set of inline byte swapping routines for arrays. //
20 // //
21 // The bswapcpy16() and bswapcpy32() routines are used for packing //
22 // arrays of basic types into a buffer in a byte swapped order. Use //
23 // of asm and the `bswap' opcode (available on i486 and up) reduces //
24 // byte swapping overhead on linux. //
25 // //
26 // Use of routines is similar to that of memcpy. //
27 // //
28 // ATTENTION: //
29 // //
30 // n - is a number of array elements to be copied and byteswapped. //
31 // (It is not the number of bytes!) //
32 // //
33 // For arrays of short type (2 bytes in size) use bswapcpy16(). //
34 // For arrays of of 4-byte types (int, float) use bswapcpy32(). //
35 // //
36 // //
37 // Author: Alexandre V. Vaniachine <AVVaniachine@lbl.gov> //
38 // //
39 //////////////////////////////////////////////////////////////////////////
40 
41 #if !defined(__CINT__)
42 #include <sys/types.h>
43 #endif
44 
45 extern inline void * bswapcpy16(void * to, const void * from, size_t n)
46 {
47 int d0, d1, d2, d3;
48 __asm__ __volatile__(
49  "cld\n"
50  "1:\tlodsw\n\t"
51  "rorw $8, %%ax\n\t"
52  "stosw\n\t"
53  "loop 1b\n\t"
54  :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
55  :"0" (n), "1" ((long) to),"2" ((long) from)
56  :"memory");
57 return (to);
58 }
59 
60 extern inline void * bswapcpy32(void * to, const void * from, size_t n)
61 {
62 int d0, d1, d2, d3;
63 __asm__ __volatile__(
64  "cld\n"
65  "1:\tlodsl\n\t"
66 #if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__ && \
67  !defined __pentium4__ && !defined __x86_64__
68  "rorw $8, %%ax\n\t"
69  "rorl $16, %%eax\n\t"
70  "rorw $8, %%ax\n\t"
71 #else
72  "bswap %%eax\n\t"
73 #endif
74  "stosl\n\t"
75  "loop 1b\n\t"
76  :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
77  :"0" (n), "1" ((long) to),"2" ((long) from)
78  :"memory");
79 return (to);
80 }
81 #endif
void * bswapcpy32(void *to, const void *from, size_t n)
Definition: Bswapcpy.h:60
void * bswapcpy16(void *to, const void *from, size_t n)
Definition: Bswapcpy.h:45
const Int_t n
Definition: legend1.C:16