2009-11-14 Colin D Bennet <colin@gibibit.com>
Trigonometry support. * include/grub/trig.h: New file. * lib/trig.c: Likewise. * maintainance/gentrigtables.py: Likewise. * conf/common.rmk (pkglib_MODULES): Add trig.mod. (trig_mod_SOURCES): New variable. (trig_mod_CFLAGS): Likewise. (trig_mod_LDFLAGS): Likewise.
This commit is contained in:
parent
bd86691a07
commit
85536ab717
4 changed files with 191 additions and 0 deletions
|
@ -638,6 +638,12 @@ xnu_uuid_mod_SOURCES = commands/xnu_uuid.c
|
|||
xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
|
||||
# For trig.mod.
|
||||
pkglib_MODULES += trig.mod
|
||||
trig_mod_SOURCES = lib/trig.c
|
||||
trig_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
trig_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
|
||||
pkglib_MODULES += setjmp.mod
|
||||
setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S
|
||||
setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||
|
|
44
include/grub/trig.h
Normal file
44
include/grub/trig.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* trig.h - Trigonometric function support. */
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_TRIG_HEADER
|
||||
#define GRUB_TRIG_HEADER 1
|
||||
|
||||
#define GRUB_TRIG_ANGLE_MAX 256
|
||||
#define GRUB_TRIG_ANGLE_MASK 255
|
||||
#define GRUB_TRIG_FRACTION_SCALE 16384
|
||||
|
||||
extern short grub_trig_sintab[];
|
||||
extern short grub_trig_costab[];
|
||||
|
||||
static __inline int
|
||||
grub_sin (int x)
|
||||
{
|
||||
x &= GRUB_TRIG_ANGLE_MASK;
|
||||
return grub_trig_sintab[x];
|
||||
}
|
||||
|
||||
static __inline int
|
||||
grub_cos (int x)
|
||||
{
|
||||
x &= GRUB_TRIG_ANGLE_MASK;
|
||||
return grub_trig_costab[x];
|
||||
}
|
||||
|
||||
#endif /* ! GRUB_TRIG_HEADER */
|
83
lib/trig.c
Normal file
83
lib/trig.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* 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
|
||||
};
|
||||
|
58
maintainance/gentrigtables.py
Normal file
58
maintainance/gentrigtables.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/python
|
||||
# Script to generate trigonometric function tables.
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
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 = []
|
||||
for i in range(256):
|
||||
# Convert to an angle in 1/256 of a circle.
|
||||
x = i * 2 * pi / 256
|
||||
sintab.append(int(round(sin(x) * 16384)))
|
||||
costab.append(int(round(cos(x) * 16384)))
|
||||
|
||||
write("#define TRIG_ANGLE_MAX 256\n")
|
||||
write("#define TRIG_FRACTION_SCALE 16384\n")
|
||||
writeTable(sintab, "sintab")
|
||||
writeTable(costab, "costab")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# vim:ai et sw=4 ts=4
|
Loading…
Reference in a new issue