GCC Middle and Back End API Reference
dfp.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "dfp.h"
#include "decimal128.h"
#include "decimal64.h"
#include "decimal32.h"
Include dependency graph for dfp.cc:

Macros

#define WORDS_BIGENDIAN   0
 

Functions

static void decimal_from_decnumber (REAL_VALUE_TYPE *r, decNumber *dn, decContext *context)
 
void decimal_real_from_string (REAL_VALUE_TYPE *r, const char *s)
 
static void decimal_to_decnumber (const REAL_VALUE_TYPE *r, decNumber *dn)
 
void encode_decimal32 (const struct real_format *fmt, long *buf, const REAL_VALUE_TYPE *r)
 
void decode_decimal32 (const struct real_format *fmt, REAL_VALUE_TYPE *r, const long *buf)
 
void encode_decimal64 (const struct real_format *fmt, long *buf, const REAL_VALUE_TYPE *r)
 
void decode_decimal64 (const struct real_format *fmt, REAL_VALUE_TYPE *r, const long *buf)
 
void encode_decimal128 (const struct real_format *fmt, long *buf, const REAL_VALUE_TYPE *r)
 
void decode_decimal128 (const struct real_format *fmt, REAL_VALUE_TYPE *r, const long *buf)
 
static void decimal_to_binary (REAL_VALUE_TYPE *to, const REAL_VALUE_TYPE *from, const real_format *fmt)
 
static void decimal_from_binary (REAL_VALUE_TYPE *to, const REAL_VALUE_TYPE *from)
 
int decimal_do_compare (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b, int nan_result)
 
void decimal_round_for_format (const struct real_format *fmt, REAL_VALUE_TYPE *r)
 
void decimal_real_convert (REAL_VALUE_TYPE *r, const real_format *fmt, const REAL_VALUE_TYPE *a)
 
void decimal_real_to_decimal (char *str, const REAL_VALUE_TYPE *r_orig, size_t buf_size, size_t digits, int crop_trailing_zeros)
 
static bool decimal_do_add (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *op0, const REAL_VALUE_TYPE *op1, int subtract_p)
 
static bool decimal_do_multiply (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *op0, const REAL_VALUE_TYPE *op1)
 
static bool decimal_do_divide (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *op0, const REAL_VALUE_TYPE *op1)
 
void decimal_do_fix_trunc (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a)
 
HOST_WIDE_INT decimal_real_to_integer (const REAL_VALUE_TYPE *r)
 
wide_int decimal_real_to_integer (const REAL_VALUE_TYPE *r, bool *fail, int precision)
 
bool decimal_real_arithmetic (REAL_VALUE_TYPE *r, enum tree_code code, const REAL_VALUE_TYPE *op0, const REAL_VALUE_TYPE *op1)
 
void decimal_real_maxval (REAL_VALUE_TYPE *r, int sign, machine_mode mode)
 

Macro Definition Documentation

◆ WORDS_BIGENDIAN

#define WORDS_BIGENDIAN   0
Decimal floating point support.
   Copyright (C) 2005-2024 Free Software Foundation, Inc.

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 3, or (at your option) any later
version.

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 COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
The order of the following headers is important for making sure
decNumber structure is large enough to hold decimal128 digits.   

Referenced by decode_decimal128(), decode_decimal64(), encode_decimal128(), and encode_decimal64().

Function Documentation

◆ decimal_do_add()

static bool decimal_do_add ( REAL_VALUE_TYPE * r,
const REAL_VALUE_TYPE * op0,
const REAL_VALUE_TYPE * op1,
int subtract_p )
static

◆ decimal_do_compare()

int decimal_do_compare ( const REAL_VALUE_TYPE * a,
const REAL_VALUE_TYPE * b,
int nan_result )
Helper function to real.cc:do_compare() to handle decimal internal
representation including when one of the operands is still in the
binary internal representation.   

References a, b, decimal_from_binary(), ggc_alloc(), and REAL_VALUE_TYPE.

Referenced by do_compare().

◆ decimal_do_divide()

static bool decimal_do_divide ( REAL_VALUE_TYPE * r,
const REAL_VALUE_TYPE * op0,
const REAL_VALUE_TYPE * op1 )
static
Compute R = OP0 / OP1.   

References decimal_from_decnumber(), decimal_to_decnumber(), ggc_alloc(), and r.

Referenced by decimal_real_arithmetic().

◆ decimal_do_fix_trunc()

void decimal_do_fix_trunc ( REAL_VALUE_TYPE * r,
const REAL_VALUE_TYPE * a )
Set R to A truncated to an integral value toward zero (decimal
floating point).   

References a, decimal_from_decnumber(), ggc_alloc(), and r.

Referenced by decimal_real_arithmetic(), and do_fix_trunc().

◆ decimal_do_multiply()

static bool decimal_do_multiply ( REAL_VALUE_TYPE * r,
const REAL_VALUE_TYPE * op0,
const REAL_VALUE_TYPE * op1 )
static
Compute R = OP0 * OP1.   

References decimal_from_decnumber(), decimal_to_decnumber(), ggc_alloc(), and r.

Referenced by decimal_real_arithmetic().

◆ decimal_from_binary()

static void decimal_from_binary ( REAL_VALUE_TYPE * to,
const REAL_VALUE_TYPE * from )
static
Helper function to convert from a binary real internal
representation.   

References decimal_real_from_string(), real_to_decimal(), and rvc_nan.

Referenced by decimal_do_compare(), decimal_real_arithmetic(), and decimal_real_convert().

◆ decimal_from_decnumber()

static void decimal_from_decnumber ( REAL_VALUE_TYPE * r,
decNumber * dn,
decContext * context )
static
Initialize R (a real with the decimal flag set) from DN.  Can
utilize status passed in via CONTEXT, if a previous operation had
interesting status.   

References ggc_alloc(), r, REAL_VALUE_TYPE, rvc_inf, rvc_nan, and rvc_normal.

Referenced by decimal_do_add(), decimal_do_divide(), decimal_do_fix_trunc(), decimal_do_multiply(), decimal_real_from_string(), decimal_round_for_format(), decode_decimal128(), decode_decimal32(), and decode_decimal64().

◆ decimal_real_arithmetic()

bool decimal_real_arithmetic ( REAL_VALUE_TYPE * r,
enum tree_code code,
const REAL_VALUE_TYPE * op0,
const REAL_VALUE_TYPE * op1 )
Perform the decimal floating point operation described by CODE.
For a unary operation, OP1 will be NULL.  This function returns
true if the result may be inexact due to loss of precision.   

References a, b, decimal_do_add(), decimal_do_divide(), decimal_do_fix_trunc(), decimal_do_multiply(), decimal_from_binary(), gcc_unreachable, ggc_alloc(), r, real_compare(), REAL_VALUE_TYPE, and rvc_nan.

Referenced by real_arithmetic().

◆ decimal_real_convert()

void decimal_real_convert ( REAL_VALUE_TYPE * r,
const real_format * fmt,
const REAL_VALUE_TYPE * a )
Extend or truncate to a new mode.  Handles conversions between
binary and decimal types.   

References a, decimal_from_binary(), decimal_to_binary(), ggc_alloc(), and r.

Referenced by real_2expN(), real_convert(), and round_for_format().

◆ decimal_real_from_string()

void decimal_real_from_string ( REAL_VALUE_TYPE * r,
const char * s )

◆ decimal_real_maxval()

void decimal_real_maxval ( REAL_VALUE_TYPE * r,
int sign,
machine_mode mode )
Fills R with the largest finite value representable in mode MODE.
If SIGN is nonzero, R is set to the most negative finite value.   

References decimal_real_from_string(), gcc_unreachable, ggc_alloc(), and r.

Referenced by real_maxval().

◆ decimal_real_to_decimal()

void decimal_real_to_decimal ( char * str,
const REAL_VALUE_TYPE * r_orig,
size_t buf_size,
size_t digits,
int crop_trailing_zeros )
Render R_ORIG as a decimal floating point constant.  Emit DIGITS
significant digits in the result, bounded by BUF_SIZE.  If DIGITS
is 0, choose the maximum for the representation.  If
CROP_TRAILING_ZEROS, strip trailing zeros.  Currently, not honoring
DIGITS or CROP_TRAILING_ZEROS.   

References gcc_assert, and ggc_alloc().

Referenced by real_to_decimal_for_mode().

◆ decimal_real_to_integer() [1/2]

HOST_WIDE_INT decimal_real_to_integer ( const REAL_VALUE_TYPE * r)
Render decimal float value R as an integer.   

References ggc_alloc(), r, real_from_string(), real_to_integer(), and REAL_VALUE_TYPE.

Referenced by real_to_integer(), and real_to_integer().

◆ decimal_real_to_integer() [2/2]

wide_int decimal_real_to_integer ( const REAL_VALUE_TYPE * r,
bool * fail,
int precision )
Likewise, but returns a wide_int with PRECISION.  *FAIL is set if the
value does not fit.   

References ggc_alloc(), r, real_from_string(), real_to_integer(), and REAL_VALUE_TYPE.

◆ decimal_round_for_format()

void decimal_round_for_format ( const struct real_format * fmt,
REAL_VALUE_TYPE * r )
Helper to round_for_format, handling decimal float types.   

References decimal_double_format, decimal_from_decnumber(), decimal_quad_format, decimal_single_format, gcc_unreachable, ggc_alloc(), r, and rvc_normal.

Referenced by round_for_format().

◆ decimal_to_binary()

static void decimal_to_binary ( REAL_VALUE_TYPE * to,
const REAL_VALUE_TYPE * from,
const real_format * fmt )
static
Helper function to convert from a binary real internal
representation.   

References ggc_alloc(), real_from_string3(), real_to_decimal(), and rvc_normal.

Referenced by decimal_real_convert().

◆ decimal_to_decnumber()

static void decimal_to_decnumber ( const REAL_VALUE_TYPE * r,
decNumber * dn )
static

◆ decode_decimal128()

void decode_decimal128 ( const struct real_format * fmt,
REAL_VALUE_TYPE * r,
const long * buf )
Decode an IEEE 754 decimal128 type into a real.   

References decimal_from_decnumber(), FLOAT_WORDS_BIG_ENDIAN, ggc_alloc(), r, and WORDS_BIGENDIAN.

Referenced by decode_decimal_quad().

◆ decode_decimal32()

void decode_decimal32 ( const struct real_format * fmt,
REAL_VALUE_TYPE * r,
const long * buf )
Decode an IEEE 754 decimal32 type into a real.   

References decimal_from_decnumber(), ggc_alloc(), and r.

Referenced by decode_decimal_single().

◆ decode_decimal64()

void decode_decimal64 ( const struct real_format * fmt,
REAL_VALUE_TYPE * r,
const long * buf )
Decode an IEEE 754 decimal64 type into a real.   

References decimal_from_decnumber(), FLOAT_WORDS_BIG_ENDIAN, ggc_alloc(), r, and WORDS_BIGENDIAN.

Referenced by decode_decimal_double().

◆ encode_decimal128()

void encode_decimal128 ( const struct real_format * fmt,
long * buf,
const REAL_VALUE_TYPE * r )
Encode a real into an IEEE 754 decimal128 type.   

References decimal_to_decnumber(), FLOAT_WORDS_BIG_ENDIAN, ggc_alloc(), r, and WORDS_BIGENDIAN.

Referenced by encode_decimal_quad().

◆ encode_decimal32()

void encode_decimal32 ( const struct real_format * fmt,
long * buf,
const REAL_VALUE_TYPE * r )
Encode a real into an IEEE 754 decimal32 type.   

References decimal_to_decnumber(), ggc_alloc(), and r.

Referenced by encode_decimal_single().

◆ encode_decimal64()

void encode_decimal64 ( const struct real_format * fmt,
long * buf,
const REAL_VALUE_TYPE * r )
Encode a real into an IEEE 754 decimal64 type.   

References decimal_to_decnumber(), FLOAT_WORDS_BIG_ENDIAN, ggc_alloc(), r, and WORDS_BIGENDIAN.

Referenced by encode_decimal_double().