2009-11-21 Robert Millan <rmh.grub@aybabtu.com>

* maintainance/gentrigtables.py: Remove.
        * lib/trig.c: Likewise.

        * gentrigtables.c: New file.  C rewrite of gentrigtables.py.

        * conf/common.rmk (trig_mod_SOURCES): Replace `lib/trig.c' with
        `trigtables.c'.
        (trigtables.c): New rule.
        (gentrigtables): Likewise.
        (DISTCLEANFILES): Add `trigtables.c' and `gentrigtables'.
This commit is contained in:
Robert Millan 2009-11-21 21:44:08 +00:00
parent f5b23252e2
commit d2be748185
5 changed files with 69 additions and 145 deletions

View file

@ -1,3 +1,16 @@
2009-11-21 Robert Millan <rmh.grub@aybabtu.com>
* maintainance/gentrigtables.py: Remove.
* lib/trig.c: Likewise.
* gentrigtables.c: New file. C rewrite of gentrigtables.py.
* conf/common.rmk (trig_mod_SOURCES): Replace `lib/trig.c' with
`trigtables.c'.
(trigtables.c): New rule.
(gentrigtables): Likewise.
(DISTCLEANFILES): Add `trigtables.c' and `gentrigtables'.
2009-11-21 Robert Millan <rmh.grub@aybabtu.com> 2009-11-21 Robert Millan <rmh.grub@aybabtu.com>
* maintainance/gentrigtables.py: Avoid duplicate hardcoding of * maintainance/gentrigtables.py: Avoid duplicate hardcoding of

View file

@ -660,12 +660,18 @@ xnu_uuid_mod_SOURCES = commands/xnu_uuid.c
xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS) xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For trig.mod.
pkglib_MODULES += trig.mod pkglib_MODULES += trig.mod
trig_mod_SOURCES = lib/trig.c trig_mod_SOURCES = trigtables.c
trig_mod_CFLAGS = $(COMMON_CFLAGS) trig_mod_CFLAGS = $(COMMON_CFLAGS)
trig_mod_LDFLAGS = $(COMMON_LDFLAGS) trig_mod_LDFLAGS = $(COMMON_LDFLAGS)
trigtables.c: gentrigtables
./gentrigtables > $@
DISTCLEANFILES += trigtables.c
gentrigtables: gentrigtables.c
$(CC) -o $@ $^ $(CPPFLAGS) -lm
DISTCLEANFILES += gentrigtables
pkglib_MODULES += setjmp.mod pkglib_MODULES += setjmp.mod
setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S
setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS)

48
gentrigtables.c Normal file
View file

@ -0,0 +1,48 @@
/* Generate trigonometric function tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
*
* GRUB 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 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE 1
#include <grub/trig.h>
#include <math.h>
#include <stdio.h>
int
main ()
{
int i;
printf ("#include <grub/types.h>\n");
#define TAB(op) \
printf ("grub_int16_t grub_trig_" #op "tab[] =\n{"); \
for (i = 0; i < GRUB_TRIG_ANGLE_MAX; i++) \
{ \
double x = i * 2 * M_PI / GRUB_TRIG_ANGLE_MAX; \
if (i % 10 == 0) \
printf ("\n "); \
printf ("%d,", (int) (round (op (x) * GRUB_TRIG_FRACTION_SCALE))); \
} \
printf ("\n};\n")
TAB(sin);
TAB(cos);
exit (0);
}

View file

@ -1,83 +0,0 @@
/* trig.c - Trigonometric table definitions. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc.
*
* GRUB 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 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/trig.h>
/* These tables were generated with `gentrigtables.py'. */
short grub_trig_sintab[] =
{
0,402,804,1205,1606,2006,2404,2801,3196,3590,
3981,4370,4756,5139,5520,5897,6270,6639,7005,7366,
7723,8076,8423,8765,9102,9434,9760,10080,10394,10702,
11003,11297,11585,11866,12140,12406,12665,12916,13160,13395,
13623,13842,14053,14256,14449,14635,14811,14978,15137,15286,
15426,15557,15679,15791,15893,15986,16069,16143,16207,16261,
16305,16340,16364,16379,16384,16379,16364,16340,16305,16261,
16207,16143,16069,15986,15893,15791,15679,15557,15426,15286,
15137,14978,14811,14635,14449,14256,14053,13842,13623,13395,
13160,12916,12665,12406,12140,11866,11585,11297,11003,10702,
10394,10080,9760,9434,9102,8765,8423,8076,7723,7366,
7005,6639,6270,5897,5520,5139,4756,4370,3981,3590,
3196,2801,2404,2006,1606,1205,804,402,0,-402,
-804,-1205,-1606,-2006,-2404,-2801,-3196,-3590,-3981,-4370,
-4756,-5139,-5520,-5897,-6270,-6639,-7005,-7366,-7723,-8076,
-8423,-8765,-9102,-9434,-9760,-10080,-10394,-10702,-11003,-11297,
-11585,-11866,-12140,-12406,-12665,-12916,-13160,-13395,-13623,-13842,
-14053,-14256,-14449,-14635,-14811,-14978,-15137,-15286,-15426,-15557,
-15679,-15791,-15893,-15986,-16069,-16143,-16207,-16261,-16305,-16340,
-16364,-16379,-16384,-16379,-16364,-16340,-16305,-16261,-16207,-16143,
-16069,-15986,-15893,-15791,-15679,-15557,-15426,-15286,-15137,-14978,
-14811,-14635,-14449,-14256,-14053,-13842,-13623,-13395,-13160,-12916,
-12665,-12406,-12140,-11866,-11585,-11297,-11003,-10702,-10394,-10080,
-9760,-9434,-9102,-8765,-8423,-8076,-7723,-7366,-7005,-6639,
-6270,-5897,-5520,-5139,-4756,-4370,-3981,-3590,-3196,-2801,
-2404,-2006,-1606,-1205,-804,-402
};
short grub_trig_costab[] =
{
16384,16379,16364,16340,16305,16261,16207,16143,16069,15986,
15893,15791,15679,15557,15426,15286,15137,14978,14811,14635,
14449,14256,14053,13842,13623,13395,13160,12916,12665,12406,
12140,11866,11585,11297,11003,10702,10394,10080,9760,9434,
9102,8765,8423,8076,7723,7366,7005,6639,6270,5897,
5520,5139,4756,4370,3981,3590,3196,2801,2404,2006,
1606,1205,804,402,0,-402,-804,-1205,-1606,-2006,
-2404,-2801,-3196,-3590,-3981,-4370,-4756,-5139,-5520,-5897,
-6270,-6639,-7005,-7366,-7723,-8076,-8423,-8765,-9102,-9434,
-9760,-10080,-10394,-10702,-11003,-11297,-11585,-11866,-12140,-12406,
-12665,-12916,-13160,-13395,-13623,-13842,-14053,-14256,-14449,-14635,
-14811,-14978,-15137,-15286,-15426,-15557,-15679,-15791,-15893,-15986,
-16069,-16143,-16207,-16261,-16305,-16340,-16364,-16379,-16384,-16379,
-16364,-16340,-16305,-16261,-16207,-16143,-16069,-15986,-15893,-15791,
-15679,-15557,-15426,-15286,-15137,-14978,-14811,-14635,-14449,-14256,
-14053,-13842,-13623,-13395,-13160,-12916,-12665,-12406,-12140,-11866,
-11585,-11297,-11003,-10702,-10394,-10080,-9760,-9434,-9102,-8765,
-8423,-8076,-7723,-7366,-7005,-6639,-6270,-5897,-5520,-5139,
-4756,-4370,-3981,-3590,-3196,-2801,-2404,-2006,-1606,-1205,
-804,-402,0,402,804,1205,1606,2006,2404,2801,
3196,3590,3981,4370,4756,5139,5520,5897,6270,6639,
7005,7366,7723,8076,8423,8765,9102,9434,9760,10080,
10394,10702,11003,11297,11585,11866,12140,12406,12665,12916,
13160,13395,13623,13842,14053,14256,14449,14635,14811,14978,
15137,15286,15426,15557,15679,15791,15893,15986,16069,16143,
16207,16261,16305,16340,16364,16379
};

View file

@ -1,60 +0,0 @@
#!/usr/bin/python
# Script to generate trigonometric function tables.
#
# GRUB -- GRand Unified Bootloader
# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
#
# GRUB 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 of the License, or
# (at your option) any later version.
#
# GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
from math import *
from sys import stdout
def write(x):
stdout.write(x)
def writeTable(arr, name):
indent = ' ' * 4
write("short ")
write(name)
write("[] =\n{\n")
write(indent)
for i in range(len(arr)):
if i != 0:
write(",")
if i % 10 == 0:
write("\n")
write(indent)
write("%d" % arr[i])
write("\n};\n")
def main():
sintab = []
costab = []
angle_max = 256
fraction_scale = 16384
for i in range(angle_max):
# Convert to an angle in 1/256 of a circle.
x = i * 2 * pi / angle_max
sintab.append(int(round(sin(x) * fraction_scale)))
costab.append(int(round(cos(x) * fraction_scale)))
write("#define TRIG_ANGLE_MAX " + str (angle_max) + "\n")
write("#define TRIG_FRACTION_SCALE " + str (fraction_scale) + "\n")
writeTable(sintab, "sintab")
writeTable(costab, "costab")
if __name__ == "__main__":
main()
# vim:ai et sw=4 ts=4