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

Unified Diff: src/runtime/runtime-numbers.cc

Issue 2117273002: Revert of [intrinsic] Drop the %_ValueOf intrinsic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-numbers.cc
diff --git a/src/runtime/runtime-numbers.cc b/src/runtime/runtime-numbers.cc
index 9f43c0acfceeeff5bfec4d3fca72ebbf41830f2d..edd83bc5e80adb19b31ec41ff1dbe1a738658e54 100644
--- a/src/runtime/runtime-numbers.cc
+++ b/src/runtime/runtime-numbers.cc
@@ -12,6 +12,90 @@
namespace v8 {
namespace internal {
+
+RUNTIME_FUNCTION(Runtime_NumberToRadixString) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_SMI_ARG_CHECKED(radix, 1);
+ CHECK(2 <= radix && radix <= 36);
+
+ // Fast case where the result is a one character string.
+ if (args[0]->IsSmi()) {
+ int value = args.smi_at(0);
+ if (value >= 0 && value < radix) {
+ // Character array used for conversion.
+ static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+ return *isolate->factory()->LookupSingleCharacterStringFromCode(
+ kCharTable[value]);
+ }
+ }
+
+ // Slow case.
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0);
+ if (std::isnan(value)) {
+ return isolate->heap()->nan_string();
+ }
+ if (std::isinf(value)) {
+ if (value < 0) {
+ return isolate->heap()->minus_infinity_string();
+ }
+ return isolate->heap()->infinity_string();
+ }
+ char* str = DoubleToRadixCString(value, radix);
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
+
+RUNTIME_FUNCTION(Runtime_NumberToFixed) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0);
+ CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
+ int f = FastD2IChecked(f_number);
+ // See DoubleToFixedCString for these constants:
+ CHECK(f >= 0 && f <= 20);
+ CHECK(!Double(value).IsSpecial());
+ char* str = DoubleToFixedCString(value, f);
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
+
+RUNTIME_FUNCTION(Runtime_NumberToExponential) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0);
+ CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
+ int f = FastD2IChecked(f_number);
+ CHECK(f >= -1 && f <= 20);
+ CHECK(!Double(value).IsSpecial());
+ char* str = DoubleToExponentialCString(value, f);
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
+
+RUNTIME_FUNCTION(Runtime_NumberToPrecision) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+
+ CONVERT_DOUBLE_ARG_CHECKED(value, 0);
+ CONVERT_DOUBLE_ARG_CHECKED(f_number, 1);
+ int f = FastD2IChecked(f_number);
+ CHECK(f >= 1 && f <= 21);
+ CHECK(!Double(value).IsSpecial());
+ char* str = DoubleToPrecisionCString(value, f);
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
RUNTIME_FUNCTION(Runtime_IsValidSmi) {
SealHandleScope shs(isolate);
« 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