fneg
Floating Negate - FC 00 00 50
fneg
Instruction Syntax
Mnemonic | Format | Flags |
fneg | frD,frB | Rc = 0 |
fneg. | 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
0
0
1
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 | 000101000 (40) |
Rc | 31 | Record Condition Register |
Operation
frD ← -frB
The negation of the contents of floating-point register frB is placed into floating-point register frD. The operation is performed by inverting the sign bit of frB.
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 operation is implemented by simply flipping the sign bit.
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 Negation
lfd f1, input_value(r0) # Load floating-point value fneg f2, f1 # f2 = -f1 (negate) stfd f2, negated_result(r0) # Store negated value
Negation with Condition Recording
lfd f3, input_value(r0) # Load input value fneg. f4, f3 # f4 = -f3, set FPSCR condition codes # FPSCR condition codes now reflect the negated result
Vector Negation
# Negate all components of a 3D vector lfd f1, vector_x(r0) # Load vector.x lfd f2, vector_y(r0) # Load vector.y lfd f3, vector_z(r0) # Load vector.z fneg f4, f1 # negated.x = -vector.x fneg f5, f2 # negated.y = -vector.y fneg f6, f3 # negated.z = -vector.z
Direction Reversal
# Reverse direction vector for physics lfd f1, velocity_x(r0) # Load velocity X lfd f2, velocity_y(r0) # Load velocity Y lfd f3, velocity_z(r0) # Load velocity Z fneg f1, f1 # Reverse X direction fneg f2, f2 # Reverse Y direction fneg f3, f3 # Reverse Z direction stfd f1, velocity_x(r0) # Store reversed X stfd f2, velocity_y(r0) # Store reversed Y stfd f3, velocity_z(r0) # Store reversed Z
Mathematical Operations
# Calculate: result = a - b (using negation and addition) lfd f1, value_a(r0) # Load a lfd f2, value_b(r0) # Load b fneg f3, f2 # f3 = -b fadd f4, f1, f3 # f4 = a + (-b) = a - b stfd f4, result(r0) # Store result
Sign Toggle
# Toggle sign based on condition lfd f1, input_value(r0) # Load input value lwz r3, should_negate(r0) # Load condition flag cmpwi cr0, r3, 0 # Check if should negate beq skip_negation # Skip if flag is 0 fneg f1, f1 # Negate if flag is non-zero skip_negation: stfd f1, output_value(r0) # Store result
Absolute Difference Calculation
# Calculate |a - b| using negation lfd f1, value_a(r0) # Load a lfd f2, value_b(r0) # Load b fsub f3, f1, f2 # f3 = a - b fabs f4, f3 # f4 = |a - b| fneg f5, f3 # f5 = -(a - b) = b - a fabs f6, f5 # f6 = |b - a| (same as f4) # Both f4 and f6 contain |a - b|
Oscillation/Wave Calculations
# Create oscillating value (sine wave approximation) lfd f1, amplitude(r0) # Load amplitude lfd f2, phase_flag(r0) # Load phase indicator fcmpo cr0, f2, f0 # Compare with zero bge positive_phase # Branch if positive phase fneg f1, f1 # Negate amplitude for negative phase positive_phase: stfd f1, oscillation_value(r0) # Store oscillating value
Color Inversion
# Invert color values (for visual effects) lfd f1, color_offset(r0) # Load color offset lfd f2, red_channel(r0) # Load red channel lfd f3, green_channel(r0) # Load green channel lfd f4, blue_channel(r0) # Load blue channel fneg f2, f2 # Invert red fneg f3, f3 # Invert green fneg f4, f4 # Invert blue fadd f2, f2, f1 # Add offset to red fadd f3, f3, f1 # Add offset to green fadd f4, f4, f1 # Add offset to blue
Financial Calculations
# Convert credit to debit (negate amount) lfd f1, transaction_amount(r0) # Load transaction amount lwz r3, is_credit(r0) # Load credit flag cmpwi cr0, r3, 1 # Check if it's a credit bne store_amount # If not credit, use as-is fneg f1, f1 # Negate for debit representation store_amount: stfd f1, final_amount(r0) # Store final amount
Physics Force Calculation
# Apply opposite force (Newton's third law) lfd f1, applied_force_x(r0) # Load applied force X lfd f2, applied_force_y(r0) # Load applied force Y lfd f3, applied_force_z(r0) # Load applied force Z fneg f4, f1 # reaction_force.x = -applied_force.x fneg f5, f2 # reaction_force.y = -applied_force.y fneg f6, f3 # reaction_force.z = -applied_force.z stfd f4, reaction_force_x(r0) # Store reaction force X stfd f5, reaction_force_y(r0) # Store reaction force Y stfd f6, reaction_force_z(r0) # Store reaction force Z