Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Tech tips: Ten helpful tips when building SPE applications in C

Make this your top ten list for vector-based Cell/B.E. SPU application development

Jonathan Bartlett (johnnyb@eskimo.com), Director of Technology, New Medio
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.

Summary:  These ten tips can save you a lot of trouble when you're coding your C applications for the Cell Broadband Engine™ (Cell/B.E.) SPU.

View more content in this series

Date:  05 Jun 2007
Level:  Intermediate

Activity:  8038 views
Comments:  

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.

4. DMA transfers

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.

8. Avoid integer multiples.

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.")

But wait! There's more.

The entire series, Programming on the Cell/B.E. processor , is an excellent resource for programming the processor.


Resources

Learn

Get products and technologies

Discuss

About the author

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.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Multicore acceleration
ArticleID=228617
ArticleTitle=Tech tips: Ten helpful tips when building SPE applications in C
publish-date=06052007
author1-email=johnnyb@eskimo.com
author1-email-cc=dwpower@us.ibm.com