我知道 Java 是一种安全的语言,但是当需要矩阵计算时,我可以尝试更快的方法吗?
我正在学习 C++、Digital-Mars 编译器和 FASM 中的 __asm{}。我想在 Java 中做同样的事情。如何在函数中内联汇编代码?这甚至可能吗?
像这样的东西(使用 CPU 的 AVX 支持将数组的所有元素钳制为一个值而不分支的向量化循环):
JavaAsmBlock(
# get pointers into registers somehow
# and tell Java which registers the asm clobbers somehow
vbroadcastss twenty_five(%rip), %ymm0
xor %edx,%edx
.Lloop: # do {
vmovups (%rsi, %rdx, 4), %ymm1
vcmpltps %ymm1, %ymm0, %ymm2
vblendvps %ymm2, %ymm0, %ymm1, %ymm1 # TODO: use vminps instead
vmovups %ymm1, (%rdi, %rdx, 4)
# TODO: unroll the loop a bit, and maybe handle unaligned output specially if that's common
add $32, %rdx
cmp %rcx, %rdx
jb .Lloop # } while(idx < count)
vzeroupper
);
System.out.println(var[0]);
我不想使用代码注入器。我想查看 Intel 或 AT&T 风格的 x86 指令。