1. 7

  2. 7

    I don’t really agree with the author’s definition of “high-level language”. By the author’s definition, as a processors become more sophisticated, C will become more and more of a high-level language. But is that actually true? The C function given here still can be compiled to a more 1-to-1 mapping of C operations to CPU instructions. But even that isn’t really satisfactory. What makes C not a high-level language isn’t about how closely the code maps to the compiled output, but it’s about how much code does one need that is irrelevant to the problem they are solving. In Haskell or Ocaml, you can make a B-line to your solution in the code, there is very little overhead for the author in solving a problem. In C there are a lot of incidental complexities. Memory management, array bounds, numerical promotions, etc. That’s what makes it low-level (IMO).

    1. [Comment removed by author]

      1. 2

        What does “execution model” mean? The C language is not specified in terms of any hardware, although the existing hardware happens to match it. But I don’t think that means C gets more high-level if you run it on a machine that doesn’t look like modern hardware. It doesn’t mean you have to write less code or can stop worrying about memory management or similar.

        Low-level and high-level are clearly pretty fuzzy concepts, I would say it’s more of a relative ordering than a point in space. Or maybe it’s a fuzzy point on a spectrum. But I would say Java is more high-level than C. Just consider all the things I don’t have to do in Java to use a Map relative to C.

    2. 3

      Loop idiom recognizing is really not a new thing; being able to convert simple loops into things like memcpy, memset, or (in this case) popcnt is a pretty old idea in compilers! I don’t really feel it has anything to do with how “high level” a language is either; usually “high level” refers to the opposite pattern, where fairly short code can perform many assembly operations, as opposed to the reverse where the compiler recognizes needlessly verbose code and simplifies it down.

      1. [Comment removed by author]

        1. 1

          I disagree, and want the compiler to do every optimization it possibly can.

          The whole point of having languages above assembly is that the programmer can write code at a higher level and ignore implementation details like, “There’s a special instruction on this architecture that implements this loop.” In 99.99% of cases, the developer doesn’t care at all, and just wants the best performance possible.

          It’s not popular to say, but by the usual definition, C is a high level language. Obviously not as high as OCaml or Haskell, but high level none the less. If a person really cares whether specific individual instructions are generated by the compiler, they should write it in assembly themselves.