* 64 bit integer support as native type @ 1994-09-22 17:29 Brent Slone 1994-09-23 11:55 ` Robert I. Eachus ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Brent Slone @ 1994-09-22 17:29 UTC (permalink / raw) Does the Ada LRM define a 64 bit integer? If not, what is the most straightforward method for implementing 64 bit ints? Thanks, Brent Slone ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: 64 bit integer support as native type 1994-09-22 17:29 64 bit integer support as native type Brent Slone @ 1994-09-23 11:55 ` Robert I. Eachus 1994-09-23 15:34 ` Robert Dewar 1994-09-23 16:09 ` Norman H. Cohen 2 siblings, 0 replies; 5+ messages in thread From: Robert I. Eachus @ 1994-09-23 11:55 UTC (permalink / raw) In article <35setv$7nq@walters.East.Sun.COM> brent@paisley.East.Sun.COM (Brent Slone) writes: > Does the Ada LRM define a 64 bit integer? Neither the Ada 83 standard or the Ada 9X standard defines the size of Integer, Long_Integer, Short_Integer, etc. However the 9X standard does provide guidance on the size and naming of various integer types, as do the UI's for Ada 83. > If not, what is the most straightforward method for implementing 64 > bit ints? If the compiler supports 64-bit integer types, and several do, try: type Integer_64 is range -2**63..2**63-1; (You might want to read Robert Dewar's recent post on how to reflect the range you actually need, but you told ME you needed 64-bits. ;-) If that doesn't work, and the compiler supports 32-bit integers, there is a package in the new ADAR components which provides 64-bit and 128-bit integer types. This package is intended to be highly portable. Replacing a few low-level operations with machine code, assembler, or calls to some other language can be used to speed things up. However, this package is pretty efficient right now. If you want to act as a beta tester, let me know. If you have a machine with quad-precision floating point or IEEE Extended Precison, the Generic_Decimal package in the current ADAR works fine. However, it provides the equivalent of fixed-point, not integer. (This solution also works if you need, say, 15-digits of precision on IEEE machines without Extended precision.) -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is... ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: 64 bit integer support as native type 1994-09-22 17:29 64 bit integer support as native type Brent Slone 1994-09-23 11:55 ` Robert I. Eachus @ 1994-09-23 15:34 ` Robert Dewar 1994-09-23 16:09 ` Norman H. Cohen 2 siblings, 0 replies; 5+ messages in thread From: Robert Dewar @ 1994-09-23 15:34 UTC (permalink / raw) The 83 RM is not even slightly in the business of defining what integer types are available. The 9X RM has some very minimal, pretty much meaningless requirements, about integer sizes. The one notable exception is that decimal types must support decent precision, equivalent to 64 binary bits, if the IS annex is supported, so that is one possible totally portable route in Ada 9X. For integer types, the idea is that your implementor provides the appropriate set of integer types. You have two choices. Either use a compiler that supports 64-bit integer types. FOr example, all versions of GNAT support at least 64-bit integer types. OR, put your own multiple preicision routines to gether (I think that Bob Eachus has some portable routines for high precision integer arithmetic!) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: 64 bit integer support as native type 1994-09-22 17:29 64 bit integer support as native type Brent Slone 1994-09-23 11:55 ` Robert I. Eachus 1994-09-23 15:34 ` Robert Dewar @ 1994-09-23 16:09 ` Norman H. Cohen 2 siblings, 0 replies; 5+ messages in thread From: Norman H. Cohen @ 1994-09-23 16:09 UTC (permalink / raw) In article <35setv$7nq@walters.East.Sun.COM>, brent@paisley.East.Sun.COM (Brent Slone) writes: |> Does the Ada LRM define a 64 bit integer? No, but then again, it wouldn't. Implementations, not the LRM, define the ranges of integer types they support. |> If not, what is the most |> straightforward method for implementing 64 bit ints? A programmer can declare an integer type with the range of conventional 64-bit twos complement as follows: type Integer_64 is range -2**63 .. 2**63-1; One of three things may happen as a result of this declaration: o You may get object code that efficiently exploits the 64-bit registers of your target machine. o You may get code that performs 64-bit arithmetic in software, for example storing an Integer_64 value in a pair of registers and turning an addition into an add-setting-carry-bit instruction for the low-order registers in each pair, followed by an add-two-registers-plus-carry-bit instruction for the high-order registers in each pair. o You may get an error message stating that your compiler does not support integer types with so large a range. In any event, you are guaranteed that if the compiler accepts the declaration, the type will support the semantics of 64-bit 2's-complement integers. (I can already hear Robert Dewar saying, "There you go again, Norman!" His displeasure with defining types in terms of presumed hardware constraints rather than the ranges of values needed to solve the problem at hand is certainly valid, but you posed a requirement for 64-bit integers, so I'm assuming that that is your application's requirement. Since just about all machines not manufactured in Minnesota have word sizes of 16, 32, or 64 bytes, and since some programs have a need to deal with hardware, hardware-inspired file formats, or interfaces to other software, it is not all that unreasonable for "64-bit integer" to arise as an abstract software requirement.) -- Norman H. Cohen ncohen@watson.ibm.com ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <35setv$7nq@walters.east.sun.com>]
* Re: 64 bit integer support as native type [not found] <35setv$7nq@walters.east.sun.com> @ 1994-09-23 17:41 ` Tucker Taft 0 siblings, 0 replies; 5+ messages in thread From: Tucker Taft @ 1994-09-23 17:41 UTC (permalink / raw) In article <35setv$7nq@walters.east.sun.com>, Brent Slone <brent@paisley.East.Sun.COM> wrote: >Does the Ada LRM define a 64 bit integer? Unlike C/C++, the language does not define any specific sizes, though it does establish some minimums for Integer (and Long_Integer if defined). Users who want an integer of a specific size should declare it themselves, such as: type Int_64 is range -2**63 .. +2**63-1; Alternatively, they can rely on package Interfaces, which has predeclared various useful sizes, such as Interfaces.Integer_64. However, using Interfaces is less portable. Note that if you want to be portable to one's complement machines, or implementations that use the most negative value to represent uninitialized (some versions of Rational), then the above should be: type Int_64 is range -(2**63-1) .. +2**63-1; To minimize the likelihood of software-imposed range checks. type Int_64_Constrained is range -(2**63-1) .. +2**63-1; subtype Int_64 is Int_64_Constrained'Base; This will give you an unconstrained subtype which has at least 64 bits, but may have more. Only overflow checks will be imposed on such a subtype, never range checks. > ... If not, what is the most >straightforward method for implementing 64 bit ints? There are many approaches to implementing 64 bit integers, given implementations of 32 bits. With the new "modular" integer types, it is even easier: type Int_64 is private; function "+"(Left, Right: Int_64) return Int_64; function "-"(Left, Right: Int_64) return Int_64; ... private type Int_64 is record Low : Interfaces.Unsigned_32; High : Interfaces.Integer_32; end record; To do a 64-bit add, you add the low parts, and check for overflow (with unsigned numbers, overflow corresponds to the case where the result is less than one of the operands), and then add the high parts, plus one more if the low parts overflowed. Similar algorithms apply to the other operations. As usual, Knuth has all of these algorithms spelled out if you need them. >Thanks, > > >Brent Slone S. Tucker Taft stt@inmet.com Intermetrics, Inc. Cambridge, MA 02138 > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1994-09-23 17:41 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1994-09-22 17:29 64 bit integer support as native type Brent Slone 1994-09-23 11:55 ` Robert I. Eachus 1994-09-23 15:34 ` Robert Dewar 1994-09-23 16:09 ` Norman H. Cohen [not found] <35setv$7nq@walters.east.sun.com> 1994-09-23 17:41 ` Tucker Taft
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox