OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 Node* backing_store = | 86 Node* backing_store = |
87 a->LoadObjectField(array_buffer, JSArrayBuffer::kBackingStoreOffset); | 87 a->LoadObjectField(array_buffer, JSArrayBuffer::kBackingStoreOffset); |
88 Node* byte_offset = a->ChangeUint32ToWord(a->TruncateTaggedToWord32( | 88 Node* byte_offset = a->ChangeUint32ToWord(a->TruncateTaggedToWord32( |
89 context, | 89 context, |
90 a->LoadObjectField(tagged, JSArrayBufferView::kByteOffsetOffset))); | 90 a->LoadObjectField(tagged, JSArrayBufferView::kByteOffsetOffset))); |
91 *out_backing_store = | 91 *out_backing_store = |
92 a->IntPtrAdd(a->BitcastTaggedToWord(backing_store), byte_offset); | 92 a->IntPtrAdd(a->BitcastTaggedToWord(backing_store), byte_offset); |
93 } | 93 } |
94 | 94 |
95 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access | 95 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access |
96 compiler::Node* ConvertTaggedAtomicIndexToWord32(CodeStubAssembler* a, | 96 compiler::Node* ConvertTaggedAtomicIndexToWord32( |
97 compiler::Node* tagged, | 97 CodeStubAssembler* a, compiler::Node* tagged, compiler::Node* context, |
98 compiler::Node* context) { | 98 compiler::Node** number_index) { |
99 using compiler::Node; | 99 using compiler::Node; |
100 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32); | 100 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32); |
101 | 101 |
102 Callable to_number = CodeFactory::ToNumber(a->isolate()); | 102 Callable to_number = CodeFactory::ToNumber(a->isolate()); |
103 Node* number_index = a->CallStub(to_number, context, tagged); | 103 *number_index = a->CallStub(to_number, context, tagged); |
104 CodeStubAssembler::Label done(a, &var_result); | 104 CodeStubAssembler::Label done(a, &var_result); |
105 | 105 |
106 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a); | 106 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a); |
107 a->Branch(a->TaggedIsSmi(number_index), &if_numberissmi, &if_numberisnotsmi); | 107 a->Branch(a->TaggedIsSmi(*number_index), &if_numberissmi, &if_numberisnotsmi); |
108 | 108 |
109 a->Bind(&if_numberissmi); | 109 a->Bind(&if_numberissmi); |
110 { | 110 { |
111 var_result.Bind(a->SmiToWord32(number_index)); | 111 var_result.Bind(a->SmiToWord32(*number_index)); |
112 a->Goto(&done); | 112 a->Goto(&done); |
113 } | 113 } |
114 | 114 |
115 a->Bind(&if_numberisnotsmi); | 115 a->Bind(&if_numberisnotsmi); |
116 { | 116 { |
117 Node* number_index_value = a->LoadHeapNumberValue(number_index); | 117 Node* number_index_value = a->LoadHeapNumberValue(*number_index); |
118 Node* access_index = a->TruncateFloat64ToWord32(number_index_value); | 118 Node* access_index = a->TruncateFloat64ToWord32(number_index_value); |
119 Node* test_index = a->ChangeInt32ToFloat64(access_index); | 119 Node* test_index = a->ChangeInt32ToFloat64(access_index); |
120 | 120 |
121 CodeStubAssembler::Label if_indexesareequal(a), if_indexesarenotequal(a); | 121 CodeStubAssembler::Label if_indexesareequal(a), if_indexesarenotequal(a); |
122 a->Branch(a->Float64Equal(number_index_value, test_index), | 122 a->Branch(a->Float64Equal(number_index_value, test_index), |
123 &if_indexesareequal, &if_indexesarenotequal); | 123 &if_indexesareequal, &if_indexesarenotequal); |
124 | 124 |
125 a->Bind(&if_indexesareequal); | 125 a->Bind(&if_indexesareequal); |
126 { | 126 { |
127 var_result.Bind(access_index); | 127 var_result.Bind(access_index); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 using compiler::Node; | 160 using compiler::Node; |
161 CodeStubAssembler a(state); | 161 CodeStubAssembler a(state); |
162 Node* array = a.Parameter(1); | 162 Node* array = a.Parameter(1); |
163 Node* index = a.Parameter(2); | 163 Node* index = a.Parameter(2); |
164 Node* context = a.Parameter(3 + 2); | 164 Node* context = a.Parameter(3 + 2); |
165 | 165 |
166 Node* instance_type; | 166 Node* instance_type; |
167 Node* backing_store; | 167 Node* backing_store; |
168 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); | 168 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); |
169 | 169 |
170 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(&a, index, context); | 170 Node* index_integer; |
171 Node* index_word32 = | |
172 ConvertTaggedAtomicIndexToWord32(&a, index, context, &index_integer); | |
171 Node* array_length_word32 = a.TruncateTaggedToWord32( | 173 Node* array_length_word32 = a.TruncateTaggedToWord32( |
172 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); | 174 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); |
173 ValidateAtomicIndex(&a, index_word32, array_length_word32, context); | 175 ValidateAtomicIndex(&a, index_word32, array_length_word32, context); |
174 Node* index_word = a.ChangeUint32ToWord(index_word32); | 176 Node* index_word = a.ChangeUint32ToWord(index_word32); |
175 | 177 |
176 CodeStubAssembler::Label i8(&a), u8(&a), i16(&a), u16(&a), i32(&a), u32(&a), | 178 CodeStubAssembler::Label i8(&a), u8(&a), i16(&a), u16(&a), i32(&a), u32(&a), |
177 other(&a); | 179 other(&a); |
178 int32_t case_values[] = { | 180 int32_t case_values[] = { |
179 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, | 181 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, |
180 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, | 182 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 CodeStubAssembler a(state); | 221 CodeStubAssembler a(state); |
220 Node* array = a.Parameter(1); | 222 Node* array = a.Parameter(1); |
221 Node* index = a.Parameter(2); | 223 Node* index = a.Parameter(2); |
222 Node* value = a.Parameter(3); | 224 Node* value = a.Parameter(3); |
223 Node* context = a.Parameter(4 + 2); | 225 Node* context = a.Parameter(4 + 2); |
224 | 226 |
225 Node* instance_type; | 227 Node* instance_type; |
226 Node* backing_store; | 228 Node* backing_store; |
227 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); | 229 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); |
228 | 230 |
229 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(&a, index, context); | 231 Node* index_integer; |
232 Node* index_word32 = | |
233 ConvertTaggedAtomicIndexToWord32(&a, index, context, &index_integer); | |
230 Node* array_length_word32 = a.TruncateTaggedToWord32( | 234 Node* array_length_word32 = a.TruncateTaggedToWord32( |
231 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); | 235 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); |
232 ValidateAtomicIndex(&a, index_word32, array_length_word32, context); | 236 ValidateAtomicIndex(&a, index_word32, array_length_word32, context); |
233 Node* index_word = a.ChangeUint32ToWord(index_word32); | 237 Node* index_word = a.ChangeUint32ToWord(index_word32); |
234 | 238 |
235 Node* value_integer = a.ToInteger(context, value); | 239 Node* value_integer = a.ToInteger(context, value); |
236 Node* value_word32 = a.TruncateTaggedToWord32(context, value_integer); | 240 Node* value_word32 = a.TruncateTaggedToWord32(context, value_integer); |
237 | 241 |
238 CodeStubAssembler::Label u8(&a), u16(&a), u32(&a), other(&a); | 242 CodeStubAssembler::Label u8(&a), u16(&a), u32(&a), other(&a); |
239 int32_t case_values[] = { | 243 int32_t case_values[] = { |
(...skipping 19 matching lines...) Expand all Loading... | |
259 a.Bind(&u32); | 263 a.Bind(&u32); |
260 a.AtomicStore(MachineRepresentation::kWord32, backing_store, | 264 a.AtomicStore(MachineRepresentation::kWord32, backing_store, |
261 a.WordShl(index_word, 2), value_word32); | 265 a.WordShl(index_word, 2), value_word32); |
262 a.Return(value_integer); | 266 a.Return(value_integer); |
263 | 267 |
264 // This shouldn't happen, we've already validated the type. | 268 // This shouldn't happen, we've already validated the type. |
265 a.Bind(&other); | 269 a.Bind(&other); |
266 a.Return(a.SmiConstant(0)); | 270 a.Return(a.SmiConstant(0)); |
267 } | 271 } |
268 | 272 |
273 void Builtins::Generate_AtomicsExchange(compiler::CodeAssemblerState* state) { | |
274 using compiler::Node; | |
275 CodeStubAssembler a(state); | |
276 Node* array = a.Parameter(1); | |
277 Node* index = a.Parameter(2); | |
278 Node* value = a.Parameter(3); | |
279 Node* context = a.Parameter(4 + 2); | |
280 | |
281 Node* instance_type; | |
282 Node* backing_store; | |
283 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); | |
284 | |
285 Node* index_integer; | |
286 Node* index_word32 = | |
287 ConvertTaggedAtomicIndexToWord32(&a, index, context, &index_integer); | |
288 Node* array_length_word32 = a.TruncateTaggedToWord32( | |
289 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); | |
290 ValidateAtomicIndex(&a, index_word32, array_length_word32, context); | |
291 | |
292 Node* value_integer = a.ToInteger(context, value); | |
293 | |
294 #if V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 | |
295 // Node* index_integer = a.ToInteger(context, index); | |
296 a.Return(a.CallRuntime(Runtime::kAtomicsExchange, context, array, | |
297 index_integer, value_integer)); | |
Jarin
2017/03/06 10:59:05
Can't you tail-call to the runtime?
I was hoping
aseemgarg
2017/03/06 23:20:07
I tried doing a.TailCallRuntime instead of a.Retur
| |
298 #else | |
299 Node* index_word = a.ChangeUint32ToWord(index_word32); | |
300 | |
301 Node* value_word32 = a.TruncateTaggedToWord32(context, value_integer); | |
302 | |
303 CodeStubAssembler::Label i8(&a), u8(&a), i16(&a), u16(&a), i32(&a), u32(&a), | |
304 other(&a); | |
305 int32_t case_values[] = { | |
306 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, | |
307 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, | |
308 }; | |
309 CodeStubAssembler::Label* case_labels[] = { | |
310 &i8, &u8, &i16, &u16, &i32, &u32, | |
311 }; | |
312 a.Switch(instance_type, &other, case_values, case_labels, | |
313 arraysize(case_labels)); | |
314 | |
315 a.Bind(&i8); | |
316 a.Return(a.SmiFromWord32(a.AtomicExchange(MachineType::Int8(), backing_store, | |
317 index_word, value_word32))); | |
318 | |
319 a.Bind(&u8); | |
320 a.Return(a.SmiFromWord32(a.AtomicExchange(MachineType::Uint8(), backing_store, | |
321 index_word, value_word32))); | |
322 | |
323 a.Bind(&i16); | |
324 a.Return(a.SmiFromWord32(a.AtomicExchange(MachineType::Int16(), backing_store, | |
325 a.WordShl(index_word, 1), | |
326 value_word32))); | |
327 | |
328 a.Bind(&u16); | |
329 a.Return(a.SmiFromWord32( | |
330 a.AtomicExchange(MachineType::Uint16(), backing_store, | |
331 a.WordShl(index_word, 1), value_word32))); | |
332 | |
333 a.Bind(&i32); | |
334 a.Return(a.ChangeInt32ToTagged( | |
335 a.AtomicExchange(MachineType::Int32(), backing_store, | |
336 a.WordShl(index_word, 2), value_word32))); | |
337 | |
338 a.Bind(&u32); | |
339 a.Return(a.ChangeUint32ToTagged( | |
340 a.AtomicExchange(MachineType::Uint32(), backing_store, | |
341 a.WordShl(index_word, 2), value_word32))); | |
342 | |
343 // This shouldn't happen, we've already validated the type. | |
344 a.Bind(&other); | |
345 a.Return(a.SmiConstant(0)); | |
346 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 | |
347 } | |
348 | |
269 } // namespace internal | 349 } // namespace internal |
270 } // namespace v8 | 350 } // namespace v8 |
OLD | NEW |