mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 08:59:23 +00:00
- Use modern API which introduced since Java 10 to get java major version - Remove useless fields in SIMD util, Java 21+ supports SIMD.
127 lines
3.9 KiB
Diff
127 lines
3.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Thu, 24 Nov 2022 01:21:32 +0100
|
|
Subject: [PATCH] SIMD support
|
|
|
|
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
This patch is based on the following patch:
|
|
"Add SIMD utilities"
|
|
By: Kevin Raneri <kevin.raneri@gmail.com>
|
|
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..8d614483b8011d47e88ace3da28e072d1febaef7
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
|
|
@@ -0,0 +1,41 @@
|
|
+// Gale - Pufferfish - SIMD support
|
|
+
|
|
+package gg.pufferfish.pufferfish.simd;
|
|
+
|
|
+import jdk.incubator.vector.FloatVector;
|
|
+import jdk.incubator.vector.IntVector;
|
|
+import jdk.incubator.vector.VectorSpecies;
|
|
+
|
|
+/**
|
|
+ * Basically, java is annoying and we have to push this out to its own class.
|
|
+ */
|
|
+@Deprecated
|
|
+public class SIMDChecker {
|
|
+
|
|
+ public static void initialize() {
|
|
+ if (SIMDDetection.isInitialized()) {
|
|
+ return;
|
|
+ }
|
|
+ SIMDDetection.setInitialized();
|
|
+ try {
|
|
+ VectorSpecies<Integer> ISPEC = IntVector.SPECIES_PREFERRED;
|
|
+ VectorSpecies<Float> FSPEC = FloatVector.SPECIES_PREFERRED;
|
|
+
|
|
+ SIMDDetection.intVectorBitSize = ISPEC.vectorBitSize();
|
|
+ SIMDDetection.floatVectorBitSize = FSPEC.vectorBitSize();
|
|
+
|
|
+ SIMDDetection.intElementSize = ISPEC.elementSize();
|
|
+ SIMDDetection.floatElementSize = FSPEC.elementSize();
|
|
+
|
|
+ SIMDDetection.testRunCompleted = true;
|
|
+
|
|
+ if (ISPEC.elementSize() < 2 || FSPEC.elementSize() < 2) {
|
|
+ SIMDDetection.unsupportingLaneSize = true;
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ SIMDDetection.isEnabled = true;
|
|
+ } catch (Throwable ignored) {} // Basically, we don't do anything. This lets us detect if it's not functional and disable it.
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..df3ef7bface99072b5bfbcdc5bf653a01a9c798c
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
|
|
@@ -0,0 +1,59 @@
|
|
+// Gale - Pufferfish - SIMD support
|
|
+
|
|
+package gg.pufferfish.pufferfish.simd;
|
|
+
|
|
+public class SIMDDetection {
|
|
+
|
|
+ private static boolean isInitialized = false;
|
|
+ static int intVectorBitSize;
|
|
+ static int floatVectorBitSize;
|
|
+ static int intElementSize;
|
|
+ static int floatElementSize;
|
|
+ static boolean testRunCompleted;
|
|
+ static boolean unsupportingLaneSize;
|
|
+ static boolean isEnabled;
|
|
+
|
|
+ @SuppressWarnings("deprecation")
|
|
+ public static void initialize() {
|
|
+ try {
|
|
+ SIMDChecker.initialize();
|
|
+ } catch (Throwable ignored) {}
|
|
+ }
|
|
+
|
|
+ static void setInitialized() {
|
|
+ isInitialized = true;
|
|
+ }
|
|
+
|
|
+ public static boolean isInitialized() {
|
|
+ return isInitialized;
|
|
+ }
|
|
+
|
|
+ public static int intVectorBitSize() {
|
|
+ return intVectorBitSize;
|
|
+ }
|
|
+
|
|
+ public static int floatVectorBitSize() {
|
|
+ return floatVectorBitSize;
|
|
+ }
|
|
+
|
|
+ public static int intElementSize() {
|
|
+ return intElementSize;
|
|
+ }
|
|
+
|
|
+ public static int floatElementSize() {
|
|
+ return floatElementSize;
|
|
+ }
|
|
+
|
|
+ public static boolean testRunCompleted() {
|
|
+ return testRunCompleted;
|
|
+ }
|
|
+
|
|
+ public static boolean unsupportingLaneSize() {
|
|
+ return unsupportingLaneSize;
|
|
+ }
|
|
+
|
|
+ public static boolean isEnabled() {
|
|
+ return isEnabled;
|
|
+ }
|
|
+
|
|
+}
|