Author Topic: Sharing of macro (x64)  (Read 10929 times)

Offline shaynox

  • Full Member
  • **
  • Posts: 118
  • Country: gr
Sharing of macro (x64)
« on: March 13, 2015, 06:49:46 PM »
Hello, today i decide to make this topic for sharing macro (HLA macro, ...)

This file contains a lot of type of macro:

I/ Factorization CPU instructions (easy to upgrade)

   This kind of macro give the possibility to factorize instructions's block.
   
Algo:
Code: [Select]
     
        call    func_1 ..
        call    func_2 ....
        call    func_3 ...... --> call  func_1, func_2, func_3, func_4, func_5
        call    func_4 ....
        call    func_5 ..

Exemple:
Code: [Select]
call_ display_screen, display_fps , clear_screen, windows_event

vbroadcastss_ {ymm0, [fsincosps_cos + _1x]}, {ymm1, [fsincosps_cos + _1y]}, {ymm2, [fsincosps_cos + _1z]}
vbroadcastss_ {ymm3, [fsincosps_sin + _1x]}, {ymm4, [fsincosps_sin + _1y]}, {ymm5, [fsincosps_sin + _1z]}
vbroadcastf128_ {ymm6, [r8 + OBJ3D_POSITION]}, {ymm7, [r8 + OBJ3D_REPERE  ]}

vbroadcastss_ {ymm0, [temp2 + _1x        ]}, {ymm1, [temp2 + _1y        ]}, {ymm2, [temp2 + _1z        ]}
vbroadcastss_ {ymm3, [temp2 + _1x + _1xmm]}, {ymm4, [temp2 + _1y + _1xmm]}, {ymm5, [temp2 + _1z + _1xmm]}

   
II/ if elseif else endif | while endwhile (very long macro, cause it doesn't exist concatenation of comparaison (|| && OR AND)
   
   It's just C-like, except of give the possibility to decide or not where branch if the condition is met (label) and the trivial one, write after endwhile, the
        modification of operand's value.
       
   Unfortunally, this macro can't get more one elseif.

Exemple:
Code: [Select]
            while   rsi ,<, tmp_end_scene_3D
           ;{
                %include "1.ASM\HackEngine\Source\show_world\show_pixel.asm"
           ;}
            endwhile    {add  rsi, voxel(2)}

        ;==========================================================================
        ; void  manage_keyboard(UINT message, WPARAM state)
        ; Purpose : Manage keyboard
        ; Input   : NONE
        ; Output  : NONE
        ;==========================================================================
        manage_keyboard:
       ;{
            if [message] is i32(WM_KEYDOWN)
            endif

            ; ALT + ²
                if [message] is i32(260)
               ;{
                    if i64 [word_param_msg] is 222, quit_program
                    endif
               ;}
                endif

            if     [message] is i32(WM_CLOSE)  , quit_program
            elseif [message] is i32(WM_DESTROY), quit_program
            endif
       ;}
        end_manage_keyboard:
        ;==========================================================================
        ; / manage_keyboard
        ;==========================================================================



quit_program:

 

; 1x
if  xmm0 ,>=, [plimit_x], .end_putpixel
endif
if  xmm0 ,<=, [mlimit_x], .end_putpixel
endif

vmovss xmm0, [showpixel_xy + 4]
; 1y
if  xmm0 ,>=, [plimit_y], .end_putpixel
endif
if  xmm0 ,<=, [mlimit_y], .end_putpixel
endif

vmovss xmm0, [rsi + _1z]
; 1z
if  xmm0 ,<=, [_0], .end_putpixel
endif

               ; ...

    .end_putpixel:

   
III/ Some defines (beta)

Exemple:
Code: [Select]
    while [quit] is false
   ;{
    ; ...
   ;}
    endwhile
ret

   
IV/ Write in single line, multiple instructions

Exemple:
Code: [Select]
_{vsubps  xmm1, xmm0, [prev_coord_mouse]}, {vaddps xmm1, [cam_angle]}
   
V/ ... (lazy to put a title)

Example:
Code: [Select]
m2m [rdx + _1color], [rsi + _1color], eax
m2m [rdx + _2color], [rsi + _2color], eax
m2m [rdx + _3color], [rsi + _3color], eax
m2m [rdx + _4color], [rsi + _4color], eax


VI/ ...

Example:
Code: [Select]
. [instance]          is rcx
. [previous_instance] is rdx
. [cmd_line]          is r8
. [cmd_show]          is r9d

VII/ WinAPI macro


Example:
Code: [Select]
                printf_ "FPS = %d", [fps_data]
LoadImageA_ 0, "data\Hackengine_logo.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE


VIII/ ASM data types

Example:
Code: [Select]
        int32       nbr1
        int64       nbr2
        float32     nbr3
        float64     nbr4
        vector2D    point2D
        vector3D    point3D

        _int32      nbr1, 32
        _int64      nbr2, 64
        _float32    nbr3, 32.0
        _float64    nbr4, 64.0
        _vector2D   point2D, 10, 20
        _vector3D   point3D, 10, 20, 30, 0
        char        str0 is "Hello"

        ; tab_f32/i32 for create 16 * 32 bit variables
            ftab     pi_180      is 0.01745329
            ftab     pi          is 3.14159265

            ftab     ps_inv_sign is -1.0         ; MUL
            ftab     ps_pos_sign is 0x7FFFFFFF   ; AND
            ftab     ps_neg_sign is 0x80000000   ; OR

            ftab     _100.0      is 100.0
            ftab     _32.0       is 32.0
            ftab     _20.0       is 20.0
            ftab     _8.0        is 8.0
            ftab     _5.0        is 5.0
            ftab     _2.0        is 2.0
            ftab     _1.0        is 1.0
            ftab     _0.01       is 0.01

            itab     _0          is 0
            itab     _32         is 32

Enjoy
« Last Edit: May 03, 2015, 08:56:44 PM by shaynox »

Offline shaynox

  • Full Member
  • **
  • Posts: 118
  • Country: gr
Re: Sharing of macro (x64)
« Reply #1 on: June 14, 2015, 03:41:24 PM »
And of course, I forget to put macro single line (define) and some update of multi line macro x)

IX/ Redefinition and fusion of if/while into jif macro

do while like:
Code: [Select]
            .l1:
           ;{
                call_   windows_event, show_fps
           ;}
            jif     [quit] ,=, false, .l1


If like:
Code: [Select]
                jif  eax ,<, 1_000, .no_show_fps
               ;{
                    printf_     "FPS = %d", [.fps_data]
                    mov         [.fps_data], i32(0)
                    clock_      [.fps_data + 4]
               ;}
               .no_show_fps:

X/ Some definition of constants

List:
       - Some redefinition of NASM's keyword
       - Some meaning of word in programming
       - Index for array (x86 x64 avx padding)
« Last Edit: June 20, 2015, 02:49:55 PM by shaynox »