OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [config/] [sh/] [divtab-sh4.c] - Blame information for rev 853

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Copyright (C) 2004 Free Software Foundation, Inc.
2
 
3
This file is free software; you can redistribute it and/or modify it
4
under the terms of the GNU General Public License as published by the
5
Free Software Foundation; either version 2, or (at your option) any
6
later version.
7
 
8
In addition to the permissions in the GNU General Public License, the
9
Free Software Foundation gives you unlimited permission to link the
10
compiled version of this file into combinations with other programs,
11
and to distribute those combinations without any restriction coming
12
from the use of this file.  (The General Public License restrictions
13
do apply in other respects; for example, they cover modification of
14
the file, and distribution when not linked into a combine
15
executable.)
16
 
17
This file is distributed in the hope that it will be useful, but
18
WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
General Public License for more details.
21
 
22
You should have received a copy of the GNU General Public License
23
along with this program; see the file COPYING.  If not, write to
24
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
25
Boston, MA 02110-1301, USA.  */
26
 
27
/* Calculate division table for SH2..4 integer division
28
   Contributed by Joern Rernnecke
29
   joern.rennecke@superh.com  */
30
 
31
#include <stdio.h>
32
#include <math.h>
33
 
34
int
35
main ()
36
{
37
  int i, j;
38
  double q, r, err, max_err = 0, max_s_err = 0;
39
 
40
  puts("/* This table has been generated by divtab-sh4.c.  */");
41
  puts ("\t.balign 4");
42
  puts ("LOCAL(div_table_clz):");
43
  /* output some dummy number for 1/0.  */
44
  printf ("\t.byte\t%d\n", 0);
45
  for (i = 1; i <= 128; i++)
46
    {
47
      int n = 0;
48
      if (i == 128)
49
        puts ("\
50
/* Lookup table translating positive divisor to index into table of\n\
51
   normalized inverse.  N.B. the '0' entry is also the last entry of the\n\
52
 previous table, and causes an unaligned access for division by zero.  */\n\
53
LOCAL(div_table_ix):");
54
      for (j = i; j <= 128; j += j)
55
        n++;
56
      printf ("\t.byte\t%d\n", n - 7);
57
    }
58
  for (i = 1; i <= 128; i++)
59
    {
60
      j = i < 0 ? -i : i;
61
      while (j < 128)
62
        j += j;
63
      printf ("\t.byte\t%d\n", j * 2 - 96*4);
64
    }
65
  puts("\
66
/* 1/64 .. 1/127, normalized.  There is an implicit leading 1 in bit 32.  */\n\
67
        .balign 4\n\
68
LOCAL(zero_l):");
69
  for (i = 64; i < 128; i++)
70
    {
71
      if (i == 96)
72
        puts ("LOCAL(div_table):");
73
      q = 4.*(1<<30)*128/i;
74
      r = ceil (q);
75
      /* The value for 64 is actually differently scaled that it would
76
         appear from this calculation.  The implicit part is %01, not 10.
77
         Still, since the value in the table is 0 either way, this
78
         doesn't matter here.  Still, the 1/64 entry is effectively a 1/128
79
         entry.  */
80
      printf ("\t.long\t0x%X\n", (unsigned) r);
81
      err = r - q;
82
      if (err > max_err)
83
        max_err = err;
84
      err = err * i / 128;
85
      if (err > max_s_err)
86
        max_s_err = err;
87
    }
88
  printf ("\t/* maximum error: %f scaled: %f*/\n", max_err, max_s_err);
89
  exit (0);
90
}

powered by: WebSVN 2.1.0

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