C8 Computer organization · Practice
What the compiler does
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
0 solved
0 in a row
0 of 8 kinds solid
Check
An unoptimized loop takes 14 instructions a pass; optimized, it takes 6. It runs 1000 passes.
(a)
How many instructions does optimization save?
(b)
By what factor does the loop speed up, at one instruction a cycle?
Check
A function with a 2-instruction body is called 1000 times, and each call costs 6 more instructions.
(a)
How many instructions do the calls run in all?
(b)
What share of that does inlining remove?
Check
Multiply a0 by 10 without mul, and put the result in a1.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
*a += *b; *a += *b; runs with a and b pointing at the same int, which holds 5.
(a)
What does the int hold afterward?
(b)
What would a compiler that loaded *b only once produce?
Check
A loop runs 1000 passes of a 3-instruction body, with 2 instructions of loop overhead per pass.
(a)
How many instructions does it run?
(b)
Unrolled by 8?
Check
12 instructions a pass before, 7 after, 500 passes. Instructions saved?
Check
What does (x << 2) + x give for x = 3?
Check
Inlining a 4-instruction function called 10000 times, at 5 instructions per call. Instructions saved?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C8