flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > TEST optimize

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 657
l4m2
usually we use a dword value to store some bits and get one by
Code:
ATTR equ 0x2000
;...
test dword [esi], dword ATTR    
but obviously it's a better choice if we use
Code:
test byte [esi+1], 0x20    
So I wrote this. Bugs can be reported here.
Code:
macro test op1, op2 {
    local tmp1, tmp2
    tmp1 equ *
    match w[x], :op1 \{
        tmp1 equ x
    \}
    tmp2 equ op2
    match w x, op2 \{
        if w eqtype word
            tmp2 equ x
        end if
    \}
    if ~(tmp1 eq *) & tmp2 eqtype 0
        if ~(tmp2 and not 0xff)
            test byte [tmp1], tmp2
        else if ~(tmp2 and not 0xff00)
            test byte [tmp1+1], tmp2 shr 8
        else if ~(tmp2 and not 0xff0000)
            test byte [tmp1+2], tmp2 shr 16
        else if ~(tmp2 and not 0xff000000)
            test byte [tmp1+3], tmp2 shr 24
        else
            test op1, op2
        end if
    else
        test op1, op2
    end if
}    
Post 06 Sep 2015, 02:44
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 713
Location: Adelaide
sinsi
Unaligned memory access makes it slower. Why not use BT?
Post 06 Sep 2015, 04:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17717
Location: In your JS exploiting you and your system
revolution
There are already some existing macros for this (and LEA) optimisations. They are from a few years ago but a bit of searching should be able to find them.
Post 06 Sep 2015, 04:14
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17717
Location: In your JS exploiting you and your system
revolution
For your viewing convenience I found the old thread:

http://board.flatassembler.net/topic.php?t=1238

Please read the whole thread, there is a lot of thoughts and information presented there.
Post 06 Sep 2015, 07:23
View user's profile Send private message Visit poster's website Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 657
l4m2
sinsi wrote:
Unaligned memory access makes it slower. Why not use BT?
Code:
bt dword [ebx], 1  ;4 bytes
test byte [ebx], 2 ;3 bytes    
Post 06 Sep 2015, 10:47
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 657
l4m2
It's not a good idea that fasm itself compile TEST [EBX], DWORD 0x20 into TEST [EBX], BYTE 0x20. In a segment 0-18, if EBX is 16, the first one rise a fault while the second one doesn't.
Post 11 Sep 2015, 15:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.