Instruction Syntax
Mnemonic | Format | Flags |
lfsx | frD,rA,rB | - |
Instruction Encoding
Field | Bits | Description |
Primary Opcode | 0-5 | 011111 (0x1F) |
frD | 6-10 | Destination floating-point register |
rA | 11-15 | Source register A |
rB | 16-20 | Source register B |
XO | 21-30 | 535 (Extended opcode) |
Rc | 31 | Reserved (0) |
Operation
if rA = 0 then EA ← (rB) else EA ← (rA) + (rB) frD ← DOUBLE(MEM(EA, 4))
A single-precision floating-point value (32 bits) is loaded from memory, converted to double-precision format, and placed in floating-point register frD. The effective address is computed by adding the contents of registers rA and rB, or just rB if rA is 0.
Note: This indexed form is essential for array access and dynamic addressing with single-precision data. The loaded single-precision value is automatically converted to double-precision before being stored in the FPR. The effective address should be word-aligned (divisible by 4) for optimal performance. If rA=0, it is treated as the value 0, not the contents of register r0.
Affected Registers
None (load instruction does not affect condition registers).
For more information on floating-point operations see Section 2.1.4, "Floating-Point Status and Control Register (FPSCR)," in the PowerPC Microprocessor Family: The Programming Environments manual.
Examples
Audio Sample Array Processing
# Process audio samples with dynamic indexing lis r3, audio_samples@ha addi r3, r3, audio_samples@l lwz r4, sample_rate(r0) # Sample rate (e.g., 44100) li r5, 1000 # Process 1000 samples li r6, 0 # Sample index audio_loop: slwi r7, r6, 2 # Convert index to byte offset (* 4) lfsx f1, r3, r7 # Load audio sample # Apply audio effects (e.g., reverb, EQ) bl apply_audio_effects # Process sample in f1 addi r6, r6, 1 # Next sample cmpw r6, r5 # Check if done blt audio_loop # Continue processing
3D Graphics Texture Sampling
# Sample texture data with computed coordinates lis r3, texture_data@ha addi r3, r3, texture_data@l lwz r4, texture_width(r0) # Texture width lfs f1, tex_u(r0) # U coordinate (0.0-1.0) lfs f2, tex_v(r0) # V coordinate (0.0-1.0) # Convert normalized coordinates to pixel coordinates stw r4, temp_width(r1) lfs f3, temp_width(r1) # Convert width to float fmul f4, f1, f3 # u * width fctiwz f5, f4 # Convert to integer stfd f5, temp_u(r1) lwz r5, temp_u+4(r1) # Integer u coordinate # Calculate texel offset slwi r6, r5, 2 # u * 4 (bytes per texel) lfsx f6, r3, r6 # Load texture sample # Apply texture filtering bl apply_texture_filter # Process texel value
Scientific Data Visualization
# Visualize scientific data with color mapping lis r3, data_values@ha addi r3, r3, data_values@l lis r4, color_map@ha addi r4, r4, color_map@l lwz r5, data_points(r0) # Number of data points visualize_loop: li r6, 0 # Data point index slwi r7, r6, 2 # Convert to byte offset lfsx f1, r3, r7 # Load data value # Normalize data value to color map index (0-255) lfs f2, data_min(r0) # Minimum data value lfs f3, data_max(r0) # Maximum data value fsub f4, f1, f2 # value - min fsub f5, f3, f2 # max - min fdiv f6, f4, f5 # normalized value (0.0-1.0) lfs f7, color_scale(r0) # 255.0 fmul f8, f6, f7 # * 255 fctiwz f9, f8 # Convert to integer stfd f9, temp_index(r1) lwz r8, temp_index+4(r1) # Color map index # Load color from color map slwi r9, r8, 2 # Convert to byte offset lfsx f10, r4, r9 # Load color value # Apply color to visualization bl set_pixel_color # Set visualization pixel addi r6, r6, 1 # Next data point cmpw r6, r5 # Check if done blt visualize_loop # Continue visualization
Machine Learning - Feature Vector Processing
# Process feature vectors with dynamic dimension access lis r3, feature_vectors@ha addi r3, r3, feature_vectors@l lwz r4, vector_dimension(r0) # Feature vector dimension lwz r5, num_vectors(r0) # Number of vectors li r6, 0 # Vector index ml_vector_loop: li r7, 0 # Feature index lfs f10, zero_constant(r0) # Initialize feature sum feature_loop: # Calculate feature address: base + (vector_index * dimension + feature_index) * 4 mullw r8, r6, r4 # vector_index * dimension add r9, r8, r7 # + feature_index slwi r10, r9, 2 # * 4 (bytes per float) lfsx f1, r3, r10 # Load feature value # Apply feature processing (e.g., normalization) lfs f2, feature_scale(r0) # Scaling factor fmul f3, f1, f2 # Scale feature fadd f10, f10, f3 # Add to feature sum addi r7, r7, 1 # Next feature cmpw r7, r4 # Check if done with vector blt feature_loop # Continue features # Process completed feature vector bl process_feature_vector # Process accumulated features addi r6, r6, 1 # Next vector cmpw r6, r5 # Check if done blt ml_vector_loop # Continue vectors
Image Processing - Convolution Filter
# Apply convolution filter to single-precision image data lis r3, image_data@ha addi r3, r3, image_data@l lis r4, filter_kernel@ha addi r4, r4, filter_kernel@l lwz r5, image_width(r0) # Image width lwz r6, image_height(r0) # Image height li r7, 3 # Filter size (3x3) # Process each pixel (excluding border) li r8, 1 # Start row (skip border) subi r9, r6, 1 # End row (skip border) convolution_row_loop: li r10, 1 # Start column (skip border) subi r11, r5, 1 # End column (skip border) convolution_col_loop: lfs f10, zero_constant(r0) # Initialize convolution sum # Apply 3x3 filter kernel li r12, -1 # Kernel row offset (-1, 0, 1) kernel_row_loop: li r13, -1 # Kernel column offset (-1, 0, 1) kernel_col_loop: # Calculate source pixel position add r14, r8, r12 # source_row = current_row + kernel_row_offset add r15, r10, r13 # source_col = current_col + kernel_col_offset # Calculate pixel offset mullw r16, r14, r5 # source_row * image_width add r17, r16, r15 # + source_col slwi r18, r17, 2 # Convert to byte offset lfsx f1, r3, r18 # Load pixel value # Load kernel coefficient addi r19, r12, 1 # Convert offset to index (0-2) mulli r20, r19, 3 # kernel_row_index * 3 addi r21, r13, 1 # Convert col offset to index add r22, r20, r21 # kernel_index slwi r23, r22, 2 # Convert to byte offset lfsx f2, r4, r23 # Load kernel coefficient # Multiply and accumulate fmadd f10, f1, f2, f10 # sum += pixel * kernel_coeff addi r13, r13, 1 # Next kernel column cmpwi r13, 2 # Check if done with kernel row ble kernel_col_loop # Continue kernel column addi r12, r12, 1 # Next kernel row cmpwi r12, 2 # Check if done with kernel ble kernel_row_loop # Continue kernel row # Store convolution result mullw r24, r8, r5 # current_row * image_width add r25, r24, r10 # + current_col slwi r26, r25, 2 # Convert to byte offset stfsx f10, r3, r26 # Store filtered pixel addi r10, r10, 1 # Next column cmpw r10, r11 # Check if done with row ble convolution_col_loop # Continue row addi r8, r8, 1 # Next row cmpw r8, r9 # Check if done with image ble convolution_row_loop # Continue image