For future reference, you can find many ppc instructions, including
isync, available for use as pseudo-builtins in the style of MWCW
__intrinsics() if you #include<ppc_intrinsics.h>.
Wow, didn't know about those. This is for postgreSQL and used in ppc
blocks (#ifdef __ppc__), which include linux and ibm machines. Is
ppc_intrinsics.h included in linux and xlc? Now it lives at
/usr/include/gcc/darwin/3.3/ppc_intrinsics.h.
Also, is there a good tutorial on using asm in gcc? What I've found
seems to be high level.
For example, what are "memory" or "cc" for?
I'm not aware of a good one. There is some description in the GCC
mainline documentation available online.
There are several ways to use assembly in C code with gcc.
1) You can use the cryptic GCC native syntax, e.g.:
__asm__ ( "mfspr %0, 1023" : "=r" (result ) );
This is often extremely difficult to use correctly because the format
specifiers are picky and there are a lot of possibilities. There are
other subtle necessities that need to be added for consistently correct
operation. There is no feedback when you get it wrong other than
incorrect operation, and in many cases you can get it wrong, have it
work anyway, only to fail when you change compiler revisions or tweak
other flags. It is not recommended that you go crazy with these unless
you have a lot of experience with that syntax.
2) In order to boost MWCW compatibility and ease of use, Apple added
the ppc_intrinsics.h header to map the difficult to use syntax to
Metrowerks' easy one, e.g.:
result = __mfspr( 1023 );
The macros/functions in the header should use the right format
specifiers. I don't know if this header has been pushed into mainline
gcc or not. Andrew might. However, subject to various legal
restrictions I won't claim to understand you can at least in
practice copy the header around from platform to platform and expect it
to still work as long as its PowerPC.
3) You may of course write complete files entirely in assembly using
normal methods.
4) Finally you can mix asm blocks into C as follows:
int ReadSPR1023( void )
{
register int result;
asm
{
mfspr result, 1023
}
return result;
}
Enable with -fasm-blocks.
If you run into problems with any of these methods (except (1) where it
is likely your fault ;-) please file a bug against the gcc component.
Inline assembly is not frequently used and doesn't get as thorough
battle testing as do most other compiler features.
Please note that most or all inline assembly methods typically confuse
GCC's scheduler and may cause some spectacularly bad (but correctly
operating) code generation in unfortunate cases. Thus, asm
optimizations that should speed up code may end up slowing it down.
Where possible, I'd recommend using the GCC real __builtin*s instead.
These gcc knows how to schedule. A common example would be data
prefetch hints. You could use dcbt:
__dcbt( byteOffset, address );
but better to use the builtin since gcc knows how to schedule that:
P.S. Please note that the particular mfspr asm example I've chosen
above will terminate user code with an illegal instruction exception.
This is correct. 1023 is a supervisor level SPR. I use it frequently as
a trigger to get amber -I to start sampling.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Scitech mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/scitech/email@hidden