Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: tools/generate-trig-table.py

Issue 78873006: Embed trigonometric lookup table. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: tiny fixes Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/trig-table.h ('K') | « src/trig-table.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/generate-trig-table.py
diff --git a/test/intl/testcfg.py b/tools/generate-trig-table.py
similarity index 53%
copy from test/intl/testcfg.py
copy to tools/generate-trig-table.py
index 9fc087e5f523fc46eda2b3c94f9951c638447d10..14d4472aadb28ad5947f83a42b83edec568a12cf 100644
--- a/test/intl/testcfg.py
+++ b/tools/generate-trig-table.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+#
# Copyright 2013 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@@ -25,47 +27,58 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import os
+# This is a utility for populating the lookup table for the
+# approximation of trigonometric functions.
+
+import sys, math
+
+SAMPLES = 1800
-from testrunner.local import testsuite
-from testrunner.objects import testcase
+TEMPLATE = """\
+// Copyright 2013 Google Inc. All Rights Reserved.
+// This file was generated from a python script.
-class IntlTestSuite(testsuite.TestSuite):
+#include "v8.h"
+#include "trig-table.h"
- def __init__(self, name, root):
- super(IntlTestSuite, self).__init__(name, root)
+namespace v8 {
+namespace internal {
- def ListTests(self, context):
- tests = []
- for dirname, dirs, files in os.walk(self.root):
- for dotted in [x for x in dirs if x.startswith('.')]:
- dirs.remove(dotted)
- dirs.sort()
- files.sort()
- for filename in files:
- if (filename.endswith(".js") and filename != "assert.js" and
- filename != "utils.js"):
- testname = os.path.join(dirname[len(self.root) + 1:], filename[:-3])
- test = testcase.TestCase(self, testname)
- tests.append(test)
- return tests
+ const double TrigonometricLookupTable::kSinTable[] =
+ { %(sine_table)s };
+ const double TrigonometricLookupTable::kCosXIntervalTable[] =
+ { %(cosine_table)s };
+ const int TrigonometricLookupTable::kSamples = %(samples)i;
+ const int TrigonometricLookupTable::kTableSize = %(table_size)i;
+ const double TrigonometricLookupTable::kSamplesOverPiHalf =
+ %(samples_over_pi_half)s;
- def GetFlagsForTestCase(self, testcase, context):
- flags = ["--allow-natives-syntax"] + context.mode_flags
+} } // v8::internal
+"""
- files = []
- files.append(os.path.join(self.root, "assert.js"))
- files.append(os.path.join(self.root, "utils.js"))
- files.append(os.path.join(self.root, testcase.path + self.suffix()))
+def main():
+ pi_half = math.pi / 2
+ interval = pi_half / SAMPLES
+ sin = []
+ cos_times_interval = []
+ table_size = SAMPLES + 2
- flags += files
- if context.isolates:
- flags.append("--isolate")
- flags += files
+ for i in range(0, table_size):
+ sample = i * interval
+ sin.append(repr(math.sin(sample)))
+ cos_times_interval.append(repr(math.cos(sample) * interval))
- return testcase.flags + flags
+ output_file = sys.argv[1]
+ output = open(str(output_file), "w")
+ output.write(TEMPLATE % {
+ 'sine_table': ','.join(sin),
+ 'cosine_table': ','.join(cos_times_interval),
+ 'samples': SAMPLES,
+ 'table_size': table_size,
+ 'samples_over_pi_half': repr(SAMPLES / pi_half)
+ })
+if __name__ == "__main__":
+ main()
-def GetSuite(name, root):
- return IntlTestSuite(name, root)
« src/trig-table.h ('K') | « src/trig-table.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698