Path: blob/master/src/hotspot/os_cpu/bsd_zero/bytes_bsd_zero.hpp
40949 views
/*1* Copyright (c) 2003, 2019, 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_ZERO_BYTES_BSD_ZERO_HPP25#define OS_CPU_BSD_ZERO_BYTES_BSD_ZERO_HPP2627// Efficient swapping of data bytes from Java byte28// ordering to native byte ordering and vice versa.2930#ifdef __APPLE__31# include <libkern/OSByteOrder.h>32#else33# include <sys/endian.h>34#endif3536#if defined(__APPLE__)37# define bswap_16(x) OSSwapInt16(x)38# define bswap_32(x) OSSwapInt32(x)39# define bswap_64(x) OSSwapInt64(x)40#elif defined(__OpenBSD__)41# define bswap_16(x) swap16(x)42# define bswap_32(x) swap32(x)43# define bswap_64(x) swap64(x)44#elif defined(__NetBSD__)45# define bswap_16(x) bswap16(x)46# define bswap_32(x) bswap32(x)47# define bswap_64(x) bswap64(x)48#else49# define bswap_16(x) __bswap16(x)50# define bswap_32(x) __bswap32(x)51# define bswap_64(x) __bswap64(x)52#endif5354inline u2 Bytes::swap_u2(u2 x) {55return bswap_16(x);56}5758inline u4 Bytes::swap_u4(u4 x) {59return bswap_32(x);60}6162inline u8 Bytes::swap_u8(u8 x) {63return bswap_64(x);64}6566#endif // OS_CPU_BSD_ZERO_BYTES_BSD_ZERO_HPP676869