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

Side by Side Diff: src/bootstrapper.cc

Issue 90643003: Experimental implementation: Exposing SIMD instructions into JavaScript Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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
« no previous file with comments | « src/ast.cc ('k') | src/code-stubs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 void InstallExperimentalNativeFunctions(); 203 void InstallExperimentalNativeFunctions();
204 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, 204 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins,
205 const char* name, 205 const char* name,
206 ElementsKind elements_kind); 206 ElementsKind elements_kind);
207 bool InstallNatives(); 207 bool InstallNatives();
208 208
209 Handle<JSFunction> InstallTypedArray(const char* name, 209 Handle<JSFunction> InstallTypedArray(const char* name,
210 ElementsKind elementsKind); 210 ElementsKind elementsKind);
211 bool InstallExperimentalNatives(); 211 bool InstallExperimentalNatives();
212 void InstallBuiltinFunctionIds(); 212 void InstallBuiltinFunctionIds();
213 void InstallExperimentalSIMDBuiltinFunctionIds();
213 void InstallJSFunctionResultCaches(); 214 void InstallJSFunctionResultCaches();
214 void InitializeNormalizedMapCaches(); 215 void InitializeNormalizedMapCaches();
215 216
216 enum ExtensionTraversalState { 217 enum ExtensionTraversalState {
217 UNVISITED, VISITED, INSTALLED 218 UNVISITED, VISITED, INSTALLED
218 }; 219 };
219 220
220 class ExtensionStates { 221 class ExtensionStates {
221 public: 222 public:
222 ExtensionStates(); 223 ExtensionStates();
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 JSGeneratorObject::kResultDonePropertyIndex, 1432 JSGeneratorObject::kResultDonePropertyIndex,
1432 NONE, 1433 NONE,
1433 Representation::Tagged()); 1434 Representation::Tagged());
1434 generator_result_map->AppendDescriptor(&done_descr, witness); 1435 generator_result_map->AppendDescriptor(&done_descr, witness);
1435 1436
1436 generator_result_map->set_unused_property_fields(0); 1437 generator_result_map->set_unused_property_fields(0);
1437 ASSERT_EQ(JSGeneratorObject::kResultSize, 1438 ASSERT_EQ(JSGeneratorObject::kResultSize,
1438 generator_result_map->instance_size()); 1439 generator_result_map->instance_size());
1439 native_context()->set_generator_result_map(*generator_result_map); 1440 native_context()->set_generator_result_map(*generator_result_map);
1440 } 1441 }
1442
1443 if (FLAG_simd_object) {
1444 // --- f l o a t 3 2 x 4 ---
1445 Handle<JSFunction> float32x4_fun =
1446 InstallFunction(global, "float32x4", JS_VALUE_TYPE, JSValue::kSize,
1447 isolate()->initial_object_prototype(),
1448 Builtins::kIllegal, true, true);
1449 native_context()->set_float32x4_function(*float32x4_fun);
1450 InstallFunction(float32x4_fun, "zero", JS_VALUE_TYPE, JSValue::kSize,
1451 isolate()->initial_object_prototype(),
1452 Builtins::kIllegal, true, true);
1453 InstallFunction(float32x4_fun, "splat", JS_VALUE_TYPE, JSValue::kSize,
1454 isolate()->initial_object_prototype(),
1455 Builtins::kIllegal, true, true);
1456
1457 // --- u i n t 3 2 x 4 ---
1458 Handle<JSFunction> int32x4_fun =
1459 InstallFunction(global, "int32x4", JS_VALUE_TYPE, JSValue::kSize,
1460 isolate()->initial_object_prototype(),
1461 Builtins::kIllegal, true, true);
1462 native_context()->set_int32x4_function(*int32x4_fun);
1463 InstallFunction(int32x4_fun, "bool", JS_VALUE_TYPE, JSValue::kSize,
1464 isolate()->initial_object_prototype(),
1465 Builtins::kIllegal, true, true);
1466 InstallFunction(int32x4_fun, "splat", JS_VALUE_TYPE, JSValue::kSize,
1467 isolate()->initial_object_prototype(),
1468 Builtins::kIllegal, true, true);
1469
1470 Handle<JSFunction> float32x4_array_fun = InstallTypedArray("Float32x4Array",
1471 EXTERNAL_FLOAT32x4_ELEMENTS);
1472 native_context()->set_float32x4_array_fun(*float32x4_array_fun);
1473 Handle<JSFunction> int32x4_array_fun = InstallTypedArray("Int32x4Array",
1474 EXTERNAL_INT32x4_ELEMENTS);
1475 native_context()->set_int32x4_array_fun(*int32x4_array_fun);
1476 }
1441 } 1477 }
1442 1478
1443 1479
1444 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { 1480 bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
1445 Vector<const char> name = Natives::GetScriptName(index); 1481 Vector<const char> name = Natives::GetScriptName(index);
1446 Handle<String> source_code = 1482 Handle<String> source_code =
1447 isolate->bootstrapper()->NativesSourceLookup(index); 1483 isolate->bootstrapper()->NativesSourceLookup(index);
1448 return CompileNative(isolate, name, source_code); 1484 return CompileNative(isolate, name, source_code);
1449 } 1485 }
1450 1486
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 if (FLAG_harmony_arrays && 2098 if (FLAG_harmony_arrays &&
2063 strcmp(ExperimentalNatives::GetScriptName(i).start(), 2099 strcmp(ExperimentalNatives::GetScriptName(i).start(),
2064 "native harmony-array.js") == 0) { 2100 "native harmony-array.js") == 0) {
2065 if (!CompileExperimentalBuiltin(isolate(), i)) return false; 2101 if (!CompileExperimentalBuiltin(isolate(), i)) return false;
2066 } 2102 }
2067 if (FLAG_harmony_maths && 2103 if (FLAG_harmony_maths &&
2068 strcmp(ExperimentalNatives::GetScriptName(i).start(), 2104 strcmp(ExperimentalNatives::GetScriptName(i).start(),
2069 "native harmony-math.js") == 0) { 2105 "native harmony-math.js") == 0) {
2070 if (!CompileExperimentalBuiltin(isolate(), i)) return false; 2106 if (!CompileExperimentalBuiltin(isolate(), i)) return false;
2071 } 2107 }
2108 if (FLAG_simd_object &&
2109 strcmp(ExperimentalNatives::GetScriptName(i).start(),
2110 "native simd128.js") == 0) {
2111 if (!CompileExperimentalBuiltin(isolate(), i)) return false;
2112 InstallExperimentalSIMDBuiltinFunctionIds();
2113 // Store the map for the float32x4 and int32x4 function prototype after
2114 // the float32x4 and int32x4 function has been set up.
2115 JSObject* float32x4_function_prototype = JSObject::cast(
2116 native_context()->float32x4_function()->instance_prototype());
2117 native_context()->set_float32x4_function_prototype_map(
2118 float32x4_function_prototype->map());
2119 JSObject* int32x4_function_prototype = JSObject::cast(
2120 native_context()->int32x4_function()->instance_prototype());
2121 native_context()->set_int32x4_function_prototype_map(
2122 int32x4_function_prototype->map());
2123 }
2072 } 2124 }
2073 2125
2074 InstallExperimentalNativeFunctions(); 2126 InstallExperimentalNativeFunctions();
2075 2127
2076 return true; 2128 return true;
2077 } 2129 }
2078 2130
2079 2131
2080 static Handle<JSObject> ResolveBuiltinIdHolder( 2132 static Handle<JSObject> ResolveBuiltinIdHolder(
2081 Handle<Context> native_context, 2133 Handle<Context> native_context,
2082 const char* holder_expr) { 2134 const char* holder_expr) {
2083 Isolate* isolate = native_context->GetIsolate(); 2135 Isolate* isolate = native_context->GetIsolate();
2084 Factory* factory = isolate->factory(); 2136 Factory* factory = isolate->factory();
2085 Handle<GlobalObject> global(native_context->global_object()); 2137 Handle<GlobalObject> global(native_context->global_object());
2086 const char* period_pos = strchr(holder_expr, '.'); 2138 const char* period_pos = strchr(holder_expr, '.');
2087 if (period_pos == NULL) { 2139 if (period_pos == NULL) {
2088 return Handle<JSObject>::cast(GetProperty( 2140 return Handle<JSObject>::cast(GetProperty(
2089 isolate, global, factory->InternalizeUtf8String(holder_expr))); 2141 isolate, global, factory->InternalizeUtf8String(holder_expr)));
2090 } 2142 }
2091 ASSERT_EQ(".prototype", period_pos); 2143 ASSERT_EQ(".prototype", period_pos);
2092 Vector<const char> property(holder_expr, 2144 Vector<const char> property(holder_expr,
2093 static_cast<int>(period_pos - holder_expr)); 2145 static_cast<int>(period_pos - holder_expr));
2094 Handle<JSFunction> function = Handle<JSFunction>::cast( 2146 Handle<JSFunction> function = Handle<JSFunction>::cast(
2095 GetProperty(isolate, global, factory->InternalizeUtf8String(property))); 2147 GetProperty(isolate, global, factory->InternalizeUtf8String(property)));
2096 return Handle<JSObject>(JSObject::cast(function->prototype())); 2148 return Handle<JSObject>(JSObject::cast(function->prototype()));
2097 } 2149 }
2098 2150
2099 2151
2152 static Handle<JSObject> ResolveBuiltinSIMDIdHolder(
2153 Handle<Context> native_context,
2154 const char* holder_expr) {
2155 Isolate* isolate = native_context->GetIsolate();
2156 Factory* factory = isolate->factory();
2157 Handle<GlobalObject> global(native_context->global_object());
2158 Handle<Object> holder = global;
2159 char* name = const_cast<char*>(holder_expr);
2160 char* period_pos = strchr(name, '.');
2161 while (period_pos != NULL) {
2162 Vector<const char> property(name, static_cast<int>(period_pos - name));
2163 holder = GetProperty(isolate, holder,
2164 factory->InternalizeUtf8String(property));
2165 if (strcmp(".prototype", period_pos) == 0) {
2166 Handle<JSFunction> function = Handle<JSFunction>::cast(holder);
2167 return Handle<JSObject>(JSObject::cast(function->prototype()));
2168 } else {
2169 name = period_pos + 1;
2170 period_pos = strchr(name, '.');
2171 }
2172 }
2173
2174 return Handle<JSObject>::cast(GetProperty(
2175 isolate, holder, factory->InternalizeUtf8String(name)));
2176 }
2177
2178
2100 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 2179 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
2101 const char* function_name, 2180 const char* function_name,
2102 BuiltinFunctionId id) { 2181 BuiltinFunctionId id) {
2103 Factory* factory = holder->GetIsolate()->factory(); 2182 Factory* factory = holder->GetIsolate()->factory();
2104 Handle<String> name = factory->InternalizeUtf8String(function_name); 2183 Handle<String> name = factory->InternalizeUtf8String(function_name);
2105 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); 2184 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked();
2106 Handle<JSFunction> function(JSFunction::cast(function_object)); 2185 Handle<JSFunction> function(JSFunction::cast(function_object));
2107 function->shared()->set_function_data(Smi::FromInt(id)); 2186 function->shared()->set_function_data(Smi::FromInt(id));
2108 } 2187 }
2109 2188
2110 2189
2111 void Genesis::InstallBuiltinFunctionIds() { 2190 void Genesis::InstallBuiltinFunctionIds() {
2112 HandleScope scope(isolate()); 2191 HandleScope scope(isolate());
2113 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ 2192 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \
2114 { \ 2193 { \
2115 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ 2194 Handle<JSObject> holder = ResolveBuiltinIdHolder( \
2116 native_context(), #holder_expr); \ 2195 native_context(), #holder_expr); \
2117 BuiltinFunctionId id = k##name; \ 2196 BuiltinFunctionId id = k##name; \
2118 InstallBuiltinFunctionId(holder, #fun_name, id); \ 2197 InstallBuiltinFunctionId(holder, #fun_name, id); \
2119 } 2198 }
2120 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID) 2199 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)
2121 #undef INSTALL_BUILTIN_ID 2200 #undef INSTALL_BUILTIN_ID
2122 } 2201 }
2123 2202
2124 2203
2204 void Genesis::InstallExperimentalSIMDBuiltinFunctionIds() {
2205 HandleScope scope(isolate());
2206 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \
2207 { \
2208 Handle<JSObject> holder = ResolveBuiltinSIMDIdHolder( \
2209 native_context(), #holder_expr); \
2210 BuiltinFunctionId id = k##name; \
2211 InstallBuiltinFunctionId(holder, #fun_name, id); \
2212 }
2213 EXPERIMENTAL_SIMD_FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)
2214 #undef INSTALL_BUILTIN_ID
2215 {
2216 Handle<GlobalObject> global(native_context()->global_object());
2217 InstallBuiltinFunctionId(global, "float32x4", kFloat32x4Constructor);
2218 InstallBuiltinFunctionId(global, "int32x4", kInt32x4Constructor);
2219 }
2220 }
2221
2222
2125 // Do not forget to update macros.py with named constant 2223 // Do not forget to update macros.py with named constant
2126 // of cache id. 2224 // of cache id.
2127 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ 2225 #define JSFUNCTION_RESULT_CACHE_LIST(F) \
2128 F(16, native_context()->regexp_function()) 2226 F(16, native_context()->regexp_function())
2129 2227
2130 2228
2131 static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) { 2229 static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) {
2132 Factory* factory = factory_function->GetIsolate()->factory(); 2230 Factory* factory = factory_function->GetIsolate()->factory();
2133 // Caches are supposed to live for a long time, allocate in old space. 2231 // Caches are supposed to live for a long time, allocate in old space.
2134 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; 2232 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size;
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
2717 return from + sizeof(NestingCounterType); 2815 return from + sizeof(NestingCounterType);
2718 } 2816 }
2719 2817
2720 2818
2721 // Called when the top-level V8 mutex is destroyed. 2819 // Called when the top-level V8 mutex is destroyed.
2722 void Bootstrapper::FreeThreadResources() { 2820 void Bootstrapper::FreeThreadResources() {
2723 ASSERT(!IsActive()); 2821 ASSERT(!IsActive());
2724 } 2822 }
2725 2823
2726 } } // namespace v8::internal 2824 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.cc ('k') | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698