1*b1e83836Smrg /* Copyright (C) 2004-2022 Free Software Foundation, Inc.
24d5abbe8Smrg Contributor: Joern Rennecke <joern.rennecke@embecosm.com>
34d5abbe8Smrg on behalf of Synopsys Inc.
44d5abbe8Smrg
54d5abbe8Smrg This file is free software; you can redistribute it and/or modify it
64d5abbe8Smrg under the terms of the GNU General Public License as published by the
74d5abbe8Smrg Free Software Foundation; either version 3, or (at your option) any
84d5abbe8Smrg later version.
94d5abbe8Smrg
104d5abbe8Smrg In addition to the permissions in the GNU General Public License, the
114d5abbe8Smrg Free Software Foundation gives you unlimited permission to link the
124d5abbe8Smrg compiled version of this file into combinations with other programs,
134d5abbe8Smrg and to distribute those combinations without any restriction coming
144d5abbe8Smrg from the use of this file. (The General Public License restrictions
154d5abbe8Smrg do apply in other respects; for example, they cover modification of
164d5abbe8Smrg the file, and distribution when not linked into a combine
174d5abbe8Smrg executable.)
184d5abbe8Smrg
194d5abbe8Smrg This file is distributed in the hope that it will be useful, but
204d5abbe8Smrg WITHOUT ANY WARRANTY; without even the implied warranty of
214d5abbe8Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
224d5abbe8Smrg General Public License for more details.
234d5abbe8Smrg
244d5abbe8Smrg You should have received a copy of the GNU General Public License
254d5abbe8Smrg along with this program; see the file COPYING3. If not see
264d5abbe8Smrg <http://www.gnu.org/licenses/>. */
274d5abbe8Smrg
284d5abbe8Smrg /* Calculate division table for ARC700 integer division
294d5abbe8Smrg Contributed by Joern Rennecke
304d5abbe8Smrg joern.rennecke@arc.com */
314d5abbe8Smrg
324d5abbe8Smrg #include <stdio.h>
334d5abbe8Smrg #include <math.h>
344d5abbe8Smrg
354d5abbe8Smrg int
main()364d5abbe8Smrg main ()
374d5abbe8Smrg {
384d5abbe8Smrg int i, j;
394d5abbe8Smrg unsigned x;
404d5abbe8Smrg double q, r, err, max_err = -1;
414d5abbe8Smrg
424d5abbe8Smrg puts("/* This table has been generated by divtab-arc700.c. */");
434d5abbe8Smrg puts("\
444d5abbe8Smrg /* 1/512 .. 1/256, normalized. There is a leading 1 in bit 31.\n\
454d5abbe8Smrg For powers of two, we list unnormalized numbers instead. The values\n\
464d5abbe8Smrg for powers of 2 are loaded, but not used. The value for 1 is actually\n\
474d5abbe8Smrg the first instruction after .Lmuldiv. */\n\
484d5abbe8Smrg .balign 4");
494d5abbe8Smrg puts (".Ldivtab:\n");
504d5abbe8Smrg for (i = 256; i >= 2; --i)
514d5abbe8Smrg {
524d5abbe8Smrg j = i < 0 ? -i : i;
534d5abbe8Smrg if (j & (j-1))
544d5abbe8Smrg while (j < 128)
554d5abbe8Smrg j += j;
564d5abbe8Smrg else
574d5abbe8Smrg /* Power of two. */
584d5abbe8Smrg j *= 128;
594d5abbe8Smrg q = 4.*(1<<30)*128/j;
604d5abbe8Smrg r = ceil (q);
614d5abbe8Smrg printf ("\t.long\t0x%X\n", (unsigned) r);
624d5abbe8Smrg err = r - q;
634d5abbe8Smrg if (err > max_err)
644d5abbe8Smrg max_err = err;
654d5abbe8Smrg }
664d5abbe8Smrg #if 0
674d5abbe8Smrg printf ("\t/* maximum error: %f */\n", max_err);
684d5abbe8Smrg #endif
694d5abbe8Smrg exit (0);
704d5abbe8Smrg }
71