How much overhead can the -fPIC flag add?

It turns out that when you compile without the -fPIC option multiplyComplex, sqComplex, isInSet and isMandelbrot are inlined automatically by the compiler. If you define those functions as static you will likely get the same performance when compiling with -fPIC because the compiler will be free to perform inlining. The reason why the compiler is … Read more

Where can I find an official reference listing the operation of SSE intrinsic functions?

As well as Intel’s vol.2 PDF manual, there is also an online intrinsics guide. The Intel® Intrinsics Guide contains reference information for Intel intrinsics, which provide access to Intel instructions such as Intel® Streaming SIMD Extensions (Intel® SSE), Intel® Advanced Vector Extensions (Intel® AVX), and Intel® Advanced Vector Extensions 2 (Intel® AVX2). It has a … Read more

How to force GCC to assume that a floating-point expression is non-negative?

You can write assert(x*x >= 0.f) as a compile-time promise instead of a runtime check as follows in GNU C: #include <cmath> float test1 (float x) { float tmp = x*x; if (!(tmp >= 0.0f)) __builtin_unreachable(); return std::sqrt(tmp); } (related: What optimizations does __builtin_unreachable facilitate? You could also wrap if(!x)__builtin_unreachable() in a macro and call … Read more

generates same number in Linux, but not in Windows

Here’s what’s going on: default_random_engine in libstdc++ (GCC’s standard library) is minstd_rand0, which is a simple linear congruential engine: typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> minstd_rand0; The way this engine generates random numbers is xi+1 = (16807xi + 0) mod 2147483647. Therefore, if the seeds are different by 1, then most of the time the first … Read more

Difference between CC, gcc and g++?

The answer to this is platform-specific; what happens on Linux is different from what happens on Solaris, for example. The easy part (because it is not platform-specific) is the separation of ‘gcc’ and ‘g++’: gcc is the GNU C Compiler from the GCC (GNU Compiler Collection). g++ is the GNU C++ Compiler from the GCC. … Read more

Compiling an application for use in highly radioactive environments

Working for about 4-5 years with software/firmware development and environment testing of miniaturized satellites*, I would like to share my experience here. *(miniaturized satellites are a lot more prone to single event upsets than bigger satellites due to its relatively small, limited sizes for its electronic components) To be very concise and direct: there is … Read more