fabs
Floating Absolute Value - FC 00 01 08
fabs
Instruction Syntax
Mnemonic | Format | Flags |
fabs | frD,frB | Rc = 0 |
fabs. | 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
1
0
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 | 100001000 (264) |
Rc | 31 | Record Condition Register |
Operation
frD ← |frB|
The absolute value of the contents of floating-point register frB is placed into floating-point register frD. The operation is performed by clearing 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.
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 Absolute Value
lfd f1, negative_value(r0) # Load negative floating-point value fabs f2, f1 # f2 = |f1| (absolute value) # f2 now contains the positive absolute value
Absolute Value with Condition Recording
lfd f3, input_value(r0) # Load floating-point input fabs. f4, f3 # f4 = |f3|, set FPSCR condition codes # FPSCR condition codes now reflect the result
Distance Calculation
# Calculate absolute difference between two values lfd f1, value_a(r0) # Load first value lfd f2, value_b(r0) # Load second value fsub f3, f1, f2 # f3 = f1 - f2 fabs f4, f3 # f4 = |f1 - f2| (absolute difference)
Vector Magnitude Component
# Calculate absolute values for vector components lfd f1, x_component(r0) # Load X component lfd f2, y_component(r0) # Load Y component lfd f3, z_component(r0) # Load Z component fabs f1, f1 # |X| fabs f2, f2 # |Y| fabs f3, f3 # |Z| # Now ready for magnitude calculation
Sign Removal
# Ensure all values are positive lfd f1, data_array(r3) # Load array element fabs f1, f1 # Remove sign bit stfd f1, data_array(r3) # Store back positive value
Floating-Point Comparison Helper
# Use absolute value in comparisons lfd f1, threshold(r0) # Load threshold value lfd f2, measured_value(r0) # Load measured value fabs f2, f2 # Get absolute value of measurement fcmpo cr0, f2, f1 # Compare |measured| with threshold blt below_threshold # Branch if |measured| < threshold