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

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

Issue 448633002: Revert "Implement trigonometric functions using a fdlibm port." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months 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
« no previous file with comments | « tools/generate-runtime-tests.py ('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/tools/concatenate-files.py b/tools/generate-trig-table.py
similarity index 53%
copy from tools/concatenate-files.py
copy to tools/generate-trig-table.py
index 86bdf5638366ad5ee681ae2e4ab89499e4ebe18e..0a4fe2861831cce741874d4379cac5f854ee817b 100644
--- a/tools/concatenate-files.py
+++ b/tools/generate-trig-table.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2014 the V8 project authors. All rights reserved.
+# 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
# met:
@@ -27,49 +27,57 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-# This utility concatenates several files into one. On Unix-like systems
-# it is equivalent to:
-# cat file1 file2 file3 ...files... > target
-#
-# The reason for writing a seperate utility is that 'cat' is not available
-# on all supported build platforms, but Python is, and hence this provides
-# us with an easy and uniform way of doing this on all platforms.
+# This is a utility for populating the lookup table for the
+# approximation of trigonometric functions.
+
+import sys, math
-import optparse
+SAMPLES = 1800
+TEMPLATE = """\
+// Copyright 2013 Google Inc. All Rights Reserved.
-def Concatenate(filenames):
- """Concatenate files.
+// This file was generated from a python script.
- Args:
- files: Array of file names.
- The last name is the target; all earlier ones are sources.
+#include "src/v8.h"
+#include "src/trig-table.h"
- Returns:
- True, if the operation was successful.
- """
- if len(filenames) < 2:
- print "An error occured generating %s:\nNothing to do." % filenames[-1]
- return False
+namespace v8 {
+namespace internal {
- try:
- with open(filenames[-1], "wb") as target:
- for filename in filenames[:-1]:
- with open(filename, "rb") as current:
- target.write(current.read())
- return True
- except IOError as e:
- print "An error occured when writing %s:\n%s" % (filenames[-1], e)
- return False
+ 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;
+} } // v8::internal
+"""
def main():
- parser = optparse.OptionParser()
- parser.set_usage("""Concatenate several files into one.
- Equivalent to: cat file1 ... > target.""")
- (options, args) = parser.parse_args()
- exit(0 if Concatenate(args) else 1)
+ pi_half = math.pi / 2
+ interval = pi_half / SAMPLES
+ sin = []
+ cos_times_interval = []
+ table_size = SAMPLES + 2
+
+ 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))
+ 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()
« no previous file with comments | « tools/generate-runtime-tests.py ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698