0

I want to use the MMX instruction set to optimize my Linux C program, which does lots of operations on images stored in RGB format (each RGB component is stored in an unsigned char). The operations are trivial: I subtract one image from the other pixel by pixel, and accumulate the sum of the absolute values of the differences. (basically, I have a small image, or pattern, and I'm trying to find if that pattern exists in a larger image).

I know this can be coded in assembly language using the MMX instructions to do the individual byte operations in SIMD fashion. However, is there an easier way? Maybe a library, or a higher-level interface that uses the MMX instructions?

JB_User
  • 3,117
  • 7
  • 31
  • 51
  • Have you seen this project? [libjpeg-turbo](http://libjpeg-turbo.virtualgl.org/) – ryyker Aug 25 '13 at 16:31
  • Well, thanks for your help, but I don't think that has anything to do with my question. :) – JB_User Aug 25 '13 at 16:48
  • Actually, this page is a good concise description and example of how to incorporate MMX instructions into a GNU C code: http://vast.uccs.edu/~tboult/frame/Boult/linux-mmx.html – JB_User Aug 25 '13 at 16:49
  • Try the Intel IPP libs, they have linux versions, and internally use the SIMD instructions. Unfortunately it's a payware SDK (free redistribs), but you can install and use it for awhile without buying anything. – Chris O Aug 25 '13 at 17:08
  • Aren't the Intel C compilers free for non-commercial use? – JB_User Aug 26 '13 at 16:20

1 Answers1

0

Normally there is a header you #include, usually called something like intrinsics.h. This page shows how to use MMX with C. It #includes the file emmintrin.h. Maybe that file exists in Linux?

Also, if you're working on hardware that's remotely recent, you probably want to use at least SSE, if not SSE2. I believe they can be included in a similar way.

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • Yes, I have a very recent CPU. Should I use SSE2 instead of the MMX instructions? This might be a lot easier because I use instructions like _mm_add_pi8() directly from C. Is that equivalent to coding MMX instructions in assembly language? – JB_User Aug 26 '13 at 14:55