Path: blob/master/src/hotspot/cpu/zero/bytes_zero.hpp
40931 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright 2007, 2008, 2009 Red Hat, Inc.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_ZERO_BYTES_ZERO_HPP26#define CPU_ZERO_BYTES_ZERO_HPP2728#include "memory/allocation.hpp"2930typedef union unaligned {31u4 u;32u2 us;33u8 ul;34} __attribute__((packed)) unaligned;3536class Bytes: AllStatic {37public:38// Efficient reading and writing of unaligned unsigned data in39// platform-specific byte ordering.40static inline u2 get_native_u2(address p){41unaligned *up = (unaligned *) p;42return up->us;43}4445static inline u4 get_native_u4(address p) {46unaligned *up = (unaligned *) p;47return up->u;48}4950static inline u8 get_native_u8(address p) {51unaligned *up = (unaligned *) p;52return up->ul;53}5455static inline void put_native_u2(address p, u2 x) {56unaligned *up = (unaligned *) p;57up->us = x;58}5960static inline void put_native_u4(address p, u4 x) {61unaligned *up = (unaligned *) p;62up->u = x;63}6465static inline void put_native_u8(address p, u8 x) {66unaligned *up = (unaligned *) p;67up->ul = x;68}6970// Efficient reading and writing of unaligned unsigned data in Java71// byte ordering (i.e. big-endian ordering).72#ifdef VM_LITTLE_ENDIAN73// Byte-order reversal is needed74static inline u2 get_Java_u2(address p) {75return (u2(p[0]) << 8) |76(u2(p[1]) );77}78static inline u4 get_Java_u4(address p) {79return (u4(p[0]) << 24) |80(u4(p[1]) << 16) |81(u4(p[2]) << 8) |82(u4(p[3]) );83}84static inline u8 get_Java_u8(address p) {85u4 hi, lo;86hi = (u4(p[0]) << 24) |87(u4(p[1]) << 16) |88(u4(p[2]) << 8) |89(u4(p[3]) );90lo = (u4(p[4]) << 24) |91(u4(p[5]) << 16) |92(u4(p[6]) << 8) |93(u4(p[7]) );94return u8(lo) | (u8(hi) << 32);95}9697static inline void put_Java_u2(address p, u2 x) {98p[0] = x >> 8;99p[1] = x;100}101static inline void put_Java_u4(address p, u4 x) {102p[0] = x >> 24;103p[1] = x >> 16;104p[2] = x >> 8;105p[3] = x;106}107static inline void put_Java_u8(address p, u8 x) {108u4 hi, lo;109lo = x;110hi = x >> 32;111p[0] = hi >> 24;112p[1] = hi >> 16;113p[2] = hi >> 8;114p[3] = hi;115p[4] = lo >> 24;116p[5] = lo >> 16;117p[6] = lo >> 8;118p[7] = lo;119}120121// Efficient swapping of byte ordering122static inline u2 swap_u2(u2 x);123static inline u4 swap_u4(u4 x);124static inline u8 swap_u8(u8 x);125#else126// No byte-order reversal is needed127static inline u2 get_Java_u2(address p) {128return get_native_u2(p);129}130static inline u4 get_Java_u4(address p) {131return get_native_u4(p);132}133static inline u8 get_Java_u8(address p) {134return get_native_u8(p);135}136137static inline void put_Java_u2(address p, u2 x) {138put_native_u2(p, x);139}140static inline void put_Java_u4(address p, u4 x) {141put_native_u4(p, x);142}143static inline void put_Java_u8(address p, u8 x) {144put_native_u8(p, x);145}146147// No byte-order reversal is needed148static inline u2 swap_u2(u2 x) { return x; }149static inline u4 swap_u4(u4 x) { return x; }150static inline u8 swap_u8(u8 x) { return x; }151#endif // VM_LITTLE_ENDIAN152};153154#ifdef VM_LITTLE_ENDIAN155// The following header contains the implementations of swap_u2,156// swap_u4, and swap_u8157158#include OS_CPU_HEADER(bytes)159160#endif // VM_LITTLE_ENDIAN161162#endif // CPU_ZERO_BYTES_ZERO_HPP163164165