Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions icicle/include/icicle/balanced_decomposition.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "icicle/vec_ops.h" // For VecOpsConfig
#include <cmath>

namespace icicle {
namespace balanced_decomposition {
Expand Down Expand Up @@ -36,10 +37,11 @@ namespace icicle {
static_assert(T::TLC == 2, "Balanced decomposition assumes q ~64-bit");

constexpr auto q_storage = T::get_modulus();
const int64_t q = *(const int64_t*)&q_storage;
ICICLE_ASSERT(q > 0) << "Expecting at least one slack bit to use int64 arithmetic";
const uint64_t q_u = (static_cast<uint64_t>(q_storage.limbs[0])) |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) I think you assume limbs are 32b so please add a static assert
(2) now that it is uint64, the ICICLE_ASSERT(q_u > 0) is redundant since uint is always >0. The original intent was to make sure we have a slack bit.
(3) If I recall correctly similar code also exists in cpu_balanced_decomposition code, please fix it as well.

(static_cast<uint64_t>(q_storage.limbs[1]) << 32);
ICICLE_ASSERT(q_u > 0) << "Expecting at least one slack bit to use 64-bit arithmetic";

const double log2_q = std::log2(static_cast<double>(q));
const double log2_q = std::log2(static_cast<double>(q_u));
const double log2_b = std::log2(static_cast<double>(base));
const uint32_t digits = static_cast<uint32_t>(std::ceil(log2_q / log2_b));

Expand Down Expand Up @@ -108,4 +110,4 @@ namespace icicle {
const T* input, size_t input_size, uint32_t base, const VecOpsConfig& config, T* output, size_t output_size);

} // namespace balanced_decomposition
} // namespace icicle
} // namespace icicle
Loading