115 lines
3.9 KiB
Diff
115 lines
3.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Kevin Raneri <kevin.raneri@gmail.com>
|
|
Date: Tue, 8 Feb 2022 12:52:25 -0500
|
|
Subject: [PATCH] Add SIMD utilities
|
|
|
|
The utilities added in this patch are not intended to be used by plugins
|
|
and API spec stability is NOT guaranteed. If you use this in plugins,
|
|
they WILL break eventually.
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index 48d254cd1ee3dc13846ce283cdae5938865607fd..b83e2c5a0a094002d12aee55ec0cf8d12bf33f3e 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -86,6 +86,13 @@ val generateApiVersioningFile by tasks.registering {
|
|
}
|
|
}
|
|
|
|
+// Pufferfish Start
|
|
+tasks.withType<JavaCompile> {
|
|
+ val compilerArgs = options.compilerArgs
|
|
+ compilerArgs.add("--add-modules=jdk.incubator.vector")
|
|
+}
|
|
+// Pufferfish End
|
|
+
|
|
tasks.jar {
|
|
from(generateApiVersioningFile.map { it.outputs.files.singleFile }) {
|
|
into("META-INF/maven/${project.group}/${project.name}")
|
|
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..ab5fea0b03224bf249352ce340e94704ff713345
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
|
|
@@ -0,0 +1,40 @@
|
|
+package gg.pufferfish.pufferfish.simd;
|
|
+
|
|
+import java.util.logging.Level;
|
|
+import java.util.logging.Logger;
|
|
+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 {
|
|
+
|
|
+ @Deprecated
|
|
+ public static boolean canEnable(Logger logger) {
|
|
+ try {
|
|
+ if (SIMDDetection.getJavaVersion() != 17 && SIMDDetection.getJavaVersion() != 18 && SIMDDetection.getJavaVersion() != 19) {
|
|
+ return false;
|
|
+ } else {
|
|
+ SIMDDetection.testRun = true;
|
|
+
|
|
+ VectorSpecies<Integer> ISPEC = IntVector.SPECIES_PREFERRED;
|
|
+ VectorSpecies<Float> FSPEC = FloatVector.SPECIES_PREFERRED;
|
|
+
|
|
+ logger.log(Level.INFO, "Max SIMD vector size on this system is " + ISPEC.vectorBitSize() + " bits (int)");
|
|
+ logger.log(Level.INFO, "Max SIMD vector size on this system is " + FSPEC.vectorBitSize() + " bits (float)");
|
|
+
|
|
+ if (ISPEC.elementSize() < 2 || FSPEC.elementSize() < 2) {
|
|
+ logger.log(Level.WARNING, "SIMD is not properly supported on this system!");
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+ } catch (NoClassDefFoundError | Exception ignored) {} // Basically, we don't do anything. This lets us detect if it's not functional and disable it.
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+}
|
|
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..a84889d3e9cfc4d7ab5f867820a6484c6070711b
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
|
|
@@ -0,0 +1,35 @@
|
|
+package gg.pufferfish.pufferfish.simd;
|
|
+
|
|
+import java.util.logging.Logger;
|
|
+
|
|
+@Deprecated
|
|
+public class SIMDDetection {
|
|
+
|
|
+ public static boolean isEnabled = false;
|
|
+ public static boolean versionLimited = false;
|
|
+ public static boolean testRun = false;
|
|
+
|
|
+ @Deprecated
|
|
+ public static boolean canEnable(Logger logger) {
|
|
+ try {
|
|
+ return SIMDChecker.canEnable(logger);
|
|
+ } catch (NoClassDefFoundError | Exception ignored) {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Deprecated
|
|
+ public static int getJavaVersion() {
|
|
+ // https://stackoverflow.com/a/2591122
|
|
+ String version = System.getProperty("java.version");
|
|
+ if(version.startsWith("1.")) {
|
|
+ version = version.substring(2, 3);
|
|
+ } else {
|
|
+ int dot = version.indexOf(".");
|
|
+ if(dot != -1) { version = version.substring(0, dot); }
|
|
+ }
|
|
+ version = version.split("-")[0]; // Azul is stupid
|
|
+ return Integer.parseInt(version);
|
|
+ }
|
|
+
|
|
+}
|