Example #1
0
static void
builtin_define_fixed_point_constants (const char *name_prefix,
				      const char *suffix,
				      tree type)
{
  char name[64], buf[256], *new_buf;
  int i, mod;

  sprintf (name, "__%s_FBIT__", name_prefix);
  builtin_define_with_int_value (name, TYPE_FBIT (type));

  sprintf (name, "__%s_IBIT__", name_prefix);
  builtin_define_with_int_value (name, TYPE_IBIT (type));

  /* If there is no suffix, defines are for fixed-point modes.
     We just return.  */
  if (strcmp (suffix, "") == 0)
    return;

  if (TYPE_UNSIGNED (type))
    {
      sprintf (name, "__%s_MIN__", name_prefix);
      sprintf (buf, "0.0%s", suffix);
      builtin_define_with_value (name, buf, 0);
    }
  else
    {
      sprintf (name, "__%s_MIN__", name_prefix);
      if (ALL_ACCUM_MODE_P (TYPE_MODE (type)))
	sprintf (buf, "(-0X1P%d%s-0X1P%d%s)", TYPE_IBIT (type) - 1, suffix,
		 TYPE_IBIT (type) - 1, suffix);
      else
	sprintf (buf, "(-0.5%s-0.5%s)", suffix, suffix);
      builtin_define_with_value (name, buf, 0);
    }

  sprintf (name, "__%s_MAX__", name_prefix);
  sprintf (buf, "0X");
  new_buf = buf + 2;
  mod = (TYPE_FBIT (type) + TYPE_IBIT (type)) % 4;
  if (mod)
    sprintf (new_buf++, "%x", (1 << mod) - 1);
  for (i = 0; i < (TYPE_FBIT (type) + TYPE_IBIT (type)) / 4; i++)
    sprintf (new_buf++, "F");
  sprintf (new_buf, "P-%d%s", TYPE_FBIT (type), suffix);
  builtin_define_with_value (name, buf, 0);

  sprintf (name, "__%s_EPSILON__", name_prefix);
  sprintf (buf, "0x1P-%d%s", TYPE_FBIT (type), suffix);
  builtin_define_with_value (name, buf, 0);
}
Example #2
0
void
fixed_from_string (FIXED_VALUE_TYPE *f, const char *str, machine_mode mode)
{
  REAL_VALUE_TYPE real_value, fixed_value, base_value;
  unsigned int fbit;
  enum fixed_value_range_code temp;
  bool fail;

  f->mode = mode;
  fbit = GET_MODE_FBIT (mode);

  real_from_string (&real_value, str);
  temp = check_real_for_fixed_mode (&real_value, f->mode);
  /* We don't want to warn the case when the _Fract value is 1.0.  */
  if (temp == FIXED_UNDERFLOW
      || temp == FIXED_GT_MAX_EPS
      || (temp == FIXED_MAX_EPS && ALL_ACCUM_MODE_P (f->mode)))
    warning (OPT_Woverflow,
	     "large fixed-point constant implicitly truncated to fixed-point type");
  real_2expN (&base_value, fbit, VOIDmode);
  real_arithmetic (&fixed_value, MULT_EXPR, &real_value, &base_value);
  wide_int w = real_to_integer (&fixed_value, &fail,
				GET_MODE_PRECISION (mode));
  f->data.low = w.ulow ();
  f->data.high = w.elt (1);

  if (temp == FIXED_MAX_EPS && ALL_FRACT_MODE_P (f->mode))
    {
      /* From the spec, we need to evaluate 1 to the maximal value.  */
      f->data.low = -1;
      f->data.high = -1;
      f->data = f->data.zext (GET_MODE_FBIT (f->mode)
				+ GET_MODE_IBIT (f->mode));
    }
  else
    f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
			      + GET_MODE_FBIT (f->mode)
			      + GET_MODE_IBIT (f->mode),
			      UNSIGNED_FIXED_POINT_MODE_P (f->mode));
}