Stream: general

Topic: Creating static array to share with asm

Kyle Siefring (Jan 03 2019 at 04:06, on Zulip):

I have some assembly copied from a C project that has relies on an array defined as such
const int8_t ALIGN(dav1d_mc_subpel_filters[5][15][8], 8) = ...
and I want to make sure that I'm not triggering undefined behavior.

Is the following rust code defined to have the same effect as const int8_t ALIGN(FOO[16], 8) = { 42, 42, 42, ... };

#[repr(C, align(8))]
pub struct Aligned([i8; 16]);
pub static FOO: Aligned = Aligned([42; 16]);
nagisa (Jan 03 2019 at 11:09, on Zulip):

Depends on what ALIGN is, but on most platforms, yes. To be extra pedantic it is the same as struct { int8_t [16]; } __attribute__((align(8))), and there may be platforms where this is not exactly the same as an aligned array with 16 elements.

Last update: Jul 16 2020 at 14:20UTC