flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > A simple way to optimise INC and DEC for the P4

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
Code:
macro inc v {add v,1}
macro dec v {sub v,1}
    


Of course, you need to make sure you do not need to preserve the carry flag!
Post 07 Nov 2004, 03:16
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
someone could create optimization macros for particular processors
Post 07 Nov 2004, 19:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
revolution wrote:
Code:
macro inc v {add v,1}
macro dec v {sub v,1}
    


Of course, you need to make sure you do not need to preserve the carry flag!


Smile

Code:
macro inc v 
{
pushf
add v,1
popf
}
macro dec v 
{
pushf
sub v,1
popf
}
    


is it a speed optimization? its bigger in size.
Post 07 Nov 2004, 19:42
View user's profile Send private message Visit poster's website Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
It's not optimization if it alter meaning of an instruction. In the first case(revolution), you need to preserve CF. In the second(Matrix), you need to not preserve any but CF. Also, touching the stack may slow down things and disrupt programmer intention.

I think if there's a better way to do in some circunstances, you do not do it by macros.
Post 07 Nov 2004, 23:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
Beppe85: Yeah, I already mentioned about the carry, but I find very rarely do I actually need to preserve the CF.

Matrix: using add and sub are faster on the P4 because it modifies all the flags, but inc/dec preserve CF. So in the P4 inc/dec stall until the flags are updated.
Post 08 Nov 2004, 01:51
View user's profile Send private message Visit poster's website 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-2019, Tomasz Grysztar.

Powered by rwasa.