9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00

update simd impl

This commit is contained in:
NONPLAYT
2025-07-20 18:01:15 +03:00
parent e0e76be411
commit 156b3bd7cf
5 changed files with 33 additions and 25 deletions

View File

@@ -1,22 +1,24 @@
package gg.pufferfish.pufferfish.simd;
import org.slf4j.Logger;
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.VectorSpecies;
import org.slf4j.Logger;
@Deprecated
public class SIMDChecker {
public static boolean canEnable(Logger logger) {
private final VectorSpecies<Integer> ISPEC;
private final VectorSpecies<Float> FSPEC;
public SIMDChecker(VectorSpecies<Integer> ISPEC, VectorSpecies<Float> FSPEC) {
this.ISPEC = ISPEC;
this.FSPEC = FSPEC;
}
public boolean canEnable(Logger logger) {
try {
if (SIMDDetection.getJavaVersion() < 17) {
if ((SIMDDetection.getJavaVersion() < SIMDDetection.MIN_JAVA_VERSION || SIMDDetection.getJavaVersion() > SIMDDetection.MAX_JAVA_VERSION)) {
return false;
} else {
SIMDDetection.testRun = true;
VectorSpecies<Integer> ISPEC = IntVector.SPECIES_PREFERRED;
VectorSpecies<Float> FSPEC = FloatVector.SPECIES_PREFERRED;
logger.info("Max SIMD vector size on this system is {} bits (int)", ISPEC.vectorBitSize());
logger.info("Max SIMD vector size on this system is {} bits (float)", FSPEC.vectorBitSize());
@@ -27,7 +29,10 @@ public class SIMDChecker {
return true;
}
} catch (NoClassDefFoundError | Exception ignored) {} // Basically, we don't do anything. This lets us detect if it's not functional and disable it.
} catch (NoClassDefFoundError | Exception ignored) {
// Basically, we don't do anything. This lets us detect if it's not functional and disable it.
}
return false;
}
}

View File

@@ -1,27 +1,30 @@
package gg.pufferfish.pufferfish.simd;
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.IntVector;
import org.slf4j.Logger;
@Deprecated
public class SIMDDetection {
public static boolean isEnabled = false;
public static boolean versionLimited = false;
public static boolean testRun = false;
@Deprecated
public static final int MAX_JAVA_VERSION = 25;
public static final int MIN_JAVA_VERSION = 21;
public static boolean canEnable(Logger logger) {
try {
return SIMDChecker.canEnable(logger);
SIMDChecker checker = new SIMDChecker(IntVector.SPECIES_PREFERRED, FloatVector.SPECIES_PREFERRED);
return checker.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.")) {
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");