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.
1. Choose the right SPU intrinsic for data conversion.
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.
2. Align your pointers correctly.
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.
3. Align your declared vectors correctly.
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.
5. Allocate aligned pointers correctly.
If you are not sure about the alignment of data on the PPE, use memalign or posix_memalign to allocate an aligned pointer from the heap; use memcpy or an equivalent to move the data to the aligned area.
6. Watch for missing prototype messages.
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.
7. Store effective addresses correctly.
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.
9. Declare scalar values as vectors and pointers.
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.
10. Watch for floats and doubles.
Be aware that on the SPE, floats and 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.
Learn
-
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.
Programming Tutorial.
-
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).
-
The
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
developerWorks Cell
Broadband Engine resource center: your definitive resource for all
things Cell/B.E.
-
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.
Discuss
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.



