Use the standard CC_LIKELY and CC_UNLIKELY macros
Several source files privately defined macros LIKELY and UNLIKELY in terms
of __builtin_expect. But <cutils/compiler.h> already has CC_LIKELY and
CC_UNLIKELY which are intended for this purpose. So rename the private
uses to use the standard names.
In addition, AudioFlinger was relying on the macro expanding to extra ( ).
Change-Id: I2494e087a0c0cac0ac998335f5e9c8ad02955873
diff --git a/media/libeffects/testlibs/AudioBiquadFilter.cpp b/media/libeffects/testlibs/AudioBiquadFilter.cpp
index 72917a3..16dd1c5 100644
--- a/media/libeffects/testlibs/AudioBiquadFilter.cpp
+++ b/media/libeffects/testlibs/AudioBiquadFilter.cpp
@@ -17,12 +17,10 @@
#include <string.h>
#include <assert.h>
+#include <cutils/compiler.h>
#include "AudioBiquadFilter.h"
-#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
-#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
-
namespace android {
const audio_coef_t AudioBiquadFilter::IDENTITY_COEFS[AudioBiquadFilter::NUM_COEFS] = { AUDIO_COEF_ONE, 0, 0, 0, 0 };
@@ -55,7 +53,7 @@
void AudioBiquadFilter::setCoefs(const audio_coef_t coefs[NUM_COEFS], bool immediate) {
memcpy(mTargetCoefs, coefs, sizeof(mTargetCoefs));
if (mState & STATE_ENABLED_MASK) {
- if (UNLIKELY(immediate)) {
+ if (CC_UNLIKELY(immediate)) {
memcpy(mCoefs, coefs, sizeof(mCoefs));
setState(STATE_NORMAL);
} else {
@@ -70,7 +68,7 @@
}
void AudioBiquadFilter::enable(bool immediate) {
- if (UNLIKELY(immediate)) {
+ if (CC_UNLIKELY(immediate)) {
memcpy(mCoefs, mTargetCoefs, sizeof(mCoefs));
setState(STATE_NORMAL);
} else {
@@ -79,7 +77,7 @@
}
void AudioBiquadFilter::disable(bool immediate) {
- if (UNLIKELY(immediate)) {
+ if (CC_UNLIKELY(immediate)) {
memcpy(mCoefs, IDENTITY_COEFS, sizeof(mCoefs));
setState(STATE_BYPASS);
} else {
@@ -142,7 +140,7 @@
audio_sample_t * out,
int frameCount) {
// The common case is in-place processing, because this is what the EQ does.
- if (UNLIKELY(in != out)) {
+ if (CC_UNLIKELY(in != out)) {
memcpy(out, in, frameCount * mNumChannels * sizeof(audio_sample_t));
}
}
diff --git a/media/libeffects/testlibs/AudioCoefInterpolator.cpp b/media/libeffects/testlibs/AudioCoefInterpolator.cpp
index 039ab9f..6b56922 100644
--- a/media/libeffects/testlibs/AudioCoefInterpolator.cpp
+++ b/media/libeffects/testlibs/AudioCoefInterpolator.cpp
@@ -16,10 +16,10 @@
*/
#include <string.h>
-#include "AudioCoefInterpolator.h"
-#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
-#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
+#include <cutils/compiler.h>
+
+#include "AudioCoefInterpolator.h"
namespace android {
@@ -44,9 +44,9 @@
size_t index = 0;
size_t dim = mNumInDims;
while (dim-- > 0) {
- if (UNLIKELY(intCoord[dim] < 0)) {
+ if (CC_UNLIKELY(intCoord[dim] < 0)) {
fracCoord[dim] = 0;
- } else if (UNLIKELY(intCoord[dim] >= (int)mInDims[dim] - 1)) {
+ } else if (CC_UNLIKELY(intCoord[dim] >= (int)mInDims[dim] - 1)) {
fracCoord[dim] = 0;
index += mInDimOffsets[dim] * (mInDims[dim] - 1);
} else {
@@ -63,7 +63,7 @@
memcpy(out, mTable + index, mNumOutDims * sizeof(audio_coef_t));
} else {
getCoefRecurse(index, fracCoord, out, dim + 1);
- if (LIKELY(fracCoord != 0)) {
+ if (CC_LIKELY(fracCoord != 0)) {
audio_coef_t tempCoef[MAX_OUT_DIMS];
getCoefRecurse(index + mInDimOffsets[dim], fracCoord, tempCoef,
dim + 1);
diff --git a/media/libeffects/testlibs/AudioCommon.h b/media/libeffects/testlibs/AudioCommon.h
index 444f93a..e8080dc 100644
--- a/media/libeffects/testlibs/AudioCommon.h
+++ b/media/libeffects/testlibs/AudioCommon.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <stddef.h>
+#include <cutils/compiler.h>
namespace android {
@@ -76,9 +77,9 @@
// Convert a audio_sample_t sample to S15 (with clipping)
inline int16_t audio_sample_t_to_s15_clip(audio_sample_t sample) {
// TODO: optimize for targets supporting this as an atomic operation.
- if (__builtin_expect(sample >= (0x7FFF << 9), 0)) {
+ if (CC_UNLIKELY(sample >= (0x7FFF << 9))) {
return 0x7FFF;
- } else if (__builtin_expect(sample <= -(0x8000 << 9), 0)) {
+ } else if (CC_UNLIKELY(sample <= -(0x8000 << 9))) {
return 0x8000;
} else {
return audio_sample_t_to_s15(sample);
diff --git a/media/libeffects/testlibs/AudioPeakingFilter.cpp b/media/libeffects/testlibs/AudioPeakingFilter.cpp
index 60fefe6..99323ac 100644
--- a/media/libeffects/testlibs/AudioPeakingFilter.cpp
+++ b/media/libeffects/testlibs/AudioPeakingFilter.cpp
@@ -21,9 +21,7 @@
#include <new>
#include <assert.h>
-
-#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
-#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
+#include <cutils/compiler.h>
namespace android {
// Format of the coefficient table:
@@ -66,12 +64,12 @@
void AudioPeakingFilter::setFrequency(uint32_t millihertz) {
mNominalFrequency = millihertz;
- if (UNLIKELY(millihertz > mNiquistFreq / 2)) {
+ if (CC_UNLIKELY(millihertz > mNiquistFreq / 2)) {
millihertz = mNiquistFreq / 2;
}
uint32_t normFreq = static_cast<uint32_t>(
(static_cast<uint64_t>(millihertz) * mFrequencyFactor) >> 10);
- if (LIKELY(normFreq > (1 << 23))) {
+ if (CC_LIKELY(normFreq > (1 << 23))) {
mFrequency = (Effects_log2(normFreq) - ((32-9) << 15)) << (FREQ_PRECISION_BITS - 15);
} else {
mFrequency = 0;
@@ -107,11 +105,11 @@
int32_t halfBW = (((mBandwidth + 1) / 2) << 15) / 1200;
low = static_cast<uint32_t>((static_cast<uint64_t>(mNominalFrequency) * Effects_exp2(-halfBW + (16 << 15))) >> 16);
- if (UNLIKELY(halfBW >= (16 << 15))) {
+ if (CC_UNLIKELY(halfBW >= (16 << 15))) {
high = mNiquistFreq;
} else {
high = static_cast<uint32_t>((static_cast<uint64_t>(mNominalFrequency) * Effects_exp2(halfBW + (16 << 15))) >> 16);
- if (UNLIKELY(high > mNiquistFreq)) {
+ if (CC_UNLIKELY(high > mNiquistFreq)) {
high = mNiquistFreq;
}
}
diff --git a/media/libeffects/testlibs/AudioShelvingFilter.cpp b/media/libeffects/testlibs/AudioShelvingFilter.cpp
index b8650ba..e031287 100644
--- a/media/libeffects/testlibs/AudioShelvingFilter.cpp
+++ b/media/libeffects/testlibs/AudioShelvingFilter.cpp
@@ -21,9 +21,7 @@
#include <new>
#include <assert.h>
-
-#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
-#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
+#include <cutils/compiler.h>
namespace android {
// Format of the coefficient tables:
@@ -71,13 +69,13 @@
void AudioShelvingFilter::setFrequency(uint32_t millihertz) {
mNominalFrequency = millihertz;
- if (UNLIKELY(millihertz > mNiquistFreq / 2)) {
+ if (CC_UNLIKELY(millihertz > mNiquistFreq / 2)) {
millihertz = mNiquistFreq / 2;
}
uint32_t normFreq = static_cast<uint32_t>(
(static_cast<uint64_t>(millihertz) * mFrequencyFactor) >> 10);
uint32_t log2minFreq = (mType == kLowShelf ? (32-10) : (32-2));
- if (LIKELY(normFreq > (1U << log2minFreq))) {
+ if (CC_LIKELY(normFreq > (1U << log2minFreq))) {
mFrequency = (Effects_log2(normFreq) - (log2minFreq << 15)) << (FREQ_PRECISION_BITS - 15);
} else {
mFrequency = 0;
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 1d8e15b..dd1c6a5 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -39,9 +39,7 @@
#include <system/audio.h>
#include <cutils/bitops.h>
-
-#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
-#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
+#include <cutils/compiler.h>
namespace android {
// ---------------------------------------------------------------------------
@@ -513,11 +511,11 @@
goto start_loop_here;
while (framesReady == 0) {
active = mActive;
- if (UNLIKELY(!active)) {
+ if (CC_UNLIKELY(!active)) {
cblk->lock.unlock();
return NO_MORE_BUFFERS;
}
- if (UNLIKELY(!waitCount)) {
+ if (CC_UNLIKELY(!waitCount)) {
cblk->lock.unlock();
return WOULD_BLOCK;
}
@@ -534,7 +532,7 @@
if (cblk->flags & CBLK_INVALID_MSK) {
goto create_new_record;
}
- if (__builtin_expect(result!=NO_ERROR, false)) {
+ if (CC_UNLIKELY(result != NO_ERROR)) {
cblk->waitTimeMs += waitTimeMs;
if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
LOGW( "obtainBuffer timed out (is the CPU pegged?) "
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 6868d99..e0c6ca5 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -38,13 +38,11 @@
#include <utils/Atomic.h>
#include <cutils/bitops.h>
+#include <cutils/compiler.h>
#include <system/audio.h>
#include <system/audio_policy.h>
-#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
-#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
-
namespace android {
// ---------------------------------------------------------------------------
@@ -856,12 +854,12 @@
goto start_loop_here;
while (framesAvail == 0) {
active = mActive;
- if (UNLIKELY(!active)) {
+ if (CC_UNLIKELY(!active)) {
ALOGV("Not active and NO_MORE_BUFFERS");
cblk->lock.unlock();
return NO_MORE_BUFFERS;
}
- if (UNLIKELY(!waitCount)) {
+ if (CC_UNLIKELY(!waitCount)) {
cblk->lock.unlock();
return WOULD_BLOCK;
}
@@ -879,7 +877,7 @@
if (cblk->flags & CBLK_INVALID_MSK) {
goto create_new_track;
}
- if (__builtin_expect(result!=NO_ERROR, false)) {
+ if (CC_UNLIKELY(result != NO_ERROR)) {
cblk->waitTimeMs += waitTimeMs;
if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
// timing out when a loop has been set and we have already written upto loop end