News for hackers. Stuff that matters.
Re:C Is Not a Low-Level Language by admax88q on Tuesday May 01, 2018 @12:18PM (#16968435)
> If C is not a low level language then a low level language does not exist for modern CPUs

I think that's a fair conclusion though, I don't think the article is misleading.

x86 assembly is a high level language. It's analogous to JVM bytecode. Modern x86 processors are more like a virtual machine for x86 bytecode.

Re:C Is Not a Low-Level Language by magduf on Tuesday May 01, 2018 @02:07PM (#16969642)
>x86 assembly is a high level language. It's analogous to JVM bytecode.

If you take this position, then having the distinction between "low level" and "high level" languages becomes pointless, and we have no way to distinguish between languages like x86 assembly and C and languages like Python and Haskell. This is why we use the terms "low level" and "high level": some of these languages have a lower level of abstraction than others. The fact that it's not giving you a great idea of exactly what's happening in the transistors is irrelevant: "low" and "high" are relative terms, not absolute.

Re:C Is Not a Low-Level Language by munificent on Tuesday May 01, 2018 @03:47PM (#16970760)
> The fact that it's not giving you a great idea of exactly what's happening in the transistors is irrelevant

The author's point is that what's happening in the transistors is relevant — not controlling it is what led to Spectre and heavy performance losses if you aren't smart about cache usage. Thinking of C as a "low-level language" makes it easier for people to overlook that fact.

Re:C Is Not a Low-Level Language by ori_b on Tuesday May 01, 2018 @04:12PM (#16971027)
And the parent's point is that there should be a distinction in level between Haskell and C, for example.
Re:C Is Not a Low-Level Language by Avshalom on Tuesday May 01, 2018 @05:22PM (#16971796)
Then we need a finer grained taxonomy instead of the current model that is essentially: machine code;c/forth; literally everything else.

I mean that should be blindingly obvious anyway looking at the actual history of programming languages and CPUs but here we are in 2018 insisting that we must have exactly three categories with exactly the definitions of: assembly;C/forth; everything else.

Re:C Is Not a Low-Level Language by ninkendo on Tuesday May 01, 2018 @01:40PM (#16969321)
It's a fair conclusion if you're willing to accept that the phrase "low-level language" has approximately zero modern examples.

Or maybe we should relax the definition of "low-level language" a bit?

Re:C Is Not a Low-Level Language by scott_s on Tuesday May 01, 2018 @02:05PM (#16969612)
I think the author of the article is willing to accept that, and it's part of his point. The point is not to label languages, but to illuminate how we ended up with our current combination of software and hardware design. He points out that we are in a local-maximum with respect to processor performance because most of the optimizations we've made in processor design the past few decades break the C abstract machine. That requires the compiler and processor to go through awkward contortions to present the fiction of that abstract machine while still getting good performance. The final section, "Imagining a Non-C Processor", is where he explores this idea.
Re:C Is Not a Low-Level Language by namibj on Tuesday May 01, 2018 @02:14PM (#16969712)
Take a look at maxas [0], and the maxwell/pascal microarchitecture if you want a modern example of low-level language (iirc. they are still manufactured on small mainstream process nodes).

[0] https://github.com/NervanaSystems/maxas

Re:C Is Not a Low-Level Language by jrochkind1 on Tuesday May 01, 2018 @01:45PM (#16969369)
Hmm, what does "virtual machine" mean if the "virtual machine" is implemented in hardware?

And, is nothing but actual binary machine code a "low level language"? I guess it's the lowest, I don't _think_ you can go lower than that... but someone's probably gonna tell me I'm wrong.

Re:C Is Not a Low-Level Language by ummonk on Tuesday May 01, 2018 @02:23PM (#16969815)
VHDL / Verilog is lower level!

In all seriousness, the "assembly is high level" argument is ridiculous and robs the "low level" vs "high level" categorization of all meaning.

Re:C Is Not a Low-Level Language by Avshalom on Tuesday May 01, 2018 @05:27PM (#16971841)
Taxonomies have been rendered meaningless constantly throughout history, fighting it is usually fighting reality.
Re:C Is Not a Low-Level Language by jrochkind1 on Tuesday May 01, 2018 @04:50PM (#16971462)
Perhaps C is a "medium-level language"? :)
Re:C Is Not a Low-Level Language by mikepurvis on Tuesday May 01, 2018 @12:49PM (#16968773)
The JVM provides native primitives around memory and thread management which are not present in x86, but that's a matter of degree.
Re:C Is Not a Low-Level Language by fixermark on Tuesday May 01, 2018 @01:33PM (#16969242)
x86 provides all sorts of memory abstractions. The whole memory segmentation model is an abstraction. https://en.wikipedia.org/wiki/X86_memory_segmentation
Re:C Is Not a Low-Level Language by pvg on Tuesday May 01, 2018 @12:29PM (#16968567)
It's analogous to JVM bytecode.

That's only true in the way everything is analogous to everything.

Re:C Is Not a Low-Level Language by chubot on Tuesday May 01, 2018 @12:40PM (#16968669)
I think it's a good analogy because it's saying that nontrivial optimizations happen below the code layer.

In early CPUs, nothing was optimized. They just executed your instructions. Now there are nontrivial optimizations and rewriting, just like the JVM.

Re:C Is Not a Low-Level Language by coldtea on Tuesday May 01, 2018 @12:40PM (#16968677)
Nope, also in the way the parent explains right after that sentence.
Re:C Is Not a Low-Level Language by pvg on Tuesday May 01, 2018 @12:49PM (#16968774)
It's a pretty terrible analogy in nearly every obvious technical way. What an x86 cpu does with its instructions is almost but not entirely unlike what a JVM does.
Re:C Is Not a Low-Level Language by admax88q on Tuesday May 01, 2018 @01:10PM (#16968978)
None of the "registers" in x86 assembly are real. Few of the instructions are implemented in hardware, most are impelmented in software microcode.

Advanced hardware will re-order and pipeline instructions based upon data dependencies.

Sure it's not doing the exact same things the JVM does with bytecode but the point is that x86 assembly is not the language of the hardware. It's a language that the hardware+firmware knows how to interpret and optimize at runtime similar to what your JVM does with java bytecode.

Re:C Is Not a Low-Level Language by pvg on Tuesday May 01, 2018 @01:27PM (#16969180)
It isn't at all similar. JVM bytecode is a pretty high-level IR for tokenized Java. The JVM's main unit of optimization is a method, not instructions. Its key component is a compiler, it's even called that.

An x86 cpu, as the article points out, spends inordinate resources looking for ILP. It's not a compiler in any reasonable sense of the word, while a JVM is.

Re:C Is Not a Low-Level Language by admax88q on Tuesday May 01, 2018 @02:13PM (#16969701)
The point I'm trying to make with the analogy is that the x86 instruction set is not representative of what the hardware is actually doing.

It is not "low level" because it is an abstraction or virtual platform that the processor exposes and then interprets using its own internal resources and programming interface (microcode). The x86 interface does not map closely to the actual hardware, just as the article states. It exposes a flat memory model with sequential execution and only a handful of registers.

Much the same way that the JVM exposes a virtual machine that doesn't directly map to any of the platforms that it runs on. It's an abstraction that is interpreted or compiled at runtime.

I don't understand why you think the two are so different just because the JVM is higher level.

Re:C Is Not a Low-Level Language by pvg on Tuesday May 01, 2018 @03:23PM (#16970511)
Right, and the point I'm trying to make is this is a pretty lousy analogy. For one thing, an x86 CPU is not nearly as VM-y as you make it out - renamed registers are very much real registers, big piles of the most common instructions execute in 1 or 2 uOps. For another, the VM you've picked as an example is singularly uncpu-like. C also exposes an abstract machine, would you use that as an analogy? Probably not.

'An abstraction that is interpreted or compiled at runtime' is so broad it's exactly the what I said up top - it's analogous in the way everything is analogous to everything else. It's the sort of thing that might be true if you squint but offers somewhere between zero and negative insight.

Re:C Is Not a Low-Level Language by admax88q on Tuesday May 01, 2018 @03:46PM (#16970745)
I don't know I think you're getting caught up too much on the specifics of what they're doing.

CPU's are adopting JIT like tendencies in order to increase performance. Instruction reorder, register renaming, branch prediction, etc.

> if you squint but offers somewhere between zero and negative insight.

The insight I bring from this is that we should look moving those features out of the hardware and into the software level. Let us take advantage of them in our compilers and virtual machines.

The JVM can beat C in many scenarios because it can make optimizations based upon runtime information that a static compiler will never have available.

Imagine what we could do if we weren't chained to the x86 abstractions.

Re:C Is Not a Low-Level Language by gpderetta on Tuesday May 01, 2018 @06:17PM (#16972236)
OoO, renaming, branch prediction, microcode have existed for a long time. If anything, more modern CPUs (x86 included) are RISCer than the older generations which had extensive microcode expansion for each instruction.

Even ignoring the fact that the JVM is typed, memory safe and with builtin GC (all things that were tried architecturally in the past and abbandoned), there is still a large difference between the scope and variety of non-local optimizations perfomed by any non-toy VM and the local, strictly realtime, constrained to a small window, set of reordering done by an OoO engine. Even tracing, which is used by some JITs, has been largely abbandoned in the CPU world.

Transmeta and Denver-like dynamic translation is closer to the behaviour of a software JIT and it is certainly considered drastically different from mainstream OoO.

Re:C Is Not a Low-Level Language by pvg on Tuesday May 01, 2018 @09:21PM (#16973326)
"x86 is an architecture hobbled by its legacy ISA, the CPUs are immensely complex VM-like dynamic beasts that hide the real CPU to get performance out of it" is one of those tropes that's inaccurate enough to have a small cottage industry of online pieces explaining the wrong bits. You can probably find highly rated SO answers or HN comments about it.

The long and the short of it is, an x86 cpu is not really VM-like and a JVM is decidedly unCPU like. The analogy only works if you generalize it so much it becomes a uselessly mushy tautology or you ignore basic aspects of how each of these things work.

Re:C Is Not a Low-Level Language by coldacid on Tuesday May 01, 2018 @01:56PM (#16969497)
`javac` is a compiler. The JVM is an execution platform, just like modern x86.
Re:C Is Not a Low-Level Language by pvg on Tuesday May 01, 2018 @02:00PM (#16969563)
What's the word that comes after 'JIT'?
Re:C Is Not a Low-Level Language by coldtea on Tuesday May 01, 2018 @05:29PM (#16971866)
What the word is not really important.

JITting is also called "dynamic translation", which is what a CPU does with microcode.

Whether that's a full compiler or not is beyond pedantic -- and irrelevant to the parent's point.

Re:C Is Not a Low-Level Language by pvg on Tuesday May 01, 2018 @08:47PM (#16973167)
The parent is telling me how the JVM doesn't have a compiler, which was my claim. It has a couple full-blown compilers.

which is what a CPU does with microcode.

Either you know something about current x86 CPUs that I don't or words and technical terms are, indeed, not important and have no meaning.