Re: intel x86 floating point power funtion in assembly?

From: Terje Mathisen (spamtrap_at_crayne.org)
Date: 12/20/04


Date: Mon, 20 Dec 2004 21:09:31 +0000 (UTC)


Matt C. wrote:

> I've been trying to find a good power function (x^y) that is
> written in 100% intel x86 fpu assembly language. Does anybody
> have one, or do you know where I can find one?

The naive approach is to simply do exp(ln(x)*y), right?

This is relatively straightforward, except that we'd prefer to use
binary logs and exponentiation:

FYL2X calculates the product of a scale factor (i.e. Y) and the binary
logarithm of the input number (X).

F2XM1 returns the result of binary exponentiation minus 1.0, so the
following code should do it:

; Assume the caller has loaded first Y, then X onto the fp stack!
power proc
   fyl2x ; Binary log
   f2xm1 ; Result - 1
   fld1 ; Load 1.0
   faddp st(1),st(0) ; Add together and pop
   ret ; Return the result as ST(0)
power endp

Next is to detect some of the special cases:

Integer y?

Negative y?

Y close to zero?

X close to zero or one?

Terje

-- 
- <Terje.Mathisen@hda.hydro.com>
"almost all programming can be viewed as an exercise in caching"

***********************************************************************
NOTICE: This e-mail transmission, and any documents, files or previous
e-mail messages attached to it, may contain confidential or privileged
information. If you are not the intended recipient, or a person
responsible for delivering it to the intended recipient, you are
hereby notified that any disclosure, copying, distribution or use of
any of the information contained in or attached to this message is
STRICTLY PROHIBITED. If you have received this transmission in error,
please immediately notify the sender and delete the e-mail and attached
documents. Thank you.
***********************************************************************



Relevant Pages

  • Re: Trying to write strncpy() in ASM
    ... > possible to test all the bytes in a register for being zero at the same ... > into an integer register or the flags. ... > e-mail messages attached to it, ... If you are not the intended recipient, ...
    (comp.lang.asm.x86)
  • Re: Any problems with massive loop unrolling on 8088?
    ... I hadn't though at all of popping ... This e-mail transmission, and any documents, files or previous ... e-mail messages attached to it, ... If you are not the intended recipient, ...
    (comp.lang.asm.x86)
  • Re: Fastest Code for byte-substitutions in a string?
    ... Run through the string twice, the first time looking for matching bytes and the terminating zero, while storing the offset to any positions that needs to be updated. ... This e-mail transmission, and any documents, files or previous ... e-mail messages attached to it, ... If you are not the intended recipient, ...
    (comp.lang.asm.x86)
  • Re: Any problems with massive loop unrolling on 8088?
    ... I'm guessing you have a byte-wide encoding here, ... This e-mail transmission, and any documents, files or previous ... e-mail messages attached to it, ... If you are not the intended recipient, ...
    (comp.lang.asm.x86)
  • Re: SSE2-Sort within a register
    ... > some kind of bubble sort with eight ints inside one 128-bit ... This e-mail transmission, and any documents, files or previous ... e-mail messages attached to it, ... If you are not the intended recipient, ...
    (comp.lang.asm.x86)