| 1 |
/* Copyright (C) 2004-2025 Free Software Foundation, Inc. |
| 2 |
|
| 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 |
| 6 |
later version. |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 16 |
|
| 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/>. */ |
| 21 |
|
| 22 |
|
| 23 |
/* Calculate division table for ST40-300 integer division |
| 24 |
Contributed by Joern Rennecke |
| 25 |
[email protected] */ |
| 26 |
|
| 27 |
#include <stdio.h> |
| 28 |
#include <math.h> |
| 29 |
|
| 30 |
int |
| 31 |
main () |
| 32 |
{ |
| 33 |
int i, j; |
| 34 |
double q, r, err, max_err = 0, max_s_err = 0; |
| 35 |
|
| 36 |
puts("/* This table has been generated by divtab-sh4.cc. */"); |
| 37 |
puts ("\t.balign 4"); |
| 38 |
for (i = -128; i < 128; i++) |
| 39 |
{ |
| 40 |
int n = 0; |
| 41 |
if (i == 0) |
| 42 |
{ |
| 43 |
/* output some dummy number for 1/0. */ |
| 44 |
puts ("LOCAL(div_table_clz):\n\t.byte\t0"); |
| 45 |
continue; |
| 46 |
} |
| 47 |
for (j = i < 0 ? -i : i; j < 128; j += j) |
| 48 |
n++; |
| 49 |
printf ("\t.byte\t%d\n", n - 7); |
| 50 |
} |
| 51 |
puts("\ |
| 52 |
/* 1/-128 .. 1/127, normalized. There is an implicit leading 1 in bit 32,\n\ |
| 53 |
or in bit 33 for powers of two. */\n\ |
| 54 |
.balign 4"); |
| 55 |
for (i = -128; i < 128; i++) |
| 56 |
{ |
| 57 |
if (i == 0) |
| 58 |
{ |
| 59 |
puts ("LOCAL(div_table_inv):\n\t.long\t0x0"); |
| 60 |
continue; |
| 61 |
} |
| 62 |
j = i < 0 ? -i : i; |
| 63 |
while (j < 64) |
| 64 |
j += j; |
| 65 |
q = 4.*(1<<30)*128/j; |
| 66 |
r = ceil (q); |
| 67 |
printf ("\t.long\t0x%X\n", (unsigned) r); |
| 68 |
err = r - q; |
| 69 |
if (err > max_err) |
| 70 |
max_err = err; |
| 71 |
err = err * j / 128; |
| 72 |
if (err > max_s_err) |
| 73 |
max_s_err = err; |
| 74 |
} |
| 75 |
printf ("\t/* maximum error: %f scaled: %f*/\n", max_err, max_s_err); |
| 76 |
exit (0); |
| 77 |
} |