|
|
Log in / Subscribe / Register

DeVault: Announcing the Hare programming language

DeVault: Announcing the Hare programming language

Posted May 4, 2022 14:24 UTC (Wed) by khim (subscriber, #9252)
In reply to: DeVault: Announcing the Hare programming language by wtarreau
Parent article: DeVault: Announcing the Hare programming language

> I'm using more and more asm() statements to prevent the compiler from lurking into what I'm doing ?

Yes, absolutely.

> I don't think so.

Why no? You said you want to “use my processor and OS for the purpose they were built” and in C all such code have to live in asm block.

The fact that it took so long for you to realize that is kinda unfortunate, but why would you perceive it as a bad thing?

> It feels like one day my whole C code will only be a bunch of macroes based on asm() statements.

If you insist on using non-portable construct in every line of code then sure, that's the proper outcome.

> That's not my goal when I'm using a C compiler, really.

That's the only proper way to write non-portable code in C. It makes non-portable code look like a portable code which is obviously a good thing.


to post comments

DeVault: Announcing the Hare programming language

Posted May 5, 2022 13:08 UTC (Thu) by wtarreau (subscriber, #51152) [Link] (2 responses)

> You said you want to “use my processor and OS for the purpose they were built” and in C all such code have to live in asm block.

Ah no, sorry for not being clear. I have to use asm statements to prevent the compiler from being smart!

Typically stuff like this that current compilers are not yet able to optimize away to produce stupid code :

#define GUESSWHAT(v) ({ typeof(v) _v; asm volatile("" : "=rm"(_v) : "0"(_v)); _v; })

It usually only costs a move or two due to register allocation, so it's cheap. And using that in high-level code is ugly. But at least it doesn't know my pointer's value and doesn't play games in my back with it.

DeVault: Announcing the Hare programming language

Posted May 5, 2022 14:08 UTC (Thu) by khim (subscriber, #9252) [Link] (1 responses)

> I have to use asm statements to prevent the compiler from being smart!

That's wrong way of doing things and you know that. Code outside of asm block have to follow the rules.

> But at least it doesn't know my pointer's value and doesn't play games in my back with it.

GCC doesn't know anything. It just emits asm blocks blindly. Clang certainly does know what happens in your asm block, it has a built-in assembler specifically for such cases.

I think what you actually want is std::launder (in C you can just call __builtin_launder directly).

DeVault: Announcing the Hare programming language

Posted May 5, 2022 15:22 UTC (Thu) by wtarreau (subscriber, #51152) [Link]

Thanks for the tip, but there isn't any trace of it in gcc's docs... Thus I'll keep that hack for a few more decades it seems.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds