Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/LESwaps.h
38825 views
1
/*
2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3
*
4
* This code is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 2 only, as
6
* published by the Free Software Foundation. Oracle designates this
7
* particular file as subject to the "Classpath" exception as provided
8
* by Oracle in the LICENSE file that accompanied this code.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
27
/*
28
*
29
* (C) Copyright IBM Corp. 1998-2010 - All Rights Reserved
30
*
31
*/
32
33
#ifndef __LESWAPS_H
34
#define __LESWAPS_H
35
36
#include "LETypes.h"
37
38
/**
39
* \file
40
* \brief C++ API: Endian independent access to data for LayoutEngine
41
*/
42
43
U_NAMESPACE_BEGIN
44
45
/**
46
* A convenience macro which invokes the swapWord member function
47
* from a concise call.
48
*
49
* @stable ICU 2.8
50
*/
51
#if defined(U_IS_BIG_ENDIAN)
52
#if U_IS_BIG_ENDIAN
53
#define SWAPW(value) (value)
54
#else
55
#define SWAPW(value) LESwaps::swapWord(value)
56
#endif
57
#else
58
#define SWAPW(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapWord(value))
59
#endif
60
61
/**
62
* A convenience macro which invokes the swapLong member function
63
* from a concise call.
64
*
65
* @stable ICU 2.8
66
*/
67
#if defined(U_IS_BIG_ENDIAN)
68
#if U_IS_BIG_ENDIAN
69
#define SWAPL(value) (value)
70
#else
71
#define SWAPL(value) LESwaps::swapLong(value)
72
#endif
73
#else
74
#define SWAPL(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapLong(value))
75
#endif
76
77
/**
78
* This class is used to access data which stored in big endian order
79
* regardless of the conventions of the platform. It has been designed
80
* to automatically detect the endian-ness of the platform, so that a
81
* compilation flag is not needed.
82
*
83
* All methods are static and inline in an attempt to induce the compiler
84
* to do most of the calculations at compile time.
85
*
86
* @stable ICU 2.8
87
*/
88
class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {
89
public:
90
91
#if !defined(U_IS_BIG_ENDIAN)
92
/**
93
* This method detects the endian-ness of the platform by
94
* casting a pointer to a word to a pointer to a byte. On
95
* big endian platforms the FF will be in the byte with the
96
* lowest address. On little endian platforms, the FF will
97
* be in the byte with the highest address.
98
*
99
* @return TRUE if the platform is big endian
100
*
101
* @stable ICU 2.8
102
*/
103
static le_uint8 isBigEndian()
104
{
105
const le_uint16 word = 0xFF00;
106
107
return *((le_uint8 *) &word);
108
};
109
#endif
110
111
/**
112
* This method does the byte swap required on little endian platforms
113
* to correctly access a (16-bit) word.
114
*
115
* @param value - the word to be byte swapped
116
*
117
* @return the byte swapped word
118
*
119
* @stable ICU 2.8
120
*/
121
static le_uint16 swapWord(le_uint16 value)
122
{
123
return (((le_uint8) (value >> 8)) | (value << 8));
124
};
125
126
/**
127
* This method does the byte swapping required on little endian platforms
128
* to correctly access a (32-bit) long.
129
*
130
* @param value - the long to be byte swapped
131
*
132
* @return the byte swapped long
133
*
134
* @stable ICU 2.8
135
*/
136
static le_uint32 swapLong(le_uint32 value)
137
{
138
return swapWord((le_uint16) (value >> 16)) | (swapWord((le_uint16) value) << 16);
139
};
140
141
private:
142
LESwaps() {} // private - forbid instantiation
143
};
144
145
U_NAMESPACE_END
146
#endif
147
148