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; 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 jdk.incubator.vector.VectorSpecies;
import org.slf4j.Logger;
@Deprecated
public class SIMDChecker { 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 { try {
if (SIMDDetection.getJavaVersion() < 17) { if ((SIMDDetection.getJavaVersion() < SIMDDetection.MIN_JAVA_VERSION || SIMDDetection.getJavaVersion() > SIMDDetection.MAX_JAVA_VERSION)) {
return false; return false;
} else { } else {
SIMDDetection.testRun = true; 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 (int)", ISPEC.vectorBitSize());
logger.info("Max SIMD vector size on this system is {} bits (float)", FSPEC.vectorBitSize()); logger.info("Max SIMD vector size on this system is {} bits (float)", FSPEC.vectorBitSize());
@@ -27,7 +29,10 @@ public class SIMDChecker {
return true; 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; return false;
} }
} }

View File

@@ -1,27 +1,30 @@
package gg.pufferfish.pufferfish.simd; package gg.pufferfish.pufferfish.simd;
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.IntVector;
import org.slf4j.Logger; import org.slf4j.Logger;
@Deprecated
public class SIMDDetection { public class SIMDDetection {
public static boolean isEnabled = false; public static boolean isEnabled = false;
public static boolean versionLimited = false; public static boolean versionLimited = false;
public static boolean testRun = 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) { public static boolean canEnable(Logger logger) {
try { try {
return SIMDChecker.canEnable(logger); SIMDChecker checker = new SIMDChecker(IntVector.SPECIES_PREFERRED, FloatVector.SPECIES_PREFERRED);
return checker.canEnable(logger);
} catch (NoClassDefFoundError | Exception ignored) { } catch (NoClassDefFoundError | Exception ignored) {
return false; return false;
} }
} }
@Deprecated
public static int getJavaVersion() { public static int getJavaVersion() {
// https://stackoverflow.com/a/2591122 // https://stackoverflow.com/a/2591122
String version = System.getProperty("java.version"); String version = System.getProperty("java.version");
if(version.startsWith("1.")) { if (version.startsWith("1.")) {
version = version.substring(2, 3); version = version.substring(2, 3);
} else { } else {
int dot = version.indexOf("."); int dot = version.indexOf(".");

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Configuration
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 512eeef7a770fa8264acbe4194a0debb23f8c3c1..80d04f4eb5122d571409a50f5921c3403dacf31f 100644 index 536a3da1d87e1d4087977196c5766f6550a95e47..bbe93d1861541991215d32186eec82fa8602fea2 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java --- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -162,6 +162,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface @@ -162,6 +162,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -24,9 +24,9 @@ index 512eeef7a770fa8264acbe4194a0debb23f8c3c1..80d04f4eb5122d571409a50f5921c340
+ org.bxteam.divinemc.command.DivineCommands.registerCommands(this); // DivineMC - Configuration + org.bxteam.divinemc.command.DivineCommands.registerCommands(this); // DivineMC - Configuration
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
// DivineMC start - Pufferfish SIMD // DivineMC start - Pufferfish: SIMD Support
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index dccfd0f30111316c9c82004358c2a7051cbd5cdb..1ad419b4a2ad4610a0a8d18b26665a7ec0ccc960 100644 index 848f936a26429d844ad439ca336dbcb8d81f09e8..2c60b1c8ecb54c4c9526a2b2f6e6698b77359065 100644
--- a/net/minecraft/world/level/Level.java --- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java +++ b/net/minecraft/world/level/Level.java
@@ -161,6 +161,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl @@ -161,6 +161,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl

View File

@@ -333,12 +333,12 @@ index 3836d60ce84fb26f30a609486a5755d3fd1c94f1..1aab02441e4dfa7703963855d77bb918
} }
} else if (this.visible.remove(advancementHolder)) { } else if (this.visible.remove(advancementHolder)) {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index dcd004749846aa9e650be438b0f097e414c2ec76..5a2b9632a1e46b512a1379923765c1b8a28250b9 100644 index 46adbe6ccf1e4291e33a52a6612f624558c18f96..374abd7e1502edefb78cd6451a36c3b8ad6d8f8f 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java --- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -218,6 +218,13 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface @@ -218,6 +218,13 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
} }
// DivineMC end - Pufferfish SIMD // DivineMC end - Pufferfish: SIMD Support
+ // DivineMC start - Parallel world ticking + // DivineMC start - Parallel world ticking
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.enableParallelWorldTicking) { + if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.enableParallelWorldTicking) {

View File

@@ -4,25 +4,25 @@
// Purpur end - Purpur config files // Purpur end - Purpur config files
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
+ // DivineMC start - Pufferfish SIMD + // DivineMC start - Pufferfish: SIMD Support
+ try { + try {
+ gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled = gg.pufferfish.pufferfish.simd.SIMDDetection.canEnable(LOGGER); + gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled = gg.pufferfish.pufferfish.simd.SIMDDetection.canEnable(LOGGER);
+ gg.pufferfish.pufferfish.simd.SIMDDetection.versionLimited = gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() < 17 || gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() > 21; + gg.pufferfish.pufferfish.simd.SIMDDetection.versionLimited = gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() < gg.pufferfish.pufferfish.simd.SIMDDetection.MIN_JAVA_VERSION || gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() > gg.pufferfish.pufferfish.simd.SIMDDetection.MAX_JAVA_VERSION;
+ } catch (NoClassDefFoundError | Exception ignored) { + } catch (final NoClassDefFoundError | Exception ignored) {
+ ignored.printStackTrace(); + ignored.printStackTrace();
+ } + }
+ +
+ if (gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled) { + if (gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled) {
+ LOGGER.info("SIMD operations detected as functional. Will replace some operations with faster versions."); + LOGGER.info("SIMD operations detected as functional. Will replace some operations with faster versions.");
+ } else if (gg.pufferfish.pufferfish.simd.SIMDDetection.versionLimited) { + } else if (gg.pufferfish.pufferfish.simd.SIMDDetection.versionLimited) {
+ LOGGER.warn("Will not enable SIMD! These optimizations are only safely supported on Java 17 and higher."); + LOGGER.warn("Will not enable SIMD! These optimizations are only safely supported on Java {}-{}", gg.pufferfish.pufferfish.simd.SIMDDetection.MIN_JAVA_VERSION, gg.pufferfish.pufferfish.simd.SIMDDetection.MAX_JAVA_VERSION);
+ } else { + } else {
+ LOGGER.warn("SIMD operations are available for your server, but are not configured!"); + LOGGER.warn("SIMD operations are available for your server, but are not configured!");
+ LOGGER.warn("To enable additional optimizations, add \"--add-modules=jdk.incubator.vector\" to your startup flags, BEFORE the \"-jar\"."); + LOGGER.warn("To enable additional optimizations, add \"--add-modules=jdk.incubator.vector\" to your startup flags, BEFORE the \"-jar\".");
+ LOGGER.warn("If you have already added this flag, then SIMD operations are not supported on your JVM or CPU."); + LOGGER.warn("If you have already added this flag, then SIMD operations are not supported on your JVM or CPU.");
+ LOGGER.warn("Debug: Java: {}, test run: {}", System.getProperty("java.version"), gg.pufferfish.pufferfish.simd.SIMDDetection.testRun); + LOGGER.warn("Debug: Java: {}, test run: {}", System.getProperty("java.version"), gg.pufferfish.pufferfish.simd.SIMDDetection.testRun);
+ } + }
+ // DivineMC end - Pufferfish SIMD + // DivineMC end - Pufferfish: SIMD Support
+ +
this.setPvpAllowed(properties.pvp); this.setPvpAllowed(properties.pvp);
this.setFlightAllowed(properties.allowFlight); this.setFlightAllowed(properties.allowFlight);