Path: blob/master/src/hotspot/os_cpu/bsd_x86/bytes_bsd_x86.hpp
40930 views
/*1* Copyright (c) 1999, 2020, 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 OS_CPU_BSD_X86_BYTES_BSD_X86_HPP25#define OS_CPU_BSD_X86_BYTES_BSD_X86_HPP2627#ifdef __APPLE__28#include <libkern/OSByteOrder.h>29#endif3031#if defined(AMD64)32# if defined(__APPLE__)33# define bswap_16(x) OSSwapInt16(x)34# define bswap_32(x) OSSwapInt32(x)35# define bswap_64(x) OSSwapInt64(x)36# elif defined(__OpenBSD__)37# define bswap_16(x) swap16(x)38# define bswap_32(x) swap32(x)39# define bswap_64(x) swap64(x)40# elif defined(__NetBSD__)41# define bswap_16(x) bswap16(x)42# define bswap_32(x) bswap32(x)43# define bswap_64(x) bswap64(x)44# else45# define bswap_16(x) __bswap16(x)46# define bswap_32(x) __bswap32(x)47# define bswap_64(x) __bswap64(x)48# endif49#endif5051// Efficient swapping of data bytes from Java byte52// ordering to native byte ordering and vice versa.53inline u2 Bytes::swap_u2(u2 x) {54#ifdef AMD6455return bswap_16(x);56#else57u2 ret;58__asm__ __volatile__ (59"movw %0, %%ax;"60"xchg %%al, %%ah;"61"movw %%ax, %0"62:"=r" (ret) // output : register 0 => ret63:"0" (x) // input : x => register 064:"ax", "0" // clobbered registers65);66return ret;67#endif // AMD6468}6970inline u4 Bytes::swap_u4(u4 x) {71#ifdef AMD6472return bswap_32(x);73#else74u4 ret;75__asm__ __volatile__ (76"bswap %0"77:"=r" (ret) // output : register 0 => ret78:"0" (x) // input : x => register 079:"0" // clobbered register80);81return ret;82#endif // AMD6483}8485#ifdef AMD6486inline u8 Bytes::swap_u8(u8 x) {87return bswap_64(x);88}89#else90// Helper function for swap_u891inline u8 Bytes::swap_u8_base(u4 x, u4 y) {92return (((u8)swap_u4(x))<<32) | swap_u4(y);93}9495inline u8 Bytes::swap_u8(u8 x) {96return swap_u8_base(*(u4*)&x, *(((u4*)&x)+1));97}98#endif // !AMD6499100#endif // OS_CPU_BSD_X86_BYTES_BSD_X86_HPP101102103