OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 double value = HeapNumber::cast(obj)->value(); | 213 double value = HeapNumber::cast(obj)->value(); |
214 int int_value = FastD2I(value); | 214 int int_value = FastD2I(value); |
215 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { | 215 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { |
216 return Smi::FromInt(int_value); | 216 return Smi::FromInt(int_value); |
217 } | 217 } |
218 } | 218 } |
219 return isolate->heap()->nan_value(); | 219 return isolate->heap()->nan_value(); |
220 } | 220 } |
221 | 221 |
222 | 222 |
223 RUNTIME_FUNCTION(Runtime_NumberAdd) { | |
224 HandleScope scope(isolate); | |
225 DCHECK(args.length() == 2); | |
226 | |
227 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
228 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | |
229 return *isolate->factory()->NewNumber(x + y); | |
230 } | |
231 | |
232 | |
233 RUNTIME_FUNCTION(Runtime_NumberSub) { | |
234 HandleScope scope(isolate); | |
235 DCHECK(args.length() == 2); | |
236 | |
237 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
238 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | |
239 return *isolate->factory()->NewNumber(x - y); | |
240 } | |
241 | |
242 | |
243 RUNTIME_FUNCTION(Runtime_NumberMul) { | |
244 HandleScope scope(isolate); | |
245 DCHECK(args.length() == 2); | |
246 | |
247 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
248 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | |
249 return *isolate->factory()->NewNumber(x * y); | |
250 } | |
251 | |
252 | |
253 RUNTIME_FUNCTION(Runtime_NumberDiv) { | |
254 HandleScope scope(isolate); | |
255 DCHECK(args.length() == 2); | |
256 | |
257 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
258 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | |
259 return *isolate->factory()->NewNumber(x / y); | |
260 } | |
261 | |
262 | |
263 RUNTIME_FUNCTION(Runtime_NumberMod) { | |
264 HandleScope scope(isolate); | |
265 DCHECK(args.length() == 2); | |
266 | |
267 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
268 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | |
269 return *isolate->factory()->NewNumber(modulo(x, y)); | |
270 } | |
271 | |
272 | |
273 RUNTIME_FUNCTION(Runtime_NumberImul) { | 223 RUNTIME_FUNCTION(Runtime_NumberImul) { |
274 HandleScope scope(isolate); | 224 HandleScope scope(isolate); |
275 DCHECK(args.length() == 2); | 225 DCHECK(args.length() == 2); |
276 | 226 |
277 // We rely on implementation-defined behavior below, but at least not on | 227 // We rely on implementation-defined behavior below, but at least not on |
278 // undefined behavior. | 228 // undefined behavior. |
279 CONVERT_NUMBER_CHECKED(uint32_t, x, Int32, args[0]); | 229 CONVERT_NUMBER_CHECKED(uint32_t, x, Int32, args[0]); |
280 CONVERT_NUMBER_CHECKED(uint32_t, y, Int32, args[1]); | 230 CONVERT_NUMBER_CHECKED(uint32_t, y, Int32, args[1]); |
281 int32_t product = static_cast<int32_t>(x * y); | 231 int32_t product = static_cast<int32_t>(x * y); |
282 return *isolate->factory()->NewNumberFromInt(product); | 232 return *isolate->factory()->NewNumberFromInt(product); |
283 } | 233 } |
284 | 234 |
285 | 235 |
286 RUNTIME_FUNCTION(Runtime_NumberOr) { | |
287 HandleScope scope(isolate); | |
288 DCHECK(args.length() == 2); | |
289 | |
290 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); | |
291 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); | |
292 return *isolate->factory()->NewNumberFromInt(x | y); | |
293 } | |
294 | |
295 | |
296 RUNTIME_FUNCTION(Runtime_NumberAnd) { | |
297 HandleScope scope(isolate); | |
298 DCHECK(args.length() == 2); | |
299 | |
300 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); | |
301 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); | |
302 return *isolate->factory()->NewNumberFromInt(x & y); | |
303 } | |
304 | |
305 | |
306 RUNTIME_FUNCTION(Runtime_NumberXor) { | |
307 HandleScope scope(isolate); | |
308 DCHECK(args.length() == 2); | |
309 | |
310 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); | |
311 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); | |
312 return *isolate->factory()->NewNumberFromInt(x ^ y); | |
313 } | |
314 | |
315 | |
316 RUNTIME_FUNCTION(Runtime_NumberShl) { | |
317 HandleScope scope(isolate); | |
318 DCHECK(args.length() == 2); | |
319 | |
320 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); | |
321 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); | |
322 return *isolate->factory()->NewNumberFromInt(x << (y & 0x1f)); | |
323 } | |
324 | |
325 | |
326 RUNTIME_FUNCTION(Runtime_NumberShr) { | |
327 HandleScope scope(isolate); | |
328 DCHECK(args.length() == 2); | |
329 | |
330 CONVERT_NUMBER_CHECKED(uint32_t, x, Uint32, args[0]); | |
331 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); | |
332 return *isolate->factory()->NewNumberFromUint(x >> (y & 0x1f)); | |
333 } | |
334 | |
335 | |
336 RUNTIME_FUNCTION(Runtime_NumberSar) { | |
337 HandleScope scope(isolate); | |
338 DCHECK(args.length() == 2); | |
339 | |
340 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); | |
341 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); | |
342 return *isolate->factory()->NewNumberFromInt( | |
343 ArithmeticShiftRight(x, y & 0x1f)); | |
344 } | |
345 | |
346 | |
347 RUNTIME_FUNCTION(Runtime_NumberEquals) { | 236 RUNTIME_FUNCTION(Runtime_NumberEquals) { |
348 SealHandleScope shs(isolate); | 237 SealHandleScope shs(isolate); |
349 DCHECK(args.length() == 2); | 238 DCHECK(args.length() == 2); |
350 | 239 |
351 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 240 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
352 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 241 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
353 if (std::isnan(x)) return Smi::FromInt(NOT_EQUAL); | 242 if (std::isnan(x)) return Smi::FromInt(NOT_EQUAL); |
354 if (std::isnan(y)) return Smi::FromInt(NOT_EQUAL); | 243 if (std::isnan(y)) return Smi::FromInt(NOT_EQUAL); |
355 if (x == y) return Smi::FromInt(EQUAL); | 244 if (x == y) return Smi::FromInt(EQUAL); |
356 Object* result; | 245 Object* result; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 357 } |
469 | 358 |
470 | 359 |
471 RUNTIME_FUNCTION(Runtime_GetRootNaN) { | 360 RUNTIME_FUNCTION(Runtime_GetRootNaN) { |
472 SealHandleScope shs(isolate); | 361 SealHandleScope shs(isolate); |
473 DCHECK(args.length() == 0); | 362 DCHECK(args.length() == 0); |
474 return isolate->heap()->nan_value(); | 363 return isolate->heap()->nan_value(); |
475 } | 364 } |
476 } // namespace internal | 365 } // namespace internal |
477 } // namespace v8 | 366 } // namespace v8 |
OLD | NEW |