[macstl-dev] Comments, help for macstlizer
Glen Low
glen.low at pixelglow.com
Thu Jun 23 08:45:25 WST 2005
Hi All,
Folks, I'd like some comments and help on macstlizer, which is a
feature of the soon-to-be-released macstl 0.3 -- I'm currently in the
midst of documenting it, it should be out on Monday.
macstlizer is a sed script and C++ header file designed to ease an
Altivec programmer's transition to SSE. At the end of the day, your
single SIMD source should compile and run in both Intel and PowerPC
worlds. This is not a panacea like Rosetta claims to be -- I of all
people know there are Altivec opcodes that simply have no good
equivalent SSE equivalents -- rather, it's a plan that maintains your
source code quality and compilability on PowerPC, and uses the
compiler to guide your transition to the brave new world of Mactel.
1. The sed script, altivec2macstl.sed, translates Altivec C code
into the equivalent macstl C++ code. After running the script and
some code cleanup, your translated source should still compile and
run correctly in PowerPC.
2. The header altivec2mmx.h provides inline versions of some
Altivec intrinsics as SSE. Compiling the code on Intel should
highlight only the opcodes that need to be ported, and the templated
inline functions assure you of full performance otherwise. This
should allow you to focus on the smaller part of your Altivec code
that needs work.
3. When you've successfully made the final code cross-platform,
you can then run Shark etc. on the result to see if you need to
revisit any of the inline functions.
I don't think a pure C inline function and/or macro-based solution
will work, because:
1. Altivec has a stronger type system than SSE. Converting all
your __vector ints to __m128i, you then have to be careful to always
treat it as a vector of 4 ints and not a vector of 8 shorts for example.
2. Altivec has a distinct vector initialization syntax. This will
bite especially for Codewarrior users who have to use the Motorola-
style ( ) syntax, whereas gcc users can still use { } on both PowerPC
and Intel and get the same syntax -- although the weak type system in
SSE will hit you again, since you will have to cast back to the
public type of __m128i to use the intrinsics at all.
3. Altivec has overloaded intrinsics, SSE doesn't. Either you have
to manually and carefully translate each vec_add into a _mm_add_ps or
_mm_add_epi16, or you have to use a language with overloading like C++.
4. Both Altivec and SSE intrinsics have literal (constant)
parameters e.g. vec_sld. These cannot be modelled using C (__inline)
functions at all, since the parameter must be a compiler constant.
Using C macros has it own dangers e.g. repeated evaluation of macro
parameters.
The macstlizer solution addresses all of these points -- comments,
suggestions are welcome.
=== HELP WANTED ===
To test out the sed script and general scheme, I need suitable chunks
of Altivec C source code to test against. Please email me off-list
with a .c file with Altivec codes in it, preferably something in
production already, don't worry I'm not about to steal your code :-).
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
aim: pixglen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pixelglow.com/lists/archive/macstl-dev/attachments/20050623/d56e1a4d/attachment.html
More information about the macstl-dev
mailing list