+++ /dev/null
-/* -*-c-*-
- *
- * $Id: mptypes.h,v 1.1 1999/09/03 08:41:12 mdw Exp $
- *
- * Types for multiprecision arithmetic
- *
- * (c) 1999 Straylight/Edgeware
- */
-
-/*----- Licensing notice --------------------------------------------------*
- *
- * This file is part of Catacomb.
- *
- * Catacomb is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * Catacomb is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with Catacomb; if not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA.
- */
-
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: mptypes.h,v $
- * Revision 1.1 1999/09/03 08:41:12 mdw
- * Initial import.
- *
- */
-
-#ifndef MPTYPES_H
-#define MPTYPES_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/*----- Header files ------------------------------------------------------*/
-
-#include <limits.h>
-#include <stddef.h>
-
-#include <mLib/bits.h>
-
-/*----- Important types ---------------------------------------------------*/
-
-/* --- Choose word and doubleword types --- *
- *
- * The types I need, and their properties, are as follows:
- *
- * * @mpw@ is the radix in which all the arithmetic is actually performed.
- * It must be an unsigned type that is efficient on the host's hardware.
- * @MPW_MAX@ is the largest value of type @mpw@ I'll use. (Although
- * there may be bigger values available, I'll not use them.) @MPW_BITS@
- * is the number of bits required to represent @MPW_MAX@.
- *
- * * @mpd@ must be twice as large as @mpw@: I must be able to multiply any
- * two @mpw@ values and end up with an @mpd@ as the result. @MPD_MAX@ is
- * the largest value of type @mpd@ I'll use, and @MPD_BITS@ is the number
- * of bits required to represent it.
- *
- * The algorithm used to choose these types is:
- *
- * * Try to use @unsigned int@ as @mpw@ and @unsigned long@ as @mpd@. If
- * @unsigned long@ looks to small to do this, try to use @unsigned long
- * long@, if it exists.
- *
- * * If that's not good enough, then fall back to @unsigned short@ as @mpw@
- * and choose one of @unsigned int@, @unsigned long@ or @unsigned long
- * long@ (in decreasing order of preference) as @mpd@.
- *
- * * If that doesn't work either, choose @unsigned int@ as both, and use
- * half its width only as @mpw@.
- */
-
-#ifndef MP_TEST
-
-/* --- Hack for GCC until it catches up with C9X --- *
- *
- * GCC uses bogus names for the @long long@ minimum and maximum values in its
- * <limits.h> file. This little hack makes the proper portable C9X names
- * work as well.
- */
-
-#if defined(ULONG_LONG_MAX) && !defined(ULLONG_MAX)
-# define LLONG_MIN LONG_LONG_MIN
-# define LLONG_MAX LONG_LONG_MAX
-# define ULLONG_MAX ULONG_LONG_MAX
-#endif
-
-/* --- Decide on the actual types to use --- *
- *
- * The division trick here makes sure that one type is twice another without
- * the risk of overflowing the arithmetic provided by the preprocessor.
- */
-
-#if ULONG_MAX / UINT_MAX >= UINT_MAX
- typedef unsigned int mpw;
- typedef unsigned long mpd;
-# define MPW_MAX UINT_MAX
-#elif ULLONG_MAX / UINT_MAX >= UINT_MAX
- typedef unsigned int mpw;
- typedef unsigned long long mpd;
-# define MPW_MAX UINT_MAX
-#elif UINT_MAX / USHRT_MAX >= USHRT_MAX
- typedef unsigned short mpw;
- typedef unsigned int mpd;
-# define MPW_MAX USHRT_MAX
-#elif ULONG_MAX / USHRT_MAX >= USHRT_MAX
- typedef unsigned short mpw;
- typedef unsigned long mpd;
-# define MPW_MAX USHRT_MAX
-#elif ULLONG_MAX / USHRT_MAX >= USHRT_MAX
- typedef unsigned short mpw;
- typedef unsigned long long mpd;
-# define MPW_MAX USHRT_MAX
-#else
- typedef unsigned int mpw;
- typedef unsigned int mpd;
-# define MPD_MAX UINT_MAX
-#endif
-
-/* --- Fix a value for @MPD_MAX@ --- *
- *
- * This will then be the target for finding the bit widths and things.
- */
-
-#ifdef MPW_MAX
-# define MPD_MAX ((MPW_MAX + 1) * MPW_MAX + MW_WMAX)
-#endif
-
-/* --- Find the width of @MPD_MAX@ in bits --- *
- *
- * It must be at least 16 bits wide, because the smallest type I bother to
- * try is @unsigned short@. I only bother testing for up to 64 bits, and in
- * power-of-two chunks, because I don't care about efficiency on more bizarre
- * systems.
- */
-
-#if MPD_MAX <= 0xfffffffff
-# if MPD_MAX == 0xffffffff
-# define MPD_BITS 32
-# elif MPD_MAX >= 0x0fffffff
-# define MPD_BITS 28
-# elif MPD_MAX >= 0x00ffffff
-# define MPD_BITS 24
-# elif MPD_MAX >= 0x000fffff
-# define MPD_BITS 20
-# elif MPD_MAX >= 0x0000ffff
-# define MPD_BITS 16
-# else
-# error "Abject failure deciding on type `mpw'"
-#else
-# if MPD_MAX / 0xffffffff < 0xffffffff
-# define MPD_BITS 32
-# else
-# define MPD_BITS 64 /* Slightly dodgy */
-#endif
-
-/* --- Now sort out the other magical values --- */
-
-#undef MPD_MAX
-#undef MPW_MAX
-
-#define MPW_BITS (MPD_BITS / 2)
-#define MPD_MAX (((1 << (MPD_BITS - 1)) - 1) * 2 + 1)
-#define MPW_MAX ((1 << MPW_BITS) - 1)
-
-#endif
-
-/*----- Macros for coercion and masking -----------------------------------*/
-
-/* --- @MPW@ --- *
- *
- * Arguments: @x@ = an unsigned value
- *
- * Use: Expands to the value of @x@ masked and typecast to a
- * multiprecision integer word.
- */
-
-#define MPW(x) ((mpw)((x) & MPW_MAX))
-
-/* --- @MPWS@ --- *
- *
- * Arguments: @n@ = number of words
- *
- * Use: Expands to the number of bytes occupied by a given number of
- * words.
- */
-
-#define MPWS(n) ((n) * sizeof(mpw))
-
-/*----- That's all, folks -------------------------------------------------*/
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif