Skip to content

Conversation

@yzewei
Copy link
Contributor

@yzewei yzewei commented Feb 7, 2026

NumPy test case timedelta floor_divide runtime exception revealed DIV/IDIV translation issues.
Before(buggy:First cover A0, then move A1)

[BOX64] 0x7fff001090bc: 48 F7 F7  DIV Ed
    ... (slowpath because RDX!=0)
    BEQ             xRDX, xZR, ...

[BOX64]   Table64: 0x3d
    ... resolve helper div64 target into x6 ...
    ADDI.D          xRDI, xEmu, 0        ; A0 <- emu   (clobber A0 which also holds xRDI)
    ADDI.D          xRSI, xRDI, 0        ; A1 <- A0    (arg1 was xRDI/A0, but now A0==emu => s becomes wrong)
    JIRL            r1, x6, 0           ; call div64(emu, s)

    ... restore regs ...

After modification (fixed: move A1 first, then overwrite A0),

[BOX64] 0x7fff001090bc: 48 F7 F7  DIV Ed
    ... (slowpath because RDX!=0)
    BEQ             xRDX, xZR, ...

[BOX64]   Table64: 0x3d
    ... resolve helper div64 target into x6 ...
    ADDI.D          xRSI, xRDI, 0        ; A1 <- xRDI  (preserve divisor s first)
    ADDI.D          xRDI, xEmu, 0        ; A0 <- emu   (set emu after arg copy)
    JIRL            r1, x6, 0           ; call div64(emu, s)

    ... restore regs ...

Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
Co-authored-by: Leslie Zhai <xiangzhai83@gmail.com>
@xiangzhai
Copy link
Contributor

Nice catch!

@ptitSeb ptitSeb requested a review from ksco February 7, 2026 07:57
@ptitSeb ptitSeb merged commit 1c0830e into ptitSeb:main Feb 9, 2026
27 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.

3 participants