fdivs
Floating Divide Single - EC 00 00 24
fdivs

Instruction Syntax

Mnemonic Format Flags
fdivs frD,frA,frB Rc = 0
fdivs. 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
0
1
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 (dividend)
frB 16-20 Source floating-point register B (divisor)
Reserved 21-25 00000
XO 26-30 10010 (18)
Rc 31 Record Condition Register

Operation

frD ← SINGLE((frA) ÷ (frB))

The contents of floating-point register frA are divided by the contents of floating-point register frB. 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 division follows IEEE-754 standard for single-precision floating-point arithmetic. Division by zero will set appropriate exception flags.

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 Division

lfs f1, dividend(r0)       # Load dividend (single-precision)
lfs f2, divisor(r0)        # Load divisor (single-precision)
fdivs f3, f1, f2           # f3 = f1 ÷ f2 (single-precision)
stfs f3, result(r0)        # Store single-precision result

Division with Exception Checking

lfs f1, numerator(r0)      # Load numerator
lfs f2, denominator(r0)    # Load denominator
fdivs. f3, f1, f2          # f3 = f1 ÷ f2, set CR1 with FP status
# Check for division by zero or other exceptions in CR1

Graphics/Game Performance Optimization

# Normalize a 3D vector (single-precision for speed)
lfs f1, vector_x(r0)       # Load vector.x
lfs f2, vector_y(r0)       # Load vector.y
lfs f3, vector_z(r0)       # Load vector.z
lfs f4, magnitude(r0)      # Load precalculated magnitude
fdivs f5, f1, f4           # normalized.x = vector.x ÷ magnitude
fdivs f6, f2, f4           # normalized.y = vector.y ÷ magnitude
fdivs f7, f3, f4           # normalized.z = vector.z ÷ magnitude

Game Performance Calculations

# Calculate frames per second
lfs f1, one_constant(r0)   # Load 1.0
lfs f2, frame_time(r0)     # Load frame time in seconds
fdivs f3, f1, f2           # fps = 1.0 ÷ frame_time
stfs f3, frames_per_sec(r0) # Store FPS

Audio Processing

# Calculate signal ratio for dynamic range
lfs f1, signal_level(r0)   # Load signal level
lfs f2, reference_level(r0) # Load reference level
fdivs f3, f1, f2           # ratio = signal ÷ reference
stfs f3, signal_ratio(r0)  # Store ratio

Real-Time Physics

# Calculate velocity: distance ÷ time
lfs f1, distance(r0)       # Load distance
lfs f2, time_delta(r0)     # Load time delta
fdivs f3, f1, f2           # velocity = distance ÷ time
stfs f3, velocity(r0)      # Store velocity

Color Processing

# Normalize color channels to 0-1 range
lfs f1, red_value(r0)      # Load red value (0-255)
lfs f2, red_max(r0)        # Load maximum (255.0)
lfs f3, green_value(r0)    # Load green value
lfs f4, blue_value(r0)     # Load blue value
fdivs f5, f1, f2           # normalized_red = red ÷ 255
fdivs f6, f3, f2           # normalized_green = green ÷ 255
fdivs f7, f4, f2           # normalized_blue = blue ÷ 255

Game AI Calculations

# Calculate success probability
lfs f1, successful_attempts(r0) # Load success count
lfs f2, total_attempts(r0)      # Load total attempts
fdivs f3, f1, f2                # probability = success ÷ total
stfs f3, success_rate(r0)       # Store success rate

Graphics Scaling

# Calculate scale factor for screen fitting
lfs f1, target_size(r0)    # Load target size
lfs f2, current_size(r0)   # Load current size
fdivs f3, f1, f2           # scale = target ÷ current
stfs f3, scale_factor(r0)  # Store scale factor

Safe Division with Zero Check

# Division with zero checking (single-precision)
lfs f1, dividend(r0)       # Load dividend
lfs f2, divisor(r0)        # Load divisor
lfs f3, zero_constant(r0)  # Load 0.0 for comparison
fcmpo cr0, f2, f3          # Compare divisor with zero
beq division_by_zero       # Branch if divisor is zero
fdivs f4, f1, f2           # Safe division
stfs f4, result(r0)        # Store result
b division_done
division_by_zero:
    # Handle division by zero case
    lfs f4, large_value(r0) # Load large value or infinity
    stfs f4, result(r0)     # Store error result
division_done:

Mixed Precision Operations

# Divide double-precision values with single-precision result
lfd f1, double_dividend(r0) # Load double-precision dividend
lfd f2, double_divisor(r0)  # Load double-precision divisor
fdivs f3, f1, f2            # Divide and round to single-precision
stfs f3, single_result(r0)  # Store as single-precision

Related Instructions

fdiv, fmuls, fadds, fsubs, fres

Back to Index