diff options
-rw-r--r-- | al/auxeffectslot.cpp | 112 | ||||
-rw-r--r-- | al/buffer.cpp | 4 | ||||
-rw-r--r-- | al/error.cpp | 2 | ||||
-rw-r--r-- | al/event.cpp | 8 | ||||
-rw-r--r-- | al/extension.cpp | 4 | ||||
-rw-r--r-- | al/source.cpp | 36 | ||||
-rw-r--r-- | alc/alu.cpp | 2 | ||||
-rw-r--r-- | alc/backends/opensl.cpp | 8 | ||||
-rw-r--r-- | alc/backends/pipewire.cpp | 14 | ||||
-rw-r--r-- | common/alcomplex.cpp | 4 | ||||
-rw-r--r-- | common/comptr.h | 2 | ||||
-rw-r--r-- | common/intrusive_ptr.h | 4 | ||||
-rw-r--r-- | common/opthelpers.h | 36 | ||||
-rw-r--r-- | common/polyphase_resampler.cpp | 16 | ||||
-rw-r--r-- | core/ambdec.cpp | 2 | ||||
-rw-r--r-- | core/hrtf.cpp | 2 | ||||
-rw-r--r-- | core/logging.cpp | 4 | ||||
-rw-r--r-- | core/uhjfilter.cpp | 10 | ||||
-rw-r--r-- | core/voice.cpp | 26 |
19 files changed, 141 insertions, 155 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 172a3566..0eca5cb7 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -90,10 +90,10 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept const size_t lidx{(id-1) >> 6}; const ALuint slidx{(id-1) & 0x3f}; - if UNLIKELY(lidx >= context->mEffectSlotList.size()) + if(lidx >= context->mEffectSlotList.size()) [[alunlikely]] return nullptr; EffectSlotSubList &sublist{context->mEffectSlotList[lidx]}; - if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) + if(sublist.FreeMask & (1_u64 << slidx)) [[alunlikely]] return nullptr; return sublist.EffectSlots + slidx; } @@ -103,10 +103,10 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept const size_t lidx{(id-1) >> 6}; const ALuint slidx{(id-1) & 0x3f}; - if UNLIKELY(lidx >= device->EffectList.size()) + if(lidx >= device->EffectList.size()) [[alunlikely]] return nullptr; EffectSubList &sublist = device->EffectList[lidx]; - if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) + if(sublist.FreeMask & (1_u64 << slidx)) [[alunlikely]] return nullptr; return sublist.Effects + slidx; } @@ -116,10 +116,10 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept const size_t lidx{(id-1) >> 6}; const ALuint slidx{(id-1) & 0x3f}; - if UNLIKELY(lidx >= device->BufferList.size()) + if(lidx >= device->BufferList.size()) [[alunlikely]] return nullptr; BufferSubList &sublist = device->BufferList[lidx]; - if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) + if(sublist.FreeMask & (1_u64 << slidx)) [[alunlikely]] return nullptr; return sublist.Buffers + slidx; } @@ -159,7 +159,7 @@ void AddActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext *co /* Reallocate newarray if the new size ended up smaller from duplicate * removal. */ - if UNLIKELY(newcount < newarray->size()) + if(newcount < newarray->size()) [[alunlikely]] { curarray = newarray; newarray = EffectSlot::CreatePtrArray(newcount); @@ -197,7 +197,7 @@ void RemoveActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext /* Reallocate with the new size. */ auto newsize = static_cast<size_t>(std::distance(newarray->begin(), new_end)); - if LIKELY(newsize != newarray->size()) + if(newsize != newarray->size()) [[allikely]] { curarray = newarray; newarray = EffectSlot::CreatePtrArray(newsize); @@ -251,7 +251,7 @@ bool EnsureEffectSlots(ALCcontext *context, size_t needed) while(needed > count) { - if UNLIKELY(context->mEffectSlotList.size() >= 1<<25) + if(context->mEffectSlotList.size() >= 1<<25) [[alunlikely]] return false; context->mEffectSlotList.emplace_back(); @@ -259,7 +259,7 @@ bool EnsureEffectSlots(ALCcontext *context, size_t needed) sublist->FreeMask = ~0_u64; sublist->EffectSlots = static_cast<ALeffectslot*>( al_calloc(alignof(ALeffectslot), sizeof(ALeffectslot)*64)); - if UNLIKELY(!sublist->EffectSlots) + if(!sublist->EffectSlots) [[alunlikely]] { context->mEffectSlotList.pop_back(); return false; @@ -320,11 +320,11 @@ AL_API void AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; - if UNLIKELY(n < 0) + if(n < 0) [[alunlikely]] context->setError(AL_INVALID_VALUE, "Generating %d effect slots", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALCdevice *device{context->mALDevice.get()}; @@ -364,22 +364,22 @@ AL_API void AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *ef START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; - if UNLIKELY(n < 0) + if(n < 0) [[alunlikely]] context->setError(AL_INVALID_VALUE, "Deleting %d effect slots", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; if(n == 1) { ALeffectslot *slot{LookupEffectSlot(context.get(), effectslots[0])}; - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] { context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslots[0]); return; } - if UNLIKELY(ReadRef(slot->ref) != 0) + if(ReadRef(slot->ref) != 0) [[alunlikely]] { context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u", effectslots[0]); @@ -394,12 +394,12 @@ START_API_FUNC for(size_t i{0};i < slots.size();++i) { ALeffectslot *slot{LookupEffectSlot(context.get(), effectslots[i])}; - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] { context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslots[i]); return; } - if UNLIKELY(ReadRef(slot->ref) != 0) + if(ReadRef(slot->ref) != 0) [[alunlikely]] { context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u", effectslots[i]); @@ -428,7 +428,7 @@ AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot) START_API_FUNC { ContextRef context{GetContextRef()}; - if LIKELY(context) + if(context) [[allikely]] { std::lock_guard<std::mutex> _{context->mEffectSlotLock}; if(LookupEffectSlot(context.get(), effectslot) != nullptr) @@ -443,11 +443,11 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotPlaySOFT(ALuint slotid) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot{LookupEffectSlot(context.get(), slotid)}; - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] { context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotid); return; @@ -467,18 +467,18 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotPlayvSOFT(ALsizei n, const ALuint * START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; - if UNLIKELY(n < 0) + if(n < 0) [[alunlikely]] context->setError(AL_INVALID_VALUE, "Playing %d effect slots", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) [[alunlikely]] return; auto slots = al::vector<ALeffectslot*>(static_cast<ALuint>(n)); std::lock_guard<std::mutex> _{context->mEffectSlotLock}; for(size_t i{0};i < slots.size();++i) { ALeffectslot *slot{LookupEffectSlot(context.get(), slotids[i])}; - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] { context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotids[i]); return; @@ -502,11 +502,11 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopSOFT(ALuint slotid) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot{LookupEffectSlot(context.get(), slotid)}; - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] { context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotid); return; @@ -521,18 +521,18 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; - if UNLIKELY(n < 0) + if(n < 0) [[alunlikely]] context->setError(AL_INVALID_VALUE, "Stopping %d effect slots", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) [[alunlikely]] return; auto slots = al::vector<ALeffectslot*>(static_cast<ALuint>(n)); std::lock_guard<std::mutex> _{context->mEffectSlotLock}; for(size_t i{0};i < slots.size();++i) { ALeffectslot *slot{LookupEffectSlot(context.get(), slotids[i])}; - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] { context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotids[i]); return; @@ -552,12 +552,12 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); ALeffectslot *target{}; @@ -580,12 +580,12 @@ START_API_FUNC err = slot->initEffect(AL_EFFECT_NULL, EffectProps{}, context.get()); } } - if UNLIKELY(err != AL_NO_ERROR) + if(err != AL_NO_ERROR) [[alunlikely]] { context->setError(err, "Effect initialization failed"); return; } - if UNLIKELY(slot->mState == SlotState::Initial) + if(slot->mState == SlotState::Initial) [[alunlikely]] { slot->mPropsDirty = false; slot->updateProps(context.get()); @@ -600,7 +600,7 @@ START_API_FUNC if(!(value == AL_TRUE || value == AL_FALSE)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Effect slot auxiliary send auto out of range"); - if UNLIKELY(slot->AuxSendAuto == !!value) + if(slot->AuxSendAuto == !!value) [[alunlikely]] return; slot->AuxSendAuto = !!value; break; @@ -609,7 +609,7 @@ START_API_FUNC target = LookupEffectSlot(context.get(), static_cast<ALuint>(value)); if(value && !target) SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect slot target ID"); - if UNLIKELY(slot->Target == target) + if(slot->Target == target) [[alunlikely]] return; if(target) { @@ -647,10 +647,10 @@ START_API_FUNC if(ALbuffer *buffer{slot->Buffer}) { - if UNLIKELY(buffer->id == static_cast<ALuint>(value)) + if(buffer->id == static_cast<ALuint>(value)) [[alunlikely]] return; } - else if UNLIKELY(value == 0) + else if(value == 0) [[alunlikely]] return; { @@ -703,11 +703,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -723,12 +723,12 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -736,7 +736,7 @@ START_API_FUNC case AL_EFFECTSLOT_GAIN: if(!(value >= 0.0f && value <= 1.0f)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Effect slot gain out of range"); - if UNLIKELY(slot->Gain == value) + if(slot->Gain == value) [[alunlikely]] return; slot->Gain = value; break; @@ -760,11 +760,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -781,11 +781,11 @@ AL_API void AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum para START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -833,11 +833,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -853,11 +853,11 @@ AL_API void AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum para START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -883,11 +883,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if UNLIKELY(!slot) + if(!slot) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) diff --git a/al/buffer.cpp b/al/buffer.cpp index d427f214..77b484d0 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -1766,7 +1766,7 @@ START_API_FUNC continue; const auto al_buffer = LookupBuffer(device, buffer); - if (!al_buffer) + if(!al_buffer) [[alunlikely]] { ERR(EAX_PREFIX "Invalid buffer ID %u.\n", buffer); return ALC_FALSE; @@ -1782,7 +1782,7 @@ START_API_FUNC * buffer ID is specified multiple times in the provided list, it * counts each instance as more memory that needs to fit in X-RAM. */ - if(unlikely(std::numeric_limits<size_t>::max()-al_buffer->OriginalSize < total_needed)) + if(std::numeric_limits<size_t>::max()-al_buffer->OriginalSize < total_needed) [[alunlikely]] { context->setError(AL_OUT_OF_MEMORY, EAX_PREFIX "Buffer size overflow (%u + %zu)\n", al_buffer->OriginalSize, total_needed); diff --git a/al/error.cpp b/al/error.cpp index 90671011..5817e153 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -85,7 +85,7 @@ AL_API ALenum AL_APIENTRY alGetError(void) START_API_FUNC { ContextRef context{GetContextRef()}; - if(unlikely(!context)) + if(!context) [[alunlikely]] { static constexpr ALenum deferror{AL_INVALID_OPERATION}; WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror); diff --git a/al/event.cpp b/al/event.cpp index e5923c43..1e31a144 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -35,7 +35,7 @@ static int EventThread(ALCcontext *context) { RingBuffer *ring{context->mAsyncEvents.get()}; bool quitnow{false}; - while(likely(!quitnow)) + while(!quitnow) [[allikely]] { auto evt_data = ring->getReadVector().first; if(evt_data.len == 0) @@ -55,7 +55,7 @@ static int EventThread(ALCcontext *context) ring->readAdvance(1); quitnow = evt.EnumType == AsyncEvent::KillThread; - if(unlikely(quitnow)) break; + if(quitnow) [[alunlikely]] break; if(evt.EnumType == AsyncEvent::ReleaseEffectState) { @@ -155,7 +155,7 @@ AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, A START_API_FUNC { ContextRef context{GetContextRef()}; - if(unlikely(!context)) return; + if(!context) [[alunlikely]] return; if(count < 0) context->setError(AL_INVALID_VALUE, "Controlling %d events", count); if(count <= 0) return; @@ -210,7 +210,7 @@ AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *user START_API_FUNC { ContextRef context{GetContextRef()}; - if(unlikely(!context)) return; + if(!context) [[alunlikely]] return; std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> __{context->mEventCbLock}; diff --git a/al/extension.cpp b/al/extension.cpp index 5dda2a86..4327b082 100644 --- a/al/extension.cpp +++ b/al/extension.cpp @@ -37,9 +37,9 @@ AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName) START_API_FUNC { ContextRef context{GetContextRef()}; - if(unlikely(!context)) return AL_FALSE; + if(!context) [[alunlikely]] return AL_FALSE; - if(!extName) + if(!extName) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_VALUE, AL_FALSE, "NULL pointer"); size_t len{strlen(extName)}; diff --git a/al/source.cpp b/al/source.cpp index c0ad3b81..1babfb2e 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -110,8 +110,8 @@ void UpdateSourceProps(const ALsource *source, Voice *voice, ALCcontext *context VoicePropsItem *next; do { next = props->next.load(std::memory_order_relaxed); - } while(unlikely(context->mFreeVoiceProps.compare_exchange_weak(props, next, - std::memory_order_acq_rel, std::memory_order_acquire) == false)); + } while(context->mFreeVoiceProps.compare_exchange_weak(props, next, + std::memory_order_acq_rel, std::memory_order_acquire) == false); props->Pitch = source->Pitch; props->Gain = source->Gain; @@ -611,7 +611,7 @@ bool SetVoiceOffset(Voice *oldvoice, const VoicePos &vpos, ALsource *source, ALC } ++vidx; } - if(unlikely(!newvoice)) + if(!newvoice) [[alunlikely]] { auto &allvoices = *context->mVoices.load(std::memory_order_relaxed); if(allvoices.size() == voicelist.size()) @@ -2440,7 +2440,7 @@ void StartSources(ALCcontext *context, const al::span<ALsource*> srchandles, /* If the device is disconnected, and voices stop on disconnect, go right * to stopped. */ - if(unlikely(!device->Connected.load(std::memory_order_acquire))) + if(!device->Connected.load(std::memory_order_acquire)) [[alunlikely]] { if(context->mStopVoicesOnDisconnect.load(std::memory_order_acquire)) { @@ -2466,7 +2466,7 @@ void StartSources(ALCcontext *context, const al::span<ALsource*> srchandles, if(free_voices == srchandles.size()) break; } - if(unlikely(srchandles.size() != free_voices)) + if(srchandles.size() != free_voices) [[alunlikely]] { const size_t inc_amount{srchandles.size() - free_voices}; auto &allvoices = *context->mVoices.load(std::memory_order_relaxed); @@ -2495,7 +2495,7 @@ void StartSources(ALCcontext *context, const al::span<ALsource*> srchandles, } /* If there's nothing to play, go right to stopped. */ - if(unlikely(BufferList == source->mQueue.end())) + if(BufferList == source->mQueue.end()) [[alunlikely]] { /* NOTE: A source without any playable buffers should not have a * Voice since it shouldn't be in a playing or paused state. So @@ -2600,7 +2600,7 @@ void StartSources(ALCcontext *context, const al::span<ALsource*> srchandles, cur->mSourceID = source->id; cur->mState = VChangeState::Play; } - if(likely(tail)) + if(tail) [[allikely]] SendVoiceChanges(context, tail); } @@ -3220,9 +3220,9 @@ void AL_APIENTRY alSourcePlayAtTimeSOFT(ALuint source, ALint64SOFT start_time) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; - if(unlikely(start_time < 0)) + if(start_time < 0) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid time point %" PRId64, start_time); std::lock_guard<std::mutex> _{context->mSourceLock}; @@ -3238,16 +3238,16 @@ AL_API void AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; - if UNLIKELY(n < 0) + if(n < 0) [[alunlikely]] context->setError(AL_INVALID_VALUE, "Playing %d sources", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) [[alunlikely]] return; al::vector<ALsource*> extra_sources; std::array<ALsource*,8> source_storage; al::span<ALsource*> srchandles; - if LIKELY(static_cast<ALuint>(n) <= source_storage.size()) + if(static_cast<ALuint>(n) <= source_storage.size()) [[allikely]] srchandles = {source_storage.data(), static_cast<ALuint>(n)}; else { @@ -3259,7 +3259,7 @@ START_API_FUNC for(auto &srchdl : srchandles) { srchdl = LookupSource(context.get(), *sources); - if(!srchdl) + if(!srchdl) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", *sources); ++sources; } @@ -3272,13 +3272,13 @@ void AL_APIENTRY alSourcePlayAtTimevSOFT(ALsizei n, const ALuint *sources, ALint START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) [[alunlikely]] return; - if UNLIKELY(n < 0) + if(n < 0) [[alunlikely]] context->setError(AL_INVALID_VALUE, "Playing %d sources", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) [[alunlikely]] return; - if(unlikely(start_time < 0)) + if(start_time < 0) [[alunlikely]] SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid time point %" PRId64, start_time); al::vector<ALsource*> extra_sources; diff --git a/alc/alu.cpp b/alc/alu.cpp index 647b163b..f2f5f04b 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -1526,7 +1526,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ContextBa } /* Distance-based air absorption and initial send decay. */ - if(likely(Distance > props->RefDistance)) + if(Distance > props->RefDistance) [[allikely]] { const float distance_base{(Distance-props->RefDistance) * props->RolloffFactor}; const float distance_meters{distance_base * context->mParams.MetersPerUnit}; diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 9ecde509..48642496 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -916,18 +916,18 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples) } SLAndroidSimpleBufferQueueItf bufferQueue{}; - if(likely(mDevice->Connected.load(std::memory_order_acquire))) + if(mDevice->Connected.load(std::memory_order_acquire)) [[allikely]] { const SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue)}; PRINTERR(result, "recordObj->GetInterface"); - if(unlikely(SL_RESULT_SUCCESS != result)) + if(SL_RESULT_SUCCESS != result) [[alunlikely]] { mDevice->handleDisconnect("Failed to get capture buffer queue: 0x%08x", result); bufferQueue = nullptr; } } - if(unlikely(!bufferQueue) || adv_count == 0) + if(!bufferQueue || adv_count == 0) return; /* For each buffer chunk that was fully read, queue another writable buffer @@ -942,7 +942,7 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples) SLresult result{SL_RESULT_SUCCESS}; auto wdata = mRing->getWriteVector(); - if(likely(adv_count > wdata.second.len)) + if(adv_count > wdata.second.len) [[allikely]] { auto len1 = std::min(wdata.first.len, adv_count-wdata.second.len); auto buf1 = wdata.first.buf + chunk_size*(wdata.first.len-len1); diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index 057ab34b..48a1cb10 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -474,7 +474,7 @@ struct EventManager { */ void waitForInit() { - if(unlikely(!mInitDone.load(std::memory_order_acquire))) + if(!mInitDone.load(std::memory_order_acquire)) [[alunlikely]] { MainloopUniqueLock plock{mLoop}; plock.wait([this](){ return mInitDone.load(std::memory_order_acquire); }); @@ -857,7 +857,7 @@ void NodeProxy::infoCallback(const pw_node_info *info) { /* Can this actually change? */ const char *media_class{spa_dict_lookup(info->props, PW_KEY_MEDIA_CLASS)}; - if(unlikely(!media_class)) return; + if(!media_class) [[alunlikely]] return; NodeType ntype{}; if(al::strcasecmp(media_class, AudioSinkClass) == 0) @@ -901,7 +901,7 @@ void NodeProxy::paramCallback(int, uint32_t id, uint32_t, uint32_t, const spa_po if(id == SPA_PARAM_EnumFormat) { DeviceNode *node{DeviceNode::Find(mId)}; - if(unlikely(!node)) return; + if(!node) [[alunlikely]] return; if(const spa_pod_prop *prop{spa_pod_find_prop(param, nullptr, SPA_FORMAT_AUDIO_rate)}) node->parseSampleRate(&prop->value); @@ -1326,7 +1326,7 @@ void PipeWirePlayback::ioChangedCallback(uint32_t id, void *area, uint32_t size) void PipeWirePlayback::outputCallback() { pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())}; - if(unlikely(!pw_buf)) return; + if(!pw_buf) [[alunlikely]] return; const al::span<spa_data> datas{pw_buf->buffer->datas, minu(mNumChannels, pw_buf->buffer->n_datas)}; @@ -1342,7 +1342,7 @@ void PipeWirePlayback::outputCallback() uint length{mRateMatch ? mRateMatch->size : 0u}; #endif /* If no length is specified, use the device's update size as a fallback. */ - if(unlikely(!length)) length = mDevice->UpdateSize; + if(!length) [[alunlikely]] length = mDevice->UpdateSize; /* For planar formats, each datas[] seems to contain one channel, so store * the pointers in an array. Limit the render length in case the available @@ -1713,7 +1713,7 @@ ClockLatency PipeWirePlayback::getClockLatency() */ nanoseconds monoclock{seconds{tspec.tv_sec} + nanoseconds{tspec.tv_nsec}}; nanoseconds curtic{}, delay{}; - if(unlikely(ptime.rate.denom < 1)) + if(ptime.rate.denom < 1) [[alunlikely]] { /* If there's no stream rate, the stream hasn't had a chance to get * going and return time info yet. Just use dummy values. @@ -1811,7 +1811,7 @@ void PipeWireCapture::stateChangedCallback(pw_stream_state, pw_stream_state, con void PipeWireCapture::inputCallback() { pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())}; - if(unlikely(!pw_buf)) return; + if(!pw_buf) [[alunlikely]] return; spa_data *bufdata{pw_buf->buffer->datas}; const uint offset{minu(bufdata->chunk->offset, bufdata->maxsize)}; diff --git a/common/alcomplex.cpp b/common/alcomplex.cpp index c08ac751..cce92665 100644 --- a/common/alcomplex.cpp +++ b/common/alcomplex.cpp @@ -101,7 +101,7 @@ complex_fft(const al::span<std::complex<Real>> buffer, const Real sign) */ const size_t log2_size{static_cast<size_t>(al::countr_zero(fftsize))}; - if(unlikely(log2_size >= gBitReverses.size())) + if(log2_size >= gBitReverses.size()) [[alunlikely]] { for(size_t idx{1u};idx < fftsize-1;++idx) { @@ -116,7 +116,7 @@ complex_fft(const al::span<std::complex<Real>> buffer, const Real sign) std::swap(buffer[idx], buffer[revidx]); } } - else for(auto &rev : gBitReverses[log2_size]) + else for(auto &rev : gBitReverses[log2_size]) [[allikely]] std::swap(buffer[rev.first], buffer[rev.second]); /* Iterative form of Danielson-Lanczos lemma */ diff --git a/common/comptr.h b/common/comptr.h index 3dc574e8..83f339ca 100644 --- a/common/comptr.h +++ b/common/comptr.h @@ -44,7 +44,7 @@ public: } ComPtr& operator=(ComPtr&& rhs) { - if(likely(&rhs != this)) + if(&rhs != this) [[allikely]] { if(mPtr) mPtr->Release(); mPtr = std::exchange(rhs.mPtr, nullptr); diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h index 9e206a6b..ba932b95 100644 --- a/common/intrusive_ptr.h +++ b/common/intrusive_ptr.h @@ -18,7 +18,7 @@ public: unsigned int release() noexcept { auto ref = DecrementRef(mRef); - if UNLIKELY(ref == 0) + if(ref == 0) [[alunlikely]] delete static_cast<T*>(this); return ref; } @@ -71,7 +71,7 @@ public: } intrusive_ptr& operator=(intrusive_ptr&& rhs) noexcept { - if(likely(&rhs != this)) + if(&rhs != this) [[allikely]] { if(mPtr) mPtr->release(); mPtr = std::exchange(rhs.mPtr, nullptr); diff --git a/common/opthelpers.h b/common/opthelpers.h index f110303e..5fe455da 100644 --- a/common/opthelpers.h +++ b/common/opthelpers.h @@ -19,41 +19,27 @@ #define force_inline inline #endif -#if defined(__GNUC__) || HAS_BUILTIN(__builtin_expect) -/* likely() optimizes for the case where the condition is true. The condition - * is not required to be true, but it can result in more optimal code for the - * true path at the expense of a less optimal false path. - */ -template<typename T> -force_inline constexpr bool likely(T&& expr) noexcept -{ return __builtin_expect(static_cast<bool>(std::forward<T>(expr)), true); } -/* The opposite of likely(), optimizing for the case where the condition is - * false. - */ -template<typename T> -force_inline constexpr bool unlikely(T&& expr) noexcept -{ return __builtin_expect(static_cast<bool>(std::forward<T>(expr)), false); } - +#if __has_attribute(likely) +#define allikely likely +#define alunlikely unlikely #else - -template<typename T> -force_inline constexpr bool likely(T&& expr) noexcept -{ return static_cast<bool>(std::forward<T>(expr)); } -template<typename T> -force_inline constexpr bool unlikely(T&& expr) noexcept -{ return static_cast<bool>(std::forward<T>(expr)); } +#define allikely +#define alunlikely #endif -#define LIKELY(x) (likely(x)) -#define UNLIKELY(x) (unlikely(x)) -#if HAS_BUILTIN(__builtin_assume) +#define LIKELY(x) (x) [[allikely]] +#define UNLIKELY(x) (x) [[alunlikely]] + /* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes * undefined behavior. It's essentially an assert without actually checking the * condition at run-time, allowing for stronger optimizations than LIKELY. */ +#if HAS_BUILTIN(__builtin_assume) #define ASSUME __builtin_assume #elif defined(_MSC_VER) #define ASSUME __assume +#elif __has_attribute(assume) +#define ASSUME(x) [[assume(x)]] #elif defined(__GNUC__) #define ASSUME(x) do { if(x) break; __builtin_unreachable(); } while(0) #else diff --git a/common/polyphase_resampler.cpp b/common/polyphase_resampler.cpp index bb8f69a4..76723915 100644 --- a/common/polyphase_resampler.cpp +++ b/common/polyphase_resampler.cpp @@ -21,7 +21,7 @@ using uint = unsigned int; */ double Sinc(const double x) { - if(unlikely(std::abs(x) < Epsilon)) + if(std::abs(x) < Epsilon) [[alunlikely]] return 1.0; return std::sin(al::numbers::pi*x) / (al::numbers::pi*x); } @@ -96,7 +96,7 @@ constexpr uint Gcd(uint x, uint y) constexpr uint CalcKaiserOrder(const double rejection, const double transition) { const double w_t{2.0 * al::numbers::pi * transition}; - if LIKELY(rejection > 21.0) + if(rejection > 21.0) [[allikely]] return static_cast<uint>(std::ceil((rejection - 7.95) / (2.285 * w_t))); return static_cast<uint>(std::ceil(5.79 / w_t)); } @@ -104,7 +104,7 @@ constexpr uint CalcKaiserOrder(const double rejection, const double transition) // Calculates the beta value of the Kaiser window. Rejection is in dB. constexpr double CalcKaiserBeta(const double rejection) { - if LIKELY(rejection > 50.0) + if(rejection > 50.0) [[allikely]] return 0.1102 * (rejection - 8.7); if(rejection >= 21.0) return (0.5842 * std::pow(rejection - 21.0, 0.4)) + @@ -171,13 +171,13 @@ void PPhaseResampler::init(const uint srcRate, const uint dstRate) // polyphase filter implementation. void PPhaseResampler::process(const uint inN, const double *in, const uint outN, double *out) { - if UNLIKELY(outN == 0) + if(outN == 0) [[alunlikely]] return; // Handle in-place operation. std::vector<double> workspace; double *work{out}; - if UNLIKELY(work == in) + if(work == in) [[alunlikely]] { workspace.resize(outN); work = workspace.data(); @@ -195,17 +195,17 @@ void PPhaseResampler::process(const uint inN, const double *in, const uint outN, // Only take input when 0 <= j_s < inN. double r{0.0}; - if LIKELY(j_f < m) + if(j_f < m) [[allikely]] { size_t filt_len{(m-j_f+p-1) / p}; - if LIKELY(j_s+1 > inN) + if(j_s+1 > inN) [[allikely]] { size_t skip{std::min<size_t>(j_s+1 - inN, filt_len)}; j_f += p*skip; j_s -= skip; filt_len -= skip; } - if(size_t todo{std::min<size_t>(j_s+1, filt_len)}) + if(size_t todo{std::min<size_t>(j_s+1, filt_len)}) [[allikely]] { do { r += f[j_f] * in[j_s]; diff --git a/core/ambdec.cpp b/core/ambdec.cpp index bcad1b55..8b7467ce 100644 --- a/core/ambdec.cpp +++ b/core/ambdec.cpp @@ -61,7 +61,7 @@ al::optional<std::string> make_error(size_t linenum, const char *fmt, ...) va_start(args, fmt); va_copy(args2, args); const int msglen{std::vsnprintf(&str[plen], str.size()-plen, fmt, args)}; - if(unlikely(msglen >= 0 && static_cast<size_t>(msglen) >= str.size()-plen)) + if(msglen >= 0 && static_cast<size_t>(msglen) >= str.size()-plen) [[alunlikely]] { str.resize(static_cast<size_t>(msglen) + plen + 1u); std::vsnprintf(&str[plen], str.size()-plen, fmt, args2); diff --git a/core/hrtf.cpp b/core/hrtf.cpp index dedd74a3..383d4340 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -405,7 +405,7 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(uint rate, ushort irSize, auto delays_ = reinterpret_cast<ubyte2*>(base + offset); offset += sizeof(delays_[0])*irCount; - if(unlikely(offset != total)) + if(offset != total) throw std::runtime_error{"HrtfStore allocation size mismatch"}; /* Copy input data to storage. */ diff --git a/core/logging.cpp b/core/logging.cpp index 7ee7ff23..ec81764c 100644 --- a/core/logging.cpp +++ b/core/logging.cpp @@ -26,7 +26,7 @@ void al_print(LogLevel level, FILE *logfile, const char *fmt, ...) va_start(args, fmt); va_copy(args2, args); const int msglen{std::vsnprintf(str, sizeof(stcmsg), fmt, args)}; - if(unlikely(msglen >= 0 && static_cast<size_t>(msglen) >= sizeof(stcmsg))) + if(msglen >= 0 && static_cast<size_t>(msglen) >= sizeof(stcmsg)) [[alunlikely]] { dynmsg.resize(static_cast<size_t>(msglen) + 1u); str = dynmsg.data(); @@ -66,7 +66,7 @@ void al_print(LogLevel level, FILE *logfile, const char *fmt, ...) va_start(args, fmt); va_copy(args2, args); const int msglen{std::vsnprintf(str, sizeof(stcmsg), fmt, args)}; - if(unlikely(msglen >= 0 && static_cast<size_t>(msglen) >= sizeof(stcmsg))) + if(msglen >= 0 && static_cast<size_t>(msglen) >= sizeof(stcmsg)) [[alunlikely]] { dynmsg.resize(static_cast<size_t>(msglen) + 1u); str = dynmsg.data(); diff --git a/core/uhjfilter.cpp b/core/uhjfilter.cpp index 5fb529ae..0ee06d06 100644 --- a/core/uhjfilter.cpp +++ b/core/uhjfilter.cpp @@ -140,7 +140,7 @@ void UhjEncoder<N>::encode(float *LeftOut, float *RightOut, float *inout{al::assume_aligned<16>(buffer)}; auto inout_end = inout + SamplesToDo; - if(likely(SamplesToDo >= sFilterDelay)) + if(SamplesToDo >= sFilterDelay) [[allikely]] { auto delay_end = std::rotate(inout, inout_end - sFilterDelay, inout_end); std::swap_ranges(inout, delay_end, distbuf); @@ -409,8 +409,8 @@ void UhjStereoDecoder<N>::decode(const al::span<float*> samples, const size_t sa * interpolate when it changes. */ const float wtarget{mWidthControl}; - const float wcurrent{unlikely(mCurrentWidth < 0.0f) ? wtarget : mCurrentWidth}; - if(likely(wtarget == wcurrent) || unlikely(forwardSamples == 0)) + const float wcurrent{(mCurrentWidth < 0.0f) ? wtarget : mCurrentWidth}; + if(wtarget == wcurrent || forwardSamples == 0) { for(size_t i{0};i < samplesToDo+sInputPadding;++i) mD[i] = (left[i] - right[i]) * wcurrent; @@ -478,8 +478,8 @@ void UhjStereoDecoderIIR::decode(const al::span<float*> samples, const size_t sa * interpolate when it changes. */ const float wtarget{mWidthControl}; - const float wcurrent{unlikely(mCurrentWidth < 0.0f) ? wtarget : mCurrentWidth}; - if(likely(wtarget == wcurrent) || unlikely(forwardSamples == 0)) + const float wcurrent{(mCurrentWidth < 0.0f) ? wtarget : mCurrentWidth}; + if(wtarget == wcurrent || forwardSamples == 0) { for(size_t i{0};i < samplesToDo;++i) mD[i] = (left[i] - right[i]) * wcurrent; diff --git a/core/voice.cpp b/core/voice.cpp index bf13d563..2a524215 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -366,7 +366,7 @@ void DoHrtfMix(const float *samples, const uint DstBufferSize, DirectParams &par std::begin(HrtfSamples)); std::copy_n(samples, DstBufferSize, src_iter); /* Copy the last used samples back into the history buffer for later. */ - if(likely(IsPlaying)) + if(IsPlaying) [[allikely]] std::copy_n(std::begin(HrtfSamples) + DstBufferSize, parms.Hrtf.History.size(), parms.Hrtf.History.begin()); @@ -596,7 +596,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi /* If the voice is stopping, only one mixing iteration will * be done, so ensure it fades out completely this mix. */ - if(unlikely(vstate == Stopping)) + if(vstate == Stopping) [[alunlikely]] Counter = std::min(Counter, DstBufferSize); } ASSUME(DstBufferSize > 0); @@ -604,7 +604,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi } float **voiceSamples{}; - if(unlikely(!BufferListItem)) + if(!BufferListItem) [[alunlikely]] { const size_t srcOffset{(increment*DstBufferSize + DataPosFrac)>>MixerFracBits}; auto prevSamples = mPrevSamples.data(); @@ -639,7 +639,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi } size_t samplesLoaded{0}; - if(unlikely(DataPosInt < 0)) + if(DataPosInt < 0) [[alunlikely]] { if(static_cast<uint>(-DataPosInt) >= SrcBufferSize) goto skip_mix; @@ -684,11 +684,11 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi { SrcBufferSize = SrcBufferSize - PostPadding + MaxResamplerEdge; mDecoder->decode(MixingSamples, SrcBufferSize, - likely(vstate == Playing) ? srcOffset : 0); + (vstate == Playing) ? srcOffset : 0); } /* Store the last source samples used for next time. */ - if(likely(vstate == Playing)) + if(vstate == Playing) [[allikely]] { prevSamples = mPrevSamples.data(); for(auto *chanbuffer : MixingSamples) @@ -721,13 +721,13 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi if(mFlags.test(VoiceHasHrtf)) { - const float TargetGain{parms.Hrtf.Target.Gain * likely(vstate == Playing)}; + const float TargetGain{parms.Hrtf.Target.Gain * (vstate == Playing)}; DoHrtfMix(samples, DstBufferSize, parms, TargetGain, Counter, OutPos, (vstate == Playing), Device); } else { - const float *TargetGains{likely(vstate == Playing) ? parms.Gains.Target.data() + const float *TargetGains{(vstate == Playing) ? parms.Gains.Target.data() : SilentTarget.data()}; if(mFlags.test(VoiceHasNfc)) DoNfcMix({samples, DstBufferSize}, mDirect.Buffer.data(), parms, @@ -747,7 +747,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi const float *samples{DoFilters(parms.LowPass, parms.HighPass, FilterBuf.data(), {ResampledData, DstBufferSize}, mSend[send].FilterType)}; - const float *TargetGains{likely(vstate == Playing) ? parms.Gains.Target.data() + const float *TargetGains{(vstate == Playing) ? parms.Gains.Target.data() : SilentTarget.data()}; MixSamples({samples, DstBufferSize}, mSend[send].Buffer, parms.Gains.Current.data(), TargetGains, Counter, OutPos); @@ -755,7 +755,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi } skip_mix: /* If the voice is stopping, we're now done. */ - if(unlikely(vstate == Stopping)) + if(vstate == Stopping) [[alunlikely]] break; /* Update positions */ @@ -770,7 +770,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi /* Do nothing extra when there's no buffers, or if the voice position * is still negative. */ - if(unlikely(!BufferListItem) || unlikely(DataPosInt < 0)) + if(!BufferListItem || DataPosInt < 0) [[alunlikely]] continue; if(mFlags.test(VoiceIsStatic)) @@ -834,7 +834,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi mFlags.set(VoiceIsFading); /* Don't update positions and buffers if we were stopping. */ - if(unlikely(vstate == Stopping)) + if(vstate == Stopping) [[alunlikely]] { mPlayState.store(Stopped, std::memory_order_release); return; @@ -888,7 +888,7 @@ void Voice::prepare(DeviceBase *device) */ uint num_channels{(mFmtChannels == FmtUHJ2 || mFmtChannels == FmtSuperStereo) ? 3 : ChannelsFromFmt(mFmtChannels, minu(mAmbiOrder, device->mAmbiOrder))}; - if(unlikely(num_channels > device->mSampleData.size())) + if(num_channels > device->mSampleData.size()) [[alunlikely]] { ERR("Unexpected channel count: %u (limit: %zu, %d:%d)\n", num_channels, device->mSampleData.size(), mFmtChannels, mAmbiOrder); |