Divide by 10 using bit shifts?

Editor’s note: this is not actually what compilers do, and gives the wrong answer for large positive integers ending with 9, starting with div10(1073741829) = 107374183 not 107374182 (Godbolt). It is exact for inputs smaller than 0x40000005, though, which may be sufficient for some uses. Compilers (including MSVC) do use fixed-point multiplicative inverses for constant … Read more

Which is faster: x

Potentially depends on the CPU. However, all modern CPUs (x86, ARM) use a “barrel shifter” — a hardware module specifically designed to perform arbitrary shifts in constant time. So the bottom line is… no. No difference.

Why do you program in assembly? [closed]

I think you’re misreading this statement: For example, many modern 3-D Games have their high performance core engine written in C++ and Assembly. Games (and most programs these days) aren’t “written in assembly” the same way they’re “written in C++”. That blog isn’t saying that a significant fraction of the game is designed in assembly, … Read more

How do I create a “spacer” in a C++ class memory structure?

How about a C++-ish way? namespace GPIO { static volatile uint32_t &MAP0_MODER = *reinterpret_cast<uint32_t*>(0x4000); static volatile uint32_t &MAP0_OTYPER = *reinterpret_cast<uint32_t*>(0x4004); } int main() { GPIO::MAP0_MODER = 42; } You get autocompletion because of the GPIO namespace, and there is no need for dummy padding. Even, it is more clear what’s going on, as you can … Read more

Why is vectorization, faster in general, than loops?

Vectorization (as the term is normally used) refers to SIMD (single instruction, multiple data) operation. That means, in essence, that one instruction carries out the same operation on a number of operands in parallel. For example, to multiply a vector of size N by a scalar, let’s call M the number of operands that size … Read more

How exactly does the callstack work?

The call stack could also be called a frame stack. The things that are stacked after the LIFO principle are not the local variables but the entire stack frames (“calls”) of the functions being called. The local variables are pushed and popped together with those frames in the so-called function prologue and epilogue, respectively. Inside … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)