2006-03-23 J"orn Rennecke <joern.rennecke@st.com>
[official-gcc.git] / gcc / config / sh / divtab-sh4.c
blobe7de6c49a7411cfbb8fb83e54fa751e37e320a24
1 /* Copyright (C) 2004 Free Software Foundation, Inc.
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.
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.)
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.
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, 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. */
27 /* Calculate division table for SH2..4 integer division
28 Contributed by Joern Rernnecke
29 joern.rennecke@superh.com */
31 #include <stdio.h>
32 #include <math.h>
34 int
35 main ()
37 int i, j;
38 double q, r, err, max_err = 0, max_s_err = 0;
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++)
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);
58 for (i = 1; i <= 128; i++)
60 j = i < 0 ? -i : i;
61 while (j < 128)
62 j += j;
63 printf ("\t.byte\t%d\n", j * 2 - 96*4);
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++)
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;
88 printf ("\t/* maximum error: %f scaled: %f*/\n", max_err, max_s_err);
89 exit (0);