28 #ifndef V8_CONVERSIONS_INL_H_
29 #define V8_CONVERSIONS_INL_H_
70 const double k2Pow52 = 4503599627370496.0;
81 return negative ? ~result + 1 : result;
91 return (x >= 0) ? std::floor(x) : std::ceil(x);
104 if (exponent > 31)
return 0;
110 template <
class Iterator,
class EndMark>
113 const char* substring) {
114 ASSERT(**current == *substring);
115 for (substring++; *substring !=
'\0'; substring++) {
117 if (*current == end || **current != *substring)
return false;
126 template <
class Iterator,
class EndMark>
130 while (*current != end) {
139 template <
int radix_log_2,
class Iterator,
class EndMark>
144 bool allow_trailing_junk) {
148 while (*current ==
'0') {
150 if (current == end)
return SignedZero(negative);
155 const int radix = (1 << radix_log_2);
159 if (*current >=
'0' && *current <=
'9' && *current <
'0' + radix) {
160 digit =
static_cast<char>(*current) -
'0';
161 }
else if (radix > 10 && *current >=
'a' && *current <
'a' + radix - 10) {
162 digit =
static_cast<char>(*current) -
'a' + 10;
163 }
else if (radix > 10 && *current >=
'A' && *current <
'A' + radix - 10) {
164 digit =
static_cast<char>(*current) -
'A' + 10;
166 if (allow_trailing_junk ||
174 number = number * radix + digit;
175 int overflow =
static_cast<int>(number >> 53);
179 int overflow_bits_count = 1;
180 while (overflow > 1) {
181 overflow_bits_count++;
185 int dropped_bits_mask = ((1 << overflow_bits_count) - 1);
186 int dropped_bits =
static_cast<int>(number) & dropped_bits_mask;
187 number >>= overflow_bits_count;
188 exponent = overflow_bits_count;
190 bool zero_tail =
true;
193 if (current == end || !
isDigit(*current, radix))
break;
194 zero_tail = zero_tail && *current ==
'0';
195 exponent += radix_log_2;
198 if (!allow_trailing_junk &&
203 int middle_value = (1 << (overflow_bits_count - 1));
204 if (dropped_bits > middle_value) {
206 }
else if (dropped_bits == middle_value) {
209 if ((number & 1) != 0 || !zero_tail) {
215 if ((number & (static_cast<int64_t>(1) << 53)) != 0) {
222 }
while (current != end);
224 ASSERT(number < ((int64_t)1 << 53));
225 ASSERT(static_cast<int64_t>(static_cast<double>(number)) == number);
229 if (number == 0)
return -0.0;
232 return static_cast<double>(number);
236 return std::ldexp(static_cast<double>(negative ? -number : number), exponent);
240 template <
class Iterator,
class EndMark>
245 const bool allow_trailing_junk =
true;
249 return empty_string_val;
253 bool leading_zero =
false;
255 if (*current ==
'+') {
258 if (current == end) {
261 }
else if (*current ==
'-') {
263 if (current == end) {
272 if (*current ==
'0') {
274 if (current == end)
return SignedZero(negative);
275 if (*current ==
'x' || *current ==
'X') {
283 }
else if (radix == 16) {
284 if (*current ==
'0') {
287 if (current == end)
return SignedZero(negative);
288 if (*current ==
'x' || *current ==
'X') {
300 while (*current ==
'0') {
303 if (current == end)
return SignedZero(negative);
306 if (!leading_zero && !
isDigit(*current, radix)) {
313 return InternalStringToIntDouble<1>(
314 unicode_cache, current, end,
negative, allow_trailing_junk);
316 return InternalStringToIntDouble<2>(
317 unicode_cache, current, end,
negative, allow_trailing_junk);
319 return InternalStringToIntDouble<3>(
320 unicode_cache, current, end,
negative, allow_trailing_junk);
323 return InternalStringToIntDouble<4>(
324 unicode_cache, current, end,
negative, allow_trailing_junk);
327 return InternalStringToIntDouble<5>(
328 unicode_cache, current, end,
negative, allow_trailing_junk);
339 const int kBufferSize = kMaxSignificantDigits + 2;
340 char buffer[kBufferSize];
342 while (*current >=
'0' && *current <=
'9') {
343 if (buffer_pos <= kMaxSignificantDigits) {
346 ASSERT(buffer_pos < kBufferSize);
347 buffer[buffer_pos++] =
static_cast<char>(*current);
350 if (current == end)
break;
353 if (!allow_trailing_junk &&
359 buffer[buffer_pos] =
'\0';
361 return negative ? -
Strtod(buffer_vector, 0) :
Strtod(buffer_vector, 0);
369 int lim_0 =
'0' + (radix < 10 ? radix : 10);
370 int lim_a =
'a' + (radix - 10);
371 int lim_A =
'A' + (radix - 10);
383 unsigned int part = 0, multiplier = 1;
386 if (*current >=
'0' && *current < lim_0) {
388 }
else if (*current >=
'a' && *current < lim_a) {
389 d = *current -
'a' + 10;
390 }
else if (*current >=
'A' && *current < lim_A) {
391 d = *current -
'A' + 10;
401 const unsigned int kMaximumMultiplier = 0xffffffff
U / 36;
402 uint32_t m = multiplier * radix;
403 if (m > kMaximumMultiplier)
break;
404 part = part * radix + d;
406 ASSERT(multiplier > part);
409 if (current == end) {
416 v = v * multiplier + part;
419 if (!allow_trailing_junk &&
424 return negative ? -v : v;
433 template <
class Iterator,
class EndMark>
438 double empty_string_val) {
448 return empty_string_val;
455 char buffer[kBufferSize];
461 int significant_digits = 0;
462 int insignificant_digits = 0;
463 bool nonzero_digit_dropped =
false;
473 if (*current ==
'+') {
478 }
else if (*current ==
'-') {
484 static const char kInfinityString[] =
"Infinity";
485 if (*current == kInfinityString[0]) {
490 if (!allow_trailing_junk &&
499 bool leading_zero =
false;
500 if (*current ==
'0') {
502 if (current == end)
return SignedZero(sign == NEGATIVE);
507 if ((flags &
ALLOW_HEX) && (*current ==
'x' || *current ==
'X')) {
509 if (current == end || !
isDigit(*current, 16) || sign !=
NONE) {
513 return InternalStringToIntDouble<4>(unicode_cache,
517 allow_trailing_junk);
520 }
else if ((flags &
ALLOW_OCTAL) && (*current ==
'o' || *current ==
'O')) {
522 if (current == end || !
isDigit(*current, 8) || sign !=
NONE) {
526 return InternalStringToIntDouble<3>(unicode_cache,
530 allow_trailing_junk);
533 }
else if ((flags &
ALLOW_BINARY) && (*current ==
'b' || *current ==
'B')) {
539 return InternalStringToIntDouble<1>(unicode_cache,
543 allow_trailing_junk);
547 while (*current ==
'0') {
549 if (current == end)
return SignedZero(sign == NEGATIVE);
556 while (*current >=
'0' && *current <=
'9') {
558 ASSERT(buffer_pos < kBufferSize);
559 buffer[buffer_pos++] =
static_cast<char>(*current);
560 significant_digits++;
563 insignificant_digits++;
564 nonzero_digit_dropped = nonzero_digit_dropped || *current !=
'0';
566 octal = octal && *current <
'8';
568 if (current == end)
goto parsing_done;
571 if (significant_digits == 0) {
575 if (*current ==
'.') {
577 if (octal)
goto parsing_done;
580 if (current == end) {
581 if (significant_digits == 0 && !leading_zero) {
588 if (significant_digits == 0) {
592 while (*current ==
'0') {
594 if (current == end)
return SignedZero(sign == NEGATIVE);
601 while (*current >=
'0' && *current <=
'9') {
603 ASSERT(buffer_pos < kBufferSize);
604 buffer[buffer_pos++] =
static_cast<char>(*current);
605 significant_digits++;
609 nonzero_digit_dropped = nonzero_digit_dropped || *current !=
'0';
612 if (current == end)
goto parsing_done;
616 if (!leading_zero && exponent == 0 && significant_digits == 0) {
625 if (*current ==
'e' || *current ==
'E') {
628 if (current == end) {
629 if (allow_trailing_junk) {
636 if (*current ==
'+' || *current ==
'-') {
637 sign =
static_cast<char>(*current);
639 if (current == end) {
640 if (allow_trailing_junk) {
648 if (current == end || *current < '0' || *current >
'9') {
649 if (allow_trailing_junk) {
656 const int max_exponent = INT_MAX / 2;
657 ASSERT(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2);
661 int digit = *current -
'0';
662 if (num >= max_exponent / 10
663 && !(num == max_exponent / 10 && digit <= max_exponent % 10)) {
666 num = num * 10 + digit;
669 }
while (current != end && *current >=
'0' && *current <=
'9');
671 exponent += (sign ==
'-' ? -num : num);
674 if (!allow_trailing_junk &&
680 exponent += insignificant_digits;
683 return InternalStringToIntDouble<3>(unicode_cache,
687 allow_trailing_junk);
690 if (nonzero_digit_dropped) {
691 buffer[buffer_pos++] =
'1';
696 buffer[buffer_pos] =
'\0';
699 return (sign == NEGATIVE) ? -converted : converted;
704 #endif // V8_CONVERSIONS_INL_H_
#define SLOW_ASSERT(condition)
uint64_t Significand() const
double InternalStringToDouble(UnicodeCache *unicode_cache, Iterator current, EndMark end, int flags, double empty_string_val)
double DoubleToInteger(double x)
bool SubStringEquals(Iterator *current, EndMark end, const char *substring)
const uint64_t kQuietNaNMask
bool isBinaryDigit(int x)
bool isDigit(int x, int radix)
double InternalStringToInt(UnicodeCache *unicode_cache, Iterator current, EndMark end, int radix)
#define ASSERT(condition)
static const int kSignificandSize
double Strtod(Vector< const char > buffer, int exponent)
double SignedZero(bool negative)
static const uint64_t kSignMask
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage including flags
static void MemCopy(void *dest, const void *src, size_t size)
unsigned int FastD2UI(double x)
double uint64_to_double(uint64_t d64)
double InternalStringToIntDouble(UnicodeCache *unicode_cache, Iterator current, EndMark end, bool negative, bool allow_trailing_junk)
bool AdvanceToNonspace(UnicodeCache *unicode_cache, Iterator *current, EndMark end)
const int kMaxSignificantDigits
int32_t DoubleToInt32(double x)
bool IsWhiteSpaceOrLineTerminator(unibrow::uchar c)