Assuming I wanted to (ab)use cache coherency to do lock free reads like FaRM, would it be enough to have a struct with a single 64 byte array as data to guarantee that on an architecture with 64 byte cache lines each struct would occupy exactly one cache line?
Asked
Active
Viewed 1,742 times
1 Answers
9
No, that wouldn't guarantee that the alignment was a cache line.
RFC 1358 added the concept of #[repr(align)]
, allowing the programmer to specify alignment requirements. This attribute was stabilized in Rust 1.25.
For your specific case, you'd use it like:
#[repr(align(64))]
struct Foo {
value: u8,
}

Shepmaster
- 388,571
- 95
- 1,107
- 1,366

Chris Emerson
- 13,041
- 3
- 44
- 66
-
I am confusing the size of the array with the size of the type. I guess there aren't any 64 byte simd types. – benjumanji Dec 11 '16 at 19:41
-
There's [AVX512](https://en.m.wikipedia.org/wiki/AVX-512). Not sure if Rust supports it yet. – Chris Emerson Dec 11 '16 at 19:45
-
@ChrisEmerson: Rust doesn't have SIMD types yet. It's a big topic of discussions, lots of people are waiting for them (and the instructions that go with them) but there are many different needs/expectations/wants so it's taking a long time to converge... – Matthieu M. Dec 12 '16 at 09:55
-
@MatthieuM. Yes, I'm following the discussions. :-) But there is [some unstable `#[repr(simd)]`](http://huonw.github.io/blog/2015/08/simd-in-rust/) support on nightlies, as far as I am aware. – Chris Emerson Dec 12 '16 at 09:59
-
@ChrisEmerson: To be honest, though, I'm not quite clear on the exact effect of applying `#[repr(simd)]`. Does it somehow use the size as alignment? – Matthieu M. Dec 12 '16 at 10:15
-
@MatthieuM. I think so, but that's only an assumption; I haven't checked. – Chris Emerson Dec 12 '16 at 10:17