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#ifndef USE_BSWAPCPY
14#warning "This header is an implementation detail of TBufferFile on Unix i386 GNUC, and is deprecated and will no longer be public after ROOT 6.44"
15#endif
16
17
18//////////////////////////////////////////////////////////////////////////
19// //
20// Bswapcpy //
21// //
22// Initial version: Apr 22, 2000 //
23// //
24// A set of inline byte swapping routines for arrays. //
25// //
26// The bswapcpy16() and bswapcpy32() routines are used for packing //
27// arrays of basic types into a buffer in a byte swapped order. Use //
28// of asm and the `bswap' opcode (available on i486 and up) reduces //
29// byte swapping overhead on linux. //
30// //
31// Use of routines is similar to that of memcpy. //
32// //
33// ATTENTION: //
34// //
35// n - is a number of array elements to be copied and byteswapped. //
36// (It is not the number of bytes!) //
37// //
38// Note: It is not safe to call these routines with n == 0. //
39// //
40// For arrays of short type (2 bytes in size) use bswapcpy16(). //
41// For arrays of of 4-byte types (int, float) use bswapcpy32(). //
42// //
43// //
44// Author: Alexandre V. Vaniachine <AVVaniachine@lbl.gov> //
45// //
46//////////////////////////////////////////////////////////////////////////
47
48#include <sys/types.h>
49
50extern inline void * bswapcpy16(void * to, const void * from, size_t n)
51{
52int d0, d1, d2, d3;
54 "cld\n"
55 "1:\tlodsw\n\t"
56 "rorw $8, %%ax\n\t"
57 "stosw\n\t"
58 "loop 1b\n\t"
59 :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
60 :"0" (n), "1" ((long) to),"2" ((long) from)
61 :"memory");
62return (to);
63}
64
65extern inline void * bswapcpy32(void * to, const void * from, size_t n)
66{
67int d0, d1, d2, d3;
69 "cld\n"
70 "1:\tlodsl\n\t"
73 "rorw $8, %%ax\n\t"
74 "rorl $16, %%eax\n\t"
75 "rorw $8, %%ax\n\t"
76#else
77 "bswap %%eax\n\t"
78#endif
79 "stosl\n\t"
80 "loop 1b\n\t"
81 :"=&c" (d0), "=&D" (d1), "=&S" (d2), "=&a" (d3)
82 :"0" (n), "1" ((long) to),"2" ((long) from)
83 :"memory");
84return (to);
85}
86#endif
void * bswapcpy16(void *to, const void *from, size_t n)
Definition Bswapcpy.h:50
void * bswapcpy32(void *to, const void *from, size_t n)
Definition Bswapcpy.h:65
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const Int_t n
Definition legend1.C:16