Java中的SIMD向量/矩阵?

时间:2014-08-02 08:03:49

标签: java graphics 3d jvm simd

我用Java编写图形库,主要用于游戏开发。它需要基本的矢量和矩阵对象用于3D计算,理想情况下,这些对象将采用SIMD操作。虽然Java没有直接提供这样的操作,但是可以提示JVM在大型数组的上下文中使用它们。因此...

JVM可以对类似矢量的对象进行矢量化操作吗?如果是这样,我该如何确保这种情况发生?

澄清一下:我需要对小型,静态大小的对象进行操作,不是可变长度数组。例如,严格为3x3或4x4的矩阵,严格为长度为4的向量,等等。大型可变长度数组的矢量化has already been discussed

矢量化的一些候选例子:

public class Vector4f
{
    public int x, y, z, w;

    public void madd(Vector4f multiplicand, Vector4f addend)
    {
        this.x = this.x * multiplicand.x + addend.x;
        this.y = this.y * multiplicand.y + addend.y;
        this.z = this.z * multiplicand.z + addend.z;
        this.w = this.w * multiplicand.w + addend.w;
    }

    public float dot(Vector4f other)
    {
        return this.x * other.x
             + this.y * other.y
             + this.z * other.z
             + this.w * other.w;
    }
}

public class Matrix44f
{
    public float m00, m01, m02, m03;
    public float m10, m11, m12, m13;
    public float m20, m21, m22, m23;
    public float m30, m31, m32, m33;

    public void multiply(Matrix44f other) { ... }
    public void transform(Vector4f other) { ... }
    public void andSoOnAndSoForth() { ... }
}

0 个答案:

没有答案