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

Side by Side Diff: src/builtins/builtins-sharedarraybuffer.cc

Issue 2504913002: Revert of [refactoring] Split CodeAssemblerState out of CodeAssembler (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « src/builtins/builtins-regexp.cc ('k') | src/builtins/builtins-string.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 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.h" 5 #include "src/builtins/builtins.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 7
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 return array_buffer->byte_length(); 25 return array_buffer->byte_length();
26 } 26 }
27 27
28 namespace { 28 namespace {
29 29
30 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged, 30 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged,
31 compiler::Node* context, 31 compiler::Node* context,
32 compiler::Node** out_instance_type, 32 compiler::Node** out_instance_type,
33 compiler::Node** out_backing_store) { 33 compiler::Node** out_backing_store) {
34 using compiler::Node; 34 using namespace compiler;
35 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a), 35 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a),
36 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a), 36 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a),
37 not_float_or_clamped(a), invalid(a); 37 not_float_or_clamped(a), invalid(a);
38 38
39 // Fail if it is not a heap object. 39 // Fail if it is not a heap object.
40 a->Branch(a->TaggedIsSmi(tagged), &is_smi, &not_smi); 40 a->Branch(a->TaggedIsSmi(tagged), &is_smi, &not_smi);
41 a->Bind(&is_smi); 41 a->Bind(&is_smi);
42 a->Goto(&invalid); 42 a->Goto(&invalid);
43 43
44 // Fail if the array's instance type is not JSTypedArray. 44 // Fail if the array's instance type is not JSTypedArray.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = a->IntPtrAdd(backing_store, byte_offset); 91 *out_backing_store = a->IntPtrAdd(backing_store, byte_offset);
92 } 92 }
93 93
94 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access 94 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access
95 compiler::Node* ConvertTaggedAtomicIndexToWord32(CodeStubAssembler* a, 95 compiler::Node* ConvertTaggedAtomicIndexToWord32(CodeStubAssembler* a,
96 compiler::Node* tagged, 96 compiler::Node* tagged,
97 compiler::Node* context) { 97 compiler::Node* context) {
98 using compiler::Node; 98 using namespace compiler;
99 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32); 99 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32);
100 100
101 Callable to_number = CodeFactory::ToNumber(a->isolate()); 101 Callable to_number = CodeFactory::ToNumber(a->isolate());
102 Node* number_index = a->CallStub(to_number, context, tagged); 102 Node* number_index = a->CallStub(to_number, context, tagged);
103 CodeStubAssembler::Label done(a, &var_result); 103 CodeStubAssembler::Label done(a, &var_result);
104 104
105 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a); 105 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a);
106 a->Branch(a->TaggedIsSmi(number_index), &if_numberissmi, &if_numberisnotsmi); 106 a->Branch(a->TaggedIsSmi(number_index), &if_numberissmi, &if_numberisnotsmi);
107 107
108 a->Bind(&if_numberissmi); 108 a->Bind(&if_numberissmi);
(...skipping 23 matching lines...) Expand all
132 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); 132 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context));
133 } 133 }
134 134
135 a->Bind(&done); 135 a->Bind(&done);
136 return var_result.value(); 136 return var_result.value();
137 } 137 }
138 138
139 void ValidateAtomicIndex(CodeStubAssembler* a, compiler::Node* index_word, 139 void ValidateAtomicIndex(CodeStubAssembler* a, compiler::Node* index_word,
140 compiler::Node* array_length_word, 140 compiler::Node* array_length_word,
141 compiler::Node* context) { 141 compiler::Node* context) {
142 using compiler::Node; 142 using namespace compiler;
143 // Check if the index is in bounds. If not, throw RangeError. 143 // Check if the index is in bounds. If not, throw RangeError.
144 CodeStubAssembler::Label if_inbounds(a), if_notinbounds(a); 144 CodeStubAssembler::Label if_inbounds(a), if_notinbounds(a);
145 // TODO(jkummerow): Use unsigned comparison instead of "i<0 || i>length". 145 // TODO(jkummerow): Use unsigned comparison instead of "i<0 || i>length".
146 a->Branch( 146 a->Branch(
147 a->WordOr(a->Int32LessThan(index_word, a->Int32Constant(0)), 147 a->WordOr(a->Int32LessThan(index_word, a->Int32Constant(0)),
148 a->Int32GreaterThanOrEqual(index_word, array_length_word)), 148 a->Int32GreaterThanOrEqual(index_word, array_length_word)),
149 &if_notinbounds, &if_inbounds); 149 &if_notinbounds, &if_inbounds);
150 a->Bind(&if_notinbounds); 150 a->Bind(&if_notinbounds);
151 a->Return( 151 a->Return(
152 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); 152 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context));
153 a->Bind(&if_inbounds); 153 a->Bind(&if_inbounds);
154 } 154 }
155 155
156 } // anonymous namespace 156 } // anonymous namespace
157 157
158 void Builtins::Generate_AtomicsLoad(compiler::CodeAssemblerState* state) { 158 void Builtins::Generate_AtomicsLoad(CodeStubAssembler* a) {
159 using compiler::Node; 159 using namespace compiler;
160 CodeStubAssembler a(state); 160 Node* array = a->Parameter(1);
161 Node* array = a.Parameter(1); 161 Node* index = a->Parameter(2);
162 Node* index = a.Parameter(2); 162 Node* context = a->Parameter(3 + 2);
163 Node* context = a.Parameter(3 + 2);
164 163
165 Node* instance_type; 164 Node* instance_type;
166 Node* backing_store; 165 Node* backing_store;
167 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); 166 ValidateSharedTypedArray(a, array, context, &instance_type, &backing_store);
168 167
169 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(&a, index, context); 168 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(a, index, context);
170 Node* array_length_word32 = a.TruncateTaggedToWord32( 169 Node* array_length_word32 = a->TruncateTaggedToWord32(
171 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); 170 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset));
172 ValidateAtomicIndex(&a, index_word32, array_length_word32, context); 171 ValidateAtomicIndex(a, index_word32, array_length_word32, context);
173 Node* index_word = a.ChangeUint32ToWord(index_word32); 172 Node* index_word = a->ChangeUint32ToWord(index_word32);
174 173
175 CodeStubAssembler::Label i8(&a), u8(&a), i16(&a), u16(&a), i32(&a), u32(&a), 174 CodeStubAssembler::Label i8(a), u8(a), i16(a), u16(a), i32(a), u32(a),
176 other(&a); 175 other(a);
177 int32_t case_values[] = { 176 int32_t case_values[] = {
178 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, 177 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE,
179 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, 178 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE,
180 }; 179 };
181 CodeStubAssembler::Label* case_labels[] = { 180 CodeStubAssembler::Label* case_labels[] = {
182 &i8, &u8, &i16, &u16, &i32, &u32, 181 &i8, &u8, &i16, &u16, &i32, &u32,
183 }; 182 };
184 a.Switch(instance_type, &other, case_values, case_labels, 183 a->Switch(instance_type, &other, case_values, case_labels,
185 arraysize(case_labels)); 184 arraysize(case_labels));
186 185
187 a.Bind(&i8); 186 a->Bind(&i8);
188 a.Return( 187 a->Return(
189 a.SmiTag(a.AtomicLoad(MachineType::Int8(), backing_store, index_word))); 188 a->SmiTag(a->AtomicLoad(MachineType::Int8(), backing_store, index_word)));
190 189
191 a.Bind(&u8); 190 a->Bind(&u8);
192 a.Return( 191 a->Return(a->SmiTag(
193 a.SmiTag(a.AtomicLoad(MachineType::Uint8(), backing_store, index_word))); 192 a->AtomicLoad(MachineType::Uint8(), backing_store, index_word)));
194 193
195 a.Bind(&i16); 194 a->Bind(&i16);
196 a.Return(a.SmiTag(a.AtomicLoad(MachineType::Int16(), backing_store, 195 a->Return(a->SmiTag(a->AtomicLoad(MachineType::Int16(), backing_store,
197 a.WordShl(index_word, 1)))); 196 a->WordShl(index_word, 1))));
198 197
199 a.Bind(&u16); 198 a->Bind(&u16);
200 a.Return(a.SmiTag(a.AtomicLoad(MachineType::Uint16(), backing_store, 199 a->Return(a->SmiTag(a->AtomicLoad(MachineType::Uint16(), backing_store,
201 a.WordShl(index_word, 1)))); 200 a->WordShl(index_word, 1))));
202 201
203 a.Bind(&i32); 202 a->Bind(&i32);
204 a.Return(a.ChangeInt32ToTagged(a.AtomicLoad( 203 a->Return(a->ChangeInt32ToTagged(a->AtomicLoad(
205 MachineType::Int32(), backing_store, a.WordShl(index_word, 2)))); 204 MachineType::Int32(), backing_store, a->WordShl(index_word, 2))));
206 205
207 a.Bind(&u32); 206 a->Bind(&u32);
208 a.Return(a.ChangeUint32ToTagged(a.AtomicLoad( 207 a->Return(a->ChangeUint32ToTagged(a->AtomicLoad(
209 MachineType::Uint32(), backing_store, a.WordShl(index_word, 2)))); 208 MachineType::Uint32(), backing_store, a->WordShl(index_word, 2))));
210 209
211 // This shouldn't happen, we've already validated the type. 210 // This shouldn't happen, we've already validated the type.
212 a.Bind(&other); 211 a->Bind(&other);
213 a.Return(a.Int32Constant(0)); 212 a->Return(a->Int32Constant(0));
214 } 213 }
215 214
216 void Builtins::Generate_AtomicsStore(compiler::CodeAssemblerState* state) { 215 void Builtins::Generate_AtomicsStore(CodeStubAssembler* a) {
217 using compiler::Node; 216 using namespace compiler;
218 CodeStubAssembler a(state); 217 Node* array = a->Parameter(1);
219 Node* array = a.Parameter(1); 218 Node* index = a->Parameter(2);
220 Node* index = a.Parameter(2); 219 Node* value = a->Parameter(3);
221 Node* value = a.Parameter(3); 220 Node* context = a->Parameter(4 + 2);
222 Node* context = a.Parameter(4 + 2);
223 221
224 Node* instance_type; 222 Node* instance_type;
225 Node* backing_store; 223 Node* backing_store;
226 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); 224 ValidateSharedTypedArray(a, array, context, &instance_type, &backing_store);
227 225
228 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(&a, index, context); 226 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(a, index, context);
229 Node* array_length_word32 = a.TruncateTaggedToWord32( 227 Node* array_length_word32 = a->TruncateTaggedToWord32(
230 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); 228 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset));
231 ValidateAtomicIndex(&a, index_word32, array_length_word32, context); 229 ValidateAtomicIndex(a, index_word32, array_length_word32, context);
232 Node* index_word = a.ChangeUint32ToWord(index_word32); 230 Node* index_word = a->ChangeUint32ToWord(index_word32);
233 231
234 Node* value_integer = a.ToInteger(context, value); 232 Node* value_integer = a->ToInteger(context, value);
235 Node* value_word32 = a.TruncateTaggedToWord32(context, value_integer); 233 Node* value_word32 = a->TruncateTaggedToWord32(context, value_integer);
236 234
237 CodeStubAssembler::Label u8(&a), u16(&a), u32(&a), other(&a); 235 CodeStubAssembler::Label u8(a), u16(a), u32(a), other(a);
238 int32_t case_values[] = { 236 int32_t case_values[] = {
239 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, 237 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE,
240 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, 238 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE,
241 }; 239 };
242 CodeStubAssembler::Label* case_labels[] = { 240 CodeStubAssembler::Label* case_labels[] = {
243 &u8, &u8, &u16, &u16, &u32, &u32, 241 &u8, &u8, &u16, &u16, &u32, &u32,
244 }; 242 };
245 a.Switch(instance_type, &other, case_values, case_labels, 243 a->Switch(instance_type, &other, case_values, case_labels,
246 arraysize(case_labels)); 244 arraysize(case_labels));
247 245
248 a.Bind(&u8); 246 a->Bind(&u8);
249 a.AtomicStore(MachineRepresentation::kWord8, backing_store, index_word, 247 a->AtomicStore(MachineRepresentation::kWord8, backing_store, index_word,
250 value_word32); 248 value_word32);
251 a.Return(value_integer); 249 a->Return(value_integer);
252 250
253 a.Bind(&u16); 251 a->Bind(&u16);
254 a.AtomicStore(MachineRepresentation::kWord16, backing_store, 252 a->AtomicStore(MachineRepresentation::kWord16, backing_store,
255 a.WordShl(index_word, 1), value_word32); 253 a->WordShl(index_word, 1), value_word32);
256 a.Return(value_integer); 254 a->Return(value_integer);
257 255
258 a.Bind(&u32); 256 a->Bind(&u32);
259 a.AtomicStore(MachineRepresentation::kWord32, backing_store, 257 a->AtomicStore(MachineRepresentation::kWord32, backing_store,
260 a.WordShl(index_word, 2), value_word32); 258 a->WordShl(index_word, 2), value_word32);
261 a.Return(value_integer); 259 a->Return(value_integer);
262 260
263 // This shouldn't happen, we've already validated the type. 261 // This shouldn't happen, we've already validated the type.
264 a.Bind(&other); 262 a->Bind(&other);
265 a.Return(a.Int32Constant(0)); 263 a->Return(a->Int32Constant(0));
266 } 264 }
267 265
268 } // namespace internal 266 } // namespace internal
269 } // namespace v8 267 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-regexp.cc ('k') | src/builtins/builtins-string.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698