blob: afdc89b7ab90746af4ce54af727caed4624531cd [file] [log] [blame]
/* Copyright (C) 2004-2019 Free Software Foundation, Inc.
Contributor: Joern Rennecke <>
on behalf of Synopsys Inc.
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING3. If not see
<>. */
/* Calculate division table for ARC700 integer division
Contributed by Joern Rennecke */
#include <stdio.h>
#include <math.h>
main ()
int i, j;
unsigned x;
double q, r, err, max_err = -1;
puts("/* This table has been generated by divtab-arc700.c. */");
/* 1/512 .. 1/256, normalized. There is a leading 1 in bit 31.\n\
For powers of two, we list unnormalized numbers instead. The values\n\
for powers of 2 are loaded, but not used. The value for 1 is actually\n\
the first instruction after .Lmuldiv. */\n\
.balign 4");
puts (".Ldivtab:\n");
for (i = 256; i >= 2; --i)
j = i < 0 ? -i : i;
if (j & (j-1))
while (j < 128)
j += j;
/* Power of two. */
j *= 128;
q = 4.*(1<<30)*128/j;
r = ceil (q);
printf ("\t.long\t0x%X\n", (unsigned) r);
err = r - q;
if (err > max_err)
max_err = err;
#if 0
printf ("\t/* maximum error: %f */\n", max_err);
exit (0);