altivec
Has any progress been made on LinuxPPC Altivec support? I posted a while back and there was some discussion, I wondered if anyone was taking it further. I suppose the arrival of G4 Macs in a few weeks' time will help kickstart things. It would be great if AIM took the lead in this sort of work...
The issues as I remember them:
.. saving/restoring altivec registers (there's sample machine
code for one of the ABIs in the Altivec documentation)
.. support in egcs for the Altivec C language extensions,
hopefully C++ also (someone said they had patches supplied by Motorola, but I've not found mention of these on the Motorola SPS site so I assume they're not for general consumption)
There was some talk of trapping an illegal instruction interrupt in Altivec-compiled code on non-Altivec processors and then emulating it in software, but as I recall this was thought to be maybe impossible (due to limited information about the illegal instruction and limits on what you can do in the trap) or more effort than it's worth.
In the meantime to learn more about Altivec I've been working on a library to emulate the instructions in software (with appropriate #defines for the language extensions in a header). If anyone's interested e-mail me and I'll let you know if/when I'm done; I'm hoping to get the bulk of it done this weekend. (It'll be C++ I'm afraid - the vector types lend themselves nicely to a template class, and a lot of the vec_* instructions are overloaded).
--
sacha varma : system simulation ltd : [email protected]
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 6 lines · Sacha Varma
There was some talk of trapping an illegal instruction interrupt in Altivec-compiled code on non-Altivec processors and then emulating it in software, but as I recall this was thought to be maybe impossible (due to limited information about the illegal instruction and limits on what you can do
in the trap) or more effort than it's worth.
This is possible since Apple provides an emulator for developers (it's an extension that you drop in your MacOS system folder and which traps the illegal instruction interrupt).
Quoted 9 lines
In the meantime to learn more about Altivec I've been working on a library to emulate the instructions in software (with appropriate #defines for the language
extensions in a header). If anyone's interested e-mail me and I'll let you know
if/when I'm done; I'm hoping to get the bulk of it done this weekend. (It'll be
C++ I'm afraid - the vector types lend themselves nicely to a template class, and a lot of the vec_* instructions are overloaded).
If your library can be turned into plain C, then we should be able to implement the same emulation mecanism in Linux, but is it really interesting ? It will be way too slow to be useful for anything but developers prototyping Altivec code on G3s.
Signature · 6 lines
Perso. e-mail: <mailto:[email protected]> Work e-mail: <mailto:[email protected]> BenH. Web : <http://calvaweb.calvacom.fr/bh40/> ** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 5 lines · Sacha Varma
In the meantime to learn more about Altivec I've been working on a library to emulate the instructions [...] (It'll
be C++ I'm afraid - the vector types lend themselves nicely to a template class, and a lot of the vec_* instructions are overloaded).
Quoted 4 lines
If your library can be turned into plain C, then we should be able to implement the same emulation mecanism in Linux, but is it really interesting ? It will be way too slow to be useful for anything but developers prototyping Altivec code on G3s.
The main reason I'm doing it is to learn about what's available in Altivec. But I guess it would also be useful (some of these are pretty far-fetched but hey) for:
1. (as you say) People who don't yet have a G4
We outside the US are subject to its export laws. Who knows when we'll see them here in the UK.
2. Those who don't yet have an Altivec compiler
I don't want to develop under MacOS (MPW, MrC) and, as a hobbyist, can't justify $375 for CodeWarrior, and I don't have the knowledge to patch up gcc and the Linux kernel.
3. People who want code that's optimised for G4 but also builds on G3 You could use the altivec API when coding and then have a header (as I do) with:
#ifndef __VEC__
/* software emulation */
#else
/* use native instructions */
#endifGranted, maybe my library - which isn't written with performance considerations in mind - will be much slower than ditching the altivec API and re-writing your code, but the principle seems sound: portability with virtually no code changes.
4. People who like the Altivec API
Maybe you dig the Altivec API but code for another platform. You could even dive in and replace the core of the library with MMX or whatever where possible.
5. People who want to know what a particular instruction does They could browse the library source code. I'm not saying that my library will be correct (I admit I don't fully understand what some of the instructions do, e.g. the saturated ones) but hopefully it would eventually be. And the code might be clearer than the sometimes terse descriptions in the Altivec documentation.
6. If Altivec is extended in the a future incarnation
Ok I'm clutching at straws here, but maybe new instructions will be added down the line; if a library exists which is easily extended, people would be able to get start using them pretty much right away.
--
sacha varma : system simulation ltd : [email protected]
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
urlich drepper put a lot of work into glibc2.1 and processor capabilities for exactly this problem.
so the RIGHT way to do this is by having two dynamic libraries, one for g4 and one for processors without altivec. the libraries just have to be put in different places; glibc's search path is defined dynamically based on processor capabilities so the appropriate shared library is linked in.
also, we can avoid the problem of binaries that blow up because they were compiled for a different powerpc.
the assembler needs to know the new opcodes.
the kernel needs to know how & when to stack and unstack the altivec registers.
for capabilities, i suspect we just need a little kernel work so the kernel identifies altivec capability and makes that info available; then glibc will need to know the symbolic name to look for.
the tough part will be designing a shared library and abstracting its entry points with an eye on performance both with and without simd capability. this is a problem that transcends altivec--it is relevant to simd processor extensions on other architectures too.
Quoted 7 lines
3. People who want code that's optimised for G4 but also builds on G3 You could use the altivec API when coding and then have a header (as I
#ifndef __VEC__ /* software emulation */ #else /* use native instructions */#endif
Brad
[email protected] | http://www.pht.com/~brad/
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
i should have explained this more. the library can't be abstracted at the level of "multiply these numbers..." it would have to be abstracted at a much higher level, such as "perform a single-precision fft up to frequency q" with a mathematician devising what high-level operations are useful.
Quoted 4 lines
the tough part will be designing a shared library and abstracting its entry points with an eye on performance both with and without simd capability. this is a problem that transcends altivec--it is relevant to simd processor extensions on other architectures too.
Brad
[email protected] | http://www.pht.com/~brad/
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 2 lines · Brad Midgley
the kernel needs to know how & when to stack and unstack the altivec registers.
To really do Altivec vector regs save/restore efficiently will require cooperation between kernel and compiler. Altivec architecture defines a VRSAVE register, which is just a general purpose 32-bit wide bitmask. The intention is for compiler to record usage of altivec registers in the prologue of every function which uses them. Likewise, the epilogue is supposed to restore VRSAVE to the caller's state. Of course, hand- written assembly routines have to play by the same rules.
This approach permits saving/restoring the absolute minimum number of vector unit regs, and [perhaps more importantly] only when the interrupted
thread was truly using them.
A less ambitious approach which doesn't require the compiler to mock with
VRSAVE would be to allow the kernel to discover whether a particular process
uses the vector unit by "faulting" in the vector unit enable bit in MSR for
each process individually.
Cheers, Vitaly.
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Sacha Varma writes:
Sacha> Has any progress been made on LinuxPPC Altivec support? I posted a while back Sacha> and there was some discussion, I wondered if anyone was taking it further. I Sacha> suppose the arrival of G4 Macs in a few weeks' time will help kickstart things. Sacha> It would be great if AIM took the lead in this sort of work...
Sacha> The issues as I remember them:
Sacha> .. support in egcs for the Altivec C language extensions, Sacha> hopefully C++ also (someone said they had patches supplied Sacha> by Motorola, but I've not found mention of these on the Sacha> Motorola SPS site so I assume they're not for general Sacha> consumption)
Apple apparently has a version of egcs-1.1.2 with an improved
version of Motorola's AltiVec support merged in. I still have not seen any offer of these patches to the GCC maintainers (and accompanying assignment to the FSF) for inclusion in the public sources.
David
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/