comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Simple Real_Time.Time_Span question
Date: 1998/10/16
Date: 1998-10-16T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.98Oct16162633@spectre.mitre.org> (raw)
In-Reply-To: 705g81$g9s$1@nnrp1.dejanews.com

In article <705g81$g9s$1@nnrp1.dejanews.com> dennison@telepath.com writes:

  > Hmmm. I guess there's a bit of a hole in my education where
  > multiprecision integer arithmetic is concerned. I assume an
  > add-with-carry instruction has some way of handling when *two*
  > bits need to be carried (eg: the msbit of both previous operands
  > was a 1, and there was a carry-in to that bit-position). Or
  > perhaps you have to add one to the second word of the result if
  > there was a carry and the msbit of the first word of the result is
  > 0?

  You are losing me a bit here, but I think I can answer your
question.  Let's assume a 32-bit machine (with 32-bit registers) where
we want to add two 64-bit numbers.  Let's be specific and use the
680x0 family.  Assume that the quantity in the register pair D0,D1 is
to be added to the quantity in the register pair D2,D3:

   ADD.L D1,D3
   ADDX  D0,D2

   The ADDX instruction adds the carry bit to the source and
destination, and puts the result in the destination register.  For the
case of a double length add, that is all there is to it.  After the
ADDX, all the condition code values are what you would want.  The Z
bit is only set if the entire result is zero, the N bit is set if the
quantity as a whole is negative, etc.  If you want to do a series of
such adds, then you do something like:

   ADD.L D2,D5
   ADDX  D1,D4
   ADDX  D0,D3

   And so on.  In any case, there is only one possible carry bit, just
as you can only carry a value between 0 and 9 when adding decimal
numbers by hand.

 > Either way it sounds like simple arithmetic will be significantly
 > slower for a Duration implemented in this way than one would
 > typically expect of a predefined type. I can certianly see where
 > compiler vendors for some real-time platforms might decide *not* to
 > do that. So I don't think I can safely assume that a Time_Span of a
 > few microseconds will translate well into Duration on any platform
 > that this code may end up on (or even its platform, 'till I find
 > out for sure).

   You are confused. I left out register loading code above, any
required overflow checking, etc.  From experience, adding or
subtracting 64-bit integer quantities on a 32-bit register machine is
less than 20 percent slower at most than the same algorithm using
32-bit quantities.  Multiplication by small factors, expecially if
constant, doesn't affect these results, but any use of division can
and will have a large impact.

   Since arithmetic as a part of time-keeping is almost all addition
and subtraction, this means that a 64-bit Duration type will have an
almost negligible impact on code speed.  (Remember, in recent hardware
on-chip processing times are dominated by memory access bandwidth.
And of course one of the ways that chip-manufacturers speed things up
is by reading an entire cache line in one buss operation, which may
take dozens of CPU cycles.)
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  reply	other threads:[~1998-10-16  0:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-13  0:00 Simple Real_Time.Time_Span question dennison
1998-10-13  0:00 ` David C. Hoos, Sr.
1998-10-13  0:00   ` dennison
1998-10-14  0:00     ` Robert I. Eachus
1998-10-14  0:00       ` Keith Thompson
1998-10-14  0:00       ` Jonathan Guthrie
1998-10-15  0:00         ` dennison
1998-10-16  0:00           ` Tucker Taft
1998-10-16  0:00             ` dennison
1998-10-16  0:00               ` dewar
1998-10-17  0:00           ` Niklas Holsti
1998-10-14  0:00     ` Niklas Holsti
1998-10-14  0:00       ` Niklas Holsti
1998-10-13  0:00 ` dennison
1998-10-13  0:00 ` Tucker Taft
1998-10-14  0:00 ` dewar
1998-10-14  0:00   ` dennison
1998-10-14  0:00     ` Robert I. Eachus
1998-10-15  0:00       ` dennison
1998-10-16  0:00         ` Robert I. Eachus [this message]
1998-10-14  0:00     ` Matthew Heaney
replies disabled

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