Path: blob/master/src/hotspot/cpu/arm/bytes_arm.hpp
40930 views
/*1* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.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 it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef CPU_ARM_BYTES_ARM_HPP25#define CPU_ARM_BYTES_ARM_HPP2627#include "memory/allocation.hpp"28#include "utilities/macros.hpp"2930#ifndef VM_LITTLE_ENDIAN31#define VM_LITTLE_ENDIAN 132#endif3334class Bytes: AllStatic {3536public:37static inline u2 get_Java_u2(address p) {38return (u2(p[0]) << 8) | u2(p[1]);39}4041static inline u4 get_Java_u4(address p) {42return u4(p[0]) << 24 |43u4(p[1]) << 16 |44u4(p[2]) << 8 |45u4(p[3]);46}4748static inline u8 get_Java_u8(address p) {49return u8(p[0]) << 56 |50u8(p[1]) << 48 |51u8(p[2]) << 40 |52u8(p[3]) << 32 |53u8(p[4]) << 24 |54u8(p[5]) << 16 |55u8(p[6]) << 8 |56u8(p[7]);57}5859static inline void put_Java_u2(address p, u2 x) {60p[0] = x >> 8;61p[1] = x;62}6364static inline void put_Java_u4(address p, u4 x) {65((u1*)p)[0] = x >> 24;66((u1*)p)[1] = x >> 16;67((u1*)p)[2] = x >> 8;68((u1*)p)[3] = x;69}7071static inline void put_Java_u8(address p, u8 x) {72((u1*)p)[0] = x >> 56;73((u1*)p)[1] = x >> 48;74((u1*)p)[2] = x >> 40;75((u1*)p)[3] = x >> 32;76((u1*)p)[4] = x >> 24;77((u1*)p)[5] = x >> 16;78((u1*)p)[6] = x >> 8;79((u1*)p)[7] = x;80}8182#ifdef VM_LITTLE_ENDIAN8384static inline u2 get_native_u2(address p) {85return (intptr_t(p) & 1) == 0 ? *(u2*)p : u2(p[0]) | (u2(p[1]) << 8);86}8788static inline u4 get_native_u4(address p) {89switch (intptr_t(p) & 3) {90case 0: return *(u4*)p;91case 2: return u4(((u2*)p)[0]) |92u4(((u2*)p)[1]) << 16;93default: return u4(p[0]) |94u4(p[1]) << 8 |95u4(p[2]) << 16 |96u4(p[3]) << 24;97}98}99100static inline u8 get_native_u8(address p) {101switch (intptr_t(p) & 7) {102case 0: return *(u8*)p;103case 4: return u8(((u4*)p)[0]) |104u8(((u4*)p)[1]) << 32;105case 2: return u8(((u2*)p)[0]) |106u8(((u2*)p)[1]) << 16 |107u8(((u2*)p)[2]) << 32 |108u8(((u2*)p)[3]) << 48;109default: return u8(p[0]) |110u8(p[1]) << 8 |111u8(p[2]) << 16 |112u8(p[3]) << 24 |113u8(p[4]) << 32 |114u8(p[5]) << 40 |115u8(p[6]) << 48 |116u8(p[7]) << 56;117}118}119120static inline void put_native_u2(address p, u2 x) {121if ((intptr_t(p) & 1) == 0) {122*(u2*)p = x;123} else {124p[0] = x;125p[1] = x >> 8;126}127}128129static inline void put_native_u4(address p, u4 x) {130switch (intptr_t(p) & 3) {131case 0: *(u4*)p = x;132break;133case 2: ((u2*)p)[0] = x;134((u2*)p)[1] = x >> 16;135break;136default: ((u1*)p)[0] = x;137((u1*)p)[1] = x >> 8;138((u1*)p)[2] = x >> 16;139((u1*)p)[3] = x >> 24;140break;141}142}143144static inline void put_native_u8(address p, u8 x) {145switch (intptr_t(p) & 7) {146case 0: *(u8*)p = x;147break;148case 4: ((u4*)p)[0] = x;149((u4*)p)[1] = x >> 32;150break;151case 2: ((u2*)p)[0] = x;152((u2*)p)[1] = x >> 16;153((u2*)p)[2] = x >> 32;154((u2*)p)[3] = x >> 48;155break;156default: ((u1*)p)[0] = x;157((u1*)p)[1] = x >> 8;158((u1*)p)[2] = x >> 16;159((u1*)p)[3] = x >> 24;160((u1*)p)[4] = x >> 32;161((u1*)p)[5] = x >> 40;162((u1*)p)[6] = x >> 48;163((u1*)p)[7] = x >> 56;164}165}166167#else168169static inline u2 get_native_u2(address p) { return get_Java_u2(p); }170static inline u4 get_native_u4(address p) { return get_Java_u4(p); }171static inline u8 get_native_u8(address p) { return get_Java_u8(p); }172static inline void put_native_u2(address p, u2 x) { put_Java_u2(p, x); }173static inline void put_native_u4(address p, u4 x) { put_Java_u4(p, x); }174static inline void put_native_u8(address p, u8 x) { put_Java_u8(p, x); }175176#endif // VM_LITTLE_ENDIAN177178// Efficient swapping of byte ordering179static inline u2 swap_u2(u2 x);180static inline u4 swap_u4(u4 x);181static inline u8 swap_u8(u8 x);182};183184185// The following header contains the implementations of swap_u2, swap_u4, and swap_u8186#include OS_CPU_HEADER(bytes)187188#endif // CPU_ARM_BYTES_ARM_HPP189190191