On 03/09/11 14:18, Thomas Schatzl wrote:
> On Wed, 09 Mar 2011 13:23:55 -0500, Andrew Haines wrote:
>> On 03/09/11 12:26, Thomas Schatzl wrote:
>>>
>>> FYL2X calculates the log to the base 2 of tmp, not log to the base e of
>>> tmp? Just a guess.
>>>
>>
>> I originally used log2(Tmp) but switched to ln to check if it was
>> correct. Thanks for noticing that, I changed it back to log2.
>>
>
> 
> Suffixes for gas for floating point are (from
> http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax)
> 
> -s 32 bit/single
> -l 64 bit/double
> -t 80 bit/extended

Thank you this is useful!

> 
> I will write a bug report.


Thank you for writing that bug report.

I finally got the plain pascal version to work properly! My major
problem was I accidentally used the sqr function instead of sqrt. Here's
the final product:


  var
    LogBase  : Double;
    i: Integer;
    Tmp: Double;
  begin
    SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
exOverflow, exUnderflow, exPrecision]);

    LogBase:=1.0/(ln(10)/ln(2));

    for i := DataSize-1 downto 0 do
    begin
      Tmp := sqrt(sqr(InData[i].Im) + sqr(InData[i].Re));
      if Tmp > 0.0 then
        Tmp := (ln(Tmp)/ln(2))*LogBase+Shift
      else
        Tmp := 0.0;

      OutData[i] := Tmp;
    end;
  end;

In case anyone is interested, this generates 45 lines of assembly. The
handwritten asm code is 40 lines. (not including the procedure pre and
post asm for either method) I cheated a little and copied the log2 code
directly to avoid the function calls, this resulted in the compiler
doing the math ahead of time.

Regards,

Andrew Haines
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to