Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/LESwaps.h
38825 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.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*/242526/*27*28* (C) Copyright IBM Corp. 1998-2010 - All Rights Reserved29*30*/3132#ifndef __LESWAPS_H33#define __LESWAPS_H3435#include "LETypes.h"3637/**38* \file39* \brief C++ API: Endian independent access to data for LayoutEngine40*/4142U_NAMESPACE_BEGIN4344/**45* A convenience macro which invokes the swapWord member function46* from a concise call.47*48* @stable ICU 2.849*/50#if defined(U_IS_BIG_ENDIAN)51#if U_IS_BIG_ENDIAN52#define SWAPW(value) (value)53#else54#define SWAPW(value) LESwaps::swapWord(value)55#endif56#else57#define SWAPW(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapWord(value))58#endif5960/**61* A convenience macro which invokes the swapLong member function62* from a concise call.63*64* @stable ICU 2.865*/66#if defined(U_IS_BIG_ENDIAN)67#if U_IS_BIG_ENDIAN68#define SWAPL(value) (value)69#else70#define SWAPL(value) LESwaps::swapLong(value)71#endif72#else73#define SWAPL(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapLong(value))74#endif7576/**77* This class is used to access data which stored in big endian order78* regardless of the conventions of the platform. It has been designed79* to automatically detect the endian-ness of the platform, so that a80* compilation flag is not needed.81*82* All methods are static and inline in an attempt to induce the compiler83* to do most of the calculations at compile time.84*85* @stable ICU 2.886*/87class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {88public:8990#if !defined(U_IS_BIG_ENDIAN)91/**92* This method detects the endian-ness of the platform by93* casting a pointer to a word to a pointer to a byte. On94* big endian platforms the FF will be in the byte with the95* lowest address. On little endian platforms, the FF will96* be in the byte with the highest address.97*98* @return TRUE if the platform is big endian99*100* @stable ICU 2.8101*/102static le_uint8 isBigEndian()103{104const le_uint16 word = 0xFF00;105106return *((le_uint8 *) &word);107};108#endif109110/**111* This method does the byte swap required on little endian platforms112* to correctly access a (16-bit) word.113*114* @param value - the word to be byte swapped115*116* @return the byte swapped word117*118* @stable ICU 2.8119*/120static le_uint16 swapWord(le_uint16 value)121{122return (((le_uint8) (value >> 8)) | (value << 8));123};124125/**126* This method does the byte swapping required on little endian platforms127* to correctly access a (32-bit) long.128*129* @param value - the long to be byte swapped130*131* @return the byte swapped long132*133* @stable ICU 2.8134*/135static le_uint32 swapLong(le_uint32 value)136{137return swapWord((le_uint16) (value >> 16)) | (swapWord((le_uint16) value) << 16);138};139140private:141LESwaps() {} // private - forbid instantiation142};143144U_NAMESPACE_END145#endif146147148