Path: blob/master/src/hotspot/cpu/ppc/bytes_ppc.hpp
40930 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2016 SAP SE. 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_BYTES_PPC_HPP26#define CPU_PPC_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// Forward declarations of the compiler-dependent implementation40static inline u2 swap_u2(u2 x);41static inline u4 swap_u4(u4 x);42static inline u8 swap_u8(u8 x);4344static inline u2 get_native_u2(address p) {45return (intptr_t(p) & 1) == 046? *(u2*)p47: ( u2(p[1]) << 8 )48| ( u2(p[0]) );49}5051static inline u4 get_native_u4(address p) {52switch (intptr_t(p) & 3) {53case 0: return *(u4*)p;5455case 2: return ( u4( ((u2*)p)[1] ) << 16 )56| ( u4( ((u2*)p)[0] ) );5758default: return ( u4(p[3]) << 24 )59| ( u4(p[2]) << 16 )60| ( u4(p[1]) << 8 )61| u4(p[0]);62}63}6465static inline u8 get_native_u8(address p) {66switch (intptr_t(p) & 7) {67case 0: return *(u8*)p;6869case 4: return ( u8( ((u4*)p)[1] ) << 32 )70| ( u8( ((u4*)p)[0] ) );7172case 2: return ( u8( ((u2*)p)[3] ) << 48 )73| ( u8( ((u2*)p)[2] ) << 32 )74| ( u8( ((u2*)p)[1] ) << 16 )75| ( u8( ((u2*)p)[0] ) );7677default: return ( u8(p[7]) << 56 )78| ( u8(p[6]) << 48 )79| ( u8(p[5]) << 40 )80| ( u8(p[4]) << 32 )81| ( u8(p[3]) << 24 )82| ( u8(p[2]) << 16 )83| ( u8(p[1]) << 8 )84| u8(p[0]);85}86}87888990static inline void put_native_u2(address p, u2 x) {91if ( (intptr_t(p) & 1) == 0 ) *(u2*)p = x;92else {93p[1] = x >> 8;94p[0] = x;95}96}9798static inline void put_native_u4(address p, u4 x) {99switch ( intptr_t(p) & 3 ) {100case 0: *(u4*)p = x;101break;102103case 2: ((u2*)p)[1] = x >> 16;104((u2*)p)[0] = x;105break;106107default: ((u1*)p)[3] = x >> 24;108((u1*)p)[2] = x >> 16;109((u1*)p)[1] = x >> 8;110((u1*)p)[0] = x;111break;112}113}114115static inline void put_native_u8(address p, u8 x) {116switch ( intptr_t(p) & 7 ) {117case 0: *(u8*)p = x;118break;119120case 4: ((u4*)p)[1] = x >> 32;121((u4*)p)[0] = x;122break;123124case 2: ((u2*)p)[3] = x >> 48;125((u2*)p)[2] = x >> 32;126((u2*)p)[1] = x >> 16;127((u2*)p)[0] = x;128break;129130default: ((u1*)p)[7] = x >> 56;131((u1*)p)[6] = x >> 48;132((u1*)p)[5] = x >> 40;133((u1*)p)[4] = x >> 32;134((u1*)p)[3] = x >> 24;135((u1*)p)[2] = x >> 16;136((u1*)p)[1] = x >> 8;137((u1*)p)[0] = x;138}139}140141// Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)142// (no byte-order reversal is needed since Power CPUs are big-endian oriented).143static inline u2 get_Java_u2(address p) { return swap_u2(get_native_u2(p)); }144static inline u4 get_Java_u4(address p) { return swap_u4(get_native_u4(p)); }145static inline u8 get_Java_u8(address p) { return swap_u8(get_native_u8(p)); }146147static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, swap_u2(x)); }148static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, swap_u4(x)); }149static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, swap_u8(x)); }150151#else // !defined(VM_LITTLE_ENDIAN)152153// Thus, a swap between native and Java ordering is always a no-op:154static inline u2 swap_u2(u2 x) { return x; }155static inline u4 swap_u4(u4 x) { return x; }156static inline u8 swap_u8(u8 x) { return x; }157158static inline u2 get_native_u2(address p) {159return (intptr_t(p) & 1) == 0160? *(u2*)p161: ( u2(p[0]) << 8 )162| ( u2(p[1]) );163}164165static inline u4 get_native_u4(address p) {166switch (intptr_t(p) & 3) {167case 0: return *(u4*)p;168169case 2: return ( u4( ((u2*)p)[0] ) << 16 )170| ( u4( ((u2*)p)[1] ) );171172default: return ( u4(p[0]) << 24 )173| ( u4(p[1]) << 16 )174| ( u4(p[2]) << 8 )175| u4(p[3]);176}177}178179static inline u8 get_native_u8(address p) {180switch (intptr_t(p) & 7) {181case 0: return *(u8*)p;182183case 4: return ( u8( ((u4*)p)[0] ) << 32 )184| ( u8( ((u4*)p)[1] ) );185186case 2: return ( u8( ((u2*)p)[0] ) << 48 )187| ( u8( ((u2*)p)[1] ) << 32 )188| ( u8( ((u2*)p)[2] ) << 16 )189| ( u8( ((u2*)p)[3] ) );190191default: return ( u8(p[0]) << 56 )192| ( u8(p[1]) << 48 )193| ( u8(p[2]) << 40 )194| ( u8(p[3]) << 32 )195| ( u8(p[4]) << 24 )196| ( u8(p[5]) << 16 )197| ( u8(p[6]) << 8 )198| u8(p[7]);199}200}201202203204static inline void put_native_u2(address p, u2 x) {205if ( (intptr_t(p) & 1) == 0 ) { *(u2*)p = x; }206else {207p[0] = x >> 8;208p[1] = x;209}210}211212static inline void put_native_u4(address p, u4 x) {213switch ( intptr_t(p) & 3 ) {214case 0: *(u4*)p = x;215break;216217case 2: ((u2*)p)[0] = x >> 16;218((u2*)p)[1] = x;219break;220221default: ((u1*)p)[0] = x >> 24;222((u1*)p)[1] = x >> 16;223((u1*)p)[2] = x >> 8;224((u1*)p)[3] = x;225break;226}227}228229static inline void put_native_u8(address p, u8 x) {230switch ( intptr_t(p) & 7 ) {231case 0: *(u8*)p = x;232break;233234case 4: ((u4*)p)[0] = x >> 32;235((u4*)p)[1] = x;236break;237238case 2: ((u2*)p)[0] = x >> 48;239((u2*)p)[1] = x >> 32;240((u2*)p)[2] = x >> 16;241((u2*)p)[3] = x;242break;243244default: ((u1*)p)[0] = x >> 56;245((u1*)p)[1] = x >> 48;246((u1*)p)[2] = x >> 40;247((u1*)p)[3] = x >> 32;248((u1*)p)[4] = x >> 24;249((u1*)p)[5] = x >> 16;250((u1*)p)[6] = x >> 8;251((u1*)p)[7] = x;252}253}254255// Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)256// (no byte-order reversal is needed since Power CPUs are big-endian oriented).257static inline u2 get_Java_u2(address p) { return get_native_u2(p); }258static inline u4 get_Java_u4(address p) { return get_native_u4(p); }259static inline u8 get_Java_u8(address p) { return get_native_u8(p); }260261static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, x); }262static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, x); }263static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, x); }264265#endif // VM_LITTLE_ENDIAN266};267268#include OS_CPU_HEADER(bytes)269270#endif // CPU_PPC_BYTES_PPC_HPP271272273