
The PowerPC Compiler Writer's Guide (1996) [pdf] - tjalfi
https://cr.yp.to/2005-590/powerpc-cwg.pdf
======
tjalfi
(submitter)

Henry Warren, the author of Hacker’s Delight[0], is one of the authors of this
book.

Chapters 3, 5, and Appendix D have some neat examples of bit twiddling code in
Power assembly language.

The content overlaps with that of Hacker’s Delight and Bit Twiddling Hacks[1].

[0]
[https://en.wikipedia.org/wiki/Hacker%27s_Delight](https://en.wikipedia.org/wiki/Hacker%27s_Delight)

[1]
[https://graphics.stanford.edu/~seander/bithacks.html](https://graphics.stanford.edu/~seander/bithacks.html)

------
classichasclass
Great document for those with an interest in PowerPC assembly and still
generally applicable to modern Power ISA. Some of these code sections appear
in the TenFourFox JIT to this day.

~~~
ndesaulniers
I just fixed an inline assembly bug in LLVM for PPC Linux kernel support:
[https://reviews.llvm.org/D81767](https://reviews.llvm.org/D81767)

I tried to see if this doc had anything about calling conventions for 64b
parameters on 32b ILP32, but alas...(at least a cursory skim of `A.1 Procedure
Interfaces` came up empty).

Another fun fact I learned about PPC assembly for that bug is that without
`-mregnames`, it can be hard to distinguish between registers and constants in
compiler generated PPC assembly. Official docs from IBM
([https://developer.ibm.com/technologies/linux/articles/l-ppc/](https://developer.ibm.com/technologies/linux/articles/l-ppc/))
say "Get used to it. :)" LOL

~~~
classichasclass
What was your question on the parameters? Is this SysV or PowerOpen ABI?

~~~
ndesaulniers
I've heard of OpenPower, but PowerOpen? I guess SysV since we're referring to
Linux (though I'm not sure that the kernel strictly adheres to SysV).

~~~
classichasclass
For 32-bit PowerPC, PowerOpen is the ABI used in PPC Mac OS and OS X (largely,
with a couple minor differences) and AIX. The System V ABI is pretty much
everything else, but it's really a misnomer since the *BSDs on 32-bit PowerPC
use SysV too.

PowerOpen is still a thing for 64-bit, see
[https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-
elf64abi-...](https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-
elf64abi-1.9.html)

As memory serves me, on 32-bit you would pass a 64-bit value in adjacent
32-bit registers in big-endian fashion.

------
pmiller2
FYI: [https://www.eejournal.com/article/ibm-gives-away-powerpc-
goe...](https://www.eejournal.com/article/ibm-gives-away-powerpc-goes-open-
source/)

You could, in theory, run code generated by your own compiler on a PPC chip
you designed and built with your own hands and brain.

Random thought: would it be feasible to implement PPC on an FPGA, as has been
done with RISC V?

Anyone know offhand what’s the most powerful PPC system you can readily buy?
I’m guessing it’s one of the PPC Mac machines.

~~~
puetzk
I don't know if there's something either higher up that you'd qualify as "can
readily buy", but a [Raptor
blackbird]([https://www.raptorcs.com/content/BK1B01/intro.html](https://www.raptorcs.com/content/BK1B01/intro.html))
would handily outclass the legacy PPC macs, and a [Talos 4U
server]([https://secure.raptorcs.com/content/TL2SV2/purchase.html](https://secure.raptorcs.com/content/TL2SV2/purchase.html))
(with two CPUs up to 22 cores each) would pretty much crush it.

Admittedly the latter is a $15k machine, which is perhaps may be pushing what
you had in mind for "can readily buy", but it's for sale...

~~~
classichasclass
This 16-core (2x8) Talos II is around $8ish-K, which is still a lot, but I
feel I got my money's worth out of it. 64 threads is good times (each core is
SMT-4). I run a "stripper" spec for the Blackbird, which was an experiment to
see how low it could go; it came to around $2100, but I would advise going a
little higher spec than I did (single-4, no GPU).

The T2 is a great machine, though. There's just no comparison to the Quad G5
sitting next to it. It's quieter, it uses less power and it doesn't feel like
I'm lacking for CPU. I got a lot of wear out of the G5 and I'll never get rid
of it, but if you don't need 32-bit and/or to run OS X on the metal, the best
Power workstation is a Raptor.

------
archi42
Aaaah, the Power ISA... If you want to "rotate left immediate speculatively if
condition matches additionally push sign bit on the stack and zero extend the
next register unless it has an odd value", this is the most likely
architecture to do that for you ;-) At least its the one I most often need to
take a look at the manual what slxwimzus (or something like that) _exactly_
does when looking at disassembly. Of course luckily most compilers don't do
the freaky stuff, so I'm probably quite lucky :)

~~~
perl4ever
Copying something quoted on HN ~4yrs ago:

"IBM has a well-known disdain for vowels, and basically refuses to use them
for mnemonics (they were called on this, and did "eieio" as an instruction
just to try to make up for it)."

\- Linus Torvalds, 2009

~~~
archi42
I could swear it also has a `mkitso` mnemonic.

~~~
perl4ever
Don't think so.

There is "stfsux" though.

I like rlwinm which takes _five_ arguments. It can do so many things there are
like 12 alternative mnemonics for simplicity.

[https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/as...](https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/assembler/idalangref_32bit_rtate_shift.html)

------
stmw
This is a great book that is good to see preserved and available in PDF form.
A lot of this is applicable to other architectures, and gives a good view into
how compiler engineers think..

