MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
fractio — binary64 fields

Data Structures

struct  FractioCfg
 Pins the two scale bounds to the values binary64 gives. More...
union  FractioCfg::[union].__unnamed0__
struct  FractioNs
 Type of the fract dispatch table. More...

Macros

#define MMGR_DBL_SIGN_MASK
 The binary64 field layout: three masks, the sign shift, the two field widths, the two whole field values and the exponent bias.
#define MMGR_DBL_EXP_MASK
#define MMGR_DBL_MANT_MASK
#define MMGR_DBL_SIGN_SHIFT
#define MMGR_DBL_MANT_BITS
#define MMGR_DBL_EXP_BITS
#define MMGR_DBL_SIGN_ONE
#define MMGR_DBL_EXP_ALL
#define MMGR_DBL_BIAS
#define MMGR_DBL_BITS
 The width of a double in bits, bytes and embed_word units.
#define MMGR_DBL_BYTES
#define MMGR_DBL_WORDS
#define MMGR_DBL_SCALE_MAX
 Pins the target's double to the width and storage this file assumes.
#define MMGR_DBL_SCALE_MIN

Functions

EMBED_HOST_DEVICE embed_u64 mmgr_fract_sign (const FractioCfg *args)
 Returns the sign bit of args->bits.
EMBED_HOST_DEVICE embed_u64 mmgr_fract_exp (const FractioCfg *args)
 Returns the exponent field of args->bits.
EMBED_HOST_DEVICE embed_u64 mmgr_fract_mant (const FractioCfg *args)
 Returns the mantissa field of args->bits.
EMBED_HOST_DEVICE embed_u64 mmgr_fract_merge (const FractioCfg *args)
 Packs args->sign, args->exp and args->mant into one bit pattern.
EMBED_HOST_DEVICE double mmgr_fract_from_bits (const FractioCfg *args)
 Reads the union as a double.
EMBED_HOST_DEVICE embed_u64 mmgr_fract_to_bits (const FractioCfg *args)
 Reads the union as a bit pattern.

Variables

static const FractioNs fract
 Dispatch table instance named fract, whose members are the mmgr_fract_ entries.

Detailed Description

Macro Definition Documentation

◆ MMGR_DBL_SIGN_MASK

#define MMGR_DBL_SIGN_MASK

The binary64 field layout: three masks, the sign shift, the two field widths, the two whole field values and the exponent bias.

Note
The masks, the shift and the widths give each field's position and extent. MMGR_DBL_SIGN_ONE and MMGR_DBL_EXP_ALL are values a field can hold and not positions, and MMGR_DBL_BIAS is an amount.
The assertions below check the masks tile the word without gap or overlap.
The masks, MMGR_DBL_SIGN_ONE and MMGR_DBL_EXP_ALL carry a ull suffix, as the embed_u64 that holds the fields. The shifts and widths carry u. MMGR_DBL_BIAS carries neither, since the signed scale arithmetic below subtracts it. The sign bit.

Definition at line 44 of file fractio.h.

◆ MMGR_DBL_EXP_MASK

#define MMGR_DBL_EXP_MASK

The eleven exponent bits.

Definition at line 45 of file fractio.h.

◆ MMGR_DBL_MANT_MASK

#define MMGR_DBL_MANT_MASK

The fifty-two stored mantissa bits.

Definition at line 46 of file fractio.h.

◆ MMGR_DBL_SIGN_SHIFT

#define MMGR_DBL_SIGN_SHIFT

Bit position of the sign.

Definition at line 47 of file fractio.h.

◆ MMGR_DBL_MANT_BITS

#define MMGR_DBL_MANT_BITS

Stored mantissa width, and the exponent's shift.

Definition at line 48 of file fractio.h.

◆ MMGR_DBL_EXP_BITS

#define MMGR_DBL_EXP_BITS

Exponent width.

Definition at line 49 of file fractio.h.

◆ MMGR_DBL_SIGN_ONE

#define MMGR_DBL_SIGN_ONE

A sign of one, and merge's mask for args->sign.

Definition at line 50 of file fractio.h.

◆ MMGR_DBL_EXP_ALL

#define MMGR_DBL_EXP_ALL

All ones in the exponent, and merge's mask for args->exp.

Definition at line 51 of file fractio.h.

◆ MMGR_DBL_BIAS

#define MMGR_DBL_BIAS

Amount added to the true exponent when stored.

Definition at line 52 of file fractio.h.

◆ MMGR_DBL_BITS

#define MMGR_DBL_BITS

The width of a double in bits, bytes and embed_word units.

Note
MMGR_DBL_BITS is a statement and not a measurement. The assertion below compares it against sizeof(double) and fails the build when the target disagrees.
The 8u in MMGR_DBL_BYTES is bits per byte. That same assertion holds a target to it, since a byte of another width would leave sizeof(double) * 8u short of MMGR_DBL_BITS.
MMGR_DBL_WORDS rounds up, and the assertion below requires it to come out exact. Bits in a double.

Definition at line 63 of file fractio.h.

◆ MMGR_DBL_BYTES

#define MMGR_DBL_BYTES

Bytes in a double.

Definition at line 64 of file fractio.h.

◆ MMGR_DBL_WORDS

#define MMGR_DBL_WORDS

embed_word units per double. \

Definition at line 65 of file fractio.h.

◆ MMGR_DBL_SCALE_MAX

#define MMGR_DBL_SCALE_MAX

Pins the target's double to the width and storage this file assumes.

Note
Checks the bit width, that a double is a whole number of embed_word units, and that embed_u64 holds it.

Pins the field constants above against each other.

Note
Checks the widths sum to 64, the masks tile the word, and no two masks overlap.
Also checks each mask against the shift or width for the same field, that MMGR_DBL_EXP_ALL fills MMGR_DBL_EXP_BITS, and that MMGR_DBL_BIAS is half the exponent range less one.

The range of powers of two a double can carry once the mantissa counts as an integer.

Note
MMGR_DBL_SCALE_MAX takes the largest finite exponent, removes the bias, and drops the mantissa width.
MMGR_DBL_SCALE_MIN starts from an exponent field of 1, the smallest normal.
Explicit casts hold both expressions in embed_iword, since neither MMGR_DBL_EXP_ALL nor MMGR_DBL_MANT_BITS has a sign. MMGR_DBL_SCALE_MIN is negative, and without its cast the subtraction would wrap.

Definition at line 110 of file fractio.h.

◆ MMGR_DBL_SCALE_MIN

#define MMGR_DBL_SCALE_MIN

Definition at line 111 of file fractio.h.

Function Documentation

◆ mmgr_fract_sign()

EMBED_HOST_DEVICE embed_u64 mmgr_fract_sign ( const FractioCfg * args)

Returns the sign bit of args->bits.

Parameters
[in]argsBit pattern in the union [BORROWS].
Returns
0 for a positive sign, 1 for a negative one.
Note
The bit reads as stored, and nothing else counts. A negative zero answers 1, and so does a NaN with the sign.

References mmgr_fract_sign().

Referenced by mmgr_fract_sign().

◆ mmgr_fract_exp()

EMBED_HOST_DEVICE embed_u64 mmgr_fract_exp ( const FractioCfg * args)

Returns the exponent field of args->bits.

Parameters
[in]argsBit pattern in the union [BORROWS].
Returns
The stored exponent, with MMGR_DBL_BIAS still in it.
Note
0 marks a zero or subnormal. MMGR_DBL_EXP_ALL marks an infinity or NaN.

References mmgr_fract_exp().

Referenced by mmgr_fract_exp().

◆ mmgr_fract_mant()

EMBED_HOST_DEVICE embed_u64 mmgr_fract_mant ( const FractioCfg * args)

Returns the mantissa field of args->bits.

Parameters
[in]argsBit pattern in the union [BORROWS].
Returns
The fifty-two stored bits, without the implicit leading one.
Note
The leading one is implicit only where the exponent field is nonzero. A zero or a subnormal has none, and there these fifty-two bits are the whole mantissa.

References mmgr_fract_mant().

Referenced by mmgr_fract_mant().

◆ mmgr_fract_merge()

EMBED_HOST_DEVICE embed_u64 mmgr_fract_merge ( const FractioCfg * args)

Packs args->sign, args->exp and args->mant into one bit pattern.

Parameters
[in]argsThe three fields [BORROWS].
Returns
The assembled pattern.
Note
Each field has a mask of its own width. A wide input cannot reach the next field.
Warning
What the mask drops stays gone and nothing reports it. A sign above MMGR_DBL_SIGN_ONE, an exponent above MMGR_DBL_EXP_ALL or a mantissa above MMGR_DBL_MANT_MASK retains only its low bits.

References mmgr_fract_merge().

Referenced by mmgr_fract_merge().

◆ mmgr_fract_from_bits()

EMBED_HOST_DEVICE double mmgr_fract_from_bits ( const FractioCfg * args)

Reads the union as a double.

Parameters
[in]argsUnion with its bits member filled [BORROWS].
Returns
The same storage interpreted as a double.

References mmgr_fract_from_bits().

Referenced by mmgr_fract_from_bits().

◆ mmgr_fract_to_bits()

EMBED_HOST_DEVICE embed_u64 mmgr_fract_to_bits ( const FractioCfg * args)

Reads the union as a bit pattern.

Parameters
[in]argsUnion with its val member filled [BORROWS].
Returns
The same storage interpreted as embed_u64.

References mmgr_fract_to_bits().

Referenced by mmgr_fract_to_bits().

Variable Documentation

◆ fract

const FractioNs fract
static

Dispatch table instance named fract, whose members are the mmgr_fract_ entries.

Note
EMBED_TABLE_STORAGE is static const, and so every translation unit that includes this header holds a copy of its own and the addresses differ between them. The six functions it points at are the one shared definition.
EMBED_UNUSED retains a translation unit that includes the header and never calls through the table from a warning about it. It expands to nothing where the unused attribute is unavailable.

Definition at line 218 of file fractio.h.