How to detect SSE/SSE2/AVX/AVX2/AVX-512/AVX-128-FMA/KCVI availability at compile-time?

Most compilers will automatically define: __SSE__ __SSE2__ __SSE3__ __AVX__ __AVX2__ etc, according to whatever command line switches you are passing. You can easily check this with gcc (or gcc-compatible compilers such as clang), like this: $ gcc -msse3 -dM -E – < /dev/null | egrep “SSE|AVX” | sort #define __SSE__ 1 #define __SSE2__ 1 #define … Read more

Suppress warning “Category is implementing a method which will also be implemented by its primary class”

Although everything bneely said is correct, it doesn’t actually answer your question of how to suppress the warning. If you have to have this code in for some reason (in my case I have HockeyKit in my project and they override a method in a UIImage category [edit: this is no longer the case]) and … Read more

In CMake, how can I test if the compiler is Clang?

A reliable check is to use the CMAKE_<LANG>_COMPILER_ID variables. E.g., to check the C++ compiler: if (CMAKE_CXX_COMPILER_ID STREQUAL “Clang”) # using Clang elseif (CMAKE_CXX_COMPILER_ID STREQUAL “GNU”) # using GCC elseif (CMAKE_CXX_COMPILER_ID STREQUAL “Intel”) # using Intel C++ elseif (CMAKE_CXX_COMPILER_ID STREQUAL “MSVC”) # using Visual Studio C++ endif() These also work correctly if a compiler wrapper … Read more

How to generate assembly code with clang in Intel syntax?

As noted below by @thakis, newer versions of Clang (3.5+) accept the -masm=intel argument. For older versions, this should get clang to emit assembly code with Intel syntax: clang++ -S -mllvm –x86-asm-syntax=intel test.cpp You can use -mllvm <arg> to pass in llvm options from the clang command line. Sadly this option doesn’t appear to be … Read more

Clang doesn’t see basic headers

This is because g++ is not installed, so libstdc++ is not present. You can install g++, or if LLVM is preferred, install LLVM libc++ and specify that you want to use it, like so: sudo apt-get install libc++-dev clang++ -stdlib=libc++ <rest of arguments> You may wish to link /usr/bin/c++ to the default compiler: ln -s … Read more

How to use clang with mingw-w64 headers on windows

The correct thing to do, is this… clang -target i686-pc-windows-gnu test.c -otest.exe Or if you want 64bit output… clang -target x86_64-pc-windows-gnu test.c -otest.exe Clang will determine the location of the headers and libraries from your path. Make sure that you only have the version of Mingw in your path that you are targetting. By default, … Read more