fnabs
Floating Negative Absolute Value - FC 00 01 10
fnabs
Instruction Syntax
Mnemonic | Format | Flags |
fnabs | frD,frB | Rc = 0 |
fnabs. | frD,frB | Rc = 1 |
Instruction Encoding
1
1
1
1
1
1
D
D
D
D
D
0
0
0
0
0
B
B
B
B
B
0
0
1
0
0
0
1
0
0
0
Rc
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 | 0 |
XO | 22-30 | 010001000 (136) |
Rc | 31 | Record Condition Register |
Operation
frD ← -|frB|
The negative absolute value of the contents of floating-point register frB is placed into floating-point register frD. The operation is performed by setting the sign bit of frB to 1, ensuring the result is always negative.
Note: This instruction does not affect the floating-point status and control register (FPSCR) exception bits, but may affect the FPSCR condition code bits if Rc = 1. The result is always negative regardless of the input sign.
Affected Registers
Floating-Point Status and Control Register (FPSCR)
(if Rc = 1)
- FPRF (Floating-Point Result Flags) - updated to reflect the result
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 Negative Absolute Value
lfd f1, input_value(r0) # Load floating-point value (positive or negative) fnabs f2, f1 # f2 = -|f1| (always negative) stfd f2, result(r0) # Store negative absolute value
Negative Absolute Value with Condition Recording
lfd f3, input_value(r0) # Load input value fnabs. f4, f3 # f4 = -|f3|, set FPSCR condition codes # FPSCR condition codes now reflect the negative absolute result
Force Values to be Negative
# Ensure all values are negative (useful for loss/cost functions) lfd f1, cost1(r0) # Load cost 1 (could be positive or negative) lfd f2, cost2(r0) # Load cost 2 lfd f3, cost3(r0) # Load cost 3 fnabs f4, f1 # Ensure cost1 is negative fnabs f5, f2 # Ensure cost2 is negative fnabs f6, f3 # Ensure cost3 is negative # All costs are now guaranteed to be negative
Distance with Direction Indicator
# Calculate distance but force negative (indicating inward/backward movement) lfd f1, measured_distance(r0) # Load distance (absolute value) fnabs f2, f1 # Make distance negative (inward direction) stfd f2, directional_dist(r0) # Store directional distance
Financial Loss Calculation
# Ensure losses are represented as negative values lfd f1, expense_amount(r0) # Load expense (might be entered as positive) lfd f2, penalty_amount(r0) # Load penalty fnabs f3, f1 # Ensure expense is negative fnabs f4, f2 # Ensure penalty is negative fadd f5, f3, f4 # Total loss = expense + penalty (both negative) stfd f5, total_loss(r0) # Store total loss (negative value)
Graphics Depth Buffer
# Force depth values to be negative (for certain rendering techniques) lfd f1, depth_value(r0) # Load depth value fnabs f2, f1 # Force depth to be negative stfd f2, neg_depth(r0) # Store negative depth
Signal Processing
# Create inverted signal envelope (always negative) lfd f1, signal_amplitude(r0) # Load signal amplitude fnabs f2, f1 # Create negative envelope stfd f2, inverted_env(r0) # Store inverted envelope
Error Magnitude with Sign
# Calculate error magnitude but keep it negative to indicate error lfd f1, measured_value(r0) # Load measured value lfd f2, expected_value(r0) # Load expected value fsub f3, f1, f2 # Calculate difference fabs f4, f3 # Get magnitude of error fnabs f5, f4 # Make error magnitude negative stfd f5, error_magnitude(r0) # Store negative error magnitude
Game Physics - Damage Calculation
# Ensure damage values are negative (health reduction) lfd f1, raw_damage(r0) # Load raw damage amount lfd f2, armor_reduction(r0) # Load armor reduction factor fmul f3, f1, f2 # Apply armor reduction fnabs f4, f3 # Ensure final damage is negative stfd f4, final_damage(r0) # Store final damage (negative)
Mathematical Function Implementation
# Implement -|x| function efficiently lfd f1, input_x(r0) # Load input value x fnabs f2, f1 # f2 = -|x| in one instruction stfd f2, output_y(r0) # Store result y = -|x| # This is more efficient than separate fabs + fneg operations
Vector Component Normalization
# Normalize vector but force all components negative 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 lfd f4, magnitude(r0) # Load vector magnitude fdiv f5, f1, f4 # normalized_x = x / magnitude fdiv f6, f2, f4 # normalized_y = y / magnitude fdiv f7, f3, f4 # normalized_z = z / magnitude fnabs f5, f5 # Force X component negative fnabs f6, f6 # Force Y component negative fnabs f7, f7 # Force Z component negative