// Copyright 2024 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
// Returns the single-precision floating-point value for the given FLI.S // immediate encoding (imm5). // Precondition: imm5 <= 31 float GetFLISValue(uint8_t imm5) {
MOZ_ASSERT(is_uint5(imm5)); // imm5=0: -1.0 (the only negative value) if (imm5 == 0) { return -1.0f;
} // imm5=1: minimum positive normal (FLT_MIN) if (imm5 == 1) { return1.17549435e-38f; // FLT_MIN = 2^(-126)
} // imm5=30: +infinity if (imm5 == 30) {
uint32_t bits = 0x7f800000; // exp=255, mantissa=0 return mozilla::BitwiseCast<float>(bits);
} // imm5=31: Canonical NaN if (imm5 == 31) { return mozilla::BitwiseCast<float>(kFP32DefaultNaN);
} // imm5=2..29: use lookup table return mozilla::BitwiseCast<float>(kLoadFP32ImmArr[imm5 - 2]);
}
// Returns the double-precision floating-point value for the given FLI.D // immediate encoding (imm5). // Precondition: imm5 <= 31 // // For imm5 != 1, the values are the same as single-precision (just represented // in double format). For imm5=1, DBL_MIN differs from FLT_MIN. double GetFLIDValue(uint8_t imm5) {
MOZ_ASSERT(is_uint5(imm5)); if (imm5 == 1) { return mozilla::BitwiseCast<double>(kFP64DblMin);
} // For all other imm5 values, convert the single-precision value to double. // The numerical value is the same, just with different representation. returnstatic_cast<double>(GetFLISValue(imm5));
}
// Returns the FLI.S immediate encoding (imm5) for the given single-precision // floating-point value, or -1 if the value cannot be encoded by FLI.S. // This is used by the compiler to determine if a constant can be loaded // using the FLI.S instruction. int GetImm5ForFLIS(float value) { // Handle special values first
// Check for NaN (imm5=31: Canonical NaN) if (std::isnan(value)) { // Only canonical NaN is encodable
uint32_t bits = mozilla::BitwiseCast<uint32_t>(value); return (bits == kFP32DefaultNaN) ? 31 : -1;
}
// Check for infinity (imm5=30: +∞) if (std::isinf(value)) { return (value > 0.0f) ? 30 : -1; // Only +∞ is encodable
}
// Check for minimum positive normal (imm5=1) // FLT_MIN = 2^(-126) if (mozilla::BitwiseCast<uint32_t>(value) == kFP32FltMin) { return1;
}
// Get the bit representation
uint32_t bits = mozilla::BitwiseCast<uint32_t>(value);
// Extract sign
uint32_t sign = (bits >> 31) & 1;
// For negative values, check the absolute value (clear sign bit)
uint32_t abs_bits = bits & 0x7FFFFFFF;
// FLI constants only have mantissa bits in the top 2 positions // Check if lower 21 bits of mantissa are zero
uint32_t mantissa = abs_bits & 0x7FFFFF; if ((mantissa & 0x1FFFFF) != 0) { return -1;
}
// Binary search in the lookup table (using absolute value) auto it = std::lower_bound(std::begin(kLoadFP32ImmArr),
std::end(kLoadFP32ImmArr), abs_bits);
if (it == std::end(kLoadFP32ImmArr) || *it != abs_bits) { return -1; // Not found in table
}
int entry = static_cast<int>(it - std::begin(kLoadFP32ImmArr)) + 2;
// Handle negative values: only -1.0 (entry 16 with sign bit) is valid if (sign) { return (entry == 16) ? 0 : -1;
}
return entry;
}
// Returns the FLI.D immediate encoding (imm5) for the given double-precision // floating-point value, or -1 if the value cannot be encoded by FLI.D. // int GetImm5ForFLID(double value) { if (std::isnan(value)) {
uint64_t bits = mozilla::BitwiseCast<uint64_t>(value); return (bits == kFP64DefaultNaN) ? 31 : -1;
} if (mozilla::BitwiseCast<uint64_t>(value) == kFP64DblMin) { // DBL_MIN return1;
}
// This check is always false for all values in the kLoadFP32ImmArr constant // table, since all FLI-defined values are exactly representable in both float // and double. float fvalue = static_cast<float>(value); if (static_cast<double>(fvalue) != value) { return -1;
} int result = GetImm5ForFLIS(fvalue); // imm5=1 for FLI.D is DBL_MIN, already handled above. // If GetImm5ForFLIS returned 1 here, the value is FLT_MIN (2^-126) // which is NOT encodable by FLI.D. if (result == 1) { return -1;
} return result;
}
} // namespace js::jit
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.