The Four Fields Inside One Address
Sv39 is the privileged architecture's own address format: the manual fixes bits 38:30, 29:21, and 20:12 as the three VPN fields over a 12-bit offset, and the canonical-form rule sign-extends bit 38 into the high bits. The article's central claim is that layout and its extraction, read straight off the specification.
No claim depends on how any core implements translation: no TLB, cache, or pipeline behavior is asserted or measured. The single timing figure is a host-side loop measurement whose own proof note limits what it covers, so it cannot carry a microarchitecture verdict.
No boot code, machine-mode service, or privilege handoff takes part: the fields are read from a value already in hand, and every step of the argument is the format contract itself, before any firmware or privilege transition enters the picture.
The argument stops before the walk: it never enters a page-table walk, a fault path, or any kernel's use of these fields. Kernels consume the four fields, but the claim proven here is the partition itself, which holds before any kernel code runs.
The extraction is a small procedure with a stated invariant: four disjoint masks cover bits 38:0 with no overlap and no gaps, so recombine(extract(va)) restores the input exactly. A per-bit oracle that builds each field without shifting a whole field proves the split on 26,777,374 cases with 0 mismatches.
A virtual address looks like one number. Under Sv39, the 39-bit virtual-address format in the RISC-V privileged architecture, it is four fields sharing one value: bits 38 to 30 are VPN[2], bits 29 to 21 are VPN[1], bits 20 to 12 are VPN[0], and bits 11 to 0 are the offset inside the page [1]. Each VPN is an index into one page table, and a page walk reads them in order: VPN[2] picks an entry in the root table, that entry names the next table, VPN[1] picks an entry there, VPN[0] picks the leaf entry that holds the physical page number, and the offset picks the byte inside that page.
The 9-bit width is the page size wearing a disguise. A page table is one 4 KiB page and each entry is eight bytes, so one table holds 4096 / 8 = 512 entries, and 512 is 2 to the 9th [1]. Nine bits name exactly one entry in one table, with no code left over and no entry unreachable. Take the address 0x40403ABC: VPN[2] is 1, VPN[1] is 2, VPN[0] is 3, and the offset is 0xABC. Three small numbers pick three entries in three tables, and the fourth field rides through untouched to land on one byte inside the page.
Photo: Shyamal L., CC BY 4.0, via Wikimedia Commons
The extraction, in four lines:
f.page_offset = (uint16_t)(va & 0xFFFULL);
f.vpn0 = (uint16_t)((va >> 12) & 0x1FFULL);
f.vpn1 = (uint16_t)((va >> 21) & 0x1FFULL);
f.vpn2 = (uint16_t)((va >> 30) & 0x1FFULL);
The extraction is four masks: page_offset is va & 0xFFF, VPN[0] is (va >> 12) & 0x1FF, VPN[1] is the same shift at 21, and VPN[2] at 30 [3]. The four masks, 0xFFF, 0x1FF << 12, 0x1FF << 21, and 0x1FF << 30, touch no bit twice and skip no bit from 38 down to 0, so the split loses nothing: shift the fields back to their positions, OR them together, and the original address comes back. recombine(extract(va)) == va is not a hope; it is what disjoint and complete means.
One contract hides inside that simplicity. A canonical 64-bit Sv39 address sign-extends bit 38 through bits 63 to 39 [1], while a raw 39-bit field leaves those high bits clear. The extractor reads only bits 38 to 0, so both forms give identical fields, and recombine returns the raw 39-bit field rather than inventing an extension it was never given [3]. Feed it either form; the answer is the same four fields.
The lab proves the split against an oracle that shares no code with it. The oracle builds each field one bit at a time, never shifting a whole field, and the test demands field equality plus recombine(extract(va)) == va on every case: 117 directed edges around powers of two, a canonical-address row with the sign extension applied, an exhaustive sweep of every 24-bit value, and 10,000,000 fixed-seed splitmix64 values masked to 39 bits [2]. That is 26,777,374 checks with 0 mismatches, and the same FNV-1a checksum, 262f6db6f6303175, at -O0, at -O2, and under the address and undefined-behavior sanitizers [2]. The bench reads 3.460 ns per value at -O2, with the caveat printed in the proof: the number covers the array load and the running XOR accumulate, not the function body alone [2].
Sources
- 01The RISC-V Instruction Set Manual, Volume II: Privileged Architecture (Sv39 paging)RISC-V International
The Sv39 layout the fields are read from (Figure 4.19): VPN[2], VPN[1], VPN[0] over a 12-bit offset, and the rule that bit 38 sign-extends into bits 63:39 in a canonical address.
- 02PROOF.md, lab/132-sv39-vpn-extractdillingerstaffing/systems-lab
The verification record: the per-bit oracle, the directed edges, the canonical row, the exhaustive 24-bit sweep, the fixed-seed values, the checksum held across three builds, and the bench caveat.
- 03lab/132-sv39-vpn-extract: vpn_extract.h and vpn_extract.cChris Dillinger, systems-lab
The code under discussion: the four masks, the stated contract that extraction reads only bits 38:0, and the recombine that returns the raw 39-bit field.