191 views|0 replies

126

Posts

1

Resources
The OP
 

[Reading] "RISC-V Open Architecture Design" 3. Multiplication and Division Instruction Set RV32M [Copy link]

This post briefly talks about multiplication and division in RV. RV32M is a standard extended instruction set in the RISC-V architecture, which adds multiplication and division operations to the RV32I basic integer instruction set. The RV32M extension contains a series of instructions for performing multiplication, division, and related operations, which are very useful for performing arithmetic-intensive tasks. As an extended instruction set of RV32I, the multiplication and division instruction set (RV32M) has relatively few instructions, as shown in the figure:

Instruction Format

RV32M instructions typically use the R-type (Register) format, which contains three register operands (rs1, rs2, and rd), and an opcode to indicate the specific multiplication or division operation to be performed.

I recommend reading Lao Lang’s post for this usage: https://www.cnblogs.com/mikewolf2002/p/9872287.html It is written in more detail, so I will not repeat it here

Instruction List

Multiplication Instructions

mul rd, rs1, rs2, the usage is register [rs2] multiplied by register [rs1], and the product is written to register x[rd].

The multiplication instructions are:

mul

: Unsigned multiplication, the result is 32 bits.

mulh

: Unsigned multiplication, the high 32 bits of the result.

mulhsu

: Multiplication when one operand is unsigned and the other is signed, the high 32 bits of the result are taken into account.

mulhu

: Both operands are unsigned multiplication, and the high 32 bits of the result are used.

mulhusu

: 32-bit signed-unsigned multiplication, the result is 32 bits. This is special: x[rs2] is an unsigned number, and the rest is the same as mulhu

Division Instructions

div rd, rs1, rs2 divides register x[rs1] by register x[rs2], rounding towards zero, treating the numbers as two's complement, and writing the quotient to x[rd].

The division instructions are:

div

: Unsigned division, the result is 32 bits.

divu

: Signed division, the result is 32 bits.

rem

: The remainder of unsigned division, the result is 32 bits.

remu

: The remainder of a signed division, the result is 32 bits.

Conclusion

Unlike ARM, which has only had multiplication instructions for a long time, the division instruction was not added until 2005. The multiplication instruction is used to perform fast hardware multiplication operations, which is essential for digital signal processing, graphics processing, and other applications that require a large number of multiplications. Moreover, RV32M, as an extended instruction, can be selectively added to RV32I, which means it can be omitted in scenarios where multiplication and division operations are not required to save hardware resources.

This post is from Programming Basics
Personal signature

没用比没有强

 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list