fres
Floating Reciprocal Estimate Single - EC 00 00 30
fres

Instruction Syntax

Mnemonic Format Flags
fres frD,frB Rc = 0
fres. frD,frB Rc = 1

Instruction Encoding

1
1
1
0
1
1
D
D
D
D
D
0
0
0
0
0
B
B
B
B
B
0
0
0
0
0
0
1
1
0
0
0
Rc

Field Bits Description
Primary Opcode 0-5 111011 (0x3B)
frD 6-10 Destination floating-point register
Reserved 11-15 00000
frB 16-20 Source floating-point register B
Reserved 21-25 00000
XO 26-30 11000 (24)
Rc 31 Record Condition Register

Operation

frD ← SINGLE_ESTIMATE(1.0 / frB)

A single-precision estimate of the reciprocal of the contents of floating-point register frB is placed into floating-point register frD. The estimate has a relative error no greater than 1/256.

Note: This instruction provides a fast approximation of 1/frB with single-precision accuracy. It's designed for performance-critical applications where speed is more important than absolute precision. For higher accuracy, the result can be refined using Newton-Raphson iteration. This is an optional instruction that may not be available on all PowerPC implementations.

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 Reciprocal Estimation

lfs f1, input_value(r0)     # Load single-precision input
fres f2, f1                 # f2 = estimate of 1/f1
stfs f2, reciprocal_est(r0) # Store reciprocal estimate

Fast Division Using Reciprocal Estimate

# Fast division: a / b ≈ a × (1/b)
lfs f1, dividend(r0)        # Load dividend (a)
lfs f2, divisor(r0)         # Load divisor (b)
fres f3, f2                 # f3 = estimate of 1/b
fmuls f4, f1, f3            # f4 = a × (1/b) ≈ a/b
stfs f4, division_result(r0) # Store division result

High-Precision Division with Newton-Raphson Refinement

# Refine reciprocal estimate for higher accuracy
lfs f1, dividend(r0)        # Load dividend
lfs f2, divisor(r0)         # Load divisor
lfs f3, two_constant(r0)    # Load 2.0
fres f4, f2                 # f4 = initial estimate of 1/divisor
# Newton-Raphson iteration: x₊₁ = x(2 - bx)
fmuls f5, f2, f4            # f5 = divisor × estimate
fsubs f6, f3, f5            # f6 = 2 - (divisor × estimate)
fmuls f7, f4, f6            # f7 = estimate × (2 - divisor × estimate) = refined estimate
fmuls f8, f1, f7            # f8 = dividend × refined_reciprocal = accurate division
stfs f8, accurate_division(r0) # Store high-accuracy result

3D Graphics: Fast Normal Vector Normalization

# Fast vector normalization: v_norm = v / |v|
lfs f1, vector_x(r0)        # Load vector X component
lfs f2, vector_y(r0)        # Load vector Y component  
lfs f3, vector_z(r0)        # Load vector Z component
fmuls f4, f1, f1            # f4 = x²
fmadds f4, f2, f2, f4       # f4 = x² + y²
fmadds f4, f3, f3, f4       # f4 = x² + y² + z² = |v|²
frsqrte f5, f4              # f5 = estimate of 1/√|v|² (if available)
# Alternative using fres:
# fsqrts f5, f4            # f5 = √|v|² = |v|
# fres f5, f5              # f5 = 1/|v|
fmuls f6, f1, f5            # f6 = x/|v| = normalized X
fmuls f7, f2, f5            # f7 = y/|v| = normalized Y
fmuls f8, f3, f5            # f8 = z/|v| = normalized Z
stfs f6, norm_vector_x(r0)  # Store normalized X
stfs f7, norm_vector_y(r0)  # Store normalized Y
stfs f8, norm_vector_z(r0)  # Store normalized Z

Audio Processing: Fast Gain Normalization

# Normalize audio level using reciprocal estimate
lfs f1, audio_sample(r0)    # Load audio sample
lfs f2, current_level(r0)   # Load current audio level
lfs f3, target_level(r0)    # Load target level
fres f4, f2                 # f4 = 1/current_level
fmuls f5, f3, f4            # f5 = target_level/current_level = gain factor
fmuls f6, f1, f5            # f6 = sample × gain = normalized sample
stfs f6, normalized_audio(r0) # Store normalized audio

Game Physics: Fast Collision Response

# Calculate collision response using reciprocal for performance
lfs f1, impact_force(r0)    # Load impact force
lfs f2, object_mass(r0)     # Load object mass
fres f3, f2                 # f3 = 1/mass
fmuls f4, f1, f3            # f4 = force/mass = acceleration
stfs f4, acceleration(r0)   # Store acceleration

Scientific Computing: Iterative Algorithm Optimization

# Fast reciprocal in iterative calculations
lfs f1, iteration_value(r0) # Load current iteration value
lfs f2, convergence_factor(r0) # Load convergence factor
fres f3, f1                 # f3 = 1/iteration_value
fmuls f4, f2, f3            # f4 = convergence_factor/iteration_value
stfs f4, next_iteration(r0) # Store next iteration value

Graphics Shader: Fast Lighting Calculations

# Fast distance-based lighting attenuation
lfs f1, light_intensity(r0) # Load base light intensity
lfs f2, distance_squared(r0) # Load distance² to light source
fres f3, f2                 # f3 = 1/distance²
fmuls f4, f1, f3            # f4 = intensity/distance² = attenuated light
stfs f4, final_lighting(r0) # Store final lighting intensity

Signal Processing: Fast Filter Coefficient Calculation

# Calculate filter coefficients using reciprocal estimates
lfs f1, cutoff_frequency(r0) # Load cutoff frequency
lfs f2, sample_rate(r0)     # Load sample rate
fres f3, f2                 # f3 = 1/sample_rate
fmuls f4, f1, f3            # f4 = cutoff/sample_rate = normalized frequency
# Use f4 for filter coefficient calculations...
stfs f4, normalized_freq(r0) # Store normalized frequency

Machine Learning: Fast Gradient Descent

# Fast learning rate adjustment using reciprocal
lfs f1, gradient_magnitude(r0) # Load gradient magnitude
lfs f2, base_learning_rate(r0) # Load base learning rate
fres f3, f1                 # f3 = 1/gradient_magnitude
fmuls f4, f2, f3            # f4 = adaptive learning rate
stfs f4, adaptive_rate(r0)  # Store adaptive learning rate

Financial Computing: Fast Ratio Calculations

# Fast financial ratio calculation
lfs f1, asset_value(r0)     # Load asset value
lfs f2, liability_value(r0) # Load liability value
fres f3, f2                 # f3 = 1/liability_value
fmuls f4, f1, f3            # f4 = asset/liability = ratio
stfs f4, financial_ratio(r0) # Store financial ratio

Real-Time Simulation: Fast Physics Integration

# Fast time step calculations using reciprocal
lfs f1, velocity_change(r0) # Load velocity change
lfs f2, time_step(r0)       # Load time step
fres f3, f2                 # f3 = 1/time_step
fmuls f4, f1, f3            # f4 = velocity_change/time_step = acceleration
stfs f4, calculated_accel(r0) # Store calculated acceleration

Game AI: Fast Probability Calculations

# Fast probability normalization using reciprocal
lfs f1, event_weight(r0)    # Load event weight
lfs f2, total_weight(r0)    # Load total weight
fres f3, f2                 # f3 = 1/total_weight
fmuls f4, f1, f3            # f4 = event_weight/total_weight = probability
stfs f4, event_probability(r0) # Store event probability

Related Instructions

fdivs, frsqrte, fmuls, fsqrts, fmadds

Back to Index