fsqrts
Floating Square Root Single - EC 00 00 2C
fsqrts

Instruction Syntax

Mnemonic Format Flags
fsqrts frD,frB Rc = 0
fsqrts. 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
0
1
1
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 010110 (22)
Rc 31 Record Condition Register

Operation

frD ← SINGLE(√frB)

The square root of the contents of floating-point register frB is computed and rounded to single-precision, then placed into floating-point register frD. The result is stored in double-precision format in the FPR.

Note: This instruction computes the square root with single-precision accuracy and follows IEEE-754 standard for single-precision floating-point arithmetic. If the contents of frB is negative (other than -0.0), the result is a NaN (Not a Number), and the VXSQRT exception is signaled. The operand is converted to single-precision format before the operation.

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 Square Root

lfs f1, input_value(r0)     # Load single-precision input
fsqrts f2, f1               # f2 = SINGLE(√f1)
stfs f2, sqrt_result(r0)    # Store single-precision result

Fast 2D Distance Calculation

# Fast 2D distance: d = √((x₁-x₂)² + (y₁-y₂)²) (single-precision)
lfs f1, point1_x(r0)        # Load point 1 X (single-precision)
lfs f2, point1_y(r0)        # Load point 1 Y (single-precision)
lfs f3, point2_x(r0)        # Load point 2 X (single-precision)
lfs f4, point2_y(r0)        # Load point 2 Y (single-precision)
fsubs f5, f1, f3            # f5 = x₁ - x₂
fsubs f6, f2, f4            # f6 = y₁ - y₂
fmuls f7, f5, f5            # f7 = (x₁ - x₂)²
fmadds f8, f6, f6, f7       # f8 = (x₁ - x₂)² + (y₁ - y₂)²
fsqrts f9, f8               # f9 = √((x₁ - x₂)² + (y₁ - y₂)²) = distance
stfs f9, distance_2d(r0)    # Store 2D distance

3D Graphics: Single-Precision Vector Magnitude

# Calculate 3D vector magnitude with single-precision
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² = magnitude²
fsqrts f5, f4               # f5 = √(x² + y² + z²) = |v|
stfs f5, vector_mag(r0)     # Store vector magnitude

Game Physics: Fast Collision Radius

# Calculate collision radius from area (single-precision for speed)
lfs f1, collision_area(r0)  # Load collision area
lfs f2, pi_constant(r0)     # Load π constant
fdivs f3, f1, f2            # f3 = area/π
fsqrts f4, f3               # f4 = √(area/π) = radius
stfs f4, collision_radius(r0) # Store collision radius

Audio Processing: Single-Precision RMS

# Fast single-precision RMS calculation for real-time audio
lfs f1, sum_squared(r0)     # Load sum of squared samples (single-precision)
lfs f2, sample_count(r0)    # Load sample count (single-precision)
fdivs f3, f1, f2            # f3 = mean of squares
fsqrts f4, f3               # f4 = √(mean of squares) = RMS
stfs f4, rms_level(r0)      # Store RMS level

Real-Time Graphics: Fast Normal Vector Length

# Calculate normal vector length for normalization (single-precision)
lfs f1, normal_x(r0)        # Load normal X component
lfs f2, normal_y(r0)        # Load normal Y component
lfs f3, normal_z(r0)        # Load normal Z component
fmuls f4, f1, f1            # f4 = nx²
fmadds f4, f2, f2, f4       # f4 = nx² + ny²
fmadds f4, f3, f3, f4       # f4 = nx² + ny² + nz²
fsqrts f5, f4               # f5 = √(nx² + ny² + nz²) = |normal|
stfs f5, normal_length(r0)  # Store normal vector length

Machine Learning: Fast Single-Precision L2 Norm

# Fast L2 norm calculation for neural networks (single-precision)
lfs f1, weight_1(r0)        # Load weight 1
lfs f2, weight_2(r0)        # Load weight 2
lfs f3, weight_3(r0)        # Load weight 3
fmuls f4, f1, f1            # f4 = w1²
fmadds f4, f2, f2, f4       # f4 = w1² + w2²
fmadds f4, f3, f3, f4       # f4 = w1² + w2² + w3²
fsqrts f5, f4               # f5 = √(w1² + w2² + w3²) = L2 norm
stfs f5, l2_norm(r0)        # Store L2 norm

Financial Computing: Single-Precision Volatility

# Calculate volatility with single-precision for speed
lfs f1, variance(r0)        # Load variance (single-precision)
fsqrts f2, f1               # f2 = √variance = volatility
stfs f2, volatility(r0)     # Store volatility

Game AI: Fast Pathfinding Heuristic

# Fast heuristic distance for A* pathfinding (single-precision)
lfs f1, current_x(r0)       # Load current position X
lfs f2, current_y(r0)       # Load current position Y
lfs f3, goal_x(r0)          # Load goal position X
lfs f4, goal_y(r0)          # Load goal position Y
fsubs f5, f3, f1            # f5 = goal_x - current_x
fsubs f6, f4, f2            # f6 = goal_y - current_y
fmuls f7, f5, f5            # f7 = (goal_x - current_x)²
fmadds f7, f6, f6, f7       # f7 = distance²
fsqrts f8, f7               # f8 = √distance² = heuristic distance
stfs f8, heuristic_dist(r0) # Store heuristic distance

Signal Processing: Single-Precision Magnitude

# Calculate magnitude of complex signal (single-precision)
lfs f1, real_component(r0)  # Load real part
lfs f2, imag_component(r0)  # Load imaginary part
fmuls f3, f1, f1            # f3 = real²
fmadds f4, f2, f2, f3       # f4 = real² + imag²
fsqrts f5, f4               # f5 = √(real² + imag²) = magnitude
stfs f5, signal_magnitude(r0) # Store signal magnitude

Physics Simulation: Fast Force Magnitude

# Calculate resultant force magnitude (single-precision for speed)
lfs f1, force_x(r0)         # Load force X component
lfs f2, force_y(r0)         # Load force Y component
lfs f3, force_z(r0)         # Load force Z component
fmuls f4, f1, f1            # f4 = Fx²
fmadds f4, f2, f2, f4       # f4 = Fx² + Fy²
fmadds f4, f3, f3, f4       # f4 = Fx² + Fy² + Fz²
fsqrts f5, f4               # f5 = √(Fx² + Fy² + Fz²) = |F|
stfs f5, force_magnitude(r0) # Store force magnitude

Computer Graphics: Single-Precision Texture Filtering

# Fast texture coordinate distance calculation
lfs f1, tex_u1(r0)          # Load texture U coordinate 1
lfs f2, tex_v1(r0)          # Load texture V coordinate 1
lfs f3, tex_u2(r0)          # Load texture U coordinate 2
lfs f4, tex_v2(r0)          # Load texture V coordinate 2
fsubs f5, f3, f1            # f5 = u2 - u1
fsubs f6, f4, f2            # f6 = v2 - v1
fmuls f7, f5, f5            # f7 = (u2 - u1)²
fmadds f8, f6, f6, f7       # f8 = (u2 - u1)² + (v2 - v1)²
fsqrts f9, f8               # f9 = texture coordinate distance
stfs f9, tex_distance(r0)   # Store texture distance

Related Instructions

fsqrt, fres, frsqrte, fmuls, fdivs, fmadds

Back to Index