Használati útmutató Microchip PIC32MM0064GPM028

Microchip nincs kategorizálva PIC32MM0064GPM028

Olvassa el alább 📖 a magyar nyelvű használati útmutatót Microchip PIC32MM0064GPM028 (158 oldal) a nincs kategorizálva kategóriában. Ezt az útmutatót 4 ember találta hasznosnak és 2 felhasználó értékelte átlagosan 4.5 csillagra

Oldal 1/158
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-1
Section 50. CPU for Devices with MIPS32
®
microAptiv™
and M-Class Cores
This section of the manual contains the following topics:
50.1 Introduction .............................................................................................................. 50-2
50.2 Architecture Overview ............................................................................................. 50-4
50.3 PIC32 CPU Details .................................................................................................. 50-8
50.4 Special Considerations When Writing to CP0 Registers ....................................... 50-13
50.5 MIPS32 Architecture.............................................................................................. 50-14
50.6 CPU Bus................................................................................................................ 50-15
50.7 Internal System Busses......................................................................................... 50-15
50.8 Set/Clear/Invert...................................................................................................... 50-16
50.9 ALU Status Bits...................................................................................................... 50-16
50.10 Interrupt and Exception Mechanism ...................................................................... 50-17
50.11 Programming Model .............................................................................................. 50-17
50.12 Floating Point Unit (FPU)....................................................................................... 50-24
50.13 Coprocessor 0 (CP0) Registers............................................................................. 50-42
50.14 Coprocessor 1 (CP1) Registers........................................................................... 50-121
50.15 microMIPS Execution .......................................................................................... 50-132
50.16 MCU ASE Extension ........................................................................................... 50-132
50.17 MIPS DSP ASE Extension .................................................................................. 50-133
50.18 Memory Model (MCU only).................................................................................. 50-133
50.19 Memory Management (MPU only)....................................................................... 50-135
50.20 L1 Caches (MPU only) ........................................................................................ 50-141
50.21 CPU Instructions.................................................................................................. 50-145
50.22 MIPS DSP ASE Instructions ................................................................................ 50-151
50.23 CPU Initialization ................................................................................................. 50-153
50.24 Effects of a Reset ................................................................................................ 50-154
50.25 Related Application Notes ...................................................................................50-155
50.26 Revision History................................................................................................... 50-156
PIC32 Family Reference Manual
DS60001192B-page 50-2 © 2013-2015 Microchip Technology Inc.
50.1 INTRODUCTION
Depending on the device family, PIC32 devices are a complex System-on-Chip (SoC), which are
based on the microAptiv Microprocessor core or the M-Class Microprocessor core from
Imagination Technologies Ltd. This document provides an overview of the CPU system
architecture and features of PIC32 microcontrollers that feature these microprocessor cores.
The microAptiv Microprocessor core is a superset of the MIPS
®
M14KE and M14KEc™
Microprocessor cores. These cores are state of the art, 32-bit, low-power, RISC processor cores
with the enhanced MIPS32
®
Release 2 Instruction Set Architecture (ISA).
The M-Class Microprocessor core is a superset of the microAptiv™ Microprocessor core. This
32-bit, low-power, RISC processor core uses the enhanced MIPS32
®
Release 5 Instruction Set
Architecture (ISA).
Visit the Imagination Technologies Ltd. website (www.imgtec.com) to learn more about the
microprocessor cores.
Depending on the core configuration, one of two options, MCU or MPU, are used, as shown in
Table 50-1.
Table 50-1: microAptiv and M-Class Microprocessor Core Configurations
The primary difference between the MCU and MPU is the presence of an L1 cache and
TLB-based MMU on the MPU. These features are used to facilitate PIC32 designs that use
operating systems to manage virtual memory.
Note: This family reference manual section is meant to serve as a complement to device
data sheets. Depending on the device variant, this manual section may not apply to
all PIC32 devices.
Please consult the note at the beginning of the “CPU” chapter in the current device
data sheet to check whether this document supports the device you are using.
Device data sheets and family reference manual sections are available for
download from the Microchip Worldwide Web site at: http://www.microchip.com
MCU Features MPU Features
Split-bus architecture Unified bus architecture
Integrated DSP ASE (see Note 1) Integrated DSP ASE (see Note 1)
Integrated MCU™ ASE Integrated MCU ASE
microMIPS™ code compression microMIPS code compression
FMT-based MMU TLB-based MMU
Two shadow register sets Eight shadow register sets
EJTAG TAP controller EJTAG TAP controller
Performance counters Performance counters
Hardware Trace (iFlowtrace
®
) Hardware Trace (iFlowtrace)
Level One (L1) CPU cache
Note 1: This feature is not available on all devices, refer to the CPU chapter of the spe-
cific device data sheet to determine availability.
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-3
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.1.1 Key Features Common to All PIC32 Devices with the microAptiv
Microprocessor Core
The following key features are common to all PIC32 devices that are based on the microAptiv
Microprocessor core:
microMIPS variable-length instruction mode for compact code
Vectored interrupt controller with up to 256 interrupt sources
Atomic bit manipulations on peripheral registers (Single cycle)
High-speed Microchip ICD port with hardware-based non-intrusive data monitoring and
application data streaming functions
EJTAG debug port allows extensive third party debug, programming and test tools support
Instruction controlled power management modes
Five-stage pipelined instruction execution
Internal code protection to help protect intellectual property
Arithmetic saturation and overflow handling support
Zero cycle overhead saturation and rounding operations
Atomic read-modify-write memory-to-memory instructions
MAC instructions with up to 4 accumulators
Native fractional data type (Q15, Q31) with rounding support
Digital Signal Processing (DSP) Application-Specific Extension (ASE) Revision 2, which adds
DSP capabilities with support for powerful data processing operations
Multiply/Divide unit with a maximum issue rate of one 32 x 32 multiply per clock
50.1.2 Key Features Common to All PIC32 Devices with the M-Class
Microprocessor Core
In addition to the features described for devices with the microAptiv core, the following key
features are common to all PIC32 devices that are based on the M-Class Microprocessor core:
Implements the latest MIPS Release 5 Architecture, which includes IP protection and
reliability for industrial controllers, Internet of Things (IoT), wearables, wireless
communications, automotive, and storage
Floating Point Unit (FPU)
50.1.3 Related MIPS Documentation
Related MIPS documentation is available for download from the related Imagination
Technologies Ltd. product page. Please note that a login may be required to access these
documents.
Documentation for the microAptiv core is available for download at:
http://www.imgtec.com/mips/aptiv/microaptiv.asp
Documentation for the M-Class core is available for download at:
http://www.imgtec.com/mips/warrior/mclass.asp
PIC32 Family Reference Manual
DS60001192B-page 50-4 © 2013-2015 Microchip Technology Inc.
50.2 ARCHITECTURE OVERVIEW
The PIC32 family of devices are complex systems-on-a-chip that contain many features.
Included in all processors of the PIC32 family is a high-performance RISC CPU, which can be
programmed in 32-bit and 16-bit modes, and even mixed modes.
Devices with the M-Class core include a Floating Point Unit (FPU) that implements the MIPS
Release 5 Instruction Set Architecture for floating point computation. The FPU implementation
supports the ANSI/IEEE Standard 754 (IEEE Standard for Binary Floating-Point Arithmetic) for
single- and double-precision data formats.
PIC32 devices contain a high-performance Interrupt Controller, DMA controller, USB controller,
in-circuit debugger, a high-performance switching matrix for high-speed data accesses to the
peripherals, and on-chip data RAM memory, which holds data and programs. The optional
prefetch cache and prefetch buffer for the Flash memory, which hides the latency of the Flash,
provides zero Wait state equivalent performance.
Figure 50-1: PIC32 Block Diagram
Note: Refer to the “CPU” chapter in the specific device data sheet to determine
availability of the FPU module in your device.
JTAG/BSCAN Priority Interrupt
Controller LDO VREG
DMAC ICD
PIC32 CPU
System Bus
Prefetch Cache Data RAM
Peripheral
Flash Memory
Flash Controller
Clock Control/
Generation Reset Generation
PMP/PSP
PORTS
ADC
RTCC
Timers
Input Capture
PWM/Output
Compare
Comparators
SSP/SPI
I2C™
UART
128-bit
USB
Bridge
CAN
Motor Control
PWM
DAC
CTMU
ETH
Note: This diagram is provided as a general example. Please refer to the “Device Overview
chapter in the specific device data sheet to determine availability of the features and
peripherals listed in this diagram.
PIC32 Family Reference Manual
DS60001192B-page 50-10 © 2013-2015 Microchip Technology Inc.
50.3.2 Execution Unit
The PIC32 Execution Unit is responsible for carrying out the processing of most of the instruc-
tions of the MIPS instruction set. The Execution Unit provides single-cycle throughput for most
instructions by means of pipelined execution. Pipelined execution, sometimes referred to as
“pipelining”, is where complex operations are broken into smaller pieces called stages. Operation
stages are executed over multiple clock cycles.
The Execution Unit contains the following features:
32-bit adder used for calculating the data address
Address unit for calculating the next instruction address
Logic for branch determination and branch target address calculation
Load aligner
Bypass multiplexers used to avoid stalls when executing instructions streams where data
producing instructions are followed closely by consumers of their results
Leading Zero/One detect unit for implementing the CLZ and CLO instructions
Arithmetic Logic Unit (ALU) for performing bit-wise logical operations
Shifter and Store Aligner
50.3.3 Multiply/Divide Unit (MDU)
The Multiply/Divide unit (MDU) performs multiply and divide operations. The MDU consists of a
32 x 16 multiplier, result-accumulation registers (HI and LO), multiply and divide state machines,
and all multiplexers and control logic required to perform these functions. The high-performance,
pipelined MDU supports execution of a 16 x 16 or 32 x 16 multiply operation every clock cycle;
32 × 32 multiply operations can be issued every other clock cycle. Appropriate interlocks are
implemented to stall the issue of back-to-back 32 x 32 multiply operations. Divide operations are
implemented with a simple 1 bit per clock iterative algorithm and require 35 clock cycles in the
worst case to complete. Any attempt to issue a subsequent MDU instruction while a divide is still
active causes a pipeline stall until the divide operation is completed.
The microprocessor cores implement an additional multiply instruction, MUL, which specifies that
lower 32-bits of the multiply result be placed in the register file instead of the HI/LO register pair.
By avoiding the explicit move from the LO (MFLO) instruction, which required when using the LO
register, and by supporting multiple destination registers, the throughput of multiply-intensive
operations is increased. Two instructions, multiply-add (MADD/MADDU) and multiply-subtract
( /MSUB MSUBU), are used to perform the multiply-add and multiply-subtract operations. The MADD
instruction multiplies two numbers, and then adds the product to the current contents of the HI
and LO registers. Similarly, the MSUB instruction multiplies two operands, and then subtracts the
product from the HI and LO registers. The MADD MADDU/ and MSUB MSUBU/ operations are
commonly used in Digital Signal Processor (DSP) algorithms.
The MDU is a separate pipeline for integer multiply and divide operations and DSP ASE multiply
instructions (see Note). This pipeline operates in parallel with the integer unit (IU) pipeline and
does not stall when the IU pipeline stalls. This allows the long-running MDU operations to be
partially masked by system stalls and/or other integer unit instructions. The MDU supports
execution of one 32 x 32 multiply or multiply-accumulate operation every clock cycle. The 32-bit
divide operation executes in 12-38 clock cycles. The MDU also implements various shift
instructions operating on the HI/LO register and multiply instructions as defined in the DSP ASE.
50.3.4 Shadow Register Sets
The PIC32 processor implements one or more copies of the General Purpose Registers (GPR)
for use by high-priority interrupts. The extra banks of registers are known as shadow register
sets. When a high-priority interrupt occurs, the processor automatically switches to a shadow
register set without software intervention. This reduces overhead in the interrupt handler and
reduces effective latency.
The shadow register sets are controlled by registers located in the System Coprocessor (CP0)
as well as the interrupt controller hardware located outside of the CPU core.
For more information on shadow register sets, refer to Section 8. “Interrupts (DS60001108) of
the “PIC32 Family Reference Manual”.
Note: DSP ASE is not available on all devices. Refer to the “CPU” chapter of the specific
device data sheet to determine availability
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-11
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.3.5 Pipeline Interlock Handling
Smooth pipeline flow is interrupted when an instruction in a pipeline stage cannot advance due
to a data dependency or a similar external condition. Pipeline interruptions are handled entirely
in hardware. These dependencies are referred to as “interlocks”. At each cycle, interlock
conditions are checked for all active instructions. An instruction that depends on the result of a
previous instruction is an example of an interlock condition.
In general, MIPS processors support two types of hardware interlocks:
Stalls These interlocks are resolved by halting the entire pipeline. All instructions, cur-
rently executing in each pipeline stage, are affected by a stall.
Slips – These interlocks allow one part of the pipeline to advance while another part of the
pipeline is held static
In the PIC32 processor core, all interlocks are handled as slips. These slips are minimized by
grabbing results from other pipeline stages by using a method called register bypassing, which
is described in 50.3.6 “Register Bypassing”.
As shown in Figure 50-6, the sub instruction has a source operand dependency on register r3
with the previous add instruction. The sub instruction slips by two clocks waiting until the result
of the add is written back to register r3. This slipping does not occur on the PIC32 family of
processors.
Figure 50-6: Pipeline Slip (If Bypassing Was Not Implemented)
Note: To illustrate the concept of a pipeline slip, the example in Figure 50-6 shows would
happen if the PIC32 core did not implement register bypassing.
EI M W
E
SLIP
I M A WE
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
A
E
SLIP
Add r3, r2, r1
(r r3 2 + r1
Sub r4, r3, r7
(r r4 3 r7
PIC32 Family Reference Manual
DS60001192B-page 50-12 © 2013-2015 Microchip Technology Inc.
50.3.6 Register Bypassing
As mentioned previously, the PIC32 processor implements a mechanism called register bypass-
ing that helps reduce pipeline slips during execution. When an instruction is in the E stage of the
pipeline, the operands must be available for that instruction to continue. If an instruction has a
source operand that is computed from another instruction in the execution pipeline, register
bypassing allows a shortcut to get the source operands directly from the pipeline. An instruction
in the E stage can retrieve a source operand from another instruction that is executing in either
the M stage or the A stage of the pipeline. As seen in Figure 50-7, a sequence of three instruc-
tions with interdependencies does not slip at all during execution. This example uses both A to
E, and M to E register bypassing. Figure 50-8 shows the operation of a load instruction utilizing
A to E bypassing. Since the result of load instructions are not available until the A pipeline stage,
M to E bypassing is not needed.
The performance benefit of register bypassing is that instruction throughput is increased to the
rate of one instruction per clock for ALU operations, even in the presence of register
dependencies.
Figure 50-7: IU Pipeline M to E Bypass
Figure 50-8: IU Pipeline A to E Data Bypass
EI M W
EI WA
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
A
M
Add
1
r r r3 = 2 + 1
Sub
2
r r r4 = 3 7
Add
3
r r r5 = 3 + 4 EI AM
M to E Bypass A to E Bypass
M to E Bypass
EI M W
EI WA
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
One
Cycle
A
M
Load Instruction
Consumer of Load Data Instruction
EI AM
Data Bypass from A to E
One Clock
Load Delay
PIC32 Family Reference Manual
DS60001192B-page 50-14 © 2013-2015 Microchip Technology Inc.
50.5 MIPS32 ARCHITECTURE
The MIPS32 architecture is based on a fixed-length, regularly encoded instruction set and uses
a load/store data model. The architecture is streamlined to support optimized execution of
high-level languages. Arithmetic and logic operations use a three-operand format, allowing
compilers to optimize complex expressions formulation. Availability of 32 general-purpose
registers enables compilers to further optimize code generation for performance by keeping
frequently accessed data in registers.
For more information and documentation, refer to the MIPS32 Architecture web page at:
http://www.imgtec.com/mips/architectures/mips32.asp
50.5.1 Architecture Release 2
PIC32 devices with the microAptiv core utilize Release 2 of the MIPS32 processor architecture,
and implement the following features:
Vectored interrupts using and external-to-core interrupt controller, which provides the ability
to vector interrupts directly to a handler for that interrupt
Programmable exception vector base, which allows the base address of the exception
vectors to be moved for exceptions that occur when Status
BEV
is ‘0’. This feature enables
any system to place the exception vectors in memory that is appropriate to the system
environment.
Atomic interrupt enable/disable, which includes two added instructions to atomically enable
or disable interrupts, and return the previous value of the Status register
The ability to disable the Count register for highly power-sensitive applications
GPR shadow registers, which provide the addition of GPR shadow registers and the ability
to bind these registers to a vectored interrupt or exception
Field, Rotate, and Shuffle instructions, which add additional capability in processing bit
fields in registers
Explicit hazard management, which provides a set of instructions to explicitly manage
hazards, in place of the cycle-based SSNOP method of dealing with hazards
50.5.2 Architecture Release 5
PIC32 devices with the M-Class core utilize all of the features of Release 2, as well as the
following Release 5 features:
User mode access through the UFR bit in the Config5 Register (CP0 Register 16, Select 5)
Additional MCU ASE instructions: ASET and ACLR for setting and clearing atomic 8-bit
memory locations
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-15
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.6 CPU BUS
The PIC32 devices use two different CPU bus architectures, either split-bus or data/instruction
bus, depending on which CPU core is implemented.
50.6.1 Split-bus Architecture
PIC32 devices based on the MCU Microprocessor core have a Split-bus architecture, with two
distinct busses to provide parallel instruction and data operations. Load and store operations
occur simultaneously as instruction fetches. The two busses are known as the I-side bus, which
is used for feeding instructions into the CPU, and the D-side bus, which is used for data transfers.
In the split-bus architecture, the CPU fetches instructions during the I-pipeline stage. A fetch is
issued to the I-side bus and is handled by the System Bus. Depending on the address, the
System Bus will do one of the following:
Forward the fetch request to the Prefetch Cache unit (if available)
Forward the fetch request to the DRM unit, or
Cause an exception
Instruction fetches always use the I-side bus independent of the addresses being fetched.
The D-side bus processes all load and store operations executed by the CPU. When a load or
store instruction is executed, the request is routed to the System Bus by the D-side bus. This
operation occurs during the M-pipeline stage and is routed to one of several targets:
Data RAM
Prefetch Cache/Flash memory
Fast Peripheral Bus (Interrupt controller, DMA, Debug unit, USB, Ethernet, GPIO ports)
General Peripheral Bus (UART, SPI, Flash Controller, EPMP/EPSP, TRCC Timers, Input
Capture, PWM/Output Compare, ADC, Dual Compare, I
2
C, Clock SIB, and Reset SIB)
50.6.2 Data/Instruction Architecture
PIC32 devices based on the MPU core have a unified Data or Instruction bus connected to the
System Bus. This architecture uses a multi-layer System Bus to provide multiple simultaneous
data transactions between bus initiators and targets.
50.7 INTERNAL SYSTEM BUSSES
The internal busses of the PIC32 processor connect the peripherals to the System Bus. The
System Bus routes bus accesses from different initiators to a set of targets utilizing several data
paths throughout the device to help eliminate performance bottlenecks.
Some of the paths that the System Bus uses serve a dedicated purpose, while others are shared
between several targets.
The data RAM and Flash memory read paths are dedicated paths, allowing low-latency access
to the memory resources without being delayed by peripheral bus activity. The high-bandwidth
peripherals are placed on a high-speed bus. These include the Interrupt controller, Debug unit,
DMA engine, the USB Host/Peripheral unit, and other high-bandwidth peripherals (i.e., CAN,
Ethernet engines).
Peripherals that do not require high-bandwidth are located on a separate peripheral bus to save
power.
PIC32 Family Reference Manual
DS60001192B-page 50-16 © 2013-2015 Microchip Technology Inc.
50.8 SET/CLEAR/INVERT
To provide single-cycle bit operations on peripherals, the registers in the peripheral units can be
accessed in three different ways depending on peripheral addresses. Each register has four dif-
ferent addresses. Although the four different addresses appear as different registers, they are
really just four different methods to address the same physical register.
Figure 50-9: Four Addresses for a Single Physical Register
The base register address provides normal Read/Write access, while the other three provide
special write-only functions.
Normal access
Set bit atomic RMW access
Clear bit atomic RMW access
Invert bit atomic RMW access
Peripheral reads must occur from the base address of each peripheral register. Reading from a
Set/Clear/Invert address has an undefined meaning, and may be different for each peripheral.
Writing to the base address writes an entire value to the peripheral register. All bits are written.
For example, assume a register contains 0xAAAA5555 before a write of 0x000000FF. After the
write, the register will contain 0x000000FF (assuming that all bits are R/W bits).
Writing to the Set address for any peripheral register causes only the bits written as 1’s to be set
in the destination register. For example, assume that a register contains 0xAAAA5555 before a
write of 0x000000FF to the set register address. After the write to the Set register address, the
value of the peripheral register will contain 0xAAAA55FF.
Writing to the Clear address for any peripheral register causes only the bits written as ‘1’s to be
cleared to 0’s in the destination register. For example, assume that a register contains
0xAAAA5555 before a write of 0x000000FF to the Clear register address. After the write to the
Clear register address, the value of the peripheral register will contain 0xAAAA5500.
Writing to the Invert address for any peripheral register causes only the bits written as ‘1’s to be
inverted, or toggled, in the destination register. For example, assume that a register contains
0xAAAA5555 before a write of 0x000000FF to the invert register address. After the write to the
Invert register, the value of the peripheral register will contain 0xAAAA55AA.
50.9 ALU STATUS BITS
Unlike most other PIC microcontrollers, the PIC32 processor does not use Status register flags.
Condition flags are used on many processors to help perform decision making operations during
program execution. Flags are set based on the results of comparison operations or some arith-
metic operations. Conditional branch instructions on these machines then make decisions based
on the values of the single set of condition codes.
Instead, the PIC32 processor uses instructions that perform a comparison and stores a flag or
value into a General Purpose Register. A conditional branch is then executed with this general
purpose register used as an operand.
Peripheral RegisterRegister Address
Register Address + 4
Register Address + 8
Register Address + 12
Clear Bits
Set Bits
Invert Bits
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-17
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.10 INTERRUPT AND EXCEPTION MECHANISM
The PIC32 family of processors implement an efficient and flexible interrupt and exception han-
dling mechanism. Interrupts and exceptions both behave similarly in that the current instruction
flow is changed temporarily to execute special procedures to handle an interrupt or exception.
The difference between the two is that interrupts are usually a result of normal operation, and
exceptions are a result of error conditions such as bus errors.
When an interrupt or exception occurs, the processor does the following:
1. The PC of the next instruction to execute after the handler returns is saved into a
coprocessor register.
2. The Cause register is updated to reflect the reason for exception or interrupt.
3. The Status register EXL or ERL bit is set to cause Kernel mode execution.
4. Handler PC is calculated from Ebase and OFFSET values.
5. Automated Interrupt Epilogue can save some of the COP0 state in the stack and
automatically update some of the COP0 registers in preparation for interrupt handling.
6. Processor starts execution from new PC.
This is a simplified overview of the interrupt and exception mechanism. Refer to the “CPU
Exceptions and Interrupt Controller” chapter in the specific device data sheet for details.
50.11 PROGRAMMING MODEL
The PIC32 family of processors is designed to be used with a high-level language such as the C
programming language. It supports several data types and uses simple but flexible addressing
modes needed for a high-level language. There are 32 General Purpose Registers and two
special registers for multiplying and dividing.
There are three different formats for the machine language instructions on the PIC32 processor:
Immediate or I-type CPU instructions
Jump or J-type CPU instructions, and
Registered or R-type CPU instructions
Most operations are performed in registers. The register type CPU instructions have three
operands; two source operands and a destination operand.
Having three operands and a large register set allows assembly language programmers and
compilers to use the CPU resources efficiently. This creates faster and smaller programs by
allowing intermediate results to stay in registers rather than constantly moving data to and from
memory.
The immediate format instructions have an immediate operand, a source operand and a desti-
nation operand. The jump instructions have a 26-bit relative instruction offset field that is used to
calculate the jump destination.
Note: In this section, the terms “precise” and “imprecise” are used to describe exceptions.
A precise exception is one in which the EPC (CP0, Register 14, Select 0) can be
used to identify the instruction that caused the exception. For imprecise exceptions,
the instruction that caused the exception cannot be identified. Most exceptions are
precise. Bus error exceptions may be imprecise.
PIC32 Family Reference Manual
DS60001192B-page 50-18 © 2013-2015 Microchip Technology Inc.
50.11.1 CPU Instruction Formats
A CPU instruction is a single 32-bit aligned word. The CPU instruction formats are:
Immediate (see Figure 50-10)
Jump (see Figure 50-11)
Register (see Figure 50-12)
Table 50-4 describes the fields used in these instructions.
Table 50-4: CPU Instruction Format Fields
Figure 50-10: Immediate (I-Type) CPU Instruction Format
Figure 50-11: Jump (J-Type) CPU Instruction Format
Figure 50-12: Register (R-Type) CPU Instruction Format
Field Description
opcode 6-bit primary operation code.
rd 5-bit specifier for the destination register.
rs 5-bit specifier for the source register.
rt 5-bit specifier for the target (source/destination) register or used to specify
functions within the primary opcode REGIMM.
immediate 16-bit signed immediate used for logical operands, arithmetic signed operands,
load/store address byte offsets, and PC-relative branch signed instruction
displacement.
instr_index 26-bit index shifted left two bits to supply the low-order 28 bits of the jump
target address.
sa 5-bit shift amount.
function 6-bit function field used to specify functions within the primary opcode
SPECIAL.
31 26 25 21 20 16 15 0
opcode rs rt immediate
6 5 5 16
31 26 25 21 20 16 15 11 10 6 5 0
opcode instr_index
6 26
31 26 25 21 20 16 15 11 10 6 5 0
opcode rs rt rd sa function
6 5 5 5 5 6
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-19
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.11.2 CPU Registers
The PIC32 architecture defines the following CPU registers:
Thirty-two 32-bit General Purpose Registers (GPRs)
The standard MIPS32 architecture defines one pair of HI/LO accumulator registers (AC0).
The cores in PIC32 devices include the DSP ASE (see Note), which provides three addi-
tional pairs of HI/LO accumulator registers (AC1, AC2, and AC3). These registers improve
the parallelization of independent accumulation routines. DSP instructions that target the
accumulators use two instruction bits to specify the destination accumulator.
A special purpose program counter (PC), which is affected only indirectly by certain
instructions; it is not an architecturally visible register.
50.11.2.1 CPU GENERAL PURPOSE REGISTERS
Two of the CPU General Purpose Registers have assigned functions:
r0 – This register is hard-wired to a value of 0’, and can be used as the target register for
any instruction the result of which will be discarded. r0 can also be used as a source when
a ‘0’ value is needed.
r31 – This is the destination register used by JAL, BLTZAL, BLTZALL, BGEZAL, and
BGEZALL, without being explicitly specified in the instruction word; otherwise, r31 is used
as a normal register.
The remaining registers are available for general purpose use.
50.11.2.2 REGISTER CONVENTIONS
Although most of the registers in the PIC32 architecture are designated as General Purpose
Registers, as shown in Table 50-5, there are some recommended uses of the registers for correct
software operation with high-level languages such as the Microchip MPLAB
®
XC32 C/C++
compiler.
Table 50-5: Register Conventions
Note: DSP ASE is not available on all devices. Please consult the “CPU” chapter of the
specific device data sheet to determine availability
CPU
Register
Symbolic
Register Usage
r0 zero Always 0’ (see Note 1)
r1 at Assembler Temporary
r2 - r3 v0-v1 Function Return Values
r4 - r7 a0-a3 Function Arguments
r8 - r15 t0-t7 Temporary – Caller does not need to preserve contents
r16 - r23 s0-s7 Saved Temporary – Caller must preserve contents
r24 - r25 t8-t9 Temporary – Caller does not need to preserve contents
r26 - r27 k0-k1 Kernel temporaryUsed for interrupt and exception handling
r28 gp Global Pointer – Used for fast-access common data
r29 sp Stack Pointer – Software stack
r30 s8 or fp Saved Temporary – Caller must preserve contents OR
Frame Pointer – Pointer to procedure frame on stack
r31 ra Return Address (see Note 1)
Note 1: Hardware enforced, not just convention.
PIC32 Family Reference Manual
DS60001192B-page 50-20 © 2013-2015 Microchip Technology Inc.
50.11.2.3 CPU SPECIAL PURPOSE REGISTERS
The CPU contains these special purpose registers:
PC – Program Counter register
AC0 through AC3 – 64-bit Accumulator register pairs (HI/LO):
- HI/LO – Multiply and divide register pair (high and low result):
During a multiply operation, the HI and LO registers store the product of integer multiply
During a multiply-add or multiply-subtract operation, the HI and LO registers store the
result of the integer multiply-add or multiply-subtract
During a division, the HI and LO registers store the quotient (in LO) and remainder (in
HI) of integer divide
During a multiply-accumulate, the HI and LO registers store the accumulated result of
the operation
Figure 50-13 shows the layout of the CPU registers.
Figure 50-13: CPU Registers
31 0 31 0
r0 (zero) HI (0)
r1 (at) LO (0)
r2 (v0) HI (1)
r3 (v1) LO (1)
r4 (a0) HI (2)
r5 (a1) LO (2)
r6 (a2) HI (3)
r7 (a3) LO (3)
r8 (t0)
r9 (t1)
r10 (t2)
r11 (t3)
r12 (t4)
r13 (t5)
r14 (t6)
r15 (t7)
r16 (s0)
r17 (s1)
r18 (s2)
r19 (s3)
r20 (s4)
r21 (s5)
r22 (s6)
r23 (s7)
r24 (t8)
r25 (t9)
r26 (k0)
r27 (k1)
r28 (gp)
r29 (sp)
r30 (s8 or fp) 31 0
r31 (ra) PC
General Purpose Registers Special Purpose Registers
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-21
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
Table 50-6: microMIPS 16-bit Instruction Register Usage
Table 50-7: microMIPS Special Registers
16-bit
Register
Encoding
32-bit MIPS
Register
Encoding
Symbolic
Name Description
0 16/0 s0/zero General-purpose register
1 17 s1 General-purpose register
2 2 v0 General-purpose register
3 3 v1 General-purpose register
4 4 a0 General-purpose register
5 5 a1 General-purpose register
6 6 a2 General-purpose register
7 7 a3 General-purpose register
N/A 28 gp microMIPS implicitly referenced
General-pointer register
N/A 29 sp microMIPS implicitly referenced Stack
pointer register
N/A 31 ra microMIPS implicitly referenced Return
address register
Symbolic
Name Purpose
PC Program counter. The PC-relative instructions can access this register as an
operand.
HI Contains high-order word of multiply or divide result.
LO Contains low-order word of multiply or divide result.
PIC32 Family Reference Manual
DS60001192B-page 50-22 © 2013-2015 Microchip Technology Inc.
50.11.3 How to Implement Stack/MIPS Calling Conventions
The PIC32 CPU does not have hardware stacks. Instead, the processor relies on software to pro-
vide this functionality. Since the hardware does not perform stack operations itself, a convention
must exist for all software within a system to use the same mechanism. For example, a stack can
grow either toward lower addresses, or grow toward higher addresses. If one piece of software
assumes that the stack grows toward a lower address, and calls a routine that assumes that the
stack grows toward a higher address, the stack would become corrupted.
Using a system-wide calling convention prevents this problem from occurring. The Microchip
MPLAB
®
XC32 C/C++ Compiler assumes the stack grows toward lower addresses.
50.11.4 Processor Modes
There are two operational modes and one special mode of execution in the PIC32 family CPUs:
User mode, Kernel mode and Debug mode. The processor starts execution in Kernel mode, and
if desired, can stay in Kernel mode for normal operation. User mode is an optional mode that
allows a system designer to partition code between privileged and unprivileged software. Debug
mode is normally only used by a debugger or monitor.
One of the main differences between the modes of operation is the memory addresses that soft-
ware is allowed to access. Peripherals are not accessible in User mode. Figure 50-14 shows the
different memory maps for each mode. For more information on the processors memory map,
refer to Section 3. “Memory Organization” (DS60001115) of the “PIC32 Family Reference
Manual.
Figure 50-14: CPU Modes
useg kuseg kuseg
kseg0
kseg1
kseg2
kseg3
kseg2
kseg1
kseg0
kseg3
kseg3
dseg
User Mode Kernel Mode Debug ModeVirtual Address
0x7FFF_FFFF
0x8000_0000
0x9FFF_FFFF
0xBFFF_FFFF
0xDFFF_FFFF
0xFF1F_FFFF
0xFF3F_FFFF
0xFFFF_FFFF
0xA000_0000
0xC000_0000
0xE000_0000
0xFF20_0000
0xFF40_0000
0x0000_0000
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-23
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.11.4.1 KERNEL MODE
To access many of the hardware resources, the processor must be operating in Kernel mode.
Kernel mode gives software access to the entire address space of the processor as well as
access to privileged instructions.
The processor operates in Kernel mode when the DM bit in the Debug register is 0and the Status
register contains one, or more, of the following values:
UM = 0
ERL = 1
EXL = 1
When a non-debug exception is detected, EXL or ERL will be set and the processor will enter
Kernel mode. At the end of the exception handler routine, an Exception Return (ERET) instruction
is generally executed. The ERET instruction jumps to the Exception PC (EPC or ErrorPC
depending on the exception), clears ERL, and clears EXL if ERL= 0.
If UM = 1 the processor will return to User mode after returning from the exception when ERL
and EXL are cleared back to 0’.
50.11.4.2 USER MODE
When executing in User mode, software is restricted to use a subset of the processor’s
resources. In many cases it is desirable to keep application-level code running in User mode
where if an error occurs it can be contained and not be allowed to affect the Kernel mode code.
Applications can access Kernel mode functions through controlled interfaces such as the
SYSCALL mechanism.
As seen in Figure 50-14, User mode software has access to the USEG memory area.
To operate in User mode, the Status register must contain each the following bit values:
UM = 1
EXL = 0
ERL = 0
50.11.4.3 DEBUG MODE
Debug mode is a special mode of the processor normally only used by debuggers and system
monitors. Debug mode is entered through a debug exception and has access to all Kernel mode
resources as well as special hardware resources used to debug applications.
The processor is in Debug mode when the DM bit in the Debug register is ‘1’.
Debug mode is normally exited by executing a DERET instruction from the debug handler.
PIC32 Family Reference Manual
DS60001192B-page 50-24 © 2013-2015 Microchip Technology Inc.
50.12 FLOATING POINT UNIT (FPU)
PIC32 devices with the M-Class core contain a Floating Point Unit (FPU) that implements the
MIPS Release 5 Instruction Set Architecture for floating point computation.
50.12.1 Features
Some of the most important features of this module include:
The PIC32 implementation supports the “IEEE Standard for Binary Floating-Point
Arithmetic” (ANSI/IEEE 754 Standard) for single and double precision data formats. See
50.12.6.5 “IEEE 754-1985 Standard” for more information.
Full 64-bit operation is implemented in both the register file and functional units. The FPU
has 32 64-bit floating point registers used for all of the floating point operations.
A 32-bit Floating Point Control Register controls the operation of the FPU, and monitors
condition codes and exception conditions
The performance of the unit is optimized for single precision formats. Most instructions have
one FPU cycle throughput and four FPU cycle latency.
The FPU implements compound multiply-add (MADD) and multiply-sub (MSUB) instructions
with intermediate rounding after the multiply function. The result is guaranteed to be the
same as executing a MUL followed by an ADD SUB/ instruction, but the instruction latency,
instruction fetch, dispatch bandwidth, and the total number of register accesses is improved.
IEEE denormalized input operands and results are supported by hardware for some
instructions. A fast flush-to-zero mode is provided to optimize performance for IEEE
denormalized results. The fast flush-to-zero mode has to be enabled through the FPU
control registers, and use of this mode is recommended for best performance when
denormalized results are generated.
Additional arithmetic operations not specified by IEEE 754 Standard (for example, reciprocal
and reciprocal square root) are specified by the MIPS
®
architecture (see Note) and are
implemented by the FPU. To achieve low latency counts, these instructions satisfy more
relaxed precision requirements.
The MIPS FPU architecture is designed such that a combination of hardware and software
can be used to implement the architecture. The PIC32 FPU can operate on numbers within
a specific range (the IEEE normalized numbers), but it relies on a software handler to
operate on numbers not handled by the FPU hardware (the IEEE denormalized numbers).
The FPU has a separate pipeline for floating point instruction execution. This pipeline
operates in parallel with the integer core pipeline and does not stall when the integer
pipeline stalls. This allows long-running FPU operations, such as divide or square root, to
be partially masked by system stalls and/or other integer unit instructions.
The FPU access is provided through Coprocessor 1. Like the main processor core,
Coprocessor 1 is programmed and operated using a Load/Store instruction set. The
processor core communicates with Coprocessor 1 using a dedicated coprocessor interface.
The FPU functions as an autonomous unit. The hardware is completely interlocked such
that, when writing software, the programmer does not have to worry about inserting delay
slots after loads and between dependent instructions.
Arithmetic instructions are always dispatched and completed in order, but loads and stores
can complete out of order. The exception model is ‘precise’ at all times.
Refer to 50.14 “Coprocessor 1 (CP1) Registers” for information on the related FPU registers.
Figure 50-15 shows a block diagram of the PIC32 FPU.
Note: This module is not available on all devices. Refer to the “CPU” chapter in the
specific device data sheet to determine availability.
Note: Refer to the Imagination Technologies Ltd. website, www.imgtec.com, for
information on the MIPS architecture.
PIC32 Family Reference Manual
DS60001192B-page 50-26 © 2013-2015 Microchip Technology Inc.
Table 50-8: Parameters of Floating Point Data Types
Figure 50-16: Single-Precision Floating Point Format (S)
Figure 50-17: Double-Precision Floating Point Format (D)
The fields in the Figure 50-16 and Figure 50-16 are:
1-bit sign, S
Biased exponent, e = E + bias
Binary fraction, f =.b1 b2..bp-1 (the b0 bit is hidden; it is not recorded)
Values are encoded in the specified format using the unbiased exponent, fraction, and sign
values listed in Table 50-9.
The high-order bit of the Fraction field, identified as b1, has also special importance for NaNs.
Parameter Single Double
Bits of mantissa precision, p 24 53
Maximum exponent, E_max +127 +1023
Minimum exponent, E_min -126 -1022
Exponent bias +127 +1023
Bits in exponent field, e 8 11
Representation of b0 integer
bit
Hidden Hidden
Bits in fraction field, f 23 52
Total format width in bits 32 64
Magnitude of largest repre-
sentable number
3.4028234664e+38 1.7976931349e+308
Magnitude of smallest normal-
ized representable number
1.1754943508e-38 2.2250738585e-308
S Exponent <0:7> Fraction <0:22>
S Exponent <0:10> Fraction <0:51>
PIC32 Family Reference Manual
DS60001192B-page 50-28 © 2013-2015 Microchip Technology Inc.
50.12.2.2 INFINITY ARITHMETIC
Infinity represents a number with magnitude too large to be represented in the given format.
During a computation it represents a magnitude overflow. A correctly signed +
or -
will be
generated as the default result in division by zero operations and some cases of overflow as
described in 50.12.5 Floating Point Exceptions Overview”.
When created as a default result, can become an operand in a subsequent operation. The
ordering is such that -
< (every finite number) < +
. Arithmetic with
is the limiting case of
real arithmetic with operands of arbitrarily large magnitude, when such limits exist. In these
cases, arithmetic on
is regarded as exact, and exception conditions do not arise. The
out-of-range indication represented by
is propagated through subsequent computations.
For some cases, there is no meaningful limiting case in real arithmetic for operands of
. These
cases raise the Invalid Operation exception condition as described in 50.12.3 “General Floating
Point Registers”.
50.12.2.2.1 Signaling Non-Number (SNaN)
SNaN operands cause an Invalid Operation exception for arithmetic operations. SNaNs are
useful values to put in uninitialized variables. A SNaN is never produced as a result value.
The MIPS architecture makes the formatted operand move instructions (MOV.fmt MOVT.fmt, ,
MOVF.fmt MOVN.fmt MOVZ.fmt, , ) non-arithmetic; they do not signal IEEE 754 Standard
exceptions.
50.12.2.2.2Quiet Non-Number (QNaN)
QNaNs provide diagnostic information propagated from invalid or unavailable data and results.
This propagation requires that the information contained in a QNaN be preserved through
arithmetic operations and floating point format conversions.
Arithmetic operations with QNaN operands do not signal an exception. When a floating point
result is to be delivered, a QNaN operand causes an arithmetic operation to supply a QNaN
result. When possible, this QNaN result is one of the operand QNaN values.
QNaNs have similar effects to SNaNs on operations that do not deliver a floating point result (i.e.,
comparison operations).
When certain invalid operations not involving QNaN operands are performed and the trap is not
enabled, a new QNaN value is created. Table 50-10 shows the QNaN value generated when no
input operand QNaN value can be copied. The values listed for the fixed point formats are the
values supplied to satisfy the IEEE 754 Standard when a QNaN or infinite floating point value is
converted to fixed point. There is no other feature of the architecture that detects or utilizes these
“integer QNaN” values.
Table 50-10: Value Supplied When a New QNaN is Created
50.12.2.3 FIXED POINT FORMATS
The PIC32 FPU provides two fixed point data types which are the signed integers that are
provided by the MIPS architecture:
32-bit Word Fixed Point Format (type W)
64-bit Long Word Fixed Point Format (type L)
The fixed point values are held in 2’s complement format, which is used for signed integers in the
CPU. Unsigned fixed point data types are not provided by the architecture; application software
can synthesize computations for unsigned integers from the existing instructions and data types.
Format New QNan Value
(FCSR
NAN
2008 = 0)
New QNaN Value
(FCSR
NAN
2008 = 1)
Single floating point 0x7FBF FFFF 0x7FFF FFFF
Double floating point 0x7FF7 FFFF FFFF FFFF 0x7FFF FFFF FFFF FFFF
Word fixed point 0x7FFF FFFF 0x7FFF FFFF
Long word fixed point 0x7FFF FFFF FFFF FFFF 0x7FFF FFFF FFFF FFFF
PIC32 Family Reference Manual
DS60001192B-page 50-30 © 2013-2015 Microchip Technology Inc.
50.12.3.3 32-BIT AND 64-BIT BINARY DATA TRANSFER
The data transfer instructions move words and double words between the FPU FPRs and the
system.
The operations of the word and double word load and move-to instructions are shown in
Figure 50-20 and Figure 50-21, respectively.
The store and move-from instructions do the reverse, reading data from the location that the
corresponding load or move-to instruction had written.
Figure 50-20: FPU Word Load and Move-to Operations
Figure 50-21: FPU Double Word Load and Move-to Operations
FR bit = FR bit = 1 0
63 0 63 0
Reg 0 Initial Value 1 Reg 0 Initial Value 1
Reg 1 Initial Value 2 Reg 2 Initial Value 2
LWC1 f0, 0(r0) / MTC1 f0, r0
63 0 63 0
Reg 0 Undefined/Unused Data Word (0) Reg 0 Undefined/Unused Data Word (0)
Reg 1 Initial Value 2 Reg 2 Initial Value 2
LWC1 f1, 4(r0) / MTC1 f1, r4
63 0 63 0
Reg 0 Undefined/Unused Data Word (0) Reg 0 Data Word (4) Data Word (0)
Reg 1 Undefined/Unused Data Word (4) Reg 2 Initial Value 2
FR bit = 1FR bit = 0
63 0 63 0
Reg 0 Initial Value 1 Reg 0 Initial Value 1
Reg 1 Initial Value 2 Reg 2 Initial Value 2
LDC1 f0, 0(r0)
63 0 63 0
Reg 0 Data Double Word (0) Reg 0 Data Double Word (0)
Reg 1 Initial Value 2 Reg 2 Initial Value 2
LDC1 f1, 8(r0)
63 0
Reg 0 Data Double Word (0) (Illegal when FR bit = 0)
Reg 1 Data Double Word (9)
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-31
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.12.4 Floating Point Instruction Overview
The FPU instructions are divided into these categories:
FPU Data Transfer Instructions
FPU Arithmetic Instructions
FPU Conversion Instructions
FPU Formatted Operand-Value Move Instructions
FPU Conditional Branch Instructions
FPU Miscellaneous Instructions
The instructions are described in detail in Chapter 14, M5150 Processor Core Instructions
of the “MIPS32
®
M5150 Processor Core Family Software User’s Manual”. This document is
available for download by registered users from the Imagination Technologies Ltd. website
(www.imgtec.com).
50.12.4.1 FPU DATA TRANSFER INSTRUCTIONS
The FPU has two register sets: Coprocessor General Registers (FPRs) and Coprocessor Control
Registers (FCRs). The FPU has a load/store architecture: all computations are done on data held
in coprocessor general registers.
The control registers are used to control FPU operation. Data is transferred between registers
and the rest of the system with dedicated load, store, and move instructions. The transferred data
is treated as unformatted binary data. No format conversions are performed, and therefore no
IEEE floating point exceptions can occur.
Table 50-11: FPU Data Transfer Instructions
All coprocessor loads and stores operate on naturally aligned data items. An attempt to load or
store to an address that is not naturally aligned for the data item causes an Address Error
exception. The address of a word or double word is the smallest byte address in the object. For
the PIC32 architecture this is the least-significant byte.
50.12.4.2 FPU DATA TRANSFER INSTRUCTIONS ADDRESSING
The FPU has loads and stores using the same register + offset addressing as that used by the
CPU. Moreover, for the FPU only, there are load and store instructions using register + register
addressing.
Table Table 50-12 Table 50-13 and list the FPU data transfer instructions.
Table 50-12: FPU Load and Store Instructions
Transfer Direction Transferred Data
FPU general register <-> Memory Word/double word load/store
FPU general register <-> CPU general register Word move
FPU control register <-> CPU general register Word move
Mnemonic Instruction Addressing Mode
LDC1 Load Double word to Floating Point Register + offset
LWC1 Load Word to Floating Point Register + offset
SDC1 Store Double word from Floating Point Register + offset
SWC1 Store Word from Floating Point Register + offset
LDXC1 Load Double word Indexed to Floating Point Register + Register
LUXC1 Load Double word Indexed Unaligned to Floating Point Register + Register
LWXC1 Load Word Indexed to Floating Point Register + Register
SDXC1 Store Double word Indexed from Floating Point Register + Register
SUXC1 Store Double word Indexed Unaligned from Floating Point Register + Register
SWXC1 Store Word Indexed from Floating Point Register + Register
PIC32 Family Reference Manual
DS60001192B-page 50-32 © 2013-2015 Microchip Technology Inc.
Table 50-13: FPU Move To and From Instructions
50.12.4.3 FPU ARITHMETIC INSTRUCTIONS
Arithmetic instructions operate on formatted data values. The results of most floating point
arithmetic operations meet the IEEE 754 Standard for accuracy. A result is identical to an
infinite-precision result that has been rounded to the specified format using the current rounding
mode. The rounded result differs from the exact result by less than one Unit in the
Least-significant Place (ULP).
In general, the arithmetic instructions take an Unimplemented Operation exception for
denormalized numbers, except for the ABS, C, and NEG instructions, which can handle
denormalized numbers. The FS, FO, and FN bits in the CP1 FCSR register can override this
behavior as described in 50.14.6 “Floating Point Operation of the FS/FO/FN Bits.
Table 50-14 lists the FPU IEEE compliant arithmetic operations.
Table 50-14: FPU IEEE Arithmetic Instructions
Four compound-operation instructions perform variations of multiply-accumulate operations:
multiply two operands, accumulate the result to a third operand, and produce a result. The
product is rounded according to the current rounding mode prior to the accumulation. This model
meets the IEEE accuracy specification; the result is numerically identical to an equivalent
computation using multiply, add, subtract, or negate instructions.
The compound-operation instructions are listed in Table 50-15.
Table 50-15: FPU Multiply-Accumulate Arithmetic Instructions
Mnemonic Instruction
CFC1 Move Control Word From Floating Point
CTC1 Move Control Word To Floating Point
MFC1 Move Word From Floating Point
MFHC1 Move Word From High Half of Floating Point
MTC1 Move Word To Floating Point
MTHC1 Move Word to High Half of Floating Point
Mnemonic Instruction
ABS.fmt Floating Point Absolute Value
ADD.fmt Floating Point Add
C.cond.fmt Floating Point Compare
DIV.fmt Floating Point Divide
MUL.fmt Floating Point Multiply
NEG.fmt Floating Point Negate
SQRT.fmt Floating Point Square Root
SUB.fmt Floating Point Subtract
RECIP.fmt Floating Point Reciprocal Approximation. See Note 1.
RSQRT.fmt Floating Point Reciprocal Square Root Approximation.
See Note 2.
Note 1: This low latency operation might be less accurate than the IEEE specification. The
result of the RECIP differs from the exact reciprocal by no more than one Unit in
the Least-significant Place (ULP).
2: This low latency operation might be less accurate than the IEEE specification. The
result of the RSQRT differs from the exact reciprocal square root by no more than
two ULPs.
Mnemonic Instruction
MADD.fmt Floating Point Multiply Add
MSUB.fmt Floating Point Multiply Subtract
NMADD.fmt Floating Point Negative Multiply Add
NMSUB.fmt Floating Point Negative Multiply Subtract
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-35
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.12.4.7 FPU MISCELLANEOUS INSTRUCTIONS
The MIPS32 architecture defines various miscellaneous instructions that conditionally move one
CPU general register to another, based on an FPU condition code.
Table 50-20: CPU Conditional Move on FPU True/False Instructions
50.12.5 Floating Point Exceptions Overview
There are five exception conditions defined by the IEEE 754 Standard:
Invalid Operation Exception
Division By Zero Exception
Underflow Exception
Overflow Exception
Inexact Exception
There is also a MIPS-specific exception condition, the Unimplemented Operation Exception, that
is used to signal a need for software emulation of an instruction.
Normally an IEEE arithmetic operation can cause only one exception condition. The only case in
which two exceptions can occur simultaneously are Inexact With Overflow and Inexact With
Underflow.
At the program’s control an IEEE exception condition can either cause a trap or not cause a trap.
The IEEE 754 Standard specifies the result to be delivered if no trap is taken. The FPU will supply
these results whenever the exception condition does not result in a trap. The default action taken
depends on the type of exception condition, and in the case of the Overflow and Underflow, the
current rounding mode.
Table 50-21 summarizes the default results supplied by the FPU.
FPU exceptions are implemented in the PIC32 FPU architecture with the Cause, Enables, and
Flags fields of the FCSR. The flag bits implement IEEE exception status flags and the cause and
enable bits control exception trapping.
Each field has a bit for each of the five IEEE exception conditions. The Cause field has an
additional exception bit, Unimplemented Operation, that could be used to trap for software
emulation assistance. If an exception type is enabled through the Enables field of the FCSR, the
FPU is operating in precise exception mode for this type of exception.
50.12.5.1 FLOATING POINT PRECISE EXCEPTION MODE
In precise exception mode, a trap occurs before the instruction that causes the trap or any
following instruction can complete and write its results. So the software trap handler can resume
execution of the interrupted instruction stream after handling the exception, if desired.
The Cause field reports per-bit instruction exception conditions. The cause bits are written during
each floating point arithmetic operation to show any exception conditions that arise during the
operation. A cause bit is set to ‘1’ if its corresponding exception condition arises; otherwise, it is
cleared to ‘0’.
A floating point trap is generated any time both a cause bit and its corresponding enable bit are
set. This case occurs either during the execution of a floating point operation or when moving a
value into the FCSR. There is no enable bit for Unimplemented Operations: this exception always
generates a trap.
In a trap handler, exception conditions that arise during any trapped floating point operations are
reported in the Cause field. Before returning from a floating point interrupt or exception, or before
setting cause bits with a move to the FCSR, software first must clear the enabled cause bits by
executing a move to the FCSR to prevent the trap from being erroneously retaken.
Mnemonic Instruction
MOVN Move Conditional on FP False
MOVZ Move Conditional on FP True
PIC32 Family Reference Manual
DS60001192B-page 50-36 © 2013-2015 Microchip Technology Inc.
If a floating point operation sets only non-enabled cause bits, no trap occurs and the default result
defined by the IEEE 754 Standard is stored (see Table 50-21). When a floating point operation
does not trap, the program can monitor the exception conditions by reading the Cause field.
The Flags field is a cumulative report of IEEE exception conditions that arise as instructions
complete; instructions that trap do not update the flag bits. The flag bits are set to ‘1’ if the
corresponding IEEE exception is raised, otherwise the bits are unchanged. There is no flag bit
for the Unimplemented Operation exception. The flag bits are never cleared as a side effect of
floating point operations, but they can be set or cleared by the software by moving a new value
into the FCSR.
Table 50-21: FPU Supplied Results for Not Trapped Exceptions
50.12.5.2 FLOATING POINT INVALID OPERATION EXCEPTION
An Invalid Operation exception is signaled when one or both of the operands are invalid for the
operation to be performed. When the exception condition occurs without a precise trap, the result
is a quiet NaN.
The following operations are invalid:
One or both operands are a signaling NaN (except for the non-arithmetic MOV.fmt,
MOVT.fmt, MOVF.fmt, MOVN.fmt, and MOVZ.fmt instructions).
Addition or subtraction: magnitude subtraction of infinities, such as (+
) + (−
) or (−
) −
(−
).
Multiplication: 0 ×
, with any signs.
Division: 0/0 or
/
, with any signs.
Square root: An operand of less than 0 (-0 is a valid operand value).
Conversion of a floating point number to a fixed point format when either an overflow or an
operand value of infinity or NaN precludes a faithful representation in that format.
Some comparison operations in which one or both of the operands is a QNaN value.
Bit
Name Description Default Action
V Invalid Operation Supplies a quiet NaN.
Z Divide by Zero Supplies a properly signed infinity.
U Underflow Depends on the rounding mode as shown below:
(RN): Supplies a zero with the sign of the exact result.
(RZ): Supplies a zero with the sign of the exact result.
(RP):
For positive underflow values, supplies 2
E_min
(MinNorm).
For negative underflow values, supplies a positive zero.
(RM):
For positive underflow values, supplies a negative zero.
For negative underflow values, supplies a negative 2
E_min
(MinNorm).
Note: this behavior is only valid if the FCSR FN bit is cleared.
I Inexact Supplies a rounded result. If caused by an overflow without the overflow trap enabled,
supplies the overflowed result. If caused by an underflow without the underflow trap
enabled, supplies the underflowed result.
O Overflow Depends on the rounding mode, as follows:
(RN): Supplies a infinity with the sign of the exact result.
(RZ): Supplies the format’s largest finite number with the sign of the exact result.
(RP): For positive overflow values, supplies positive infinity. For negative overflow
values, supplies the format’s most negative finite number.
(RM): For positive overflow values, supplies the formats largest finite number. For
negative overflow values, supplies minus infinity.
PIC32 Family Reference Manual
DS60001192B-page 50-38 © 2013-2015 Microchip Technology Inc.
50.12.6 Floating Point Pipeline and Performance
This section describes the structure and operation of the FPU pipeline.
50.12.6.1 FPU PIPELINE OVERVIEW
The FPU has a seven stage pipeline to which the integer pipeline dispatches instructions:
Decode, register read and unpack (FR stage)
Multiply tree - double pumped for double (M1 stage)
Multiply complete (M2 stage)
Addition first step (A1 stage)
Addition second and final step (A2 stage)
Packing to IEEE format (FP stage)
Register writeback (FW stage)
The FPU implements a bypass mechanism that allows the result of an operation to be forwarded
directly to the instruction that needs it without having to write the result to the FPU register and
then read it back.
The FPU pipeline runs in parallel with the PIC32 core integer pipeline. The FPU is built to run at
the same frequency as the PIC32 core.
The FPU pipeline is optimized for single-precision instructions, such that the basic multiply,
ADD/SUB, and MADD/MSUB instructions can be performed with single-cycle throughput and
low latency. Executing double-precision multiply and MADD/MSUB instructions requires a
second pass through the M1 stage to generate all 64 bits of the product.
Executing long latency instructions, such as DIV and RSQRT, extends the M1 stage.
Figure 50-22 shows the FPU pipeline.
Figure 50-22: PIC32 FPU Pipeline
Stage 1: FPU Pipeline: FR Stage – Decode, Register Read, and Unpack
The FR stage has the following functionality:
The dispatched instruction is decoded for register accesses.
Data is read from the register file.
The operands are unpacked into an internal format.
Stage 2: FPU Pipeline: M1 Stage – Multiply Tree
The M1 stage has the following functionality:
A single-cycle multiply array is provided for single-precision data format multiplication, and
two cycles are provided for double-precision data format multiplication
The long instructions, such as divide and square root, iterate for several cycles in this stage.
Sum of exponents is calculated.
RF AG
FR M1 M2 A1 A2 FP FW
FR M1 M1 M2 A1 A3 FP
FR M1 M1 M2 A1 A2 FP FW
Multiple Cycles
Second
Pass
EX MS ER WB
Dispatch
Processor Integer Pipeline
FPU Instruction in general
FPU Double Multiplication (i.e., MUL MADD, )
FPU Long Instructions (i.e., DIV, RSQRT)
FW
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-39
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
Stage 3: FPU Pipeline: M2 Stage – Multiply Complete
The M2 stage has the following functionality:
Multiplication is complete when the carry-save encoded product is compressed into binary
Rounding is performed
Exponent difference for addition path is calculated
Stage 4: FPU Pipeline: A1 StageAddition First Step
This stage performs the first step of the addition.
Stage 5: FPU Pipeline: A2 Stage - Addition Second and Final Step
This stage performs the second and final step of the addition.
Stage 6: FPU Pipeline: FP Stage – Result Pack
The FP stage has the following functionality:
The result coming from the data path is packed into the IEEE 754 Standard format for the
FPR register file
Overflow and underflow exceptional conditions are resolved
Stage 7: FPU Pipeline: FW Stage – Register Write
The result is written to the FPR register file.
50.12.6.2 FPU BYPASSING
The FPU pipeline implements extensive bypassing so that the results do not need to be written
into the register file and read back before they can be used, but can be forwarded directly to an
instruction already in the pipe.
Some bypassing is disabled when operating in 32-bit register file mode (the FR bit in the CP0
Status<26> register is ‘0’), due to the paired even-odd 32-bit registers that provide 64-bit
registers.
Figure 50-23: PIC32 FPU Pipeline Bypass Paths
FR M1 M2 A1 A2 FP FW
A2 Bypass
FP Bypass
FW Bypass
PIC32 Family Reference Manual
DS60001192B-page 50-40 © 2013-2015 Microchip Technology Inc.
50.12.6.3 FPU REPEAT RATE AND LATENCY
Table 50-22 shows the repeat rate and latency for the FPU instructions.
Note that cycles related to floating point operations are listed in terms of FPU clocks.
Table 50-22: FPU Latency and Repeat Rate
Op code
(see Note 1)
Latency
(FPU
Cycles)
Repeat Rate
(FPU Cycles)
ABS.[S,D], NEG.[S,D], ADD.[S,D], SUB.[S,D],
MUL.S,
MADD.S, MSUB.S, NMADD.S, MSUB.S
4 1
MUL.D, MADD.D, MSUB.D, NMADD.D, NMSUB.D 5 2
RECIP.S 13 10
RECIP.D 25 21
RSQRT.S 17 14
RSQRT.D 35 31
DIV.S SQRT.S, 17 14
DIV.D SQRT.D, 32 29
C.cond.[S,D] MOVF.fmt MOVT.fmt to and instruction/
MOVT, MOVN, BC1 instruction
One-half 1
CVT.D.S CVT.[S,D].[W,L], 4 1
CVT.S.D 6 1
CVT.[W,L].[S,D],
CEIL.[W,L].[S,D], FLOOR.[W,L].[S,D],
ROUND.[W,L].[S,D],
TRUNC.[W,L].[S,D]
5 1
MOV.[S,D], MOVF.[S,D], MOVN.[S,D], MOVT.[S,D],
MOVZ.[S,D]
4 1
LWC1, LDC1, LDXC1, LUXC1, LWXC1 3 1
MTC1, MFC1 2 1
Legend: S = Single; D = Double; W = Word; L = Long Word
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-41
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
50.12.6.4 FLOATING POINT 2008 FPU SUPPORT
The PIC32 FPU implements the following status/control bits to provide greater compatibility with
the IEEE 754 Standard Floating Point released in 2008:
The Has2008 bit (FIR<23>) will always read as ‘1’ to signify that 2008 FPU is implemented.
The MAC2008 bit (FCSR<20>) will always read as ‘0’ to signify that Fused Multiply Add
operation is not implemented.
The ABS2008 bit (FCSR<19>) is always set to ‘1’ which makes ABS and NEG instructions
non-arithmetic instructions. All floating point exceptions will be disabled.
The NAN2008 bit (FCSR<18>) is always set to ‘1’ to show Quiet and signaling NaN
encodings recommended by the IEEE 754-2008 Standard. In addition, the following
behaviors are implemented:
- In the case of one or more QNaN operands (no SNaN), the QNaN operand is propagated
from one of the input register operands (in order of priority): (see the following fs, ft, and fr
Note).
- When SNaN is used as an input, and exceptions are disabled, QNaN is the expected
output
- The QNaN output will not be a fixed value. To comply with IEEE, an input NaN should
produce a NaN with the payload of the input NaN if representable in the destination
format, where the payload is defined as the Mantissa field less its most-significant bit.
- If ABS2008 = 1 and MAC2008 = 0 (as it always is in PIC32), the sign of NMADD and
NMSUB do not flip the sign of any QNaN input, and the sign is retained and propagated
to the output.
- When a NaN is an input, the output will be one of the input NaNs with as much of the
mantissa preserved as possible.
- SNaN inputs have higher priority than QNaN inputs and then has higher priority than fs ft
which has higher priority than fr register (see the following Note).
- The sign of the selected NaN input is preserved. If the input that is selected for the output
is already a QNaN, the entire mantissa is preserved. However, if the input that is selected
for the output is a SNaN, the most significant bit of the SNaN mantissa is complemented
to convert the SNaN into a QNaN. If this conversion to a QNaN would result in an infinity,
the next most significant bit of the mantissa is set.
- For CVT.s.d, the NaN mantissa most significant bits are preserved. For CVT.d.s, the
NaN mantissa is padded with ‘0’s in the least significant bits.
- For multiply-add, if both fs ft/ and fr registers are QNaNs, the multiply produces a QNaN
based upon fs ft/ , and this QNaN has priority over fr in the add operation. However, if both
fs fr/ft and registers are SNaNs and the invalid trap is not enabled, the multiply generates
a QNaN based upon fs/ft, which is then added to the signaling fr register and the signaling
fr has priority
- When a NaN is needed for output but there is no NaN input, a positive QNaN is created
that has all other mantissa bits set.
50.12.6.5 IEEE 754-1985 STANDARD
The IEEE 754-1985 Standard, “IEEE Standard for Binary Floating-Point Arithmetic” defines the
following:
Floating Point data types
The basic arithmetic, comparison, and conversion operations
A computational model
The IEEE 754-1985 Standard does not define specific processing resources nor does it define
an instruction set. For additional information about the IEEE 754-1985 standard, visit the IEEE
Web page at http://stdsbbs.ieee.org/.
Note: Registers fs, ft, and fr are floating point registers that occur in the multiply-add
floating point operations. For example: MADD.D fd, fr, fs, ft.
PIC32 Family Reference Manual
DS60001192B-page 50-42 © 2013-2015 Microchip Technology Inc.
50.13 COPROCESSOR 0 (CP0) REGISTERS
The PIC32 uses a special register interface to communicate status and control information
between system software and the CPU. This interface is called Coprocessor 0, or CP0. The
features of the CPU that are visible through Coprocessor 0 are:
Translation Lookaside Buffer (TLB)
Core timer
Interrupt and exception control
Virtual memory configuration
Shadow register set control
Processor identification
Debugger control
Performance counters
System software accesses the registers in CP0 using coprocessor instructions such as MFC0
and MTC0. Table 50-23 describes the CP0 registers found on PIC32 devices.
Table 50-23: CP0 Registers
Register
Number Register Name Function
0 Index Index into the TLB array (MPU only).
1 Random Randomly generated index into the TLB array (MPU only).
2 EntryLo0 Low-order portion of the TLB entry for even-numbered virtual pages (MPU only).
3 EntryLo1 Low-order portion of the TLB entry for odd-numbered virtual pages (MPU only).
4 Context/
UserLocal
Pointer to the page table entry in memory (MPU only).
User information that can be written by privileged software and read via the RDHWR
instruction.
5 PageMask/
PageGrain
PageMask controls the variable page sizes in TLB entries. PageGrain enables support
of 1 KB pages in the TLB (MPU only).
6 Wired Controls the number of fixed (i.e., wired) TLB entries (MPU only).
7 HWREna Enables access via the RDHWR instruction to selected hardware registers in
Non-privileged mode.
8 BadVAddr Reports the address for the most recent address-related exception.
BadInstr Reports the instruction that caused the most recent exception.
BadInstrP Reports the branch instruction if a delay slot caused the most recent exception.
9 Count Processor cycle count.
10 EntryHi High-order portion of the TLB entry (MPU only).
11 Compare Core timer interrupt control.
12 Status Processor status and control.
IntCtl Interrupt control of vector spacing.
SRSCtl Shadow register set control.
SRSMap Shadow register mapping control.
View_IPL Allows the Priority Level to be read/written without
extracting or inserting that bit from/to the Status register.
SRSMAP2 Contains two 4-bit fields that provide the mapping from a vector number to the shadow
set number to use when servicing such an interrupt.
13 Cause Describes the cause of the last exception.
NestedExc Contains the error and exception level status bit values that existed prior to the current
exception.
View_RIPL Enables read access to the RIPL bit that is available in the Cause register.
14 EPC Program counter at last exception.
NestedEPC Contains the exception program counter that existed prior to the current exception.
© 2013-2015 Microchip Technology Inc. DS60001192B-page 50-43
Section 50. CPU for Devices with MIPS32
®
microAptiv™ and M-Class Cores
15 PRID Processor identification and revision
Ebase Exception base address of exception vectors.
CDMMBase Common device memory map base.
16 Config Configuration register.
Config1 Configuration register 1.
Config2 Configuration register 2.
Config3 Configuration register 3.
Config4 Configuration register 4.
Config5 Configuration register 5.
Config7 Configuration register 7.
17 LLAddr Load link address (MPU only).
18 WatchLo Low-order watchpoint address (MPU only).
19 WatchHi High-order watchpoint address (MPU only).
20-22 Reserved Reserved in the PIC32 core.
23 Debug EJTAG debug register.
TraceControl EJTAG trace control.
TraceControl2 EJTAG trace control 2.
UserTraceData1 EJTAG user trace data 1 register.
TraceBPC EJTAG trace breakpoint register.
Debug2 Debug control/exception status 1.
24 DEPC Program counter at last debug exception.
UserTraceData2 EJTAG user trace data 2 register.
25 PerfCtl0 Performance counter 0 control.
PerfCnt0 Performance counter 0.
PerfCtl1 Performance counter 1 control.
PerfCnt1 Performance counter 1.
26 ErrCtl Software test enable of way-select and data RAM arrays for I-Cache and D-Cache
(MPU only).
27 CacheErr Records information about Cache/SPRAM parity errors.
28 TagLo/DataLo Low-order portion of cache tag interface (MPU only).
29 Reserved Reserved in the PIC32 core.
30 ErrorEPC Program counter at last error.
31 DeSAVE Debug handler scratchpad register.
KScratch1 Scratch register for Kernel mode.
KScratch2 Scratch register for Kernel mode.
Table 50-23: CP0 Registers (Continued)
Register
Number Register Name Function
PIC32 Family Reference Manual
DS60001192B-page 50-44 © 2013-2015 Microchip Technology Inc.
50.13.1 Index Register (CP0 Register 0, Select 0)
(MPU only)
The Index register is a 32-bit read/write register that contains the index used to access the TLB
for TLBP, TLBR, and TLBWI instructions.
Register 50-1: Index; TLB Index Register; CP0 Register 0, Select 0
Bit
Range
Bit
31/23/15/7
Bit
30/22/14/6
Bit
29/21/13/5
Bit
28/20/12/4
Bit
27/19/11/3
Bit
26/18/10/2
Bit
25/17/9/1
Bit
24/16/8/0
31:24
R-x U-0 U-0 U-0 U-0 U-0 U-0 U-0
P — — —
23:16
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— — —
15:8
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— — —
7:0
U-0 U-0 U-0 R/W-x R/W-x R/W-x R/W-x R/W-x
— — Index<4:0>
(1)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 31 P: Probe Failure Detect bit
1 = The previous TLBP instruction failed to find a match in the TLB
0 = The previous TLBP instruction found a match in the TLB
bit 30-5 Unimplemented: Read as ‘0
bit 4-0 Index<4:0>: Index to TLB Entry Affected by the TLBR and TLBW Instructions bits
(1)
11111 = TLB Entry 31
00000 = TLB Entry 0
Note 1: Depending on the configuration of the MMU, not all bits may be used. The number of TLB entries
supported by the MMU can be read from the MMU Size<5:0> field of the Config1 CP0 register.

Termékspecifikációk

Márka: Microchip
Kategória: nincs kategorizálva
Modell: PIC32MM0064GPM028

Szüksége van segítségre?

Ha segítségre van szüksége Microchip PIC32MM0064GPM028, tegyen fel kérdést alább, és más felhasználók válaszolnak Önnek




Útmutatók nincs kategorizálva Microchip

Útmutatók nincs kategorizálva

Legújabb útmutatók nincs kategorizálva

MOZA

MOZA SR-P Útmutató

10 Április 2025
CaterChef

CaterChef 445001 Útmutató

9 Április 2025
IFM

IFM E40581 Útmutató

9 Április 2025
Livn

Livn Bolt Útmutató

9 Április 2025
Livn

Livn Beats Útmutató

9 Április 2025
IFM

IFM O3R252 Útmutató

9 Április 2025