r/programming • • May 01 '18

C Is Not a Low-level Language - ACM Queue

https://queue.acm.org/detail.cfm?id=3212479
152 Upvotes

303 comments sorted by

239

u/Sethcran May 01 '18

Argue all you want about what defines a high level or a low level language... But most people look at this relatively.

If c is a high level language, what the hell does that make something like JavaScript or F#?

If c isn't a low level language, what is below it? Most programmers these days don't touch any form of assembly anymore.

So yea, this is true depending on your definition of these words, but people will continue to refer to c as a low level language because, relative to the languages most of us actually know and use, it's one of the lowest.

76

u/imperialismus May 01 '18

But most people look at this relatively.

That is indeed what the author starts out by saying: imagine a spectrum where assembly is on one end and the most advanced computer interface imaginable is on the other. Then he goes on to talk about out of order execution and cache and how they don't map to C even though assembly has no concept of OoO or cache either.

101

u/yiliu May 01 '18

So really what he's saying is that C is a low-level language...for a different (and much simpler) system than what your code is actually running on. What you're actually running on is kind of a PDP-11 hardware emulation layer on top of a heavily-parallelized multi-core architecture with complex memory and cache layouts. Maintaining that hardware emulation layer is becoming a burden, and is starting to result in exploits and regressions.

10

u/munificent May 03 '18

Maintaining that hardware emulation layer is becoming a burden

I think a better way to describe it is that it's an increasingly leaky abstraction. And those leaks are becoming so bad that we should consider whether it's even the right abstraction to use anymore.

9

u/Valmar33 May 02 '18

Would make a good tl;dr. :)

→ More replies (1)

23

u/lelanthran May 01 '18

Then he goes on to talk about out of order execution and cache and how they don't map to C even though assembly has no concept of OoO or cache either

I've made the same observation down below, where I was having fun with some trolls (hence got downmodded).

This article is a more a "Programming Language Problems" than a "C Language Problems" article. I'm not sure what the author's intention was to deride C for having all these problems when literally every other language, including assembly, has these problems because these are processor problems.


How is that a C problem as opposed to a programming language problem?

Look, I get the point that the author is trying to make WRT to spectre-type attacks, but the how is this a C problem and not a Programming Language problem?

It doesn't matter what programming language you use, you are still open to spectre. It doesn't even matter if you go off and design your own language that emits native instructions, you're still going to get hit by errors in the microcode that lies beneath the published ISA.

The only way to avoid this is to emit microcode and bypass the entire ISA entirely, at which point you can use any high level language (C included) that has a compiler that emits microcode.

Chances are, even if you did all of the above, you'd find there's no way to actually get your microcode to run anyway.

So, given the above, why does the article have such a provocative title, and why is the article itself written as if this is a C problem? It clearly isn't.

18

u/yiliu May 01 '18

I'm not sure what the author's intention was to deride C for having all these problems

He's challenging the assumption that people have that C is "close to the metal". That's definitely something people believe about C, as opposed to other programming languages, but he points out that it's no longer particularly true.

At the end of the article, the author takes a shot at suggesting some alternative approaches (Erlang-style actor model code, immutable objects, etc.

→ More replies (7)

9

u/AntiauthoritarianNow May 02 '18

I don't understand why you think this is "deriding C". Saying that something is not low-level is not saying that it is bad.

→ More replies (8)
→ More replies (15)

44

u/HeadAche2012 May 01 '18

Even using assembly is high level in this description as the processor itself will reorder and execute assembly instructions in parallel

There aren’t any low level languages, assembly is a set of instructions that must maintain data dependence ordering, but can be executed in parallel or any order desired that improves performance. Processors don’t even have x86 registers as they map and rename registers internally where data dependence allows

22

u/meneldal2 May 02 '18

Seriously, the issue is that because CPUs want to maintain backwards-compatibility, they end up messing with your machine code. It's been years since all the x86 assembly you write won't be run in the order you think it would.

You can't program the CPU directly now, only Intel and AMD can.

11

u/YumiYumiYumi May 02 '18

the issue is that because CPUs want to maintain backwards-compatibility, they end up messing with your machine code

Backwards compatibility is a reason, but not the only reason. If you were to design an ISA today, you'd still hide a lot of the underlying uArch details from the programmer's perspective, and the end result probably wouldn't be terribly different from x86.

As it turns out, the processor has a lot of runtime information that a compiler cannot determine ahead of time.
Attempts try to and expose more of the underlying pipeline, like Intel's Itanium, generally haven't proven to be that successful.

→ More replies (10)

9

u/wavy_lines May 02 '18

Did you even read the article or did you just comment off the title?

7

u/max_maxima May 01 '18

If c is a high level language, what the hell does that make something like JavaScript or F#?

Depends on the context. All three are low level compare to more higher level languages.

4

u/AlmennDulnefni May 02 '18

Must we consider LabVIEW a programming language?

18

u/takanuva May 02 '18 edited May 02 '18

You - and most people on this thread - seem to be focusing on the everyday Intel/AMD computers. Yeah, the translation of C to those is pretty straightforward. But it isn't to the JVM, for example. To the JVM and others, pointers are a high level abstraction, since it has no instructions for direct addressing. Also, to the JVM, Java is a pretty "low level" language, since it's translation to JVM's bytecode is pretty straightforward.

One may argue "but the JVM is a virtual machine", well, we do have physical implementations (e.g., Jazelle). So why "low level" would imply "closer to Intel" but not "closer to the JVM"? Closer to the random access machine instead of any other kind of register machine? What about the SECD?

Also noteworthy: the C standard gives absolutely no guarantees about direct addressing (as in int *ptr = 0xB8000), as one would expect to work in plain assembly for accessing VGA memory. Picturing C as a low level language makes programmers make bad assumptions and write undefined behavior (according to the standard, you can't even compare two pointers that didn't come from the same array with < or >... a low level language sure would allow that).

C, just like Java or JavaScript or F#, is a high level language. C is not a portable assembly.

11

u/m50d May 02 '18

If c is a high level language, what the hell does that make something like JavaScript or F#?

Also high level languages.

The point of the article is that if you ever think something like "I'll use C instead of JavaScript/F#, it'll be more work but my code will correspond exactly to machine behaviour and that will make it easy to understand the performance", that thought is wrong and you'd be better off just using JavaScript/F#. It's similar to the "it tastes bad so it must be good for me" fallacy - since C is so much harder to program in than JavaScript or F#, people assume there must be some counterbalancing benefit, but that's not actually true.

4

u/KangstaG May 02 '18

I think it's fair to look at it relatively in which case C is pretty low level. The only thing lower you can go is assembly/byte code.

If he gave a decent definition of 'low level' and contrasted it with C, then I wouldn't have too much of an issue. But he gives a fairly hand wavy definition and spends minimal time arguing why C doesn't go by this definition.

3

u/spinicist May 04 '18

In the words of a wise man I worked with a long time ago, “C is high level assembly”.

4

u/[deleted] May 01 '18

Yeah, there's no set rule book on what constitutes low or high level. If C is considered a high level language, then the only low-level language in existence is probably straight assembler. When C was first written for the PDP-11 it was a high level language. Higher levels of abstraction simply didn't exist at the time. Now, with languages like Java and Python, C feels low-level by comparison (pointers, direct access to memory, etc.)

4

u/doom_Oo7 May 02 '18

If c is a high level language, what the hell does that make something like JavaScript or F#?

Low-level and high-level is a distinction that stopped making sense in 1978. You can have javascript that looks like this and C code that looks like that.

2

u/bumblebritches57 May 04 '18

what the hell does that make something like JavaScript or F#?

What they actually are, just giant standard libraries.

→ More replies (2)

85

u/[deleted] May 01 '18

C Is Not a Low-level Language

Quite correct. C is a midlevel language. In fact C is the only language that I have ever heard of to fit that rare category. This means that, while not truly low level, as the author correctly cites, C does have a unique relationship with assembly language. C is a especially efficient systems language. It was invented solely for the purpose of porting Unix to system architectures other than PDP-11. Because of C's success at this porting of an Operating system, it has become the de facto systems language for just about every computer since. The kernels for both Linux and Windows were written in C (at least at first).

40

u/os12 May 01 '18

Right, originally K&R C was meant to be a high-level cross-platform assember replacement and the author notes that C/asm transformation for the PDP-11 was quite simple. Such days are gone though.

For a quick demonstration of what modern C++ compilers do with, say, user-defined types see this example: https://godbolt.org/g/fvbSha

23

u/irqlnotdispatchlevel May 01 '18

C++ is not a superset of C, nor is C a subset of C++.

59

u/anttirt May 01 '18

None of the differences matter for this example.

→ More replies (3)

17

u/monocasa May 01 '18

It's verrry close though.

3

u/ThirdEncounter May 01 '18 edited May 02 '18

Don't C programs compile unmodified with a C++ compiler?

Edit: So the consensus is, not except for specific cases. Thanks, all.

20

u/defnotthrown May 01 '18

Just from memory VLAs and designated initializers are the two C99 features not supported by C++.

But they're available as custom extensions in many C++ compilers (since they mostly happen to be C compilers too) and designated initializers might make it to C++20 last time I checked.

so neither int a = getchar(); int arr[a]; nor int arr[5] = { [1] =50, [4] = 30}; are valid C++, but they are valid C

10

u/MayorOfBubbleTown May 01 '18

Most of the time. Beginner C programs will but the C programming language has added new features since the early 80s when C++ was created.

8

u/dangerbird2 May 01 '18

Aside from new features in C99 that don't exist in C++, implicit type conversions are different, especially for void pointers, which act as an "escape hatch" to the C type system, but require explicit type conversions in C++. A program with the line char *buffer = malloc(10 * sizeof(char)); would compile in C, but fail to compile in C++, where you'd need to cast the malloc to char *. public headers for C libraries also need to wrap functions with extern "C" when compiled in C++, so the linker does not assume the functions have a C++ API with name mangling to support function overloading.

14

u/Charles_Dexter_Ward May 01 '18

Most would but, for example, you can have a variable named "class" or "new" in C and a C++ compiler would complain.

→ More replies (2)
→ More replies (6)
→ More replies (3)

15

u/vytah May 01 '18

Middle level languages used to be an actual category, with languages simpler than C but more advanced that assembly. They're usually called high level assemblers (although not all middle level languages fit into this category), which can have macros, structured programming support, readable syntax, decent type systems, but on the other hand most of their language constructs have a single and simple normal assembly representation.

Nowadays, there isn't much market for something that is more annoying and less portable than C, so high level assemblers are mostly just a convenience layer used by assembly programmers.

6

u/meneldal2 May 02 '18

The biggest open source projects that use assembler (x264, x265 and vpx) use macro assembler to help people keep their sanity.

You need it for the high performance code.

12

u/jerf May 01 '18

I would have to disagree. C is a low-level language, for a computer that isn't the one you're programming on, so you're really working with a simulation of that computer rather than the hardware you're really on. That doesn't make C a mid-level language... it makes it a mismatched language. For instance, C just has no concept of your GPU, which on many computers is in some sense the majority of raw computational power available from the hardware! And C just has nothing for that. It's never heard of GPUs.

(Neither do most other languages. I submit that part of that is the way that C has controlled our very conception of what a programming language is for so long that people creating new languages tend to create languages that are often "C, but with this new feature", rather than "Let's think about how to create a language that takes advantage of the CPU and the GPU together." Or "let's build a language that works with cloud abstractions and has a fundamental concept of 'a function that may not return' or something". Or any number of other interesting avenues left unexamined because A Computer Language Is Basically C With More Features.)

41

u/Isvara May 01 '18

This is like arguing over whether 3 is a small number.

16

u/JessieArr May 01 '18

It's obviously a large number. It's 300 times as big as 0.01!

5

u/eattherichnow May 02 '18

There exists a positive 𝜀 smaller than it, therefore it's not a small number.

25

u/monocasa May 01 '18

C is a low-level language, for a computer that isn't the one you're programming on, so you're really working with a simulation of that computer rather than the hardware you're really on.

That's true of every high level language though.

21

u/jerf May 01 '18

Not every high-level language claims to be an accurate representation of the hardware the way C proponents claim it to be. In fact, pretty much nothing else does. So there's no contradiction there.

→ More replies (20)

21

u/oridb May 01 '18 edited May 01 '18

C is a low-level language, for a computer that isn't the one you're programming on

This is a meme. This meme is false. The pdp11 is close enough to most modern architectures that it would not have affected the design of C too much.

There are differences, but these differences aren't exposed by the assembly language either.

For instance, C just has no concept of your GPU, which on many computers is in some sense the majority of raw computational power available from the hardware!

And yet, it runs just fine on the GPU, once you give the appropriate compiler a hint to compile the function for the GPU.

10

u/monocasa May 01 '18

This is a meme. This meme is false. The pdp11 is close enough to most modern architectures that it would not have affected the design of C too much.

To be fair, modern architectures were designed to run C well. That was the whole point of RISC, take a look at what a compiler actually emits and make a core that runs just that.

→ More replies (2)

11

u/jerf May 01 '18 edited May 01 '18

This is a meme. This meme is false. The pdp11 is close enough to most modern architectures that it would not have affected the design of C too much.

I completely disagree. For one thing, I cite the article's own listing of the differences, and the fact they are visible and relevant. Considering among those things are "multicore", we're talking some pretty fundamental differences. (C11 sort of has it, but it is clearly bolted on literally decades after the fact, not something C has any concept of.) The article isn't even complete, and this is including as monocasa points out that modern hardware is designed to be a C machine, which means that the differences aren't just "things that happened", but changes that were made despite the fact it would take the hardware farther from what C supports.

Among the other things that C doesn't account for is the importance of the memory hierarchy. It may superficially seem like C has good support for cache locality by letting you arrange structs and pack things tightly, but that's just because things like dynamic scripting languages have such poor cache locality that even C looks good. A language that was truly good with cache locality would be something like that language Jonathon Blow was prototyping that would let you use columnar arrays of data, where arrays slice horizontally on structs instead of just plopping structs down in a row, with a simple specification on the array rather than the manual implementation you'd have to do in C.

(This is another one of those things where C limits the very thoughts of language designers. This is an obvious consequence of the way modern caches work, but few languages have fiddled with this, even though it isn't even that hard, once you're writing your own language.)

And yet, it runs just fine on the GPU, once you give the appropriate compiler a hint to compile the function for the GPU.

Does it run on the GPU, or does it run on a simulation of the C standard machine running on the GPU, resulting in access to only a fraction of the GPU's capabilities?

Honest question. Last I knew you needed CUDA or something to get anything like real access to the GPU's capabilities. Since the entire point here is precisely that merely running C doesn't mean you're getting a good abstraction of your computer's capabilities, a GPU merely running C could very well be merely a more obvious version of the point I'm making about the CPU as well.

10

u/oridb May 01 '18 edited May 01 '18

I completely disagree. For one thing, I cite the article's own listing of the differences, and the fact they are visible and relevant.

Once again, if that is the case, the argument can be made that assembly is not a low level language, because these differences that the article discusses are also not reflected in assembly language. There's an argument to be made there, I suppose, but that would also imply that there is no low level language that a programmer who does not work at a CPU manufacturer can use.

Does it run on the GPU, or does it run on a simulation of the C standard machine running on the GPU, resulting in access to only a fraction of the GPU's capabilities?

It runs on the GPU in the same sense that it runs on the CPU. In many ways, it targets the GPU better than the CPU, because GPUs are exposed as scalar architectures, where vector instructions are not exposed by the ISA. Vector instructions are the biggest mismatch between C and current hardware.

→ More replies (1)
→ More replies (1)
→ More replies (10)

15

u/[deleted] May 01 '18

For any system architecture in history, the only low level language has been, and is, assembly language. Assembly language is merely the one-to-one direct association to machine language for any CPU. If you want to call C a "mixed" level language, fine. That is merely semantics. But C is not a low level language - only assembly is.

24

u/[deleted] May 01 '18

Assembly is still a high level language. The only real language is writing the op codes by hand with toggle switches. /s

13

u/monocasa May 01 '18

There was a program to do that job, an “optimizing assembler”, but Mel refused to use it.

“You never know where it's going to put things”, he explained, “so you'd have to use separate constants”.

http://www.catb.org/jargon/html/story-of-mel.html

→ More replies (1)

17

u/Chippiewall May 01 '18

Ehh.. these days even assembly wouldn't constitute a low level language. The machine code that's generated still doesn't run precisely as described. Modern CPUs perform so many optimisations at runtime in terms of instruction re-ordering, register remapping, skipping no-op instructions that even assembly doesn't fit as an accurate description of what the hardware will do.

5

u/ThirdEncounter May 01 '18

The thing is, as a programmer you have no control over how those CPU tasks are done - except, of course, if there is a bug that leads to Spectre and others. So, what does it matter if assembler does not account for such tasks?

That's like saying that you're not a true expert car driver because you can't access the steering hydraulic pump with your bare hands to control it.

→ More replies (3)
→ More replies (2)

6

u/MINIMAN10001 May 01 '18

If we want to get this stupidly nitpicky x86 assembly isn't low level because x86 is a virtual machine

→ More replies (2)

11

u/Vhin May 01 '18

This makes the term "low level languages" useless. We already have a perfectly satisfactory term to refer to assembly languages. Namely, assembly languages.

→ More replies (6)
→ More replies (4)

2

u/pdp10 May 01 '18

Lisp predates C considerably, and in 1985 was the second-most popular language after C in TIOBE (such as TIOBE is). The third was a version of Pascal, which has also been a relatively popular systems language along with C and Lisp, but was not C derived as it predated C.

Therefore we can conclude that nobody was forced by lack of alternatives to use C or to have C-influenced constructs in new languages.

C just has no concept of your GPU

It has no concept of a mouse, either, despite the mouse being invented in 1968. Use a library, just like we use a C library with inline assembler to access platform SIMD or crypto instructions. (Does the Haskell language have a concept of a mouse?)

→ More replies (1)

2

u/ThirdEncounter May 01 '18

it makes it a mismatched language.

That's true for almost every freaking programming language out there.

9

u/jerf May 01 '18

It's true for every language. It's even true for assembler nowadays, which is actually a layer presented by the CPU to make compiled C code run well on top of a platform which is actually executing micro-operations.

The difference is that most of the rest of those languages don't have people claiming that the language is a "good representation of the computer hardware". Those other languages that do are also wrong. Though assembly is as close as you can get on current hardware, so people claiming that would be most correct.

→ More replies (1)

1

u/wavy_lines May 02 '18

C is the only language that I have ever heard of to fit that rare category

How about Pascal?

→ More replies (1)

58

u/microfortnight May 01 '18

"Your computer is not a fast PDP-11."

Yes it is. I'm on a VAX 4000-60 right now.

4

u/pdp10 May 01 '18

That's a nice box. I used to own a VAX 4000. Do you have the separate data cabinet?

5

u/microfortnight May 02 '18 edited May 02 '18

I have a bunch of VAX 4000-series... some are the small "desktop" workstations and some are the bigger "mini-fridge"-sized systems. I have a couple of SCSI disk towers which are separate.

EDIT: my active VAX run OpenBSD, but I still have a couple with OpenVMS

→ More replies (4)

29

u/[deleted] May 01 '18

"Let's all argue about C" - 1999

"Let's all argue about C" - 2008

"Let's all argue about C" - 2018

"Let's all argue with the AI about C" - 2030

Please don't get all semantic on me, people. It's a joke. I don't want to argue.

14

u/Isvara May 01 '18

Creating a new thread is a library operation known to be expensive, so processors wishing to keep their execution units busy running C code rely on ILP (instruction-level parallelism).

That's not why they do that, though. Even when you have multiple threads, you still have an instruction pipeline, and the processor still has to reorder instructions if it wants to make the best use of it.

→ More replies (3)

11

u/tasminima May 01 '18 edited May 01 '18

I disagree with some key elements of the reasoning.

When Itanium was actively developed, it was competitive with x64. C compiled good enough to it, and the hardware was not in charge of speculation.

Most of what the article is about is not about C but about any classical imperative language (some very modern ones included). Key elements of what he describes also applies to assembly language for most considered architectures -- that makes me think those are not the good criteria.

GPU cores are nowadays typically programmed in a derivative of C. But despite some explained differences, this is also a model not near the execution units, in other aspects even further than CPU cores.

And I really don't see how x86 is more focused on C in contrast is UltraSPARC or abstract vectors of ARM SVE. In case of ARM SVE this is weird to think that because of a different abstraction between SW and execution units, this is a model further away to C, while in the case of OOO and renaming etc, the abstractions are supposedly there to make the C model work better on those CPU. Not only the same general ideas (abstracting away from execution units in some aspects) result in the author spirit in completely opposite situation on the model fit for C or not scale, but we have also seen plenty of times somehow similar implementations in x86 CPU of the same vector ISA vs. vector execution units width ideas.

GPU are vastly less cache coherent than CPU, yet I remind again that they are often basically programmed in C (or something with a model similar enough).

The idea of limiting the hardware to mutable or shared caches is cute, but in the general case this would make existing legacy software terrible. And I argue that this would not result in more low level software.

Should we recycle the good old idea of going the nearest possible to the execution units for general purpose tasks? I'm not sure. Most of the time dynamic transformations give better perfs, because the CPU can observe what the program does in practice, while it's less practical to do that at build time, and even when it is (rarely) done with PGO, it still can not adapt to workloads anyway.

4

u/[deleted] May 01 '18

about any classical imperative language

How many of them require byte addressing, unaligned loads (well, C does not really demand it explicitly, but too much code out there that does) and, the worst part, strict memory access ordering?

GPU cores are nowadays typically programmed in a derivative of C.

And, you know, it's very bad. It contaminated GPU architectures too.

GPU are vastly less cache coherent than CPU, yet I remind again that they are often basically programmed in C (or something with a model similar enough).

Memory model in CUDA and OpenCL is very different from C though.

but in the general case this would make existing legacy software terrible.

Good riddance, I'd say.

4

u/tasminima May 01 '18

How many of them require byte addressing, unaligned loads (well, C does not really demand it explicitly, but too much code out there that does) and, the worst part, strict memory access ordering?

Unaligned load are vastly unsupported by C, both from a theoretical and now practical pov (some major compiler will make daemon fly out of your nose even on architectures where the CPU supports them)

About the memory access ordering I believe you are talking about the well defined layout of C structs? I don't really see what kind of terrible impact it can have on CPU architecture. It's more a compiler pessimization, if any. Some non trivial projects have even succeeded in randomizing the layout of some select structs, so even the practical dep is not as high as we could imagine.

And, you know, it's very bad. It contaminated GPU architectures too.

Not really. GPU present vastly different performance characteristics compared to CPU. What is not critical to the application you can always put in slow paths, and GPU designers do so. The cost is somewhat low, because you have at a ridiculous number of transistors to play with. Or because you typically have an extra run time compile layer available, you can even completely omit some stuff from the HW and emulate it during one of the last compile stage.

Memory model in CUDA and OpenCL is very different from C though.

But nVidia has now managed to basically integrate most of the C++/C11 memory model.

Good riddance, I'd say.

Getting rid of all the existing sw we have is not realistic and this idea will not yield to successful and durable engineering at scale. Progressive transitions have become mandatory in practice. So like it or not existing sw is here to stay, and productive effort will consist in discovering how to intelligently cope with it and/or develop slightly less bad ones, over and over.

3

u/[deleted] May 02 '18

About the memory access ordering I believe you are talking about the well defined layout of C structs?

No, I'm talking about the strict order of memory reads/writes. Combined with lax aliasing rules it cripples both static and dynamic optimisation badly.

Progressive transitions have become mandatory in practice.

It depends. I find the recent trend towards unikernels reassuring - people are ready for building bespoke systems from scratch, with as little third party dependencies as possible.

1

u/[deleted] May 04 '18

One problem with Itanium was that seemingly Intel didn't have much plans to move it to more regular use.
That gave AMD an opening to extend x86 to 64bit.
And we all still suffer as a result...

6

u/balefrost May 02 '18

Link broken for anybody else?

4

u/break_the_system May 02 '18

I can get to it, but we appear to be blocked.

5

u/MayorOfBubbleTown May 01 '18

When I was a kid I used to write DOS in assembly. You could use interrupts for input and output through the operating system. Today most operating systems no longer guarantee that these interrupts will work the same between versions and they provide C libraries as the lowest level access to input and output. I'd say that currently C is a very low level language for input and output through operating system calls and many higher level programming languages can't be extended with anything lower level than a C library.

24

u/claytonkb May 01 '18 edited May 01 '18

tl;dr: We should alter history because that would somehow make it easier for us to design performant systems.

This article is the rewrite-fallacy writ large. A sufficiently performant parallel system does not need to rewrite the serial component in order to bring large performance gains.

The real fallacy here - that is perpetuated by the article - is the idea that automatic parallelism is not possible without special support for parallelism in the base language(s). This is obviously false. Assembly code for the major CPU instruction-sets (x86, MIPS, etc.) is natively serial because those systems were designed during an era when a single thread was all that general-purpose CPU hardware could manage. Yet, superscalar CPUs easily process these serial programs in parallel by taking advantage of dynamic conditions in the code that permit instructions to execute in parallel. Of course, higher levels of parallelism are possible but the principle remains the same. Rather than whining about the "messiness" of C, build systems that use the abundance of threads to parallelize natively serial code. People will only stop using C when it freezes into the legacy layer and is surpassed by systems that actually achieve better end-result performance, as decided by paying customers (the market), not statistics, graphs, profiling compilers and online flame-wars.

6

u/eliot_and_charles May 01 '18

The real fallacy here - that is perpetuated by the article - is the idea that automatic parallelism is not possible without special support for parallelism in the base language(s).

You're saying the idea that doing that is impossible is perpetuated by an article that discusses how it's done?

-1

u/claytonkb May 01 '18

Is "re-write the C code-base in Erlang" what you mean by "how it's done"? Because that's more-or-less what the article boils down to.

5

u/ArkyBeagle May 01 '18

Erlang

The actor model is hardly specific to Erlang. You can write C that conforms to the actor model.

6

u/claytonkb May 01 '18

You can write C that conforms to the actor model.

There you have it.

I find - as with most things - that criticism of C is often founded on ignorance. "C does not support structured programming." Only if you redefine structured programming to mean something other than modular, interface-based design. Is it vintage? Well, yes, of course it is. I find that the people who complain about C's lack of this-or-that frequently lack the knowledge of what is possible with C. C is useful as an intermediate language for structured program generation (Lua, Chicken Scheme, et. al.) I don't know what the exact percentage is, but a huge portion of modern programming languages themselves depend upon C in one way or another. A quick Web search shows that an early Erlang VM (no longer in use) was written in C.

→ More replies (4)

3

u/eliot_and_charles May 02 '18

The article describes several techniques already in use by mainstream microarchitecture and compilers. You really should read it.

→ More replies (1)

1

u/[deleted] May 01 '18

Of course, higher levels of parallelism are possible but the principle remains the same.

Nope. We have pretty much all the dynamic ILP we could get, and at a very high price, OoO is not cheap. No way to go any further. And with architectures like this you do not even have tools for expressing static parallelism.

7

u/claytonkb May 01 '18

Yes, and as the famous USPTO officer Charles Duell once said, "Everything that can be invented has been invented." OOO scheduling is not bound to ILP, it is actually a high-level algorithm that can be applied at any level, such as a database, network or web-server. A modern CPU reorders not only instructions as they pass through the pipeline but also memory accesses and even, to some extent, I/O. Many-threaded systems can chop up a single thread and execute it out-of-order - subject to the constraints of serial correctness, of course. There has been quite a bit of research into Disjoint Eager Execution and related techniques to enable high-level multi-thread parallel execution of single-threaded code. Will this allow a 128-core CPU to run Microsoft Office 128 times faster? Obviously not. But there is no reason that a 128-core CPU cannot run Microsoft Office many times faster if the right automatic parallelization techniques are employed by the CPU and (by proxy) the compiler.

5

u/[deleted] May 01 '18

Well, of course OO is a powerful thing, but it comes at a price. There is a reason why there is no such a thing as an OoO GPU, for example. If you want a 128-core CPU, say goodbye to OoO (see Xeon Phi).

As for higher level parallelisation, I doubt it will ever be possible to do more (for a language like C) than what can already be done with polyhedral model. And I guess there are not that many places in Microsoft Office code that can benefit from it. For going further you need to think about code in a very different way.

→ More replies (6)

4

u/billsnow May 01 '18

Honestly, the leap of conceptual abstraction you get from assembly to c is much greater than that of c to any other language. I think you have to have coded many thousands of lines of assembly to realize how true this is.

3

u/headhunglow May 02 '18

Wow, an in depth, detailed article about an interesting, relevant topic written by someone knowledgeable. And no memes! How refreshing for /r/programming/!

7

u/os12 May 01 '18

This is a very nice write up that focuses on the C language semantics (said or consciously omitted from the Standard). Everything here also applies to C++ as the design is based on the very same "abstract C machine". Of course there are more constructs in C++ but they are all governed by the same set of fundamental rules.

The only thing missing from the article is the Memory Model (C++11 and onward) which specifies std::atomic and their semantics.

2

u/LordofNarwhals May 01 '18

It used to be considered a high-level language. It's just that there are now even higher-level languages.

"C is a very nice high-level language."
- John R. Mashey, from a 1982 Bell Labs video about UNIX.

2

u/tourgen May 01 '18

Nah. I think every C compiler I have used has allowed some form of direct, inline assembly code. So just enough abstraction when you need it, with bare assembly when you need it. It is definitely a low-level language. If it is not, nothing else can be called low-level and so the term would be meaningless.

12

u/[deleted] May 01 '18

i don't get it, inline asm in C does not make C low level, it makes the inline asm low level..

3

u/[deleted] May 01 '18

i don't get it, inline asm in C does not make C low level, it makes the inline asm low level..

Correct. You do indeed get it.

16

u/MindStalker May 01 '18

I take it you didn't read the article. The gist is that C is so far abstracted from the actual architecture of modern processors that it is no longer low level as it doesn't significantly represent what is going on under the hood, and is in-fact becoming dangerous because its existence and non native parallelism leads to dangerous branch predictions that wouldn't be necessary if we simply let it go.

12

u/[deleted] May 01 '18

That's all well and good, but the same is also generally true of assembly (especially in the x86 family). The whole fun this with speculative execution attacks is that there is no way to issue instructions to stop speculative execution, because it occurs on a much lower hardware level than you can issue instructions for.

5

u/ggtsu_00 May 01 '18

Yeah well at that point even assembly language can't be considered a low level languages because it is also pretty abstracted from the actual architecture of modern processors since they it still gets compiled into even lower level machine microcode and get reordered and muted by the CPU before being executed. Some x86 instructions can sometimes compile into dozens of microcode instructions and complete reordered so you never really know what is truly happening under the hood.

6

u/[deleted] May 01 '18

The ability to include inline assembly directly in the source code doesn't change the nature of the language. Many languages offer this ability but remain high level languages. C has language constructs not available in assembly. However, C has features to control the machine at a low level in specific points. This mixture of properties is why C is called a "mid" level language.

2

u/AntiauthoritarianNow May 01 '18

The assembly is the low-level code — assembly isn't part of the C language. Compilers may offer directives for inline assembly, but it's still not C. Plenty of other languages' tools can include or link with assembly code in a similar fashion.

edit: And even then, assembly doesn't necessarily give you full control over the hardware.

3

u/tonefart May 01 '18

That has got nothing to do with C being a low-level language just because you can inline some assembly, because those are COMPILER specific features, NOT language specific features. C is neither middle nor low level language. It is a high level language.

1

u/Poddster May 02 '18

mirror: https://pastebin.com/kTXwyQcb

(kept getting 404 and 'too many users' type errors)

1

u/Babahoyo May 01 '18

So for these new ARM and Sun chips that treat parallelism differently, what language is used instead of C for them? Is it Rust with a compiler that hasn't been built yet?

1

u/yes_u_suckk May 02 '18

It depends on the time you ask this question. I remember when I started to code around 22 years ago (Java was barely released at the time and there was no such thing as Javascript, C#, etc), everybody in my circle of friends considered C a high level language.

But nowadays, with much modern programming languages used in the market, everybody in my circle considers C a low level language.

0

u/skulgnome May 01 '18

, and even the pre- and post-increment operators cleanly lined up with the PDP-11 addressing modes.

That's literally false right there.

3

u/Poddster May 02 '18

Could you elaborate?

https://en.wikipedia.org/wiki/PDP-11_architecture#General_register_addressing_modes

Only mode 3 and 5 aren't easily mapped to the pre- and post-inc/decrement operators

x = ptr
x = *ptr
x = *ptr++
x = *++ptr
x = ptr[5]
x = *ptr[5]

(n.b. I couldn't be bothered to test that, and I can't remember if I need parens between the dereference and the increments etc.)

However, whilst pre and post increment do "line up" with PDP-11 addressing modes, I don't believe that's why there were added to C. They were added to C because the original authors wanted everything to be as terse as possible as a design goal, and x = x+1 is too damn long for them.

0

u/axilmar May 02 '18

C is a low level programming language. That does not mean it is the lowest level though.

6

u/[deleted] May 02 '18

What the article actually said (and nearly nobody in this thread cared to read) is that C was always a high level language, and now it forced the CPU designs all the way up to its high level, crippling the potential for performance improvement and introducing all those side channel issues.

1

u/axilmar May 02 '18

Nope, C is a low level programming language. The fact that it sits on many abstractions at the hardware level is irrelevant: it's low-level as a programming language, not as hardware design.

4

u/[deleted] May 02 '18

As a programming language, it is enforcing far too many constraints on the underlying hardware to be considered "low level". Its semantics is abstract enough for this.

3

u/axilmar May 02 '18

That does not mean it's not low level.

5

u/[deleted] May 02 '18

What the article says is it's too high level to stay the common denominator any longer, and lower level system programming languages are needed to overcome this crisis. Of course it is always comparative - in another thread I was arguing that Python is a low level language.

-9

u/lelanthran May 01 '18

The more I read reddit, the more I realise that the proponents of upcoming languages (Rust, Go) are not content to simply build up their language features, they have to tear down C (and, in some cases C++).

Simply competing on features appears way too difficult. Gaining mindshare the way programming languages did before, by offering utility, is apparently not in vogue anymore.

I haven't read the article but I'm guessing it is written by a Rust or Go developer. It's probably just another dissing-the-competition article that bemoans the lack of safety on C memory accesses.

Great. But we all already know that. I'm very surprised at how bitter Rust and Go fans get when C comes up. Almost like they're annoyed that the world has yet to see how wonderful their language is.

16

u/AntiauthoritarianNow May 01 '18

Maybe read the article before leaping into language zealotry? It doesn't even mention any other programming languages, and the author has plenty of experience in C compilers and operating systems.

Also, it's not like the title is some admonishment of precious C — it is simply a statement of how C does not map directly onto modern hardware, and the content of article goes in detail on the consequences of that.

→ More replies (4)

5

u/[deleted] May 01 '18

I haven't read the article but I'm guessing it is written by a Rust or Go developer.

Maybe you should. It's not written by a Rust or Go developer.

It's probably just another dissing-the-competition article that bemoans the lack of safety on C memory accesses.

Nope. It spends the bulk of its time talking about the PDP-11, optimization, and parallelism. The parts that talk about memory discuss the difficulty of memory alignment, lack of representation of hierarchical memory access, and power use. The only part that talks about memory safety does so in the context of the effects it has on flow control.

3

u/lelanthran May 01 '18

The parts that talk about memory discuss the difficulty of memory alignment, lack of representation of hierarchical memory access, and power use.

How is that a C problem as opposed to a programming language problem?

Look, I get the point that the author is trying to make WRT to spectre-type attacks, but the how is this a C problem and not a Programming Language problem?

It doesn't matter what programming language you use, you are still open to spectre. It doesn't even matter if you go off and design your own language that emits native instructions, you're still going to get hit by errors in the microcode that lies beneath the published ISA.

The only way to avoid this is to emit microcode and bypass the entire ISA entirely, at which point you can use any high level language (C included) that has a compiler that emits microcode.

Chances are, even if you did all of the above, you'd find there's no way to actually get your microcode to run anyway.

So, given the above, why does the article have such a provocative title, and why is the article itself written as if this is a C problem? It clearly isn't.

4

u/[deleted] May 01 '18

So, given the above, why does the article have such a provocative title, and why is the article itself written as if this is a C problem?

I suggest you read the article. You may not find the argument compelling, but it does answer these questions.

More direct answers:

  • The title is provocative because people pay attention to provocative titles. ¯_(ツ)_/¯

  • The article is written as if this is a C problem because the vast majority of popular modern languages are derived from C.

5

u/[deleted] May 01 '18 edited May 01 '18

How is that a C problem as opposed to a programming language problem?

Because all those performance-crippling requirements are coming from C.

It doesn't matter what programming language you use, you are still open to spectre.

Nope. It matters - this kind of hardware is made for C, exclusively. You would not need all that OoO stuff for a lower level language. You would not have such a complex and crippled memory hierarchy in a hardware designed to run a lower level language.

The only way to avoid this is to emit microcode and bypass the entire ISA entirely

This ISA is crippled because it's designed for C. Is it such a complex idea for you to comprehend?!?

So, given the above, why does the article have such a provocative title, and why is the article itself written as if this is a C problem? It clearly isn't.

You have a reading comprehension problem.

6

u/defnotthrown May 01 '18

This ISA is crippled because it's designed for C.

Sometimes it's kind of weird how strong the feedback loop is. There was a talk about CUDA and how they made a concerted effort to design the newer NVIDIA GPU processors to be able to map all the C++ language constructs to it.

I mean, you can't blame people, being able to leverage huge legacy code-bases or even pieces of it seems like a huge market advantage. But it does feel backwards to design hardware for languages that were designed to run on different hardware.

5

u/eliot_and_charles May 01 '18

I'm very surprised at how bitter Rust and Go fans get when C comes up.

It's not nearly as funny as watching C zealots flip out at the mere possibility that someone might have mentioned Rust. Almost like they're annoyed that the world has noticed the flaws they'd like to keep pretending their favorite language doesn't have. And then we also get to see the ones who actually read the article throw a tantrum over someone pointing out that their favorite language doesn't actually fulfill the promises they make about it.

→ More replies (2)

4

u/Zy14rk May 01 '18

I rather like C - and I also rather like Go. I find there is little overlap between where I'd chose C and where I'd chose Go for a given task. Now, between Java, C# and Go on the other hand...

C is great for where resources in terms of processing and memory usage are at a premium. Go is great where resources are relatively abundant, and all one care about is getting the job done fast - deadlines are real - and still not compromise too much on performance.

Each language have their strengths and weaknesses - there is no language 'to rule them all'.

5

u/[deleted] May 01 '18

I haven't read the article

Why the fuck you're commenting then?

→ More replies (6)

-4

u/tonefart May 01 '18

C is a high level language. Middle level label is defacto unofficial given due to it's ability to manipulate absolute pointers. But generally 'middle level' doesn't officially exist to describe a language. Low level language label is given by new generation noobs who can only code in javascript. If it's portable, it cannot be a low level language.

2

u/stefantalpalaru May 01 '18

If it's portable, it cannot be a low level language.

This is an interesting criterion. You're either close to the metal or removed far enough to be portable.

2

u/Poddster May 02 '18

due to it's ability to manipulate absolute pointers

C can't manipulate absolute pointers. e.g. 6.5.6.9 -- you can't perform arithmetic on two pointers that don't already point to the same allocation. And then when you are subtracting you have to ensure you can fit the result in a ptrdiff_t etc etc etc.

Hell, you can't even MAKE a pointer to a non-allocated address in C, regardless of whether you dereference it or not.

Non of these rules or restrictions exist on the CPU.

→ More replies (2)

-6

u/[deleted] May 01 '18

General purpose everything sucks. General purpose CPUs, trying to cater for the perceived common denominator, C, do suck a lot. General purpose programming languages (including C) suck enormously. General purpose memory suck (or, actually, anyone accessing it via slow and wobbly DDR interface sucks).

The right way would have been to have very flexible, reconfigurable architectures that can be easily tweaked for semantics of problems being solved. Maybe one day we'll have FPGA fabric on every single CPU die, with tons of useful macro modules (as in, entire ALUs vs. simple puny DSP slices).

7

u/stefantalpalaru May 01 '18

General purpose everything sucks.

It does the job.

The right way would have been to have very flexible, reconfigurable architectures that can be easily tweaked for semantics of problems being solved.

That's a case of better being the enemy of good. We can't afford to delay our computing needs until the better solution jumps the chasm between half-thought proposal and widely available reality.

1

u/[deleted] May 01 '18

It does the job.

Badly.

We can't afford to delay our computing needs until the better solution jumps the chasm between half-thought proposal and widely available reality.

There are many cases where there are no other options available, where general purpose architectures simply do not fit the purpose (e.g., due to power/area constraints). And people have to resort to completely custom ASIC, or to general purpose FPGAs, with both solutions being too expensive (for different reasons).

There is some hope that now Intel is moving in the right direction though.

3

u/gpcprog May 01 '18

The problem with reconfigurable logic, like FPGA is that it's a bear to program. As result general CPUs are not going to go away. In applications where it make sense programmable logic / Asics will and actually are being used. But for the vast majority of applications it's just too expensive to make use of such resource.

0

u/[deleted] May 02 '18 edited May 02 '18

Nope, they're not hard to program, especially if such high level macro blocks are used. And even on simpler FPGAs, still, it should not be hard.

2

u/gpcprog May 02 '18

"should not be hard", famous last words. Seriosly though, in my experience there is an order of magnitude difference in difficulty between getting something working in software vs in logic.

→ More replies (1)

1

u/pdp10 May 01 '18

Maybe one day we'll have FPGA fabric on every single CPU die

Xilinx sells a SoC line like this. Microsoft made waves a couple of years ago about having FPGAs in all of their servers, yet we hear nothing about it now. The most obvious conclusion is that it isn't a big win for most computing apps (it is for other realms, like software defined radio).

1

u/[deleted] May 02 '18

It's a huge win for pure compute, for the same kind that is done on GPUs now, but there is no option yet with more capable DSP slices (e.g., full FPUs) and with a sufficient number of hardware DDR controllers.

-3

u/[deleted] May 01 '18

The right way would have been to have very flexible, reconfigurable architectures that can be easily tweaked for semantics of problems being solved. Maybe one day we'll have FPGA fabric on every single CPU die, with tons of useful macro modules (as in, entire ALUs vs. simple puny DSP slices).

If our society wasn't driven by profits, greed and market share, then, yes, you would be absolutely correct. The main reason Assembly Language is rarely used, despite it's legendary speed and efficiency, is simply economics. Assembly is difficult to code in. It is time consuming. It is inflexible. It isn't portable. FOSS software notwithstanding, software is meant to generate profits, like everything else in out greed fueled society, and the fastest to market gets the profits. This is why version 1.0 of anything is so demonized.

9

u/stratoscope May 01 '18 edited May 01 '18

There's a flaw in your argument.

As you correctly point out, "Assembly is difficult to code in. It is time consuming. It is inflexible. It isn't portable."

And yet you say that the main reason it's rarely used is none of those, but because of "profits, greed and market share" and the need to "generate profits, like everything else in [our] greed fueled society".

But you also mention FOSS. Most open source code is written in the same kinds of languages used by any other software, isn't it?

If your claim is true, wouldn't there be a big difference in assembly language popularity between open source and commercial software?

Suppose I'm volunteering my time to build some useful app or service for a nonprofit. I have no commercial motivation, no greed, only my own altruism and desire to support the nonprofit's mission.

Do you think I will use assembly language? Or will I use another language that lets me build a quality app for the nonprofit in less time - so now I have more time left over to do some other neat thing for them?

Is it really "greed" when people simply want to make the best use of their limited time?

4

u/flukus May 02 '18

A society free of profits and greed would still have time constraints.

→ More replies (1)

2

u/[deleted] May 01 '18

Well, what this article is really about is that the assembly language those CPUs are exposing to you is also not a proper low level language, and that ISA is very opinionated towards emulating PDP-11 semantics (and, ultimately, supporting C). Going one step down from C to assembly won't fix this problem.

0

u/[deleted] May 01 '18

[deleted]

6

u/ismtrn May 03 '18

Did you read the article? The point is not arguing about the definition of high level or low level languages or comparing languages on a scale.

He explains what he means by low-level in this context, and then explains how C is not that. The interesting part is not how low-level is defined, but how C fails to live up to this particular definition of low-level. the article would still be meaningfull if he called it "bananna" instead of "low-level".

→ More replies (2)

0

u/[deleted] May 01 '18

[deleted]

18

u/djthecaneman May 01 '18

While the title of the article seems rather misleading, I love the main thrust of it. This idea that we're approaching a "performance crisis" where the CPU's ISA should be rethought was like turning a light. That's it, really. It's not just C, but the abstractions the CPU presents for a programming language to manipulate. Impedance mismatch indeed.

4

u/[deleted] May 01 '18

I had so much to say, but it would probably start a fight, a flame war, and probably fuel hate inside of me

This shows that you are passionate person.

I will refrain from going deep, and instead, will just say, this article makes me feel uneasy.

Passion aside, if there are points that need to be clarified, then logic would be the order of the day - without the passion.

0

u/[deleted] May 01 '18

[deleted]

19

u/anttirt May 01 '18

We live in an age where C (and C++) optimizers frequently reduce hundreds of lines of code to a single instruction and the CPU itself only pretends to execute instructions in the order you specify.

If you actually care about low level details and not just the illusion of them, then you might want to take up FPGA programming and hardware design as a hobby.

9

u/claytonkb May 01 '18

What compilers are capable of under certain conditions and what compilers actually do in every specific condition are two, very different things. When I write hand-optimized C code, the difference between -O0 and -O3 is not often more than 3x and I know that most of that performance gain comes from the compiler taking advantage of LEAs and other old-school assembly optimization tricks.

The power of C is not that it transforms 1-to-1 into assembly -- no one who actually understands C thinks that. Rather, the power of C is that there are no moving parts except those parts you tell to move. Of course, this is an illusion that is helped along by the compiler, assembler, linker, OS loader, and so on, but most of those tools are pretty close to immutable, so surprises are few and far between. The power of C is the absence of the very "magic" that makes other languages so useful. The absence of a garbage-collector, for example, is not a bug, it is a feature. This feature is what makes C a killer app for embedded design.

11

u/anttirt May 01 '18 edited May 01 '18

the power of C is that there are no moving parts except those parts you tell to move

I think there's one huge caveat (or class of caveats) that really makes it difficult for me to agree to that statement: undefined behavior, especially as it pertains to aliasing, integer overflow, and multi-threaded memory access.

The fundamental machine model of C is a leaky abstraction in the presence of optimizers, caches and multiple cores, and you have to use unintuitive contrivances to patch over those leaks, or suffer extremely unpredictable catastrophic consequences.

There's lots of magic and in this case you actually have to be aware of the magic or your code is wrong. You can't just cast a float* to an int* to get at the bits of the floating point representation because you might get complete nonsense as a result of alias-based optimizations. It would make sense if you could, and it works at -O0! Likewise you can't just write to a variable in one thread and read from it in another thread; you have to be aware of all the magic of compiler optimizations and out-of-order execution and CPU caches and memory barriers so that you'll know that you need to use special magical atomic access functions instead (or atomic types which automatically do that for you).

2

u/claytonkb May 01 '18

The fundamental machine model of C is a leaky abstraction

This is more true of most other languages than people will admit. Try loading a Bluray-sized file in most languages without some specialized library. Try doing RSA encryption with a simple base and exponent in most other languages with the default exponentiation operator. It works on the chalkboard, it works in the whitepapers, but it often doesn't work in the actually compiled implementation. There are exceptions, of course. So, it's kind of one of those situations where C is the worst major programming language... except for all the others.

7

u/anttirt May 01 '18

So, it's kind of one of those situations where C is the worst major programming language... except for all the others.

Having few "moving parts" is presumably a virtue because it makes systems easy to reason about and thus enables reliability.

The trouble is that C's moving parts (UB) earn you silent data corruption and getting owned by black hats, whereas more abstract languages' moving parts mostly earn you easily debuggable exceptions and possibly a hung process in some cases. GC sometimes earns you extremely difficult-to-diagnose performance issues, which I could certainly do without.

C is perhaps the most reliable in terms of performance but in all other metrics of reliability it is far from number one.

→ More replies (2)

5

u/[deleted] May 01 '18

And yet, C is way too high level and way too opinionated. Opinionated about lots of things that you may want to implement in hardware differently, but cannot if you ever want to run existing C code.

It's memory layout dictated by C, it's byte-level addressing, it's a particular set of integer data types (and let's stop pretending that C standard does not really enforce anything, in practice it's not true). It's the reliance on the existence of stack (well, you can find some passable workarounds, by forbidding recursion and indirect calls, for example). And, of course, a notion of execution order, something that cripples any possible attempts of parallelisation on a lower level.

2

u/claytonkb May 01 '18

Opinionated about lots of things that you may want to implement in hardware differently, but cannot

I remember reading about an architecture that has 9-bit bytes (seriously!) and there was actually a port of cc to compile on that architecture. I think this is like trying to argue that we should be able to write English with the Greek alphabet. I mean, no one is stopping you, go ahead and do it. But don't expect the rest of us to follow suit. A byte is a byte. Deal with it.

Ditto for all the other (more or less arbitrary) standards that have been built along the way. Look at the QWERTY keyboard. It doesn't matter that it is sub-optimal compared to the best conceivable keyboard layout. It was so much better than not having a standard that its sub-optimality is irrelevant. It enabled new, more efficient modes of operation that would be unreachable without it. The same logic applies to many domains. Evolution doesn't need the best design, only a good enough design.

4

u/pdp10 May 03 '18

I remember reading about an architecture that has 9-bit bytes (seriously!)

I enjoy your incredulity.

The first few generations of full-capability binary computers typically had 36-bit words because the market wanted machines that could calculate to ten decimal digits. Most minicomputers used 18-bit or 12-bit word size to accomplish the same goals with more-modest hardware. Bytes were usually 9-bit, but text encoding were often packed into various 6-bit encodings for efficiency (this is why old machines USE ALL CAPITAL LETTERS -- there was no lowercase in their text encoding).

What really changed that was the 32-bit IBM System 360. It was possibly the first machine with a standard architecture that would be used to make many compatible models and for years to come. It was very ambitious and it succeeded. (It was also to have used ASCII text encoding, but that bit of ambition was a bridge too far in the end, and IBM's big and midrange business systems and other machines in that ecosystem use the Extended BCDIC encoding to this day.)

The first minis to use 8-bit bytes were the PDP-11 and competitor Data General Eclipse. The PDP-11 architecture was groundbreaking in as many ways as the System 360, and set the standards for many future machines. C arguably had a symbiotic relationship with this architecture.

→ More replies (1)

3

u/[deleted] May 01 '18

When time comes and CPU architectures change, I can only hope there will be some new language like C, to stay in the middle ground again, and offer some thin interface to the hardware.

There very likely will be. C has been implemented on a great variety of system architectures. This would include everything from the original PDP-11 and its contemporary systems to the lowly 8bit Atari 800 to a Cray super computer across a timeline of nearly 50 years (which is loosely 100 computer "generations"). That is impressive.

0

u/[deleted] May 01 '18

[deleted]

4

u/stefantalpalaru May 01 '18

A quote I've heard is C is a high-level assembly.

Not any more. Read the article.

1

u/ThatsPresTrumpForYou May 01 '18

It's actually still true, C gives you most of the tools that x86 offers you.

2

u/stefantalpalaru May 01 '18

It's actually still true, C gives you most of the tools that x86 offers you.

Except when it doesn't: https://gcc.gnu.org/onlinedocs/gcc/Target-Builtins.html

2

u/ThatsPresTrumpForYou May 01 '18

I said most, no shit it doesn't support every instruction, it's not a 1 to 1 mapping. Just having access to pointers and raw memory means it's much closer to a high level assembly than most other languages.

5

u/pjmlp May 02 '18

Like C++, D, Object Pascal, Modula-2, Modula-3, Oberon and plenty other languages.

3

u/doom_Oo7 May 02 '18

Just having access to pointers and raw memory means it's much closer to a high level assembly than most other languages.

well, Python and C# both give you access to pointers and raw memory allowing you to fuck things up badly if you want.

2

u/Poddster May 02 '18

Just having access to pointers and raw memory means it's much closer to a high level assembly than most other languages.

C pointers are nothing like your CPU's addresses, however, as it has all sorts of weird rules about what you can and can't do with those pointers, rules that your CPU doesn't have.

3

u/stefantalpalaru May 01 '18

Just having access to pointers and raw memory means it's much closer to a high level assembly than most other languages.

The same applies to C++ and no one in their right mind would call it "high level assembly".

1

u/ThatsPresTrumpForYou May 01 '18

Because assembly usually doesn't have multiple turing complete meta languages built in. C++ is so ridiculously complex, and you wouldn't even use things like raw memory pointers in modern C++, that it's hard to call it high level assembly with a straight face.

0

u/[deleted] May 01 '18

[deleted]

5

u/[deleted] May 01 '18

You did not read the article.