kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | /* The global function contained in this file initializes SPL function |
| 12 | * pointers, currently only for ARM platforms. |
| 13 | * |
| 14 | * Some code came from common/rtcd.c in the WebM project. |
| 15 | */ |
| 16 | |
pbos@webrtc.org | aa30bb7 | 2013-05-27 09:49:58 +0000 | [diff] [blame] | 17 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 18 | #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 19 | |
| 20 | /* Declare function pointers. */ |
| 21 | MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16; |
| 22 | MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32; |
| 23 | MaxValueW16 WebRtcSpl_MaxValueW16; |
| 24 | MaxValueW32 WebRtcSpl_MaxValueW32; |
| 25 | MinValueW16 WebRtcSpl_MinValueW16; |
| 26 | MinValueW32 WebRtcSpl_MinValueW32; |
| 27 | CrossCorrelation WebRtcSpl_CrossCorrelation; |
| 28 | DownsampleFast WebRtcSpl_DownsampleFast; |
| 29 | ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound; |
| 30 | |
pasko | e305d95 | 2016-05-17 10:56:40 -0700 | [diff] [blame] | 31 | #if (!defined(WEBRTC_HAS_NEON)) && !defined(MIPS32_LE) |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 32 | /* Initialize function pointers to the generic C version. */ |
| 33 | static void InitPointersToC() { |
| 34 | WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16C; |
| 35 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32C; |
| 36 | WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16C; |
| 37 | WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32C; |
| 38 | WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16C; |
| 39 | WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32C; |
| 40 | WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelationC; |
| 41 | WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFastC; |
| 42 | WebRtcSpl_ScaleAndAddVectorsWithRound = |
| 43 | WebRtcSpl_ScaleAndAddVectorsWithRoundC; |
| 44 | } |
wu@webrtc.org | 7aa1189 | 2012-10-10 20:59:35 +0000 | [diff] [blame] | 45 | #endif |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 46 | |
pasko | e305d95 | 2016-05-17 10:56:40 -0700 | [diff] [blame] | 47 | #if defined(WEBRTC_HAS_NEON) |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 48 | /* Initialize function pointers to the Neon version. */ |
| 49 | static void InitPointersToNeon() { |
| 50 | WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16Neon; |
| 51 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32Neon; |
| 52 | WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16Neon; |
| 53 | WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32Neon; |
| 54 | WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16Neon; |
| 55 | WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32Neon; |
| 56 | WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelationNeon; |
| 57 | WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFastNeon; |
| 58 | WebRtcSpl_ScaleAndAddVectorsWithRound = |
fischman@webrtc.org | 874920f | 2014-04-28 20:09:09 +0000 | [diff] [blame] | 59 | WebRtcSpl_ScaleAndAddVectorsWithRoundC; |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 60 | } |
| 61 | #endif |
| 62 | |
andrew@webrtc.org | 5140e24 | 2013-02-21 20:12:21 +0000 | [diff] [blame] | 63 | #if defined(MIPS32_LE) |
| 64 | /* Initialize function pointers to the MIPS version. */ |
| 65 | static void InitPointersToMIPS() { |
| 66 | WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16_mips; |
| 67 | WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16_mips; |
| 68 | WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32_mips; |
| 69 | WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16_mips; |
| 70 | WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32_mips; |
andrew@webrtc.org | 8bf755d | 2013-09-18 17:40:46 +0000 | [diff] [blame] | 71 | WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelation_mips; |
andrew@webrtc.org | eed919d | 2013-05-30 16:38:36 +0000 | [diff] [blame] | 72 | WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFast_mips; |
andrew@webrtc.org | 5140e24 | 2013-02-21 20:12:21 +0000 | [diff] [blame] | 73 | #if defined(MIPS_DSP_R1_LE) |
| 74 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32_mips; |
andrew@webrtc.org | 8bf755d | 2013-09-18 17:40:46 +0000 | [diff] [blame] | 75 | WebRtcSpl_ScaleAndAddVectorsWithRound = |
| 76 | WebRtcSpl_ScaleAndAddVectorsWithRound_mips; |
andrew@webrtc.org | 5140e24 | 2013-02-21 20:12:21 +0000 | [diff] [blame] | 77 | #else |
| 78 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32C; |
andrew@webrtc.org | 8bf755d | 2013-09-18 17:40:46 +0000 | [diff] [blame] | 79 | WebRtcSpl_ScaleAndAddVectorsWithRound = |
| 80 | WebRtcSpl_ScaleAndAddVectorsWithRoundC; |
andrew@webrtc.org | 5140e24 | 2013-02-21 20:12:21 +0000 | [diff] [blame] | 81 | #endif |
| 82 | } |
| 83 | #endif |
| 84 | |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 85 | static void InitFunctionPointers(void) { |
pasko | e305d95 | 2016-05-17 10:56:40 -0700 | [diff] [blame] | 86 | #if defined(WEBRTC_HAS_NEON) |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 87 | InitPointersToNeon(); |
andrew@webrtc.org | 5140e24 | 2013-02-21 20:12:21 +0000 | [diff] [blame] | 88 | #elif defined(MIPS32_LE) |
| 89 | InitPointersToMIPS(); |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 90 | #else |
| 91 | InitPointersToC(); |
pasko | e305d95 | 2016-05-17 10:56:40 -0700 | [diff] [blame] | 92 | #endif /* WEBRTC_HAS_NEON */ |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 93 | } |
| 94 | |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 95 | #if defined(WEBRTC_POSIX) |
| 96 | #include <pthread.h> |
| 97 | |
| 98 | static void once(void (*func)(void)) { |
| 99 | static pthread_once_t lock = PTHREAD_ONCE_INIT; |
| 100 | pthread_once(&lock, func); |
| 101 | } |
| 102 | |
| 103 | #elif defined(_WIN32) |
| 104 | #include <windows.h> |
| 105 | |
| 106 | static void once(void (*func)(void)) { |
| 107 | /* Didn't use InitializeCriticalSection() since there's no race-free context |
| 108 | * in which to execute it. |
| 109 | * |
| 110 | * TODO(kma): Change to different implementation (e.g. |
| 111 | * InterlockedCompareExchangePointer) to avoid issues similar to |
| 112 | * http://code.google.com/p/webm/issues/detail?id=467. |
| 113 | */ |
andrew@webrtc.org | 63e0964 | 2013-01-29 06:45:22 +0000 | [diff] [blame] | 114 | static CRITICAL_SECTION lock = {(void *)((size_t)-1), -1, 0, 0, 0, 0}; |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 115 | static int done = 0; |
| 116 | |
| 117 | EnterCriticalSection(&lock); |
| 118 | if (!done) { |
| 119 | func(); |
| 120 | done = 1; |
| 121 | } |
| 122 | LeaveCriticalSection(&lock); |
| 123 | } |
| 124 | |
| 125 | /* There's no fallback version as an #else block here to ensure thread safety. |
| 126 | * In case of neither pthread for WEBRTC_POSIX nor _WIN32 is present, build |
| 127 | * system should pick it up. |
| 128 | */ |
| 129 | #endif /* WEBRTC_POSIX */ |
| 130 | |
| 131 | void WebRtcSpl_Init() { |
| 132 | once(InitFunctionPointers); |
| 133 | } |