Skip to content

SP int MIPS: support MIPS Release 6 - #11966

Open
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:mips_r6_sp_int_asm
Open

SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:mips_r6_sp_int_asm

Conversation

@SparkiDev

@SparkiDev SparkiDev commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

MIPS Release 6 removed the HI/LO registers and the multu/dmultu, mflo and mfhi instructions. The SP int MIPS and MIPS64 assembly used them and listed $hi/$lo as clobbers, so builds for r6 CPUs failed with "the register '$hi' cannot be clobbered".

Add SP_ASM_MIPS_MUL to put the low and high words of a multiplication into registers. Use mulu/muhu (dmulu/dmuhu for 64-bit) when __mips_isa_rev >= 6 and the existing multu/mflo/mfhi sequence otherwise. Only clobber HI/LO before r6. Mark the high word output as early clobber in the macros that write the result directly, as r6 writes it before the inputs are fully consumed.

Code generated for pre-r6 targets is unchanged.

Fixes #11953

Testing

The patched source was cross-built with ./configure --host=<mips triplet> --enable-all --disable-shared using zig 0.14.1 cc (clang-based, musl libc) as the compiler. wolfcrypt/test/testwolfcrypt was then run under qemu-user.

Target configure define qemu CPU Multiply instructions in sp_int.o testwolfcrypt
mips64r6el, n64 WOLFSSL_SP_MIPS64 I6400 dmulu/dmuhu Pass
mips64r6el, n32 WOLFSSL_SP_MIPS64 I6400 dmulu/dmuhu Pass
mips32r6el WOLFSSL_SP_MIPS mips32r6-generic mulu/muhu Pass
mips32r2el (regression) WOLFSSL_SP_MIPS 24Kf multu/mflo/mfhi Pass

@SparkiDev SparkiDev self-assigned this Nov 3, 2026
Copilot AI balanced review requested due to automatic review settings November 3, 2026 00:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The cryptographic assembly changes across MIPS32 and MIPS64 n32/n64 need GCC cross-build and runtime validation, since Clang-only results do not confirm the compiler-specific register constraints implicated in the original GCC failure.

No open issues 🎉

What changed in this PR

Adds MIPS Release 6 support to wolfCrypt’s SP integer assembly, addressing the build failure caused by removed HI/LO registers and instructions in #11953.

Changes:

  • Uses mulu/muhu and dmulu/dmuhu on Release 6, retaining legacy multiply sequences on older targets.
  • Makes HI/LO clobbers conditional on the ISA revision.
  • Adds early-clobber constraints to high-word outputs to prevent input-register overlap.
File Description
wolfcrypt/​src/​sp_int.c Updates MIPS32 and MIPS64 multiply and square macros for Release 6 compatibility.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

@SparkiDev

Copy link
Copy Markdown
Contributor Author

Jenkins: retest this please

@SparkiDev
SparkiDev force-pushed the mips_r6_sp_int_asm branch 3 times, most recently from 0accbf8 to 400f19d Compare November 4, 2026 00:23
@SparkiDev

Copy link
Copy Markdown
Contributor Author

Jenkins: retest this please

MIPS Release 6 removed the HI/LO registers and the multu/dmultu,
mflo and mfhi instructions. The SP int MIPS and MIPS64 assembly used
them and listed $hi/$lo as clobbers, so builds for r6 CPUs failed with
"the register '$hi' cannot be clobbered".

Add SP_ASM_MIPS_MUL to put the low and high words of a multiplication
into registers. Use mulu/muhu (dmulu/dmuhu for 64-bit) when
__mips_isa_rev >= 6 and the existing multu/mflo/mfhi sequence
otherwise. Only clobber HI/LO before r6. Mark the high word output as
early clobber in the macros that write the result directly, as r6
writes it before the inputs are fully consumed.

Code generated for pre-r6 targets is unchanged.
@SparkiDev

Copy link
Copy Markdown
Contributor Author

Jenkins: retest this please

@SparkiDev SparkiDev assigned wolfSSL-Bot and unassigned SparkiDev Nov 4, 2026
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.

[Bug]: sp_int.c MIPS assembly fails to build on MIPS Release 6 ('$hi' cannot be clobbered)

3 participants