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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [config/] [sh/] [divtab-sh4.c] - Blame information for rev 801

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

Line No. Rev Author Line
1 709 jeremybenn
/* Copyright (C) 2004, 2009 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 3, or (at your option) any
6
later version.
7
 
8
This file is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
General Public License for more details.
12
 
13
Under Section 7 of GPL version 3, you are granted additional
14
permissions described in the GCC Runtime Library Exception, version
15
3.1, as published by the Free Software Foundation.
16
 
17
You should have received a copy of the GNU General Public License and
18
a copy of the GCC Runtime Library Exception along with this program;
19
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
20
<http://www.gnu.org/licenses/>.  */
21
 
22
/* Calculate division table for SH2..4 integer division
23
   Contributed by Joern Rernnecke
24
   joern.rennecke@superh.com  */
25
 
26
#include <stdio.h>
27
#include <math.h>
28
 
29
int
30
main ()
31
{
32
  int i, j;
33
  double q, r, err, max_err = 0, max_s_err = 0;
34
 
35
  puts("/* This table has been generated by divtab-sh4.c.  */");
36
  puts ("\t.balign 4");
37
  puts ("LOCAL(div_table_clz):");
38
  /* output some dummy number for 1/0.  */
39
  printf ("\t.byte\t%d\n", 0);
40
  for (i = 1; i <= 128; i++)
41
    {
42
      int n = 0;
43
      if (i == 128)
44
        puts ("\
45
/* Lookup table translating positive divisor to index into table of\n\
46
   normalized inverse.  N.B. the '0' entry is also the last entry of the\n\
47
 previous table, and causes an unaligned access for division by zero.  */\n\
48
LOCAL(div_table_ix):");
49
      for (j = i; j <= 128; j += j)
50
        n++;
51
      printf ("\t.byte\t%d\n", n - 7);
52
    }
53
  for (i = 1; i <= 128; i++)
54
    {
55
      j = i < 0 ? -i : i;
56
      while (j < 128)
57
        j += j;
58
      printf ("\t.byte\t%d\n", j * 2 - 96*4);
59
    }
60
  puts("\
61
/* 1/64 .. 1/127, normalized.  There is an implicit leading 1 in bit 32.  */\n\
62
        .balign 4\n\
63
LOCAL(zero_l):");
64
  for (i = 64; i < 128; i++)
65
    {
66
      if (i == 96)
67
        puts ("LOCAL(div_table):");
68
      q = 4.*(1<<30)*128/i;
69
      r = ceil (q);
70
      /* The value for 64 is actually differently scaled that it would
71
         appear from this calculation.  The implicit part is %01, not 10.
72
         Still, since the value in the table is 0 either way, this
73
         doesn't matter here.  Still, the 1/64 entry is effectively a 1/128
74
         entry.  */
75
      printf ("\t.long\t0x%X\n", (unsigned) r);
76
      err = r - q;
77
      if (err > max_err)
78
        max_err = err;
79
      err = err * i / 128;
80
      if (err > max_s_err)
81
        max_s_err = err;
82
    }
83
  printf ("\t/* maximum error: %f scaled: %f*/\n", max_err, max_s_err);
84
  exit (0);
85
}

powered by: WebSVN 2.1.0

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