A SIMD “Hello World”

Let’s get you started.

You’ll need to put the macstl library where your favorite supported ompiler will find it — usually at /usr/include/, or with the appropriate -I compiler option, or just use the macstl.framework as built on Mac OS X.

Then code the following in your favorite editor or IDE:

#include <iostream>
#include <macstl/vec.h>

int main ()
{
  using namespace std;
  using namespace macstl;

  // put "Hello, World!!!" into a SIMD register
  vec <unsigned char, 16> message =
    vec <unsigned char, 16>::set <'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!', '!', '!', '!'> ();

  // output the SIMD register
  cout << message << '\n';

  return 0;
}

Compile the above with the appropriate SIMD compiler options on. For Mac OS X, it’s usually -faltivec from the command line or check Enable Altivec Extensions from Xcode. For Windows, you need to predefine the right macros __MMX__, __SSE__, __SSE2__ and/or __SSE3__.

Run the snippet and you should see:

H e l l o , W o r l d ! ! ! !

Congratulations, you’re now a fully fledged SIMD programmer.

Mon, 29 Sep 2003. © Pixelglow Software.
» vec common interface
Search
Download
Purchase
Discuss