Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM Divide and Square Root Accelerator (DIVAS) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Divide and Square Root Accelerator functionality.

The following peripherals are used by this module:

The following devices can use this module:

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

This driver provides an interface for the Divide and Square Root Accelerator on the device.

The DIVAS is a programmable 32-bit signed or unsigned hardware divider and a 32-bit unsigned square root hardware engine. When running signed division, both the input and the result will be in two's complement format. The result of signed division is that the remainder has the same sign as the dividend and the quotient is negative if the dividend and divisor have opposite signs. When the square root input register is programmed, the square root function starts and the result will be stored in the Remainder register.

There are two ways to calculate the results:

Overload Operation

The operation is implemented automatically by EABI (Enhanced Application Binary Interface). EABI is a standard calling convention, which is defined by ARM. The four functions interface can implement division and mod operation in EABI.

The following prototypes for EABI division operation in ICCARM tool chain:

int __aeabi_idiv(int numerator, int denominator);
unsigned __aeabi_uidiv(unsigned numerator, unsigned denominator);
__value_in_regs idiv_return __aeabi_idivmod( int numerator, int denominator);
__value_in_regs uidiv_return __aeabi_uidivmod( unsigned numerator,
unsigned denominator);

The following prototypes for EABI division operation in GNUC tool chain:

int __aeabi_idiv(int numerator, int denominator);
unsigned __aeabi_uidiv(unsigned numerator, unsigned denominator);
uint64_t __aeabi_idivmod( int numerator, int denominator);
uint64_t uidiv_return __aeabi_uidivmod( unsigned numerator,
unsigned denominator);

No matter what kind of tool chain, by using DIVAS module in the four functions body, the user can transparently access the DIVAS module when writing normal C code. For example:

void division(int32_t b, int32_t c)
{
int32_t a;
a = b / c;
return a;
}

Similarly, the user can use the "a = b % c;" symbol to implement the operation with DIVAS, and needn't to care about the internal operation process.

Operand Size

Signed Division

When the signed flag is one, both the input and the result will be in two's complement format. The result of signed division is that the remainder has the same sign as the dividend and the quotient is negative if the dividend and divisor have opposite signs.

Note
When the maximum negative number is divided by the minimum negative number, the resulting quotient overflows the signed integer range and will return the maximum negative number with no indication of the overflow. This occurs for 0x80000000 / 0xFFFFFFFF in 32-bit operation and 0x8000 / 0xFFFF in 16-bit operation.

Divide By Zero

A divide by zero will cause a fault if the DIVISOR is programmed to zero. The result is that the quotient is zero and the reminder is equal to the dividend.

Unsigned Square Root

When the square root input register is programmed, the square root function starts and the result will be stored in the Result and Remainder registers.

Note
The square root function can't overload.

Special Considerations

There are no special considerations for this module.

Extra Information

For extra information, see Extra Information for DIVAS Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for DIVAS Driver.

API Overview

Modules

 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the SAM Divide and Square Root Accelerator (DIVAS) Driver.
 

Data Structures

struct  idiv_return
 DIVAS signed division operator result output structure. More...
 
struct  uidiv_return
 DIVAS unsigned division operator result output structure. More...
 

Functions

static void divas_disable_dlz (void)
 Disables DIVAS leading zero optimization. More...
 
static void divas_enable_dlz (void)
 Enables DIVAS leading zero optimization. More...
 

Call the DIVAS API Operation

In this mode, the way that directly call the DIVAS API implement division or mod operation.

int32_t divas_idiv (int32_t numerator, int32_t denominator)
 Signed division operation. More...
 
uint32_t divas_uidiv (uint32_t numerator, uint32_t denominator)
 Unsigned division operation. More...
 
int32_t divas_idivmod (int32_t numerator, int32_t denominator)
 Signed division remainder operation. More...
 
uint32_t divas_uidivmod (uint32_t numerator, uint32_t denominator)
 Unsigned division remainder operation. More...
 
uint32_t divas_sqrt (uint32_t radicand)
 Square root operation. More...
 

DIVAS Overload '/' and '' Operation

In this mode, the user can transparently access the DIVAS module when writing normal C code.

E.g. "a = b / c;" or "a = b % c;" will be translated to a subroutine call, which uses the DIVAS.

int32_t __aeabi_idiv (int32_t numerator, int32_t denominator)
 Signed division operation overload. More...
 
uint32_t __aeabi_uidiv (uint32_t numerator, uint32_t denominator)
 Unsigned division operation overload. More...
 
uint64_t __aeabi_idivmod (int32_t numerator, int32_t denominator)
 Signed division remainder operation overload. More...
 
uint64_t __aeabi_uidivmod (uint32_t numerator, uint32_t denominator)
 Unsigned division remainder operation overload. More...
 

int32_t __aeabi_idiv ( int32_t  numerator,
int32_t  denominator 
)

Signed division operation overload.

Run the signed division operation and return the results.

Parameters
[in]numeratorThe dividend of the signed division operation
[in]denominatorThe divisor of the signed division operation
Returns
The quotient of the DIVAS signed division operation.

References divas_idiv().

uint64_t __aeabi_idivmod ( int32_t  numerator,
int32_t  denominator 
)

Signed division remainder operation overload.

Run the signed division operation and return the remainder.

Parameters
[in]numeratorThe dividend of the signed division operation
[in]denominatorThe divisor of the signed division operation
Returns
The remainder of the DIVAS signed division operation.

References cpu_irq_enter_critical(), and cpu_irq_leave_critical().

uint32_t __aeabi_uidiv ( uint32_t  numerator,
uint32_t  denominator 
)

Unsigned division operation overload.

Run the unsigned division operation and return the results.

Parameters
[in]numeratorThe dividend of the unsigned division operation
[in]denominatorThe divisor of the unsigned division operation
Returns
The quotient of the DIVAS unsigned division operation.

References divas_uidiv().

uint64_t __aeabi_uidivmod ( uint32_t  numerator,
uint32_t  denominator 
)

Unsigned division remainder operation overload.

Run the unsigned division operation and return the remainder.

Parameters
[in]numeratorThe dividend of the unsigned division operation
[in]denominatorThe divisor of the unsigned division operation
Returns
The remainder of the DIVAS unsigned division operation.

References cpu_irq_enter_critical(), and cpu_irq_leave_critical().

static void divas_disable_dlz ( void  )
inlinestatic

Disables DIVAS leading zero optimization.

Disable leading zero optimization from the Divide and Square Root Accelerator module. When leading zero optimization is disable, 16-bit division completes in 8 cycles and 32-bit division completes in 16 cycles.

static void divas_enable_dlz ( void  )
inlinestatic

Enables DIVAS leading zero optimization.

Enable leading zero optimization from the Divide and Square Root Accelerator module. When leading zero optimization is enable, 16-bit division completes in 2-8 cycles and 32-bit division completes in 2-16 cycles.

int32_t divas_idiv ( int32_t  numerator,
int32_t  denominator 
)

Signed division operation.

Run the signed division operation and return the quotient.

Parameters
[in]numeratorThe dividend of the signed division operation
[in]denominatorThe divisor of the signed division operation
Returns
The quotient of the DIVAS signed division operation.

References cpu_irq_enter_critical(), and cpu_irq_leave_critical().

Referenced by __aeabi_idiv(), and signed_division().

int32_t divas_idivmod ( int32_t  numerator,
int32_t  denominator 
)

Signed division remainder operation.

Run the signed division operation and return the remainder.

Parameters
[in]numeratorThe dividend of the signed division operation
[in]denominatorThe divisor of the signed division operation
Returns
The remainder of the DIVAS signed division operation.

References cpu_irq_enter_critical(), and cpu_irq_leave_critical().

Referenced by signed_division_mod().

uint32_t divas_sqrt ( uint32_t  radicand)

Square root operation.

Run the square root operation and return the results.

Parameters
[in]radicandThe radicand of the square root operation
Returns
The result of the DIVAS square root operation.

References cpu_irq_enter_critical(), and cpu_irq_leave_critical().

Referenced by squart_root().

uint32_t divas_uidiv ( uint32_t  numerator,
uint32_t  denominator 
)

Unsigned division operation.

Run the unsigned division operation and return the results.

Parameters
[in]numeratorThe dividend of the unsigned division operation
[in]denominatorThe divisor of the unsigned division operation
Returns
The quotient of the DIVAS unsigned division operation.

References cpu_irq_enter_critical(), and cpu_irq_leave_critical().

Referenced by __aeabi_uidiv(), and unsigned_division().

uint32_t divas_uidivmod ( uint32_t  numerator,
uint32_t  denominator 
)

Unsigned division remainder operation.

Run the unsigned division operation and return the remainder.

Parameters
[in]numeratorThe dividend of the unsigned division operation
[in]denominatorThe divisor of the unsigned division operation
Returns
The remainder of the DIVAS unsigned division operation.

References cpu_irq_enter_critical(), and cpu_irq_leave_critical().

Referenced by unsigned_division_mod().