Commit Graph

18142 Commits

Author SHA1 Message Date
Flāvius
3e3eec090d x86: +r decoding was legacy-only, so BSWAP could not be read back
`bswap` is `0F C8+rd` — the register rides in the opcode's low three bits, like
`push`/`pop`/`xchg`/`mov`, but behind an escape byte. The decoder's retry at the
+r base opcode was gated on `esc == .NONE`, so only the register-0 forms
(`0F C8` = bswap eax, `48 0F C8` = bswap rax) landed on a table entry directly;
the other seven registers came back INVALID_OPCODE. Emission was always correct
— every `bswap` this compiler has ever produced runs — but a disassembly
containing one stopped dead, which is how it surfaced: three functions in
sigil's JIT corpus disassembled to a header with no instructions under it.

The table was never the problem. BSWAP is in `tablegen/encoding_table.odin` and
in the generated decode table, exactly where it should be.

Fixing the gate meant looking at why the retry existed twice. There is a correct
+r handler further down, carrying comments that describe two bugs already found
and fixed in it — "scan ALL entries, not just the first", "scan for the sized
register rather than assuming op0" — and the copy inside the retry had received
neither, plus a third of its own. So the retry now re-runs only the LOOKUP and
falls through to the single handler, which fixes two more instruction families
that were equally undecodable:

  - `xchg rAX, r` (90+rd): 0x90's run sorts NOP ahead of XCHG, and the copy
    tested only the first entry for a +r form, so every `xchg rAX, r` was
    rejected.
  - `push bx` / `pop bx` / `mov cx, imm` (any +r under 0x66): the copy passed
    `prefix` where the legacy row wants 0, since for legacy opcodes 0x66 is
    operand size rather than part of the opcode's identity.

Two supporting changes. The shared handler's default answer is now the first +r
entry rather than `idx.start`, so a fall-through at 0x90 cannot answer NOP for
an `xchg`. And a base-opcode retry that does not land on a +r form is now an
error rather than a fall-through: decoding 0x0E as the 0x08 entry (OR) would be
a wrong instruction reported confidently, which is worse than an unknown byte.

Verified three ways. Every opcode in every escape map was decoded before and
after: 154 combinations changed, every one of them INVALID -> valid, and nothing
that already decoded decodes differently. All 24 BSWAP encodings and all 96
legacy +r encodings were diffed against llvm-mc's disassembly and agree
operand-for-operand. Six new decode-only cases pin the three families; five of
them fail without this change.

(Two remaining differences from llvm-mc are deliberate and documented here:
implicit accumulators are left unmaterialized so a short form re-encodes to the
short form, and `48 90` reads as `xchg rax` rather than `nop`.)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Riok9vMpkLmo78wsVKJHhz
2026-08-16 12:05:42 -04:00
Flāvius
2e8d3b9e10 rexcode/isa: display-side label naming — address order, offset-keyed names
Internal label ids are allocation-order handles: the encoder's creation
order, or the decoder's branch-DISCOVERY order (a loop's latch names the
header before an earlier forward target). Printing labels by raw id leaked
that accident into listings — label numbers appeared out of order down the
page — and the printers' `label_names: ^map[u32]string` keyed the caller's
names by those synthesized ids, which a decode consumer cannot know without
re-deriving them (the practical result: naming "label 0" could caption a
random interior branch target).

Naming is now derived at the presentation seam, shared by every ISA
(`isa.Label_Display` in isa/print.odin):

  - display numbers are assigned in ASCENDING ADDRESS order, so a listing
    reads L0, L1, L2 … top to bottom regardless of id allocation;
  - caller names are keyed by BYTE OFFSET (`isa.Label_Names`, with a
    `distinct` Label_Offset key so an id-keyed map from the old contract
    fails to compile instead of silently mis-naming);
  - a named offset is guaranteed a label row even when no Label_Definition
    points at it — `names[0] = "factorial"` heads a function's listing.

All ten ISA printers (x86, mips, rsp, arm32, arm64, riscv, ppc, ppc_vle,
mos6502, mos65816) drop their per-printer offset_to_label maps and
write_label helpers for the shared display; each arch re-exports
Label_Offset/Label_Names beside Label_Definition. En route this fixes an
arm32/ppc/ppc_vle bug where passing ANY names map suppressed the default
L<n> label rows for unnamed labels. Decode-side id assignment is untouched:
the reloc round-trip contract (encoder ids surviving decode) and the
sparse-id padding it relies on stay exactly as they were.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Riok9vMpkLmo78wsVKJHhz
2026-08-03 20:52:11 -04:00
Flāvius
da15373ee9 rexcode/mips: add the R6 signed mul/div encodings (MUL_R6/DIV_R6/DIVU_R6)
The table had the R6 unsigned mul, both muh, and mod/modu, but not the R6
SIGNED low multiply (SPECIAL funct 0x18, sa=2 → 0x98) or the R6 signed/unsigned
divide (funct 0x1A, sa=2/3 → 0x9A/0x9B). Add MUL_R6, DIV_R6, DIVU_R6 to the
Mnemonic enum + the encoding table (all SPECIAL, RD/RS/RT, mask 0xFC0007FF,
MIPS32_R6) and regenerate the tables. Verified against llvm-mc -mcpu=mips32r6
(mul/div/divu $rd,$rs,$rt). All existing mips tests pass (166/39/65/14).
2026-08-03 20:52:11 -04:00
Flāvius
69c6135b55 rexcode/mips: feature-gate the decoder so shared opcodes resolve per ISA variant
The MIPS decode tables are universal — every variant (MIPS I..64/R6, the PS1
GTE, PS2 MMI/VU, PSP VFPU) shares one table. Some primary opcodes collide
across variants: most visibly 0x37 is `LD` on 64-bit MIPS but `vfim.s` on the
PSP Allegrex VFPU. The decoder took the first table match, so `LD $ra, 0($sp)`
(0xdfbf0000) mis-decoded as `vfim.s $31, 0`.

Each Decode_Entry already carries a `feature`; the decoder just ignored it.
`decode` now takes a `features: Feature_Set` (a bit_set over `Feature`),
defaulting to `FEATURES_ALL` so existing callers are unchanged, and skips an
entry whose feature isn't enabled — the first ENABLED match wins, preserving
the most-specific-mask-first order. Added `FEATURES_MIPS_III` (MIPS I/II/III +
COP0 + FPU — the VR4300 / classic 64-bit baseline) for N64/MIPS-III consumers.

decode_smoke: opcode 0x37 decodes as LD under FEATURES_MIPS_III and (still)
as the PSP VFPU entry under FEATURES_ALL. 65 decoder checks pass.
2026-08-03 20:52:11 -04:00
gingerBill
c2b4099c01 Fix typo 2026-07-31 00:44:15 +01:00
gingerBill
821a24eb3a Improve formatting in rexcode/isa/x86/encoder.odin 2026-07-31 00:39:41 +01:00
Flāvius
0f472409c4 rexcode/x86: label addressing for RIP-relative disp and movabs imm
Add mem_rip_label(label_id) so a RIP-relative memory operand can
reference a label: the encoder writes a placeholder disp32 and emits a
REL32 relocation (addend 0) at the field's byte offset, mirroring the
existing .RELATIVE jump/call path. This expresses lea reg, [rip + <label>]
(position-independent data addressing).

Add op_imm_label(label_id) for movabs reg, <label>: the imm stays kind
.IMMEDIATE (form matching unchanged) but is flagged so the encoder emits
an ABS64 relocation for the imm64 instead of a literal; imm_matches_inline
forces the full IMM64 form so a small id can't collapse to mov r64, imm32.

Both labeled forms bypass the contextless recipe fast-path (which cannot
append relocations) and fall back to the interpreter. Flags reuse spare
bits in Memory (disp_is_label) and Operand_Flags (imm_is_label) -- no
struct growth. Section 11 tests cover resolved/unresolved disp, the ABS64
movabs, and an end-to-end executed lea+load.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 15:05:16 -04:00
gingerBill
8b7d1be601 Keep -vet happy 2026-07-14 13:28:12 +01:00
gingerBill
ee21677ac7 Begin work on the module encoder 2026-07-14 11:29:49 +01:00
gingerBill
1def2e3c66 Improve docs a little 2026-07-13 16:36:45 +01:00
gingerBill
fc17efdd0c Add TODO in encode to make it actually write out the entire module and not just the functions 2026-07-13 16:28:57 +01:00
gingerBill
bfed392a0e Improve printing for call 2026-07-13 16:15:41 +01:00
gingerBill
0696f46bfb Add indentation for block, loop, if, else` constructs 2026-07-13 16:02:38 +01:00
gingerBill
ac5f5fe3ed Add print_wat.odin 2026-07-13 15:56:25 +01:00
gingerBill
8cd5838112 wasm: parse custom sections 2026-07-13 15:30:00 +01:00
gingerBill
23c5c4e668 Add module parsing 2026-07-13 15:24:45 +01:00
gingerBill
085bae1028 Update examples/all for rexcode's wasm and spirv packages 2026-07-13 14:18:40 +01:00
gingerBill
fcc6b65ed4 Remove old wasm and wasm/module code 2026-07-13 14:17:27 +01:00
gingerBill
2478af9b1f Minor alignment fix 2026-07-13 14:16:40 +01:00
gingerBill
27e5225730 Refactor core:rexcode/wasm to use the new ir structure and move to core:rexcode/ir/wasm 2026-07-13 14:16:27 +01:00
gingerBill
f7b797cc6f Fix formatting 2026-07-13 13:06:41 +01:00
gingerBill
2bbb04e4f6 Merge branch 'master' into bill/rexcode 2026-07-13 12:10:57 +01:00
gingerBill
683d40db69 Merge pull request #7013 from rmn64k/reject-chained-defer
Reject chained deferred procedures.
2026-07-12 09:34:42 +01:00
Richard Nyberg
bb2e7e60ce Reject chained deferred procedures. 2026-07-12 07:49:46 +02:00
gingerBill
9b4adb0159 Merge branch 'master' of https://github.com/odin-lang/Odin 2026-07-12 00:08:00 +01:00
gingerBill
0694535d4e Correct arithmetic >> behaviour in LLVM IR 2026-07-12 00:07:51 +01:00
gingerBill
51bc27be01 Fix big_int_shr for arithmetic shift (i.e. negative numbers) 2026-07-12 00:04:35 +01:00
Jeroen van Rijn
049138d3ff Merge pull request #6857 from Yawning/feature/rsa
core/crypto: RSA support
2026-07-11 23:37:39 +02:00
Yawning Angel
e1d32cb19f core/cryto/rsa: Initial import 2026-07-12 06:17:08 +09:00
Yawning Angel
483221ef97 core/crypto/_bigint: Initial import 2026-07-12 06:17:08 +09:00
Yawning Angel
f259b416e3 core/crypto/_subtle: Cleanups, dedup from RSA code 2026-07-12 03:28:20 +09:00
Yawning Angel
98e22205af core/crypto/ed25519: Add missing require_results annotations 2026-07-12 03:28:20 +09:00
gingerBill
a60a77f57f Merge pull request #6997 from tf2spi/6981-increase-stack-size
Increase stack size for threads
2026-07-11 10:37:55 +01:00
Jeroen van Rijn
0bc15952bb Merge pull request #7006 from febrandao/master
vendor:box3d - fix missing return value of *_GetUserData functions
2026-07-11 11:00:32 +02:00
Felipe Brandão
6a73a4ece7 fixes missing return value of GetUserData functions 2026-07-10 22:16:40 -03:00
Felipe Brandão
d62d17faa3 fix missing return value of World_GetUserData 2026-07-10 22:10:04 -03:00
Jeroen van Rijn
5c6194c988 Fix #7004 2026-07-10 23:43:30 +02:00
Jeroen van Rijn
43a9f145e1 Merge pull request #7002 from Kelimion/rbtree_upsert
Add `rbtree.upsert`
2026-07-10 22:36:17 +02:00
Jeroen van Rijn
c90f7b1c48 ensure key reuse for upsert test 2026-07-10 21:48:52 +02:00
Jeroen van Rijn
5377cd9c49 Add rbtree.upsert 2026-07-10 21:37:47 +02:00
Jeroen van Rijn
e26b5ba54e Merge pull request #6988 from catermujo/push-rmqymlxpmqtk
core/rbtree: match find_or_insert semantics with AVL
2026-07-10 21:03:23 +02:00
callframe
cb7d7a5b7d Allow using absolute path's in foreign import's (#6999)
Document that `-collection` can be used for foreign imports.
Fix absolute path detection on Windows.
2026-07-10 20:45:59 +02:00
gingerBill
a6ba977a38 Merge pull request #6996 from Creativty/master
Disallow proc group assignment to blank identifier
2026-07-10 13:53:32 +01:00
Abderrahim Indjaren
ac6688c166 add: disallow proc group assignment to blank identifier 2026-07-10 12:19:39 +01:00
gingerBill
819fdc7a80 Merge pull request #6990 from jagnat/objc-superclass-lookup-fix
Fix for @(objc_implement) being broken in 2026-07
dev-2026-07a
2026-07-10 10:56:01 +01:00
gingerBill
96ca9f3b48 Merge pull request #6984 from A1029384756/master
[cli] remove `default` help option for stack protector
2026-07-10 08:56:07 +01:00
gingerBill
7f8a9e2114 Merge pull request #6987 from RoBaertschi/master
Fix #6979
2026-07-10 08:55:53 +01:00
gingerBill
2c36fd3e35 Merge pull request #6993 from DerTee/master
fix assign_at_elems_fixed_capacity_dynamic_array
2026-07-10 08:55:36 +01:00
DerTee
78c04ca65d fix assign_at_elems_fixed_capacity_dynamic_array & co
copy-paste error: the fixed cap version of resize doesn't take a location
2026-07-10 06:25:17 +02:00
misomosi
b9e0916189 Use better triple for ARM32 freestanding 2026-07-09 19:39:59 -04:00