Memory-align the first variable when Structure Align is used

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Memory-align the first variable when Structure Align is used

Post by Keya »

Tonight i needed an aligned variable but there doesnt seem to be any direct way. I was able to come up with a workaround using pointers and CopyMemory but its not pretty.

At the moment you might have something like this:

Code: Select all

Structure Bytes Align 16
 Byte1.a
 Byte2.a
EndStructure
and Byte2 will be 16 bytes after Byte1, BUT the address for Byte1 won't necessarily be a 16-aligned address... but that's what's often needed now with a lot of these new x64 instructions as i keep finding out!

basically my problem would been solved if the "Align n" parameter of the Structure command also ensured that the first element is aligned. It'd be great to be able to align all variables, like "Protected myvar.i Align 16" as well, but at least if Structures have that ability with the first element i guess it would be sufficient?

Thankyou very much for your consideration
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Memory-align the first variable when Structure Align is

Post by wilbert »

Keya wrote:that's what's often needed now with a lot of these new x64 instructions as i keep finding out!
It's also needed with a lot of SSE instructions.
It would be great to have this ability you are requesting for 16 byte aligned variables.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Memory-align the first variable when Structure Align is

Post by Keya »

please also add alignment to function calls to ensure the stack is correctly aligned! perhaps ...

Code: Select all

Import ""
  SomeAlignedFunction.i() Align 16
EndImport
Post Reply