spinn_common 7.3.1
Support code for SpiNNaker applications.
Loading...
Searching...
No Matches
Functions | Variables
log.c File Reference

Implementation of log for the accum type. More...

#include "stdfix-full-iso.h"
#include "assert.h"
#include "arm_acle.h"

Functions

static int32_t divide_ck (int32_t x, uint32_t k)
 This function divides x by k/64.
 
static uint32_t uint32_round (uint32_t r, uint32_t n)
 Shift away a given number of bits, with rounding.
 
static int32_t subtract_mult_log2 (int32_t r, int32_t x)
 This function performs a multiply-accumulate.
 
static int32_t cubic_term (int32_t r)
 Computes the cubic term for log_1_2()
 
static uint32_t log_1_2 (uint32_t x)
 This function calculates a range-reduced log function.
 
static int32_t logkbits (int32_t x)
 This function calculates the internal representation of the log function.
 
accum logk (accum x)
 Logarithm: log(x) for the accum type (s16.15).
 

Variables

static uint32_t log_ck []
 
static int16_t recip_table []
 Reciprocal table.
 

Detailed Description

Implementation of log for the accum type.

The details of the algorithm are from "Elementary Functions: Algorithms and Implemenation", 2nd edn, Jean-Michel Muller, Birkhauser, 2006.

Author
Dave Lester (david.nosp@m..r.l.nosp@m.ester.nosp@m.@man.nosp@m.chest.nosp@m.er.a.nosp@m.c.uk)
Date
30 September, 2014

Function Documentation

◆ divide_ck()

static int32_t divide_ck ( int32_t  x,
uint32_t  k 
)
inlinestatic

This function divides x by k/64.

Parameters
[in]xinput value
[in]kthe ‘breakpoint’ index.
Returns
x/(k/64)

◆ uint32_round()

static uint32_t uint32_round ( uint32_t  r,
uint32_t  n 
)
inlinestatic

Shift away a given number of bits, with rounding.

Parameters
[in]rThe number to be rounded.
[in]nThe number of least-significant bits to remove. Should be a constant for efficiency.
Returns
the rounded number

◆ subtract_mult_log2()

static int32_t subtract_mult_log2 ( int32_t  r,
int32_t  x 
)
inlinestatic

This function performs a multiply-accumulate.

Parameters
[in]raccumulator value
[in]xone of the factors
Returns
\( r - x * log(2) \)

◆ cubic_term()

static int32_t cubic_term ( int32_t  r)
inlinestatic

Computes the cubic term for log_1_2()

Parameters
[in]ran s0.31 representation of the x/ck
Returns
\( 44739601/2^{29} * r^3 \)

◆ log_1_2()

static uint32_t log_1_2 ( uint32_t  x)
inlinestatic

This function calculates a range-reduced log function.

Parameters
[in]xa u0.31 fraction.
Returns
A value representing log(1+x) in u5.27 (or s4.27) format.

◆ logkbits()

static int32_t logkbits ( int32_t  x)
inlinestatic

This function calculates the internal representation of the log function.

Parameters
[in]xa positive signed accum, in integer form.
Returns
A value representing log(x) (in integer form of signed accum).

◆ logk()

accum logk ( s1615  x)

Logarithm: log(x) for the accum type (s16.15).

Parameters
[in]xValue to compute the logarithm of as an accum
Returns
The logarithm of x in accum format

Variable Documentation

◆ log_ck

uint32_t log_ck[]
static
Initial value:
= {
1610612736, 1612693673, 1614742838, 1616761188,
1618749635, 1620709053, 1622640276, 1624544106,
1626421307, 1628272616, 1630098736, 1631900343,
1633678087, 1635432592, 1637164458, 1638874261,
1640562556, 1642229879, 1643876743, 1645503644,
1647111061, 1648699455, 1650269271, 1651820939,
1653354872, 1654871473, 1656371128, 1657854212,
1659321087, 1660772103, 1662207601, 1663627908,
1665033342, 1666424211, 1667800815, 1669163444,
1670512377, 1671847888, 1673170241, 1674479692,
1675776492, 1677060882, 1678333097, 1679593367,
1680841913, 1682078952, 1683304693, 1684519341,
1685723096, 1686916150, 1688098693, 1689270907,
1690432973, 1691585063, 1692727349, 1693859995,
1694983162, 1696097009, 1697201687, 1698297348,
1699384138, 1700462197, 1701531667, 1702592682,
1703645376
}

\( ck = 1 + k/64 \)

Thus \( log_ck[k] = log(1 + k/64) + 12 \) in u5.27

◆ recip_table

int16_t recip_table[]
static
Initial value:
= {
0, -1008, -1986, -2934, -3855, -4749, -5617, -6461,
-7282, -8080, -8856, -9612, -10348, -11065, -11763, -12444,
-13107, -13754, -14386, -15002, -15604, -16191, -16765, -17326,
-17873, -18409, -18933, -19445, -19946, -20436, -20916, -21385,
-21845, -22296, -22737, -23169, -23593, -24008, -24415, -24815,
-25206, -25590, -25967, -26337, -26700, -27056, -27406, -27749,
-28087, -28418, -28744, -29064, -29378, -29687, -29991, -30290,
-30583, -30872, -31156, -31436, -31711, -31982, -32248, -32510,
-32768
}

Reciprocal table.