Commit 5eda5bad by Ian Lance Taylor Committed by Ian Lance Taylor

compiler: Use MPC library for complex numbers.

	* go-gcc.cc (Gcc_backend::complex_constant_expression): Take one
	mpc_t parameter instead of two mpfr_t parameters.

From-SVN: r216611
parent 3c765286
2014-10-23 Ian Lance Taylor <iant@google.com>
* go-gcc.cc (Gcc_backend::complex_constant_expression): Take one
mpc_t parameter instead of two mpfr_t parameters.
2014-09-15 Jakub Jelinek <jakub@redhat.com>
* Make-lang.in (check_go_parallelize): Change to just an upper bound
......
......@@ -247,7 +247,7 @@ class Gcc_backend : public Backend
float_constant_expression(Btype* btype, mpfr_t val);
Bexpression*
complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag);
complex_constant_expression(Btype* btype, mpc_t val);
Bexpression*
string_constant_expression(const std::string& val);
......@@ -1241,7 +1241,7 @@ Gcc_backend::float_constant_expression(Btype* btype, mpfr_t val)
// Return a typed real and imaginary value as a constant complex number.
Bexpression*
Gcc_backend::complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag)
Gcc_backend::complex_constant_expression(Btype* btype, mpc_t val)
{
tree t = btype->get_tree();
tree ret;
......@@ -1249,12 +1249,12 @@ Gcc_backend::complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag)
return this->error_expression();
REAL_VALUE_TYPE r1;
real_from_mpfr(&r1, real, TREE_TYPE(t), GMP_RNDN);
real_from_mpfr(&r1, mpc_realref(val), TREE_TYPE(t), GMP_RNDN);
REAL_VALUE_TYPE r2;
real_convert(&r2, TYPE_MODE(TREE_TYPE(t)), &r1);
REAL_VALUE_TYPE r3;
real_from_mpfr(&r3, imag, TREE_TYPE(t), GMP_RNDN);
real_from_mpfr(&r3, mpc_imagref(val), TREE_TYPE(t), GMP_RNDN);
REAL_VALUE_TYPE r4;
real_convert(&r4, TYPE_MODE(TREE_TYPE(t)), &r3);
......
......@@ -9,6 +9,7 @@
#include <gmp.h>
#include <mpfr.h>
#include <mpc.h>
#include "operator.h"
......@@ -277,9 +278,9 @@ class Backend
virtual Bexpression*
float_constant_expression(Btype* btype, mpfr_t val) = 0;
// Return an expression for the complex value REAL/IMAG in BTYPE.
// Return an expression for the complex value VAL in BTYPE.
virtual Bexpression*
complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag) = 0;
complex_constant_expression(Btype* btype, mpc_t val) = 0;
// Return an expression for the string value VAL.
virtual Bexpression*
......
......@@ -8,6 +8,7 @@
#define GO_EXPRESSIONS_H
#include <mpfr.h>
#include <mpc.h>
#include "operator.h"
......@@ -52,6 +53,9 @@ class Label;
class Ast_dump_context;
class String_dump;
// The precision to use for complex values represented as an mpc_t.
const int mpc_precision = 256;
// The base class for all expressions.
class Expression
......@@ -237,7 +241,7 @@ class Expression
// Make a constant complex expression. TYPE should be NULL for an
// abstract type.
static Expression*
make_complex(const mpfr_t* real, const mpfr_t* imag, Type*, Location);
make_complex(const mpc_t*, Type*, Location);
// Make a nil expression.
static Expression*
......@@ -2585,7 +2589,7 @@ class Numeric_constant
// Set to a complex value.
void
set_complex(Type*, const mpfr_t, const mpfr_t);
set_complex(Type*, const mpc_t);
// Classifiers.
bool
......@@ -2617,7 +2621,7 @@ class Numeric_constant
get_float(mpfr_t*) const;
void
get_complex(mpfr_t*, mpfr_t*) const;
get_complex(mpc_t*) const;
// Codes returned by to_unsigned_long.
enum To_unsigned_long
......@@ -2653,7 +2657,7 @@ class Numeric_constant
// If the value can be expressed as a complex, return true and
// initialize and set VR and VI.
bool
to_complex(mpfr_t* vr, mpfr_t* vi) const;
to_complex(mpc_t* val) const;
// Get the type.
Type*
......@@ -2709,11 +2713,7 @@ class Numeric_constant
// If NC_FLOAT.
mpfr_t float_val;
// If NC_COMPLEX.
struct
{
mpfr_t real;
mpfr_t imag;
} complex_val;
mpc_t complex_val;
} u_;
// The type if there is one. This will be NULL for an untyped
// constant.
......
......@@ -2525,9 +2525,12 @@ Parse::operand(bool may_be_sink, bool* is_parenthesized)
{
mpfr_t zero;
mpfr_init_set_ui(zero, 0, GMP_RNDN);
ret = Expression::make_complex(&zero, token->imaginary_value(),
NULL, token->location());
mpc_t val;
mpc_init2(val, mpc_precision);
mpc_set_fr_fr(val, zero, *token->imaginary_value(), MPC_RNDNN);
mpfr_clear(zero);
ret = Expression::make_complex(&val, NULL, token->location());
mpc_clear(val);
this->advance_token();
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment