1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os_cpu/windows_x86/vm/bytes_windows_x86.inline.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,87 @@ 1.4 +/* 1.5 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef OS_CPU_WINDOWS_X86_VM_BYTES_WINDOWS_X86_INLINE_HPP 1.29 +#define OS_CPU_WINDOWS_X86_VM_BYTES_WINDOWS_X86_INLINE_HPP 1.30 + 1.31 +#pragma warning(disable: 4035) // Disable warning 4035: no return value 1.32 + 1.33 +// Efficient swapping of data bytes from Java byte 1.34 +// ordering to native byte ordering and vice versa. 1.35 +inline u2 Bytes::swap_u2(u2 x) { 1.36 +#ifdef AMD64 1.37 + address p = (address) &x; 1.38 + return ( (u2(p[0]) << 8 ) | ( u2(p[1])) ); 1.39 +#else 1.40 + __asm { 1.41 + mov ax, x 1.42 + xchg al, ah 1.43 + } 1.44 + // no return statement needed, result is already in ax 1.45 + // compiler warning C4035 disabled via warning pragma 1.46 +#endif // AMD64 1.47 +} 1.48 + 1.49 +inline u4 Bytes::swap_u4(u4 x) { 1.50 +#ifdef AMD64 1.51 + address p = (address) &x; 1.52 + return ( (u4(p[0]) << 24) | (u4(p[1]) << 16) | (u4(p[2]) << 8) | u4(p[3])) ; 1.53 +#else 1.54 + __asm { 1.55 + mov eax, x 1.56 + bswap eax 1.57 + } 1.58 + // no return statement needed, result is already in eax 1.59 + // compiler warning C4035 disabled via warning pragma 1.60 +#endif // AMD64 1.61 +} 1.62 + 1.63 +#ifdef AMD64 1.64 +inline u8 Bytes::swap_u8(u8 x) { 1.65 + address p = (address) &x; 1.66 + return ( (u8(p[0]) << 56) | (u8(p[1]) << 48) | (u8(p[2]) << 40) | (u8(p[3]) << 32) | 1.67 + (u8(p[4]) << 24) | (u8(p[5]) << 16) | (u8(p[6]) << 8) | u8(p[7])) ; 1.68 +} 1.69 + 1.70 +#else 1.71 +// Helper function for swap_u8 1.72 +inline u8 Bytes::swap_u8_base(u4 x, u4 y) { 1.73 + __asm { 1.74 + mov eax, y 1.75 + mov edx, x 1.76 + bswap eax 1.77 + bswap edx 1.78 + } 1.79 + // no return statement needed, result is already in edx:eax 1.80 + // compiler warning C4035 disabled via warning pragma 1.81 +} 1.82 + 1.83 +inline u8 Bytes::swap_u8(u8 x) { 1.84 + return swap_u8_base(*(u4*)&x, *(((u4*)&x)+1)); 1.85 +} 1.86 +#endif // AMD64 1.87 + 1.88 +#pragma warning(default: 4035) // Enable warning 4035: no return value 1.89 + 1.90 +#endif // OS_CPU_WINDOWS_X86_VM_BYTES_WINDOWS_X86_INLINE_HPP