Bug 1833484 - Optimize bytecode emission for Infinity, NaN and undefined where possible. r=arai

This is possible because once we are looking at the global we know that these values aren't
configurable and therefore have well known values.

Differential Revision: https://phabricator.services.mozilla.com/D178243
This commit is contained in:
Matthew Gaudet 2023-05-17 14:59:51 +00:00
Родитель ba1d4a0dfc
Коммит f0828bc714
2 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -463,6 +463,11 @@ static MOZ_ALWAYS_INLINE double GenericNaN() {
return mozilla::BitwiseCast<double>(detail::CanonicalizedNaNBits);
}
// Return the infinity the engine uses
static MOZ_ALWAYS_INLINE double Infinity() {
return mozilla::BitwiseCast<double>(detail::InfinityBits);
}
// Convert an arbitrary double to one compatible with JS::Value representation
// by replacing any NaN value with a canonical one.
static MOZ_ALWAYS_INLINE double CanonicalizeNaN(double d) {

Просмотреть файл

@ -12,6 +12,7 @@
#include "frontend/SharedContext.h"
#include "frontend/TDZCheckCache.h"
#include "frontend/ValueUsage.h"
#include "js/Value.h"
#include "vm/Opcodes.h"
using namespace js;
@ -44,9 +45,25 @@ bool NameOpEmitter::emitGet() {
return false;
}
} else {
if (!bce_->emitAtomOp(JSOp::GetGName, name_)) {
// [stack] VAL
return false;
// Some names on the global are not configurable and have fixed values
// which we can emit instead.
if (name_ == TaggedParserAtomIndex::WellKnown::undefined()) {
if (!bce_->emit1(JSOp::Undefined)) {
return false;
}
} else if (name_ == TaggedParserAtomIndex::WellKnown::NaN()) {
if (!bce_->emitDouble(JS::GenericNaN())) {
return false;
}
} else if (name_ == TaggedParserAtomIndex::WellKnown::Infinity()) {
if (!bce_->emitDouble(JS::Infinity())) {
return false;
}
} else {
if (!bce_->emitAtomOp(JSOp::GetGName, name_)) {
// [stack] VAL
return false;
}
}
}
break;