Question bank — RISC-V extensions (M, A, F, D, V, C)
5.1.8 · D5· Hardware › Instruction Set Architecture (ISA) › RISC-V extensions (M, A, F, D, V, C)
Shuru karne se pehle, ek simple refresher taaki koi cheez undefined na rahe:
Neeche ke bit-level pictures multiplication, LR/SC, aur floating-point traps ko support karte hain — inhe kaam karte waqt dekho.
Pictures that power the traps
Ek product, do halves. Ek 32×32 multiply ek 64-bit result banata hai. MUL low half leta hai, MULH* usi product ka high half:

LR/SC retry loop. LR ek reservation raise karta hai; agar koi doosra core line likhta hai, SC fail ho jaata hai aur loop fresh data ke saath retry karta hai:

Float addition alignment. Mantissas ko add karne se pehle unhe ek shared exponent chahiye — chhote wale ko right shift karo:

IEEE-754 exponent map. Stored exponent field number line ko regions mein divide karta hai — zero/subnormal, normal, aur infinity/NaN:

Poori treatment ke liye 5.2.03-IEEE-754-floating-point dekho.
True or false — justify karo
Base ISA mein already integer multiply hai, isliye M extension sirf divide add karta hai.
MUL* aur DIV* add karta hai. Ek base-only chip multiply ek shift-add software loop mein karta hai.MUL aur MULH do independent multiplications compute karte hain.
MUL low half return karta hai, MULH usi product ka high half (do-halves figure dekho).Agar tumhe sirf ek 32×32 product ke low 32 bits chahiye, toh operands ki signedness matter nahi karti.
MUL hai lekin teen MULH variants hain.LR.W ke baad SC.W guarantee karta hai ki store succeed karega.
SC fail ho sakta hai (non-zero return kar sakta hai) agar kisi doosre core ne reserved line ko touch kiya, ya spuriously bhi; retry loop ka point yahi hai ki failure expected aur normal hai.amoadd.w aur ek LR/SC loop jo add karta hai functionally interchangeable hain, isliye jo chaaho choose karo.
amoadd.w ek single instruction hai jo line ko directly lock karta hai, jabki LR/SC ek multi-instruction loop hai jo heavy contention mein livelock kar sakta hai — simple patterns ke liye AMO prefer karo.A extension ko memory system ki koi help nahi chahiye; yeh purely ek CPU feature hai.
F extension ke registers f0–f31 wahi registers hain jo integer x0–x31 hain.
FMV/load-store se data move karna padega; ye overlap nahi karte.Source code mein jo bhi decimal likhte ho uski exact single-precision representation hoti hai.
0.1 aur 0.2 binary mein forever repeat karte hain, isliye ye rounded store hote hain (dekho 5.2.03-IEEE-754-floating-point).Double precision bas "single precision but slower" hai; number range same hai.
Ek chip RV32IMAC implement kar sakta hai jabki F aur D skip kar de.
Signed division DIV of MIN_INT by −1 ek exception raise karta hai, bilkul jaise x86 pe division by zero karta hai.
MIN_INT ÷ −1 representable range overflow karta hai isliye yeh defined hai ki MIN_INT return kare (aur REM 0 return kare); koi fault nahi hota.Spot the error
mulh t1, a0, a1 jahan a0, a1 do unsigned magnitudes hold karte hain — kya galat hai?
MULH dono operands ko sign-extend karta hai, isliye agar kisi ka top bit set hai toh use negative pad liya jaayega. Unsigned inputs ke liye MULHU use karo.Ek programmer sc.w likhta hai bina pehle lr.w run kiye, ek plain conditional store expect karte hue.
SC ka matlab sirf ek prior LR reservation ke relative kuch hai; koi reservation raise na hone par yeh simply fail ho jaayega (ya contract ke hisaab se undefined behave karega). Yeh ek general "store-if" instruction nahi hai.Ek LR/SC retry loop ke andar, koi lr.w aur sc.w ke beech ek unrelated address pe normal load/store insert karta hai.
Ek single-precision number ke liye true exponent −126 ko directly ek signed 8-bit field mein store karna.
−126 + 127 = 1 store karte ho, ek unsigned value. Raw signed exponents "magnitudes compare karne ke liye unsigned integer compare as bit patterns" wali trick tod denge.Yeh claim karna ki 0x80000000 × 0x80000000 overflow karta hai aur represent nahi ho sakta.
MULH high half 0x40000000 return karta hai; kuch overflow nahi hota kyunki product width design ke hisaab se doubled hai.Floating equality test karna if (0.1 + 0.2 == 0.3) se aur true expect karna.
0.1 + 0.2 0.30000000000000004 banta hai; float comparisons mein tolerance use karo, kabhi exact == nahi.Har DIV ko "hardware will fault, so I'll catch the exception" pattern mein wrap karke divide-by-zero handle karna.
DIV x, 0 all-ones (−1) return kare, DIVU x, 0 bhi all-ones, aur REM/REMU x, 0 dividend return kare. Agar tumhe error handling chahiye toh software mein divisor test karo divide karne se pehle.Why questions
MULH teen flavours mein kyun aata hai (MULH, MULHU, MULHSU) lekin MUL ek hi kyun hai?
MUL kaafi hai.RISC-V ne divide-by-zero results ko trap karne ki jagah define karna kyun choose kiya?
User mode mein lock kyun nahi bana sakte "critical section ke around interrupts disable karke"?
A extension cache coherence pe "piggyback" kyun karta hai instead of new hardware add karne ke?
Floating-point exponent biased kyun store hota hai instead of signed two's-complement number ke?
0.1 + 0.2 == 0.3 ka result rounding mode pe kyun depend karta hai?
0.1+0.2 ko ...0004 tak round up karta hai, lekin round-toward-zero jaisa mode alag last bit pe land kar sakta hai — isliye "kaun se floats equal hain" mode-dependent hai.F aur D ko ek "floating point" extension ki jagah do mein kyun split kiya?
Hardware floating-point addition mein "align exponents" step ki zarurat hi kyun hai?
Leading mantissa bit "implicit" (stored nahi) kyun hai normalized floats mein?
1.something × 2ᵏ hota hai, isliye leading 1 guaranteed hai aur use store karna ek bit waste karna hoga — ise drop karna ek extra bit of precision free mein deta hai.Edge cases
SC kya return karta hai, aur success aur failure ke boundary pe uski value ka kya matlab hai?
rd mein 0 likhta hai success pe (store hua, atomicity hold ki) aur non-zero (typically 1) failure pe (reservation lost); zero being success bnez ko seedha retry pe branch karne deta hai.Do cores dono ek LR/SC increment loop mein hamesha spin karte hain — kya progress guarantee hai?
RV32 pe DIV MIN_INT, −1 aur REM MIN_INT, −1 ka defined result kya hai?
DIV MIN_INT (0x80000000) return karta hai kyunki true quotient +2³¹ fit nahi hota, aur REM 0 return karta hai; dono specified hain, koi overflow flag ya trap nahi.Reserved exponent fields: IEEE 754 mein all-zero aur all-ones exponents ka kya matlab hai?
Agar true product ko dono halves ki zarurat ho — MUL aur MULH se full value kaise reconstruct karte ho?
MULH MUL ke upar baithta hai jab tum dono words concatenate karte ho.~10⁶ additions ke baad ek running single-precision sum ka kya hota hai numbers ke saath jo same magnitude ke around hain?
Kya ek compressed-instruction (C) chip multiply bhi lack kar sakta hai?
C sirf existing instructions ko code density ke liye 16-bit forms mein re-encode karta hai (3.3.06-Instruction-encoding); yeh koi arithmetic capability add nahi karta, isliye M ke bina RV32C mein phir bhi koi hardware multiply nahi hai.Kya MULHSU symmetric hai — kya tum swap kar sakte ho ki kaun sa operand signed hai?
MULHSU rs1 ko signed aur rs2 ko unsigned fix karta hai; roles swap karne se interpretation badal jaati hai aur generally result bhi, isliye operand order yahan meaningful hai.Recall Quick self-check
Product ka low half signedness-independent kyun hai? ::: Kyunki two's-complement addition/multiplication sign interpretation ki parwah kiye bina identical low bits produce karte hain — sirf high (sign-carrying) bits differ karte hain.
Kaunsa flag atomics ko kaam karta hai, aur use kaun invalidate karta hai? ::: Per-core reservation flag, kisi bhi doosre core ke coherence write se reserved line par invalidate hota hai.
Single precision ke liye bias 127 kyun? ::: Yeh hai, exponent range ko centre karta hai aur exponents ko unsigned integers ke roop mein compare karne deta hai.
RISC-V divide-by-zero par kya karta hai? ::: Kuch exceptional nahi — yeh ek defined value return karta hai (DIV ke liye −1, REM ke liye dividend); koi trap nahi, isliye software mein check karo.