comparison operations cannot be vectorized

Open
#534 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start by locating the existing uint128 and int128 comparison operators and their tests; the issue does not name file paths or test targets. Check how those operators currently compare the high and low words, then evaluate the proposed individual comparison functions against the project’s conventions. Done when the six comparison operations work correctly for both integer types and the relevant tests pass.

Written by the indexing model from the issue text.

Description

I think it's more efficient to implement the six comparison functions individually and then use them in the operators.

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_uint128_eq(const uint128& x, const uint128& y) noexcept
{
#if BOOST_INT128_ENDIAN_LITTLE_BYTE
	return (x.low == y.low) & (x.high == y.high);
#else
	return (x.high == y.high) & (x.low == y.low);
#endif
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_uint128_ne(const uint128& x, const uint128& y) noexcept
{
#if BOOST_INT128_ENDIAN_LITTLE_BYTE
	return (x.low != y.low) | (x.high != y.high);
#else
	return (x.high != y.high) | (x.low != y.low);
#endif
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_uint128_lt(const uint128& x, const uint128& y) noexcept
{
	return (x.high < y.high) | ((x.high == y.high) & (x.low < y.low));
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_uint128_gt(const uint128& x, const uint128& y) noexcept
{
	return (x.high > y.high) | ((x.high == y.high) & (x.low > y.low));
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_uint128_le(const uint128& x, const uint128& y) noexcept
{
	return !compare_uint128_lt(y, x);
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_uint128_ge(const uint128& x, const uint128& y) noexcept
{
	return !compare_uint128_gt(y, x);
}
BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_int128_eq(const int128& x, const int128& y) noexcept
{
#if BOOST_INT128_ENDIAN_LITTLE_BYTE
	return (x.low == y.low) & (x.high == y.high);
#else
	return (x.high == y.high) & (x.low == y.low);
#endif
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_int128_ne(const int128& x, const int128& y) noexcept
{
#if BOOST_INT128_ENDIAN_LITTLE_BYTE
	return (x.low != y.low) | (x.high != y.high);
#else
	return (x.high != y.high) | (x.low != y.low);
#endif
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_int128_lt(const int128& x, const int128& y) noexcept
{
	return ((x.signed_high() < y.signed_high())) | ((x.high == y.high) & (x.low < y.low));
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_int128_gt(const int128& x, const int128& y) noexcept
{
	return (x.signed_high() > y.signed_high()) | ((x.high == y.high) & (x.low > y.low));
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_int128_le(const int128& x, const int128& y) noexcept
{
	return !compare_int128_lt(y, x);
}

BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr bool	compare_int128_ge(const int128& x, const int128& y) noexcept
{
	return !compare_int128_gt(y, x);
}
Dominant language
C++
Stars
22
Forks
6
Avg merge
17h 33m
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/int128

All issues in boostorg/int128

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.