Keep these following ten tips in mind when you want to code C applications for the Cell Broadband Engine SPU. For more on vector intrinsics, see "Programming on the Cell/B.E. processor, Part 5," the article from which this tip was taken.
Vectors can be cast between vectors of other types, as well as back-and-forth between the vector types and the special
quad type, but none of these casts perform any data conversion. If you need to convert between types, use an appropriate SPU intrinsic.
Vector and non-vector pointers can be cast between each other, but when converting from a scalar pointer to a vector pointer it is the programmer's responsibility to be sure that the pointer is quadword-aligned.
Declared vectors are always quadword-aligned when allocated.
Remember that DMA transfers of 16 bytes or more must be in 16-byte multiples and aligned to 16-byte boundaries on both the SPE and the PPE. Transfers smaller than that must be a power of two and be naturally aligned. Optimal transfers are multiples of 128 bytes that are on 128-byte boundaries.
If you are not sure about the alignment of data on the PPE, use
posix_memalign to allocate an aligned pointer from the heap; use
memcpy or an equivalent to move the data to the aligned area.
Always compile with
-Wall; pay special attention to missing prototype messages. Incorrectly implied prototypes (especially between 32- and 64-bit types) can lead to bizarre error conditions.
Always store effective addresses as
unsigned long longs on both the PPE and the SPE. This way they can be treated in a unified fashion on the SPE and on the PPE whether the PPE code is compiled for 32-bit or 64-bit execution.
Avoid integer multiplies (especially 32-bit multiplies) on the SPE. It takes five instructions to perform the multiply. If you must multiply, cast to an
unsigned short before multiplying.
In scalar code on the SPE, declaring scalar values as vectors and vector pointers (even if you aren't using them as vectors) can speed up code because it doesn't have to do unaligned loads and stores.
Be aware that on the SPE,
doubles are implemented differently; they round differently as well.
floats in particular deviate from the C99 standard. (More on this in the article "Smart buffer management with DMA transfers.")
The entire series, Programming on the Cell/B.E. processor , is an excellent resource for programming the processor.
The full set of intrinsics is documented in the PPU
& SPU C/C++ Language Extension Specification.
Another (more extended) tutorial resource for Cell/B.E. programming on both
the SPE and the PPE is the official Cell/B.E.
For a complete list of available DMA commands on the MFC, see chapter 7
of the Cell/B.E. Architecture Specification (1.01) and pages 508-510 of the Cell/B.E. Programming Handbook (1.0).
For more information on DMA list commands, see pages 51-62, 124-125,
129-130, and 157-158 of the Cell/B.E. Architecture Specification (1.01) and pages 73, 459-460, 509-510, and 527-530 of the Cell/B.E. Programming Handbook (1.0).
The transfer class ID and replacement class ID fields for MFC operations
is described on pages 78 and 114 of the Cell/B.E. Architecture Specification (1.01) and pages 155-158, 455-456, and 513-515 of the Cell/B.E. Programming Handbook (1.0).
IBM Semiconductor Solutions Technical Library
Cell Broadband Engine
documentation section contains a wealth of downloadable manuals,
specifications, and much more.
Find all Cell/B.E.-related articles, discussion forums, downloads,
and more at the IBM
Broadband Engine resource center: your definitive resource for all
The IBM microNews newsletter delivers Cell/B.E happenings to your desktop twice a month.
Get products and technologies
Get Cell/B.E. solutions: Contact
IBM about custom Cell/B.E.- or custom-processor-based solutions.
Get the alphaWorksCell
Broadband Engine downloads -- including the IBM Full System Simulator,
support libraries, toolchains, and source code for libraries and samples.
Jonathan Bartlett is the author of the book Programming from the Ground Up which is an introduction to programming using Linux assembly language. He is the lead developer at New Medio, developing Web, video, kiosk, and desktop applications for clients.