Skip to content

mulhsu instruction actually returns the lower bits of the multiplication result, not the higher bits. #101

Description

@cassuto

The mulhsu instruction actually returns the lower bits of the multiplication result, not the higher bits.

For the operation:

mulhsu x20, x1, x3

Input:
x1 = 0xabababab, x3 = 0xa36566c8

Output:
x20 = 0x1ffb3f98

Expected result (from Spike reference):
x20 = 0xca2ce72d

Mathematically correct result: (signed)0xabababab * (unsigned)0xa36566c8 = 0xca2ce72d_1ffb3f98

Please refer to our PoC for reproduction: https://github.com/gpu-experimental/poc-ventus-b30

It appears that the GVM has crashed.

[RTL    error]@3515 GVM error in `gvm_t::getDutXRegWbFinish`: xreg writeback for instruction that does not care for retire
getDutXRegWbFinish Error: sm_id: 0, hardware_warp_id: 0, dispatch_id: 45, pc: 0x800000d4, insn: 0x0230a333
poc.out: /home/ain/fuzz_gpgpu/poc/ventus-env/gpgpu/sim-verilator/gvm.cpp:212: void gvm_t::getDutXRegWbFinish(): Assertion `isInsnCare(item.insn, retire_care_insns)' failed.

Thank you for your hard work!

Activity

  1. whyuwhyi commented on Feb 28, 2026

    @whyuwhyi

    The following patch may help.

    diff --git a/ventus/src/pipeline/Multiplier.scala b/ventus/src/pipeline/Multiplier.scala
    index 8a519d4..1a18cc1 100644
    --- a/ventus/src/pipeline/Multiplier.scala
    +++ b/ventus/src/pipeline/Multiplier.scala
    @@ -202,7 +202,7 @@ class ArrayMultiplier(num_thread: Int, len: Int)
     
       val xlen = len - 1
       val res = Mux(isMAC(func),mac_out(xlen,0),
    -    Mux(func===FN_MULH | func===FN_MULHU, result(2*len-1, len),result(xlen,0)))//Mux(func===FN_MULH | func===FN_MULHU, result(2*xlen-1, xlen),result(xlen,0)))
    +    Mux(func===FN_MULH | func===FN_MULHU | func===FN_MULHSU, result(2*len-1, len),result(xlen,0)))//Mux(func===FN_MULH | func===FN_MULHU, result(2*xlen-1, xlen),result(xlen,0)))
       io.out.bits.result:=PipelineReg(latency)(res)
       io.out.bits.ctrl:=ctrlVec.last
       io.out.bits.mask:=maskVec.last
    

    issue101.patch

    Thanks agin for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions