| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 static void Clear(); | 1992 static void Clear(); |
| 1993 | 1993 |
| 1994 private: | 1994 private: |
| 1995 MUST_USE_RESULT inline MaybeObject* Get(double input) { | 1995 MUST_USE_RESULT inline MaybeObject* Get(double input) { |
| 1996 Converter c; | 1996 Converter c; |
| 1997 c.dbl = input; | 1997 c.dbl = input; |
| 1998 int hash = Hash(c); | 1998 int hash = Hash(c); |
| 1999 Element e = elements_[hash]; | 1999 Element e = elements_[hash]; |
| 2000 if (e.in[0] == c.integers[0] && | 2000 if (e.in[0] == c.integers[0] && |
| 2001 e.in[1] == c.integers[1]) { | 2001 e.in[1] == c.integers[1]) { |
| 2002 ASSERT(e.output != NULL); | 2002 if (e.output != NULL) { |
| 2003 Counters::transcendental_cache_hit.Increment(); | 2003 Counters::transcendental_cache_hit.Increment(); |
| 2004 return e.output; | 2004 return e.output; |
| 2005 } else { |
| 2006 Object* heap_number; |
| 2007 { MaybeObject* maybe_heap_number = |
| 2008 Heap::AllocateHeapNumber(e.untagged_output); |
| 2009 if (!maybe_heap_number->ToObject(&heap_number)) |
| 2010 return maybe_heap_number; |
| 2011 } |
| 2012 elements_[hash].output = heap_number; |
| 2013 return heap_number; |
| 2014 } |
| 2005 } | 2015 } |
| 2006 double answer = Calculate(input); | 2016 double answer = Calculate(input); |
| 2007 Counters::transcendental_cache_miss.Increment(); | 2017 Counters::transcendental_cache_miss.Increment(); |
| 2008 Object* heap_number; | 2018 Object* heap_number; |
| 2009 { MaybeObject* maybe_heap_number = Heap::AllocateHeapNumber(answer); | 2019 { MaybeObject* maybe_heap_number = Heap::AllocateHeapNumber(answer); |
| 2010 if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number; | 2020 if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number; |
| 2011 } | 2021 } |
| 2012 elements_[hash].in[0] = c.integers[0]; | 2022 elements_[hash].in[0] = c.integers[0]; |
| 2013 elements_[hash].in[1] = c.integers[1]; | 2023 elements_[hash].in[1] = c.integers[1]; |
| 2014 elements_[hash].output = heap_number; | 2024 elements_[hash].output = heap_number; |
| 2025 elements_[hash].untagged_output = answer; |
| 2015 return heap_number; | 2026 return heap_number; |
| 2016 } | 2027 } |
| 2017 | 2028 |
| 2018 inline double Calculate(double input) { | 2029 inline double Calculate(double input) { |
| 2019 switch (type_) { | 2030 switch (type_) { |
| 2020 case ACOS: | 2031 case ACOS: |
| 2021 return acos(input); | 2032 return acos(input); |
| 2022 case ASIN: | 2033 case ASIN: |
| 2023 return asin(input); | 2034 return asin(input); |
| 2024 case ATAN: | 2035 case ATAN: |
| 2025 return atan(input); | 2036 return atan(input); |
| 2026 case COS: | 2037 case COS: |
| 2027 return cos(input); | 2038 return cos(input); |
| 2028 case EXP: | 2039 case EXP: |
| 2029 return exp(input); | 2040 return exp(input); |
| 2030 case LOG: | 2041 case LOG: |
| 2031 return log(input); | 2042 return log(input); |
| 2032 case SIN: | 2043 case SIN: |
| 2033 return sin(input); | 2044 return sin(input); |
| 2034 case TAN: | 2045 case TAN: |
| 2035 return tan(input); | 2046 return tan(input); |
| 2036 default: | 2047 default: |
| 2037 return 0.0; // Never happens. | 2048 return 0.0; // Never happens. |
| 2038 } | 2049 } |
| 2039 } | 2050 } |
| 2040 static const int kCacheSize = 512; | 2051 static const int kCacheSize = 512; |
| 2041 struct Element { | 2052 struct Element { |
| 2042 uint32_t in[2]; | 2053 uint32_t in[2]; |
| 2043 Object* output; | 2054 Object* output; |
| 2055 double untagged_output; |
| 2044 }; | 2056 }; |
| 2057 static const int kElementSize = sizeof(Element); // NOLINT |
| 2045 union Converter { | 2058 union Converter { |
| 2046 double dbl; | 2059 double dbl; |
| 2047 uint32_t integers[2]; | 2060 uint32_t integers[2]; |
| 2048 }; | 2061 }; |
| 2049 inline static int Hash(const Converter& c) { | 2062 inline static int Hash(const Converter& c) { |
| 2050 uint32_t hash = (c.integers[0] ^ c.integers[1]); | 2063 uint32_t hash = (c.integers[0] ^ c.integers[1]); |
| 2051 hash ^= static_cast<int32_t>(hash) >> 16; | 2064 hash ^= static_cast<int32_t>(hash) >> 16; |
| 2052 hash ^= static_cast<int32_t>(hash) >> 8; | 2065 hash ^= static_cast<int32_t>(hash) >> 8; |
| 2053 return (hash & (kCacheSize - 1)); | 2066 return (hash & (kCacheSize - 1)); |
| 2054 } | 2067 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 // Return whether this object should be retained. If NULL is returned the | 2124 // Return whether this object should be retained. If NULL is returned the |
| 2112 // object has no references. Otherwise the address of the retained object | 2125 // object has no references. Otherwise the address of the retained object |
| 2113 // should be returned as in some GC situations the object has been moved. | 2126 // should be returned as in some GC situations the object has been moved. |
| 2114 virtual Object* RetainAs(Object* object) = 0; | 2127 virtual Object* RetainAs(Object* object) = 0; |
| 2115 }; | 2128 }; |
| 2116 | 2129 |
| 2117 | 2130 |
| 2118 } } // namespace v8::internal | 2131 } } // namespace v8::internal |
| 2119 | 2132 |
| 2120 #endif // V8_HEAP_H_ | 2133 #endif // V8_HEAP_H_ |
| OLD | NEW |