Make cordic method static

This commit is contained in:
Camille Monière 2022-02-15 19:37:37 +01:00
parent 0947b52266
commit f921587f5b
Signed by: moniere
GPG key ID: 188DD5B072181C0F
2 changed files with 13 additions and 15 deletions

View file

@ -41,8 +41,8 @@ public:
return in * kn_i / 8U;
}
constexpr std::complex<int64_t> cordic(std::complex<int64_t> x_in,
uint8_t counter) const {
static constexpr std::complex<int64_t> cordic(std::complex<int64_t> x_in,
uint8_t counter) {
int64_t A = x_in.real();
int64_t B = x_in.imag();
@ -72,8 +72,8 @@ public:
return in * kn_values[NStages - 1];
}
constexpr std::complex<double> cordic(std::complex<double> x_in,
uint8_t counter) const {
static constexpr std::complex<double> cordic(std::complex<double> x_in,
uint8_t counter) {
const std::complex<int64_t> fx_x_in(int64_t(x_in.real() * double(in_scale_factor)),
int64_t(x_in.imag() * double(in_scale_factor)));
@ -89,9 +89,9 @@ public:
return ap_int<ap_W>(tmp >> 3);
}
void cordic(const ap_int<In_W> & re_in, const ap_int<In_W> & im_in,
static void cordic(const ap_int<In_W> & re_in, const ap_int<In_W> & im_in,
const ap_uint<8> & counter,
ap_int<Out_W> & re_out, ap_int<Out_W> & im_out) const {
ap_int<Out_W> & re_out, ap_int<Out_W> & im_out) {
const ap_uint<6 + 1> R = (rom_cordic.rom[counter] >> (7 - NStages));

View file

@ -119,7 +119,7 @@ TEST_CASE("ROM-based Cordic works with C-Types", "[CORDIC]") {
for (unsigned iter = 0; iter < n_lines; iter++) {
// Execute
values_out[iter] = cordic.cordic(values_in[iter], (iter & 255));
values_out[iter] = cordic_rom::cordic(values_in[iter], (iter & 255));
// Display the results
// cout << "Series " << iter;
@ -196,7 +196,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") {
// if (iter < cnt_mask + 1)
// fprintf(romf, "%03d\n", (uint16_t) cordic.rom_cordic.rom[counter]);
cordic.cordic(
cordic_rom::cordic(
values_re_in[iter], values_im_in[iter],
counter,
values_re_out[iter], values_im_out[iter]);
@ -273,7 +273,7 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") {
// if (iter < cnt_mask + 1)
// fprintf(romf, "%03d\n", (uint16_t) cordic.rom_cordic.rom[counter]);
cordic.cordic(
cordic_rom::cordic(
values_re_in[iter], values_im_in[iter],
counter,
values_re_out[iter], values_im_out[iter]);
@ -303,15 +303,13 @@ TEST_CASE("ROM-based Cordic works with AP-Types", "[CORDIC]") {
TEST_CASE("ROM-based Cordic constexpr are evaluated during compilation.", "[CORDIC]") {
SECTION("W:16 - I:4 - Stages:6 - q:64 - C-Types") {
static constexpr cordic_rom cordic {};
constexpr complex<int64_t> value_in = (1U << 12) * 97;
constexpr uint8_t angle = 169;
constexpr complex<int64_t> res1 = cordic.cordic(value_in, angle);
constexpr complex<int64_t> res2 = cordic.cordic(value_in, angle);
constexpr complex<int64_t> res1 = cordic_rom::cordic(value_in, angle);
constexpr complex<int64_t> res2 = cordic_rom::cordic(value_in, angle);
static_assert(res1 == res2, "Test");
REQUIRE_FALSE(res1 == cordic.cordic(complex<int64_t>(1, 0), angle));
REQUIRE(res1 == cordic.cordic(value_in, angle));
REQUIRE_FALSE(res1 == cordic_rom::cordic(complex<int64_t>(1, 0), angle));
REQUIRE(res1 == cordic_rom::cordic(value_in, angle));
}
}