News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

macro for call-convention name mangling

Started by KradMoonRa, June 17, 2018, 09:07:23 AM

Previous topic - Next topic

KradMoonRa

 :biggrin:

After some research how exported symbols from uasm to call convention c or c++ works, I came with a macro to make the task easy to write asm code.

Currently I only have it done for __vectorcall exported c function. I want to know more about unix gcc or clang systemv call and the name mangling for it. Researching how c++ name mangling applies for the different compilers, conventions and  architecture.


#ifdef __cplusplus
extern "C" {
#endif
extern __m128i __vectorcall _uXm_mm_move_si128(__m128i Inxmm_A);
#ifdef __cplusplus
}
#endif



include uXmx86asm.inc

_uXm_func_start _uXm_mm_move_si128, xmmword, < >, 16 ;xmm_size ;InXmm_A:xmmword
movdqa xmm0, xmm0
ret
_uXm_func_end
.code




;; function proc macro start
;; name, return type, uses, parameter's size
_uXm_func_start macro functionName:REQ, retType:REQ, usesStr:REQ, parameterSize:REQ
ifdef WINDOWS
curfunctionName textequ <functionName>
  ifdef EXTERNC_VECCALL
curfunctionName catstr curfunctionName, <@@>, _uXm_StrValue(parameterSize)
  endif
_curfunctionName_ textequ <curfunctionName>
else
_curfunctionName_ textequ <functionName>
endif

fnexproto textequ <>
fnexproto catstr fnexproto, <&functionName&>
ifdef WINDOWS
  ifdef EXTERNC_VECCALL
fnexproto catstr fnexproto, <@@>, _uXm_StrValue(parameterSize)
  endif
else
endif
fnexproto catstr fnexproto, < proto __veccall >, <(&retType&)>
fnexproto

fnexproc textequ <>
fnexproc catstr fnexproc, <&functionName&>
ifdef WINDOWS
  ifdef EXTERNC_VECCALL
fnexproc catstr fnexproc, <@@>, _uXm_StrValue(parameterSize)
  endif
else
endif
fnexproc catstr fnexproc, < proc __veccall >, <(&retType&)>, < >, <frame>, < >, <&usesStr&>

fnexproc
endm

;; function proc macro end
_uXm_func_end macro
fnexfuncend textequ <>
fnexfuncend catstr fnexfuncend, _curfunctionName_
fnexfuncend catstr fnexfuncend, < endp>
fnexfuncend
endm


Some examples in the zip file
The uasmlib

habran

Hi KradMoonRa :biggrin:
Who am I to criticise your style of coding, however, you get me lost at second '_
It is painful for me to read expressions like: _uXm_func_start _uXm_mm_move_si128 _uXm_func_end
I believe you would get more people interested in your code if you simplify your expressions EG:
UxmFuncStart or something similar.
Please, don't be offended, I appreciate your intentions and work 8)
Cod-Father

KradMoonRa

Hi habran  :biggrin:,

No problem, really appreciate Your comment.
Macro definitions (one of the thing's i mess around in macro world), but just for the sake of read and search, which conflicts with fast coding write, almost I do its a copy and paste with the rename.

I'll change my code.
The uasmlib

habran

I am glad you are not offended, that tells me more about your great personality:t
Keep up good work 8)
Cod-Father

KradMoonRa

#4
 :biggrin:

  Coding is fun. Some dig-in the UASM code, I made some 2 small options changes in the code to use vectorcall globally uasm command option -Gv and names mangle exported symbols for vectorcall with a help of macro to emulate xmmword sizes.

  Unfortunately I have no idea to make the necessary changes in uasm mangler to recognize param sizes higher than the general register type sizes 8 for 64bits 4 for 32bits.

  I have played with ParseParams and parasize but no idea to make work correctly, CurrWordSize its a fixed value only applies to general registers and the code never checks for different registers types and sizes.

  Staying with macros if the reference parameter its never used in asm, this emulates the xmmword sizes with extra general register references parameters.

Example:
 
_uX_mm_shuffle_ps proc uXveccall (xmmword) xmmwordparam1(InxmmA), xmmwordparam2(InxmmB), _Imm8:dword
     ret
_uX_mm_shuffle_ps endp


prints correctly
_uX_mm_shuffle_ps@@40  (2*xmmword+gr)

Attached precompiled uasm requerid to test and my test examples.


The uasmlib

jj2007

Quote from: KradMoonRa on June 27, 2018, 04:26:34 AMUnfortunately I have no idea to make the necessary changes in uasm to recognize param sizes higher than the general register type sizes 8 for 64bits 4 for 32bits.

Have you tried something like this:
themac MACRO arg
Local is
  is INSTR <arg>, <xmm>
  if is
      ... 16 byte code ...
  else
    if TYPE(arg) eq XMMWORD
      ... 16 byte code ...
    elseif TYPE(arg) eq QWORD
      ... 8 byte code ...
    elseif TYPE(arg) eq DWORD
      ...
    else
  endif
ENDM

johnsa

:XMMWORD If i recall should be a recognised type, as well as the new built in data types for __m128 etc.
UASM already supports vectorcall and uses those types on the arguments list.. Perhaps give that a try and just focus on name-mangling of the proc name itself ?

KradMoonRa

#7
Hi  :biggrin: jj2007 and johnsa,

Quotejj2007
That will be a good solution to recognize the types in asm, and send the correct int. Macro its cool indeed.

Quotejohnsa
Sorry I have not explained correctly myself.
  I has only trying to use the mangler edition already in uasm, but its only available for stdcall and or fastcall, one little add in uasm c++ code I almost do what I pretend, barely miss the essential to recognize the types reg's sizes (print) for xmmword ymmword zmmword, same results for __m128, __m256, __m512, wen its an reference param in protos or procs.

   I'm happy with the macros, but love to find new options already in uasm, but I never know if I dont read the uasm c code itself.

  :t
The uasmlib