News for hackers. Stuff that matters.
Re:New inline assembly syntax available in Rust nightly by pjmlp on Tuesday June 09, 2020 @11:04AM (#23467258)
Sadly it is yet another language that follows the UNIX tradition of not having a proper Assembly parser instead forcing us to play with strings.

I guess it leaves PC based languages to have actual inline Assembly parsers or intrisics.

Re:New inline assembly syntax available in Rust nightly by Someone1234 on Tuesday June 09, 2020 @11:10AM (#23467308)
If you want the outer language to be cross platform (e.g. x64, ARM64, etc), then you'd either need a parser for every potential platform (even ones you aren't currently using!) OR you just settle for strings.

Don't get me wrong: Parsed assembly is superior because you can have certain parser guarantees/checks. But it will definitely limit the scope of your language or at least slow its adoption to new platforms.

Re:New inline assembly syntax available in Rust nightly by zamalek on Tuesday June 09, 2020 @01:02PM (#23468398)
I really don't like the strings (because Rust is so good at avoiding things like this), but your explanation makes tons of sense.

That being said, it wouldn't be hard to create an asm_x86! macro that hides the string.

Re:New inline assembly syntax available in Rust nightly by pjmlp on Tuesday June 09, 2020 @11:16AM (#23467361)
Productivity of language users vs compiler developers.
Re:New inline assembly syntax available in Rust nightly by Someone1234 on Tuesday June 09, 2020 @11:45AM (#23467625)
Productivity of a niche area.

But related: There's no reason parsers cannot be externalized and inject the resultant assembly strings into the Rust solution. If that's really what people want. The nice thing about external parsers is that they become optional in every sense.

If the Rust team builds them in, then every supported platform needs support, every development environment needs every parser, and tooling also has to support it (e.g. IDEs, code checkers, etc).

It isn't simply just adding it once and leaving it forever, the work is repeated several times over and the maintenance will be time-consuming for what is: A niche feature.

Re:New inline assembly syntax available in Rust nightly by pjmlp on Tuesday June 09, 2020 @11:57AM (#23467749)
Better not starting talking about niche in regards to Rust, unless adoption of a niche systems language isn't something to care about.

Productivity matters everywhere, systems languages that care about happy programmers have better chances of long term adoption.

Re:New inline assembly syntax available in Rust nightly by Someone1234 on Tuesday June 09, 2020 @12:51PM (#23468277)
That's a pretty shallow argument, one that can literally be re-used verbatim to argue for any and every feature/philosophy. Particularly when "happy" is as subjective as this.

It also ignores the reality that the Rust team's time is finite, and if they invest it into three or more assembly parsers then they aren't investing it into other areas of the language that could also be productivity multipliers. Areas that more programmers actually use.

Ultimately how much is unsafe assembly in Rust going to be used? And how large are those code sections? And are you better off creating Assembly in existing dedicated tooling and importing it, even if Rust had native parsers (e.g. due to better debugging/visualization elsewhere)?

Honestly if Rust code outside of standard libraries ends up with a ton of assembly anyway then that's a weakness of Rust. You should be using as little as possible. Even unsafe Rust is superior to assembly because it is platform agnostic. I'd go as far as to call it a "last resort."

Re:New inline assembly syntax available in Rust nightly by yazaddaruvala on Tuesday June 09, 2020 @04:32PM (#23470576)
It seems reasonable, but we need to not conflate niche with lacking-popularity (i.e. low usage).

Niche is about the environment, i.e. the problem domain.

Analogy to biology/ecology, grazing on mountain tops is a niche that is also unpopular (i.e. low usage), meanwhile pollination is a niche that is popular.

The problem domain for Rust to be useful is very large, across the programming ecosystem and across the programming ecosystem effort is put into increase accessibility for the less and less experienced (e.g. embedded, wasm, webservers, clis, etc). However, Rust might currently lack popularity (i.e. low usage).

The problem domain for Inline Asm to be useful is very small, typically by experts in narrow domains and across the programming ecosystem effort is put into decrease the need for inline asm (e.g. crypto, firmware, drivers, etc). It also happens to be unpopular, and is avoided as much as possible.

Summary, Rust is pragmatically niche, rather than theoretically niche, Inline Asm is theoretically niche, and also pragmatically niche.

Re:New inline assembly syntax available in Rust nightly by alharith on Tuesday June 09, 2020 @11:22AM (#23467418)
There are infinitely more language users. I'd rather throw a bone to the compiler developers.
Re:New inline assembly syntax available in Rust nightly by AnIdiotOnTheNet on Tuesday June 09, 2020 @11:29AM (#23467476)
Then that means there is infinitely more productivity to be gained catering to the language users.
Re:New inline assembly syntax available in Rust nightly by pjmlp on Tuesday June 09, 2020 @11:29AM (#23467480)
One more reason to actually care about the productivity of language users.

They are free to go elsewhere more welcoming.

Re:New inline assembly syntax available in Rust nightly by newacct583 on Tuesday June 09, 2020 @11:11AM (#23467325)
It's not "PC based" that's the magic you want, it's the assumption of x86 (and, very recently, sorta, ARM, in a few compilers).

Architectures are weird, assembly is crazy. There just isn't going to be a single set of semantics around what you want.

This Rust thing isn't revolutionary, it's indeed just a prettier way of writing the model GCC invented a few decades back:

+ "Assembly" is a black box for the code author.

+ The compiler's job is generating code around the assembly, not the code itself.

+ So the fundamental model is "constraints": the rules the compiler needs to follow before and after the assembly, and how to emit an appropriate string to represent the register/address/immediate/whatever requested by the assembly code.

And like it or not, this works. It works really well. Generations of OSes have been written in this model without much complaint (beyond the general ugliness of the gcc syntax, which Rust is trying to fix).

I think this is fine. I agree it's not going to bring a revolution, but we really don't want one in this space.

Re:New inline assembly syntax available in Rust nightly by pjmlp on Tuesday June 09, 2020 @11:18AM (#23467382)
GCC did not invent anything, that dumb approach to inline Assembly is traditional in UNIX environments.

Amiga and Atari also had similar inline Assembly support.

Re:New inline assembly syntax available in Rust nightly by newacct583 on Tuesday June 09, 2020 @11:52AM (#23467707)
I still think you're missing the point. GCC indeed didn't invent "inline assembly as a string", no.

GCC invented "constraint metalanguage as the foundation for inline assembly generation", which is the model here that enables one compiler and one syntax to work the same way for basically every architecture over decades. Modelling the interior of the assembly code as a black box (which in this implementation means "string") is just a side effect of this important design choice.

Again, the stuff you're imagining isn't a general purpose assembly language model, it's an x86-specific hack that works only on the specific compilers and architectures for which it was targeted.

Re:New inline assembly syntax available in Rust nightly by pjmlp on Tuesday June 09, 2020 @12:06PM (#23467827)
Except that compilers with inline Assembly also don't have dumb backends that just dump Assembly for as, like on UNIX.

They interact with the backend.

They weren't specific of x86, although I mentioned only PC, they were available across all 8 and 16 bit home computers and several embedded targets support it as well.

Re:New inline assembly syntax available in Rust nightly by not2b on Tuesday June 09, 2020 @02:25PM (#23469229)
GCC doesn't implement the "dumb approach" that existed before it, and that Amiga and Atari originally had. The GCC approach provides enough information to the compiler that code can be optimized in the presence of inline assembly; the compiler is informed of what the assembler code reads and writes, and can allocate registers for it. It was much more flexible than the implementation in the original Unix compiler.
Re:New inline assembly syntax available in Rust nightly by jcranmer on Tuesday June 09, 2020 @11:54AM (#23467721)
Microsoft declined to extend its inline assembly syntax to support x64 or ARM-based processors.

If you want to use a single specific instruction or two, it's usually better to just use the compiler's intrinsics (Rust has already stabilized the x86 SSE and AVX intrinsics) than inline assembly. When you go to more complex assembly fragments, you tend to need more control over how the inline assembly fragment interacts with scheduling and the register allocator, and making that control work ergonomically is that much more challenging.

Re:New inline assembly syntax available in Rust nightly by jerf on Tuesday June 09, 2020 @11:09AM (#23467304)
I'm sure someone will be along to provide a wrapper macro or macros to address that shortly.

I can see why they would not want to bless a particular syntax tree or whatever into the core compiler.

Re:New inline assembly syntax available in Rust nightly by gpm on Tuesday June 09, 2020 @11:14AM (#23467344)
(Once this is stable) haven't they blessed a particular syntax tree anyways, since the contents of the "" string is parsed to a specific syntax tree that will have to remain stable. The only difference is that that syntax tree is delimited "<contents>" instead of asm!(<contents>).
Re:New inline assembly syntax available in Rust nightly by andrewf on Tuesday June 09, 2020 @08:55PM (#23472717)
Does compiler behavior matter here, or could your problems be fixed in your editor?

On the rare occasion I write inline assembly, my annoyances were autoindent, syntax highlighting, and keystrokes required. Only the latter is directly caused by the stringy inline syntax, and an editor could still mitigate it.

Re:New inline assembly syntax available in Rust nightly by patrec on Tuesday June 09, 2020 @12:07PM (#23467842)
Are you aware of PeachPy? It's the only (Intel) assembler I have ever seen I liked.
Re:New inline assembly syntax available in Rust nightly by kzrdude on Tuesday June 09, 2020 @02:37PM (#23469358)
Strings can be parsed. The rust compiler parses format strings, for example.