flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Problem with 'proc' macro 64bit

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 16 Feb 2016, 14:50
I've converted an old opengl program to work with the new glut32 library called 'freeglut' which has a 64bit version of glut. At first, I thought my code was the problem, but discovered that it was a stack alignment problem in the 64bit proc macro.
Here is the problem area, full code can be downloaded below:

Code:
proc gldisplay
     ;local jitter:QWORD, transx:DWORD, transy:DWORD, ftemp:DWORD, viewport[4]:DWORD <- doesn't work right
     local jitter:QWORD, viewport[4]:DWORD, transx:DWORD, transy:DWORD, ftemp:DWORD ;<- does work right

     invoke  glGetIntegerv, GL_VIEWPORT, addr viewport

     invoke  glClear, GL_ACCUM_BUFFER_BIT
    


Full code:


Description:
Download
Filename: Old OpenGL Examples Renewed.rar
Filesize: 90.16 KB
Downloaded: 555 Time(s)


_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 16 Feb 2016, 14:50
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 16 Feb 2016, 14:59
Sorry about this, should have added that I'm using some redefined macros in proc macro:
Code:
;Well, if you wanted size optimization, you could change the macro to use
;PUSH/POP for registers instead of MOV. Something like this, I think:
macro static_rsp_prologue procname,flag,parmbytes,localbytes,reglist
 { local counter,loc,frame,current
   counter = 0
   irps reg, reglist \{ push reg
                        counter = counter+1 \}
   loc = (localbytes+7) and (not 7)
   if frame & (counter+loc shr 3+1) and 1
    loc = loc + 8
   end if
   framebytes@proc equ frame+loc
   if framebytes@proc
    sub rsp,framebytes@proc
   end if
   localbase@proc equ rsp+frame
   regsbase@proc equ rsp+frame+loc
   parmbase@proc equ rsp+frame+loc+counter*8+8
   current = 0
   current@frame equ current
   size@frame equ frame }

macro static_rsp_epilogue procname,flag,parmbytes,localbytes,reglist
 { if framebytes@proc
    add rsp,framebytes@proc
   end if
   irps reg, reglist \{ reverse pop reg \}
   retn }

macro static_rsp_close procname,flag,parmbytes,localbytes,reglist
 { size@frame = current@frame
   restore size@frame,current@frame }

prologue@proc equ static_rsp_prologue
epilogue@proc equ static_rsp_epilogue
close@proc equ static_rsp_close
;end extra code

stdcall fix fastcall


macro cinvoke proc,[arg]
 { common ccall [proc],arg }

macro ccall proc,[arg]
 { common vararg@fastcall = 1
          fastcall proc,arg
          vararg@fastcall = 0 }

vararg@fastcall = 0     
Post 16 Feb 2016, 14:59
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 16 Feb 2016, 15:02
madmatt
The problem is that local variable definition macros do not provide any guarantees for the alignment. In your case they don't even have to do that. But a possibility for explicit alignment specification is desirable. Here's a bit of a discussion on that.

_________________
Faith is a superposition of knowledge and fallacy
Post 16 Feb 2016, 15:02
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 16 Feb 2016, 15:23
l_inc wrote:
madmatt
The problem is that local variable definition macros do not provide any guarantees for the alignment. In your case they don't even have to do that. But a possibility for explicit alignment specification is desirable. Here's a bit of a discussion on that.


Strange! But I didn't add or remove anything, just re-arranged. Why would one variation be aligned, and another not?

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 16 Feb 2016, 15:23
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 16 Feb 2016, 15:35
madmatt
Because the local variables are put onto the stack in the order you enumerate them. The stack at the beginning of the procedure is aligned to at least 16 bytes (because the calling convention demands that). So if you put one qword in front of viewport, than it will be aligned to 8 bytes only. And if you put 3 more dwords in front of it, than it will be aligned to 4 bytes only.

_________________
Faith is a superposition of knowledge and fallacy
Post 16 Feb 2016, 15:35
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 16 Feb 2016, 16:05
l_inc wrote:
madmatt
Because the local variables are put onto the stack in the order you enumerate them. The stack at the beginning of the procedure is aligned to at least 16 bytes (because the calling convention demands that). So if you put one qword in front of viewport, than it will be aligned to 8 bytes only. And if you put 3 more dwords in front of it, than it will be aligned to 4 bytes only.


Hmmm, all right, I guess I have to keep an eye on that from now on.

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 16 Feb 2016, 16:05
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.