Skip to content

Commit

Permalink
Merge pull request #433 from ckormanyos/various_updates
Browse files Browse the repository at this point in the history
Various updates
  • Loading branch information
ckormanyos authored Aug 6, 2023
2 parents 40bbf88 + 17d183a commit b073580
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 86 deletions.
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ initializes a skinny microcontroller abstraction layer (MCAL). Control is
then passed to a simple multitasking scheduler that schedules the
LED application, calls a cyclic a benchmark task, and services the watchdog.

The LED application toggles a user-LED with a frequency of 1/2 Hz
The LED application toggles a user-LED with a frequency of $\frac{1}{2}~\text{Hz}$
The result is LED on for one second, LED off for one second.
The LED application runs cyclically and perpetually
without break or pause.
Expand Down Expand Up @@ -197,7 +197,7 @@ prior to building the target of the reference application.
You can `wget` (or with a slightly different procedure optionally install)
the `gcc-arm-none-eabi` toolchain if needed.
In this case, I have found it convenient to use
a modern GCC-`arm-none-eabi` for MacOS which can be found at
a modern `gcc-arm-none-eabi` for MacOS which can be found at
[Arm GNU Toolchain Downloads](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads).

The `arm-non-eabi` toolchain can be fetched via `wget`
Expand Down Expand Up @@ -356,7 +356,7 @@ The program toggles the yellow LED on `portb.5`.
The MICROCHIP(R) [former ATMEL(R)] ATmega4809 configuration
called `target atmega4809` runs
on an ARDUINO(R) EVERY compatible board clocked
with the internal resonator at 20MHz.
with the internal resonator at $20~\text{MHz}$.
The program toggles the yellow LED on `porte.2` (i.e., `D5`).

The Espressif (XTENSA) NodeMCU ESP32 implementation uses
Expand Down Expand Up @@ -392,7 +392,7 @@ The program toggles the green LED on `portb.0`.

The ARM(R) A8 configuration (called `target am335x`) runs on the BeagleBone
board (black edition). For the white edition, the CPU clock needs to be reduced
from 900MHz to something like 600MHz. This project creates a bare-metal program
from $900~\text{MHz}$ to something like $600~\text{MHz}$. This project creates a bare-metal program
for the BeagleBone that runs independently from any kind of `*nix` distro on
the board. Our program is designed to boot the BeagleBone from a raw binary file
called _MLO_ stored on a FAT32 SDHC microcard. The binary file includes a
Expand Down Expand Up @@ -422,7 +422,7 @@ starter kit is used.

The `riscvfe310` target utilizes the SiFive RISC-V FE310 SoC
on Spark Fun's commercially available _Red_ _Thing_ _Plus_ Board.
The blue LED on port GPIO0.5 is toggled.
The blue LED on port `GPIO0.5` is toggled.

Target `nxp_imxrt1062` runs on the Teensy 4.0 board from Spark Fun.
The orange user-LED is toggled.
Expand Down
81 changes: 37 additions & 44 deletions ref_app/src/math/wide_decimal/decwide_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@
typename std::enable_if<( std::is_integral<UnsignedIntegralType>::value
&& std::is_unsigned<UnsignedIntegralType>::value
&& (std::numeric_limits<UnsignedIntegralType>::digits <= std::numeric_limits<limb_type>::digits))>::type const* = nullptr>
decwide_t(const UnsignedIntegralType u) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
constexpr decwide_t(const UnsignedIntegralType u) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
: my_data (decwide_t_elem_number),
my_exp (static_cast<exponent_type>(INT8_C(0))),
my_neg (false),
Expand Down Expand Up @@ -1119,9 +1119,11 @@
my_data.cend() - static_cast<std::ptrdiff_t>(-ofs),
my_n_data_for_add_sub.begin() + static_cast<std::ptrdiff_t>(-ofs));

// LCOV_EXCL_START
std::fill(my_n_data_for_add_sub.begin(),
my_n_data_for_add_sub.begin() + static_cast<std::ptrdiff_t>(-ofs),
static_cast<limb_type>(UINT8_C(0))); // LCOV_EXCL_LINE
static_cast<limb_type>(UINT8_C(0)));
// LCOV_EXCL_STOP

using const_limb_pointer_type = typename std::add_const<limb_type*>::type;

Expand Down Expand Up @@ -2213,7 +2215,7 @@
my_neg = (!my_neg);
}

return *this;
return *this; // LCOV_EXCL_LINE
}

// Comparison functions.
Expand Down Expand Up @@ -2425,20 +2427,6 @@

xx.my_neg = false;

// Check if *this decwide_t is zero (or is essentially zero).
if( iszero()
|| (xx.cmp(long_double_min<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>()) < static_cast<int_fast8_t>(INT8_C(0))))
{
return static_cast<long double>(0.0F);
}

// Check if *this decwide_t over/under-flows the min/max of long double.
if(xx.cmp(long_double_max<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>()) > static_cast<int_fast8_t>(INT8_C(0)))
{
return ((!my_neg) ? std::numeric_limits<long double>::infinity()
: -std::numeric_limits<long double>::infinity());
}

constexpr auto digs_of_ldbl_to_get = static_cast<std::int32_t>(std::numeric_limits<long double>::max_digits10);

constexpr auto elems_of_ldbl_to_get_try =
Expand Down Expand Up @@ -3481,36 +3469,35 @@
}

#if !defined(WIDE_DECIMAL_DISABLE_CONSTRUCT_FROM_STRING)
auto rd_string(const char* s) -> bool // NOLINT(readability-function-cognitive-complexity)
static auto pos_of_e_func(const std::string& local_str) -> std::string::size_type
{
std::string str(s);
auto pos_of_e = std::string::npos;

// Get a possible exponent and remove it.
my_exp = static_cast<exponent_type>(INT8_C(0));
const auto pos_of_e_lo = local_str.find('e');

auto pos_of_e_func =
[](const std::string& local_str) // NOLINT(modernize-use-trailing-return-type)
{
std::string::size_type pos_of_e = std::string::npos;
if(pos_of_e_lo != std::string::npos)
{
pos_of_e = pos_of_e_lo;
}
else
{
const auto pos_of_e_hi = local_str.find('E');

const auto pos_of_e_lo = local_str.find('e');
if(pos_of_e_hi != std::string::npos)
{
pos_of_e = pos_of_e_hi;
}
}

if(pos_of_e_lo != std::string::npos)
{
pos_of_e = pos_of_e_lo;
}
else
{
const auto pos_of_e_hi = local_str.find('E');
return pos_of_e;
};

if(pos_of_e_hi != std::string::npos)
{
pos_of_e = pos_of_e_hi;
}
}
auto rd_string(const char* s) -> bool // NOLINT(readability-function-cognitive-complexity)
{
std::string str(s);

return pos_of_e;
};
// Get a possible exponent and remove it.
my_exp = static_cast<exponent_type>(INT8_C(0));

auto pos = pos_of_e_func(str);

Expand Down Expand Up @@ -4708,7 +4695,7 @@

if(pfn_callback_to_report_digits10 != nullptr)
{
pfn_callback_to_report_digits10(static_cast<std::uint32_t>(UINT8_C(0)));
pfn_callback_to_report_digits10(static_cast<std::uint32_t>(UINT8_C(0))); // LCOV_EXCL_LINE
}

using floating_point_type =
Expand Down Expand Up @@ -4806,7 +4793,7 @@

if(pfn_callback_to_report_digits10 != nullptr)
{
pfn_callback_to_report_digits10(digits10_of_iteration);
pfn_callback_to_report_digits10(digits10_of_iteration); // LCOV_EXCL_LINE
}

// Estimate the approximate decimal digits of this iteration term.
Expand All @@ -4830,7 +4817,7 @@

if(pfn_callback_to_report_digits10 != nullptr)
{
pfn_callback_to_report_digits10(static_cast<std::uint32_t>(std::numeric_limits<floating_point_type>::digits10));
pfn_callback_to_report_digits10(static_cast<std::uint32_t>(std::numeric_limits<floating_point_type>::digits10)); // LCOV_EXCL_LINE
}

return val_pi;
Expand Down Expand Up @@ -5243,11 +5230,13 @@
return decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>::my_value_ln_two();
}
#else
// LCOV_EXCL_START
template<const std::int32_t ParamDigitsBaseTen, typename LimbType, typename AllocatorType, typename InternalFloatType, typename ExponentType, typename FftFloatType>
auto ln_two() -> decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>
{
return calc_ln_two<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>();
}
// LCOV_EXCL_STOP
#endif

// Global unary operators of decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType> reference.
Expand Down Expand Up @@ -5305,13 +5294,15 @@
return decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>(u).sub_unsigned_long_long(n);
}

// LCOV_EXCL_START
template<const std::int32_t ParamDigitsBaseTen, typename LimbType, typename AllocatorType, typename InternalFloatType, typename ExponentType, typename FftFloatType, typename FloatingPointType>
auto operator-(const decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>& u,
FloatingPointType f) -> typename std::enable_if<std::is_floating_point<FloatingPointType>::value,
decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>>::type
{
return decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>(u) -= decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>(f);
}
// LCOV_EXCL_STOP

template<const std::int32_t ParamDigitsBaseTen, typename LimbType, typename AllocatorType, typename InternalFloatType, typename ExponentType, typename FftFloatType, typename SignedIntegralType>
auto operator*(const decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>& u,
Expand Down Expand Up @@ -5444,6 +5435,7 @@
return u.add_signed_long_long(n);
}

// LCOV_EXCL_START
template<const std::int32_t ParamDigitsBaseTen, typename LimbType, typename AllocatorType, typename InternalFloatType, typename ExponentType, typename FftFloatType, typename UnsignedIntegralType>
auto operator+=(decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>& u,
UnsignedIntegralType n) -> typename std::enable_if< std::is_integral<UnsignedIntegralType>::value
Expand Down Expand Up @@ -5512,6 +5504,7 @@
{
return u *= decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>(f);
}
// LCOV_EXCL_STOP

template<const std::int32_t ParamDigitsBaseTen, typename LimbType, typename AllocatorType, typename InternalFloatType, typename ExponentType, typename FftFloatType, typename SignedIntegralType>
auto operator/=(decwide_t<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>& u,
Expand Down Expand Up @@ -6219,7 +6212,7 @@
#if !defined(WIDE_DECIMAL_DISABLE_CACHED_CONSTANTS)
const floating_point_type& ln2 = ln_two<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>();
#else
const floating_point_type ln2 = ln_two<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>();
const floating_point_type ln2 = ln_two<ParamDigitsBaseTen, LimbType, AllocatorType, InternalFloatType, ExponentType, FftFloatType>(); // LCOV_EXCL_LINE
#endif

const auto nf = static_cast<std::uint32_t>(xx / ln2);
Expand Down
2 changes: 1 addition & 1 deletion ref_app/src/math/wide_decimal/decwide_t_detail_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 14U)) ? static_cast<float_type>(1.9174759731070330743990956198900093346887E-04L) : // Pi / 2^14 : as uint64_t --> UINT64_C(0x3F2921FB51AEB57C) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 15U)) ? static_cast<float_type>(9.5873799095977345870517210976476351187066E-05L) : // Pi / 2^15 : as uint64_t --> UINT64_C(0x3F1921FB539ECF31) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 16U)) ? static_cast<float_type>(4.7936899603066884549003990494658872746867E-05L) : // Pi / 2^16 : as uint64_t --> UINT64_C(0x3F0921FB541AD59E) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
// LCOV_EXCL_START
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 17U)) ? static_cast<float_type>(2.3968449808418218729186577165021820094761E-05L) : // Pi / 2^17 : as uint64_t --> UINT64_C(0x3EF921FB5439D73A) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 18U)) ? static_cast<float_type>(1.1984224905069706421521561596988984804732E-05L) : // Pi / 2^18 : as uint64_t --> UINT64_C(0x3EE921FB544197A1) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 19U)) ? static_cast<float_type>(5.9921124526424278428797118088908617299872E-06L) : // Pi / 2^19 : as uint64_t --> UINT64_C(0x3ED921FB544387BA) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
// LCOV_EXCL_START
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 20U)) ? static_cast<float_type>(2.9960562263346607504548128083570598118252E-06L) : // Pi / 2^20 : as uint64_t --> UINT64_C(0x3EC921FB544403C1) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 21U)) ? static_cast<float_type>(1.4980281131690112288542788461553611206918E-06L) : // Pi / 2^21 : as uint64_t --> UINT64_C(0x3EB921FB544422C2) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
(num_points == static_cast<std::uint32_t>(UINT32_C(1) << 22U)) ? static_cast<float_type>(7.4901405658471572113049856673065563715596E-07L) : // Pi / 2^22 : as uint64_t --> UINT64_C(0x3EA921FB54442A83) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
Expand Down
42 changes: 13 additions & 29 deletions ref_app/src/math/wide_integer/uintwide_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -4328,15 +4328,15 @@
std::allocator<void>,
AllocatorType>>::template rebind_alloc<limb_type>>>;

uu_array_type uu { };
uu_array_type uu;

representation_type
vv
{
static_cast<typename representation_type::size_type>(number_of_limbs),
static_cast<typename representation_type::value_type>(UINT8_C(0)),
typename representation_type::allocator_type() // LCOV_EXCL_LINE
};
vv
{
static_cast<typename representation_type::size_type>(number_of_limbs),
static_cast<typename representation_type::value_type>(UINT8_C(0)),
typename representation_type::allocator_type() // LCOV_EXCL_LINE
};

if(d > static_cast<limb_type>(UINT8_C(1)))
{
Expand Down Expand Up @@ -4437,7 +4437,7 @@
eval_subtract_n(detail::advance_and_point(uu.begin(), static_cast<size_t>(static_cast<local_uint_index_type>(uj - n))),
detail::advance_and_point(uu.cbegin(), static_cast<size_t>(static_cast<local_uint_index_type>(uj - n))),
nv.cbegin(),
n + static_cast<size_t>(UINT8_C(1)));
n + 1U);

// Step D5: Test the remainder.
// Set the result value: Set result.m_data[m - j] = q_hat.
Expand Down Expand Up @@ -4594,13 +4594,11 @@
| part_from_previous_value
);

const auto right_shift_prev_amount =
static_cast<local_integral_type>
part_from_previous_value =
static_cast<limb_type>
(
static_cast<unsigned_fast_type>(std::numeric_limits<limb_type>::digits - left_shift_amount)
t >> static_cast<local_integral_type>(static_cast<unsigned_fast_type>(std::numeric_limits<limb_type>::digits - left_shift_amount))
);

part_from_previous_value = static_cast<limb_type>(t >> right_shift_prev_amount);
}
}
}
Expand Down Expand Up @@ -4654,23 +4652,9 @@
{
const limb_type t = *r_ai;

*r_ai++ =
static_cast<limb_type>
(
static_cast<limb_type>
(
t >> static_cast<local_integral_type>(right_shift_amount)
)
| part_from_previous_value
);

const auto left_shift_prev_amount =
static_cast<local_integral_type>
(
static_cast<unsigned_fast_type>(std::numeric_limits<limb_type>::digits - right_shift_amount)
);
*r_ai++ = static_cast<limb_type>(static_cast<limb_type>(t >> static_cast<local_integral_type>(right_shift_amount)) | part_from_previous_value);

part_from_previous_value = static_cast<limb_type>(t << left_shift_prev_amount);
part_from_previous_value = static_cast<limb_type>(t << static_cast<local_integral_type>(static_cast<unsigned_fast_type>(std::numeric_limits<limb_type>::digits - right_shift_amount)));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions ref_app/src/mcal/mcal_gpt_arm_sys_tick.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

static constexpr auto scs_base = static_cast<register_address_type>(UINT32_C(0xE000E000));
static constexpr auto sys_tick_mhz = SysTickMHz;
static constexpr auto sys_tick_base = static_cast<register_address_type>(scs_base + static_cast<register_address_type>(UINT8_C(0x10)));
static constexpr auto sys_tick_ctrl = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x00)));
static constexpr auto sys_tick_load = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x04)));
static constexpr auto sys_tick_val = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x08)));
static constexpr auto sys_tick_cal = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x0C)));
static constexpr auto sys_tick_base = static_cast<register_address_type>(scs_base + static_cast<register_address_type>(UINT8_C(0x10)));
static constexpr auto sys_tick_ctrl = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x00)));
static constexpr auto sys_tick_load = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x04)));
static constexpr auto sys_tick_val = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x08)));
static constexpr auto sys_tick_cal = static_cast<register_address_type>(sys_tick_base + static_cast<register_address_type>(UINT8_C(0x0C)));

template<const register_address_type address,
const register_value_type value = static_cast<register_value_type>(0)>
Expand Down Expand Up @@ -148,8 +148,8 @@
static_cast<std::uint64_t>
(
((sys_tick_counter_2 >= sys_tick_counter_1)
? static_cast<std::uint64_t>( sys_tick_value | sys_tick_counter_1)
: static_cast<std::uint64_t>(my_sys_tick_value | sys_tick_counter_2))
? static_cast<std::uint64_t>(static_cast<std::uint64_t>( sys_tick_value) | sys_tick_counter_1)
: static_cast<std::uint64_t>(static_cast<std::uint64_t>(my_sys_tick_value) | sys_tick_counter_2))
);

// Perform scaling and include a rounding correction.
Expand Down

0 comments on commit b073580

Please sign in to comment.