1 /* Copyright (C) 2004-2020 Free Software Foundation, Inc.
2    Contributor: Joern Rennecke <joern.rennecke@embecosm.com>
3 		on behalf of Synopsys Inc.
4 
5 This file is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any
8 later version.
9 
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file.  (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
17 executable.)
18 
19 This file is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING3.  If not see
26 <http://www.gnu.org/licenses/>.  */
27 
28 /* Calculate division table for ARC700 integer division
29    Contributed by Joern Rennecke
30    joern.rennecke@arc.com  */
31 
32 #include <stdio.h>
33 #include <math.h>
34 
35 int
36 main ()
37 {
38   int i, j;
39   unsigned x;
40   double q, r, err, max_err = -1;
41 
42   puts("/* This table has been generated by divtab-arc700.c.  */");
43   puts("\
44 /* 1/512 .. 1/256, normalized.  There is a leading 1 in bit 31.\n\
45    For powers of two, we list unnormalized numbers instead.  The values\n\
46    for powers of 2 are loaded, but not used.  The value for 1 is actually\n\
47    the first instruction after .Lmuldiv.  */\n\
48 	.balign 4");
49   puts (".Ldivtab:\n");
50   for (i = 256; i >= 2; --i)
51     {
52       j = i < 0 ? -i : i;
53       if (j & (j-1))
54 	while (j < 128)
55 	  j += j;
56       else
57 	/* Power of two. */
58 	j *= 128;
59       q = 4.*(1<<30)*128/j;
60       r = ceil (q);
61       printf ("\t.long\t0x%X\n", (unsigned) r);
62       err = r - q;
63       if (err > max_err)
64 	max_err = err;
65     }
66 #if 0
67   printf ("\t/* maximum error: %f */\n", max_err);
68 #endif
69   exit (0);
70 }
71