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

Make unaligned unmarshaling opt-in in C++ #2536

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

bernardnormier
Copy link
Member

This PR makes the unaligned unmarshaling of some cpp:array sequences opt-in in C++.

It also improves the custom test.

# Extra -I because we include <MyByteSeq.h> in the generated code.
# ICE_UNALIGNED means enable unaligned decoding for integral types such as int32_t. It requires a little endian CPU.
# TODO: should be turn on ICE_UNALIGNED only on some platforms?
$(test)_cppflags := -I$(project) -DICE_UNALIGNED
Copy link
Member Author

Choose a reason for hiding this comment

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

We also need to define ICE_UNALIGNED on Windows. I'll do this later as I currently don't have access to a Windows computer.

cpp/test/Ice/custom/TestAMDI.cpp Outdated Show resolved Hide resolved
#ifdef ICE_UNALIGNED
// Verify inSeq is not aligned.
test(reinterpret_cast<size_t>(in.first) % 8 != 0);
test(*(in.first) == 3.14);
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure this works everywhere. It works on macos arm64.

Copy link
Member

@pepone pepone left a comment

Choose a reason for hiding this comment

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

Ice for Python took advantage of this optimization for unmarshaling sequences

See

IcePy::SequenceInfo::unmarshalPrimitiveSequence(

Maybe we should enable it for Python builds.

cpp/test/Ice/custom/TestAMDI.cpp Outdated Show resolved Hide resolved
@@ -591,7 +583,8 @@ namespace Ice
}
}

#ifdef ICE_UNALIGNED // Optimization with unaligned reads
#if defined(ICE_UNALIGNED) || (defined(_WIN32) && defined(ICE_API_EXPORTS))
Copy link
Member Author

Choose a reason for hiding this comment

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

On Windows, we need to build & export these functions all the time, otherwise they aren't available when we "opt in" to get them.


using namespace std;
using namespace Ice;
using namespace Test;

void
TestIntfI::opShortArrayAsync(
pair<const int16_t*, const int16_t*> inSeq,
Copy link
Member

Choose a reason for hiding this comment

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

don't we need to add padding here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the padding is a function of the number of previous bytes in the request message (14 for the header, N for the operation name etc.).

@@ -591,7 +583,8 @@ namespace Ice
}
}

#ifdef ICE_UNALIGNED // Optimization with unaligned reads
#if defined(ICE_UNALIGNED) || (defined(_WIN32) && defined(ICE_API_EXPORTS))
Copy link
Member

Choose a reason for hiding this comment

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

What about renaming this macro to ICE_SUPPORT_UNALIGMENT_READ

Copy link
Member Author

@bernardnormier bernardnormier Jul 22, 2024

Choose a reason for hiding this comment

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

I prefer a short / easier to type name. And it's not about supporting unaligned reads, but about wanting to use them.

@bernardnormier bernardnormier merged commit 0e019ef into zeroc-ice:main Jul 23, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants