Skip to contentSkip to conversation

Altivec and binary compatibility

DISCUSSION Adrian Cox 2 participants 7 messages Feb 4, 2000 – Feb 20, 2000 2 messages not in the archive

lore
Share & tools
lore

Adrian Cox

author
#0 lore raw

Altivec raises an interesting question of binary compatibility, in the area of C++ exceptions and C setjmp/longjmp.

As the jmp_buf is a different size in Altivec and non-Altivec code, it is not possible to jump or pass exceptions between the two. This is a problem, because:
1) Now would not be a good time to change the size of a jmp_buf.
2) We do not need two incompatible 32-bit PowerPC ABIs under Linux. 2a) Most libraries installed by a distribution will be non-Altivec code, to avoid having both G[123] and G4 binary variants of the distribution.

To add to the problem, throwing exceptions on an error is just what a modern C++ library is supposed to do. Throwing or catching an exception in Altivec code will produce sequences that cannot execute on a G3 (which is precisely what got me considering this).

Does anybody have any bright ideas, beyond ensuring that everybody restricts the use of Altivec compilation to routines which only call safe functions? As long as Altivec code requires the vector keyword, that's probably a reasonable assumption.

- Adrian Cox, AG Electronics

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 6 lines

Altivec raises an interesting question of binary compatibility, in the area of C++ exceptions and C setjmp/longjmp.

As the jmp_buf is a different size in Altivec and non-Altivec code

Because with Altivec we need to save V registers, right ? Well, I suppose intel developers had the same problem with P-III "vector" unit. How did they solve the problem ?

Quoted 6 lines

it is not possible to jump or pass exceptions between the two. This is a problem, because:
1) Now would not be a good time to change the size of a jmp_buf.
2) We do not need two incompatible 32-bit PowerPC ABIs under Linux. 2a) Most libraries installed by a distribution will be non-Altivec code, to avoid having both G[123] and G4 binary variants of the distribution.

I agree.

Quoted 3 lines

To add to the problem, throwing exceptions on an error is just what a modern C++ library is supposed to do. Throwing or catching an exception in Altivec code will produce sequences that cannot execute on a G3

Why ?? (sorry for my ignorance...)

Bye.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

author
#2 lore raw

Giuliano Pochini wrote:

Quoted 5 lines · Giuliano Pochini
Quoted 1 line

As the jmp_buf is a different size in Altivec and non-Altivec code

Because with Altivec we need to save V registers, right ? Well, I suppose intel developers had the same problem with P-III "vector" unit. How did they solve the problem ?

As far as I can tell, by ignoring it, and making the assumption that only low-level libraries will use the vector registers. I plan to take a similar approach, and warn users not to mix Altivec and exceptions.

Quoted 5 lines
Quoted 3 lines

To add to the problem, throwing exceptions on an error is just what a modern C++ library is supposed to do. Throwing or catching an exception in Altivec code will produce sequences that cannot execute on a G3

Why ?? (sorry for my ignorance...)

I haven't studied GCC's implementation of exceptions in great detail. The compiler saves and restores all the non-transient registers as part of the exception sequence. When generating Altivec code this produces stvx and lvx instructions, which will cause an illegal instruction exception on G3 processors.

- Adrian Cox

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#3 lore raw
Quoted 8 lines
Quoted 5 lines

Because with Altivec we need to save V registers, right ? Well, I suppose intel developers had the same problem with P-III "vector" unit. How did they solve the problem ?

As far as I can tell, by ignoring it, and making the assumption that only low-level libraries will use the vector registers.

mm :-/

Quoted 4 lines

I plan to take
a similar approach, and warn users not to mix Altivec and exceptions.

From altivec p. e. m.: "1.2.6 - The AltiVec vector unit never generates an

exception"

I just started to read the book, but I think AltiVec tells nothing even on things like divisions by 0, etc.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

To add to the problem, throwing exceptions on an error is just what a modern C++ library is supposed to do. Throwing or catching an exception in Altivec code will produce sequences that cannot execute on a G3

Why ?? (sorry for my ignorance...)

I haven't studied GCC's implementation of exceptions in great detail. The compiler saves and restores all the non-transient registers as part of the exception sequence. When generating Altivec code this produces stvx and lvx instructions, which will cause an illegal instruction exception on G3 processors.

Ok, the programmmer will have to check for AltiVec at the beginning of the program. What's really important is that programs compiled for 603, 604, G3, will work fine on G4.

Bye.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

author
#4 lore raw
Quoted 5 lines · Giuliano Pochini

From altivec p. e. m.: "1.2.6 - The AltiVec vector unit never generates an exception"

I just started to read the book, but I think AltiVec tells nothing even on things like divisions by 0, etc.

C++ exceptions, not machine exceptions:

if (failure()) thow Oops();

- Adrian Cox, AG Electronics

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#7 lore raw
In reply to a message not in the archive
Quoted 7 lines
Quoted 6 lines

This is not correct. OS's on P-III have to be updated to provide proper
context switch support for the SSE registers. I'm pretty sure Win98 has it covered. It's really the same type of jump as AltiVec - use of SSE features is not restricted to OS or driver code, apps use them too.

Quoted 7 lines

I know that the OS has to support these registers. Latest development kernels *DO* support them.

That is not the problem.

The problem is with C++ exception sequences and setjmp being different for Altivec and non-Altivec code.

IMHO C++ exceptions are not a problem. All objects are destroyed when a function exits with an exception and it's an exit without return. The thrown object is put on the stack (I think) and the calling code will handle it. Obviously you can't mix code compiled for Altivec and code compiled for plain PPC if they exchange data with exceptions, jumps and friends.

Quoted 1 line

How does Linux on ia32 handle linking between generic ia32 and Pentium-III user-space code ?

No idea... It's likely an unsolved issue yet.

Bye.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#8 lore raw
In reply to a message not in the archive
Quoted 7 lines
Quoted 6 lines

This is not correct. OS's on P-III have to be updated to provide proper
context switch support for the SSE registers. I'm pretty sure Win98 has it covered. It's really the same type of jump as AltiVec - use of SSE features is not restricted to OS or driver code, apps use them too.

Quoted 7 lines

I know that the OS has to support these registers. Latest development kernels *DO* support them.

That is not the problem.

The problem is with C++ exception sequences and setjmp being different for Altivec and non-Altivec code.

IMHO C++ exceptions are not a problem. All objects are destroyed when a function exits with an exception and it's an exit without return. The thrown object is put on the stack (I think) and the calling code will handle it. Obviously you can't mix code compiled for Altivec and code compiled for plain PPC if they exchange data with exceptions, jumps and friends.

Quoted 1 line

How does Linux on ia32 handle linking between generic ia32 and Pentium-III user-space code ?

No idea... It's likely an unsolved issue yet.

Bye.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/