Post

7. Advanced ARM Features

7. Advanced ARM Features

NEON SIMD (Single Instruction, Multiple Data) – Vector Operations

NEON is an advanced SIMD (Single Instruction, Multiple Data) extension for ARM processors that provides hardware-accelerated vector processing. SIMD allows a single instruction to perform the same operation on multiple data elements simultaneously, leading to significant performance improvements for data-parallel tasks like multimedia processing, signal processing, and scientific computing.

Key Features of NEON

  • Wide Register Set: NEON uses a set of 32 registers (V0-V31), each capable of holding 128-bit data. These registers can be used for both integer and floating-point operations.
  • Parallelism: NEON performs operations on vectors of data (e.g., multiple integers or floats) in parallel, allowing for high throughput and efficiency.
  • Efficient Data Handling: NEON can process data in parallel, improving throughput in applications like video encoding, audio processing, and cryptography.

NEON Data Types

NEON supports various data types and operations. The supported data types include:

  • 8-bit, 16-bit, 32-bit, and 64-bit integers (signed and unsigned)
  • Single-precision floating-point numbers (32-bit)

Common NEON Operations

NEON provides a rich set of vector operations, including:

  • Addition/Subtraction: VADD, VSUB
  • Multiplication: VMUL
  • Dot product: VDOT
  • Shifting and packing: VSHL, VZIP

Example: NEON Vector Addition

The following is an example of adding two vectors using NEON instructions:

1
2
3
VLD1.32 {D0-D1}, [R0]     // Load vector A (128 bits) into D0-D1
VLD1.32 {D2-D3}, [R1]     // Load vector B (128 bits) into D2-D3
VADD.F32 D4, D0, D2       // Add vectors A and B (element-wise) and store in D4

In this example:

  • VLD1.32 loads the 128-bit vectors into the registers.
  • VADD.F32 adds the corresponding elements of the two vectors (e.g., A[0] + B[0], A[1] + B[1], etc.).
  • D0-D1, D2-D3 are 64-bit parts of the 128-bit NEON registers (since each NEON register holds 128 bits, which can store multiple elements).

Privileged Instructions (SVC, CPS)

ARM architecture provides privileged instructions for controlling the system’s operation, such as system calls, changing processor modes, and controlling interrupt behavior. These instructions allow software to perform high-level tasks like managing security contexts, switching between privilege levels, and handling system services.

SVC (Supervisor Call)

  • Purpose: The SVC instruction triggers a software interrupt to switch the processor to supervisor mode. This allows the application to request a service from the operating system or invoke system-level functionality.
  • Usage: Typically used in operating systems or bare-metal applications to interact with the kernel or execute system-level operations.
Example of SVC Usage
1
SVC #0              // Trigger a supervisor call with an immediate value of 0

When SVC is called, the processor saves the current state and jumps to a predefined address (usually an interrupt handler or a specific system service handler).

CPS (Change Processor State)

  • Purpose: The CPS instruction is used to modify the processor’s state, such as enabling or disabling interrupts and changing the current processor mode.
  • Usage: Often used to manipulate the interrupt flags and set the IRQ (Interrupt Request) or FIQ (Fast Interrupt Request) modes.
Common CPS Instructions
  • CPSID: Disable interrupts (CPSID stands for “Change Processor State and Disable interrupts”).
  • CPSIE: Enable interrupts (CPSIE stands for “Change Processor State and Enable interrupts”).
  • CPS can also change between user mode and privileged modes (e.g., SVC, IRQ, FIQ).

Example of CPS Instruction

1
CPSID I            // Disable interrupts (I = IRQ mask)

This instruction disables interrupts in the ARM processor, ensuring no IRQs are handled until re-enabled.

Exception Handling (SWI, IRQ, FIQ)

ARM processors have an efficient mechanism for handling exceptions (such as interrupts, system calls, and software exceptions). The exception handling system in ARM includes a variety of exception types that are invoked under different conditions. These exceptions can trigger interrupt handlers, software interrupt handlers, or system services.

Types of Exceptions

  • SWI (Software Interrupt): A software exception triggered by the SWI instruction. It is used for system calls in a system, allowing user-mode programs to request services from the operating system.
  • IRQ (Interrupt Request): A standard interrupt request triggered by hardware devices. It is used to handle general interrupts in the system (e.g., a timer interrupt).
  • FIQ (Fast Interrupt Request): A high-priority interrupt that can preempt IRQs. It is used for time-sensitive operations that require faster response times.

SWI (Software Interrupt)

  • Purpose: The SWI instruction triggers a software interrupt, typically used to invoke kernel or system-level services.
  • Usage: Often used in operating systems to transition from user mode to supervisor mode.
Example of SWI Usage
1
SWI #1                // Trigger software interrupt with service number 1

In this case, the operating system will handle the SWI and execute a specific system call associated with service number 1.

IRQ (Interrupt Request)

  • Purpose: The IRQ is used to handle regular interrupts, which can be caused by external devices such as timers or peripherals.
  • Usage: In embedded systems, IRQ is triggered by events like GPIO changes, timers, or UART activity.
  • Interrupt Handling: When an IRQ occurs, the processor saves its state and jumps to the interrupt service routine (ISR) to handle the interrupt.

Example of IRQ Handling

1
2
3
4
5
IRQ_Handler:
    ; Handle IRQ interrupt here
    ; Typically used for timer or peripheral interrupts
    MOV R0, #1          ; Some example processing
    SUBS PC, LR, #4     ; Return from interrupt

FIQ (Fast Interrupt Request)

  • Purpose: The FIQ is a high-priority interrupt used for more time-critical operations, ensuring they are processed faster than regular IRQs.
  • Usage: FIQs are often used for real-time processing tasks, such as handling high-frequency data from sensors or processing fast communication channels.

Example of FIQ Handling

1
2
3
4
FIQ_Handler:
    ; Handle FIQ interrupt here
    MOV R0, #2          ; Example high-priority processing
    SUBS PC, LR, #4     ; Return from interrupt

ARM Exception Handling Flow

  • When an exception occurs (whether from SWI, IRQ, or FIQ), the processor saves the current state (Program Counter, CPSR, etc.) and switches to the appropriate mode (Supervisor, IRQ, FIQ).
  • The address of the exception vector (a predefined location in memory for handling exceptions) is used to jump to the appropriate exception handler.

ARM Modes During Exceptions:

  • User Mode: The normal mode of operation for non-privileged code.
  • Supervisor Mode (SVC): A privileged mode for handling exceptions like SWI or system calls.
  • IRQ Mode: A privileged mode for handling interrupts (IRQ).
  • FIQ Mode: A high-priority mode for handling fast interrupts (FIQ).
This post is licensed under CC BY 4.0 by the author.