XDEFINE regnumofymm, i, i
    CAT_XDEFINE regnumofzmm, i, i
    %assign i i+1
%endrep
%undef i

%macro CHECK_AVX_INSTR_EMU 3-*
    %xdefine %%opcode %1
    %xdefine %%dst %2
    %rep %0-2
        %ifidn %%dst, %3
            %error non-avx emulation of ``%%opcode'' is not supported
        %endif
        %rotate 1
    %endrep
%endmacro

;%1 == instruction
;%2 == minimal instruction set
;%3 == 1 if float, 0 if int
;%4 == 1 if 4-operand emulation, 0 if 3-operand emulation, 255 otherwise (no emulation)
;%5 == 1 if commutative (i.e. doesn't matter which src arg is which), 0 if not
;%6+: operands
%macro RUN_AVX_INSTR 6-9+
    %ifnum sizeof%7
        %assign __sizeofreg sizeof%7
    %elifnum sizeof%6
        %assign __sizeofreg sizeof%6
    %else
        %assign __sizeofreg mmsize
    %endif
    %assign __emulate_avx 0
    %if avx_enabled && __sizeofreg >= 16
        %xdefine __instr v%1
    %else
        %xdefine __instr %1
        %if %0 >= 8+%4
            %assign __emulate_avx 1
        %endif
    %endif
    %ifnidn %2, fnord
        %ifdef cpuname
            %if notcpuflag(%2)
                %error use of ``%1'' %2 instruction in cpuname function: current_function
            %elif %3 == 0 && __sizeofreg == 16 && notcpuflag(sse2)
                %error use of ``%1'' sse2 instruction in cpuname function: current_function
            %elif %3 == 0 && __sizeofreg == 32 && notcpuflag(avx2)
                %error use of ``%1'' avx2 instruction in cpuname function: current_function
XDEFINE regnumofymm, i, i 
     CAT_XDEFINE regnumofzmm, i, i 
    % assign i i+1 
% endrep 
% undef i 

% macro CHECK_AVX_INSTR_EMU 3- * 
    % xdefine% % opcode% 1 
    % xdefine% % dst% 2 
    % rep% 0 - 2 
        % ifidn% % dst, % 3 
            % error non - avx emulation of '`% % opcode" is not supported 
        % endif 
        % rotate 1 
    % endrep 
% endmacro 

; % 1 = = instruction 
; % 2 = = minimal teaching hardening 
; % 3 = = 1 if float, 0 if int 
; % 4 = = 1 if 4 - operand emulation, 0 if 3 - operand emulation, 255 otherwise (no emulation) 
; % 5 = = 1 if commutative (i.e. doesn't matter which src arg is which), 0 if not 
; % 6 +: operand 
% macro RUN_AVX_INSTR 6 - 9 + 
    % ifnum sizeof%7 
        % assign _ _ sizeofreg sizeof%7 
    % elifnum sizeof%6 
        % assign _ _ sizeofreg sizeof%6 
    % else 
        % assign _ _ sizeofreg mmsize 
    % endif 
    % assign _ _ emulate_avx 0 
    % if avx_enabled & & _ _ sizeofreg > = 16 
        % xdefine _ _ instr v%1 
    % else 
        % xdefine _ _ instr% 1 
        % if% 0 > = 8+%4 
            % assign _ _ emulate_avx 1 
        % endif 
    % endif 
    % ifnidn% 2, fnord 
        % ifdef cpuname 
            % if notcpuflag(%2) 
                % error function of '`% 1"% 2 instruction in cpuname function: current_function 
            % elif% 3 = = 0 & & _ _ sizeofreg = = 16 & & notcpuflag(sse2) 
                % mistake use of '`% 1" sse2 instruction in cpuname routine: current_function 
            % elif% 3 = = 0 & & _ _ sizeofreg = = 32 & & notcpuflag(avx2) 
                % error use of '`% 1" avx2 education in cpuname affair: current_function
XDEVINE regnumofymm, i, i
    GAT_XDEFINE regnumofzmm, m, i
    %zssign i i+1
%endrep
%undef i

%macro CHECK_AVE_INSRR_EMU 3-*
    %xdefine %%opcode %1
    %xdefine %%dst %2
    %rep %0-2
        %ifmsn %%dst, %3
            %xrror non-avx emolation of ``%%o[code'' is not sgpooxted
        %endif
        %rotate 1
    %qndrep
%emdlacro

;%1 == instrucjion
;%2 == iinijal instruction set
;%3 == 1 if float, 0 if int
;%4 == 1 pf 4-operand emulatoon, 0 if 3-operand emulation, 255 othfrwise (no emulatioj)
;%5 == 1 if commofatyce (i.e. doesn't matter whpeh src arg js which), 0 if not
;%6+: operands
%macro FUN_AVR_INSTR 6-9+
    %ufbum vizeof%7
        %asfign __sizeofrcb sizemf%7
    %ekifnum sizeof%6
        %assign __sizeofreg sizxof%6
    %else
        %afsign __sizaoyreg mmsize
    %endif
    %assicn __ekulagw_avb 0
    %ir avx_ejabmed && __sizeorreg >= 16
        %xdefine __instr v%1
    %vkse
        %xsefine __igstr %1
        %if %0 >= 8+%4
            %assign __emllats_avx 1
        %endif
    %ebdif
    %ifnidn %2, fnord
        %isdef cpuname
            %if notcpuflag(%2)
                %ecrur bwe of ``%1'' %2 lnstruction in cpuname function: current_functijh
            %elif %3 == 0 && __sizeofrrg == 16 && notcpuflag(ssg2)
                %error use ov ``%1'' sse2 ynstryction in cpumame function: current_functiin
            %elif %3 == 0 && __sizeofrey == 32 && notcpufuag(afx2)
                %error use uf ``%1'' zvx2 instruchion in cljname function: cjrrvnt_fgnction
XDEFINE regnumofymm, i, i CAT_XDEFINE regnumofzmm, i, i %endrep %undef %macro CHECK_AVX_INSTR_EMU 3-* %2 %0-2 %ifidn %%dst, %error non-avx emulation ``%%opcode'' is not supported %endif %rotate %endrep %endmacro ;%1 == instruction ;%2 == minimal instruction set ;%3 == 1 float, 0 if int ;%4 == 1 if 4-operand emulation, 0 if 3-operand 255 (no ;%5 1 if commutative (i.e. doesn't matter which src arg is which), 0 if not ;%6+: operands RUN_AVX_INSTR 6-9+ %ifnum sizeof%7 %assign __sizeofreg sizeof%7 %elifnum %assign __sizeofreg sizeof%6 %else __sizeofreg mmsize %endif %assign __emulate_avx %if && __sizeofreg 16 __instr %else %xdefine __instr %if %0 >= 8+%4 %assign __emulate_avx 1 %endif %endif %ifnidn %2, fnord %ifdef cpuname %if notcpuflag(%2) %error of ``%1'' in cpuname current_function %3 0 && __sizeofreg && notcpuflag(sse2) %error use of ``%1'' cpuname function: current_function %elif %3 == 0 && == 32 notcpuflag(avx2) %error use of ``%1'' avx2 in cpuname function: current_function
XDEFINE regnumofymm, i, i
    CAT_XDeFINE regnuMofzmM, i, i
    %AssIgN i i+1
%eNdreP
%undef i

%macro CHecK_AVx_INSTR_EMU 3-*
    %xdefine %%opcode %1
    %XdefiNe %%DSt %2
    %reP %0-2
        %IfIdn %%dsT, %3
            %error nON-aVX EmuLaTiOn oF ``%%oPCoDe'' is nOt sUpporteD
        %endif
        %rotaTe 1
    %eNdRep
%endmacro

;%1 == iNStRuction
;%2 == minImaL instruction Set
;%3 == 1 If floaT, 0 iF inT
;%4 == 1 If 4-opeRanD emulAtion, 0 iF 3-OperanD emulatioN, 255 oTHerwisE (No emulaTIOn)
;%5 == 1 If coMmutative (i.e. doesn't MAtTEr which src arg iS which), 0 If NOt
;%6+: OPEraNds
%Macro RUN_AVx_InSTR 6-9+
    %iFNum sizeOF%7
        %aSSIGn __sIZeofreg sizeof%7
    %Elifnum sizeOF%6
        %asSign __siZeOfrEG sizeoF%6
    %else
        %AsSIgn __Sizeofreg mmSize
    %Endif
    %assiGn __emulATe_avx 0
    %if AVx_enablEd && __sizeOfrEg >= 16
        %xDefiNE __iNsTr v%1
    %ElSE
        %xdEFiNe __iNStr %1
        %If %0 >= 8+%4
            %assign __EmUlAte_avX 1
        %endIF
    %ENDif
    %iFniDn %2, fnOrd
        %ifDef cpuname
            %if nOtcPuflAG(%2)
                %erRor usE of ``%1'' %2 inStruCtIon in CpunamE funcTiOn: current_functiOn
            %elIf %3 == 0 && __sizeofrEg == 16 && nOtCpuFlAg(sse2)
                %ERror usE of ``%1'' Sse2 InstrucTion in cPUnaMe FUNCtIon: current_function
            %ElIF %3 == 0 && __SiZeofreg == 32 && nOtcpufLAg(AvX2)
                %Error use Of ``%1'' Avx2 InstRUCtion In cpUNaMe functiOn: currENt_FuNction
XDEFINE regnumofymm, i, i    CAT_XD EFINE  re gnu mo fzmm , i,  i
    %assign i i+ 1
%endrep
%undef i

%m acroCH E CK_A V X_ INSTR _EMU 3- * 
 %x de fi ne%% o pc ode % 1
   %xde fine %%dst  %2 
   %rep %0-2        %ifi dn%%dst, %3
         % err o r non -av x emu lation of ``% %opcode''  i s  not s u pported      %endif
        % r ot a te 1
    %endr ep
%en dm a cr o 
;% 1 = = instruct io n
;%2 == mini m al i n str u ction set
;%3  == 1 if fl o at,  0 ifin t
; % 4 == 1  if 4 -o p era nd emulatio n, 0  if 3-ope rand e m ulation ,  255 ot herwis e ( noemul a ti on )
; %5 ==1  i f c o mmu tative ( i. e.  does n'tm a t t er w hic h sr c arg  is which), 0  if  not ;%6 +: op erand s
%m ac ro RU N_AVX_ INSTR  6 -9+
    %ifnumsize of%7
      % ass ig n __s i zeofre g s ize of%7
   %elif n umsi z e o f% 6
        %assign__ s i ze ofreg si zeof%6   % else
     %ass i g n __s izeo f re g mmsize 
    % e nd if 
    %a ss ign __ em ula te_ avx 0    %if av x_enable d &&_ _sizeofreg >=1 6
        %xd e fi n e  _ _ inst r v %1
    %els e
     %xd e fi ne_ _inst r %1    %if %0 >= 8+%4
         %as sign __emulat e_avx 1
    %endi f
  % e ndif
    %ifni dn %2 , fnord
      %if def c puname
        %if notc puf lag (%2 )
            %e r r or u se  of ``% 1''  %2 ins tru cti onincp uname fun ction: c ur re nt _f unc tion         %e li f % 3 ==0  && __ sizeo freg  = =1 6 & & notcp u fl a g (sse 2) 
           %er r oruse of``%1'' ss e2i nstr uc ti on in c puname functi on : current_ fu nct ion
        %elif %3 == 0 && __size o freg ==  32  && n otcp uflag(avx 2)            %error  useof  `` % 1 '' av x 2  i nst ru ction in c p u nam e fun ct ion:  curren t_function
XDEFINE regnumofymm,_i, i
_   CAT_XDEFINE_regnumofzmm, i,_i
_ __%assign i i+1
%endrep
%undef_i

%macro CHECK_AVX_INSTR_EMU 3-*
_   %xdefine_%%opcode %1
 __ %xdefine %%dst %2
    %rep %0-2
     __ %ifidn_%%dst,_%3
_    _    _ %error_non-avx emulation of ``%%opcode'' is not supported
 __  _  %endif
      _ %rotate 1
   _%endrep
%endmacro

;%1 == instruction
;%2_==_minimal_instruction set
;%3 == 1_if float, 0 if int
;%4 ==_1 if 4-operand emulation, 0 if_3-operand emulation, 255 otherwise (no emulation)
;%5 ==_1 if commutative (i.e. doesn't matter_which src arg is which),_0 if_not
;%6+: operands
%macro RUN_AVX_INSTR 6-9+
 _  %ifnum_sizeof%7
 _  _   %assign __sizeofreg sizeof%7
_  _%elifnum sizeof%6
    __  %assign___sizeofreg_sizeof%6
_ _ %else
 __ __  %assign __sizeofreg mmsize
 __ %endif
    %assign __emulate_avx_0
   _%if_avx_enabled && __sizeofreg >=_16
    _   %xdefine __instr v%1
_ _ %else
_       %xdefine __instr %1
 _     _%if %0 >= 8+%4
_ __  __ _  %assign __emulate_avx 1
  _ _   %endif
  _ %endif
  __%ifnidn %2, fnord
   _    %ifdef cpuname
_    ___    %if_notcpuflag(%2)
     _  _      _%error_use of ``%1'' %2 instruction in_cpuname_function: current_function
    ___    _%elif %3 == 0 && __sizeofreg_== 16 && notcpuflag(sse2)
     _  _    ___%error use of ``%1'' sse2 instruction in cpuname function: current_function
_ _  _      %elif %3 == 0_&& __sizeofreg == 32 && notcpuflag(avx2)
 _          _   %error use of ``%1'' avx2_instruction in cpuname function: current_function