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> 2014-09-15 Jakub Jelinek <jakub@redhat.com>
* Make-lang.in (check_go_parallelize): Change to just an upper bound * Make-lang.in (check_go_parallelize): Change to just an upper bound
......
...@@ -247,7 +247,7 @@ class Gcc_backend : public Backend ...@@ -247,7 +247,7 @@ class Gcc_backend : public Backend
float_constant_expression(Btype* btype, mpfr_t val); float_constant_expression(Btype* btype, mpfr_t val);
Bexpression* Bexpression*
complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag); complex_constant_expression(Btype* btype, mpc_t val);
Bexpression* Bexpression*
string_constant_expression(const std::string& val); string_constant_expression(const std::string& val);
...@@ -1241,7 +1241,7 @@ Gcc_backend::float_constant_expression(Btype* btype, mpfr_t 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. // Return a typed real and imaginary value as a constant complex number.
Bexpression* 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 t = btype->get_tree();
tree ret; tree ret;
...@@ -1249,12 +1249,12 @@ Gcc_backend::complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag) ...@@ -1249,12 +1249,12 @@ Gcc_backend::complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag)
return this->error_expression(); return this->error_expression();
REAL_VALUE_TYPE r1; 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_VALUE_TYPE r2;
real_convert(&r2, TYPE_MODE(TREE_TYPE(t)), &r1); real_convert(&r2, TYPE_MODE(TREE_TYPE(t)), &r1);
REAL_VALUE_TYPE r3; 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_VALUE_TYPE r4;
real_convert(&r4, TYPE_MODE(TREE_TYPE(t)), &r3); real_convert(&r4, TYPE_MODE(TREE_TYPE(t)), &r3);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <gmp.h> #include <gmp.h>
#include <mpfr.h> #include <mpfr.h>
#include <mpc.h>
#include "operator.h" #include "operator.h"
...@@ -277,9 +278,9 @@ class Backend ...@@ -277,9 +278,9 @@ class Backend
virtual Bexpression* virtual Bexpression*
float_constant_expression(Btype* btype, mpfr_t val) = 0; 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* 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. // Return an expression for the string value VAL.
virtual Bexpression* virtual Bexpression*
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define GO_EXPRESSIONS_H #define GO_EXPRESSIONS_H
#include <mpfr.h> #include <mpfr.h>
#include <mpc.h>
#include "operator.h" #include "operator.h"
...@@ -52,6 +53,9 @@ class Label; ...@@ -52,6 +53,9 @@ class Label;
class Ast_dump_context; class Ast_dump_context;
class String_dump; 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. // The base class for all expressions.
class Expression class Expression
...@@ -237,7 +241,7 @@ class Expression ...@@ -237,7 +241,7 @@ class Expression
// Make a constant complex expression. TYPE should be NULL for an // Make a constant complex expression. TYPE should be NULL for an
// abstract type. // abstract type.
static Expression* 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. // Make a nil expression.
static Expression* static Expression*
...@@ -2585,7 +2589,7 @@ class Numeric_constant ...@@ -2585,7 +2589,7 @@ class Numeric_constant
// Set to a complex value. // Set to a complex value.
void void
set_complex(Type*, const mpfr_t, const mpfr_t); set_complex(Type*, const mpc_t);
// Classifiers. // Classifiers.
bool bool
...@@ -2617,7 +2621,7 @@ class Numeric_constant ...@@ -2617,7 +2621,7 @@ class Numeric_constant
get_float(mpfr_t*) const; get_float(mpfr_t*) const;
void void
get_complex(mpfr_t*, mpfr_t*) const; get_complex(mpc_t*) const;
// Codes returned by to_unsigned_long. // Codes returned by to_unsigned_long.
enum To_unsigned_long enum To_unsigned_long
...@@ -2653,7 +2657,7 @@ class Numeric_constant ...@@ -2653,7 +2657,7 @@ class Numeric_constant
// If the value can be expressed as a complex, return true and // If the value can be expressed as a complex, return true and
// initialize and set VR and VI. // initialize and set VR and VI.
bool bool
to_complex(mpfr_t* vr, mpfr_t* vi) const; to_complex(mpc_t* val) const;
// Get the type. // Get the type.
Type* Type*
...@@ -2709,11 +2713,7 @@ class Numeric_constant ...@@ -2709,11 +2713,7 @@ class Numeric_constant
// If NC_FLOAT. // If NC_FLOAT.
mpfr_t float_val; mpfr_t float_val;
// If NC_COMPLEX. // If NC_COMPLEX.
struct mpc_t complex_val;
{
mpfr_t real;
mpfr_t imag;
} complex_val;
} u_; } u_;
// The type if there is one. This will be NULL for an untyped // The type if there is one. This will be NULL for an untyped
// constant. // constant.
......
...@@ -2525,9 +2525,12 @@ Parse::operand(bool may_be_sink, bool* is_parenthesized) ...@@ -2525,9 +2525,12 @@ Parse::operand(bool may_be_sink, bool* is_parenthesized)
{ {
mpfr_t zero; mpfr_t zero;
mpfr_init_set_ui(zero, 0, GMP_RNDN); mpfr_init_set_ui(zero, 0, GMP_RNDN);
ret = Expression::make_complex(&zero, token->imaginary_value(), mpc_t val;
NULL, token->location()); mpc_init2(val, mpc_precision);
mpc_set_fr_fr(val, zero, *token->imaginary_value(), MPC_RNDNN);
mpfr_clear(zero); mpfr_clear(zero);
ret = Expression::make_complex(&val, NULL, token->location());
mpc_clear(val);
this->advance_token(); this->advance_token();
return ret; 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