Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/ppc/vm/bytes_ppc.hpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* Copyright 2012, 2013 SAP AG. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#ifndef CPU_PPC_VM_BYTES_PPC_HPP26#define CPU_PPC_VM_BYTES_PPC_HPP2728#include "memory/allocation.hpp"2930class Bytes: AllStatic {31public:32// Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering33// PowerPC needs to check for alignment.3435// Can I count on address always being a pointer to an unsigned char? Yes.3637#if defined(VM_LITTLE_ENDIAN)3839// Returns true, if the byte ordering used by Java is different from the native byte ordering40// of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc.41static inline bool is_Java_byte_ordering_different() { return true; }4243// Forward declarations of the compiler-dependent implementation44static inline u2 swap_u2(u2 x);45static inline u4 swap_u4(u4 x);46static inline u8 swap_u8(u8 x);4748static inline u2 get_native_u2(address p) {49return (intptr_t(p) & 1) == 050? *(u2*)p51: ( u2(p[1]) << 8 )52| ( u2(p[0]) );53}5455static inline u4 get_native_u4(address p) {56switch (intptr_t(p) & 3) {57case 0: return *(u4*)p;5859case 2: return ( u4( ((u2*)p)[1] ) << 16 )60| ( u4( ((u2*)p)[0] ) );6162default: return ( u4(p[3]) << 24 )63| ( u4(p[2]) << 16 )64| ( u4(p[1]) << 8 )65| u4(p[0]);66}67}6869static inline u8 get_native_u8(address p) {70switch (intptr_t(p) & 7) {71case 0: return *(u8*)p;7273case 4: return ( u8( ((u4*)p)[1] ) << 32 )74| ( u8( ((u4*)p)[0] ) );7576case 2: return ( u8( ((u2*)p)[3] ) << 48 )77| ( u8( ((u2*)p)[2] ) << 32 )78| ( u8( ((u2*)p)[1] ) << 16 )79| ( u8( ((u2*)p)[0] ) );8081default: return ( u8(p[7]) << 56 )82| ( u8(p[6]) << 48 )83| ( u8(p[5]) << 40 )84| ( u8(p[4]) << 32 )85| ( u8(p[3]) << 24 )86| ( u8(p[2]) << 16 )87| ( u8(p[1]) << 8 )88| u8(p[0]);89}90}91929394static inline void put_native_u2(address p, u2 x) {95if ( (intptr_t(p) & 1) == 0 ) *(u2*)p = x;96else {97p[1] = x >> 8;98p[0] = x;99}100}101102static inline void put_native_u4(address p, u4 x) {103switch ( intptr_t(p) & 3 ) {104case 0: *(u4*)p = x;105break;106107case 2: ((u2*)p)[1] = x >> 16;108((u2*)p)[0] = x;109break;110111default: ((u1*)p)[3] = x >> 24;112((u1*)p)[2] = x >> 16;113((u1*)p)[1] = x >> 8;114((u1*)p)[0] = x;115break;116}117}118119static inline void put_native_u8(address p, u8 x) {120switch ( intptr_t(p) & 7 ) {121case 0: *(u8*)p = x;122break;123124case 4: ((u4*)p)[1] = x >> 32;125((u4*)p)[0] = x;126break;127128case 2: ((u2*)p)[3] = x >> 48;129((u2*)p)[2] = x >> 32;130((u2*)p)[1] = x >> 16;131((u2*)p)[0] = x;132break;133134default: ((u1*)p)[7] = x >> 56;135((u1*)p)[6] = x >> 48;136((u1*)p)[5] = x >> 40;137((u1*)p)[4] = x >> 32;138((u1*)p)[3] = x >> 24;139((u1*)p)[2] = x >> 16;140((u1*)p)[1] = x >> 8;141((u1*)p)[0] = x;142}143}144145// Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)146// (no byte-order reversal is needed since Power CPUs are big-endian oriented).147static inline u2 get_Java_u2(address p) { return swap_u2(get_native_u2(p)); }148static inline u4 get_Java_u4(address p) { return swap_u4(get_native_u4(p)); }149static inline u8 get_Java_u8(address p) { return swap_u8(get_native_u8(p)); }150151static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, swap_u2(x)); }152static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, swap_u4(x)); }153static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, swap_u8(x)); }154155#else // !defined(VM_LITTLE_ENDIAN)156157// Returns true, if the byte ordering used by Java is different from the nativ byte ordering158// of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc.159static inline bool is_Java_byte_ordering_different() { return false; }160161// Thus, a swap between native and Java ordering is always a no-op:162static inline u2 swap_u2(u2 x) { return x; }163static inline u4 swap_u4(u4 x) { return x; }164static inline u8 swap_u8(u8 x) { return x; }165166static inline u2 get_native_u2(address p) {167return (intptr_t(p) & 1) == 0168? *(u2*)p169: ( u2(p[0]) << 8 )170| ( u2(p[1]) );171}172173static inline u4 get_native_u4(address p) {174switch (intptr_t(p) & 3) {175case 0: return *(u4*)p;176177case 2: return ( u4( ((u2*)p)[0] ) << 16 )178| ( u4( ((u2*)p)[1] ) );179180default: return ( u4(p[0]) << 24 )181| ( u4(p[1]) << 16 )182| ( u4(p[2]) << 8 )183| u4(p[3]);184}185}186187static inline u8 get_native_u8(address p) {188switch (intptr_t(p) & 7) {189case 0: return *(u8*)p;190191case 4: return ( u8( ((u4*)p)[0] ) << 32 )192| ( u8( ((u4*)p)[1] ) );193194case 2: return ( u8( ((u2*)p)[0] ) << 48 )195| ( u8( ((u2*)p)[1] ) << 32 )196| ( u8( ((u2*)p)[2] ) << 16 )197| ( u8( ((u2*)p)[3] ) );198199default: return ( u8(p[0]) << 56 )200| ( u8(p[1]) << 48 )201| ( u8(p[2]) << 40 )202| ( u8(p[3]) << 32 )203| ( u8(p[4]) << 24 )204| ( u8(p[5]) << 16 )205| ( u8(p[6]) << 8 )206| u8(p[7]);207}208}209210211212static inline void put_native_u2(address p, u2 x) {213if ( (intptr_t(p) & 1) == 0 ) { *(u2*)p = x; }214else {215p[0] = x >> 8;216p[1] = x;217}218}219220static inline void put_native_u4(address p, u4 x) {221switch ( intptr_t(p) & 3 ) {222case 0: *(u4*)p = x;223break;224225case 2: ((u2*)p)[0] = x >> 16;226((u2*)p)[1] = x;227break;228229default: ((u1*)p)[0] = x >> 24;230((u1*)p)[1] = x >> 16;231((u1*)p)[2] = x >> 8;232((u1*)p)[3] = x;233break;234}235}236237static inline void put_native_u8(address p, u8 x) {238switch ( intptr_t(p) & 7 ) {239case 0: *(u8*)p = x;240break;241242case 4: ((u4*)p)[0] = x >> 32;243((u4*)p)[1] = x;244break;245246case 2: ((u2*)p)[0] = x >> 48;247((u2*)p)[1] = x >> 32;248((u2*)p)[2] = x >> 16;249((u2*)p)[3] = x;250break;251252default: ((u1*)p)[0] = x >> 56;253((u1*)p)[1] = x >> 48;254((u1*)p)[2] = x >> 40;255((u1*)p)[3] = x >> 32;256((u1*)p)[4] = x >> 24;257((u1*)p)[5] = x >> 16;258((u1*)p)[6] = x >> 8;259((u1*)p)[7] = x;260}261}262263// Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)264// (no byte-order reversal is needed since Power CPUs are big-endian oriented).265static inline u2 get_Java_u2(address p) { return get_native_u2(p); }266static inline u4 get_Java_u4(address p) { return get_native_u4(p); }267static inline u8 get_Java_u8(address p) { return get_native_u8(p); }268269static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, x); }270static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, x); }271static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, x); }272273#endif // VM_LITTLE_ENDIAN274};275276#if defined(TARGET_OS_ARCH_linux_ppc)277#include "bytes_linux_ppc.inline.hpp"278#endif279280#endif // CPU_PPC_VM_BYTES_PPC_HPP281282283