Vector primitives in high level languages?

There's something I've been pondering for quite some time yet have never come up with a satisfactory answer. How come no major high level language (C, C++, Java, C#) supports vector primitives? After all how long have we had MMX, SSE, 3DNow, etc...

I know that compilers have a hard time with auto vectorization, but at the same time the languages aren't providing for manual vectorization either. It seems like the only way to make use of these instructions is to write assembly, and that's not really palatable for myself (and I assume MANY MANY other developers).

It also seems like languages like Java and C# would have the easiest time with this since they can compile a high-level representation into the latest and greatest version supported by the processor.
 
C++ does support vector primitivies without assembly trough intrinsics, but it is compiler and platform specific due to the glacial speed the C++ standard moves. That is probably a good thing in this case tough since vectorization is such a low-level feature and there are many differences with it on the the different platforms.

But you can do this at least:

Code:
#if defined(DICE_XENON)
	typedef __vector4 Vec;
#elif defined(DICE_WIN32)
	typedef __m128 Vec;
#elif defined(DICE_PS3)
	struct Vec
	{
		vector float v;
	};
#endif

And then define your own functions such as:

Code:
Vec dot3(VecRef u, VecRef v);
Vec dot4(VecRef u, VecRef v);
Vec cross(VecRef u, VecRef v);
Vec operator+(VecRef r1, VecRef r2)

That can then be efficiently implemented using platform specific intrinsics such as

Code:
#ifdef DICE_WIN32
__forceinline Vec operator+(VecRef r1, VecRef r2)
{
	return _mm_add_ps(r1, r2);
}
#elif defined(DICE_XENON)
__forceinline Vec operator+(VecRef r1, VecRef r2)
{
	return __vaddfp(r1, r2);
}
#elif defined(DICE_PS3)
__forceinline Vec operator+(VecRef r1, VecRef r2)
{
	Vec t;
	t.v = vec_add(r1.v, r2.v);
	return t;
}
#endif

So it isn't that much of a problem if you have the resources to create your own library, which isn't very difficult to do.
 
The advantage of them being first class types though would be that the compiler could do basic constant folding and trivial optimisations, the same way it does with float expressions.
 
The advantage of them being first class types though would be that the compiler could do basic constant folding and trivial optimisations, the same way it does with float expressions.


And on top of that, I would very much like the JIT languages to support this, because then the latest version of SIMD instructions available in the users processor can be used, all with very little if any work on the developers end.
 
Back
Top