Skip to content

Commit

Permalink
More Inline Comments, Add .valid()
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Jan 31, 2024
1 parent d01cf94 commit c5ef706
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Src/Particle/AMReX_Particle.H
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct ParticleIDWrapper
val = -id;
}

m_idata |= (sign << 63); // put the sign in the leftmost bit
m_idata |= (sign << 63); // put the inverse sign in the uppermost bit
m_idata |= (val << 24); // put the val in the next 39
return *this;
}
Expand All @@ -95,10 +95,10 @@ struct ParticleIDWrapper
{
Long r = 0;

uint64_t sign = m_idata >> 63; // extract leftmost sign bit
uint64_t sign = m_idata >> 63; // extract uppermost sign bit
uint64_t val = ((m_idata >> 24) & 0x7FFFFFFFFF); // extract next 39 id bits

Long lval = static_cast<Long>(val); // bc we take -
Long lval = static_cast<Long>(val); // bc we store the inverse sign bit
r = (sign) ? lval : -lval;
return r;
}
Expand All @@ -110,7 +110,8 @@ struct ParticleIDWrapper
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void negate () noexcept
{
// the leftmost bit is our id sign - we will XOR it with 1 to flip it
// The uppermost bit is our id inverse sign.
// We will XOR it with 1 to flip it.
m_idata ^= static_cast<uint64_t>(1) << 63;
}

Expand All @@ -121,7 +122,18 @@ struct ParticleIDWrapper
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool negative () const noexcept
{
// the leftmost bit is our id sign
// the leftmost bit is our id's inverse sign
return !(m_idata >> 63);
}

/** Check the sign of the id.
*
* Returns true if the id is positive, otherwise false (invalid particle).
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool valid () const noexcept
{
// the leftmost bit is our id's inverse sign
return m_idata >> 63;
}
};
Expand Down

0 comments on commit c5ef706

Please sign in to comment.