Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable the SSE4.2 instruction set in Visual C++?

I am using the BRIEF descriptor in OpenCV in Visual C++ 2010 to match points in two images.

In the paper about the BRIEF-descriptor is written that it is possible to speed up things:

"The BRIEF descriptor uses hamming distance, which can be done extremely fast on modern CPUs that often provide a specific instruction to perform a XOR or bit count operation, as is the case in the latest SSE instruction set."

With SSE4.2 enabled it should be speeded up. My questions is simply how I do this in Visual C++?

An alternative way could be to choose another compiler supporting SSE4. For instance Intel's ICC. Is this really necessary?

like image 435
Fredrik Avatar asked Jan 16 '23 22:01

Fredrik


1 Answers

Unfortunately, it doesn't work like that.

The C/C++ compiler may be told to use a specific instruction set in project-> C/C++ -> Code generation->Enable enhanced instruction set. But it does almost nothing, and in your case, absolutely nothing. That's because some CPU instructions cannot be easily accessed from C statements. Some compilers (like Intel's) are better at this than others, but for what you want to achieve, no compiler is smart enough.

What you have to do is to find the specific algorithm, learn the SSE instructions and rewrite the algorithm with those instructions manually. You can write in pure assembly, or use intrinsic functions, which can be called from C/C++, and will issue SSE instructions when compiled.

like image 111
Sam Avatar answered Jan 28 '23 16:01

Sam