Earlier quoted context omitted.
Even binary code isn't "how the computer works" these days.
Never has been. Deep down 1's and 0's are still analog voltages, subject to capacity and inductance, on a tiny wire between transistors. Without proper timing you end up reading the voltage half way between ascending from 0 to 1 and who knows what value you end up with.
“C is how the computer works” is a dangerous mindset for C programmers
141–150 of 387 posts
Re: “C is how the computer works” is a dangerous mindset for C programmers
#142Earlier quoted context omitted.
Not really, assembly language is extremely close to microcode, much much closer than it is to C. C has a whole bunch of baggage like pointer provenance, inability to read uninitialized memory, doesn't understand cache aliasing, etc that don't fit hardware well.
No, it really isn't on anything modern, like ARM SoCs or x86 CPUs. The number of times I've hit my head to wall trying to understand what the heck the CPU is doing for a given sequence of instructions, like why the number of cycles or memory bandwidth required is way different from my expectation. A modern CPU willy nilly reorders instructions, stores, and creates new "virtual" registers out of thin air to dissolve s…
One of those only worth of time to learn as hardware engineers, but understanding both of them will give you an introduction to Spectre vulnerability.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#143Earlier quoted context omitted.
M............................................C M..............................................Java Look. C is much closer to how the machine (M) works.
Give that Java is written in C++ which is in turn an extended version of C, I'm not sure that chart is entirely to scale.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#144Earlier quoted context omitted.
Pseudo-code: a = 10; b = 20; c = b + 30; bar = a + b; x = 1; y = 2; z = y + 3; foo = x + y; ... in order to remove dependency stalls might be executed as: b = 20; y = 2; a = 10; x = 1; c = b + 30; z = y + 3; bar = a + b; foo = x + y; This would still be true, even if 'x' and 'a', 'y' and 'b' etc. variables (well, registers) had same name. In that case CPU would just make up new "variables" as required and do the same…
This has nothing to do with microcode. It doesn't even have anything to do with microops. Reordering instructions (likely register renaming or load-store forwarding here, though the pseudo C code doesn't let me determine) is just part of how the processor retires instructions.
On x86, a lot of instructions are close matches, yet some are removed entirely (say "xor eax, eax") or fused into one micro-op, (like "cmp #123, eax / je ").
Future CPUs might even do some data flow analysis to optimize code even further.
Say speculative "constant" folding based on runtime profile to remove chunks of code from hot inner loops.
Or to replace longer instruction patterns with HW optimized implementation, if that's what it takes to get some extra performance for the next year's model.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#145Earlier quoted context omitted.
>inability to read uninitialized memory printf("%x", *(int*)0x12345678);
This is not a well-defined C program though.
In short, how much does the concept of a "well-defined C program" differ from the concept of a "C program" as implemented in practice? Can we say that most C programs, or even a medium-sized percentage of C programs, are well-defined?
Re: “C is how the computer works” is a dangerous mindset for C programmers
#146Earlier quoted context omitted.
No, it really isn't on anything modern, like ARM SoCs or x86 CPUs. The number of times I've hit my head to wall trying to understand what the heck the CPU is doing for a given sequence of instructions, like why the number of cycles or memory bandwidth required is way different from my expectation. A modern CPU willy nilly reorders instructions, stores, and creates new "virtual" registers out of thin air to dissolve s…
You are mixing up how branch prediction works with how processing unit works. One of those only worth of time to learn as hardware engineers, but understanding both of them will give you an introduction to Spectre vulnerability.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#147Earlier quoted context omitted.
According to Wikipedia, C is named C because it resulted from work done by Dennis Ritchie to improve the language B, and C comes after B. B came from Ken Thompson making a cut down version of the language BCPL, so he just kept the first letter. https://en.wikipedia.org/wiki/C_(programming_language)
It almost implies that at the time, they realized a plethora of languages would emerge but were hoping everyone would stick with their alphabetic convention. Instead, someone skipped straight to S, someone else stepped back to R, and then everyone said screw it and started making up their own funny names & acronyms. I've read some intriguing things about D, though (which came along more recently, interestingly enough…
Re: “C is how the computer works” is a dangerous mindset for C programmers
#148Earlier quoted context omitted.
Not really, assembly language is extremely close to microcode, much much closer than it is to C. C has a whole bunch of baggage like pointer provenance, inability to read uninitialized memory, doesn't understand cache aliasing, etc that don't fit hardware well.
Microcode is not used for the majority of operations. Are you confusing it with micro-ops?
Re: “C is how the computer works” is a dangerous mindset for C programmers
#149Earlier quoted context omitted.
Pseudo-code: a = 10; b = 20; c = b + 30; bar = a + b; x = 1; y = 2; z = y + 3; foo = x + y; ... in order to remove dependency stalls might be executed as: b = 20; y = 2; a = 10; x = 1; c = b + 30; z = y + 3; bar = a + b; foo = x + y; This would still be true, even if 'x' and 'a', 'y' and 'b' etc. variables (well, registers) had same name. In that case CPU would just make up new "variables" as required and do the same…
Okay, you're talking about OoO execution here, and you're right that this can be hard to reason about (in terms of stalls/latencies), however that's orthogonal to microcode translation.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#150There's the computer, and then there's the computer, and then there's the computer and then there's the computer: The computer is the thing that has the web browser running on it. The computer is the thing that has the code editor running on it. The computer is the thing that has the compiler running on it. The computer is the thing that provides a virtual hardware interface for running programs. The computer is the…
There's the c1(physical computer), and then there's the c2(os runtime), and then there's the c3(silicon) and then there's the c4(turing machine): The c1 is the thing that has the web browser running on it. The c1 is the thing that has the code editor running on it. The c1 is the thing that has the compiler running on it. The c2 is the thing that provides a virtual hardware interface for running programs. The c3 is th…
I wasn't being super-precise with my comment, and my point is that there is no one thing that "is the computer". There are many computers in your computer, and many definitions of what a computer is.
I've never had to go below the HAL, or inside the JIT, but to some people that's where "the" computer really is. If that's where the computer really is, then I'm not a computer programmer (HINT: I'm not, but I do write code sometimes and get paid for it).
So if I write code, but it doesn't tell the computer what to do, what am I even doing?
Well, I write code that gets consumed by pre-processors and lexers and parsers and compilers and linkers and build agents and I don't know how the soup works, and you probably don't either, you may know more or less of the of the alpha-bits in the soup, but it's still soup. The soup is turned into jello and fed to a virtual machine, which is a fake computer, but it works well enough.
---
If I were to be more precise, I would say that there's a von Neumann machine C0 that is represented by some hardware abstraction layer C1 by a operating system kernel. There may be a virtual machine C2 running in the C1 context.
But, inside that C0 von Neumann machine there are a bunch of microprocessors that may be called computers that may have Turing complete instruction sets.
---
Or you could say, anything that can be Turing complete is a computer, in which case your web browser is a computer (among many others).