Author Topic: Directive query  (Read 2988 times)

Biterider

  • Member
  • *****
  • Posts: 1083
  • ObjAsm Developer
    • ObjAsm
Directive query
« on: April 07, 2020, 04:39:42 PM »
Hi
Is there a way to determine at compile-time if the .xmm directive was activated?
I recently came to the situation where I had to disable a code path that uses sse instructions and it would have been handy to know if these instructions were enabled or not.

What about the more advanced instruction sets like sse2, sse3, ... avx2? Are there directives or options for them?  :rolleyes:
I checked the manual and found no reference. Maybe I'm missing something ...

Biterider

KradMoonRa

  • Member
  • **
  • Posts: 80
Re: Directive query
« Reply #1 on: April 07, 2020, 11:02:30 PM »
Hi Biterider,

Think uasm in x64 defaults always implies to xmm if not option arch:avx or option evex:1 implies option arch:avx.

For 32bits the options are more vast an intriguing to do.
« Last Edit: April 08, 2020, 03:36:03 AM by KradMoonRa »

mabdelouahab

  • Member
  • ****
  • Posts: 537
Re: Directive query
« Reply #2 on: April 08, 2020, 02:06:08 AM »
Maybe this solves the problem  :biggrin:
Code: [Select]
ifdef xmm0
echo 1st check
endif
.xmm
ifdef xmm0
echo  2ndt check
endif


2ndt check

Make finished.
Total compile time 469 ms

Biterider

  • Member
  • *****
  • Posts: 1083
  • ObjAsm Developer
    • ObjAsm
Re: Directive query
« Reply #3 on: April 08, 2020, 04:11:05 AM »
Hi
Thank you for your suggestions.  :thumbsup:
For now I will go with "ifdef xmm0"

Biterider

Biterider

  • Member
  • *****
  • Posts: 1083
  • ObjAsm Developer
    • ObjAsm
Re: Directive query
« Reply #4 on: April 08, 2020, 05:11:20 AM »
Hi mabdelouahab
Unfortunately it doesnt work for me. I got the following output:
Code: [Select]
1st check
2ndt check

Maybe I'm doing something wrong. Can you post your complete code and UASM settings? That will help.

Biterider

mabdelouahab

  • Member
  • ****
  • Posts: 537
Re: Directive query
« Reply #5 on: April 08, 2020, 05:35:56 AM »
C:\Masm32\Bin\ML.EXE /c /coff /Cp /nologo /I"C:\Masm32\Include" "for_test.asm"
 Assembling: for_test.asm

***********
ASCII build
***********

2ndt check

Make finished.
Total compile time 500 ms

Code: [Select]
include masm32rt.inc

.code
Start:
ifdef xmm0
echo 1st check
endif
.xmm
ifdef xmm0
echo  2ndt check
endif
inkey
exit
end Start

it doesnt work with UASM  :sad:

C:\Masm32\Bin\uasm64.EXE /c /coff /Cp /nologo /I"C:\Masm32\Include" "for_test.asm"

***********
ASCII build
***********

1st check
2ndt check
for_test.Asm: 14 lines, 2 passes, 127 ms, 0 warnings, 0 errors

Make finished.
Total compile time 265 ms

Biterider

  • Member
  • *****
  • Posts: 1083
  • ObjAsm Developer
    • ObjAsm
Re: Directive query
« Reply #6 on: April 08, 2020, 05:39:21 AM »
OK, thanks.
Quote
it doesnt work with UASM  :sad:

That is my problem too.

habran

  • Member
  • *****
  • Posts: 1228
    • uasm
Re: Directive query
« Reply #7 on: April 08, 2020, 10:44:29 AM »
Hi Biterider,

I think the solution is a variable @Arch. Here is how to use it in compile time (it is from UASM Extended Guide):
Code: [Select]
2.15) NEW LANGUAGE TYPES
Procedures can now be decorated with attribute SYSTEMV to generate a 64bit SystemV ABI call.
For example:
OPTION ARCH:SSE
nixproc PROC SYSTEMV FRAME USES rbx xmm0 arg1:qword, arg2:DWORD, arg3:REAL4
 mov rbx,arg1
 mov ecx,arg2
IF @Arch EQ 0
 movss xmm10,arg3
ELSE
 vmovss xmm10,arg3
ENDIF
ret
nixproc ENDP
OPTION ARCH:AVX
Cod-Father

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Directive query
« Reply #8 on: April 08, 2020, 01:33:33 PM »
I think the solution is a variable @Arch

That works:
Code: [Select]
  ifdef @Arch
tmp$ CATSTR <Arch=>, %@Arch
% echo tmp$
.err
  endif

Output: Arch=1

It could be a little bit more verbose, given that nobody reads manuals, and of course it's not MASM-compatible, but it works indeed.

Biterider

  • Member
  • *****
  • Posts: 1083
  • ObjAsm Developer
    • ObjAsm
Re: Directive query
« Reply #9 on: April 08, 2020, 03:25:25 PM »
Hi habran
That is what I was looking for. Thanks!  :thumbsup:

Biterider

habran

  • Member
  • *****
  • Posts: 1228
    • uasm
Re: Directive query
« Reply #10 on: April 08, 2020, 06:50:52 PM »
No problemo Biterider :biggrin:
Sometimes, when you run out of ideas look up the option.c . You can get an idea how it is implemented.
in this case it is this function:
Code: [Select]
/* OPTION ARCH:SSE/AVX */
OPTFUNC( SetArch )
{
int i = *pi;
struct asym *archSym = SymFind("@Arch");

if (tokenarray[i].token == T_ID) {
if (0 == _stricmp(tokenarray[i].string_ptr, "SSE")) {
MODULEARCH = ARCH_SSE;
ModuleInfo.arch = ARCH_SSE;
archSym->value = ARCH_SSE;
}
else if (0 == _stricmp(tokenarray[i].string_ptr, "AVX")) {
MODULEARCH = ARCH_AVX;
ModuleInfo.arch = ARCH_AVX;
archSym->value = ARCH_AVX;
}
else {
return(EmitErr(SYNTAX_ERROR_EX, tokenarray[i].tokpos));
}
DebugMsg1(("SetArch(%s) ok\n", tokenarray[i].string_ptr));
i++;
}
else {
return(EmitErr(SYNTAX_ERROR_EX, tokenarray[i].tokpos));
}
*pi = i;
return( NOT_ERROR );
}
Of course it is easier if you know what are you looking for :wink2:

I would suggest to every serious programmer to get familiar with option.c source file
Cod-Father