flat assembler
Message board for the users of flat assembler.

Index > Main > inc vs add

Author
Thread Post new topic Reply to topic
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
what is better? what should i use?

inc can be used with lock
add set more flags



is there a way to make fasm generate inc/dec using modrm version (in 32bit mode)?
Post 09 Jul 2010, 13:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
b1528932 wrote:
what is better?
There is no such thing as "better". It is just different. But anyhow, what is your metric for determining "better"?
b1528932 wrote:
what should i use?
Probably doesn't matter at all. And there is no "should" either. Up to you what you want to use.
b1528932 wrote:
inc can be used with lock
add set more flags
Yes. inc is also less bytes.
b1528932 wrote:
is there a way to make fasm generate inc/dec using modrm version (in 32bit mode)?
Use db 0x??,0x?? if you want a particular encoding.
Post 09 Jul 2010, 13:22
View user's profile Send private message Visit poster's website Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
"add" can prevent partial flags stall and enhancing reordering
Post 09 Jul 2010, 13:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
asmfan wrote:
"add" can prevent partial flags stall and enhancing reordering
... in some older variants of one company's CPUs.
Post 09 Jul 2010, 14:25
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
With a lot of P4's inc or dec reg is slower then add or sub reg,1.
The difference between loop, dec and sub was interesting for code like
Code:
  loop label ;slowest on all intel cpu's

  dec ecx
  jnz label  ;dec is slow on most P4's

  sub ecx,1
  jnz label  ;this was the fastest on P4's
    

Fastest here means clocks, not time, but the differences were all over the place because of the different CPU's used - everything from a P3 to an i7.
Sometimes the P3 was faster, go figure.
Post 09 Jul 2010, 14:39
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
revolution wrote:
b1528932 wrote:
inc can be used with lock
add set more flags
Yes. inc is also less bytes.
And actually ADD can also be used with LOCK.
Post 09 Jul 2010, 16:00
View user's profile Send private message Reply with quote
roboman



Joined: 03 Dec 2006
Posts: 122
Location: USA
roboman
The general rule I try to follow is is when ever the reg inc or dec is getting used in the next command I'll use add because on some cpu's it has to wait for the inc/dec to clear through and you loose some of the optimization built into some of the cpu's. If it's not getting used right away the add/sub are bigger, so I tend to use inc/dec. But what the heck it's all faster then java, c and basic Smile
Post 09 Jul 2010, 16:26
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-2020, Tomasz Grysztar.

Powered by rwasa.