diff --git a/Src/Particle/AMReX_Particle.H b/Src/Particle/AMReX_Particle.H index bed72c2cc5..9f37cadeaf 100644 --- a/Src/Particle/AMReX_Particle.H +++ b/Src/Particle/AMReX_Particle.H @@ -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; } @@ -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(val); // bc we take - + Long lval = static_cast(val); // bc we store the inverse sign bit r = (sign) ? lval : -lval; return r; } @@ -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(1) << 63; } @@ -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; } };