Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fix some warnings on windows + fix 32 bits builds an incorrect use of size_t #7425

Conversation

nicola-cab
Copy link
Member

What, How & Why?

WIP. Contains some fixes for some warnings + uses uint64_t instead of size_t in order to make compressed arrays compatible with 32 bits builds.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed
  • bindgen/spec.yml, if public C++ API changed

Copy link
Contributor

@finnschiermer finnschiermer left a comment

Choose a reason for hiding this comment

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

I think there is a fix in this PR, but there are also a lot of unwanted changes. I'll move the fix to a separate branch with less clutter.

src/realm/array.cpp Show resolved Hide resolved
@@ -233,7 +233,7 @@ class bf_ref;
class bf_iterator {
uint64_t* data_area;
uint64_t* first_word_ptr;
size_t field_position;
uint64_t field_position;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is just a slowdown on 32 bit machines. The position is never too large for a 32 bit value.

@@ -303,11 +303,12 @@ class bf_iterator {
auto first_word = first_word_ptr[0];
uint64_t mask = 0 - 1ULL;
if (field_size < 64) {
mask = static_cast<size_t>((1ULL << field_size) - 1);
//we should never cast to size_t, but to uint64_t in order to support 32 bits
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not have a cast here at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in other PR I hope

value &= mask;
}
// zero out field in first word:
auto first_word_mask = ~(mask << in_word_position);
uint64_t first_word_mask = ~(mask << in_word_position);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is fine. (but makes no difference).

@@ -391,14 +392,14 @@ inline void write_bitfield(uint64_t* data_area, size_t field_position, size_t wi

inline int64_t sign_extend_field_by_mask(size_t sign_mask, uint64_t value)
{
uint64_t sign_extension = 0 - (value & sign_mask);
uint64_t sign_extension = (uint64_t)0 - (value & sign_mask);
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer 0ULL

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in other PR

@@ -174,13 +174,15 @@ class NodeHeader {

static size_t unsigned_to_num_bits(uint64_t value)
{
return 1 + log2(static_cast<size_t>(value));
return 1 + static_cast<size_t>(std::log2(value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this could be a fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

now in different PR

src/realm/node_header.hpp Show resolved Hide resolved
src/realm/node_header.hpp Show resolved Hide resolved
src/realm/node_header.hpp Show resolved Hide resolved
src/realm/node_header.hpp Show resolved Hide resolved
@nicola-cab
Copy link
Member Author

This PR #7427 contains the same fixes expressed in better way and less fuzzy..

@nicola-cab nicola-cab closed this Mar 7, 2024
const auto search_vector = populate(static_cast<int>(width), value);
const auto field_count = num_fields_for_width(static_cast<int>(width));
const auto bit_count_pr_iteration = num_bits_for_width(static_cast<int>(width));
int64_t total_bit_count_left = static_cast<int64_t>((end - start) * width);
Copy link
Contributor

Choose a reason for hiding this comment

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

it would also be ok to use size_t for this ... perhaps that would allow for dropping a cast below?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think total_bit_count_left can become negative since we are taking out the amount of bits read per iteration. I'll address all the casts in a separate PR.. let's merge #7427

@@ -1285,6 +1285,20 @@ NONCONCURRENT_TEST(Test_basic_find_GT_value_greater_32bit)

#endif

ONLY(Test_ArrayInt_negative_nums)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to merge an ONLY test?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants