Instruction Syntax
Mnemonic | Format | Flags |
frsqrte | frD,frB | Rc = 0 |
frsqrte. | frD,frB | Rc = 1 |
Instruction Encoding
Field | Bits | Description |
Primary Opcode | 0-5 | 111111 (0x3F) |
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 | 011010 (26) |
Rc | 31 | Record Condition Register |
Operation
frD ← ESTIMATE(1.0 / √frB)
An estimate of the reciprocal of the square root 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/32.
Note: This instruction provides a fast approximation of 1/√frB with double-precision accuracy. It's essential for high-performance vector normalization, distance calculations, and 3D graphics applications where speed is critical. 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)
- 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)
- ZX (Zero Divide Exception) - if frB is zero
- VXSNAN (Invalid Operation Exception for SNaN)
- VXSQRT (Invalid Operation Exception for square root of negative number)
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 Square Root Estimation
lfd f1, input_value(r0) # Load input value frsqrte f2, f1 # f2 = estimate of 1/√f1 stfd f2, rsqrt_estimate(r0) # Store reciprocal square root estimate
Fast Vector Normalization
# Fast 3D vector normalization: v_norm = v / |v| lfd f1, vector_x(r0) # Load vector X component lfd f2, vector_y(r0) # Load vector Y component lfd f3, vector_z(r0) # Load vector Z component fmadd f4, f1, f1, f0 # f4 = x² fmadd f4, f2, f2, f4 # f4 = x² + y² fmadd f4, f3, f3, f4 # f4 = x² + y² + z² = |v|² frsqrte f5, f4 # f5 = 1/√|v|² = 1/|v| fmul f6, f1, f5 # f6 = x × (1/|v|) = normalized X fmul f7, f2, f5 # f7 = y × (1/|v|) = normalized Y fmul f8, f3, f5 # f8 = z × (1/|v|) = normalized Z stfd f6, norm_vector_x(r0) # Store normalized X stfd f7, norm_vector_y(r0) # Store normalized Y stfd f8, norm_vector_z(r0) # Store normalized Z
High-Precision Vector Normalization with Newton-Raphson
# High-accuracy vector normalization using refinement lfd f1, vector_x(r0) # Load vector X lfd f2, vector_y(r0) # Load vector Y lfd f3, vector_z(r0) # Load vector Z lfd f10, half_constant(r0) # Load 0.5 lfd f11, three_constant(r0) # Load 3.0 fmadd f4, f1, f1, f0 # f4 = x² fmadd f4, f2, f2, f4 # f4 = x² + y² fmadd f4, f3, f3, f4 # f4 = |v|² frsqrte f5, f4 # f5 = initial estimate of 1/√|v|² # Newton-Raphson refinement: x₊₁ = 0.5 × x × (3 - a × x²) fmul f6, f5, f5 # f6 = estimate² fmul f7, f4, f6 # f7 = |v|² × estimate² fsub f8, f11, f7 # f8 = 3 - |v|² × estimate² fmul f9, f5, f8 # f9 = estimate × (3 - |v|² × estimate²) fmul f5, f10, f9 # f5 = refined 1/√|v|² (high accuracy) fmul f6, f1, f5 # f6 = normalized X (high accuracy) fmul f7, f2, f5 # f7 = normalized Y (high accuracy) fmul f8, f3, f5 # f8 = normalized Z (high accuracy) stfd f6, precise_norm_x(r0) # Store precise normalized X stfd f7, precise_norm_y(r0) # Store precise normalized Y stfd f8, precise_norm_z(r0) # Store precise normalized Z
Fast Distance Calculation
# Fast distance calculation: d = √((x₁-x₂)² + (y₁-y₂)² + (z₁-z₂)²) lfd f1, point1_x(r0) # Load point 1 X lfd f2, point1_y(r0) # Load point 1 Y lfd f3, point1_z(r0) # Load point 1 Z lfd f4, point2_x(r0) # Load point 2 X lfd f5, point2_y(r0) # Load point 2 Y lfd f6, point2_z(r0) # Load point 2 Z fsub f7, f1, f4 # f7 = x₁ - x₂ fsub f8, f2, f5 # f8 = y₁ - y₂ fsub f9, f3, f6 # f9 = z₁ - z₂ fmadd f10, f7, f7, f0 # f10 = (x₁-x₂)² fmadd f10, f8, f8, f10 # f10 = (x₁-x₂)² + (y₁-y₂)² fmadd f10, f9, f9, f10 # f10 = distance² frsqrte f11, f10 # f11 = 1/√distance² frec f12, f11 # f12 = 1/(1/√distance²) = √distance² = distance stfd f12, distance(r0) # Store distance
3D Graphics: Fast Normal Map Processing
# Normalize normal map vectors for lighting calculations lfd f1, normal_map_x(r0) # Load normal map X component lfd f2, normal_map_y(r0) # Load normal map Y component lfd f3, normal_map_z(r0) # Load normal map Z component fmadd f4, f1, f1, f0 # f4 = x² fmadd f4, f2, f2, f4 # f4 = x² + y² fmadd f4, f3, f3, f4 # f4 = x² + y² + z² = magnitude² frsqrte f5, f4 # f5 = 1/√magnitude² fmul f6, f1, f5 # f6 = normalized normal X fmul f7, f2, f5 # f7 = normalized normal Y fmul f8, f3, f5 # f8 = normalized normal Z stfd f6, normalized_nx(r0) # Store normalized normal X stfd f7, normalized_ny(r0) # Store normalized normal Y stfd f8, normalized_nz(r0) # Store normalized normal Z
Physics Engine: Fast Velocity Normalization
# Normalize velocity vector for direction calculation lfd f1, velocity_x(r0) # Load velocity X lfd f2, velocity_y(r0) # Load velocity Y lfd f3, velocity_z(r0) # Load velocity Z fmadd f4, f1, f1, f0 # f4 = vx² fmadd f4, f2, f2, f4 # f4 = vx² + vy² fmadd f4, f3, f3, f4 # f4 = vx² + vy² + vz² = |v|² frsqrte f5, f4 # f5 = 1/|v| fmul f6, f1, f5 # f6 = normalized direction X fmul f7, f2, f5 # f7 = normalized direction Y fmul f8, f3, f5 # f8 = normalized direction Z stfd f6, direction_x(r0) # Store direction X stfd f7, direction_y(r0) # Store direction Y stfd f8, direction_z(r0) # Store direction Z
Game AI: Fast Pathfinding Distance Heuristic
# Fast heuristic distance calculation for A* pathfinding lfd f1, current_x(r0) # Load current position X lfd f2, current_y(r0) # Load current position Y lfd f3, goal_x(r0) # Load goal position X lfd f4, goal_y(r0) # Load goal position Y fsub f5, f3, f1 # f5 = goal_x - current_x fsub f6, f4, f2 # f6 = goal_y - current_y fmadd f7, f5, f5, f0 # f7 = (goal_x - current_x)² fmadd f7, f6, f6, f7 # f7 = distance² frsqrte f8, f7 # f8 = 1/√distance² frec f9, f8 # f9 = √distance² = heuristic distance stfd f9, heuristic_dist(r0) # Store heuristic distance
Audio Processing: Fast RMS Calculation
# Fast RMS (Root Mean Square) calculation for audio level metering lfd f1, sample_sum_squares(r0) # Load sum of squared samples lfd f2, sample_count(r0) # Load number of samples fdiv f3, f1, f2 # f3 = mean of squares frsqrte f4, f3 # f4 = 1/√(mean of squares) frec f5, f4 # f5 = √(mean of squares) = RMS value stfd f5, rms_level(r0) # Store RMS level
Scientific Computing: Fast Standard Deviation
# Fast standard deviation calculation: σ = √(Σ(x-μ)²/N) lfd f1, variance(r0) # Load variance (Σ(x-μ)²/N) frsqrte f2, f1 # f2 = 1/√variance frec f3, f2 # f3 = √variance = standard deviation stfd f3, std_deviation(r0) # Store standard deviation
Machine Learning: Fast Gradient Magnitude
# Fast gradient magnitude calculation for optimization lfd f1, gradient_x(r0) # Load gradient X component lfd f2, gradient_y(r0) # Load gradient Y component fmadd f3, f1, f1, f0 # f3 = gradient_x² fmadd f3, f2, f2, f3 # f3 = gradient_x² + gradient_y² frsqrte f4, f3 # f4 = 1/√(gradient magnitude²) frec f5, f4 # f5 = gradient magnitude stfd f5, grad_magnitude(r0) # Store gradient magnitude
Real-Time Graphics: Fast Specular Lighting
# Fast specular reflection calculation with normalization lfd f1, reflect_x(r0) # Load reflection vector X lfd f2, reflect_y(r0) # Load reflection vector Y lfd f3, reflect_z(r0) # Load reflection vector Z lfd f4, view_x(r0) # Load view vector X lfd f5, view_y(r0) # Load view vector Y lfd f6, view_z(r0) # Load view vector Z # Normalize reflection vector fmadd f7, f1, f1, f0 # f7 = reflect_x² fmadd f7, f2, f2, f7 # f7 = reflect_x² + reflect_y² fmadd f7, f3, f3, f7 # f7 = |reflect|² frsqrte f8, f7 # f8 = 1/|reflect| fmul f9, f1, f8 # f9 = normalized reflect X fmul f10, f2, f8 # f10 = normalized reflect Y fmul f11, f3, f8 # f11 = normalized reflect Z # Calculate dot product for specular term fmadd f12, f9, f4, f0 # f12 = reflect·view (partial) fmadd f12, f10, f5, f12 # f12 = reflect·view (partial) fmadd f12, f11, f6, f12 # f12 = reflect·view (final dot product) stfd f12, specular_factor(r0) # Store specular lighting factor