1 /* Copyright (C) 2004-2018 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 3, or (at your option) any
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.
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.
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/>. */
22 /* Calculate division table for SH2..4 integer division
23 Contributed by Joern Rernnecke
24 joern.rennecke@superh.com */
33 double q
, r
, err
, max_err
= 0, max_s_err
= 0;
35 puts("/* This table has been generated by divtab-sh4.c. */");
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
++)
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
)
51 printf ("\t.byte\t%d\n", n
- 7);
53 for (i
= 1; i
<= 128; i
++)
58 printf ("\t.byte\t%d\n", j
* 2 - 96*4);
61 /* 1/64 .. 1/127, normalized. There is an implicit leading 1 in bit 32. */\n\
64 for (i
= 64; i
< 128; i
++)
67 puts ("LOCAL(div_table):");
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
75 printf ("\t.long\t0x%X\n", (unsigned) r
);
83 printf ("\t/* maximum error: %f scaled: %f*/\n", max_err
, max_s_err
);