From: Jerry van Dijk <jvandyk@attglobal.net>
Subject: Re: Compute a Sin(X) and Cos(X) pair, FSINCOS, inlining
Date: 14 Jul 2003 01:32:02 +0200
Date: 2003-07-14T01:32:02+02:00 [thread overview]
Message-ID: <m2he5qype5.fsf@attglobal.net> (raw)
In-Reply-To: 3F0FAA0E.7BCA9AA7@somewhere.nil
Gautier Write-only <gautier@somewhere.nil> writes:
> # Sorry, the original article already scrolled off my system.
>
> Nice... (what system! even with on a VT220 I could scroll up news ;-)
Nah. I just hooked my VT220 clone to the serial port of my laptop, but
it didn't help... :-)
BTW, I always preferred the TeleVideo 970.
> BTW, what is the variant for Long_Float ?
Here is a full example of both:
------------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics; use Ada.Numerics;
with System.Machine_Code; use System.Machine_Code;
with Ada.Numerics.Generic_Elementary_Functions;
procedure Check is
package Float_Funcs is new
Ada.Numerics.Generic_Elementary_Functions (Float);
use Float_Funcs;
package Long_Float_Funcs is new
Ada.Numerics.Generic_Elementary_Functions (Long_Float);
use Long_Float_Funcs;
procedure Sin_Cos (Angle : Float; Sin : out Float; Cos : out Float);
procedure Sin_Cos
(Angle : Long_Float; Sin : out Long_Float; Cos : out Long_Float);
pragma Inline (Sin_Cos);
procedure Sin_Cos (Angle : Float; Sin : out Float; Cos : out Float) is
use ASCII;
begin
Asm (("fsincos" & LF & HT &
"fstp %0" & LF & HT &
"fst %1"),
Outputs => (Float'Asm_Output ("=m", Cos),
(Float'Asm_Output ("=m", Sin))),
Inputs => (Float'Asm_Input ("t", Angle)));
end Sin_Cos;
procedure Sin_Cos
(Angle : Long_Float; Sin : out Long_Float; Cos : out Long_Float) is
use ASCII;
begin
Asm (("fsincos" & LF & HT &
"fstpl %0" & LF & HT &
"fstl %1"),
Outputs => (Long_Float'Asm_Output ("=m", Cos),
(Long_Float'Asm_Output ("=m", Sin))),
Inputs => (Long_Float'Asm_Input ("t", Angle)));
end Sin_Cos;
package IO_Concats is
function "&" (S : String; F : Float) return String;
function "&" (S : String; F : Long_Float) return String;
end IO_Concats;
package body IO_Concats is
function "&" (S : String; F : Float) return String is
begin
return S & Float'Image (F);
end "&";
function "&" (S : String; F : Long_Float) return String is
begin
return S & Long_Float'Image (F);
end "&";
end IO_Concats;
use IO_Concats;
Sin_Float, Cos_Float : Float;
Float_Value : constant Float := 0.25 * Pi;
Sin_Long_Float, Cos_Long_Float : Long_Float;
Long_Float_Value : constant Long_Float := 0.25 * Pi;
begin
Sin_Float := Sin (Float_Value);
Cos_Float := Cos (Float_Value);
Put_Line ("Sin_Float:" & Sin_Float & ", Cos_Float:" & Cos_Float);
Sin_Cos (Float_Value, Sin_Float, Cos_Float);
Put_Line ("Sin_Float:" & Sin_Float & ", Cos_Float:" & Cos_Float);
Sin_Long_Float := Sin (Long_Float_Value);
Cos_Long_Float := Cos (Long_Float_Value);
Put_Line
("Sin_LFloat:" & Sin_Long_Float & ", Cos_LFloat:" & Cos_Long_Float);
Sin_Cos (Long_Float_Value, Sin_Long_Float, Cos_Long_Float);
Put_Line
("Sin_LFloat:" & Sin_Long_Float & ", Cos_LFloat:" & Cos_Long_Float);
end Check;
-------------------------------------------------------------------------------
> In any case, it would be nice to have a compiler producing FSINCOS - e.g.
> for those users not familiar with machine code.
Yes. Have you checked gcc 3.3 ? Probably the Fortran folks would like this
too.
--
-- Jerry van Dijk | email: jvandyk@attglobal.net
-- Leiden, Holland | web: users.ncrvnet.nl/gmvdijk
prev parent reply other threads:[~2003-07-13 23:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-09 20:30 Compute a Sin(X) and Cos(X) pair, FSINCOS, inlining Gautier Write-only
2003-07-09 20:40 ` Florian Weimer
2003-07-10 1:51 ` Jeffrey Carter
2003-07-12 6:26 ` Gautier Write-only
2003-07-13 23:32 ` Jerry van Dijk [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox