flat assembler
Message board for the users of flat assembler.

Index > Main > How "expensive" is the conditional operations

Author
Thread Post new topic Reply to topic
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
I was looking at the IF.INC file and was wondering how expensive in regard to CPU instructions these macros are compared to regular jumping
Anyone know?
Post 14 Nov 2010, 04:23
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
drobole,

Due to straightforward condition expression evaluator you can't expect optimized branching from those macros. For simple conditions they're as effective as hand-coded.
Post 14 Nov 2010, 09:23
View user's profile Send private message Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
If they don't produce redundant instructions in circumstances like this
Code:
stdcall strcompare, dbuf, cbuf, sizeof.dbuf
.if ecx = 0 
  ccall printf, w_equal, ecx      
.else 
  ccall printf, w_not_equal, ecx
.endif
    

Im happy. That makes them very useful indeed
Post 14 Nov 2010, 10:54
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
drobole,

That will be equivalent to
Code:
stdcall strcompare, dbuf, cbuf, sizeof.dbuf
;.if ecx = 0
        cmp   ecx, 0
        jne   ..else?0; generated unique symbol
        ccall printf, w_equal, ecx
;.else
        jmp   ..endif?1; another generated unique symbol
..else?0:
        ccall printf, w_not_equal, ecx
;.endif
..endif?1:    
What do you mean, redundant? While generated instructions are sub-optimal for this case (~ecx as the condition will generate shorter test ecx, ecx instead of cmp ecx, 0; entire conditional block can be rewritten using something like ?: C conditional operator, merging calls and stack adjustment), it's almost exactly what you've written.
Post 15 Nov 2010, 17:53
View user's profile Send private message Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
Quote:

What do you mean, redundant?

I was thinking about how higher level language compilers tend to generate redundant assembly instructions. At least on the first pass. After all, optimizing a compiler is much about reducing, factoring and simplifying the assembly instructions generated.
I wasn't sure how assemblers and their macros go about stuff like that, but since assembly instructions for the most part correspond to a single machine instruction I guess there is not much room for redundant code being generated anyway.

Also, I'm not all that used to assembly at this point. I just dislike all the labels/jumps you need in order to facilitate a if,else if, else if etc. Especially when you get loops and stuff inside those.
Coming from C, this is kinda hard to swallow. But maybe I'll get used to it Shocked
Post 16 Nov 2010, 22:29
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
drooble: Outside the extremely time critical pieces of code (eg. crypto algorithms, distributed computations, etc.) you can freely use them, difference would be hardly measurable .

But if you want to learn assembly, I'd suggest you to first learn how to go on without these macros (get accustomed to "linear" source code layout), and only start using macros after you understand well what they do.
Post 16 Nov 2010, 23:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
Sounds like a good idea. Thanks guys
Post 17 Nov 2010, 09:12
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 YouTube, Twitter.

Website powered by rwasa.