2

I am writing a graphics library in C and I would like to utilize SSE instructions to speed up some of the functions. How would I go about doing this? I am using the GCC compiler so I can rely on compiler intrinsics. I would also like to know whether I should change the way I am storing the image data (currently I am just using an array of floats) - do I need to use an array of type float __attribute__ ((vector_size (16))) ?

EDIT: the type of image manipulation/processing I am interested in include affine transformations, geometry, and frequency domain filtering (Fourier analysis)

Any references or tips on how I should go about using SSE for image manipulation in C would be much appreciated.

thanks

horseyguy
  • 29,455
  • 20
  • 103
  • 145
  • You should describe what the algorithms in your library do. No need to prematurly convert everything to float... there are a lot SSE instructions which deal with char, short and int, some are specifically designed to to a typical image processing step (like MPSADBW). And do you enjoy assembly low level programming stuff and bit trickery? If not, SSE is probably not for you. – Gunther Piez Nov 29 '09 at 10:30
  • drhirsh, My library will support the standard functions like rotate, scale, shear, composites, geometry, and such. So there will be a lot of matrix work. Also I am researching frequency domain image processing (fourier transforms and such). Yes i am very interested in doing more assembly level programming, I have done a bit in the past and enjoy it :) Any tips on where I go from here to learn more about SSE and image manipulation/processing? :) – horseyguy Nov 29 '09 at 22:05
  • 1
    @banister: You may find some of the links I posted at http://stackoverflow.com/questions/1389712/getting-started-with-sse/1795196#1795196 useful in learning about SSE in general. I don't have experience with image processing though. – int3 Nov 30 '09 at 14:51

1 Answers1

2

I've been working on some image processing with SSE on Microsoft Visual C++. I've found it's easiest to align all image data (in Visual C++ that's done with _aligned_malloc and _aligned_free) right from the start. Alignment is a real pain though, that's why I only used SSE for arithmetic operations (add, subtract, dot product, those kinds of things). If I had to do more complicated things I generally just used pointers.

Ray Hidayat
  • 16,055
  • 4
  • 37
  • 43
  • heya thanks for your answer! :) However i'd like a bit more info on how you went about it:) Do you have any example code illustrating a simple operation on an image using SSE? Any tips or pitfalls i should be aware of? Were you relying on inline asm or compiler intrisics? etc :) thanks – horseyguy Nov 29 '09 at 22:35
  • 1
    Great. I used compiler intrinsics. No obvious pitfalls, make sure everything is aligned, that's all. It's difficult for me to show you example code because I made everything with C++ templates, so there are many levels of abstraction behind even a simple addition operation. I learnt off examples from CodeProject.com though, check there for some good examples. – Ray Hidayat Nov 29 '09 at 23:05