fmsubs
Floating Multiply-Subtract Single - EC 00 00 38
fmsubs

Instruction Syntax

Mnemonic Format Flags
fmsubs frD,frA,frC,frB Rc = 0
fmsubs. frD,frA,frC,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
C
C
C
C
C
0
1
1
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 (multiplicand)
frB 16-20 Source floating-point register B (subtrahend)
frC 21-25 Source floating-point register C (multiplier)
XO 26-30 11100 (28)
Rc 31 Record Condition Register

Operation

frD ← SINGLE((frA × frC) - frB)

The contents of floating-point register frA are multiplied by the contents of floating-point register frC. The contents of floating-point register frB are then subtracted from this intermediate product. The result is rounded to single-precision and placed into floating-point register frD.

Note: This is a fused multiply-subtract operation optimized for single-precision. The intermediate product (frA × frC) is computed to infinite precision, frB is subtracted from it, and then the result is rounded to single-precision format. This provides both the accuracy benefits of fused multiply-subtract and the performance advantages of single-precision arithmetic. The result is stored in double-precision format in the FPR.

Affected Registers

Condition Register (CR1 field)

(if Rc = 1)

Floating-Point Status and Control Register (FPSCR)

Affected fields:

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 Multiply-Subtract

lfs f1, multiplicand(r0)   # Load single-precision multiplicand
lfs f2, subtrahend(r0)     # Load single-precision subtrahend
lfs f3, multiplier(r0)     # Load single-precision multiplier
fmsubs f4, f1, f3, f2      # f4 = SINGLE((f1 × f3) - f2)
stfs f4, result(r0)        # Store single-precision result

3D Graphics: Single-Precision Vector Operations

# Calculate vector difference scaled: result = scale × vector1 - vector2
lfs f1, scale_factor(r0)   # Load scale factor
lfs f2, vector1_x(r0)      # Load vector1 X component
lfs f3, vector2_x(r0)      # Load vector2 X component
fmsubs f4, f1, f2, f3      # f4 = scale × vector1_x - vector2_x
stfs f4, result_x(r0)      # Store result X component

Audio Processing: Single-Precision Echo Subtraction

# Echo removal: output = gain × input - delayed_signal
lfs f1, gain_factor(r0)    # Load gain factor
lfs f2, input_signal(r0)   # Load input signal
lfs f3, delayed_signal(r0) # Load delayed signal (echo)
fmsubs f4, f1, f2, f3      # f4 = gain × input - delayed
stfs f4, clean_output(r0)  # Store echo-free output

Game Physics: Single-Precision Force Calculation

# Net force calculation: F_net = applied_force × multiplier - friction_force
lfs f1, force_multiplier(r0) # Load force multiplier
lfs f2, applied_force(r0)  # Load applied force
lfs f3, friction_force(r0) # Load friction force
fmsubs f4, f1, f2, f3      # f4 = multiplier × applied_force - friction
stfs f4, net_force(r0)     # Store net force

Computer Graphics: Single-Precision Lighting

# Lighting calculation: intensity = light_strength × dot_product - ambient
lfs f1, light_strength(r0) # Load light strength
lfs f2, dot_product(r0)    # Load surface normal · light direction
lfs f3, ambient_light(r0)  # Load ambient light level
fmsubs f4, f1, f2, f3      # f4 = light_strength × dot_product - ambient
stfs f4, light_intensity(r0) # Store lighting intensity

Financial Computing: Single-Precision Profit/Loss

# Calculate profit: profit = selling_price × quantity - cost_basis
lfs f1, selling_price(r0)  # Load selling price per unit
lfs f2, quantity(r0)       # Load quantity sold
lfs f3, cost_basis(r0)     # Load total cost basis
fmsubs f4, f1, f2, f3      # f4 = selling_price × quantity - cost_basis
stfs f4, profit_loss(r0)   # Store profit/loss

Signal Processing: Single-Precision Noise Reduction

# Noise reduction: clean = signal × enhancement_factor - noise_estimate
lfs f1, enhancement_factor(r0) # Load signal enhancement factor
lfs f2, noisy_signal(r0)   # Load noisy signal
lfs f3, noise_estimate(r0) # Load estimated noise
fmsubs f4, f1, f2, f3      # f4 = enhancement × signal - noise
stfs f4, clean_signal(r0)  # Store cleaned signal

Machine Learning: Single-Precision Weight Update

# Weight update: new_weight = learning_rate × gradient - weight_decay
lfs f1, learning_rate(r0)  # Load learning rate
lfs f2, gradient(r0)       # Load gradient
lfs f3, weight_decay(r0)   # Load weight decay term
fmsubs f4, f1, f2, f3      # f4 = learning_rate × gradient - weight_decay
stfs f4, weight_update(r0) # Store weight update

Real-Time Audio: Single-Precision Filter Design

# High-pass filter: output = gain × input - lowpass_component
lfs f1, highpass_gain(r0)  # Load high-pass gain
lfs f2, input_sample(r0)   # Load input sample
lfs f3, lowpass_out(r0)    # Load low-pass filter output
fmsubs f4, f1, f2, f3      # f4 = gain × input - lowpass_out
stfs f4, highpass_out(r0)  # Store high-pass output

Game AI: Single-Precision Pathfinding Cost

# Calculate movement cost: cost = distance × difficulty_multiplier - bonus
lfs f1, difficulty_mult(r0) # Load difficulty multiplier
lfs f2, movement_distance(r0) # Load movement distance
lfs f3, terrain_bonus(r0)  # Load terrain bonus
fmsubs f4, f1, f2, f3      # f4 = difficulty × distance - bonus
stfs f4, movement_cost(r0) # Store movement cost

Scientific Computing: Single-Precision Error Analysis

# Calculate error: error = measured_value × calibration_factor - reference_value
lfs f1, calibration_factor(r0) # Load calibration factor
lfs f2, measured_value(r0) # Load measured value
lfs f3, reference_value(r0) # Load reference value
fmsubs f4, f1, f2, f3      # f4 = calibration × measured - reference
stfs f4, measurement_error(r0) # Store measurement error

Graphics Rendering: Single-Precision Texture Filtering

# Texture filtering: filtered = texture_weight × sample1 - sample2
lfs f1, texture_weight(r0) # Load texture blend weight
lfs f2, texture_sample1(r0) # Load first texture sample
lfs f3, texture_sample2(r0) # Load second texture sample
fmsubs f4, f1, f2, f3      # f4 = weight × sample1 - sample2
stfs f4, filtered_texel(r0) # Store filtered texture value

Related Instructions

fmsub, fmadds, fnmsubs, fnmadds, fmuls, fsubs

Back to Index