4 ms·
How does new instructions, register renaming, etc work with different compilers? Say I'm using Visual Studio to compile C++, will it take advantage of the new p
by sorenjan 7y ago
How does new instructions, register renaming, etc work with different compilers? Say I'm using Visual Studio to compile C++, will it take advantage of the new processor features by default? What about if the binary runs on a different CPU, will the compiler include feature checks and multiple code versions?
- horyzen 7y agoNot sure about VC++, but in gcc you can use -march=native to let the compiler compile the code with all instruction sets available on your CPU, I think there is a VC++ equivalent. As for already compiled binary, depending on how it was compiled it may or may not work of a different CPU. Also the compiler doesn't do the runtime checks.
- jjuhl 7y agoGCC can do Function Multi Versioning (https://gcc.gnu.org/wiki/FunctionMultiVersioning https://gcc.gnu.org/wiki/FunctionMultiVersioning , https://lwn.net/Articles/691932/ https://lwn.net/Articles/691932/) where it will generate code for multiple CPUs and select the best at run time.
- ken 7y agoAIUI, register renaming is a runtime feature of the microcode and has nothing to do with the machine language interface.
- mhh__ 7y agoCorrect. The compiler can be trained to utilise it efficiently but it's not a exposed feature
- opencl 7y agoGCC and LLVM have supported multiple code versions based on feature detection for a few years, they call it function multiversioning. As far as I'm aware MSVC does not have this yet.
- wahern 7y agoGCC has supported it for over 6 years, since 4.8. It was only added to clang in 7.0, released 8 months ago.
- fulafel 7y ago"new instructions" and "register renaming" are on opposite sides of the spectrum. It's up to your compiler to carch up with insn set additions, but register renaming is invisible.
- holy_city 7y agoRE new instructions, those appear to be mostly useful for things running on bare metal (like the OS kernel). The under the hood stuff like true 256 bit registers, branch prediction, cache, etc, all is below the machine code level as other people have pointed out. The compiler doesn't know about it. >What about if the binary runs on a different CPU, will the compiler include feature checks and multiple code versions? This is referred to as multiple/dynamic code paths and it needs to be supported by the processor microarchitecture and compiler. afaik only the Intel Compiler and Intel processors support it with the <code>-ax</code> compilation flag. In general you should pick a minimum architecture for your applications, since it will be forward compatible.