Commit Graph

11 Commits

Author SHA1 Message Date
Benjamin Oldenburg
e7a16ce876 arm64: finish GNU inline asm constraint support 2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
62345bb113 refactor: replace remaining ARM64 opcode literals with symbolic constants 2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
7d2f376843 refactor: replace vector load/store and struct load opcodes with symbolic constants (Phase 2.2)
arm64-gen.c:
- arm64_ldrv(): ARM64_LDR_SCALAR, ARM64_LDUR_Q_SIMD, ARM64_LDR_Q_REG
- arm64_strx(): ARM64_STR_B, ARM64_STUR_B, ARM64_STR_B_REG
- arm64_strv(): ARM64_STR_SCALAR, ARM64_STUR_Q_SIMD, ARM64_STR_Q_REG
- arm64_ldrs(): ARM64_ORR_REG_LSL, ARM64_LSR_IMM_32, ARM64_LSR_IMM

arm64-tok.h:
- ARM64_LDR_SCALAR (0x3D400000U)
- ARM64_STR_SCALAR (0x3D000000U)
- ARM64_LSR_IMM_32 (0x53000000U)
- ARM64_STR_X_PRE (0xF8000000U)
- ARM64_LDR_X_POST (0xF8400000U)

All 137 tests2 tests pass.
2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
38cff9b8ef feat: add missing ARM64 opcode constants and helper macros
- Add ARM64_MOVZ64, ARM64_MOVN64 for 64-bit move wide instructions
- Add ARM64_FMOV_SCALAR, ARM64_FMOV_XD, ARM64_FMOV_WS for FMOV variants
- Add ARM64_MOV_V16B for vector move (ORR alias, corrected from FMOV_SIMD)
- Add ARM64_EXTR64 for 64-bit extract instruction
- Add helper macros: ARM64_HW, ARM64_SHIFT_*, ARM64_IMM_*, ARM64_EXTEND_LSL
- All constants verified against ARM Architecture Reference Manual DDI 0602
- Fixes DRY violation by removing duplicate ARM64_HW_SHIFT macro

Build:  No warnings
Tests:  All 137 tests2 tests pass
2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
1a55a3e041 fix(arm64): verify and correct all opcode constants against ARM ARM
Comprehensive verification of all ARM64 opcode constants against the ARM
Architecture Reference Manual.

Critical fixes:
- ARM64_MUL_REG/MULS_REG: 0x1B007C00/0x3B007C00 → 0x1B000000/0x3B000000
- ARM64_RET: 0xD65F03C0 → 0xD65F001F

Corrected to base templates:
- ARM64_STR_Q_PRE: 0x3C9F0FE0 → 0x3C800000
- ARM64_LDR_Q_POST: 0x3CC107E0 → 0x3CC00000
- ARM64_ORR_REG_LSL: 0x2A0043E0 → 0x2A000000
- ARM64_SUB_REG_LSL: 0xCB2063FF → 0xCB000000

Removed incorrect constants:
- ARM64_FMOV_S_D, ARM64_LDPSW, ARM64_LDR_S_SIMD, ARM64_MOV_V_D
- ARM64_ORR_REG_LSL32, ARM64_LSR_W_8, ARM64_LSR_X_8/16/24
- ARM64_MOVI_W/X (SIMD instruction, not general-purpose)
- Duplicate definitions

All 108 remaining opcode constants verified correct.
Builds successfully with no functional changes.
2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
f0d9ddf0eb feat(arm64): add HW shift field macro for MOVZ/MOVN instructions 2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
c15dff2e5a feat(arm64): add more opcode constants for load/store and shift instructions 2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
926f4a3cb8 feat(arm64): add more opcode constants for code generator
Add additional ARM64 instruction opcode constants needed by arm64-gen.c:
- ARM64_FMOV_*: Floating-point move variants
- ARM64_STR_Q_PRE/LDR_Q_POST: Quadword load/store with pre/post increment
- ARM64_LDPSW: Load pair of words with sign-extend
- ARM64_LDR_S_SIMD: SIMD load (distinct from scalar LDR_S)
- ARM64_MOV_V_D: Move vector to double
- ARM64_FCMP: Floating-point compare
- ARM64_SDIV: Signed divide
- ARM64_MUL: Multiply

These constants will be used in the next commit to refactor arm64-gen.c.
2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
99d2daeb47 refactor(arm64): use symbolic opcode constants consistently
Replace hardcoded magic numbers with symbolic constants for ARM64
instruction opcodes, matching the style used in x86_64 backend.

Changes:
- arm64-tok.h: Add 93 new opcode constants and helper macros
  - Instruction opcodes: ARM64_ADD_IMM, ARM64_LDR_X, ARM64_B, etc.
  - Helper macros: ARM64_RD(), ARM64_RN(), ARM64_IMM12(), etc.
  - Field encodings: ARM64_SF(), ARM64_S(), ARM64_SH(), etc.

- arm64-asm.c: Refactor all instruction generation functions
  - gen_movz/gen_movn/gen_movk: Use ARM64_MOVZ/MOVN/MOVK
  - gen_add_imm/gen_sub_imm: Use ARM64_ADD_IMM/SUB_IMM
  - gen_dp_reg: Use symbolic opcodes
  - gen_ldst_imm/gen_ldst_pair: Use ARM64_LDR_*/STR_*
  - gen_b/gen_bl/gen_br/gen_blr/gen_ret: Use ARM64_B/BL/BR/BLR/RET
  - gen_cbz/gen_cbnz: Use ARM64_CBZ/CBNZ
  - gen_shift: Use ARM64_LSL_REG/LSR_REG/ASR_REG/ROR_REG
  - gen_barrier: Use ARM64_ISB/DSB/DMB
  - gen_mrs/gen_msr: Use symbolic constants
  - Inline asm save/restore: Use ARM64_STP_X/LDP_X

- arm64-gen.c: Begin systematic refactoring (first batch)
  - arm64_sub_sp: Use ARM64_SUB_IMM with helper macros

Benefits:
- Readability: Self-documenting code (ARM64_LDR_X vs 0xF9400000)
- Maintainability: Easier to spot encoding errors
- Consistency: Matches x86_64 backend style
- Safety: Helper macros prevent bit-shift mistakes

All tests pass with no functional changes.
2026-04-04 20:02:33 +07:00
Benjamin Oldenburg
0decb1b86f arm64: support mnemonic win32 stack helpers 2026-04-04 20:02:32 +07:00
Benjamin Oldenburg
4f4b3dda6b Add and stabilize Windows ARM64 support 2026-04-04 20:02:31 +07:00