Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Unified Diff: webrtc/modules/audio_processing/agc/legacy/digital_agc.c

Issue 2003623003: Re-enable UBsan on AGC. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/agc/legacy/digital_agc.c
diff --git a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c
index 2ca967a4aae1a0d0a00758b4861a4838b1d11d46..8ad91278b0840e57a9ded287ef517e51f1d9fd25 100644
--- a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c
+++ b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c
@@ -187,14 +187,12 @@ int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16
numFIX -= (int32_t)logApprox * diffGain; // Q14
// Calculate ratio
- // Shift |numFIX| as much as possible.
- // Ensure we avoid wrap-around in |den| as well.
- if (numFIX > (den >> 8)) // |den| is Q8.
minyue-webrtc 2016/05/21 12:33:37 Two problems were with this part 1. if |numFIX| i
- {
- zeros = WebRtcSpl_NormW32(numFIX);
- } else {
- zeros = WebRtcSpl_NormW32(den) + 8;
- }
+ // 1) Shift |numFIX| as much as possible. Since we later add |den| / 2 to
+ // |numFIX| before dividing |den| to round the ratio, we use |numFIX| *2 to
+ // calculate the bit for shifting.
+ // 2) Ensure we avoid wrap-around in |den| as well.
+ zeros = WEBRTC_SPL_MIN(WebRtcSpl_NormW32(numFIX * 2),
peah-webrtc 2016/05/23 04:59:37 The norm computation is on some platforms fairly c
peah-webrtc 2016/05/23 04:59:37 How do you know that numFIX * 2 does not overflow?
minyue-webrtc 2016/05/23 07:40:48 Good question, after a second thought, I see that
+ WebRtcSpl_NormW32(den) + 8);
numFIX *= 1 << zeros; // Q(14+zeros)
// Shift den so we end up in Qy1

Powered by Google App Engine
This is Rietveld 408576698