A question about bytecodes

John Rose John.Rose at Sun.COM
Sat Jan 10 14:50:04 PST 2009


On Jan 10, 2009, at 1:25 PM, Stephen Dawkins wrote:

> ...because we're stuck with a limited set of bytecodes that can't  
> adequately express what the programmer was intending? It seems  
> silly that we're making do with with this limited bytecode language  
> and losing  so much information the programmer could provide for  
> us, allowing the compiler/optimiser todo a much better job, without  
> having to guess that:
>
> float a[] = new float[4], b[] = new float[4];
> float c = a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
>
> could be compiled down to:
>
> DPPS xmm1, xmm2

Yes, vectors are a hard case.  But it is not because the JVM has no  
way to express all the new operations.  Want to add a new operation  
to the system?  That is what methods are for!

Vectors are hard because (unlike unsigned) they cannot be represented  
directly using the existing set of primitive types.  They must be  
boxed into the heap somehow (float[]), which adds extra distraction  
for both coders and compilers.

But, given some way to define multiple value return, your latest  
example could be expressed as an intrinsic with no special-purpose  
bytecodes:

(float, float, float, float) Math.dpps(float a0, float a1, float a2,  
float a3, float b0, float b1, float b2, float b3)

It is straightforward for a compiler to render such an intrinsic as a  
a vector operation.  I think Linux uses asm statements routinely for  
such purposes.  HotSpot has its own way of doing this; see the type  
vmIntrinsics::ID, which is the hook for introducing new "instructions".

For vectors, the sticking point is not lack of bytecodes, but lack of  
multiple value return.  That's what the tuple proposal is addressing.

Given tuple types in Java, it would look much better.

struct VectorF4 {  // signature {Ljava/math/VectorF4;FFFF}
   float a0, a1, a2, a3;
}

// declaration in java.math.VectorMath
VectorF4 dpps(VectorF4 a, VectorF4 b);

// example Java
VectorF4 c = VectorMath.dpps(a, b);

// example bytecodes
fload 10; fload 11; fload 12; fload 13
fload 20; fload 21; fload 22; fload 23
invokestatic java/math/VectorMath, dpps, ({Ljava/math/VectorF4;FFFF} 
{Ljava/math/VectorF4;FFFF}){Ljava/math/VectorF4;FFFF}
fstore 33; fstore 32; fstore 31; fstore 30

// compiler graph after intrinsic application would be something like
VdppsF4(ConvF4(10,11,12,13), ConvF4(20,21,22,23))

-- John



More information about the hotspot-dev mailing list