Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ usage of special CPU features

Tags:

c++

sse

mmx

I am curious, do new compilers use some extra features built into new CPUs such as MMX SSE,3DNow! and so?

I mean, in original 8086 there was even no FPU, so compiler that old cannot even use it, but new compilers can, since FPU is part of every new CPU. So, does new compilers use new features of CPU?

Or, it should be more right to ask, does new C/C++ standart library functions use new features?

Thanks for answer.

EDIT:

OK, so, if I get all of you right,even some standart operations, especially with float numbers can be done using SSE faster.

In order to use it, I must enable this feature in my compiler, if it supports it. If it does, I must be sure that targeted platform supports that features.

In case of some system libraries that require top performance, such as OpenGL, DirectX and so, this support may be supported in system.

By default, for compatibility reasons, compiler doesen´t support it, but you can add this support using special C functions delivered by, for example Intel. This should be the best way, since you can directly control wheather and when you use special features of desired platform, to write multi-CPU-support applications.

like image 788
B.Gen.Jack.O.Neill Avatar asked May 17 '10 21:05

B.Gen.Jack.O.Neill


People also ask

What is a CPU made of?

CPUs are made mostly of an element called silicon. Silicon is rather common in earths crust and is a semiconductor. This means that depending on what materials you add to it, it can conduct when a voltage is applied to it. It is the 'switch that makes a CPU work.


2 Answers

gcc will support newer instructions via command line arguments. See here for more info. To quote:

GCC can take advantage of the additional instructions in the MMX, SSE, SSE2, SSE3 and 3dnow extensions of recent Intel and AMD processors. The options -mmmx, -msse, -msse2, -msse3 and -m3dnow enable the use of these extra instructions, allowing multiple words of data to be processed in parallel. The resulting executables will only run on processors supporting the appropriate extensions--on other systems they will crash with an Illegal instruction error (or similar)

like image 131
Brian Agnew Avatar answered Oct 08 '22 21:10

Brian Agnew


These instructions are not part of any ISO C/C++ standards. They are available through compiler intrinsics, depending on the compiler used.

For MSVC, see http://msdn.microsoft.com/en-us/library/26td21ds(VS.80).aspx

For GCC, you could look at http://developer.apple.com/hardwaredrivers/ve/sse.html

AFAIK, SSE intrinsics are the same between GCC and MSVC.

like image 38
rotoglup Avatar answered Oct 08 '22 21:10

rotoglup