ROOT
Version master
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
▼
ROOT
ROOT Reference Documentation
Tutorials
►
Functional Parts
►
Namespaces
►
All Classes
▼
Files
▼
File List
►
bindings
▼
core
▼
base
►
doc
▼
inc
►
ROOT
►
Bswapcpy.h
►
Buttons.h
►
Bytes.h
►
Byteswap.h
►
GLConstants.h
Gtypes.h
Htypes.h
►
KeySymbols.h
►
Match.h
►
MessageTypes.h
RConfig.h
Riostream.h
Rpair.h
►
RQ_OBJECT.h
►
RStipples.h
►
Rtypes.h
►
RtypesImp.h
Strlen.h
►
TApplication.h
TAtt3D.h
TAttAxis.h
TAttBBox.h
TAttBBox2D.h
►
TAttFill.h
►
TAttLine.h
►
TAttMarker.h
TAttPad.h
►
TAttText.h
TBase64.h
►
TBenchmark.h
►
TBuffer.h
►
TBuffer3D.h
►
TBuffer3DTypes.h
►
TColor.h
►
TColorGradient.h
►
TDatime.h
►
TDirectory.h
►
TEnv.h
►
TException.h
TExec.h
TFileCollection.h
►
TFileInfo.h
TFolder.h
TInetAddress.h
TMacro.h
►
TMathBase.h
►
TMD5.h
TMemberInspector.h
TMessageHandler.h
TNamed.h
►
TNotifyLink.h
►
TObject.h
TObjString.h
TParameter.h
►
TPluginManager.h
►
TPoint.h
►
TPRegexp.h
►
TProcessID.h
TProcessUUID.h
►
TQClass.h
►
TQCommand.h
►
TQConnection.h
►
TQObject.h
►
TRedirectOutputGuard.h
TRef.h
TRefCnt.h
TRegexp.h
TRemoteObject.h
►
TROOT.h
►
TRootIOCtor.h
TStopwatch.h
►
TStorage.h
►
TString.h
►
TStringLong.h
►
TStyle.h
►
TSysEvtHandler.h
►
TSystem.h
TSystemDirectory.h
TSystemFile.h
TTask.h
►
TThreadSlots.h
►
TTime.h
TTimer.h
►
TTimeStamp.h
►
TUri.h
TUrl.h
►
TUUID.h
►
TVersionCheck.h
►
TVirtualAuth.h
TVirtualFFT.h
►
TVirtualGL.h
TVirtualMapFile.h
►
TVirtualMonitoring.h
►
TVirtualMutex.h
►
TVirtualPad.h
TVirtualPadEditor.h
TVirtualPadPainter.h
►
TVirtualPerfStats.h
►
TVirtualPS.h
►
TVirtualQConnection.h
►
TVirtualRWMutex.h
►
TVirtualTableInterface.h
TVirtualViewer3D.h
►
TVirtualX.h
►
Varargs.h
►
src
►
v7
►
clingutils
►
cont
►
dictgen
►
foundation
►
gui
►
imt
►
macosx
►
meta
►
metacling
►
multiproc
►
rint
►
testsupport
►
thread
►
unix
►
winnt
►
zip
►
documentation
►
geom
►
graf2d
►
graf3d
►
gui
►
hist
►
io
►
main
►
master
►
math
►
montecarlo
►
net
►
proof
►
roofit
►
sql
►
tmva
►
tree
►
tutorials
►
File Members
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
Byteswap.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
11
#ifndef ROOT_Byteswap
12
#define ROOT_Byteswap
13
14
/* Originally (mid-1990s), this file contained copy/pasted assembler from RH6.0's
15
* version of <bits/byteswap.h>. Hence, we keep a copy of the FSF copyright below.
16
* I believe all the original code has been excised, perhaps with exception of the
17
* R__bswap_constant_* functions. To be on the safe side, we are keeping the
18
* copyright below.
19
* -- Brian Bockelman, August 2018
20
*/
21
22
/* Copyright (C) 1997 Free Software Foundation, Inc.
23
This file is part of the GNU C Library.
24
25
The GNU C Library is free software; you can redistribute it and/or
26
modify it under the terms of the GNU Library General Public License as
27
published by the Free Software Foundation; either version 2 of the
28
License, or (at your option) any later version.
29
30
The GNU C Library is distributed in the hope that it will be useful,
31
but WITHOUT ANY WARRANTY; without even the implied warranty of
32
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
Library General Public License for more details.
34
35
You should have received a copy of the GNU Library General Public
36
License along with the GNU C Library; see the file COPYING.LIB. If not,
37
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
38
Boston, MA 02111-1307, USA. */
39
40
#include <cstdint>
41
42
#ifndef R__USEASMSWAP
43
#if (defined(__linux) || defined(__APPLE__)) && \
44
(defined(__i386__) || defined(__x86_64__)) && \
45
(defined(__GNUC__))
46
# define R__USEASMSWAP
47
#endif
48
49
#if defined(_WIN32) && (_MSC_VER >= 1300)
50
# include <stdlib.h>
51
# pragma intrinsic(_byteswap_ushort,_byteswap_ulong,_byteswap_uint64)
52
# define R__USEASMSWAP
53
#endif
54
#endif
/* R__USEASMSWAP */
55
56
/* Swap bytes in 16 bit value. */
57
#define R__bswap_constant_16(x) \
58
((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
59
60
#if defined(R__USEASMSWAP)
61
# if defined(__GNUC__)
62
# define R__bswap_16(x) __builtin_bswap16(x)
63
# elif defined(_MSC_VER)
64
# define R__bswap_16(x) _byteswap_ushort(x)
65
# endif
66
#else
67
# define R__bswap_16(x) R__bswap_constant_16(x)
68
#endif
69
70
/* Swap bytes in 32 bit value. */
71
#define R__bswap_constant_32(x) \
72
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
73
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
74
75
#if defined(R__USEASMSWAP)
76
# if defined(__GNUC__)
77
# define R__bswap_32(x) __builtin_bswap32(x)
78
# elif defined(_MSC_VER)
79
# define R__bswap_32(x) _byteswap_ulong(x)
80
# endif
81
#else
82
# define R__bswap_32(x) R__bswap_constant_32(x)
83
#endif
84
85
/* Swap bytes in 64 bit value. */
86
static
inline
uint64_t
R__bswap_constant_64
(uint64_t
x
) {
87
x
= ((
x
& 0x00000000ffffffff) << 32) | ((
x
& 0xffffffff00000000) >> 32);
88
x
= ((
x
& 0x0000ffff0000ffff) << 16) | ((
x
& 0xffff0000ffff0000) >> 16);
89
x
= ((
x
& 0x00ff00ff00ff00ff) << 8) | ((
x
& 0xff00ff00ff00ff00) >> 8);
90
return
x
;
91
}
92
93
#if defined(R__USEASMSWAP)
94
# if defined(__GNUC__)
95
# define R__bswap_64(x) __builtin_bswap64(x)
96
# elif defined(_MSC_VER)
97
# define R__bswap_64(x) _byteswap_uint64(x)
98
# endif
99
#else
100
# define R__bswap_64(x) R__bswap_constant_64(x)
101
#endif
102
103
104
/* Return a value with all bytes in the 16 bit argument swapped. */
105
#define Rbswap_16(x) R__bswap_16(x)
106
107
/* Return a value with all bytes in the 32 bit argument swapped. */
108
#define Rbswap_32(x) R__bswap_32(x)
109
110
/* Return a value with all bytes in the 64 bit argument swapped. */
111
#define Rbswap_64(x) R__bswap_64(x)
112
113
/// \brief Helper templated class for swapping bytes; specializations for `N={2,4,8}`
114
/// are provided below. This class can be used to byteswap any other type, e.g. in a
115
/// templated function (see example below).
116
/// ```
117
/// template <typename T>
118
/// void byteswap_arg(T &x) {
119
/// using value_type = typename RByteSwap<sizeof(T)>::value_type;
120
/// x = RByteSwap<sizeof(T)>::bswap(reinterpret_cast<value_type>(x));
121
/// }
122
/// ```
123
template
<
unsigned
N>
124
struct
RByteSwap
{
125
};
126
127
template
<>
128
struct
RByteSwap
<2> {
129
// Signed integers can be safely byteswapped if they are reinterpret_cast'ed to unsigned
130
using
value_type
= std::uint16_t;
131
static
value_type
bswap
(
value_type
x
) {
return
Rbswap_16
(
x
); }
132
};
133
134
template
<>
135
struct
RByteSwap
<4> {
136
using
value_type
= std::uint32_t;
137
static
value_type
bswap
(
value_type
x
) {
return
Rbswap_32
(
x
); }
138
};
139
140
template
<>
141
struct
RByteSwap
<8> {
142
using
value_type
= std::uint64_t;
143
static
value_type
bswap
(
value_type
x
) {
return
Rbswap_64
(
x
); }
144
};
145
146
#endif
/* Byteswap.h */
R__bswap_constant_64
static uint64_t R__bswap_constant_64(uint64_t x)
Definition
Byteswap.h:86
Rbswap_32
#define Rbswap_32(x)
Definition
Byteswap.h:108
Rbswap_64
#define Rbswap_64(x)
Definition
Byteswap.h:111
Rbswap_16
#define Rbswap_16(x)
Definition
Byteswap.h:105
x
Double_t x[n]
Definition
legend1.C:17
RByteSwap< 2 >::bswap
static value_type bswap(value_type x)
Definition
Byteswap.h:131
RByteSwap< 2 >::value_type
std::uint16_t value_type
Definition
Byteswap.h:130
RByteSwap< 4 >::bswap
static value_type bswap(value_type x)
Definition
Byteswap.h:137
RByteSwap< 4 >::value_type
std::uint32_t value_type
Definition
Byteswap.h:136
RByteSwap< 8 >::value_type
std::uint64_t value_type
Definition
Byteswap.h:142
RByteSwap< 8 >::bswap
static value_type bswap(value_type x)
Definition
Byteswap.h:143
RByteSwap
Helper templated class for swapping bytes; specializations for N={2,4,8} are provided below.
Definition
Byteswap.h:124
core
base
inc
Byteswap.h
ROOT master - Reference Guide Generated on Sun Mar 30 2025 15:55:22 (GVA Time) using Doxygen 1.10.0