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

Side by Side Diff: webrtc/common_audio/signal_processing/division_operations.c

Issue 3009123002: Move UBSan warnings from a blacklist to the source (Closed)
Patch Set: Address review comments Created 3 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 11
12 /* 12 /*
13 * This file contains implementations of the divisions 13 * This file contains implementations of the divisions
14 * WebRtcSpl_DivU32U16() 14 * WebRtcSpl_DivU32U16()
15 * WebRtcSpl_DivW32W16() 15 * WebRtcSpl_DivW32W16()
16 * WebRtcSpl_DivW32W16ResW16() 16 * WebRtcSpl_DivW32W16ResW16()
17 * WebRtcSpl_DivResultInQ31() 17 * WebRtcSpl_DivResultInQ31()
18 * WebRtcSpl_DivW32HiLow() 18 * WebRtcSpl_DivW32HiLow()
19 * 19 *
20 * The description header can be found in signal_processing_library.h 20 * The description header can be found in signal_processing_library.h
21 * 21 *
22 */ 22 */
23 23
24 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 24 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
25 #include "webrtc/rtc_base/sanitizer.h"
25 26
26 uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den) 27 uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den)
27 { 28 {
28 // Guard against division with 0 29 // Guard against division with 0
29 if (den != 0) 30 if (den != 0)
30 { 31 {
31 return (uint32_t)(num / den); 32 return (uint32_t)(num / den);
32 } else 33 } else
33 { 34 {
34 return (uint32_t)0xFFFFFFFF; 35 return (uint32_t)0xFFFFFFFF;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 div++; 91 div++;
91 } 92 }
92 } 93 }
93 if (change_sign == 1) 94 if (change_sign == 1)
94 { 95 {
95 div = -div; 96 div = -div;
96 } 97 }
97 return div; 98 return div;
98 } 99 }
99 100
100 int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) 101 int32_t RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486
102 WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
101 { 103 {
102 int16_t approx, tmp_hi, tmp_low, num_hi, num_low; 104 int16_t approx, tmp_hi, tmp_low, num_hi, num_low;
103 int32_t tmpW32; 105 int32_t tmpW32;
104 106
105 approx = (int16_t)WebRtcSpl_DivW32W16((int32_t)0x1FFFFFFF, den_hi); 107 approx = (int16_t)WebRtcSpl_DivW32W16((int32_t)0x1FFFFFFF, den_hi);
106 // result in Q14 (Note: 3FFFFFFF = 0.5 in Q30) 108 // result in Q14 (Note: 3FFFFFFF = 0.5 in Q30)
107 109
108 // tmpW32 = 1/den = approx * (2.0 - den * approx) (in Q30) 110 // tmpW32 = 1/den = approx * (2.0 - den * approx) (in Q30)
109 tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1); 111 tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1);
110 // tmpW32 = den * approx 112 // tmpW32 = den * approx
111 113
112 tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den* approx)) 114 tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den* approx))
115 // UBSan: 2147483647 - -2 cannot be represented in type 'int'
113 116
114 // Store tmpW32 in hi and low format 117 // Store tmpW32 in hi and low format
115 tmp_hi = (int16_t)(tmpW32 >> 16); 118 tmp_hi = (int16_t)(tmpW32 >> 16);
116 tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1); 119 tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1);
117 120
118 // tmpW32 = 1/den in Q29 121 // tmpW32 = 1/den in Q29
119 tmpW32 = (tmp_hi * approx + (tmp_low * approx >> 15)) << 1; 122 tmpW32 = (tmp_hi * approx + (tmp_low * approx >> 15)) << 1;
120 123
121 // 1/den in hi and low format 124 // 1/den in hi and low format
122 tmp_hi = (int16_t)(tmpW32 >> 16); 125 tmp_hi = (int16_t)(tmpW32 >> 16);
123 tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1); 126 tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1);
124 127
125 // Store num in hi and low format 128 // Store num in hi and low format
126 num_hi = (int16_t)(num >> 16); 129 num_hi = (int16_t)(num >> 16);
127 num_low = (int16_t)((num - ((int32_t)num_hi << 16)) >> 1); 130 num_low = (int16_t)((num - ((int32_t)num_hi << 16)) >> 1);
128 131
129 // num * (1/den) by 32 bit multiplication (result in Q28) 132 // num * (1/den) by 32 bit multiplication (result in Q28)
130 133
131 tmpW32 = num_hi * tmp_hi + (num_hi * tmp_low >> 15) + 134 tmpW32 = num_hi * tmp_hi + (num_hi * tmp_low >> 15) +
132 (num_low * tmp_hi >> 15); 135 (num_low * tmp_hi >> 15);
133 136
134 // Put result in Q31 (convert from Q28) 137 // Put result in Q31 (convert from Q28)
135 tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3); 138 tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3);
136 139
137 return tmpW32; 140 return tmpW32;
138 } 141 }
OLDNEW
« no previous file with comments | « tools_webrtc/ubsan/blacklist.txt ('k') | webrtc/common_audio/signal_processing/levinson_durbin.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698