-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some (small) performance helpers
- Loading branch information
1 parent
1ab078f
commit a4f21c2
Showing
3 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef SIGNALSMITH_DSP_PERF_H | ||
#define SIGNALSMITH_DSP_PERF_H | ||
|
||
|
||
namespace signalsmith { | ||
namespace perf { | ||
/** @defgroup Performance Performance helpers | ||
@brief Nothing serious, just some `#defines` and helpers | ||
@{ | ||
@file | ||
*/ | ||
|
||
/// *Really* insist that a function/method is inlined | ||
#ifndef SIGNALSMITH_INLINE | ||
#ifdef __GNUC__ | ||
#define SIGNALSMITH_INLINE __attribute__((always_inline)) inline | ||
#elif defined(__MSVC__) | ||
#define SIGNALSMITH_INLINE __forceinline inline | ||
#else | ||
#define SIGNALSMITH_INLINE inline | ||
#endif | ||
#endif | ||
|
||
/** @brief Complex-multiplication (with optional conjugate second-arg), without handling NaN/Infinity | ||
The `std::complex` multiplication has edge-cases around NaNs which slow things down and prevent auto-vectorisation. | ||
*/ | ||
template <bool conjugateSecond=false, typename V> | ||
static SIGNALSMITH_INLINE std::complex<V> mul(const std::complex<V> &a, const std::complex<V> &b) { | ||
return conjugateSecond ? std::complex<V>{ | ||
b.real()*a.real() + b.imag()*a.imag(), | ||
b.real()*a.imag() - b.imag()*a.real() | ||
} : std::complex<V>{ | ||
a.real()*b.real() - a.imag()*b.imag(), | ||
a.real()*b.imag() + a.imag()*b.real() | ||
}; | ||
} | ||
|
||
/** @} */ | ||
}} // signalsmith::perf:: | ||
|
||
#endif // include guard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters