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