Commit 5077e794 authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[js] Replace max/min macros with calls to Math.max/Math.min

In the years since https://codereview.chromium.org/1331993004, a lot has
changed in v8: Math.max/min are now CSA builtins, with lowerings in
TF.

In a quick test on my machine of the microbenchmark on that CL
(modified with start and end values), I don't detect any difference
in speed between the macro versions on master and this version.

Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: I82d9d14c043fd2a112050cdbcb98a872bfb87b61
Reviewed-on: https://chromium-review.googlesource.com/664339Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47994}
parent eb0950d2
...@@ -15,6 +15,8 @@ var GetIterator; ...@@ -15,6 +15,8 @@ var GetIterator;
var GetMethod; var GetMethod;
var GlobalArray = global.Array; var GlobalArray = global.Array;
var InternalArray = utils.InternalArray; var InternalArray = utils.InternalArray;
var MathMax = global.Math.max;
var MathMin = global.Math.min;
var ObjectHasOwnProperty = global.Object.prototype.hasOwnProperty; var ObjectHasOwnProperty = global.Object.prototype.hasOwnProperty;
var ObjectToString = global.Object.prototype.toString; var ObjectToString = global.Object.prototype.toString;
var iteratorSymbol = utils.ImportNow("iterator_symbol"); var iteratorSymbol = utils.ImportNow("iterator_symbol");
...@@ -222,7 +224,7 @@ function SparseMove(array, start_i, del_count, len, num_additional_args) { ...@@ -222,7 +224,7 @@ function SparseMove(array, start_i, del_count, len, num_additional_args) {
// Move data to new array. // Move data to new array.
var new_array = new InternalArray( var new_array = new InternalArray(
// Clamp array length to 2^32-1 to avoid early RangeError. // Clamp array length to 2^32-1 to avoid early RangeError.
MINSIMPLE(len - del_count + num_additional_args, 0xffffffff)); MathMin(len - del_count + num_additional_args, 0xffffffff));
var big_indices; var big_indices;
var indices = %GetArrayKeys(array, len); var indices = %GetArrayKeys(array, len);
if (IS_NUMBER(indices)) { if (IS_NUMBER(indices)) {
...@@ -612,7 +614,7 @@ function ArraySliceFallback(start, end) { ...@@ -612,7 +614,7 @@ function ArraySliceFallback(start, end) {
if (end_i > len) end_i = len; if (end_i > len) end_i = len;
} }
var result = ArraySpeciesCreate(array, MAXSIMPLE(end_i - start_i, 0)); var result = ArraySpeciesCreate(array, MathMax(end_i - start_i, 0));
if (end_i < start_i) return result; if (end_i < start_i) return result;
...@@ -1081,28 +1083,28 @@ DEFINE_METHOD_LEN( ...@@ -1081,28 +1083,28 @@ DEFINE_METHOD_LEN(
target = TO_INTEGER(target); target = TO_INTEGER(target);
var to; var to;
if (target < 0) { if (target < 0) {
to = MAXSIMPLE(length + target, 0); to = MathMax(length + target, 0);
} else { } else {
to = MINSIMPLE(target, length); to = MathMin(target, length);
} }
start = TO_INTEGER(start); start = TO_INTEGER(start);
var from; var from;
if (start < 0) { if (start < 0) {
from = MAXSIMPLE(length + start, 0); from = MathMax(length + start, 0);
} else { } else {
from = MINSIMPLE(start, length); from = MathMin(start, length);
} }
end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
var final; var final;
if (end < 0) { if (end < 0) {
final = MAXSIMPLE(length + end, 0); final = MathMax(length + end, 0);
} else { } else {
final = MINSIMPLE(end, length); final = MathMin(end, length);
} }
var count = MINSIMPLE(final - from, length - to); var count = MathMin(final - from, length - to);
var direction = 1; var direction = 1;
if (from < to && to < (from + count)) { if (from < to && to < (from + count)) {
direction = -1; direction = -1;
......
...@@ -31,6 +31,7 @@ var GlobalRegExp = global.RegExp; ...@@ -31,6 +31,7 @@ var GlobalRegExp = global.RegExp;
var GlobalString = global.String; var GlobalString = global.String;
var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol"); var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol");
var InternalArray = utils.InternalArray; var InternalArray = utils.InternalArray;
var MathMax = global.Math.max;
var ObjectHasOwnProperty = global.Object.prototype.hasOwnProperty; var ObjectHasOwnProperty = global.Object.prototype.hasOwnProperty;
var ObjectKeys = global.Object.keys; var ObjectKeys = global.Object.keys;
var patternSymbol = utils.ImportNow("intl_pattern_symbol"); var patternSymbol = utils.ImportNow("intl_pattern_symbol");
...@@ -1219,7 +1220,7 @@ function SetNumberFormatDigitOptions(internalOptions, options, ...@@ -1219,7 +1220,7 @@ function SetNumberFormatDigitOptions(internalOptions, options,
mnfdDefault); mnfdDefault);
defineWEProperty(internalOptions, 'minimumFractionDigits', mnfd); defineWEProperty(internalOptions, 'minimumFractionDigits', mnfd);
var mxfdActualDefault = MAXSIMPLE(mnfd, mxfdDefault); var mxfdActualDefault = MathMax(mnfd, mxfdDefault);
var mxfd = getNumberOption(options, 'maximumFractionDigits', mnfd, 20, var mxfd = getNumberOption(options, 'maximumFractionDigits', mnfd, 20,
mxfdActualDefault); mxfdActualDefault);
......
...@@ -112,7 +112,3 @@ define PROPERTY_FILTER_NONE = 0; ...@@ -112,7 +112,3 @@ define PROPERTY_FILTER_NONE = 0;
# Check whether debug is active. # Check whether debug is active.
define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0); define DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
# Min and max
macro MAXSIMPLE(a, b) = ((a) > (b) ? (a) : (b));
macro MINSIMPLE(a, b) = ((a) > (b) ? (b) : (a));
...@@ -25,6 +25,8 @@ var InnerArrayJoin; ...@@ -25,6 +25,8 @@ var InnerArrayJoin;
var InnerArraySort; var InnerArraySort;
var InnerArrayToLocaleString; var InnerArrayToLocaleString;
var InternalArray = utils.InternalArray; var InternalArray = utils.InternalArray;
var MathMax = global.Math.max;
var MathMin = global.Math.min;
var iteratorSymbol = utils.ImportNow("iterator_symbol"); var iteratorSymbol = utils.ImportNow("iterator_symbol");
var speciesSymbol = utils.ImportNow("species_symbol"); var speciesSymbol = utils.ImportNow("species_symbol");
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
...@@ -204,15 +206,15 @@ function NAMESubArray(begin, end) { ...@@ -204,15 +206,15 @@ function NAMESubArray(begin, end) {
} }
if (beginInt < 0) { if (beginInt < 0) {
beginInt = MAXSIMPLE(0, srcLength + beginInt); beginInt = MathMax(0, srcLength + beginInt);
} else { } else {
beginInt = MINSIMPLE(beginInt, srcLength); beginInt = MathMin(beginInt, srcLength);
} }
if (endInt < 0) { if (endInt < 0) {
endInt = MAXSIMPLE(0, srcLength + endInt); endInt = MathMax(0, srcLength + endInt);
} else { } else {
endInt = MINSIMPLE(endInt, srcLength); endInt = MathMin(endInt, srcLength);
} }
if (endInt < beginInt) { if (endInt < beginInt) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment