1 /*
2 * Copyright (c) 1997, 2002, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2007, 2008, 2009 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
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 typedef union unaligned {
27 u4 u;
28 u2 us;
29 u8 ul;
30 } __attribute__((packed)) unaligned;
31
32 class Bytes: AllStatic {
33 public:
34 // Returns true if the byte ordering used by Java is different
35 // from the native byte ordering of the underlying machine.
36 static inline bool is_Java_byte_ordering_different() {
37 #ifdef VM_LITTLE_ENDIAN
38 return true;
39 #else
40 return false;
41 #endif
42 }
43
44 // Efficient reading and writing of unaligned unsigned data in
45 // platform-specific byte ordering.
143 static inline void put_Java_u2(address p, u2 x) {
144 put_native_u2(p, x);
145 }
146 static inline void put_Java_u4(address p, u4 x) {
147 put_native_u4(p, x);
148 }
149 static inline void put_Java_u8(address p, u8 x) {
150 put_native_u8(p, x);
151 }
152
153 // No byte-order reversal is needed
154 static inline u2 swap_u2(u2 x) { return x; }
155 static inline u4 swap_u4(u4 x) { return x; }
156 static inline u8 swap_u8(u8 x) { return x; }
157 #endif // VM_LITTLE_ENDIAN
158 };
159
160 #ifdef VM_LITTLE_ENDIAN
161 // The following header contains the implementations of swap_u2,
162 // swap_u4, and swap_u8
163 #include "incls/_bytes_pd.inline.hpp.incl"
164 #endif // VM_LITTLE_ENDIAN
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2007, 2008, 2009 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
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 #ifndef CPU_ZERO_VM_BYTES_ZERO_HPP
27 #define CPU_ZERO_VM_BYTES_ZERO_HPP
28
29 #include "memory/allocation.hpp"
30
31 typedef union unaligned {
32 u4 u;
33 u2 us;
34 u8 ul;
35 } __attribute__((packed)) unaligned;
36
37 class Bytes: AllStatic {
38 public:
39 // Returns true if the byte ordering used by Java is different
40 // from the native byte ordering of the underlying machine.
41 static inline bool is_Java_byte_ordering_different() {
42 #ifdef VM_LITTLE_ENDIAN
43 return true;
44 #else
45 return false;
46 #endif
47 }
48
49 // Efficient reading and writing of unaligned unsigned data in
50 // platform-specific byte ordering.
148 static inline void put_Java_u2(address p, u2 x) {
149 put_native_u2(p, x);
150 }
151 static inline void put_Java_u4(address p, u4 x) {
152 put_native_u4(p, x);
153 }
154 static inline void put_Java_u8(address p, u8 x) {
155 put_native_u8(p, x);
156 }
157
158 // No byte-order reversal is needed
159 static inline u2 swap_u2(u2 x) { return x; }
160 static inline u4 swap_u4(u4 x) { return x; }
161 static inline u8 swap_u8(u8 x) { return x; }
162 #endif // VM_LITTLE_ENDIAN
163 };
164
165 #ifdef VM_LITTLE_ENDIAN
166 // The following header contains the implementations of swap_u2,
167 // swap_u4, and swap_u8
168 #ifdef TARGET_OS_ARCH_linux_zero
169 # include "bytes_linux_zero.inline.hpp"
170 #endif
171
172 #endif // VM_LITTLE_ENDIAN
173
174 #endif // CPU_ZERO_VM_BYTES_ZERO_HPP
|