PPL  1.2
globals_inlines.hh
Go to the documentation of this file.
1 /* Implementation of global objects: inline functions.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_globals_inlines_hh
25 #define PPL_globals_inlines_hh 1
26 
27 #include "compiler.hh"
28 #include <limits>
29 #include <cassert>
30 #include <istream>
31 #include <ostream>
32 #include <cctype>
33 #include <stdexcept>
34 
35 namespace Parma_Polyhedra_Library {
36 
37 inline dimension_type
39  return std::numeric_limits<dimension_type>::max();
40 }
41 
42 inline int32_t
44  const dimension_type divisor = 1U << (32 - 1);
45  dim = dim % divisor;
46  return static_cast<int32_t>(dim);
47 }
48 
51  return weight;
52 }
53 
54 inline bool
56  return b - a < (1ULL << (sizeof_to_bits(sizeof(Threshold)) - 1));
57 }
58 
60 Weightwatch_Traits::compute_delta(unsigned long unscaled, unsigned scale) {
61  if ((std::numeric_limits<Delta>::max() >> scale) < unscaled) {
62  throw std::invalid_argument("PPL::Weightwatch_Traits::"
63  "compute_delta(u, s):\n"
64  "values of u and s cause wrap around.");
65  }
66  return static_cast<Delta>(unscaled) << scale;
67 }
68 
69 inline void
70 Weightwatch_Traits::from_delta(Threshold& threshold, const Delta& delta) {
71  threshold = weight + delta;
72 }
73 
74 inline void
76 #ifndef NDEBUG
77  if (In_Assert::asserting()) {
78  return;
79  }
80 #endif
83  }
84  if (const Throwable* const p = abandon_expensive_computations) {
85  p->throw_me();
86  }
87 }
88 
89 inline dimension_type
90 compute_capacity(const dimension_type requested_size,
91  const dimension_type maximum_size) {
92  assert(requested_size <= maximum_size);
93  // Speculation factor 2.
94  return (requested_size < maximum_size/2)
95  ? (2*(requested_size + 1))
96  : maximum_size;
97  // Speculation factor 1.5.
98  // return (maximum_size - requested_size > requested_size/2)
99  // ? requested_size + requested_size/2 + 1
100  // : maximum_size;
101 }
102 
103 template <typename T>
104 inline typename
107  return 0;
108 }
109 
110 template <typename T>
111 inline typename
114  return sizeof(T);
115 }
116 
117 inline memory_size_type
118 external_memory_in_bytes(const mpz_class& x) {
119  return static_cast<memory_size_type>(x.get_mpz_t()[0]._mp_alloc)
120  * PPL_SIZEOF_MP_LIMB_T;
121 }
122 
123 inline memory_size_type
124 total_memory_in_bytes(const mpz_class& x) {
125  return sizeof(x) + external_memory_in_bytes(x);
126 }
127 
128 inline memory_size_type
129 external_memory_in_bytes(const mpq_class& x) {
130  return external_memory_in_bytes(x.get_num())
131  + external_memory_in_bytes(x.get_den());
132 }
133 
134 inline memory_size_type
135 total_memory_in_bytes(const mpq_class& x) {
136  return sizeof(x) + external_memory_in_bytes(x);
137 }
138 
139 inline void
140 ascii_dump(std::ostream& s, Representation r) {
141  if (r == DENSE) {
142  s << "DENSE";
143  }
144  else {
145  s << "SPARSE";
146  }
147 }
148 
149 inline bool
150 ascii_load(std::istream& is, Representation& r) {
151  std::string s;
152  if (!(is >> s)) {
153  return false;
154  }
155 
156  if (s == "DENSE") {
157  r = DENSE;
158  return true;
159  }
160  if (s == "SPARSE") {
161  r = SPARSE;
162  return true;
163  }
164  return false;
165 }
166 
167 inline bool
168 is_space(char c) {
169  return isspace(c) != 0;
170 }
171 
172 template <typename RA_Container>
173 inline typename RA_Container::iterator
174 nth_iter(RA_Container& cont, dimension_type n) {
175  typedef typename RA_Container::difference_type diff_t;
176  return cont.begin() + static_cast<diff_t>(n);
177 }
178 
179 template <typename RA_Container>
180 inline typename RA_Container::const_iterator
181 nth_iter(const RA_Container& cont, dimension_type n) {
182  typedef typename RA_Container::difference_type diff_t;
183  return cont.begin() + static_cast<diff_t>(n);
184 }
185 
186 inline dimension_type
188  return i & (~i + 1U);
189 }
190 
191 } // namespace Parma_Polyhedra_Library
192 
193 #endif // !defined(PPL_globals_inlines_hh)
size_t dimension_type
An unsigned integral type for representing space dimensions.
Enable_If< Is_Native_Or_Checked< T >::value, void >::type ascii_dump(std::ostream &s, const T &t)
unsigned long long Threshold
The type used to specify thresholds for computational weight.
dimension_type not_a_dimension()
Returns a value that does not designate a valid dimension.
static bool less_than(const Threshold &a, const Threshold &b)
Compares the two weights a and b.
bool is_space(char c)
Returns true if c is any kind of space character.
RA_Container::iterator nth_iter(RA_Container &cont, dimension_type n)
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
unsigned long long Delta
The type used to specify increments of computational weight.
#define sizeof_to_bits(size)
Definition: compiler.hh:80
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type ascii_load(std::istream &s, T &t)
Coefficient value
Definition: PIP_Tree.cc:618
static const Threshold & get()
Returns the current computational weight.
int32_t hash_code_from_dimension(dimension_type dim)
Returns the hash code for space dimension dim.
static Threshold weight
The current computational weight.
The entire library is confined to this namespace.
Definition: version.hh:61
Dense representation: the coefficient sequence is represented as a vector of coefficients, including the zero coefficients. If there are only a few nonzero coefficients, this representation is faster and also uses a bit less memory.
static void(* check_function)(void)
A pointer to the function that has to be called when checking the reaching of thresholds.
Sparse representation: only the nonzero coefficient are stored. If there are many nonzero coefficient...
static void from_delta(Threshold &threshold, const Delta &delta)
Sets threshold to be delta units bigger than the current weight.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Coefficient c
Definition: PIP_Tree.cc:64
const Throwable *volatile abandon_expensive_computations
A pointer to an exception object.
Definition: globals.cc:34
Enable_If< Is_Native< T >::value, memory_size_type >::type total_memory_in_bytes(const T &)
For native types, returns the total size in bytes of the memory occupied by the type of the (unused) ...
User objects the PPL can throw.
dimension_type least_significant_one_mask(dimension_type i)
static Delta compute_delta(unsigned long unscaled, unsigned scale)
Computes a Delta value from unscaled and scale.