aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gcc/elna-builtins.cc33
1 files changed, 31 insertions, 2 deletions
diff --git a/gcc/gcc/elna-builtins.cc b/gcc/gcc/elna-builtins.cc
index 4a50967..fc43ebe 100644
--- a/gcc/gcc/elna-builtins.cc
+++ b/gcc/gcc/elna-builtins.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
#include "stor-layout.h"
#include "stringpool.h"
#include "varasm.h"
+#include "realmpfr.h"
#include "elna/boot/evaluator.h"
#include "elna/gcc/elna-tree.h"
@@ -36,6 +37,34 @@ namespace elna::gcc
};
}
+ static double real_to_double(const REAL_VALUE_TYPE& real)
+ {
+ mpfr_t number;
+ mpfr_init2(number, SIGNIFICAND_BITS);
+ mpfr_from_real(number, &real, MPFR_RNDN);
+ const double result = mpfr_get_d(number, MPFR_RNDN);
+ mpfr_clear(number);
+ return result;
+ }
+
+ template<typename T>
+ static boot::float_properties<T> get_host_float_properties(tree node)
+ {
+ REAL_VALUE_TYPE max_real;
+ real_maxval(&max_real, 0, TYPE_MODE(node));
+ const double max_val = real_to_double(max_real);
+
+ REAL_VALUE_TYPE min_real;
+ real_maxval(&min_real, 1, TYPE_MODE(node));
+ const double min_val = real_to_double(min_real);
+
+ return boot::float_properties<T>{
+ get_host_numeric_properties(node),
+ static_cast<T>(min_val),
+ static_cast<T>(max_val)
+ };
+ }
+
const boot::target_info& get_host_target()
{
static const boot::target_info info = boot::target_info{
@@ -55,8 +84,8 @@ namespace elna::gcc
},
.pointer_properties = get_host_numeric_properties(ptr_type_node),
.char_properties = get_host_numeric_properties(elna_char_type_node),
- .single_properties = get_host_numeric_properties(float_type_node),
- .double_properties = get_host_numeric_properties(double_type_node),
+ .single_properties = get_host_float_properties<float>(float_type_node),
+ .double_properties = get_host_float_properties<double>(double_type_node),
.bool_properties = {
.size = static_cast<std::size_t>(
(TYPE_PRECISION(elna_bool_type_node) + BITS_PER_UNIT - 1) / BITS_PER_UNIT),