Live data from Hacker News

C Is Not a Low-Level Language

queue.acm.org

291–300 of 326 posts

Re: C Is Not a Low-Level Language

#291

Ok, w/o dipping into machine code, show me a low level language. Any snippet of C-code is transparent in that you know roughly how it is going to be translated into machine code.

literally the whole point of the article was that this isn't true any more

Re: C Is Not a Low-Level Language

#292

Earlier quoted context omitted.

> cost of cache misses How is the C memory model a leaky abstraction here? What better way do you suggest? Are we not fine coding sequential (in memory) datastructures in C?

How about a different example entirely? Memory nowadays is either CPU (and the GPU can access it) or GPU (and the CPU has a window into it). It's terribly important to use the right one: if a chunk of memory is mostly used by the CPU, it needs to be CPU memory, and if it's mostly used by the GPU, it needs to be GPU memory. But there's no good way to specify that. You might argue that a modern computer is more like pr…

Still, what you normally do and can assume is that you're using just "CPU" memory with pretty predictable (I think) latencies and a transparent caching layer.

When different things are mapped into the address space, that's an abstraction the programmer (or the user) consciously made. It should be possible to figure out the performance characteristics there.

Of course, many programs work on various machines with their own performance characteristics. You should still be able optimize for any one of them by querying the hardware and selecting an appropriate implementation. If you want to put in the work.

I don't think assembler/C is such a big problem here. But then again, I'm not a low level guy (in this sense) for now.

Re: C Is Not a Low-Level Language

#293

This article makes some valid points but is overall rather misleading I think. Almost all of the reasons given why C is "not a low-level language" also apply to x86/x64 assembly. Register renaming, cache hierarchies, out of order and speculative execution etc are not visible at the assembly / machine code level either on Intel or other mainstream CPU architectures like ARM or Power PC. If C is not a low level languag…

> Register renaming, cache hierarchies, out of order and speculative execution etc are not visible at the assembly / machine code level

Cache hierarchies are directly accessible with CLFLUSH, INV, WBINVD x86 instructions; we may count also PREFETCHx, but they call it "a hint". FENCE instructions touch even the multicore part of system.

Many low-level CPU concepts leak to higher layer. A bright example is false sharing, which may manifest even in Java or C# programs.

Re: C Is Not a Low-Level Language

#294

Earlier quoted context omitted.

C cannot read the overflow bit after an ADD, because of it's abstractions ... so I would say modern ASM is still lower in some aspects because it has less constrains and more importantly, it is less expressive, which is the whole idea of this hierarchy. The compiler should offer a macro for that. Then the question is whether to take the specification or the implementation at which point it's an absurd question to beg…

> C cannot read the overflow bit after an ADD ... The compiler should offer a macro for that. If you use GCC then __builtin_add_overflow() is what you are looking for: "The compiler will attempt to use hardware instructions to implement these built-in functions where possible, like conditional jump on overflow after addition, conditional jump on carry etc." https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins…

Yes, I know that. Y ou could add macros implementing a complete asm language to become a subset of C and C would still be more expressive

Re: C Is Not a Low-Level Language

#296

Earlier quoted context omitted.

It's just practical. Otherwise how do you call java ? Or python ? And what would be the benefit of changing those particular sementics ? In french we define such article as "fucking a fly".

Java and Python are much closer to C than C is to assembly. Managing memory and raw pointers are nothing. Try implementing a recursive function call in x86 assembler to get a real idea of low level.

> Try implementing a recursive function call in x86 assembler to get a real idea of low level.

Isn't that pretty easy? Recursion is just a function calling itself, directly or indirectly.

Here's the simplest possible recursive function in x86 assembler. It simply causes a stack overflow.

  recursion:
    call recursion
That's it.

Tail recursive version would be simply a jump:

  recursion:
    jmp recursion
Here's the simplest terminating version I could think of:

  recursion:
    dec eax
    jz rec_exit
    call recursion
  rec_exit:
    ret

Re: C Is Not a Low-Level Language

#297
post #70

Earlier quoted context omitted.

I played a little bit with gpgpu on the raspberry pi. I’d imagine it’s relativly primitive compared to whatever shaders are compiled to on modern GPUs, but it was humbling to have to manage things like separate, per core, disjoint register files which can only be read 4 cycles after write. The cores are heterogeneous, so there is special hardware for exchanging register reads between cores if necessary.

What language do you use for GPGPU?

Sounded like Videocore 4 assembler.

Re: C Is Not a Low-Level Language

#298

>403 Error - Access Forbidden We are sorry ... ... but we have temporarily restricted your access to the Digital Library. Your activity appears to be coming from some type of automated process. To ensure the availability of the Digital Library we can not allow these types of requests to continue. The restriction will be removed automatically once this activity stops. We apologize for this inconvenience. Please contac…

Could it be the influx of traffic with the same referral link that tripped some defense mechanism?

Re: C Is Not a Low-Level Language

#299

>403 Error - Access Forbidden We are sorry ... ... but we have temporarily restricted your access to the Digital Library. Your activity appears to be coming from some type of automated process. To ensure the availability of the Digital Library we can not allow these types of requests to continue. The restriction will be removed automatically once this activity stops. We apologize for this inconvenience. Please contac…

It's still on after 9 hours from the OP. I suppose someone in ACM management is obsessed with their intellectual property being stolen, including their public articles. Good luck to them.

Re: C Is Not a Low-Level Language

#300

I really really liked this article, and reading the comments here is blowing my mind. Did we read the same thing? I think it's a strong insight that insight that chip designers and compiler vendors have spent person-millenia maintaining the illusion that we are targeting a PDP-11-like platform even while the platform has grown less and less like that. And, it turns out, with things like Spectre and the performance co…

I think the bigger take away for me is that what constitutes low level has evolved over time. I still think C is low level because you have to manage your own memory and can play tricks with pointers and memory that other languages protect you from. Meaning that low level takes off a lot of the training wheels. The compiler still does what it can and optimizes things but you have a far greater ability to shoot yourself in the foot than in some other language. The arguments about what a "real" low level in these comments seem mostly pedantic.
Post reply on HN