tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit bc3082c9357c819bce6156dd6c42da1fc00415ec
parent 8705f290a1a4e82a0bd18c8966af6f1183b5eebe
Author: Rong "Mantle" Bao <webmaster@csmantle.top>
Date:   Fri, 12 Dec 2025 14:17:58 +0000

Bug 2004879 - [riscv64] Part 4: Extract next link getter into Assembler::jumpChainGetNextLink. r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D275570

Diffstat:
Mjs/src/jit/riscv64/Assembler-riscv64.cpp | 33++++++++++++++++++---------------
Mjs/src/jit/riscv64/Assembler-riscv64.h | 3++-
2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/js/src/jit/riscv64/Assembler-riscv64.cpp b/js/src/jit/riscv64/Assembler-riscv64.cpp @@ -1011,18 +1011,23 @@ int Assembler::jumpChainTargetAt(Instruction* instruction, BufferOffset pos, } } -uint32_t Assembler::jumpChainNextLink(Label* L, bool is_internal) { - MOZ_ASSERT(L->used()); - BufferOffset pos(L); +BufferOffset Assembler::jumpChainGetNextLink(BufferOffset pos, + bool is_internal) { int link = jumpChainTargetAt(pos, is_internal); - if (link == kEndOfChain) { + return link == kEndOfChain ? BufferOffset() : BufferOffset(link); +} + +uint32_t Assembler::jumpChainUseNextLink(Label* L, bool is_internal) { + MOZ_ASSERT(L->used()); + BufferOffset link = jumpChainGetNextLink(BufferOffset(L), is_internal); + if (!link.assigned()) { L->reset(); return LabelBase::INVALID_OFFSET; } - MOZ_ASSERT(link >= 0); - DEBUG_PRINTF("next: %p to offset %d\n", L, link); - L->use(link); - return link; + int offset = link.getOffset(); + DEBUG_PRINTF("next: %p to offset %d\n", L, offset); + L->use(offset); + return offset; } void Assembler::bind(Label* label, BufferOffset boff) { @@ -1036,7 +1041,7 @@ void Assembler::bind(Label* label, BufferOffset boff) { do { // A used label holds a link to branch that uses it. - // It's okay we use it here since jumpChainNextLink() mutates `label`. + // It's okay we use it here since jumpChainUseNextLink() mutates `label`. BufferOffset b(label); DEBUG_PRINTF("\tbind next:%d\n", b.getOffset()); // Even a 0 offset may be invalid if we're out of memory. @@ -1045,7 +1050,7 @@ void Assembler::bind(Label* label, BufferOffset boff) { } int fixup_pos = b.getOffset(); int dist = dest.getOffset() - fixup_pos; - next = jumpChainNextLink(label, false); + next = jumpChainUseNextLink(label, false); DEBUG_PRINTF( "\t%p fixup: %d next: %u dest: %d dist: %d nextOffset: %d " "currOffset: %d\n", @@ -1188,8 +1193,7 @@ int32_t Assembler::branchLongOffsetHelper(Label* L) { BufferOffset exbr; do { exbr = next; - const int link = jumpChainTargetAt(next, false); - next = link == kEndOfChain ? BufferOffset() : BufferOffset(link); + next = jumpChainGetNextLink(next, false); } while (next.assigned()); mozilla::DebugOnly<bool> ok = jumpChainPutTargetAt(exbr, next_instr_offset); MOZ_ASSERT(ok, "Still can't reach list head"); @@ -1276,8 +1280,7 @@ int32_t Assembler::branchOffsetHelper(Label* L, OffsetSize bits) { BufferOffset exbr; do { exbr = next; - const int link = jumpChainTargetAt(next, false); - next = link == kEndOfChain ? BufferOffset() : BufferOffset(link); + next = jumpChainGetNextLink(next, false); } while (next.assigned()); mozilla::DebugOnly<bool> ok = jumpChainPutTargetAt(exbr, next_instr_offset); MOZ_ASSERT(ok, "Still can't reach list head"); @@ -1506,7 +1509,7 @@ void Assembler::retarget(Label* label, Label* target) { // Find the head of the use chain for label. do { - next = jumpChainNextLink(label, false); + next = jumpChainUseNextLink(label, false); labelBranchOffset = BufferOffset(next); } while (next != LabelBase::INVALID_OFFSET); diff --git a/js/src/jit/riscv64/Assembler-riscv64.h b/js/src/jit/riscv64/Assembler-riscv64.h @@ -365,7 +365,8 @@ class Assembler : public AssemblerShared, static int jumpChainTargetAt(Instruction* instruction, BufferOffset pos, bool is_internal, Instruction* instruction2 = nullptr); - uint32_t jumpChainNextLink(Label* label, bool is_internal); + BufferOffset jumpChainGetNextLink(BufferOffset pos, bool is_internal); + uint32_t jumpChainUseNextLink(Label* label, bool is_internal); static uint64_t jumpChainTargetAddressAt(Instruction* pos); static void jumpChainSetTargetValueAt(Instruction* pc, uint64_t target); // Returns true if the target was successfully assembled and spewed.