Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit f5a728a

Browse files
committedApr 7, 2020
8238289: Use _byteswap_ functions to implenent Bytes::swap_uX on Windows
Reviewed-by: minqi, dholmes
1 parent edc4ffe commit f5a728a

File tree

1 file changed

+4
-47
lines changed

1 file changed

+4
-47
lines changed
 

‎src/hotspot/os_cpu/windows_x86/bytes_windows_x86.inline.hpp

+4-47
Original file line numberDiff line numberDiff line change
@@ -25,63 +25,20 @@
2525
#ifndef OS_CPU_WINDOWS_X86_BYTES_WINDOWS_X86_INLINE_HPP
2626
#define OS_CPU_WINDOWS_X86_BYTES_WINDOWS_X86_INLINE_HPP
2727

28-
#pragma warning(disable: 4035) // Disable warning 4035: no return value
28+
#include <stdlib.h>
2929

3030
// Efficient swapping of data bytes from Java byte
3131
// ordering to native byte ordering and vice versa.
3232
inline u2 Bytes::swap_u2(u2 x) {
33-
#ifdef AMD64
34-
address p = (address) &x;
35-
return ( (u2(p[0]) << 8 ) | ( u2(p[1])) );
36-
#else
37-
__asm {
38-
mov ax, x
39-
xchg al, ah
40-
}
41-
// no return statement needed, result is already in ax
42-
// compiler warning C4035 disabled via warning pragma
43-
#endif // AMD64
33+
return (u2) _byteswap_ushort((unsigned short) x);
4434
}
4535

4636
inline u4 Bytes::swap_u4(u4 x) {
47-
#ifdef AMD64
48-
address p = (address) &x;
49-
return ( (u4(p[0]) << 24) | (u4(p[1]) << 16) | (u4(p[2]) << 8) | u4(p[3])) ;
50-
#else
51-
__asm {
52-
mov eax, x
53-
bswap eax
54-
}
55-
// no return statement needed, result is already in eax
56-
// compiler warning C4035 disabled via warning pragma
57-
#endif // AMD64
37+
return (u4) _byteswap_ulong((unsigned long) x);
5838
}
5939

60-
#ifdef AMD64
6140
inline u8 Bytes::swap_u8(u8 x) {
62-
address p = (address) &x;
63-
return ( (u8(p[0]) << 56) | (u8(p[1]) << 48) | (u8(p[2]) << 40) | (u8(p[3]) << 32) |
64-
(u8(p[4]) << 24) | (u8(p[5]) << 16) | (u8(p[6]) << 8) | u8(p[7])) ;
41+
return (u8) _byteswap_uint64((unsigned __int64) x);
6542
}
6643

67-
#else
68-
// Helper function for swap_u8
69-
inline u8 Bytes::swap_u8_base(u4 x, u4 y) {
70-
__asm {
71-
mov eax, y
72-
mov edx, x
73-
bswap eax
74-
bswap edx
75-
}
76-
// no return statement needed, result is already in edx:eax
77-
// compiler warning C4035 disabled via warning pragma
78-
}
79-
80-
inline u8 Bytes::swap_u8(u8 x) {
81-
return swap_u8_base(*(u4*)&x, *(((u4*)&x)+1));
82-
}
83-
#endif // AMD64
84-
85-
#pragma warning(default: 4035) // Enable warning 4035: no return value
86-
8744
#endif // OS_CPU_WINDOWS_X86_BYTES_WINDOWS_X86_INLINE_HPP

0 commit comments

Comments
 (0)
This repository has been archived.