Boost logo

Boost Users :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2005-07-22 03:41:31

Guillaume Melquiond wrote:

> I unfortunately never had access to an Alpha computer, so I didn't get
> to write the rounding routines for this processor (EV6.8 is a 21264,
> right?).
> If you want to add support for it, you could first try to create a new
> rounding detail file. It would be almost identical to
> boost/numeric/interval/detail/ppc_rounding_control.hpp. It has to be
> referenced from the file boost/numeric/interval/hw_rounding.hpp. This is
> only a matter of adding a few preprocessor directives.
> In this new file, the asm instructions mtfsf and mfss of the PowerPC
> have to be replaced by accesses (mf_fcpr and mt_fcpr?) to the fpcr
> register of the Alpha processor. The rounding mode constants also have
> to be changed accordingly. This is the stage that requires to know a bit
> about the processor internals.
> Then your programs would probably have to be compiled with these GCC
> options in order for these changes to have effect:
> -mieee -mfp-rounding-mode=d -mfloat-ieee
> The tests are in libs/numeric/interval/test.

Attached is a first stab at this I did ages ago. It is a good starting
point, but unfortunately not all tests pass, mainly because of issues with
sqrt, IIRC. I had some mail exchange with HP about this but I can't
remember the details right now. I seem to remember that sqrt doesn't have
to adhere to the dynamic rounding modes, and maybe the tests are wrong in
this area, but I'm not really sure.

I will be away for a week, but upon return I will be available to perhaps
create real support for interval on alpha.

Note that for the rounding mode to have any effect, you need to use special
compiler (and linker) options, -ieee -fprmd should be enough for cxx, IIRC.

HTH, Markus

/* Boost interval/detail/alpha_rounding_control.hpp file
 * Copyright 2005 Markus Schöpflin
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or
 * copy at
 * The basic code in this file was kindly provided by Jeremy Siek.


#if !defined(__alpha)
# error This header is only intended for ALPHA CPUs.

#include <float.h> // write_rnd() and read_rnd()

namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {

struct alpha_rounding_control
  typedef unsigned int rounding_mode;

  static void set_rounding_mode(const rounding_mode& mode)

  static void get_rounding_mode(rounding_mode& mode)
    mode = read_rnd();

  static void downward() { set_rounding_mode(FP_RND_RM); }
  static void upward() { set_rounding_mode(FP_RND_RP); }
  static void to_nearest() { set_rounding_mode(FP_RND_RN); }
  static void toward_zero() { set_rounding_mode(FP_RND_RZ); }

} // namespace detail

extern "C" {
  float rintf(float);
  double rint(double);
  long double rintl(long double);

// NOTE: I'm not sure if this is enough to force rounding.

struct rounding_control<float>:
  static const float force_rounding(const float& x) {
    float x_ = x; return x_; }
  static float to_int(const float& x) { return rintf(x); }

struct rounding_control<double>:
  static const double force_rounding(const double& x) {
    double x_ = x; return x_; }
  static double to_int(const double& x) { return rint(x); }

struct rounding_control<long double>:
  static const long double force_rounding(const long double& x) {
    long double x_ = x; return x_; }
  static long double to_int(const long double& x) { return rintl(x); }

} // namespace interval_lib
} // namespace numeric
} // namespace boost



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at