News for hackers. Stuff that matters.
Re:The cost of forsaking C by bluetomcat on Wednesday October 05, 2016 @05:11AM (#12642510)
> With multiple layers of caching and nearly a couple hundred registers in current CPUs this is far from the truth.

Add to that the aggressive optimisations performed by modern compilers and that mental model breaks completely. It may be a good conceptual model, but it's not the model under which your program actually executes.

However, even programming in assembly keeps you very "far from the truth", since modern CPUs are very complex beasts internally and that complexity is mostly not visible in the ISA.

Re:The cost of forsaking C by sigjuice on Wednesday October 05, 2016 @05:25AM (#12642558)
Yup. Caches, prefetching, NUMA, out-of-order execution, speculative execution etc.
Re:The cost of forsaking C by planteen on Wednesday October 05, 2016 @08:17AM (#12643147)
The thing about speculative execution and out of order execution to remember is that you always get the expected result from a single threaded perspective. If you throw in interrupts or threads, you know you must tread cautiously in C.

Few things have made me more nervous in my career than seeing a ISR making use of C++ standard library features. When I asked the engineer how they were sure this was safe and worked under the covers, I was immediately dismissed as "the compiler takes care of all that." The project only ever worked at -O0 and was still buggy. The engineer blamed the hardware.

Re:The cost of forsaking C by claudius on Wednesday October 05, 2016 @10:46AM (#12644208)
> The thing about speculative execution and out of order execution to remember is that you always get the expected result from a single threaded perspective.

Could you elaborate on this? I thought at least speculative execution was handled internally in the CPU and essentially not visible to the user apart from the performance impact?

I’m not sure what you refer to as out-of-order execution, is this execution reordering within the C compiler?

> If you throw in interrupts or threads, you know you must tread cautiously in C.

Naturally, yes.

Re:The cost of forsaking C by vkuruthers on Wednesday October 05, 2016 @09:20AM (#12643539)
Ahh, blaming the hardware. A sure sign they haven't looked into their code closely.
Re:The cost of forsaking C by johncolanduoni on Wednesday October 05, 2016 @09:10AM (#12643474)
You're right as far as results, but both can still mess significantly with performance even when everything is single threaded.