The MASM Forum

64 bit assembler => UASM Assembler Development => Topic started by: TouEnMasm on November 25, 2020, 06:31:13 AM

Title: vectorcall
Post by: TouEnMasm on November 25, 2020, 06:31:13 AM
Hello,
I have a fonction who need the  __vectorcall.
UASM don't seem to support it.
Is there a way  to correct this ?

Title: Re: vectorcall
Post by: jj2007 on November 25, 2020, 08:27:51 AM
You have one function? Just load the registers manually, then use call thefunction
Title: Re: vectorcall
Post by: TouEnMasm on November 25, 2020, 06:58:26 PM

Good idea but ...
in c++
Quote
   the call look strange
   .data
   Eye    CXMVECTOR <0.0, 3.0, -6.0, 0.0> ; 4*REAL4
   At    CXMVECTOR < 0.0, 1.0, 0.0, 0.0 >
   Up    CXMVECTOR <0.0, 1.0, 0.0, 0.0>
   .code
   
   mov g_View,func(XMMatrixLookAtLH,addr Eye,addr At,addr Up)
;-------------------------------------------------------------------   
/quote]

in asm /FA

Quote
   FXMVECTOR  ptr XMVECTOR
;################################################################
XMMatrixLookAtLH PROC  EyePosition:FXMVECTOR ,FocusPosition:FXMVECTOR ,UpDirection:FXMVECTOR
         Local  retour:DWORD
         mov retour,1
   movaps   xmm2, XMMWORD PTR UpDirection
   movaps   xmm1, XMMWORD PTR FocusPosition
   movaps   xmm0, XMMWORD PTR EyePosition
   lea   eax, DWORD PTR $T4[ebp]               ;<<<<<<<<<<<<<<< created by c++ in stack ???????????????
   push   eax
   call   ?XMMatrixLookAtLH@@YA?AU_XMMATRIX@@T__m128@@00@Z ; XMMatrixLookAtLH

FindeXMMatrixLookAtLH:
         mov eax,retour
         ret
XMMatrixLookAtLH endp
[



Title: Re: vectorcall
Post by: TouEnMasm on November 25, 2020, 07:29:40 PM
If i understand well,the space needed by XMMVECTOR (size=40h 64 ) is reserved on the stack as last argument

XMMATRIX    XM_CALLCONV     XMMatrixLookAtLH(FXMVECTOR EyePosition, FXMVECTOR FocusPosition, FXMVECTOR UpDirection);


translate by C++ this give
Quote
extern "C" int _stdcall    AXMMatrixLookAtLH(FXMVECTOR EyePosition, FXMVECTOR FocusPosition, FXMVECTOR UpDirection)
{
   XMMatrixLookAtLH(EyePosition,  FocusPosition, UpDirection);
   return 0;



Quote
;   COMDAT _AXMMatrixLookAtLH@48
_TEXT   SEGMENT
$T1 = -176                  ; size = 64
_UpDirection$ = -48               ; size = 16
_FocusPosition$ = -32               ; size = 16
_EyePosition$ = -16               ; size = 16
_AXMMatrixLookAtLH@48 PROC            ; COMDAT
; _EyePosition$ = xmm0
; _FocusPosition$ = xmm1
; _UpDirection$ = xmm2
; File H:\directx\Tutorial07\Tutorial07.cpp
; Line 31
   push   ebx
   mov   ebx, esp
   sub   esp, 8
   and   esp, -16            ; fffffff0H
   add   esp, 4
   push   ebp
   mov   ebp, DWORD PTR [ebx+4]
   mov   DWORD PTR [esp+4], ebp
   mov   ebp, esp
   sub   esp, 184            ; 000000b8H
   push   esi
   push   edi
   movaps   XMMWORD PTR _UpDirection$[ebp], xmm2
   movaps   XMMWORD PTR _FocusPosition$[ebp], xmm1
   movaps   XMMWORD PTR _EyePosition$[ebp], xmm0
; Line 32
   movaps   xmm2, XMMWORD PTR _UpDirection$[ebp]
   movaps   xmm1, XMMWORD PTR _FocusPosition$[ebp]
   movaps   xmm0, XMMWORD PTR _EyePosition$[ebp]
   lea   eax, DWORD PTR $T1[ebp]
   push   eax
   call   ?XMMatrixLookAtLH@@YA?AU_XMMATRIX@@T__m128@@00@Z ; XMMatrixLookAtLH
   add   esp, 4
; Line 33
   xor   eax, eax
; Line 34
   pop   edi
   pop   esi
   mov   esp, ebp
   pop   ebp
   mov   esp, ebx
   pop   ebx
   ret   0
_AXMMatrixLookAtLH@48 ENDP

Title: Re: vectorcall
Post by: LiaoMi on November 27, 2020, 04:26:02 AM
Quote from: TouEnMasm on November 25, 2020, 06:31:13 AM
Hello,
I have a fonction who need the  __vectorcall.
UASM don't seem to support it.
Is there a way  to correct this ?

Hi TouEnMasm,

https://github.com/Terraspace/UASM/blob/master/regress/src/vcall/vectorcall.asm
Title: Re: vectorcall
Post by: TouEnMasm on November 27, 2020, 06:31:50 AM

Thanks , it's work only in 64 bits.
Title: Re: vectorcall
Post by: nidud on November 27, 2020, 09:54:00 AM
deleted
Title: Re: vectorcall
Post by: TouEnMasm on November 27, 2020, 07:34:23 PM

Vectorcall is perfectly defined here https://docs.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-160 (https://docs.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-160)
Attached is the code sample with the annotated assembly listing.
Title: Re: vectorcall
Post by: johnsa on December 05, 2020, 05:15:04 AM
I implemented vectorcall for 64bit, but never for 32bit. If there is sufficient demand it would be relatively trivial to extend this as the convention is the same and the registers are the same.
I just didn't because A I'm lazy and B I never use 32bit code anymore, especially with vectorcall :)
Title: Re: vectorcall
Post by: TouEnMasm on December 05, 2020, 05:28:40 AM
Thanks for answer.
Don't obliged you to do it.
There is surely better things to do as made better the debugging in 64.