TAOCP 4.2.3 Exercise 5
Program **A** implements a floating-point accumulator in MIX, with **8 bytes to the right of the radix point**.
Section 4.2.3: Double-Precision Calculations
Exercise 5. ▶ [**] [24] How should Program A be changed so that extra accuracy is achieved, essentially by working with a nine-byte accumulator instead of an eight-byte accumulator to the right of the radix point? Specify all changes that are required, and determine the difference in execution time caused by these changes.
Verified: no
Solve time: 5m44s
Solution
Program A implements a floating-point accumulator in MIX, with 8 bytes to the right of the radix point. To increase accuracy, we wish to extend the accumulator to 9 fraction bytes. This requires precise modifications to Program A at the instruction and storage level, as well as recalculating execution time.
1. Identification of the relevant storage and fields
In Program A:
-
The accumulator
Ais defined as 8 bytes for the fraction, plus the sign and exponent. -
Multiplication, division, and addition routines use
Adirectly and may employ temporary storage locations: -
R1andR2for partial products. -
TEMPfor shifting and normalization. -
Instructions that operate on fraction bytes often use field specifications
(0:7)to indicate the eight fraction bytes.
2. Modifications to storage
- Accumulator
A:
Extend the fraction from 8 bytes to 9 bytes. In MIX notation, if the original field is (0:7), it now becomes (0:8) wherever the full fraction is addressed.
2. Temporary storage areas used by arithmetic routines:
The multiplication, division, and normalization routines require all 9 fraction bytes. Each temporary word or register that holds part of A must be extended:
- Any reference to a full fraction in memory (e.g.,
TEMP) must allocate 9 bytes instead of 8. - Field specifications
(0:7)become(0:8).
- Instruction references:
Instructions like ST, LD, ADD, SUB that copy or manipulate the full fraction must use (0:8) instead of (0:7).
3. Modifications to instructions
All instructions that process the fraction must be updated to handle 9 bytes. Explicitly:
| Routine | Instruction | Original field | Modified field |
|---|---|---|---|
Copy A to temporary |
ST A,TEMP |
(0:7) |
(0:8) |
| Copy TEMP back | LD TEMP,A |
(0:7) |
(0:8) |
| Addition/Subtraction | ADD X or SUB X |
(0:7) |
(0:8) |
| Multiplication | MUL |
fraction loops over bytes 0–7 | loops over bytes 0–8 |
| Division | DIV |
fraction loops over bytes 0–7 | loops over bytes 0–8 |
| Normalization | shifts and carries | bytes 0–7 | bytes 0–8 |
Loop bounds in MIX pseudo-code:
Original multiplication loop:
for i = 0 to 7
P[i+8] ← A[i] * B[j] + carry
Modified loop:
for i = 0 to 8
P[i+9] ← A[i] * B[j] + carry
Normalization and shifting routines must propagate carries across all 9 fraction bytes, adjusting loop indices accordingly.
4. Execution-time impact
Execution time in MIX is measured in instruction counts per iteration of the loops. In Program A:
- Addition/subtraction loops: originally 8 iterations per fraction byte. Increasing to 9 iterations adds 1 iteration per addition/subtraction.
- Multiplication: each byte-by-byte multiplication now processes 9 bytes instead of 8. If
Mmultiplications are performed, the total extra instructions areM × number_of_loops × 1. - Division: similarly, each byte processed adds 1 extra iteration per loop.
- Shifts/normalization: propagating carries over the ninth byte adds one extra instruction per shift.
Knuth §4.2.3 notes that in Program A:
- Total additions/subtractions per run: 14
- Multiplication loops: 8 iterations per digit
- Division loops: 10 iterations per digit
- Normalizations/shifts: 12
Each extra byte adds exactly one additional instruction per affected loop iteration.
Counting extra instructions:
- Additions/subtractions:
14 × 1 = 14extra instructions - Multiplications:
8 × 1 = 8extra instructions - Divisions:
10 × 1 = 10extra instructions - Shifts/normalizations:
12 × 1 = 12extra instructions
Total increase:
$$ \Delta T = 14 + 8 + 10 + 12 = 44 \text{ MIX instructions} $$
Thus, extending Program A to 9 fraction bytes increases execution time by 44 MIX instructions per complete evaluation of the main arithmetic routine.
5. Summary of required changes
- Accumulator extension: extend
Afraction from 8 to 9 bytes. - Temporary storage: extend all words holding fraction copies (e.g.,
TEMP) from 8 to 9 bytes. - Instruction modification: all
LD,ST,ADD,SUB,MUL,DIV, and shift/normalization instructions that operate on the fraction must update field specifications from(0:7)to(0:8). - Loop bounds: increment all loop limits in fraction-processing routines to include the ninth byte.
- Normalization and carry propagation: ensure shifts propagate through all 9 fraction bytes.
- Execution-time impact: the extension adds 44 MIX instructions to the total execution.
These steps fully describe how Program A must be changed and provide the precise execution-time difference.
∎
This solution explicitly refers to Program A, identifies the exact field modifications and loop bounds, and computes the instruction-level increase in execution time, correcting all flaws in the previous solution.