1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- S Y S T E M . S H A R E D _ B I G N U M S -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 2012-2020, Free Software Foundation, Inc. -- 10-- -- 11-- GNAT is free software; you can redistribute it and/or modify it under -- 12-- terms of the GNU General Public License as published by the Free Soft- -- 13-- ware Foundation; either version 3, or (at your option) any later ver- -- 14-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16-- or FITNESS FOR A PARTICULAR PURPOSE. -- 17-- -- 18-- As a special exception under Section 7 of GPL version 3, you are granted -- 19-- additional permissions described in the GCC Runtime Library Exception, -- 20-- version 3.1, as published by the Free Software Foundation. -- 21-- -- 22-- You should have received a copy of the GNU General Public License and -- 23-- a copy of the GCC Runtime Library Exception along with this program; -- 24-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25-- <http://www.gnu.org/licenses/>. -- 26-- -- 27-- GNAT was originally developed by the GNAT team at New York University. -- 28-- Extensive contributions were provided by Ada Core Technologies Inc. -- 29-- -- 30------------------------------------------------------------------------------ 31 32-- This package provides declarations shared across all instantiations of 33-- System.Generic_Bignums. 34 35with Ada.Unchecked_Conversion; 36with Interfaces; 37 38package System.Shared_Bignums is 39 pragma Preelaborate; 40 41 pragma Assert (Long_Long_Integer'Size = 64); 42 -- This package assumes that Long_Long_Integer size is 64 bit (i.e. that it 43 -- has a range of -2**63 to 2**63-1). The front end ensures that the mode 44 -- ELIMINATED is not allowed for overflow checking if this is not the case. 45 46 subtype Length is Natural range 0 .. 2 ** 23 - 1; 47 -- Represent number of words in Digit_Vector 48 49 Base : constant := 2 ** 32; 50 -- Digit vectors use this base 51 52 subtype SD is Interfaces.Unsigned_32; 53 -- Single length digit 54 55 type Digit_Vector is array (Length range <>) of SD; 56 -- Represent digits of a number (most significant digit first) 57 58 type Bignum_Data (Len : Length) is record 59 Neg : Boolean; 60 -- Set if value is negative, never set for zero 61 62 D : Digit_Vector (1 .. Len); 63 -- Digits of number, most significant first, represented in base 64 -- 2**Base. No leading zeroes are stored, and the value of zero is 65 -- represented using an empty vector for D. 66 end record; 67 68 for Bignum_Data use record 69 Len at 0 range 0 .. 23; 70 Neg at 3 range 0 .. 7; 71 end record; 72 73 type Bignum is access all Bignum_Data; 74 75 function To_Bignum is new Ada.Unchecked_Conversion (System.Address, Bignum); 76 77 function To_Address is new 78 Ada.Unchecked_Conversion (Bignum, System.Address); 79 80end System.Shared_Bignums; 81