News for hackers. Stuff that matters.
Re:The x86 architecture is the weirdo (2004) by ncmncm on Tuesday April 19, 2022 @11:24AM (#31084382)
Superstition is as powerful as it ever was.
Re:The x86 architecture is the weirdo (2004) by cryptonector on Tuesday April 19, 2022 @06:10PM (#31089973)
It's definitely received wisdom that may once have been right and no longer is.

Most people are not used to facts having a half-life, but many facts do, or, rather, much knowledge, does.

We feel very secure in knowing what we know, and the reality is that we need to be willing to question a lot of things, like authority, including our very own. Now, we can't be questioning everything all the time because that way madness lies, but we can't never question anything we think we know either!

Epistemology is hard. I want a doll that says that when you pull the cord.

Re:The x86 architecture is the weirdo (2004) by cogman10 on Tuesday April 19, 2022 @06:48PM (#31090390)
Sort of depends on the knowledge.

It's certainly true that in the tech industry things are CONSTANTLY shifting.

However, talk physics and you'll find that things rarely change, especially the physics that most college graduates learn.

Re:The x86 architecture is the weirdo (2004) by cryptonector on Wednesday April 20, 2022 @11:01AM (#31097936)
There was a famous study about the half-lives of "facts" in different fields. They do seem to vary by field.
Re:The x86 architecture is the weirdo (2004) by MBCook on Tuesday April 19, 2022 @04:02PM (#31088231)
Is this superstition or more received wisdom, which may have been true at one point in the past as is now just orthodoxy?
Re:The x86 architecture is the weirdo (2004) by notriddle on Tuesday April 19, 2022 @04:04PM (#31088260)
Fifty bucks says it isn't even about performance, but is instead about passing pointers to C code. Zero-overhead FFI has killed a lot of radical performance improvements that Rust could have otherwise made.

I don't know, because nobody's actually posting a link to it.

Re:The x86 architecture is the weirdo (2004) by ncmncm on Tuesday April 19, 2022 @06:04PM (#31089906)
This strikes me as likely. Bitwise compatibility with machine ABI layout rules has powerful compatibility advantages even in places where it might make code slower. (And, for the large majority of code, slower doesn't matter anyway.)

Of course C and C++ themselves have to keep to machine ABI layout rules for backward compatibility to code built when those rules were (still) thought a good idea. Compilers offer annotations to dictate packing for specified types, and the Rust compiler certainly also offers such a choice. So, maybe such annotations should just be used a lot more in Rust, C, and C++.

This is not unlike the need to write "const" everywhere in C and C++ because the inherited default (from before it existed) was arguably wrong. We just need to get used to ignoring the annotation clutter.

But there is no doubt there are lots of people who think padding to alignment boundaries is faster. And, there can be other reasons to align even more strictly than the machine ABI says, even knowing what it costs.

Re:The x86 architecture is the weirdo (2004) by nynx on Tuesday April 19, 2022 @09:05PM (#31091527)
Rust structs have non-C layouts. You can optionally specifiy that a struct should be laid out in the same way that C does it.
Re:The x86 architecture is the weirdo (2004) by notriddle on Wednesday April 20, 2022 @09:35AM (#31096714)
Structs aren’t the problem here. It’s the primitives.

You can take a pointer to an i32 and pass that pointer to C code as int32_t. This means it has to have the same alignment in Rust that it has in C.

Re:The x86 architecture is the weirdo (2004) by ncmncm on Wednesday April 20, 2022 @12:27PM (#31099370)
The topic at hand is, specifically, that nobody makes cores that enforce alignment restrictions anymore. So, it doesn't matter where the pointer goes. All that matters is if your compiler lays out its structs the same way as whoever compiled the code a pointer to one ends up in.

There are embedded targets that still enforce alignment restrictions, but you are even less likely to pass pointers between code compiled with different compilers, there.

Re:The x86 architecture is the weirdo (2004) by notriddle on Wednesday April 20, 2022 @02:42PM (#31101176)
> The topic at hand is, specifically, that nobody makes cores that enforce alignment restrictions anymore. So, it doesn't matter where the pointer goes.

Compilers can rely on alignment even if the CPU doesn't. LLVM does, which is why older versions of rustc had segfaults when repr(packed) used to allow taking references. While it would be pretty easy to get rustc to stop emitting aligned loads, getting Clang and GCC to stop emitting aligned loads might be trickier. https://github.com/rust-lang/rust/issues/27060

Re:The x86 architecture is the weirdo (2004) by ncmncm on Tuesday April 19, 2022 @10:25PM (#31092075)
People arguing against changing struct layout rules are probably mainly interested, then, in maintaining backward compatibility with older Rust, itself.

Anyway, same policy applies: annotate your structs "packed" anywhere performance matters and bitwise compatibility with other stuff doesn't.

Re:The x86 architecture is the weirdo (2004) by zozbot234 on Wednesday April 20, 2022 @04:26AM (#31094181)
Rust does not keep backward compatibility like that. In the absence of any statement forcing a specific ABI, the only guaranteed compatibility is with code that's part of the same build, or else part of the current Rust runtime and being linked into said build.
Re:The x86 architecture is the weirdo (2004) by ncmncm on Wednesday April 20, 2022 @12:34PM (#31099480)
Even in Rust, mapping memory between processes, or via files between past and future processes, happens. Although structure-blasting is frowned upon in some circles, it is very fast where allowed.

But... when you are structure-blasting, you are probably also already paying generous attention to layout issues.