/* Multiply table generator for tile.
Copyright (C) 2011-2017 Free Software Foundation, Inc.
Contributed by Walter Lee (walt@tilera.com)
This file is part of GCC.
GCC 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.
GCC is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
. */
/* This program creates a table used to compile multiply by constant
efficiently.
This program should be compiled by a c++ compiler. If it's
compiled with -DTILEPRO, it generates the multiply table for
TILEPro; otherwise it generates the multiply table for TILE-Gx.
Running the program produces the table in stdout.
The program works by generating every possible combination of up to
MAX_INSTRUCTIONS linear operators (such as add, sub, s2a, left
shift) and computing the multiplier computed by those instructions.
For example,
s2a r2,r1,r1
s2a r3,r2,r2
multiplies r1 by 25.
There are usually multiple instruction sequences to multiply by a
given constant. This program keeps only the cheapest one.
"Cheapest" is defined first by the minimum theoretical schedule
length, and if those are equal then by the number of instructions,
and if those are equal then by which instructions we "prefer"
(e.g. because we think one might take infinitesimally less power
than another, or simply because we arbitrarily pick one to be more
canonical).
Once this program has determined the best instruction sequence for
each multiplier, it emits them in a table sorted by the multiplier
so the user can binary-search it to look for a match. The table is
pruned based on various criteria to keep its sizes reasonable. */
#include
#include
#include
#include
#define __STDC_LIMIT_MACROS
#include
#include