GCC Middle and Back End API Reference
sreal Class Reference

#include <sreal.h>

Public Member Functions

 sreal ()
 
 sreal (int64_t sig, int exp=0)
 
void dump (FILE *) const
 
int64_t to_int () const
 
int64_t to_nearest_int () const
 
double to_double () const
 
void stream_out (struct output_block *)
 
sreal operator+ (const sreal &other) const
 
sreal operator- (const sreal &other) const
 
sreal operator* (const sreal &other) const
 
sreal operator/ (const sreal &other) const
 
bool operator< (const sreal &other) const
 
bool operator== (const sreal &other) const
 
sreal operator- () const
 
sreal shift (int s) const
 

Static Public Member Functions

static sreal stream_in (class lto_input_block *)
 
static sreal min ()
 
static sreal max ()
 

Private Member Functions

void normalize (int64_t new_sig, signed int new_exp)
 
void normalize_up (int64_t new_sig, signed int new_exp)
 
void normalize_down (int64_t new_sig, signed int new_exp)
 
void shift_right (int amount)
 

Static Private Member Functions

static sreal signedless_plus (const sreal &a, const sreal &b, bool negative)
 
static sreal signedless_minus (const sreal &a, const sreal &b, bool negative)
 

Private Attributes

int32_t m_sig
 
signed int m_exp
 

Detailed Description

Structure for holding a simple real number.   

Constructor & Destructor Documentation

◆ sreal() [1/2]

sreal::sreal ( )
inline

◆ sreal() [2/2]

sreal::sreal ( int64_t sig,
int exp = 0 )
inline

References exp(), and normalize().

Member Function Documentation

◆ dump()

void sreal::dump ( FILE * file) const
Simple data type for real numbers for the GNU compiler.
   Copyright (C) 2002-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/>.   
This library supports real numbers;
  inf and nan are NOT supported.
  It is written to be simple and fast.

  Value of sreal is
       x = sig * 2 ^ exp
  where
       sig = significant
         (for < 64-bit machines sig = sig_lo + sig_hi * 2 ^ SREAL_PART_BITS)
       exp = exponent

  One uint64_t is used for the significant.
  Only a half of significant bits is used (in normalized sreals) so that we do
  not have problems with overflow, for example when c->sig = a->sig * b->sig.
  So the precision is 32-bit.

  Invariant: The numbers are normalized before and after each call of sreal_*.

  Normalized sreals:
  All numbers (except zero) meet following conditions:
        SREAL_MIN_SIG <= sig && sig <= SREAL_MAX_SIG
       -SREAL_MAX_EXP <= exp && exp <= SREAL_MAX_EXP

  If the number would be too large, it is set to upper bounds of these
  conditions.

  If the number is zero or would be too small it meets following conditions:
       sig == 0 && exp == -SREAL_MAX_EXP
Print the content of struct sreal.   

References ggc_alloc(), m_exp, m_sig, and PRIi64.

Referenced by debug().

◆ max()

◆ min()

static sreal sreal::min ( )
inlinestatic

References m_exp, m_sig, min(), SREAL_MAX_EXP, and SREAL_MAX_SIG.

Referenced by min(), and recursive_inlining().

◆ normalize()

void sreal::normalize ( int64_t new_sig,
signed int new_exp )
inlineprivate
Normalize *this; the hot path.   

References absu_hwi(), ggc_alloc(), m_exp, m_sig, normalize_down(), normalize_up(), SREAL_MAX_EXP, SREAL_MAX_SIG, and SREAL_MIN_SIG.

Referenced by sreal().

◆ normalize_down()

void sreal::normalize_down ( int64_t new_sig,
signed int new_exp )
inlineprivate
Make significant to be <= SREAL_MAX_SIG.

Make this separate method so inliner can handle hot path better.   

References absu_hwi(), floor_log2(), gcc_checking_assert, ggc_alloc(), m_exp, m_sig, shift, SREAL_MAX_EXP, SREAL_MAX_SIG, SREAL_MIN_SIG, SREAL_PART_BITS, and SREAL_SIGN.

Referenced by normalize().

◆ normalize_up()

void sreal::normalize_up ( int64_t new_sig,
signed int new_exp )
inlineprivate
Make significant to be >= SREAL_MIN_SIG.

Make this separate method so inliner can handle hot path better.   

References absu_hwi(), floor_log2(), gcc_checking_assert, ggc_alloc(), m_exp, m_sig, shift, SREAL_MAX_EXP, SREAL_MIN_SIG, SREAL_PART_BITS, and SREAL_SIGN.

Referenced by normalize().

◆ operator*()

sreal sreal::operator* ( const sreal & other) const
Return *this * other.   

References absu_hwi(), ggc_alloc(), m_exp, m_sig, r, SREAL_MAX_EXP, and SREAL_MIN_SIG.

◆ operator+()

sreal sreal::operator+ ( const sreal & other) const
Return *this + other.   

References ggc_alloc(), m_sig, r, and SREAL_BITS.

◆ operator-() [1/2]

sreal sreal::operator- ( ) const
inline

References ggc_alloc().

◆ operator-() [2/2]

sreal sreal::operator- ( const sreal & other) const
Return *this - other.   

References ggc_alloc(), m_sig, r, and SREAL_BITS.

◆ operator/()

sreal sreal::operator/ ( const sreal & other) const
Return *this / other.   

References gcc_checking_assert, ggc_alloc(), m_exp, m_sig, r, SREAL_ABS, SREAL_PART_BITS, and SREAL_SIGN.

◆ operator<()

bool sreal::operator< ( const sreal & other) const
inline

References ggc_alloc(), m_exp, m_sig, and r.

◆ operator==()

bool sreal::operator== ( const sreal & other) const
inline

References m_exp, and m_sig.

◆ shift()

sreal sreal::shift ( int s) const
inline

◆ shift_right()

void sreal::shift_right ( int s)
private
Shift this right by S bits.  Needed: 0 < S <= SREAL_BITS.
When the most significant bit shifted out is 1, add 1 to this (rounding).

References gcc_checking_assert, ggc_alloc(), m_exp, m_sig, SREAL_BITS, and SREAL_MAX_EXP.

◆ signedless_minus()

static sreal sreal::signedless_minus ( const sreal & a,
const sreal & b,
bool negative )
staticprivate

◆ signedless_plus()

static sreal sreal::signedless_plus ( const sreal & a,
const sreal & b,
bool negative )
staticprivate

◆ stream_in()

sreal sreal::stream_in ( class lto_input_block * ib)
static
Read sreal value from IB.   

References ggc_alloc(), m_exp, m_sig, and streamer_read_hwi().

Referenced by inline_read_section().

◆ stream_out()

void sreal::stream_out ( struct output_block * ob)
Stream sreal value to OB.   

References m_exp, m_sig, and streamer_write_hwi().

Referenced by ipa_fn_summary_write().

◆ to_double()

◆ to_int()

int64_t sreal::to_int ( ) const
Return integer value of *this.   

References ggc_alloc(), INTTYPE_MAXIMUM, m_exp, m_sig, SREAL_ABS, SREAL_BITS, SREAL_PART_BITS, and SREAL_SIGN.

◆ to_nearest_int()

int64_t sreal::to_nearest_int ( ) const
Return nearest integer value of *this.   

References ggc_alloc(), INTTYPE_MAXIMUM, m_exp, m_sig, SREAL_ABS, SREAL_BITS, SREAL_PART_BITS, and SREAL_SIGN.

Field Documentation

◆ m_exp

◆ m_sig


The documentation for this class was generated from the following files: