Module conv

Module conv 

Source
Expand description

Scaled fixed-point conversion helpers used by the generated bitfields.

Every generated numeric field exposes the physical value as an f32 (the Rust equivalent of the C float the definitions use), while the bitfield stores a raw N-bit integer. These const functions apply the divisor / multiplier from the JSON formatter spec and, for signed fields, sign-extend the stored bits.

They are referenced by the #[bits(N, from = .., into = ..)] attributes that generate_all_messages! emits, e.g. #[bits(12, from = conv::div_from_u16::<12, 10>, into = conv::div_into_u16::<12, 10>)].

  • B is the field width in bits (used for masking / sign-extension only).
  • ARG is the formatter argument (the divisor or multiplier).

Functions§

div_from_u8
unsigned, divide: physical = raw / ARG
div_from_u16
unsigned, divide: physical = raw / ARG
div_from_u32
unsigned, divide: physical = raw / ARG
div_from_u64
unsigned, divide: physical = raw / ARG
div_into_u8
The clamped result is always within the #[bits(B)] range, so bitfield_struct’s bounds check never fires. This is why a custom try is needed
div_into_u16
The clamped result is always within the #[bits(B)] range, so bitfield_struct’s bounds check never fires. This is why a custom try is needed
div_into_u32
The clamped result is always within the #[bits(B)] range, so bitfield_struct’s bounds check never fires. This is why a custom try is needed
div_into_u64
The clamped result is always within the #[bits(B)] range, so bitfield_struct’s bounds check never fires. This is why a custom try is needed
mul_from_u8
unsigned, multiply: physical = raw * ARG
mul_from_u16
unsigned, multiply: physical = raw * ARG
mul_from_u32
unsigned, multiply: physical = raw * ARG
mul_from_u64
unsigned, multiply: physical = raw * ARG
mul_into_u8
Saturates the raw count to [0, 2^B - 1] (see $div_into).
mul_into_u16
Saturates the raw count to [0, 2^B - 1] (see $div_into).
mul_into_u32
Saturates the raw count to [0, 2^B - 1] (see $div_into).
mul_into_u64
Saturates the raw count to [0, 2^B - 1] (see $div_into).
sdiv_from_u8
signed, divide: sign-extended over B bits on read.
sdiv_from_u16
signed, divide: sign-extended over B bits on read.
sdiv_from_u32
signed, divide: sign-extended over B bits on read.
sdiv_from_u64
signed, divide: sign-extended over B bits on read.
sdiv_into_u8
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field.
sdiv_into_u16
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field.
sdiv_into_u32
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field.
sdiv_into_u64
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1], then masks to B bits so the two’s-complement pattern fits the field.
smul_from_u8
signed, multiply: sign-extended over B bits on read.
smul_from_u16
signed, multiply: sign-extended over B bits on read.
smul_from_u32
signed, multiply: sign-extended over B bits on read.
smul_from_u64
signed, multiply: sign-extended over B bits on read.
smul_into_u8
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1] (see $sdiv_into).
smul_into_u16
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1] (see $sdiv_into).
smul_into_u32
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1] (see $sdiv_into).
smul_into_u64
Saturates the raw count to [-2^(B-1), 2^(B-1) - 1] (see $sdiv_into).