Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <sys/types.h>
42
43extern inline void * bswapcpy16(void * to, const void * from, size_t n)
44{
45int d0, d1, d2, d3;
46__asm__ __volatile__(
47 "cld\n"
48 "1:\tlodsw\n\t"
49 "rorw $8, %%ax\n\t"
50 "stosw\n\t"
51 "loop 1b\n\t"
52 :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
53 :"0" (n), "1" ((long) to),"2" ((long) from)
54 :"memory");
55return (to);
56}
57
58extern inline void * bswapcpy32(void * to, const void * from, size_t n)
59{
60int d0, d1, d2, d3;
61__asm__ __volatile__(
62 "cld\n"
63 "1:\tlodsl\n\t"
64#if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__ && \
65 !defined __pentium4__ && !defined __x86_64__
66 "rorw $8, %%ax\n\t"
67 "rorl $16, %%eax\n\t"
68 "rorw $8, %%ax\n\t"
69#else
70 "bswap %%eax\n\t"
71#endif
72 "stosl\n\t"
73 "loop 1b\n\t"
74 :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
75 :"0" (n), "1" ((long) to),"2" ((long) from)
76 :"memory");
77return (to);
78}
79#endif
void * bswapcpy16(void *to, const void *from, size_t n)
Definition Bswapcpy.h:43
void * bswapcpy32(void *to, const void *from, size_t n)
Definition Bswapcpy.h:58
const Int_t n
Definition legend1.C:16