Skip to content

Commit

Permalink
Merge branch 'main' into issue111
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Jan 14, 2024
2 parents 0b9ab92 + b35ccb3 commit 17fef2d
Show file tree
Hide file tree
Showing 16 changed files with 1,527 additions and 1,138 deletions.
1,785 changes: 908 additions & 877 deletions math/wide_decimal/decwide_t.h

Large diffs are not rendered by default.

298 changes: 156 additions & 142 deletions math/wide_decimal/decwide_t_detail.h

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions math/wide_decimal/decwide_t_detail_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,28 @@

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> typename std::enable_if<IsForwardFft, float_type>::type
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> std::enable_if_t<IsForwardFft, float_type>
{
return template_sin_order_1<float_type>(num_points);
}

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> typename std::enable_if<(!IsForwardFft), float_type>::type
constexpr auto const_unique_wp_real_init(std::uint32_t num_points) -> std::enable_if_t<(!IsForwardFft), float_type>
{
return static_cast<float_type>(-template_sin_order_1<float_type>(num_points));
}

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> typename std::enable_if<IsForwardFft, float_type>::type
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> std::enable_if_t<IsForwardFft, float_type>
{
return template_sin_order_2<float_type>(num_points);
}

template<typename float_type,
const bool IsForwardFft>
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> typename std::enable_if<(!IsForwardFft), float_type>::type
constexpr auto const_unique_wp_imag(std::uint32_t num_points) -> std::enable_if_t<(!IsForwardFft), float_type>
{
return static_cast<float_type>(-template_sin_order_2<float_type>(num_points));
}
Expand Down Expand Up @@ -248,8 +248,8 @@
{
if(j > i)
{
std::swap(data[j - 1U], data[i - 1U]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
std::swap(data[j], data[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
util::swap_unsafe(data[j - 1U], data[i - 1U]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
util::swap_unsafe(data[j], data[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}

auto m = num_points;
Expand All @@ -268,7 +268,7 @@

template<typename float_type,
const bool IsForwardFft>
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> typename std::enable_if<IsForwardFft, void>::type
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> std::enable_if_t<IsForwardFft>
{
fft_lanczos_fft<float_type, true>(num_points / 2U, data);

Expand Down Expand Up @@ -312,7 +312,7 @@

template<typename float_type,
const bool IsForwardFft>
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> typename std::enable_if<(!IsForwardFft), void>::type
auto rfft_lanczos_rfft(std::uint32_t num_points, float_type* data) -> std::enable_if_t<(!IsForwardFft)>
{
auto real_part = static_cast<float_type>(static_cast<float_type>(1) + const_unique_wp_real<float_type, false>(num_points));
auto imag_part = static_cast<float_type>( const_unique_wp_imag<float_type, false>(num_points));
Expand Down
24 changes: 17 additions & 7 deletions math/wide_decimal/decwide_t_detail_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

template<typename InputIteratorLeftType,
typename InputIteratorRightType>
WIDE_DECIMAL_CONSTEXPR
auto compare_ranges( InputIteratorLeftType pa,
InputIteratorRightType pb,
const std::uint_fast32_t count) -> std::int_fast8_t
Expand Down Expand Up @@ -68,6 +69,7 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_add_n( OutputLimbIteratorType r,
InputLimbIteratorType u,
InputLimbIteratorType v,
Expand Down Expand Up @@ -107,6 +109,7 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_subtract_n( OutputLimbIteratorType r,
InputLimbIteratorType u, // NOLINT(bugprone-easily-swappable-parameters)
InputLimbIteratorType v,
Expand Down Expand Up @@ -166,13 +169,14 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
void eval_multiply_n_by_n_to_2n
(
OutputLimbIteratorType r,
InputLimbIteratorType a,
InputLimbIteratorType b,
const std::int_fast32_t count,
const typename std::enable_if<std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint8_t>::value>::type* p_nullparam = nullptr
std::enable_if_t<std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint8_t>::value, int>* p_nullparam = static_cast<int*>(nullptr)
)
{
static_cast<void>(p_nullparam);
Expand All @@ -195,7 +199,7 @@
count * static_cast<std::int_fast32_t>(INT8_C(2))
);

std::fill(r, r + fill_dst, static_cast<local_limb_type>(UINT8_C(0)));
util::fill_unsafe(r, r + fill_dst, static_cast<local_limb_type>(UINT8_C(0)));

const auto count_minus_one =
static_cast<std::int_fast32_t>
Expand Down Expand Up @@ -237,14 +241,16 @@

template<typename InputLimbIteratorType,
typename OutputLimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
void eval_multiply_n_by_n_to_2n
(
OutputLimbIteratorType r,
InputLimbIteratorType a,
InputLimbIteratorType b,
const std::int_fast32_t count,
const typename std::enable_if<( std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint16_t>::value
|| std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint32_t>::value)>::type* p_nullparam = nullptr)
std::enable_if_t<( std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint16_t>::value
|| std::is_same<typename std::iterator_traits<OutputLimbIteratorType>::value_type, std::uint32_t>::value), int>* p_nullparam = static_cast<int*>(nullptr)
)
{
static_cast<void>(p_nullparam);

Expand Down Expand Up @@ -317,6 +323,7 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto mul_loop_n( LimbIteratorType u,
typename std::iterator_traits<LimbIteratorType>::value_type n,
const std::int32_t p) -> typename std::iterator_traits<LimbIteratorType>::value_type
Expand Down Expand Up @@ -354,6 +361,7 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto div_loop_n( LimbIteratorType u,
typename std::iterator_traits<LimbIteratorType>::value_type n,
const std::int32_t p) -> typename std::iterator_traits<LimbIteratorType>::value_type
Expand Down Expand Up @@ -389,6 +397,7 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_multiply_kara_propagate_carry( LimbIteratorType t,
const std::uint_fast32_t n,
const typename std::iterator_traits<LimbIteratorType>::value_type carry) -> void
Expand Down Expand Up @@ -433,6 +442,7 @@
}

template<typename LimbIteratorType>
WIDE_DECIMAL_CONSTEXPR
auto eval_multiply_kara_propagate_borrow( LimbIteratorType t,
const std::uint_fast32_t n,
const bool has_borrow) -> void
Expand Down Expand Up @@ -548,7 +558,7 @@
// Step 1
eval_multiply_kara_n_by_n_to_2n(r0, a1, b1, nh, t);
eval_multiply_kara_n_by_n_to_2n(r2, a0, b0, nh, t);
std::copy(r0, r0 + static_cast<std::size_t>(static_cast<std::size_t>(n) * static_cast<std::size_t>(UINT8_C(2))), t0);
util::copy_unsafe(r0, r0 + static_cast<std::size_t>(static_cast<std::size_t>(n) * static_cast<std::size_t>(UINT8_C(2))), t0);

// Step 2
local_limb_type carry;
Expand Down Expand Up @@ -703,8 +713,8 @@
static_cast<std::size_t>(prec_elems_for_multiply) * static_cast<std::size_t>(UINT8_C(2))
);

std::fill(af + fill_distance, af + n_fft, static_cast<local_fft_float_type>(0));
std::fill(bf + fill_distance, bf + n_fft, static_cast<local_fft_float_type>(0));
util::fill_unsafe(af + fill_distance, af + n_fft, static_cast<local_fft_float_type>(0));
util::fill_unsafe(bf + fill_distance, bf + n_fft, static_cast<local_fft_float_type>(0));

// Perform forward FFTs on the data arrays a and b.
detail::fft::rfft_lanczos_rfft<local_fft_float_type, true>(n_fft, af);
Expand Down
2 changes: 2 additions & 0 deletions soft_double.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<ClInclude Include="test\test_soft_double_examples.h" />
<ClInclude Include="util\memory\util_n_slot_array_allocator.h" />
<ClInclude Include="util\utility\util_baselexical_cast.h" />
<ClInclude Include="util\utility\util_constexpr_algorithm_unsafe.h" />
<ClInclude Include="util\utility\util_constexpr_cmath_unsafe.h" />
<ClInclude Include="util\utility\util_dynamic_array.h" />
<ClInclude Include="util\utility\util_noncopyable.h" />
<ClInclude Include="util\utility\util_pseudorandom_time_point_seed.h" />
Expand Down
6 changes: 6 additions & 0 deletions soft_double.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
<ClInclude Include="util\utility\util_pseudorandom_time_point_seed.h">
<Filter>util\utility</Filter>
</ClInclude>
<ClInclude Include="util\utility\util_constexpr_algorithm_unsafe.h">
<Filter>util\utility</Filter>
</ClInclude>
<ClInclude Include="util\utility\util_constexpr_cmath_unsafe.h">
<Filter>util\utility</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include=".github\workflows\soft_double.yml">
Expand Down
2 changes: 2 additions & 0 deletions soft_double_vs2022.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<ClInclude Include="test\test_soft_double_examples.h" />
<ClInclude Include="util\memory\util_n_slot_array_allocator.h" />
<ClInclude Include="util\utility\util_baselexical_cast.h" />
<ClInclude Include="util\utility\util_constexpr_algorithm_unsafe.h" />
<ClInclude Include="util\utility\util_constexpr_cmath_unsafe.h" />
<ClInclude Include="util\utility\util_dynamic_array.h" />
<ClInclude Include="util\utility\util_noncopyable.h" />
<ClInclude Include="util\utility\util_pseudorandom_time_point_seed.h" />
Expand Down
6 changes: 6 additions & 0 deletions soft_double_vs2022.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
<ClInclude Include="util\utility\util_pseudorandom_time_point_seed.h">
<Filter>util\utility</Filter>
</ClInclude>
<ClInclude Include="util\utility\util_constexpr_algorithm_unsafe.h">
<Filter>util\utility</Filter>
</ClInclude>
<ClInclude Include="util\utility\util_constexpr_cmath_unsafe.h">
<Filter>util\utility</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include=".github\workflows\soft_double.yml">
Expand Down
36 changes: 19 additions & 17 deletions target/micros/stm32f429/make/single/crt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include <cstdlib>
#include <iterator>

extern "C"
{
// Patched labels.
void* __dso_handle;
}

namespace crt
{
void init_ram();
Expand All @@ -24,8 +30,6 @@ void __my_startup(void)
// the base position of the interrupt vector table.
// So we do nothing here.

// TBD: Chip init: Watchdog, port, and oscillator, if any needed.

// Initialize statics from ROM to RAM.
// Zero-clear default-initialized static RAM.
crt::init_ram();
Expand All @@ -36,16 +40,8 @@ void __my_startup(void)
// Jump to main (and never return).
asm volatile("ldr r3, =main");
asm volatile("blx r3");

exit(EXIT_SUCCESS);

// TBD: Nothing on return from main.
}

extern "C" void _exit (int);

extern "C" void _exit (int) { }

extern "C"
{
extern std::uintptr_t _rom_data_begin; // Start address for the initialization values of the rom-to-ram section.
Expand Down Expand Up @@ -73,25 +69,31 @@ void crt::init_ram()
// Note that the bss segment is aligned by 4.
std::fill(static_cast<memory_aligned_type*>(static_cast<void*>(&_bss_begin)),
static_cast<memory_aligned_type*>(static_cast<void*>(&_bss_end)),
static_cast<memory_aligned_type>(0U));
static_cast<memory_aligned_type>(UINT8_C(0)));
}

extern "C"
{
struct ctor_type
{
typedef void(*function_type)();
typedef std::reverse_iterator<const function_type*> const_reverse_iterator;
using function_type = void(*)(void);
};

extern ctor_type::function_type _ctors_end[];
extern ctor_type::function_type _ctors_begin[];
extern ctor_type::function_type _ctors_end;
extern ctor_type::function_type _ctors_begin;
}

namespace crt
{
void init_ctors();
}

void crt::init_ctors()
{
std::for_each(ctor_type::const_reverse_iterator(_ctors_end),
ctor_type::const_reverse_iterator(_ctors_begin),
using local_const_reverse_iterator = std::reverse_iterator<const ctor_type::function_type*>;

std::for_each(local_const_reverse_iterator(&_ctors_end),
local_const_reverse_iterator(&_ctors_begin),
[](const ctor_type::function_type pf)
{
pf();
Expand Down
16 changes: 8 additions & 8 deletions target/micros/stm32f429/make/stm32f429.ld
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)

/* The beginning and end of the program ROM area */
/* Set up a ROM area with a size of 64K */
/* Set up a ROM area with a size of 512K */
_rom_begin = 0x08000000;
_rom_end = 0x08010000;
_rom_end = 0x08080000;

/* The beginning and end (i.e., the top) of the stack */
/* Set up a stack with a size of 4K */
_stack_begin = 0x20007000;
_stack_end = 0x20008000;
/* Set up a stack with a size of 16K */
_stack_begin = 0x2001C000;
_stack_end = 0x20020000;

__initial_stack_pointer = 0x20008000 - 4;
__initial_stack_pointer = 0x20020000 - 4;

MEMORY
{
ROM(rx) : ORIGIN = 0x08000000, LENGTH = 64K
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 0x7000
ROM(rx) : ORIGIN = 0x08000000, LENGTH = 512K
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 128K - 16K
}

SECTIONS
Expand Down
5 changes: 3 additions & 2 deletions util/utility/util_baselexical_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#ifndef UTIL_BASELEXICAL_CAST_2020_06_28_H // NOLINT(llvm-header-guard)
#define UTIL_BASELEXICAL_CAST_2020_06_28_H

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator>

#include <util/utility/util_constexpr_algorithm_unsafe.h>

namespace util {

template<typename OutputIterator,
Expand Down Expand Up @@ -131,7 +132,7 @@
}
}

std::reverse(out_first, out + static_cast<std::size_t>(UINT8_C(1)));
util::reverse_unsafe(out_first, out + static_cast<std::size_t>(UINT8_C(1)));
}

return out + static_cast<std::size_t>(UINT8_C(1));
Expand Down
Loading

0 comments on commit 17fef2d

Please sign in to comment.