flat assembler
Message board for the users of flat assembler.

Index > Main > How to align SSE variables

Author
Thread Post new topic Reply to topic
SDragon



Joined: 13 Sep 2005
Posts: 19
Location: Siberia
SDragon 13 Sep 2005, 05:31
I have the following code:
Code:
format MS COFF ; it's an .obj file to be linked with MSVC++ program
include '%fasminc%\win32a.inc'
section '.data' data readable writeable
; align 16
cx1 dd 4 dup ?
cy1 dd 4 dup ?
        ; some other declarations

section '.text' code readable executable
proc PaintSSE c
        ; some other code
        MOVAPS dqword[cx1], xmm0 ; NEED 16-byte align here!
        MOVAPS dqword[cy1], xmm1
        ; some other code
endp
public PaintSSE as '_PaintSSE'    

How to align cx1 and cy1 on 16-byte boundary? I've tried align 16, but it reports "section is not aligned enough". This macro from manual:
Code:
macro align value { rb (value-1)-($+value-1) mod value }    

doesn't help too (it says "invalid expression").
How do I align 128-bit variables?
Post 13 Sep 2005, 05:31
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 13 Sep 2005, 15:17
Although my macro posted below works alright, I had to use virtual, and don't have an idea why doesn't it work the way you had it.
Code:
macro dalign value {
 local __ADDR
 virtual
  dd $
  load __ADDR dword from $-4
 end virtual
 rb value-(__ADDR mod value) }    
Post 13 Sep 2005, 15:17
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 13 Sep 2005, 15:49
Quote:
I've tried align 16, but it reports "section is not aligned enough".

This means you have to align the section first - when section is not aligned on 16 bytes boundary, aligning the data relatively to the beginning of this section is useless. For the same reason you cannot use $ symbol this way, since assembler doesn't know at what address this section will be put by the linker/loader. To align the section, you declare it like:
Code:
section '.data' data readable writeable align 16    

This tells the linker that this section should be put at aligned address; and thus assembler can do "align 16" and smaller alignments inside such section without problems (and in the beginning of section you even don't have to do additional alignment).
Post 13 Sep 2005, 15:49
View user's profile Send private message Visit poster's website Reply with quote
SDragon



Joined: 13 Sep 2005
Posts: 19
Location: Siberia
SDragon 14 Sep 2005, 00:49
Thank you very much, Tomasz. It works!
Post 14 Sep 2005, 00:49
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 16 Sep 2005, 20:56
Tomasz: Why is it so? Sections in PE are aligned always to at least 512, so I guess all alignments in sections below that value should be possible. I agree with your point of view (as I understand it), but only for alignment values greater than the default 512.
Post 16 Sep 2005, 20:56
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 Feb 2006, 15:45
while revising old thread i found this unanswered question interesting... Tomasz?
Post 15 Feb 2006, 15:45
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Feb 2006, 15:58
The sections in COFF are not the same thing as sections in PE - the linker may compose the final PE section out of many COFF sections of the same name, and when it concatenates them, it uses the alignment specified for each of them.
Post 15 Feb 2006, 15:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.