Merge pull request #3026 from lioncash/constexpr

MathUtil: Make Clamp and IsPow2 constexpr functions.
This commit is contained in:
Ryan Houdek
2015-09-12 02:28:38 -04:00
14 changed files with 46 additions and 70 deletions

View File

@ -36,8 +36,7 @@ static s16 ADPCM_Step(u32& _rSamplePos)
// 0x400 = 0.5 in 11-bit fixed point
int val = (scale * temp) + ((0x400 + coef1 * (s16)g_dsp.ifx_regs[DSP_YN1] + coef2 * (s16)g_dsp.ifx_regs[DSP_YN2]) >> 11);
MathUtil::Clamp(&val, -0x7FFF, 0x7FFF);
val = MathUtil::Clamp(val, -0x7FFF, 0x7FFF);
g_dsp.ifx_regs[DSP_YN2] = g_dsp.ifx_regs[DSP_YN1];
g_dsp.ifx_regs[DSP_YN1] = val;

View File

@ -503,11 +503,8 @@ void AXUCode::OutputSamples(u32 lr_addr, u32 surround_addr)
// Output samples clamped to 16 bits and interlaced RLRLRLRLRL...
for (u32 i = 0; i < 5 * 32; ++i)
{
int left = m_samples_left[i];
int right = m_samples_right[i];
MathUtil::Clamp(&left, -32767, 32767);
MathUtil::Clamp(&right, -32767, 32767);
int left = MathUtil::Clamp(m_samples_left[i], -32767, 32767);
int right = MathUtil::Clamp(m_samples_right[i], -32767, 32767);
buffer[2 * i + 0] = Common::swap16(right);
buffer[2 * i + 1] = Common::swap16(left);

View File

@ -185,7 +185,7 @@ u16 AcceleratorGetSample()
temp -= 16;
int val = (scale * temp) + ((0x400 + coef1 * acc_pb->adpcm.yn1 + coef2 * acc_pb->adpcm.yn2) >> 11);
MathUtil::Clamp(&val, -0x7FFF, 0x7FFF);
val = MathUtil::Clamp(val, -0x7FFF, 0x7FFF);
acc_pb->adpcm.yn2 = acc_pb->adpcm.yn1;
acc_pb->adpcm.yn1 = val;

View File

@ -618,11 +618,8 @@ void AXWiiUCode::OutputSamples(u32 lr_addr, u32 surround_addr, u16 volume,
left = ((s64)left * volume_ramp[i]) >> 15;
right = ((s64)right * volume_ramp[i]) >> 15;
MathUtil::Clamp(&left, -32767, 32767);
MathUtil::Clamp(&right, -32767, 32767);
m_samples_left[i] = left;
m_samples_right[i] = right;
m_samples_left[i] = MathUtil::Clamp(left, -32767, 32767);
m_samples_right[i] = MathUtil::Clamp(right, -32767, 32767);
}
for (u32 i = 0; i < 3 * 32; ++i)
@ -653,8 +650,7 @@ void AXWiiUCode::OutputWMSamples(u32* addresses)
u16* out = (u16*)HLEMemory_Get_Pointer(addresses[i]);
for (u32 j = 0; j < 3 * 6; ++j)
{
int sample = in[j];
MathUtil::Clamp(&sample, -32767, 32767);
int sample = MathUtil::Clamp(in[j], -32767, 32767);
out[j] = Common::swap16((u16)sample);
}
}

View File

@ -1015,8 +1015,7 @@ void ZeldaAudioRenderer::ApplyReverb(bool post_rendering)
for (u16 j = 0; j < 8; ++j)
sample += (s32)buffer[i + j] * rpb.filter_coeffs[j];
sample >>= 15;
MathUtil::Clamp(&sample, -0x8000, 0x7fff);
buffer[i] = sample;
buffer[i] = MathUtil::Clamp(sample, -0x8000, 0x7FFF);
}
};
@ -1445,8 +1444,8 @@ void ZeldaAudioRenderer::Resample(VPB* vpb, const s16* src, MixingBuffer* dst)
for (size_t i = 0; i < 4; ++i)
dst_sample_unclamped += (s64)2 * coeffs[i] * input[i];
dst_sample_unclamped >>= 16;
MathUtil::Clamp(&dst_sample_unclamped, (s64)-0x8000, (s64)0x7fff);
dst_sample = (s16)dst_sample_unclamped;
dst_sample = (s16)MathUtil::Clamp<s64>(dst_sample_unclamped, -0x8000, 0x7FFF);
pos += ratio;
}
@ -1696,7 +1695,7 @@ void ZeldaAudioRenderer::DecodeAFC(VPB* vpb, s16* dst, size_t block_count)
yn1 * m_afc_coeffs[idx * 2] +
yn2 * m_afc_coeffs[idx * 2 + 1];
sample >>= 11;
MathUtil::Clamp(&sample, -0x8000, 0x7fff);
sample = MathUtil::Clamp(sample, -0x8000, 0x7fff);
*dst++ = (s16)sample;
yn2 = yn1;
yn1 = sample;

View File

@ -46,8 +46,8 @@ private:
{
s32 tmp = (u32)(*buf)[i] * (u32)vol;
tmp >>= 16 - B;
MathUtil::Clamp(&tmp, -0x8000, 0x7fff);
(*buf)[i] = (s16)tmp;
(*buf)[i] = (s16)MathUtil::Clamp(tmp, -0x8000, 0x7FFF);
}
}
template <size_t N>
@ -90,8 +90,7 @@ private:
while (count--)
{
s32 vol_src = ((s32)*src++ * (s32)vol) >> 15;
MathUtil::Clamp(&vol_src, -0x8000, 0x7fff);
*dst++ += vol_src;
*dst++ += MathUtil::Clamp(vol_src, -0x8000, 0x7FFF);
}
}

View File

@ -31,8 +31,7 @@ static s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2)
hist = (hist1 * 0x62) - (hist2 * 0x37);
break;
}
hist = (hist + 0x20) >> 6;
MathUtil::Clamp(&hist, -0x200000, 0x1fffff);
hist = MathUtil::Clamp((hist + 0x20) >> 6, -0x200000, 0x1fffff);
s32 cur = (((s16)(bits << 12) >> (q & 0xf)) << 6) + hist;
@ -40,7 +39,7 @@ static s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2)
hist1 = cur;
cur >>= 6;
MathUtil::Clamp(&cur, -0x8000, 0x7fff);
cur = MathUtil::Clamp(cur, -0x8000, 0x7fff);
return (s16)cur;
}

View File

@ -53,8 +53,8 @@ template<typename SType> SType ScaleAndClamp(double ps, u32 stScale)
float convPS = (float)ps * m_quantizeTable[stScale];
float min = (float)std::numeric_limits<SType>::min();
float max = (float)std::numeric_limits<SType>::max();
MathUtil::Clamp(&convPS, min, max);
return (SType)convPS;
return (SType)MathUtil::Clamp(convPS, min, max);
}
template<typename T> static T ReadUnpaired(u32 addr);

View File

@ -924,7 +924,7 @@ void Jit64::MultiplyImmediate(u32 imm, int a, int d, bool overflow)
if (!overflow)
{
// power of 2; just a shift
if (IsPow2(imm))
if (MathUtil::IsPow2(imm))
{
u32 shift = IntLog2(imm);
// use LEA if it saves an op