fsubs
Floating Subtract Single - EC 00 00 28
fsubs
Instruction Syntax
Mnemonic | Format | Flags |
fsubs | frD,frA,frB | Rc = 0 |
fsubs. | frD,frA,frB | Rc = 1 |
Instruction Encoding
1
1
1
0
1
1
D
D
D
D
D
A
A
A
A
A
B
B
B
B
B
0
0
0
0
0
0
0
0
1
0
1
0
0
Rc
Field | Bits | Description |
Primary Opcode | 0-5 | 111011 (0x3B) |
frD | 6-10 | Destination floating-point register |
frA | 11-15 | Source floating-point register A (minuend) |
frB | 16-20 | Source floating-point register B (subtrahend) |
Reserved | 21-25 | 00000 |
XO | 26-30 | 10100 (20) |
Rc | 31 | Record Condition Register |
Operation
frD ← SINGLE((frA) - (frB))
The contents of floating-point register frB are subtracted from the contents of floating-point register frA. The result is rounded to single-precision and placed into floating-point register frD.
Note: Both operands are converted to single-precision format before the operation, and the result is in single-precision format (stored in double-precision format in the FPR). The subtraction follows IEEE-754 standard for single-precision floating-point arithmetic.
Affected Registers
Condition Register (CR1 field)
(if Rc = 1)
- Reflects floating-point exception summary and status
Floating-Point Status and Control Register (FPSCR)
Affected fields:
- FPRF (Floating-Point Result Flags)
- FX (Floating-Point Exception Summary)
- OX (Overflow Exception)
- UX (Underflow Exception)
- XX (Inexact Exception)
- VXISI (Invalid Operation Exception for ∞ - ∞)
- FR (Fraction Rounded)
- FI (Fraction Inexact)
For more information on floating-point status see Section 2.1.4, "Floating-Point Status and Control Register (FPSCR)," in the PowerPC Microprocessor Family: The Programming Environments manual.
Examples
Basic Single-Precision Subtraction
lfs f1, minuend(r0) # Load minuend (single-precision) lfs f2, subtrahend(r0) # Load subtrahend (single-precision) fsubs f3, f1, f2 # f3 = f1 - f2 (single-precision) stfs f3, result(r0) # Store single-precision result
Single-Precision with Condition Recording
lfs f1, value_a(r0) # Load first value lfs f2, value_b(r0) # Load second value fsubs. f3, f1, f2 # f3 = f1 - f2, set CR1 with FP status # CR1 now reflects floating-point exception status
Graphics/Game Vector Operations
# Single-precision 3D vector subtraction (faster than double) lfs f1, vector1_x(r0) # Load vector1.x (single) lfs f2, vector1_y(r0) # Load vector1.y (single) lfs f3, vector1_z(r0) # Load vector1.z (single) lfs f4, vector2_x(r0) # Load vector2.x (single) lfs f5, vector2_y(r0) # Load vector2.y (single) lfs f6, vector2_z(r0) # Load vector2.z (single) fsubs f7, f1, f4 # result.x = vector1.x - vector2.x fsubs f8, f2, f5 # result.y = vector1.y - vector2.y fsubs f9, f3, f6 # result.z = vector1.z - vector2.z
Audio Processing
# Calculate audio signal difference for noise reduction lfs f1, signal_sample(r0) # Load original signal lfs f2, noise_sample(r0) # Load noise sample fsubs f3, f1, f2 # cleaned = signal - noise stfs f3, output_sample(r0) # Store cleaned signal
Color Channel Processing
# Color difference calculation (single-precision for speed) lfs f1, color1_red(r0) # Load red channel of color1 lfs f2, color1_green(r0) # Load green channel of color1 lfs f3, color1_blue(r0) # Load blue channel of color1 lfs f4, color2_red(r0) # Load red channel of color2 lfs f5, color2_green(r0) # Load green channel of color2 lfs f6, color2_blue(r0) # Load blue channel of color2 fsubs f7, f1, f4 # Difference in red channels fsubs f8, f2, f5 # Difference in green channels fsubs f9, f3, f6 # Difference in blue channels
Performance-Critical Calculations
# Calculate offset from reference (optimized for speed) lfs f1, current_position(r0) # Load current position (single) lfs f2, reference_pos(r0) # Load reference position fsubs f3, f1, f2 # offset = current - reference stfs f3, offset_result(r0) # Store offset
Game Physics Calculations
# Calculate velocity difference for collision detection lfs f1, object1_velocity(r0) # Load object1 velocity lfs f2, object2_velocity(r0) # Load object2 velocity fsubs f3, f1, f2 # relative velocity = v1 - v2 fabs f4, f3 # speed difference = |relative_velocity| stfs f4, speed_diff(r0) # Store speed difference
Single-Precision Error Calculation
# Calculate error with single-precision for performance lfs f1, measured_value(r0) # Load measured value lfs f2, expected_value(r0) # Load expected value fsubs f3, f1, f2 # error = measured - expected fabs f4, f3 # absolute_error = |error| stfs f4, abs_error(r0) # Store absolute error
Real-Time Animation
# Calculate frame-to-frame position change lfs f1, current_frame_pos(r0) # Load current frame position lfs f2, previous_frame_pos(r0) # Load previous frame position fsubs f3, f1, f2 # delta = current - previous stfs f3, position_delta(r0) # Store position change
Mixed Precision Operations
# Subtract double-precision values with single-precision result lfd f1, double_a(r0) # Load double-precision value lfd f2, double_b(r0) # Load double-precision value fsubs f3, f1, f2 # Subtract and round to single-precision stfs f3, single_result(r0) # Store as single-precision