From e903fadf1b201a4b4c3deff976ffbb777992c22a Mon Sep 17 00:00:00 2001 From: httpdigest Date: Fri, 28 Oct 2022 22:03:51 +0200 Subject: [PATCH] Add JVMCI x64 code for Matrix4f invert and transpose --- src/main/java/org/joml/JvmciCode.java | 135 ++++++++++++++++++++++++++ src/main/java/org/joml/Matrix4f.java | 124 ++++++++++++++--------- 2 files changed, 212 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/joml/JvmciCode.java b/src/main/java/org/joml/JvmciCode.java index 90128144..8aaac665 100644 --- a/src/main/java/org/joml/JvmciCode.java +++ b/src/main/java/org/joml/JvmciCode.java @@ -91,5 +91,140 @@ class JvmciCode { (byte) 0x59, (byte) 0xC6, (byte) 0xC5, (byte) 0xF0, (byte) 0x59, (byte) 0xCF, (byte) 0xC5, (byte) 0xF8, (byte) 0x58, (byte) 0xC1, (byte) 0xC5, (byte) 0xE8, (byte) 0x58, (byte) 0xC0, (byte) 0xC4, (byte) 0xC1, (byte) 0x78, (byte) 0x11, (byte) 0x41, (byte) 0x40, (byte) 0xC3}; + + static final byte[] INVERT_LINUX = { + (byte) 0xC5, (byte) 0xFB, (byte) 0x10, (byte) 0x46, (byte) 0x10, (byte) 0xC5, + (byte) 0xFB, (byte) 0x10, (byte) 0x66, (byte) 0x18, (byte) 0xC5, (byte) 0xFB, (byte) 0x10, (byte) 0x4E, + (byte) 0x30, (byte) 0xC5, (byte) 0xFB, (byte) 0x10, (byte) 0x6E, (byte) 0x38, (byte) 0xC5, (byte) 0xF8, + (byte) 0x16, (byte) 0x56, (byte) 0x20, (byte) 0xC5, (byte) 0xF0, (byte) 0x16, (byte) 0x5E, (byte) 0x40, + (byte) 0xC5, (byte) 0xE8, (byte) 0xC6, (byte) 0xC3, (byte) 0x88, (byte) 0xC5, (byte) 0xE0, (byte) 0xC6, + (byte) 0xCA, (byte) 0xDD, (byte) 0xC5, (byte) 0xD8, (byte) 0x16, (byte) 0x76, (byte) 0x28, (byte) 0xC5, + (byte) 0x50, (byte) 0x16, (byte) 0x46, (byte) 0x48, (byte) 0xC4, (byte) 0xC1, (byte) 0x48, (byte) 0xC6, + (byte) 0xF8, (byte) 0x88, (byte) 0xC5, (byte) 0xB8, (byte) 0xC6, (byte) 0xE6, (byte) 0xDD, (byte) 0xC5, + (byte) 0xD8, (byte) 0x59, (byte) 0xEF, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x04, (byte) 0xED, + (byte) 0xB1, (byte) 0xC4, (byte) 0x63, (byte) 0x79, (byte) 0x05, (byte) 0xCD, (byte) 0x01, (byte) 0xC5, + (byte) 0xB0, (byte) 0x5C, (byte) 0xED, (byte) 0xC5, (byte) 0x50, (byte) 0x59, (byte) 0xD9, (byte) 0xC5, + (byte) 0x40, (byte) 0x59, (byte) 0xC9, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x04, (byte) 0xC9, + (byte) 0xB1, (byte) 0xC5, (byte) 0x30, (byte) 0x59, (byte) 0xE4, (byte) 0xC4, (byte) 0x43, (byte) 0x79, + (byte) 0x05, (byte) 0xE9, (byte) 0x01, (byte) 0xC4, (byte) 0x41, (byte) 0x10, (byte) 0x5C, (byte) 0xC9, + (byte) 0xC5, (byte) 0x78, (byte) 0x29, (byte) 0x4C, (byte) 0x24, (byte) 0xE8, (byte) 0xC5, (byte) 0x68, + (byte) 0xC6, (byte) 0xD3, (byte) 0x77, (byte) 0xC5, (byte) 0x38, (byte) 0xC6, (byte) 0xF6, (byte) 0x77, + (byte) 0xC4, (byte) 0x41, (byte) 0x08, (byte) 0x59, (byte) 0xF2, (byte) 0xC4, (byte) 0x63, (byte) 0x79, + (byte) 0x05, (byte) 0xD7, (byte) 0x01, (byte) 0xC4, (byte) 0xC1, (byte) 0x08, (byte) 0x59, (byte) 0xFA, + (byte) 0xC5, (byte) 0x98, (byte) 0x58, (byte) 0xFF, (byte) 0xC5, (byte) 0xA0, (byte) 0x58, (byte) 0xFF, + (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xDE, (byte) 0x01, (byte) 0xC5, (byte) 0x10, + (byte) 0x59, (byte) 0xE4, (byte) 0xC4, (byte) 0x41, (byte) 0x20, (byte) 0x59, (byte) 0xEA, (byte) 0xC4, + (byte) 0x41, (byte) 0x18, (byte) 0x58, (byte) 0xE5, (byte) 0xC4, (byte) 0xC1, (byte) 0x40, (byte) 0x5C, + (byte) 0xFC, (byte) 0xC4, (byte) 0x41, (byte) 0x20, (byte) 0x5C, (byte) 0xDE, (byte) 0xC5, (byte) 0x20, + (byte) 0x59, (byte) 0xD8, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xDB, (byte) 0x01, + (byte) 0xC5, (byte) 0x70, (byte) 0x59, (byte) 0xE0, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x04, + (byte) 0xE4, (byte) 0xB1, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xEC, (byte) 0x01, + (byte) 0xC5, (byte) 0x58, (byte) 0x59, (byte) 0xF0, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x04, + (byte) 0xF6, (byte) 0xB1, (byte) 0xC4, (byte) 0x41, (byte) 0x10, (byte) 0x5C, (byte) 0xFC, (byte) 0xC5, + (byte) 0x00, (byte) 0x59, (byte) 0xFC, (byte) 0xC4, (byte) 0x41, (byte) 0x00, (byte) 0x5C, (byte) 0xDB, + (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xFE, (byte) 0x01, (byte) 0xC4, (byte) 0x41, + (byte) 0x08, (byte) 0x5C, (byte) 0xCF, (byte) 0xC5, (byte) 0x30, (byte) 0x59, (byte) 0xC9, (byte) 0xC4, + (byte) 0x41, (byte) 0x20, (byte) 0x58, (byte) 0xC9, (byte) 0xC5, (byte) 0xE8, (byte) 0xC6, (byte) 0xD3, + (byte) 0x22, (byte) 0xC5, (byte) 0xB8, (byte) 0xC6, (byte) 0xDE, (byte) 0x22, (byte) 0xC5, (byte) 0xE0, + (byte) 0x59, (byte) 0xD2, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, (byte) 0xDA, (byte) 0x01, + (byte) 0xC5, (byte) 0xE8, (byte) 0x5C, (byte) 0xF3, (byte) 0xC5, (byte) 0xC8, (byte) 0x59, (byte) 0xE4, + (byte) 0xC4, (byte) 0xC1, (byte) 0x00, (byte) 0x5C, (byte) 0xF6, (byte) 0xC5, (byte) 0xA8, (byte) 0x59, + (byte) 0xF6, (byte) 0xC5, (byte) 0xC8, (byte) 0x58, (byte) 0xE4, (byte) 0xC5, (byte) 0xD0, (byte) 0x59, + (byte) 0xE8, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, (byte) 0xED, (byte) 0x01, (byte) 0xC5, + (byte) 0xD0, (byte) 0x58, (byte) 0xE4, (byte) 0xC5, (byte) 0xE0, (byte) 0x5C, (byte) 0xD2, (byte) 0xC5, + (byte) 0xE8, (byte) 0x59, (byte) 0xC9, (byte) 0xC4, (byte) 0xC1, (byte) 0x18, (byte) 0x5C, (byte) 0xD5, + (byte) 0xC5, (byte) 0xA8, (byte) 0x59, (byte) 0xD2, (byte) 0xC5, (byte) 0xF8, (byte) 0x59, (byte) 0x5C, + (byte) 0x24, (byte) 0xE8, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, (byte) 0xDB, (byte) 0x01, + (byte) 0xC5, (byte) 0xE8, (byte) 0x5C, (byte) 0xD3, (byte) 0xC5, (byte) 0xE8, (byte) 0x58, (byte) 0xC9, + (byte) 0xC5, (byte) 0xC0, (byte) 0x59, (byte) 0xC0, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, + (byte) 0xD0, (byte) 0x01, (byte) 0xC5, (byte) 0xE8, (byte) 0x58, (byte) 0xC0, (byte) 0xC5, (byte) 0xFA, + (byte) 0x16, (byte) 0xD0, (byte) 0xC5, (byte) 0xF8, (byte) 0x58, (byte) 0xC2, (byte) 0xC5, (byte) 0xFA, + (byte) 0x53, (byte) 0xD0, (byte) 0xC5, (byte) 0xEA, (byte) 0x59, (byte) 0xDA, (byte) 0xC5, (byte) 0xE2, + (byte) 0x59, (byte) 0xC0, (byte) 0xC5, (byte) 0xEA, (byte) 0x58, (byte) 0xD2, (byte) 0xC5, (byte) 0xEA, + (byte) 0x5C, (byte) 0xC0, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x04, (byte) 0xC0, (byte) 0x00, + (byte) 0xC5, (byte) 0xF8, (byte) 0x59, (byte) 0xD4, (byte) 0xC5, (byte) 0xF8, (byte) 0x11, (byte) 0x52, + (byte) 0x20, (byte) 0xC5, (byte) 0xF8, (byte) 0x59, (byte) 0xD7, (byte) 0xC5, (byte) 0xF8, (byte) 0x11, + (byte) 0x52, (byte) 0x10, (byte) 0xC5, (byte) 0xB0, (byte) 0x59, (byte) 0xD0, (byte) 0xC5, (byte) 0xF8, + (byte) 0x59, (byte) 0xC1, (byte) 0xC5, (byte) 0xF8, (byte) 0x11, (byte) 0x42, (byte) 0x40, (byte) 0xC5, + (byte) 0xF8, (byte) 0x11, (byte) 0x52, (byte) 0x30, (byte) 0xC3 }; + static final byte[] INVERT_WINDOWS = { + (byte) 0xC5, (byte) 0xFB, (byte) 0x10, (byte) 0x42, (byte) 0x10, (byte) 0xC5, + (byte) 0xFB, (byte) 0x10, (byte) 0x62, (byte) 0x18, (byte) 0xC5, (byte) 0xFB, (byte) 0x10, (byte) 0x4A, + (byte) 0x30, (byte) 0xC5, (byte) 0xFB, (byte) 0x10, (byte) 0x6A, (byte) 0x38, (byte) 0xC5, (byte) 0xF8, + (byte) 0x16, (byte) 0x52, (byte) 0x20, (byte) 0xC5, (byte) 0xF0, (byte) 0x16, (byte) 0x5A, (byte) 0x40, + (byte) 0xC5, (byte) 0xE8, (byte) 0xC6, (byte) 0xC3, (byte) 0x88, (byte) 0xC5, (byte) 0xE0, (byte) 0xC6, + (byte) 0xCA, (byte) 0xDD, (byte) 0xC5, (byte) 0xD8, (byte) 0x16, (byte) 0x72, (byte) 0x28, (byte) 0xC5, + (byte) 0x50, (byte) 0x16, (byte) 0x42, (byte) 0x48, (byte) 0xC4, (byte) 0xC1, (byte) 0x48, (byte) 0xC6, + (byte) 0xF8, (byte) 0x88, (byte) 0xC5, (byte) 0xB8, (byte) 0xC6, (byte) 0xE6, (byte) 0xDD, (byte) 0xC5, + (byte) 0xD8, (byte) 0x59, (byte) 0xEF, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x04, (byte) 0xED, + (byte) 0xB1, (byte) 0xC4, (byte) 0x63, (byte) 0x79, (byte) 0x05, (byte) 0xCD, (byte) 0x01, (byte) 0xC5, + (byte) 0xB0, (byte) 0x5C, (byte) 0xED, (byte) 0xC5, (byte) 0x50, (byte) 0x59, (byte) 0xD9, (byte) 0xC5, + (byte) 0x40, (byte) 0x59, (byte) 0xC9, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x04, (byte) 0xC9, + (byte) 0xB1, (byte) 0xC5, (byte) 0x30, (byte) 0x59, (byte) 0xE4, (byte) 0xC4, (byte) 0x43, (byte) 0x79, + (byte) 0x05, (byte) 0xE9, (byte) 0x01, (byte) 0xC4, (byte) 0x41, (byte) 0x10, (byte) 0x5C, (byte) 0xC9, + (byte) 0xC5, (byte) 0x78, (byte) 0x29, (byte) 0x4C, (byte) 0x24, (byte) 0xE8, (byte) 0xC5, (byte) 0x68, + (byte) 0xC6, (byte) 0xD3, (byte) 0x77, (byte) 0xC5, (byte) 0x38, (byte) 0xC6, (byte) 0xF6, (byte) 0x77, + (byte) 0xC4, (byte) 0x41, (byte) 0x08, (byte) 0x59, (byte) 0xF2, (byte) 0xC4, (byte) 0x63, (byte) 0x79, + (byte) 0x05, (byte) 0xD7, (byte) 0x01, (byte) 0xC4, (byte) 0xC1, (byte) 0x08, (byte) 0x59, (byte) 0xFA, + (byte) 0xC5, (byte) 0x98, (byte) 0x58, (byte) 0xFF, (byte) 0xC5, (byte) 0xA0, (byte) 0x58, (byte) 0xFF, + (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xDE, (byte) 0x01, (byte) 0xC5, (byte) 0x10, + (byte) 0x59, (byte) 0xE4, (byte) 0xC4, (byte) 0x41, (byte) 0x20, (byte) 0x59, (byte) 0xEA, (byte) 0xC4, + (byte) 0x41, (byte) 0x18, (byte) 0x58, (byte) 0xE5, (byte) 0xC4, (byte) 0xC1, (byte) 0x40, (byte) 0x5C, + (byte) 0xFC, (byte) 0xC4, (byte) 0x41, (byte) 0x20, (byte) 0x5C, (byte) 0xDE, (byte) 0xC5, (byte) 0x20, + (byte) 0x59, (byte) 0xD8, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xDB, (byte) 0x01, + (byte) 0xC5, (byte) 0x70, (byte) 0x59, (byte) 0xE0, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x04, + (byte) 0xE4, (byte) 0xB1, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xEC, (byte) 0x01, + (byte) 0xC5, (byte) 0x58, (byte) 0x59, (byte) 0xF0, (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x04, + (byte) 0xF6, (byte) 0xB1, (byte) 0xC4, (byte) 0x41, (byte) 0x10, (byte) 0x5C, (byte) 0xFC, (byte) 0xC5, + (byte) 0x00, (byte) 0x59, (byte) 0xFC, (byte) 0xC4, (byte) 0x41, (byte) 0x00, (byte) 0x5C, (byte) 0xDB, + (byte) 0xC4, (byte) 0x43, (byte) 0x79, (byte) 0x05, (byte) 0xFE, (byte) 0x01, (byte) 0xC4, (byte) 0x41, + (byte) 0x08, (byte) 0x5C, (byte) 0xCF, (byte) 0xC5, (byte) 0x30, (byte) 0x59, (byte) 0xC9, (byte) 0xC4, + (byte) 0x41, (byte) 0x20, (byte) 0x58, (byte) 0xC9, (byte) 0xC5, (byte) 0xE8, (byte) 0xC6, (byte) 0xD3, + (byte) 0x22, (byte) 0xC5, (byte) 0xB8, (byte) 0xC6, (byte) 0xDE, (byte) 0x22, (byte) 0xC5, (byte) 0xE0, + (byte) 0x59, (byte) 0xD2, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, (byte) 0xDA, (byte) 0x01, + (byte) 0xC5, (byte) 0xE8, (byte) 0x5C, (byte) 0xF3, (byte) 0xC5, (byte) 0xC8, (byte) 0x59, (byte) 0xE4, + (byte) 0xC4, (byte) 0xC1, (byte) 0x00, (byte) 0x5C, (byte) 0xF6, (byte) 0xC5, (byte) 0xA8, (byte) 0x59, + (byte) 0xF6, (byte) 0xC5, (byte) 0xC8, (byte) 0x58, (byte) 0xE4, (byte) 0xC5, (byte) 0xD0, (byte) 0x59, + (byte) 0xE8, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, (byte) 0xED, (byte) 0x01, (byte) 0xC5, + (byte) 0xD0, (byte) 0x58, (byte) 0xE4, (byte) 0xC5, (byte) 0xE0, (byte) 0x5C, (byte) 0xD2, (byte) 0xC5, + (byte) 0xE8, (byte) 0x59, (byte) 0xC9, (byte) 0xC4, (byte) 0xC1, (byte) 0x18, (byte) 0x5C, (byte) 0xD5, + (byte) 0xC5, (byte) 0xA8, (byte) 0x59, (byte) 0xD2, (byte) 0xC5, (byte) 0xF8, (byte) 0x59, (byte) 0x5C, + (byte) 0x24, (byte) 0xE8, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, (byte) 0xDB, (byte) 0x01, + (byte) 0xC5, (byte) 0xE8, (byte) 0x5C, (byte) 0xD3, (byte) 0xC5, (byte) 0xE8, (byte) 0x58, (byte) 0xC9, + (byte) 0xC5, (byte) 0xC0, (byte) 0x59, (byte) 0xC0, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x05, + (byte) 0xD0, (byte) 0x01, (byte) 0xC5, (byte) 0xE8, (byte) 0x58, (byte) 0xC0, (byte) 0xC5, (byte) 0xFA, + (byte) 0x16, (byte) 0xD0, (byte) 0xC5, (byte) 0xF8, (byte) 0x58, (byte) 0xC2, (byte) 0xC5, (byte) 0xFA, + (byte) 0x53, (byte) 0xD0, (byte) 0xC5, (byte) 0xEA, (byte) 0x59, (byte) 0xDA, (byte) 0xC5, (byte) 0xE2, + (byte) 0x59, (byte) 0xC0, (byte) 0xC5, (byte) 0xEA, (byte) 0x58, (byte) 0xD2, (byte) 0xC5, (byte) 0xEA, + (byte) 0x5C, (byte) 0xC0, (byte) 0xC4, (byte) 0xE3, (byte) 0x79, (byte) 0x04, (byte) 0xC0, (byte) 0x00, + (byte) 0xC5, (byte) 0xF8, (byte) 0x59, (byte) 0xD4, (byte) 0xC4, (byte) 0xC1, (byte) 0x78, (byte) 0x11, + (byte) 0x50, (byte) 0x20, (byte) 0xC5, (byte) 0xF8, (byte) 0x59, (byte) 0xD7, (byte) 0xC4, (byte) 0xC1, + (byte) 0x78, (byte) 0x11, (byte) 0x50, (byte) 0x10, (byte) 0xC5, (byte) 0xB0, (byte) 0x59, (byte) 0xD0, + (byte) 0xC5, (byte) 0xF8, (byte) 0x59, (byte) 0xC1, (byte) 0xC4, (byte) 0xC1, (byte) 0x78, (byte) 0x11, + (byte) 0x40, (byte) 0x40, (byte) 0xC4, (byte) 0xC1, (byte) 0x78, (byte) 0x11, (byte) 0x50, (byte) 0x30, + (byte) 0xC3 }; + + static final byte[] TRANSPOSE_LINUX = { + (byte) 0xC5, (byte) 0xF8, (byte) 0x10, (byte) 0x46, (byte) 0x10, (byte) 0xC5, + (byte) 0xF8, (byte) 0x10, (byte) 0x4E, (byte) 0x20, (byte) 0xC5, (byte) 0xF8, (byte) 0x10, (byte) 0x56, + (byte) 0x30, (byte) 0xC5, (byte) 0xF8, (byte) 0x10, (byte) 0x5E, (byte) 0x40, (byte) 0xC5, (byte) 0xF8, + (byte) 0x14, (byte) 0xE1, (byte) 0xC5, (byte) 0xE8, (byte) 0x14, (byte) 0xEB, (byte) 0xC5, (byte) 0xF8, + (byte) 0x15, (byte) 0xC1, (byte) 0xC5, (byte) 0xE8, (byte) 0x15, (byte) 0xCB, (byte) 0xC5, (byte) 0xD8, + (byte) 0x16, (byte) 0xD5, (byte) 0xC5, (byte) 0xD9, (byte) 0x15, (byte) 0xDD, (byte) 0xC5, (byte) 0xF8, + (byte) 0x16, (byte) 0xE1, (byte) 0xC5, (byte) 0xF9, (byte) 0x15, (byte) 0xC1, (byte) 0xC5, (byte) 0xF8, + (byte) 0x11, (byte) 0x52, (byte) 0x10, (byte) 0xC5, (byte) 0xF8, (byte) 0x11, (byte) 0x5A, (byte) 0x20, + (byte) 0xC5, (byte) 0xF8, (byte) 0x11, (byte) 0x62, (byte) 0x30, (byte) 0xC5, (byte) 0xF8, (byte) 0x11, + (byte) 0x42, (byte) 0x40, (byte) 0xC3 }; + static final byte[] TRANSPOSE_WINDOWS = { + (byte) 0xC5, (byte) 0xF8, (byte) 0x10, (byte) 0x42, (byte) 0x10, (byte) 0xC5, + (byte) 0xF8, (byte) 0x10, (byte) 0x4A, (byte) 0x20, (byte) 0xC5, (byte) 0xF8, (byte) 0x10, (byte) 0x52, + (byte) 0x30, (byte) 0xC5, (byte) 0xF8, (byte) 0x10, (byte) 0x5A, (byte) 0x40, (byte) 0xC5, (byte) 0xF8, + (byte) 0x14, (byte) 0xE1, (byte) 0xC5, (byte) 0xE8, (byte) 0x14, (byte) 0xEB, (byte) 0xC5, (byte) 0xF8, + (byte) 0x15, (byte) 0xC1, (byte) 0xC5, (byte) 0xE8, (byte) 0x15, (byte) 0xCB, (byte) 0xC5, (byte) 0xD8, + (byte) 0x16, (byte) 0xD5, (byte) 0xC5, (byte) 0xD9, (byte) 0x15, (byte) 0xDD, (byte) 0xC5, (byte) 0xF8, + (byte) 0x16, (byte) 0xE1, (byte) 0xC5, (byte) 0xF9, (byte) 0x15, (byte) 0xC1, (byte) 0xC4, (byte) 0xC1, + (byte) 0x78, (byte) 0x11, (byte) 0x50, (byte) 0x10, (byte) 0xC4, (byte) 0xC1, (byte) 0x78, (byte) 0x11, + (byte) 0x58, (byte) 0x20, (byte) 0xC4, (byte) 0xC1, (byte) 0x78, (byte) 0x11, (byte) 0x60, (byte) 0x30, + (byte) 0xC4, (byte) 0xC1, (byte) 0x78, (byte) 0x11, (byte) 0x40, (byte) 0x40, (byte) 0xC3 }; } //#endif diff --git a/src/main/java/org/joml/Matrix4f.java b/src/main/java/org/joml/Matrix4f.java index 272ab80d..9d710520 100644 --- a/src/main/java/org/joml/Matrix4f.java +++ b/src/main/java/org/joml/Matrix4f.java @@ -67,50 +67,6 @@ public class Matrix4f implements Externalizable, Cloneable, Matrix4fc { //#ifdef __HAS_JVMCI__ private static final boolean isWindows = isWindows(); private static final boolean canUseJvmci = canUseJvmci(); - private static boolean isWindows() { - String os = System.getProperty("os.name"); - return os.contains("Windows"); - } - private static sun.misc.Unsafe getUnsafeInstance() throws SecurityException { - java.lang.reflect.Field[] fields = sun.misc.Unsafe.class.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - java.lang.reflect.Field field = fields[i]; - if (!field.getType().equals(sun.misc.Unsafe.class)) - continue; - int modifiers = field.getModifiers(); - if (!(java.lang.reflect.Modifier.isStatic(modifiers) && java.lang.reflect.Modifier.isFinal(modifiers))) - continue; - field.setAccessible(true); - try { - return (sun.misc.Unsafe) field.get(null); - } catch (IllegalAccessException e) { - /* Ignore */ - } - break; - } - throw new UnsupportedOperationException(); - } - private static boolean canUseJvmci() { - try { - sun.misc.Unsafe u = getUnsafeInstance(); - long m00off = u.objectFieldOffset(Matrix4f.class.getDeclaredField("m00")); - if (m00off != 16L) - return false; - JVMCIBackend jvmci = JVMCI.getRuntime().getHostJVMCIBackend(); - installCode(jvmci, Matrix4f.class.getDeclaredMethod("__mulJvmciAvx", Matrix4f.class, Matrix4f.class, Matrix4f.class), isWindows ? MUL_WINDOWS : MUL_LINUX); - return true; - } catch (Throwable t) { - return false; - } - } - private static void installCode(JVMCIBackend jvmci, Method m, byte[] code) { - ResolvedJavaMethod rm = jvmci.getMetaAccess().lookupJavaMethod(m); - HotSpotCompiledNmethod nm = new HotSpotCompiledNmethod(m.getName(), code, code.length, new Site[0], - new Assumptions.Assumption[0], new ResolvedJavaMethod[0], new HotSpotCompiledCode.Comment[0], new byte[0], 1, - new DataPatch[0], true, 0, null, (HotSpotResolvedJavaMethod) rm, JVMCICompiler.INVOCATION_ENTRY_BCI, 1, 0, false); - jvmci.getCodeCache().setDefaultCode(rm, nm); - } - private static native void __mulJvmciAvx(Matrix4f a, Matrix4f b, Matrix4f r); //#endif int properties; @@ -1202,7 +1158,9 @@ else if ((right.properties() & PROPERTY_IDENTITY) != 0) return dest.set(this); //#ifdef __HAS_JVMCI__ else if (canUseJvmci && right instanceof Matrix4f) { - __mulJvmciAvx(this, (Matrix4f) right, dest); + Matrix4f mright = (Matrix4f) right; + __mulJvmciAvx(this, mright, dest); + dest.properties = properties & mright.properties & (PROPERTY_AFFINE | PROPERTY_ORTHONORMAL); return dest; } //#endif @@ -2597,12 +2555,19 @@ public float determinantAffine() { } public Matrix4f invert(Matrix4f dest) { - if ((properties & PROPERTY_IDENTITY) != 0) { + if ((properties & PROPERTY_IDENTITY) != 0) return dest.identity(); - } else if ((properties & PROPERTY_TRANSLATION) != 0) + else if ((properties & PROPERTY_TRANSLATION) != 0) return invertTranslation(dest); else if ((properties & PROPERTY_ORTHONORMAL) != 0) return invertOrthonormal(dest); +//#ifdef __HAS_JVMCI__ + else if (canUseJvmci) { + __invertJvmciAvx(this, dest); + dest.properties = properties & PROPERTY_AFFINE; + return dest; + } +//#endif else if ((properties & PROPERTY_AFFINE) != 0) return invertAffine(dest); else if ((properties & PROPERTY_PERSPECTIVE) != 0) @@ -3005,6 +2970,13 @@ public Matrix4f invertAffine() { public Matrix4f transpose(Matrix4f dest) { if ((properties & PROPERTY_IDENTITY) != 0) return dest.identity(); +//#ifdef __HAS_JVMCI__ + else if (canUseJvmci) { + __transposeJvmciAvx(this, dest); + dest.properties = 0; + return dest; + } +//#endif else if (this != dest) return transposeNonThisGeneric(dest); return transposeThisGeneric(dest); @@ -15882,4 +15854,62 @@ public boolean isFinite() { public Object clone() throws CloneNotSupportedException { return super.clone(); } + + +//#ifdef __HAS_JVMCI__ + private static boolean isX86() { + String a = System.getProperty("os.arch").toLowerCase(); + return a.contains("64") && !a.contains("aarch") && !a.contains("arm") && !a.contains("riscv"); + } + private static boolean isWindows() { + String os = System.getProperty("os.name"); + return os.contains("Windows"); + } + private static sun.misc.Unsafe getUnsafeInstance() throws SecurityException { + java.lang.reflect.Field[] fields = sun.misc.Unsafe.class.getDeclaredFields(); + for (int i = 0; i < fields.length; i++) { + java.lang.reflect.Field field = fields[i]; + if (!field.getType().equals(sun.misc.Unsafe.class)) + continue; + int modifiers = field.getModifiers(); + if (!(java.lang.reflect.Modifier.isStatic(modifiers) && java.lang.reflect.Modifier.isFinal(modifiers))) + continue; + field.setAccessible(true); + try { + return (sun.misc.Unsafe) field.get(null); + } catch (IllegalAccessException e) { + /* Ignore */ + } + break; + } + throw new UnsupportedOperationException(); + } + private static boolean canUseJvmci() { + if (!isX86()) + return false; + try { + sun.misc.Unsafe u = getUnsafeInstance(); + long m00off = u.objectFieldOffset(Matrix4f.class.getDeclaredField("m00")); + if (m00off != 16L) + return false; + JVMCIBackend jvmci = JVMCI.getRuntime().getHostJVMCIBackend(); + installCode(jvmci, Matrix4f.class.getDeclaredMethod("__mulJvmciAvx", Matrix4f.class, Matrix4f.class, Matrix4f.class), isWindows ? MUL_WINDOWS : MUL_LINUX); + installCode(jvmci, Matrix4f.class.getDeclaredMethod("__invertJvmciAvx", Matrix4f.class, Matrix4f.class), isWindows ? INVERT_WINDOWS : INVERT_LINUX); + installCode(jvmci, Matrix4f.class.getDeclaredMethod("__transposeJvmciAvx", Matrix4f.class, Matrix4f.class), isWindows ? TRANSPOSE_WINDOWS : TRANSPOSE_LINUX); + return true; + } catch (Throwable t) { + return false; + } + } + private static void installCode(JVMCIBackend jvmci, Method m, byte[] code) { + ResolvedJavaMethod rm = jvmci.getMetaAccess().lookupJavaMethod(m); + HotSpotCompiledNmethod nm = new HotSpotCompiledNmethod(m.getName(), code, code.length, new Site[0], + new Assumptions.Assumption[0], new ResolvedJavaMethod[0], new HotSpotCompiledCode.Comment[0], new byte[0], 1, + new DataPatch[0], true, 0, null, (HotSpotResolvedJavaMethod) rm, JVMCICompiler.INVOCATION_ENTRY_BCI, 1, 0, false); + jvmci.getCodeCache().setDefaultCode(rm, nm); + } + private static native void __mulJvmciAvx(Matrix4f a, Matrix4f b, Matrix4f r); + private static native void __invertJvmciAvx(Matrix4f a, Matrix4f r); + private static native void __transposeJvmciAvx(Matrix4f a, Matrix4f r); +//#endif }