Commit a06b4603 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Speed up ValueType::element_size_bytes

It turns out that Liftoff often needs to know the size of a value in
bytes. Currently we are loading the size_log_2 from an array and then
performing a shift by that amount. We can slightly speed this up by just
loading the correct value directly.

Drive-by: Use {int8_t} for the internal array, since all values will
easily fit in that range.

R=thibaudm@chromium.org

Bug: v8:10576
Change-Id: I1b832ba404ff9913e2272d332f312b371b6ce3d4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2267302Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68557}
parent 07e71020
......@@ -122,19 +122,29 @@ class ValueType {
constexpr uint32_t raw_bit_field() const { return bit_field_; }
constexpr int element_size_log2() const {
CONSTEXPR_DCHECK(kStmt != kind());
CONSTEXPR_DCHECK(kBottom != kind());
constexpr int kElementSizeLog2[] = {
constexpr int8_t kElementSizeLog2[] = {
#define ELEM_SIZE_LOG2(kind, log2Size, ...) log2Size,
FOREACH_VALUE_TYPE(ELEM_SIZE_LOG2)
#undef ELEM_SIZE_LOG2
};
return kElementSizeLog2[kind()];
int size_log_2 = kElementSizeLog2[kind()];
CONSTEXPR_DCHECK(size_log_2 >= 0);
return size_log_2;
}
constexpr int element_size_bytes() const { return 1 << element_size_log2(); }
constexpr int element_size_bytes() const {
constexpr int8_t kElementSize[] = {
#define ELEM_SIZE_LOG2(kind, log2Size, ...) \
log2Size == -1 ? -1 : (1 << std::max(0, log2Size)),
FOREACH_VALUE_TYPE(ELEM_SIZE_LOG2)
#undef ELEM_SIZE_LOG2
};
int size = kElementSize[kind()];
CONSTEXPR_DCHECK(size > 0);
return size;
}
constexpr bool operator==(ValueType other) const {
return bit_field_ == other.bit_field_;
......
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