comp.lang.ada
 help / color / mirror / Atom feed
From: Aurele Vitali <aurele.vitali@gmail.com>
Subject: Re: GNAT for AVR - Mathematical Functions
Date: Mon, 17 Sep 2018 15:35:55 -0700 (PDT)
Date: 2018-09-17T15:35:55-07:00	[thread overview]
Message-ID: <2532e136-865d-4e81-8f55-471bb3a9e1ea@googlegroups.com> (raw)
In-Reply-To: <ed6bc2e2-a2e1-4a0b-b253-8142d47518c9@googlegroups.com>

I don't know anything about the ATmega328P, but if it uses a builtin floating point processor, you can use Ada inline floating point assembler.  Its not hard to do. Here is a simple example of the square root function:

  with System.Machine_Code; use System.Machine_Code;

  function Sqrt( x : in Long_Float ) return Long_Float is
    Result : Long_Float := 0.0;
  begin
    Asm( ( "fldl  %1" & EOL &                 -- Load x in St(0)
           "fsqrt   " & EOL &                 -- Take the Sqrt of St(0)
           "fstpl %0" ),                      -- Store result and pop St(0)
         Outputs => ( Long_Float'Asm_Output("=m", Result ) ),
         Inputs  => ( Long_Float'Asm_Input ( "m",      x ) ) );
    return Result;
  end Sqrt;

You can do the same thing for trig functions...  Just cut and past and see if this example works. 

Cheers

  parent reply	other threads:[~2018-09-17 22:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-17  2:22 GNAT for AVR - Mathematical Functions ada.newcomer
2018-09-17  7:18 ` Dmitry A. Kazakov
2018-09-17 22:41   ` Aurele Vitali
2018-09-17 12:22 ` Simon Wright
2018-09-17 17:28 ` Bill Findlay
2018-09-17 22:35 ` Aurele Vitali [this message]
2018-09-18  1:16 ` rakusu_klein
2018-09-25  7:14 ` R R
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox