1/*
2 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11
12/*
13 * This file contains the function WebRtcSpl_AddSatW32().
14 * The description header can be found in signal_processing_library.h
15 *
16 */
17
18#include "signal_processing_library.h"
19
20#ifndef SPL_NO_DOUBLE_IMPLEMENTATIONS
21
22WebRtc_Word32 WebRtcSpl_AddSatW32(WebRtc_Word32 var1, WebRtc_Word32 var2)
23{
24    WebRtc_Word32 l_sum;
25
26    // perform long addition
27    l_sum = var1 + var2;
28
29    // check for under or overflow
30    if (WEBRTC_SPL_IS_NEG(var1))
31    {
32        if (WEBRTC_SPL_IS_NEG(var2) && !WEBRTC_SPL_IS_NEG(l_sum))
33        {
34            l_sum = (WebRtc_Word32)0x80000000;
35        }
36    } else
37    {
38        if (!WEBRTC_SPL_IS_NEG(var2) && WEBRTC_SPL_IS_NEG(l_sum))
39        {
40            l_sum = (WebRtc_Word32)0x7FFFFFFF;
41        }
42    }
43
44    return l_sum;
45}
46
47#endif
48