News for hackers. Stuff that matters.
Re:C meeting is over. C23 added: by dkjaudyeqooe on Saturday February 19, 2022 @03:39AM (#30395450)
C is a portable alternative to assembly language.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @04:29AM (#30395681)
When the world is a PDP-11.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @05:22AM (#30395959)
And x86, Arm, PIC, Xtensa,... and everything else.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @06:12AM (#30396215)
There is where you went off rails, with greetings from ACM.

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

Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @07:23AM (#30396599)
I'm so glad that you have linked this article from Chisnall. I can now ask you in what ways is the abstract model of a machine on which assembly language operates on, different from the one on which the C language operates on?

This is the claim which started this thread:

>>C is a portable alternative to assembly language.

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @08:45AM (#30397083)
C's abstract machine is leaky and full of surprises when UB comes into play for one.

Second when people talk about C being portable Assembly, they mistakenly assume to know what comes out of the compiler's backend.

Third, unless we are speaking about PDP-11 like CPUs, modern CPUs have tons of capabilities not exposed to ISO C.

Finally, since 1958 there are portable alternatives to Assembly in systems programming with JOVIAL being one of the first remarkable ones, yet another thing that C did not invent.

Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @09:15AM (#30397263)
You haven't answered the question?

Maybe because is there is no concernable difference between abstract machine models of both languages? You can't do anything more about instruction reordering or cache invalidation at the CPU level with assembly than you can with C.

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @09:59AM (#30397570)
You surely can, better read those CPU manuals about line bus controllers.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @10:23AM (#30397764)
Have you? I used to write device drivers mostly on ARM architectures and I have newer seen an instruction which would let me precisely control CPU instruction ordering or what it does with cache that I couldn't do in C.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @12:51PM (#30398959)
That is why stuff like V-Tune exist with micro-ops profiler and pipeline debugging, maybe ARM should provide better tooling.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @01:30PM (#30399279)
This tool helps as much with C (or even higher level languages) as it does with Assembly. It doesn't change the fact both languages work on the same abstract machine model.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @01:51PM (#30399444)
What is C's abstract model for NEON?
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @02:24PM (#30399713)
A simple c library:

https://github.com/projectNe10/Ne10

You have not yet shown an argument for why c is not a portable assembly.

Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @01:39AM (#30403730)
Access to CPU-specific flags like the carry flag. When doing a multiple-precision addition, if the CPU carry bit is inaccessible, then it must instead be compared to the result to see if it overflowed, which takes 3-5 more instructions per limb or worse on modern superscalar processors that are serial in terms of data accesses.
Re:C meeting is over. C23 added: by nec4b on Sunday February 20, 2022 @03:59AM (#30404305)
Portable by definition means it cannot capture every specific detail of every architecture out there.
Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @09:52AM (#30406136)
The carry flag is not a specific architectural detail; it is part of the output from the prime example of a basic electronic circuit that is the digital adder.
Re:C meeting is over. C23 added: by nec4b on Sunday February 20, 2022 @07:10PM (#30410514)
It is an architectural detail. MIPS for example doesn't have a carry flag. You have to do the exact same procedure in assembly on MIPS you have described in your previous comment when doing multiple word addition.
Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @08:38PM (#30411029)
MIPS along with DEC alpha do not have adder circuits as a design goal was not to have flags. This along with the scenario of multi-precision arithmetic resulted in the implementation of multi-precision arithmetic on MIPS and DEC alpha using a form of branch like instruction with an ALU stage instead of the unavailable instructions dependent on the alternative adder circuits. The choice of having or not having a carry flag alone is not an architectural detail as the choices of [micro]architecture involve how operations are implemented in circuits/hardware. The carry flag specifically has to be considered in the context of its [the adder] circuit when making architecture decisions. The lack of control over flags leading to the inability to compile the same C program to the same assembly operations with same behavior on different hardware demonstrates that a strictly C program is unable to express a consistent portable assembly program across all hardware.
Re:C meeting is over. C23 added: by nec4b on Monday February 21, 2022 @05:08AM (#30413910)
You are basically arguing CF == !CF. On MIPS you literally have to compare your result with an operand in order to establish if there was an overflow. On Arm you just look at the status register.

When I was doing embedded development, I used C as portable assembly in practice and I know I wasn't the only one. Can you do everything an architecture enables you in a portable way? No, of course not.

Re:C meeting is over. C23 added: by pjmlp on Sunday February 20, 2022 @04:29AM (#30404431)
By definition there isn't such thing as portable Assembly.
Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @11:43AM (#30407006)
Not by definition, but by practice as generating assembly is usually done to optimize performance. Languages restricted to generate a common feature set between isomorphic ISAs and bijectively associated assembly languages are at a performance disadvantage compared to the full ISA specific assembly.
Re:C meeting is over. C23 added: by pornel on Saturday February 19, 2022 @06:47AM (#30396387)
Where's my overflow flag?
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @07:27AM (#30396621)
Not all CPU's have overflow flags. On those that have them, you can also usually access them in C in a non portable way.
Re:C meeting is over. C23 added: by uecker on Saturday February 19, 2022 @01:21PM (#30399205)
C23 will get support for checked integer operations that report overflow.
Re:C meeting is over. C23 added: by kaba0 on Saturday February 19, 2022 @06:11AM (#30396202)
I don’t see my SIMD instructions anywhere.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @07:16AM (#30396561)
The word "portable" means a subset of everything possible. Do you think every CPU architecture supports SIMD?
Re:C meeting is over. C23 added: by foxfluff on Saturday February 19, 2022 @07:51AM (#30396773)
> The word "portable" means a subset of everything possible.

Exactly; for example, C has single precision and double double precision floating point, 64 bit types, and complex arithmetic because every CPU architecture has those built-in.

Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @08:38AM (#30397044)
No, but those things can be easily emulated on every hardware or simply not used. One more reason to use C instead of plain assembly.
Re:C meeting is over. C23 added: by jdkjs on Saturday February 19, 2022 @06:54AM (#30396428)
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @10:00AM (#30397583)
That isn't C, rather Intel C.