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

Side by Side Diff: src/heap.h

Issue 5720005: Add an untagged double to transcendental cache elements. They now contain an... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 static void Clear(); 1986 static void Clear();
1987 1987
1988 private: 1988 private:
1989 MUST_USE_RESULT inline MaybeObject* Get(double input) { 1989 MUST_USE_RESULT inline MaybeObject* Get(double input) {
1990 Converter c; 1990 Converter c;
1991 c.dbl = input; 1991 c.dbl = input;
1992 int hash = Hash(c); 1992 int hash = Hash(c);
1993 Element e = elements_[hash]; 1993 Element e = elements_[hash];
1994 if (e.in[0] == c.integers[0] && 1994 if (e.in[0] == c.integers[0] &&
1995 e.in[1] == c.integers[1]) { 1995 e.in[1] == c.integers[1]) {
1996 ASSERT(e.output != NULL); 1996 if (e.output != NULL) {
1997 Counters::transcendental_cache_hit.Increment(); 1997 Counters::transcendental_cache_hit.Increment();
1998 return e.output; 1998 return e.output;
1999 } else {
2000 Object* heap_number;
2001 { MaybeObject* maybe_heap_number =
2002 Heap::AllocateHeapNumber(e.untagged_output);
2003 if (!maybe_heap_number->ToObject(&heap_number))
2004 return maybe_heap_number;
2005 }
2006 elements_[hash].output = heap_number;
2007 return heap_number;
2008 }
1999 } 2009 }
2000 double answer = Calculate(input); 2010 double answer = Calculate(input);
2001 Counters::transcendental_cache_miss.Increment(); 2011 Counters::transcendental_cache_miss.Increment();
2002 Object* heap_number; 2012 Object* heap_number;
2003 { MaybeObject* maybe_heap_number = Heap::AllocateHeapNumber(answer); 2013 { MaybeObject* maybe_heap_number = Heap::AllocateHeapNumber(answer);
2004 if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number; 2014 if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number;
2005 } 2015 }
2006 elements_[hash].in[0] = c.integers[0]; 2016 elements_[hash].in[0] = c.integers[0];
2007 elements_[hash].in[1] = c.integers[1]; 2017 elements_[hash].in[1] = c.integers[1];
2008 elements_[hash].output = heap_number; 2018 elements_[hash].output = heap_number;
2019 elements_[hash].untagged_output = answer;
2009 return heap_number; 2020 return heap_number;
2010 } 2021 }
2011 2022
2012 inline double Calculate(double input) { 2023 inline double Calculate(double input) {
2013 switch (type_) { 2024 switch (type_) {
2014 case ACOS: 2025 case ACOS:
2015 return acos(input); 2026 return acos(input);
2016 case ASIN: 2027 case ASIN:
2017 return asin(input); 2028 return asin(input);
2018 case ATAN: 2029 case ATAN:
2019 return atan(input); 2030 return atan(input);
2020 case COS: 2031 case COS:
2021 return cos(input); 2032 return cos(input);
2022 case EXP: 2033 case EXP:
2023 return exp(input); 2034 return exp(input);
2024 case LOG: 2035 case LOG:
2025 return log(input); 2036 return log(input);
2026 case SIN: 2037 case SIN:
2027 return sin(input); 2038 return sin(input);
2028 case TAN: 2039 case TAN:
2029 return tan(input); 2040 return tan(input);
2030 default: 2041 default:
2031 return 0.0; // Never happens. 2042 return 0.0; // Never happens.
2032 } 2043 }
2033 } 2044 }
2034 static const int kCacheSize = 512; 2045 static const int kCacheSize = 512;
2035 struct Element { 2046 struct Element {
2036 uint32_t in[2]; 2047 uint32_t in[2];
2037 Object* output; 2048 Object* output;
2049 double untagged_output;
2038 }; 2050 };
2051 static const int kElementSize = sizeof (Element);
Erik Corry 2010/12/13 20:26:13 There should really be some constants here that yo
2039 union Converter { 2052 union Converter {
2040 double dbl; 2053 double dbl;
2041 uint32_t integers[2]; 2054 uint32_t integers[2];
2042 }; 2055 };
2043 inline static int Hash(const Converter& c) { 2056 inline static int Hash(const Converter& c) {
2044 uint32_t hash = (c.integers[0] ^ c.integers[1]); 2057 uint32_t hash = (c.integers[0] ^ c.integers[1]);
2045 hash ^= static_cast<int32_t>(hash) >> 16; 2058 hash ^= static_cast<int32_t>(hash) >> 16;
2046 hash ^= static_cast<int32_t>(hash) >> 8; 2059 hash ^= static_cast<int32_t>(hash) >> 8;
2047 return (hash & (kCacheSize - 1)); 2060 return (hash & (kCacheSize - 1));
2048 } 2061 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 // Return whether this object should be retained. If NULL is returned the 2119 // Return whether this object should be retained. If NULL is returned the
2107 // object has no references. Otherwise the address of the retained object 2120 // object has no references. Otherwise the address of the retained object
2108 // should be returned as in some GC situations the object has been moved. 2121 // should be returned as in some GC situations the object has been moved.
2109 virtual Object* RetainAs(Object* object) = 0; 2122 virtual Object* RetainAs(Object* object) = 0;
2110 }; 2123 };
2111 2124
2112 2125
2113 } } // namespace v8::internal 2126 } } // namespace v8::internal
2114 2127
2115 #endif // V8_HEAP_H_ 2128 #endif // V8_HEAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698