News for hackers. Stuff that matters.
Re:Asm-declaration – Embed assembly language code within a C... by siempreme on Friday July 26, 2019 @09:25AM (#20534588)
In a string literal?!?! We did better almost 40 years ago..., this is assembly in turbo pascal:

  procedure init; assembler;
  asm
    mov ax,13h
    int 10h
  end;
You can even have only the asm block in a regular pascal function and make use of regular arguments in the asm block.
Re:Asm-declaration – Embed assembly language code within a C... by pjmlp on Friday July 26, 2019 @10:22AM (#20534988)
For some cultural reason C and C++ compilers for UNIX do it the hard way.

PC compilers always followed that path.

The same in Turbo C would be:

    void init()
    {
        asm {
            mov ax, 0x13
            int 0x10
        }
    }
Re:Asm-declaration – Embed assembly language code within a C... by tropo on Friday July 26, 2019 @12:18PM (#20535912)
The style used by Turbo C is strictly inferior. There is no way for the author of the assembly code to cooperate with the compiler's register allocator or instruction scheduler.

You wouldn't even need both of those lines with gcc. You could ask the compiler to put 0x13 into ax, and the compiler might schedule that instruction far earlier or even take advantage of the value already being in the register by luck.

Turbo C makes a simplistic assumption about what registers might have been trashed. With gcc, the compiler knows because you told it. Turbo C must save things to memory before the assembly and then reload registers afterward, which adds enough slowness that the assembly might not even be worthwhile.

Re:Asm-declaration – Embed assembly language code within a C... by a1369209993 on Friday July 26, 2019 @02:31PM (#20537165)
That has nothing to do with their actual point; Turbo C could perfectly well support:

  void init() {
    asm("ax"(0x13)) { int 0x10 }
    }
and as TFA suggests, plenty of implementations use the string-syntax without any register/clobber extensions.
Re:Asm-declaration – Embed assembly language code within a C... by pjmlp on Friday July 26, 2019 @01:00PM (#20536271)
Turbo C was a compiler done in 1990 for MS-DOS, naturally it was just an example.

Your remarks are a mute point in modern Windows compilers with Assembly intrinsics, the evolution of those inline assembly instructions.

Re:Asm-declaration – Embed assembly language code within a C... by tropo on Friday July 26, 2019 @01:47PM (#20536677)
It's not mute or even moot. Assembly intrinsics are not enough.

I've dealt with this, getting software to run in Visual Studio. The intrinsics are simply not available. You end up running code through gcc to produce assembly, then hacking up the assembly (way too much to write by hand) into a separate *.asm file for Visual Studio.

Vector stuff, if it isn't very new, is covered by intrinsics. Well, it is badly covered, with terrible failures to keep things in registers.

Once you get into exotic OS-level stuff, the intrinsics simply don't exist. The most important one is the ability to put an arbitrary byte sequence into the instruction stream. For example, suppose you wanted to add a Spectre fix to your JIT on day 1. You needed to fix a security problem, so waiting for a new release of Visual Studio isn't an acceptable option. You really truly need the ability to put weird byte sequences into the code. Visual Studio doesn't provide an intrinsic for that.

Re:Asm-declaration – Embed assembly language code within a C... by pjmlp on Friday July 26, 2019 @02:07PM (#20536910)
For such corner cases using MASM on day 1 until the new VC++ release isn't much of an issue.
Re:Asm-declaration – Embed assembly language code within a C... by tropo on Friday July 26, 2019 @06:53PM (#20539054)
MASM is just an assembler, with no awareness of the C or C++ code. MASM is unable to place arbitrary bytes into the middle of functions that are written in C or C++.

To fix a problem like Spectre, and generally to solve unusual problems that the compiler vendor isn't dealing with, the full capability of an inline assembler is required.

Re:Asm-declaration – Embed assembly language code within a C... by pjmlp on Saturday July 27, 2019 @03:09AM (#20540801)
Sure it can, I really don't see any difference between that and a naked call with LTO, beyond the convenience of saving about a minute not having to write a prototype for the function being called and adding MASM into the build.
Re:Asm-declaration – Embed assembly language code within a C... by Tinfoilhat666 on Friday July 26, 2019 @10:54AM (#20535233)
Also Rust uses strings for asm. It can't be bad.
Re:Asm-declaration – Embed assembly language code within a C... by steveklabnik on Friday July 26, 2019 @11:18AM (#20535419)
It’s a fairly major point of contention, and we may not keep it. Note that it’s not a stable feature yet. As pointed out below, it’s this way because it’s basically a convenience into LLVM.
Re:Asm-declaration – Embed assembly language code within a C... by tropo on Friday July 26, 2019 @12:11PM (#20535848)
Keep it.

Porting to rust is easier if it doesn't require a person to be an expert at two different kinds of inline assembly syntax. Being able to grab a chunk of inline assembly from a C project is very useful.

Whatever you do, don't embed knowledge of the assembly language into the compiler. That way lies madness. Assembly is often used for new CPU features that are not yet supported by the compilers that people are using. Constantly putting out minor compiler updates for every CPU revision would be miserable, and the users won't want to force those upgrades anyway.

There is also the issue, I'm sorry, of the rust preprocessor. It will be written and it will be used. It may even be popular and ultimately written into an ISO standard. The irregularity of switching suddenly to a radically different CPU-specific syntax for assembly code would make the preprocessor situation much more nasty and gross.

Re:Asm-declaration – Embed assembly language code within a C... by steveklabnik on Friday July 26, 2019 @01:12PM (#20536354)
> Porting to rust is easier if it doesn't require a person to be an expert at two different kinds of inline assembly syntax.

Sadly, this doesn't save you from that, in fact, it can be argued that the string syntax is what makes you need to learn a whole second set of syntax. This is due to clobbers.

> There is also the issue, I'm sorry, of the rust preprocessor. It will be written and it will be used.

I don't forsee this happening; Rust has powerful enough generic capabilities that even with tens of millions of lines of Rust existing today (I'd actually guess we're in the hundreds right now, but still), nobody has invented one yet. Getting away from the pre-processor is considered a pro, not a con.

Re:Asm-declaration – Embed assembly language code within a C... by jcelerier on Friday July 26, 2019 @04:21PM (#20538042)
> nobody has invented one yet.

no need to invent one when cpp exists and works. I've seen people use it in Java, and it is sometimes used in unix config files (e.g. .Xresources).

Re:Asm-declaration – Embed assembly language code within a C... by steveklabnik on Friday July 26, 2019 @04:58PM (#20538277)
Sure; I'm not aware of anybody using cpp with Rust either.
Re:Asm-declaration – Embed assembly language code within a C... by pjmlp on Friday July 26, 2019 @01:43PM (#20536631)
> Getting away from the pre-processor is considered a pro, not a con.

Yep, even ISO C++ is putting energy into making each standard revision one reason less to use it.

Re:Asm-declaration – Embed assembly language code within a C... by pjmlp on Friday July 26, 2019 @01:06PM (#20536310)
Unisys ClearPath MCP, the modern version of the Burroughs linage never supported any kind of Assembly, instead it was the first high level systems programming language to use compiler intrinsics, in 1961.

The same path that Microsoft has decided to follow since they introduced 64 bit support. Compiler intrinsics.

Also copy paste inline Assembly from C into Rust only works for a specific C compiler.

Re:Asm-declaration – Embed assembly language code within a C... by cesarb on Friday July 26, 2019 @12:58PM (#20536245)
> Being able to grab a chunk of inline assembly from a C project is very useful.

Wasn't Rust's current inline assembly syntax subtly different from the gcc-compatible one you'd find in most C projects? IIRC, it uses the syntax from the LLVM IR to specify inputs and outputs, instead of the syntax from GCC inline assembly.

Re:Asm-declaration – Embed assembly language code within a C... by jashmatthews on Friday July 26, 2019 @11:07AM (#20535335)
Rust stdlib uses strings because it's just piping through to LLVM and that's what LLVM expects: http://llvm.org/docs/LangRef.html#inline-assembler-expressio...

There's also a Rust version of Dynasm.

Re:Asm-declaration – Embed assembly language code within a C... by snarfy on Friday July 26, 2019 @09:37AM (#20534666)
It gives me nostalgia seeing mode 13 graphics. What's next, mode x? Triangle drawing routines? :)
Re:Asm-declaration – Embed assembly language code within a C... by pan69 on Friday July 26, 2019 @06:29PM (#20538918)
I've actually picked this up as a hobby since a year ago or so.

I grew up in the late 80's early 90's doing exactly this type of thing as a kid. Having worked as a professional dev for the past few decades I started to notice that I've been taking my work home for all that time, and even though I like my work, I felt I needed a hobby as I'm getting older.

So, I'm currently making a shooting game for the 286/16 in modex VGA with SoundBlaster digitised sound and Adlib for music. All programmed from scratch...

Re:Asm-declaration – Embed assembly language code within a C... by jsd1982 on Saturday July 27, 2019 @12:59AM (#20540461)
Cool! Got a public repo of code? What toolchain are you using?
Re:Asm-declaration – Embed assembly language code within a C... by pan69 on Saturday July 27, 2019 @03:16AM (#20540821)
Sorry, no public repo, yet. Once I have something coherent working I will definitely publish it.

I'm using Watcom C v11. I actually bought this somewhere in the 90's. However, the Watcom tool chain is still being developed as Open Watcom. So, great for 32bit DOS:

https://github.com/open-watcom

Re:Asm-declaration – Embed assembly language code within a C... by nurettin on Friday July 26, 2019 @11:09AM (#20535345)
next, we implement bresenham's algorithms, then we embed antialiasing.
Re:Asm-declaration – Embed assembly language code within a C... by dfeojm-zlib on Friday July 26, 2019 @02:08PM (#20536917)
Ah yes. And Borland Pascal. Mode X VGA hackery in unreal mode. Later, when I worked for a software store in high school, I acquired Borland C++ 3.1, the physically-largest and heaviest (27 lbs / 12.2 kg) retail software package that I know of. It was a small software shop, they gave us crazy discounts, vendors gave us NFRs and they let us borrow anything on the shelf (trusty-dusty shrinkwrap machine). The profiler, debugger, and assembler were also good as there were protected-mode variants that could sometimes keep the machine from crashing.
Re:Asm-declaration – Embed assembly language code within a C... by gumby on Friday July 26, 2019 @07:00PM (#20539092)
> In a string literal?!?!

It's a thing literal as it is literally dumped straight into the generated .s file by the compiler, as most C compilers don't do the actual assembly or generation of object file.

Of course these days it's not literally dumped in unmodified -- various compilers do substitutions for you. But that's the legacy.

Re:Asm-declaration – Embed assembly language code within a C... by childintime on Friday July 26, 2019 @05:03PM (#20538306)
Assembler? Inline LLVM intermediate representation might be extremely useful instead, for many applications, see:

https://idea.popcount.org/2013-07-24-ir-is-better-than-assem...