Skip to content

[FIX] Simulator: fix TinyFive dead loop caused by ABI names and non-s…#15

Merged
FeelTheBeats merged 2 commits into
ScratchV-Compiler:mainfrom
FeelTheBeats:seven_main
Jul 26, 2026
Merged

[FIX] Simulator: fix TinyFive dead loop caused by ABI names and non-s…#15
FeelTheBeats merged 2 commits into
ScratchV-Compiler:mainfrom
FeelTheBeats:seven_main

Conversation

@FeelTheBeats

@FeelTheBeats FeelTheBeats commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

解决了loop的死循环问题,并适配了部分tinyfive的abi不兼容问题。
文档展示了问题定位思路和修改根因:
01_devdoc_simulator_deadloop.md
…tandard assembly syntax

Des:

  1. Switch verify_assembly() to assemble_to_binary() + load_binary() as primary path, avoiding TinyFive's asm() which rejects ABI register names and silently skips failed instructions via except Exception: continue.
  2. Add _expand_pseudo() to expand max pseudo-instruction and branch-with-immediate into standard RISC-V sequences before encoding.
  3. Add SW dual-syntax support (compiler format and standard format) in _encode_line(), suppressing non-standard instruction errors.
  4. Add encoding for rem, srai, xor, and instructions; remove broken max handling that incorrectly encoded max as add.
  5. Set ra = mem_size after binary load as termination sentinel, preventing jalr zero, ra from looping back to address 0.

…tandard assembly syntax

Des:
1. Switch verify_assembly() to assemble_to_binary() + load_binary() as primary path, avoiding TinyFive's asm() which rejects ABI register names and silently skips failed instructions via except Exception: continue.
2. Add _expand_pseudo() to expand max pseudo-instruction and branch-with-immediate into standard RISC-V sequences before encoding.
3. Add SW dual-syntax support (compiler format and standard format) in _encode_line(), suppressing non-standard instruction errors.
4. Add encoding for rem, srai, xor, and instructions; remove broken max handling that incorrectly encoded max as add.
5. Set ra = mem_size after binary load as termination sentinel, preventing jalr zero, ra from looping back to address 0.

Signed-off-by: Seven Gao <799889633@qq.com>
@FeelTheBeats

Copy link
Copy Markdown
Contributor Author
  1. max 编码为 add(语义错误) — 编译器所有 ReLU 测试均生成 max rd, rs1, 0(见 scratchv-topic06-deliverable/build/relu_only.s 等 6 个文件),旧编码将其编码为 add =
    mv,导致负数输入透传而非截断为 0。属于 结果错误。
  2. max 展开依赖 branch-with-immediate 支持 — max 展开为 bge rs1, 0, label,而 RISC-V branch 只接受寄存器操作数。没有 branch-with-immediate 扩展,max
    自身的展开就无法编码。
  3. sw 编译器格式支持 — reg_pressure_32.s 中 19 处 spill 使用编译器格式 sw sp(4), t0(非标准 sw t0, 4(sp)),TinyFive 的 asm() 直接拒绝,旧编码器也无法解析。
  4. rem/srai/xor/and 编码缺失 —
    四个指令已完整接入编译器流水线(machine_types.py/asm_emit.py/inst_scheduler.py/const_merge.py/cycle_estimator.py),但编码器不支持,一旦生成即崩溃。
  5. TinyFive 死循环 — 所有 .s 文件以 jalr zero, ra 结尾,启动时 ra = 0 导致跳转到地址 0 死循环。ra = mem_size 哨兵是必要修复。
  6. verify_assembly() 二进制加载替代 TinyFive asm() — TinyFive 的 asm() 拒绝 ABI 寄存器名(sp/ra)和非标准语法,且 except Exception: continue
    静默跳过失败指令。不用 assemble_to_binary() 就无法可靠验证。

@FeelTheBeats
FeelTheBeats merged commit fc4e5cf into ScratchV-Compiler:main Jul 26, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants