Skip to content

Commit

Permalink
8319577: x86_64 AVX2 intrinsics for Arrays.sort methods (int, float a…
Browse files Browse the repository at this point in the history
…rrays)

Reviewed-by: sviswanathan, ihse, jbhateja, kvn
  • Loading branch information
vamsi-parasa authored and Sandhya Viswanathan committed Dec 8, 2023
1 parent 5c12a18 commit ce10844
Show file tree
Hide file tree
Showing 24 changed files with 2,466 additions and 1,715 deletions.
2 changes: 1 addition & 1 deletion make/modules/java.base/Lib.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ ifeq ($(call isTargetOs, linux)+$(call isTargetCpu, x86_64)+$(INCLUDE_COMPILER2)
TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
OPTIMIZATION := HIGH, \
CFLAGS := $(CFLAGS_JDKLIB), \
CXXFLAGS := $(CXXFLAGS_JDKLIB), \
CXXFLAGS := $(CXXFLAGS_JDKLIB) -std=c++17, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
LIBS := $(LIBCXX), \
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/cpu/aarch64/matcher_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,9 @@
}
}

// Is SIMD sort supported for this CPU?
static bool supports_simd_sort(BasicType bt) {
return false;
}

#endif // CPU_AARCH64_MATCHER_AARCH64_HPP
5 changes: 5 additions & 0 deletions src/hotspot/cpu/arm/matcher_arm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,9 @@
}
}

// Is SIMD sort supported for this CPU?
static bool supports_simd_sort(BasicType bt) {
return false;
}

#endif // CPU_ARM_MATCHER_ARM_HPP
5 changes: 5 additions & 0 deletions src/hotspot/cpu/ppc/matcher_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,9 @@
}
}

// Is SIMD sort supported for this CPU?
static bool supports_simd_sort(BasicType bt) {
return false;
}

#endif // CPU_PPC_MATCHER_PPC_HPP
5 changes: 5 additions & 0 deletions src/hotspot/cpu/riscv/matcher_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,9 @@
}
}

// Is SIMD sort supported for this CPU?
static bool supports_simd_sort(BasicType bt) {
return false;
}

#endif // CPU_RISCV_MATCHER_RISCV_HPP
5 changes: 5 additions & 0 deletions src/hotspot/cpu/s390/matcher_s390.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,9 @@
}
}

// Is SIMD sort supported for this CPU?
static bool supports_simd_sort(BasicType bt) {
return false;
}

#endif // CPU_S390_MATCHER_S390_HPP
13 changes: 13 additions & 0 deletions src/hotspot/cpu/x86/matcher_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,17 @@
}
}

// Is SIMD sort supported for this CPU?
static bool supports_simd_sort(BasicType bt) {
if (VM_Version::supports_avx512dq()) {
return true;
}
else if (VM_Version::supports_avx2() && !is_double_word_type(bt)) {
return true;
}
else {
return false;
}
}

#endif // CPU_X86_MATCHER_X86_HPP
11 changes: 6 additions & 5 deletions src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4193,22 +4193,23 @@ void StubGenerator::generate_compiler_stubs() {
= CAST_FROM_FN_PTR(address, SharedRuntime::montgomery_square);
}

// Load x86_64_sort library on supported hardware to enable avx512 sort and partition intrinsics
if (VM_Version::is_intel() && VM_Version::supports_avx512dq()) {
// Load x86_64_sort library on supported hardware to enable SIMD sort and partition intrinsics

if (VM_Version::is_intel() && (VM_Version::supports_avx512dq() || VM_Version::supports_avx2())) {
void *libsimdsort = nullptr;
char ebuf_[1024];
char dll_name_simd_sort[JVM_MAXPATHLEN];
if (os::dll_locate_lib(dll_name_simd_sort, sizeof(dll_name_simd_sort), Arguments::get_dll_dir(), "simdsort")) {
libsimdsort = os::dll_load(dll_name_simd_sort, ebuf_, sizeof ebuf_);
}
// Get addresses for avx512 sort and partition routines
// Get addresses for SIMD sort and partition routines
if (libsimdsort != nullptr) {
log_info(library)("Loaded library %s, handle " INTPTR_FORMAT, JNI_LIB_PREFIX "simdsort" JNI_LIB_SUFFIX, p2i(libsimdsort));

snprintf(ebuf_, sizeof(ebuf_), "avx512_sort");
snprintf(ebuf_, sizeof(ebuf_), VM_Version::supports_avx512dq() ? "avx512_sort" : "avx2_sort");
StubRoutines::_array_sort = (address)os::dll_lookup(libsimdsort, ebuf_);

snprintf(ebuf_, sizeof(ebuf_), "avx512_partition");
snprintf(ebuf_, sizeof(ebuf_), VM_Version::supports_avx512dq() ? "avx512_partition" : "avx2_partition");
StubRoutines::_array_partition = (address)os::dll_lookup(libsimdsort, ebuf_);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/vm_version_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ void VM_Version::get_processor_features() {

// Check if processor has Intel Ecore
if (FLAG_IS_DEFAULT(EnableX86ECoreOpts) && is_intel() && cpu_family() == 6 &&
(_model == 0x97 || _model == 0xAC || _model == 0xAF)) {
(_model == 0x97 || _model == 0xAA || _model == 0xAC || _model == 0xAF)) {
FLAG_SET_DEFAULT(EnableX86ECoreOpts, true);
}

Expand Down
8 changes: 8 additions & 0 deletions src/hotspot/share/opto/library_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5387,6 +5387,10 @@ bool LibraryCallKit::inline_array_partition() {
const TypeInstPtr* elem_klass = gvn().type(elementType)->isa_instptr();
ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type();
BasicType bt = elem_type->basic_type();
// Disable the intrinsic if the CPU does not support SIMD sort
if (!Matcher::supports_simd_sort(bt)) {
return false;
}
address stubAddr = nullptr;
stubAddr = StubRoutines::select_array_partition_function();
// stub not loaded
Expand Down Expand Up @@ -5440,6 +5444,10 @@ bool LibraryCallKit::inline_array_sort() {
const TypeInstPtr* elem_klass = gvn().type(elementType)->isa_instptr();
ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type();
BasicType bt = elem_type->basic_type();
// Disable the intrinsic if the CPU does not support SIMD sort
if (!Matcher::supports_simd_sort(bt)) {
return false;
}
address stubAddr = nullptr;
stubAddr = StubRoutines::select_arraysort_function();
//stub not loaded
Expand Down
Loading

0 comments on commit ce10844

Please sign in to comment.