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

Side by Side Diff: src/runtime/runtime-numbers.cc

Issue 2126453002: [intrinsic] Drop the %_ValueOf intrinsic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix noi18n build (narf) Created 4 years, 5 months 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/runtime/runtime-internal.cc ('k') | test/cctest/compiler/test-run-intrinsics.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 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"
11 #include "src/isolate-inl.h" 11 #include "src/isolate-inl.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 RUNTIME_FUNCTION(Runtime_NumberToRadixString) {
17 HandleScope scope(isolate);
18 DCHECK(args.length() == 2);
19 CONVERT_SMI_ARG_CHECKED(radix, 1);
20 CHECK(2 <= radix && radix <= 36);
21
22 // Fast case where the result is a one character string.
23 if (args[0]->IsSmi()) {
24 int value = args.smi_at(0);
25 if (value >= 0 && value < radix) {
26 // Character array used for conversion.
27 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
28 return *isolate->factory()->LookupSingleCharacterStringFromCode(
29 kCharTable[value]);
30 }
31 }
32
33 // Slow case.
34 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
35 if (std::isnan(value)) {
36 return isolate->heap()->nan_string();
37 }
38 if (std::isinf(value)) {
39 if (value < 0) {
40 return isolate->heap()->minus_infinity_string();
41 }
42 return isolate->heap()->infinity_string();
43 }
44 char* str = DoubleToRadixCString(value, radix);
45 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
46 DeleteArray(str);
47 return *result;
48 }
49
50
51 RUNTIME_FUNCTION(Runtime_NumberToFixed) {
52 HandleScope scope(isolate);
53 DCHECK(args.length() == 2);
54
55 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
56 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
57 int f = FastD2IChecked(f_number);
58 // See DoubleToFixedCString for these constants:
59 CHECK(f >= 0 && f <= 20);
60 CHECK(!Double(value).IsSpecial());
61 char* str = DoubleToFixedCString(value, f);
62 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
63 DeleteArray(str);
64 return *result;
65 }
66
67
68 RUNTIME_FUNCTION(Runtime_NumberToExponential) {
69 HandleScope scope(isolate);
70 DCHECK(args.length() == 2);
71
72 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
73 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
74 int f = FastD2IChecked(f_number);
75 CHECK(f >= -1 && f <= 20);
76 CHECK(!Double(value).IsSpecial());
77 char* str = DoubleToExponentialCString(value, f);
78 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
79 DeleteArray(str);
80 return *result;
81 }
82
83
84 RUNTIME_FUNCTION(Runtime_NumberToPrecision) {
85 HandleScope scope(isolate);
86 DCHECK(args.length() == 2);
87
88 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
89 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
90 int f = FastD2IChecked(f_number);
91 CHECK(f >= 1 && f <= 21);
92 CHECK(!Double(value).IsSpecial());
93 char* str = DoubleToPrecisionCString(value, f);
94 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
95 DeleteArray(str);
96 return *result;
97 }
98
99
100 RUNTIME_FUNCTION(Runtime_IsValidSmi) { 16 RUNTIME_FUNCTION(Runtime_IsValidSmi) {
101 SealHandleScope shs(isolate); 17 SealHandleScope shs(isolate);
102 DCHECK(args.length() == 1); 18 DCHECK(args.length() == 1);
103 19
104 CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]); 20 CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]);
105 return isolate->heap()->ToBoolean(Smi::IsValid(number)); 21 return isolate->heap()->ToBoolean(Smi::IsValid(number));
106 } 22 }
107 23
108 24
109 RUNTIME_FUNCTION(Runtime_StringToNumber) { 25 RUNTIME_FUNCTION(Runtime_StringToNumber) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 217
302 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) { 218 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) {
303 HandleScope scope(isolate); 219 HandleScope scope(isolate);
304 DCHECK(args.length() == 0); 220 DCHECK(args.length() == 0);
305 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32); 221 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32);
306 } 222 }
307 223
308 224
309 } // namespace internal 225 } // namespace internal
310 } // namespace v8 226 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/cctest/compiler/test-run-intrinsics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698