I'm writing a graphics library in Java, primarily for use in game development. It needs basic vector and matrix objects for use in 3D calculations, and ideally those objects would employ SIMD operations. Although Java doesn't provide such operations directly, it is possible to hint to the JVM to use them in the context of large arrays. Hence...
Can the JVM vectorize operations on vector-like objects? If so, how can I ensure that this happens?
To clarify: I need operations on small, statically sized objects, not variable-length arrays. E.g., matrices that are strictly 3x3 or 4x4, vectors that are strictly of length 4, etc. Vectorization of large, variable-length arrays has already been discussed.
Some example candidates for vectorization:
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() { ... }
}