]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/sh/divtab-sh4.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / sh / divtab-sh4.c
CommitLineData
5624e564 1/* Copyright (C) 2004-2015 Free Software Foundation, Inc.
b368d6b8
R
2
3This file is free software; you can redistribute it and/or modify it
4under the terms of the GNU General Public License as published by the
748086b7 5Free Software Foundation; either version 3, or (at your option) any
b368d6b8
R
6later version.
7
b368d6b8
R
8This file is distributed in the hope that it will be useful, but
9WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11General Public License for more details.
12
748086b7
JJ
13Under Section 7 of GPL version 3, you are granted additional
14permissions described in the GCC Runtime Library Exception, version
153.1, as published by the Free Software Foundation.
16
17You should have received a copy of the GNU General Public License and
18a copy of the GCC Runtime Library Exception along with this program;
19see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
20<http://www.gnu.org/licenses/>. */
b368d6b8
R
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
29int
30main ()
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\
48LOCAL(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\
63LOCAL(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}