comp.lang.ada
 help / color / mirror / Atom feed
* very fast procedure call
@ 2013-07-23  8:49 wrostek
  2013-08-01 12:14 ` Jacob Sparre Andersen
  0 siblings, 1 reply; 2+ messages in thread
From: wrostek @ 2013-07-23  8:49 UTC (permalink / raw)


Hi all,

this question is related to my tracing work started here last week.
https://groups.google.com/forum/#!topic/comp.lang.ada/vSNunYeX6GY

For injecting a bunch of trace I'll need an ultimate fast store call.

Here my approach.

The trace call will only provide storing 4 and 8 byte values. Each
call should generate a pair of id/value. There is no tasking/threading
involved.

First looking at the package body behaviour I'll come to the interface
later.

The body will use an array storage area which will be copied to disk
at the end of each 20msec cycle. (this may even be done via shared
memory by a different process)

Filling the array should be really fast.

The interface should be somehow this kind (sorry using C style)

procedure put32u(id: in uint32; val: in uint32);
procedure put32s(id: in uint32; val: in sint32);
procedure put32f(id: in uint32; val: in float32);
procedure put64d(id: in uint32; val: in double64);

This should be sufficient for the caller (e.g. an emum must be converted
to use the first call).

I would like to make all inline, no range checking, no C-usage, etc.

Can you give me some ideas or a similar example?

thanks in advance
Wolfgang R.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: very fast procedure call
  2013-07-23  8:49 very fast procedure call wrostek
@ 2013-08-01 12:14 ` Jacob Sparre Andersen
  0 siblings, 0 replies; 2+ messages in thread
From: Jacob Sparre Andersen @ 2013-08-01 12:14 UTC (permalink / raw)


Wolfgan Rostek <wolfgang.rostek@gmx.de> wrote:

> For injecting a bunch of trace I'll need an ultimate fast store call.

> The trace call will only provide storing 4 and 8 byte values. Each
> call should generate a pair of id/value. There is no tasking/threading
> involved.

> The body will use an array storage area which will be copied to disk
> at the end of each 20msec cycle.

What about writing this out explicitly:

package Trace is
   type IDs is mod 2 ** 32;

   procedure Put (ID : in     IDs; Value : in     ...) with Inline => (True);
   procedure Put (ID : in     IDs; Value : in     ...) with Inline => (True);
   procedure Put (ID : in     IDs; Value : in     ...) with Inline => (True);
   procedure Put (ID : in     IDs; Value : in     ...) with Inline => (True);
end Trace;

package body Trace is
   type Kinds is (...);
   type Data (Kind : Kinds := ...) is
      record
         ID : IDs;
         case Kind is
            when ... =>
               ...
         end case;
      end record;

   type Indices is mod 2 ** ...;
   type Circular_Buffer is array (Index) of Data;

   Storage : Circular_Buffer;
   Next    : Indices := 0;

   procedure Put (ID : in     IDs; Value : in     ...) is
   begin
      Storage (Next) := (Kind => ...,
                         ID   => ID,
                         ...  => Value);
      Next := Next + 1;
   end Put;

   ...
end Trace;

If you build your application with optimisation enabled, I would expect
the compiler to inline all calls to Trace.Put.

As the type of Next matches Storage'Range perfectly, there is no need
for range checks on the array indexing.

As Next is a modular number with a power of two modulus, the wrap-around
arithmetic is easy to implement as a constant-time operation.
   
> This should be sufficient for the caller (e.g. an emum must be
> converted to use the first call).

Why do it that way?  You could just as will expand the Trace to include
support for the enumeration types you are interested in storing.  Also,
remember that most well-written Ada applications and libraries don't use
numerical types declared in terms of how many bits/bytes they require.

> I would like to make all inline, no range checking, no C-usage, etc.

The above is probably the nicest way to do it.

Greetings,

Jacob
-- 
"Don't get me wrong, perl is an OK operating system, but it
 lacks a lightweight scripting language."


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-01 12:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-23  8:49 very fast procedure call wrostek
2013-08-01 12:14 ` Jacob Sparre Andersen

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