OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [config/] [sh/] [divtab.c] - Diff between revs 282 and 338

Only display areas with differences | Details | Blame | View Log

Rev 282 Rev 338
/* Copyright (C) 2003, 2009 Free Software Foundation, Inc.
/* Copyright (C) 2003, 2009 Free Software Foundation, Inc.
 
 
This file is free software; you can redistribute it and/or modify it
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
Free Software Foundation; either version 3, or (at your option) any
later version.
later version.
 
 
This file is distributed in the hope that it will be useful, but
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
General Public License for more details.
 
 
Under Section 7 of GPL version 3, you are granted additional
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
3.1, as published by the Free Software Foundation.
 
 
You should have received a copy of the GNU General Public License and
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
 
 
/* Calculate division table for SH5Media integer division
/* Calculate division table for SH5Media integer division
   Contributed by Joern Rennecke
   Contributed by Joern Rennecke
   joern.rennecke@superh.com  */
   joern.rennecke@superh.com  */
 
 
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <math.h>
 
 
#define BITS 5
#define BITS 5
#define N_ENTRIES (1 << BITS)
#define N_ENTRIES (1 << BITS)
#define CUTOFF_BITS 20
#define CUTOFF_BITS 20
 
 
#define BIAS (-330)
#define BIAS (-330)
 
 
double max_defect = 0.;
double max_defect = 0.;
double max_defect_x;
double max_defect_x;
 
 
double min_defect = 1e9;
double min_defect = 1e9;
double min_defect_x;
double min_defect_x;
 
 
double max_defect2 = 0.;
double max_defect2 = 0.;
double max_defect2_x;
double max_defect2_x;
 
 
double min_defect2 = 0.;
double min_defect2 = 0.;
double min_defect2_x;
double min_defect2_x;
 
 
double min_defect3 = 01e9;
double min_defect3 = 01e9;
double min_defect3_x;
double min_defect3_x;
int min_defect3_val;
int min_defect3_val;
 
 
double max_defect3 = 0.;
double max_defect3 = 0.;
double max_defect3_x;
double max_defect3_x;
int max_defect3_val;
int max_defect3_val;
 
 
static double note_defect3 (int val, double d2, double y2d, double x)
static double note_defect3 (int val, double d2, double y2d, double x)
{
{
  int cutoff_val = val >> CUTOFF_BITS;
  int cutoff_val = val >> CUTOFF_BITS;
  double cutoff;
  double cutoff;
  double defect;
  double defect;
 
 
  if (val < 0)
  if (val < 0)
    cutoff_val++;
    cutoff_val++;
  cutoff = (cutoff_val * (1<<CUTOFF_BITS) - val) * y2d;
  cutoff = (cutoff_val * (1<<CUTOFF_BITS) - val) * y2d;
  defect = cutoff + val * d2;
  defect = cutoff + val * d2;
  if (val < 0)
  if (val < 0)
    defect = - defect;
    defect = - defect;
  if (defect > max_defect3)
  if (defect > max_defect3)
    {
    {
      max_defect3 = defect;
      max_defect3 = defect;
      max_defect3_x = x;
      max_defect3_x = x;
      max_defect3_val = val;
      max_defect3_val = val;
    }
    }
  if (defect < min_defect3)
  if (defect < min_defect3)
    {
    {
      min_defect3 = defect;
      min_defect3 = defect;
      min_defect3_x = x;
      min_defect3_x = x;
      min_defect3_val = val;
      min_defect3_val = val;
    }
    }
}
}
 
 
/* This function assumes 32-bit integers.  */
/* This function assumes 32-bit integers.  */
static double
static double
calc_defect (double x, int constant, int factor)
calc_defect (double x, int constant, int factor)
{
{
  double y0 = (constant - (int) floor ((x * factor * 64.))) / 16384.;
  double y0 = (constant - (int) floor ((x * factor * 64.))) / 16384.;
  double y1 = 2 * y0 -y0 * y0 * (x + BIAS / (1.*(1LL<<30)));
  double y1 = 2 * y0 -y0 * y0 * (x + BIAS / (1.*(1LL<<30)));
  double y2d0, y2d;
  double y2d0, y2d;
  int y2d1;
  int y2d1;
  double d, d2;
  double d, d2;
 
 
  y1 = floor (y1 * (1024 * 1024 * 1024)) / (1024 * 1024 * 1024);
  y1 = floor (y1 * (1024 * 1024 * 1024)) / (1024 * 1024 * 1024);
  d = y1 - 1 / x;
  d = y1 - 1 / x;
  if (d > max_defect)
  if (d > max_defect)
    {
    {
      max_defect = d;
      max_defect = d;
      max_defect_x = x;
      max_defect_x = x;
    }
    }
  if (d < min_defect)
  if (d < min_defect)
    {
    {
      min_defect = d;
      min_defect = d;
      min_defect_x = x;
      min_defect_x = x;
    }
    }
  y2d0 = floor (y1 * x * (1LL << 60-16));
  y2d0 = floor (y1 * x * (1LL << 60-16));
  y2d1 = (int) (long long) y2d0;
  y2d1 = (int) (long long) y2d0;
  y2d = - floor ((y1 - y0 / (1<<30-14)) * y2d1) / (1LL<<44);
  y2d = - floor ((y1 - y0 / (1<<30-14)) * y2d1) / (1LL<<44);
  d2 = y1 + y2d - 1/x;
  d2 = y1 + y2d - 1/x;
  if (d2 > max_defect2)
  if (d2 > max_defect2)
    {
    {
      max_defect2 = d2;
      max_defect2 = d2;
      max_defect2_x = x;
      max_defect2_x = x;
    }
    }
  if (d2 < min_defect2)
  if (d2 < min_defect2)
    {
    {
      min_defect2 = d2;
      min_defect2 = d2;
      min_defect2_x = x;
      min_defect2_x = x;
    }
    }
  /* zero times anything is trivially zero.  */
  /* zero times anything is trivially zero.  */
  note_defect3 ((1 << CUTOFF_BITS) - 1, d2, y2d, x);
  note_defect3 ((1 << CUTOFF_BITS) - 1, d2, y2d, x);
  note_defect3 (1 << CUTOFF_BITS, d2, y2d, x);
  note_defect3 (1 << CUTOFF_BITS, d2, y2d, x);
  note_defect3 ((1U << 31) - (1 << CUTOFF_BITS), d2, y2d, x);
  note_defect3 ((1U << 31) - (1 << CUTOFF_BITS), d2, y2d, x);
  note_defect3 ((1U << 31) - 1, d2, y2d, x);
  note_defect3 ((1U << 31) - 1, d2, y2d, x);
  note_defect3 (-1, d2, y2d, x);
  note_defect3 (-1, d2, y2d, x);
  note_defect3 (-(1 << CUTOFF_BITS), d2, y2d, x);
  note_defect3 (-(1 << CUTOFF_BITS), d2, y2d, x);
  note_defect3 ((1U << 31) - (1 << CUTOFF_BITS) + 1, d2, y2d, x);
  note_defect3 ((1U << 31) - (1 << CUTOFF_BITS) + 1, d2, y2d, x);
  note_defect3 (-(1U << 31), d2, y2d, x);
  note_defect3 (-(1U << 31), d2, y2d, x);
  return d;
  return d;
}
}
 
 
int
int
main ()
main ()
{
{
  int i;
  int i;
  unsigned char factors[N_ENTRIES];
  unsigned char factors[N_ENTRIES];
  short constants[N_ENTRIES];
  short constants[N_ENTRIES];
  int steps = N_ENTRIES / 2;
  int steps = N_ENTRIES / 2;
  double step = 1. / steps;
  double step = 1. / steps;
  double eps30 = 1. / (1024 * 1024 * 1024);
  double eps30 = 1. / (1024 * 1024 * 1024);
 
 
  for (i = 0; i < N_ENTRIES; i++)
  for (i = 0; i < N_ENTRIES; i++)
    {
    {
      double x_low = (i < steps ? 1. : -3.) + i * step;
      double x_low = (i < steps ? 1. : -3.) + i * step;
      double x_high = x_low + step - eps30;
      double x_high = x_low + step - eps30;
      double x_med;
      double x_med;
      int factor, constant;
      int factor, constant;
      double low_defect, med_defect, high_defect, max_defect;
      double low_defect, med_defect, high_defect, max_defect;
 
 
      factor = (1./x_low- 1./x_high) / step * 256. + 0.5;
      factor = (1./x_low- 1./x_high) / step * 256. + 0.5;
      if (factor == 256)
      if (factor == 256)
        factor = 255;
        factor = 255;
      factors[i] = factor;
      factors[i] = factor;
      /* Use minimum of error function for x_med.  */
      /* Use minimum of error function for x_med.  */
      x_med = sqrt (256./factor);
      x_med = sqrt (256./factor);
      if (x_low < 0)
      if (x_low < 0)
        x_med = - x_med;
        x_med = - x_med;
      low_defect = 1. / x_low + x_low * factor / 256.;
      low_defect = 1. / x_low + x_low * factor / 256.;
      high_defect = 1. / x_high + x_high * factor / 256.;
      high_defect = 1. / x_high + x_high * factor / 256.;
      med_defect = 1. / x_med + x_med * factor / 256.;
      med_defect = 1. / x_med + x_med * factor / 256.;
      max_defect
      max_defect
        = ((low_defect > high_defect) ^ (x_med < 0)) ? low_defect : high_defect;
        = ((low_defect > high_defect) ^ (x_med < 0)) ? low_defect : high_defect;
      constant = (med_defect + max_defect) * 0.5 * 16384. + 0.5;
      constant = (med_defect + max_defect) * 0.5 * 16384. + 0.5;
      if (constant < -32768 || constant > 32767)
      if (constant < -32768 || constant > 32767)
        abort ();
        abort ();
      constants[i] = constant;
      constants[i] = constant;
      calc_defect (x_low, constant, factor);
      calc_defect (x_low, constant, factor);
      calc_defect (x_med, constant, factor);
      calc_defect (x_med, constant, factor);
      calc_defect (x_high, constant, factor);
      calc_defect (x_high, constant, factor);
    }
    }
    printf ("/* This table has been generated by divtab.c .\n");
    printf ("/* This table has been generated by divtab.c .\n");
    printf ("Defects for bias %d:\n", BIAS);
    printf ("Defects for bias %d:\n", BIAS);
    printf ("   Max defect: %e at %e\n", max_defect, max_defect_x);
    printf ("   Max defect: %e at %e\n", max_defect, max_defect_x);
    printf ("   Min defect: %e at %e\n", min_defect, min_defect_x);
    printf ("   Min defect: %e at %e\n", min_defect, min_defect_x);
    printf ("   Max 2nd step defect: %e at %e\n", max_defect2, max_defect2_x);
    printf ("   Max 2nd step defect: %e at %e\n", max_defect2, max_defect2_x);
    printf ("   Min 2nd step defect: %e at %e\n", min_defect2, min_defect2_x);
    printf ("   Min 2nd step defect: %e at %e\n", min_defect2, min_defect2_x);
    printf ("   Max div defect: %e at %d:%e\n", max_defect3, max_defect3_val, max_defect3_x);
    printf ("   Max div defect: %e at %d:%e\n", max_defect3, max_defect3_val, max_defect3_x);
    printf ("   Min div defect: %e at %d:%e\n", min_defect3, min_defect3_val, min_defect3_x);
    printf ("   Min div defect: %e at %d:%e\n", min_defect3, min_defect3_val, min_defect3_x);
    printf ("   Defect at 1: %e\n",
    printf ("   Defect at 1: %e\n",
            calc_defect (1., constants[0], factors[0]));
            calc_defect (1., constants[0], factors[0]));
    printf ("   Defect at -2: %e */\n",
    printf ("   Defect at -2: %e */\n",
            calc_defect (-2., constants[steps], factors[steps]));
            calc_defect (-2., constants[steps], factors[steps]));
    printf ("\t.section\t.rodata\n");
    printf ("\t.section\t.rodata\n");
    printf ("\t.balign 2\n");
    printf ("\t.balign 2\n");
    printf ("/* negative division constants */\n");
    printf ("/* negative division constants */\n");
    for (i = steps; i < 2 * steps; i++)
    for (i = steps; i < 2 * steps; i++)
      printf ("\t.word\t%d\n", constants[i]);
      printf ("\t.word\t%d\n", constants[i]);
    printf ("/* negative division factors */\n");
    printf ("/* negative division factors */\n");
    for (i = steps; i < 2*steps; i++)
    for (i = steps; i < 2*steps; i++)
      printf ("\t.byte\t%d\n", factors[i]);
      printf ("\t.byte\t%d\n", factors[i]);
    printf ("\t.skip %d\n", steps);
    printf ("\t.skip %d\n", steps);
    printf ("\t.global  GLOBAL(div_table):\n");
    printf ("\t.global  GLOBAL(div_table):\n");
    printf ("GLOBAL(div_table):\n");
    printf ("GLOBAL(div_table):\n");
    printf ("\t.skip %d\n", steps);
    printf ("\t.skip %d\n", steps);
    printf ("/* positive division factors */\n");
    printf ("/* positive division factors */\n");
    for (i = 0; i < steps; i++)
    for (i = 0; i < steps; i++)
      printf ("\t.byte\t%d\n", factors[i]);
      printf ("\t.byte\t%d\n", factors[i]);
    printf ("/* positive division constants */\n");
    printf ("/* positive division constants */\n");
    for (i = 0; i < steps; i++)
    for (i = 0; i < steps; i++)
      printf ("\t.word\t%d\n", constants[i]);
      printf ("\t.word\t%d\n", constants[i]);
  exit (0);
  exit (0);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.