From 72ac97cdfc0592b567cb62582300c0d707701bb1 Mon Sep 17 00:00:00 2001 From: Tom Musta Date: Mon, 21 Apr 2014 15:54:45 -0500 Subject: libdecnumber: Introduce libdecnumber Code Add files from the libdecnumber decimal floating point library to QEMU. The libdecnumber library was originally part of GCC and contains code that is useful in emulating the PowerPC decimal floating point (DFP) instructions. This particular copy of the source comes from GCC 4.3 and is licensed at GPLv2+. Signed-off-by: Tom Musta Signed-off-by: Alexander Graf --- include/libdecnumber/dpd/decimal32.h | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 include/libdecnumber/dpd/decimal32.h (limited to 'include/libdecnumber/dpd/decimal32.h') diff --git a/include/libdecnumber/dpd/decimal32.h b/include/libdecnumber/dpd/decimal32.h new file mode 100644 index 0000000000..0d53046417 --- /dev/null +++ b/include/libdecnumber/dpd/decimal32.h @@ -0,0 +1,99 @@ +/* Decimal 32-bit format module header for the decNumber C Library. + Copyright (C) 2005, 2007 Free Software Foundation, Inc. + Contributed by IBM Corporation. Author Mike Cowlishaw. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2, or (at your option) any later + version. + + In addition to the permissions in the GNU General Public License, + the Free Software Foundation gives you unlimited permission to link + the compiled version of this file into combinations with other + programs, and to distribute those combinations without any + restriction coming from the use of this file. (The General Public + License restrictions do apply in other respects; for example, they + cover modification of the file, and distribution when not linked + into a combine executable.) + + GCC 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 General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING. If not, write to the Free + Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ + +/* ------------------------------------------------------------------ */ +/* Decimal 32-bit format module header */ +/* ------------------------------------------------------------------ */ + +#if !defined(DECIMAL32) + #define DECIMAL32 + #define DEC32NAME "decimal32" /* Short name */ + #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */ + #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */ + + /* parameters for decimal32s */ + #define DECIMAL32_Bytes 4 /* length */ + #define DECIMAL32_Pmax 7 /* maximum precision (digits) */ + #define DECIMAL32_Emax 96 /* maximum adjusted exponent */ + #define DECIMAL32_Emin -95 /* minimum adjusted exponent */ + #define DECIMAL32_Bias 101 /* bias for the exponent */ + #define DECIMAL32_String 15 /* maximum string length, +1 */ + #define DECIMAL32_EconL 6 /* exp. continuation length */ + /* highest biased exponent (Elimit-1) */ + #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1) + + /* check enough digits, if pre-defined */ + #if defined(DECNUMDIGITS) + #if (DECNUMDIGITS=7 for safe use + #endif + #endif + + #ifndef DECNUMDIGITS + #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/ + #endif + #ifndef DECNUMBER + #include "decNumber.h" /* context and number library */ + #endif + + /* Decimal 32-bit type, accessible by bytes */ + typedef struct { + uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/ + } decimal32; + + /* special values [top byte excluding sign bit; last two bits are */ + /* don't-care for Infinity on input, last bit don't-care for NaN] */ + #if !defined(DECIMAL_NaN) + #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ + #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ + #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ + #endif + + /* ---------------------------------------------------------------- */ + /* Routines */ + /* ---------------------------------------------------------------- */ + + #include "decimal32Symbols.h" + + /* String conversions */ + decimal32 * decimal32FromString(decimal32 *, const char *, decContext *); + char * decimal32ToString(const decimal32 *, char *); + char * decimal32ToEngString(const decimal32 *, char *); + + /* decNumber conversions */ + decimal32 * decimal32FromNumber(decimal32 *, const decNumber *, + decContext *); + decNumber * decimal32ToNumber(const decimal32 *, decNumber *); + + /* Format-dependent utilities */ + uint32_t decimal32IsCanonical(const decimal32 *); + decimal32 * decimal32Canonical(decimal32 *, const decimal32 *); + +#endif -- cgit v1.2.3-55-g7522 From f5d7f1464692433fc0ff2c3418ef9ad3e14d3a3d Mon Sep 17 00:00:00 2001 From: Tom Musta Date: Mon, 21 Apr 2014 15:54:46 -0500 Subject: libdecnumber: Eliminate #include *Symbols.h The various *Symbols.h files were not copied from the original GCC libdecnumber library; they are not necessary for use in QEMU. Remove all instances of #include "*Symbols.h" Signed-off-by: Tom Musta Signed-off-by: Alexander Graf --- include/libdecnumber/decContext.h | 1 - include/libdecnumber/decDPD.h | 1 - include/libdecnumber/decNumber.h | 1 - include/libdecnumber/decNumberLocal.h | 2 -- include/libdecnumber/dpd/decimal128.h | 1 - include/libdecnumber/dpd/decimal32.h | 1 - include/libdecnumber/dpd/decimal64.h | 1 - 7 files changed, 8 deletions(-) (limited to 'include/libdecnumber/dpd/decimal32.h') diff --git a/include/libdecnumber/decContext.h b/include/libdecnumber/decContext.h index f80d03c50c..1a3f15eba8 100644 --- a/include/libdecnumber/decContext.h +++ b/include/libdecnumber/decContext.h @@ -237,7 +237,6 @@ /* decContext routines */ - #include "decContextSymbols.h" extern decContext * decContextClearStatus(decContext *, uint32_t); extern decContext * decContextDefault(decContext *, int32_t); diff --git a/include/libdecnumber/decDPD.h b/include/libdecnumber/decDPD.h index 3cc1d63413..26a21ec8ed 100644 --- a/include/libdecnumber/decDPD.h +++ b/include/libdecnumber/decDPD.h @@ -35,7 +35,6 @@ /* ------------------------------------------------------------------------ */ /* For details, see: http://www2.hursley.ibm.com/decimal/DPDecimal.html */ -#include "decDPDSymbols.h" /* This include file defines several DPD and BCD conversion tables: */ /* */ diff --git a/include/libdecnumber/decNumber.h b/include/libdecnumber/decNumber.h index 0a9fdced8b..aa99a5b55c 100644 --- a/include/libdecnumber/decNumber.h +++ b/include/libdecnumber/decNumber.h @@ -111,7 +111,6 @@ /* decNumber public functions and macros */ /* ---------------------------------------------------------------- */ - #include "decNumberSymbols.h" /* Conversions */ decNumber * decNumberFromInt32(decNumber *, int32_t); diff --git a/include/libdecnumber/decNumberLocal.h b/include/libdecnumber/decNumberLocal.h index f1568f725e..f2a919bb11 100644 --- a/include/libdecnumber/decNumberLocal.h +++ b/include/libdecnumber/decNumberLocal.h @@ -100,7 +100,6 @@ extern const uByte DECSTICKYTAB[10]; /* re-round digits if sticky */ extern const uInt DECPOWERS[10]; /* powers of ten table */ /* The following are included from decDPD.h */ -#include "decDPDSymbols.h" extern const uShort DPD2BIN[1024]; /* DPD -> 0-999 */ extern const uShort BIN2DPD[1000]; /* 0-999 -> DPD */ extern const uInt DPD2BINK[1024]; /* DPD -> 0-999000 */ @@ -326,7 +325,6 @@ #define DFISSNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7e000000) /* Shared lookup tables */ -#include "decCommonSymbols.h" extern const uInt DECCOMBMSD[64]; /* Combination field -> MSD */ extern const uInt DECCOMBFROM[48]; /* exp+msd -> Combination */ diff --git a/include/libdecnumber/dpd/decimal128.h b/include/libdecnumber/dpd/decimal128.h index f8f5b5a8ff..251b964bad 100644 --- a/include/libdecnumber/dpd/decimal128.h +++ b/include/libdecnumber/dpd/decimal128.h @@ -82,7 +82,6 @@ /* Routines */ /* ---------------------------------------------------------------- */ - #include "decimal128Symbols.h" /* String conversions */ decimal128 * decimal128FromString(decimal128 *, const char *, decContext *); diff --git a/include/libdecnumber/dpd/decimal32.h b/include/libdecnumber/dpd/decimal32.h index 0d53046417..5f06cd48eb 100644 --- a/include/libdecnumber/dpd/decimal32.h +++ b/include/libdecnumber/dpd/decimal32.h @@ -80,7 +80,6 @@ /* Routines */ /* ---------------------------------------------------------------- */ - #include "decimal32Symbols.h" /* String conversions */ decimal32 * decimal32FromString(decimal32 *, const char *, decContext *); diff --git a/include/libdecnumber/dpd/decimal64.h b/include/libdecnumber/dpd/decimal64.h index 549b626536..c391e254e4 100644 --- a/include/libdecnumber/dpd/decimal64.h +++ b/include/libdecnumber/dpd/decimal64.h @@ -82,7 +82,6 @@ /* Routines */ /* ---------------------------------------------------------------- */ - #include "decimal64Symbols.h" /* String conversions */ decimal64 * decimal64FromString(decimal64 *, const char *, decContext *); -- cgit v1.2.3-55-g7522 From 0f2d3732202818fb85c09d1c204a08c4d79b70bc Mon Sep 17 00:00:00 2001 From: Tom Musta Date: Mon, 21 Apr 2014 15:54:47 -0500 Subject: libdecnumber: Prepare libdecnumber for QEMU include structure Consistent with other libraries in QEMU, the libdecnumber header files were placed in include/libdecnumber, separate from the C code. This is different from the original libdecnumber source, where they were co-located. Change the libdecnumber source code so that it reflects this split. Specifically, modify directives of the form: #include "xxx.h" to look like: #include "libdecnumber/xxx.h" Signed-off-by: Tom Musta Signed-off-by: Alexander Graf --- include/libdecnumber/decNumber.h | 2 +- include/libdecnumber/decNumberLocal.h | 2 +- include/libdecnumber/dpd/decimal128.h | 2 +- include/libdecnumber/dpd/decimal32.h | 2 +- include/libdecnumber/dpd/decimal64.h | 2 +- libdecnumber/decContext.c | 6 +++--- libdecnumber/decNumber.c | 6 +++--- libdecnumber/dpd/decimal128.c | 8 ++++---- libdecnumber/dpd/decimal32.c | 8 ++++---- libdecnumber/dpd/decimal64.c | 12 ++++++------ 10 files changed, 25 insertions(+), 25 deletions(-) (limited to 'include/libdecnumber/dpd/decimal32.h') diff --git a/include/libdecnumber/decNumber.h b/include/libdecnumber/decNumber.h index aa99a5b55c..fb324bd35a 100644 --- a/include/libdecnumber/decNumber.h +++ b/include/libdecnumber/decNumber.h @@ -39,7 +39,7 @@ #define DECAUTHOR "Mike Cowlishaw" /* Who to blame */ #if !defined(DECCONTEXT) - #include "decContext.h" + #include "libdecnumber/decContext.h" #endif /* Bit settings for decNumber.bits */ diff --git a/include/libdecnumber/decNumberLocal.h b/include/libdecnumber/decNumberLocal.h index f2a919bb11..f5f508f294 100644 --- a/include/libdecnumber/decNumberLocal.h +++ b/include/libdecnumber/decNumberLocal.h @@ -44,7 +44,7 @@ #include /* for abs */ #include /* for memset, strcpy */ - #include "dconfig.h" /* for WORDS_BIGENDIAN */ + #include "libdecnumber/dconfig.h" /* Conditional code flag -- set this to match hardware platform */ /* 1=little-endian, 0=big-endian */ diff --git a/include/libdecnumber/dpd/decimal128.h b/include/libdecnumber/dpd/decimal128.h index 251b964bad..7d9ee24f85 100644 --- a/include/libdecnumber/dpd/decimal128.h +++ b/include/libdecnumber/dpd/decimal128.h @@ -60,7 +60,7 @@ #define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/ #endif #ifndef DECNUMBER - #include "decNumber.h" /* context and number library */ + #include "libdecnumber/decNumber.h" #endif /* Decimal 128-bit type, accessible by bytes */ diff --git a/include/libdecnumber/dpd/decimal32.h b/include/libdecnumber/dpd/decimal32.h index 5f06cd48eb..de313e0024 100644 --- a/include/libdecnumber/dpd/decimal32.h +++ b/include/libdecnumber/dpd/decimal32.h @@ -60,7 +60,7 @@ #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/ #endif #ifndef DECNUMBER - #include "decNumber.h" /* context and number library */ + #include "libdecnumber/decNumber.h" #endif /* Decimal 32-bit type, accessible by bytes */ diff --git a/include/libdecnumber/dpd/decimal64.h b/include/libdecnumber/dpd/decimal64.h index c391e254e4..2f6c049402 100644 --- a/include/libdecnumber/dpd/decimal64.h +++ b/include/libdecnumber/dpd/decimal64.h @@ -62,7 +62,7 @@ #define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined*/ #endif #ifndef DECNUMBER - #include "decNumber.h" /* context and number library */ + #include "libdecnumber/decNumber.h" #endif /* Decimal 64-bit type, accessible by bytes */ diff --git a/libdecnumber/decContext.c b/libdecnumber/decContext.c index 8d577f48ad..684710626d 100644 --- a/libdecnumber/decContext.c +++ b/libdecnumber/decContext.c @@ -37,9 +37,9 @@ #include /* for strcmp */ #include /* for printf if DECCHECK */ -#include "dconfig.h" /* for GCC definitions */ -#include "decContext.h" /* context and base types */ -#include "decNumberLocal.h" /* decNumber local types, etc. */ +#include "libdecnumber/dconfig.h" +#include "libdecnumber/decContext.h" +#include "libdecnumber/decNumberLocal.h" #if DECCHECK /* compile-time endian tester [assumes sizeof(Int)>1] */ diff --git a/libdecnumber/decNumber.c b/libdecnumber/decNumber.c index f9a624a1af..1bfc08173e 100644 --- a/libdecnumber/decNumber.c +++ b/libdecnumber/decNumber.c @@ -170,9 +170,9 @@ #include /* for printf [if needed] */ #include /* for strcpy */ #include /* for lower */ -#include "dconfig.h" /* for GCC definitions */ -#include "decNumber.h" /* base number library */ -#include "decNumberLocal.h" /* decNumber local types, etc. */ +#include "libdecnumber/dconfig.h" +#include "libdecnumber/decNumber.h" +#include "libdecnumber/decNumberLocal.h" /* Constants */ /* Public lookup table used by the D2U macro */ diff --git a/libdecnumber/dpd/decimal128.c b/libdecnumber/dpd/decimal128.c index 54191aab5c..8f8e9835f5 100644 --- a/libdecnumber/dpd/decimal128.c +++ b/libdecnumber/dpd/decimal128.c @@ -42,11 +42,11 @@ #include /* [for memset/memcpy] */ #include /* [for printf] */ -#include "dconfig.h" /* GCC definitions */ +#include "libdecnumber/dconfig.h" #define DECNUMDIGITS 34 /* make decNumbers with space for 34 */ -#include "decNumber.h" /* base number library */ -#include "decNumberLocal.h" /* decNumber local types, etc. */ -#include "decimal128.h" /* our primary include */ +#include "libdecnumber/decNumber.h" +#include "libdecnumber/decNumberLocal.h" +#include "libdecnumber/dpd/decimal128.h" /* Utility routines and tables [in decimal64.c] */ extern const uInt COMBEXP[32], COMBMSD[32]; diff --git a/libdecnumber/dpd/decimal32.c b/libdecnumber/dpd/decimal32.c index d8e3f59781..f8d30e6304 100644 --- a/libdecnumber/dpd/decimal32.c +++ b/libdecnumber/dpd/decimal32.c @@ -42,11 +42,11 @@ #include /* [for memset/memcpy] */ #include /* [for printf] */ -#include "dconfig.h" /* GCC definitions */ +#include "libdecnumber/dconfig.h" #define DECNUMDIGITS 7 /* make decNumbers with space for 7 */ -#include "decNumber.h" /* base number library */ -#include "decNumberLocal.h" /* decNumber local types, etc. */ -#include "decimal32.h" /* our primary include */ +#include "libdecnumber/decNumber.h" +#include "libdecnumber/decNumberLocal.h" +#include "libdecnumber/dpd/decimal32.h" /* Utility tables and routines [in decimal64.c] */ extern const uInt COMBEXP[32], COMBMSD[32]; diff --git a/libdecnumber/dpd/decimal64.c b/libdecnumber/dpd/decimal64.c index 474eb7cf8a..3bd27760ae 100644 --- a/libdecnumber/dpd/decimal64.c +++ b/libdecnumber/dpd/decimal64.c @@ -42,11 +42,11 @@ #include /* [for memset/memcpy] */ #include /* [for printf] */ -#include "dconfig.h" /* GCC definitions */ +#include "libdecnumber/dconfig.h" #define DECNUMDIGITS 16 /* make decNumbers with space for 16 */ -#include "decNumber.h" /* base number library */ -#include "decNumberLocal.h" /* decNumber local types, etc. */ -#include "decimal64.h" /* our primary include */ +#include "libdecnumber/decNumber.h" +#include "libdecnumber/decNumberLocal.h" +#include "libdecnumber/dpd/decimal64.h" /* Utility routines and tables [in decimal64.c]; externs for C++ */ extern const uInt COMBEXP[32], COMBMSD[32]; @@ -70,7 +70,7 @@ extern void decNumberShow(const decNumber *); /* .. */ #define DEC_BIN2CHAR 1 #define DEC_DPD2BIN 1 #define DEC_BIN2DPD 1 /* used for all sizes */ -#include "decDPD.h" /* lookup tables */ +#include "libdecnumber/decDPD.h" /* ------------------------------------------------------------------ */ /* decimal64FromNumber -- convert decNumber to decimal64 */ @@ -559,7 +559,7 @@ void decimal64Show(const decimal64 *d64) { #else #define DEC_DPD2BCD 1 #endif -#include "decDPD.h" /* lookup tables */ +#include "libdecnumber/decDPD.h" /* The maximum number of decNumberUnits needed for a working copy of */ /* the units array is the ceiling of digits/DECDPUN, where digits is */ -- cgit v1.2.3-55-g7522