How do compilers view SSE's built-in functions (or any)?

Some time ago I read somewhere that SSE's built-in functions are compiled into efficient machine code, because compilers treat them differently than regular functions. I wander how compilers do this and what C programmers can do to make the process easier. Are there any recommendations on how to use the built-in functions in such a way as to facilitate the work with the compiler when creating efficient machine code.

Thanks.

+8
c ++ optimization c sse intrinsics
source share
2 answers

Internal compilations before instructions presented, whether they are effective or not, depend on how they are used.

also, each compiler treats properties in a slightly different way (as well as its implementation), but GCC is open source, so you can see how they relate to SSE, Open Watcom *, LCC , PCC and TCC * are open source compilers C code, although thwey has no built-in SSE functions, they should still have built-in functions, and you can see how they handle them.

I think that what you read was related to automatic vectorization of the code, something GCC (see this ) and ICC are very good, but they are not as good as manually optimized code, at least not yet

* may have been updated with SSE support, not recently verified ...

+6
source share

Contrary to what Necrolis wrote, the insides may or may not compile with the instructions they represent. This is especially true for copy or load instructions, such as _mm_load_pd , since the compiler is still responsible for register allocation and allocation using built-in tools. This means that copying a value from one place to another may not be necessary at all if two locations can be represented by the same register. In this case, the compiler may choose to delete the copy. He can also choose to delete other instructions if the result is not used.

Check out this blog post where the behavior of different compilers is compared in practice. This is from 2009, so the details may no longer apply. However, newer compilers are more likely to optimize your code more, not less.

As for the actual use of the built-in functions, the answer will be the same as for any other performance optimization: measurement, measurement and measurement. Make sure that you are actually dealing with the hot part of the code, find out why it is slow, and then improve it. You will most likely find that improving memory access patterns is more important than using built-in functions.

+4
source share

All Articles