85 lines
3.2 KiB
Diff
85 lines
3.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <wangxyper@163.com>
|
|
Date: Wed, 4 Dec 2024 23:51:17 +0800
|
|
Subject: [PATCH] Pufferfish SIMD Utilities
|
|
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index 4b79f96103c98896332113ffe5f0e22cf08ffdd1..fbf51f738e98ac6e8358a7fa81b7fc545469a5a6 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -94,6 +94,14 @@ paperweight {
|
|
craftBukkitPackageVersion.set("v1_21_R3") // also needs to be updated in MappingEnvironment
|
|
}
|
|
|
|
+
|
|
+// Pufferfish Start
|
|
+tasks.withType<JavaCompile> {
|
|
+ val compilerArgs = options.compilerArgs
|
|
+ compilerArgs.add("--add-modules=jdk.incubator.vector")
|
|
+}
|
|
+// Pufferfish End
|
|
+
|
|
tasks.jar {
|
|
archiveClassifier.set("dev")
|
|
|
|
diff --git a/src/main/java/me/earthme/luminol/config/modules/optimizations/SIMDConfig.java b/src/main/java/me/earthme/luminol/config/modules/optimizations/SIMDConfig.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..76cea165bcef0794a66ef7c29721f7716869420f
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/earthme/luminol/config/modules/optimizations/SIMDConfig.java
|
|
@@ -0,0 +1,53 @@
|
|
+package me.earthme.luminol.config.modules.optimizations;
|
|
+
|
|
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
|
+import com.mojang.logging.LogUtils;
|
|
+import gg.pufferfish.pufferfish.simd.SIMDDetection;
|
|
+import me.earthme.luminol.config.ConfigInfo;
|
|
+import me.earthme.luminol.config.DoNotLoad;
|
|
+import me.earthme.luminol.config.EnumConfigCategory;
|
|
+import me.earthme.luminol.config.IConfigModule;
|
|
+import org.slf4j.Logger;
|
|
+
|
|
+public class SIMDConfig implements IConfigModule {
|
|
+ @DoNotLoad
|
|
+ private static final Logger LOGGER = LogUtils.getLogger();
|
|
+ @ConfigInfo(baseName = "enabled")
|
|
+ public static boolean enabled = true;
|
|
+
|
|
+ @Override
|
|
+ public EnumConfigCategory getCategory() {
|
|
+ return EnumConfigCategory.OPTIMIZATIONS;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getBaseName() {
|
|
+ return "use_simd";
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onLoaded(CommentedFileConfig configInstance) {
|
|
+ if (!enabled){
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // Attempt to detect vectorization
|
|
+ try {
|
|
+ SIMDDetection.isEnabled = SIMDDetection.canEnable(LOGGER);
|
|
+ SIMDDetection.versionLimited = SIMDDetection.getJavaVersion() < 17;
|
|
+ } catch (NoClassDefFoundError | Exception ignored) {
|
|
+ ignored.printStackTrace();
|
|
+ }
|
|
+
|
|
+ if (SIMDDetection.isEnabled) {
|
|
+ LOGGER.info("SIMD operations detected as functional. Will replace some operations with faster versions.");
|
|
+ } else if (SIMDDetection.versionLimited) {
|
|
+ LOGGER.warn("Will not enable SIMD! These optimizations are only safely supported on Java 17+.");
|
|
+ } else {
|
|
+ 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("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"), SIMDDetection.testRun);
|
|
+ }
|
|
+ }
|
|
+}
|