Re: pushf v rcl, save, restore carry flag
- From: "robertwessel2@xxxxxxxxx" <robertwessel2@xxxxxxxxx>
- Date: Mon, 25 Feb 2008 14:48:02 -0800 (PST)
On Feb 24, 2:25 pm, stork <Todd.Bandrow...@xxxxxxxxx> wrote:
I'm writing my own large integer library in x86-64 assembly, and, to
start with, I'm working on addition. My basic approach is to loop
through each pair of 64 bit longs and adc them. The one thing I've
noticed is that for this to work I need to save and restore the carry
flag, as, my loop counter sets it too. What's the fastest way to do
that these days? I'm looking at pushf, popf, but, some sites that
I've looked at claims rcr/rcl ought to be faster as of 486 and
pentium. Is this still true?
You should review your loop implementation, since you can usually
implement that sort of loop without stomping on the carry flag. For
example, inc/dec and lea can be used to adjust counters and pointers
without altering the carry flag. You'll almost certainly want to
unroll the loop some too (which will almost certainly be a bigger win
than anything else).
Anyway, assuming you have to do a single iteration loop, and you can't
avoid trashing the carry flag, your best bet is probably to avoid
trying to actually save and restore the carry, just save the carry for
input to the next cycle in a register. Let's say you use rdx, so
before the loop you'd load rdx with zero, and in the loop you'd do
something like:
mov rax,0
add rdx,num1[rsi] ;prior carry
adc rax,0
add num2[rdi],rdx
adc rax,0
mov rdx,rax ;new carry for next round
That can be optimized a bit too, of course.
OTOH, this sort of optimization always needs to be tested, it's far to
easy to get it wrong given how complex the execution of instructions
is in modern CPUs.
.
- References:
- pushf v rcl, save, restore carry flag
- From: stork
- pushf v rcl, save, restore carry flag
- Prev by Date: Re: [OT] could it to be a good idea?
- Next by Date: Re: [OT] could it to be a good idea?
- Previous by thread: Re: pushf v rcl, save, restore carry flag
- Next by thread: [OT] could it to be a good idea?
- Index(es):
Relevant Pages
|