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

Fix compilation of primitive types #98

Merged
merged 3 commits into from
May 30, 2022
Merged

Fix compilation of primitive types #98

merged 3 commits into from
May 30, 2022

Conversation

ridiculousfish
Copy link
Owner

To restate #96: currently libdivide "dispatches" based on whether its type is uint32_t, uint64_t, etc. However these types are mapped to a primitive type like unsigned int; if say unsigned long has the same width then divider<unsigned long> will fail to compile since there is no specialization for it.

The idea here is to go back to a dispatch based on the size and signedness of the type, so that unsigned long and unsigned int will be handled the same. To detect the signedness we avoid type_traits which is apparently unavailable in AVR; instead we use the following trick:

T(0) > T(-1)

which will be true only for signed types. We can prevent floating point by throwing in a shift:

(T(0) >> 0) > T(-1)

An inelegant hack for an uncivilized language but it does the job. Fixes #96.

This addresses the issue where e.g. 'long' and 'long long' are both 64 bit,
but we only overload for int64_t which is either long or 'long long',
meaning template instantiation will fail with the other type.

Fixes #96
Instead of the libdivide namespace, use the libdivide::detail
namespace, to limit what we inject.
@ridiculousfish
Copy link
Owner Author

@adbancroft if possible please check whether this works with your AVR setup, thank you

@adbancroft
Copy link
Collaborator

@adbancroft if possible please check whether this works with your AVR setup, thank you

The tests passed on both simulator & real hardware (AT Mega 2560)

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.

Regression: ptrdiff_t/size_t on macOS don't work anymore
2 participants