1 #ifndef MHO_BitReversalPermutation_HH__
2 #define MHO_BitReversalPermutation_HH__
6 #define USE_STDALGO_SWAP
8 #ifdef USE_STDALGO_SWAP
54 static unsigned int LogBaseTwo(
unsigned int N);
103 static unsigned int LogBaseB(
unsigned int N,
unsigned int B);
123 template<
typename DataType >
124 static void PermuteArray(
unsigned int N,
const unsigned int* permutation_index_arr, DataType* arr)
128 for(
unsigned int i = 0; i < N; i++)
130 unsigned int perm = permutation_index_arr[i];
134 #ifdef USE_STDALGO_SWAP
135 std::swap(arr[i], arr[perm]);
155 template<
typename DataType >
156 static void PermuteArray(
unsigned int N,
const unsigned int* permutation_index_arr, DataType* arr,
unsigned int stride)
160 for(
unsigned int i = 0; i < N; i++)
162 unsigned int perm = permutation_index_arr[i];
166 #ifdef USE_STDALGO_SWAP
167 std::swap(arr[i * stride], arr[perm * stride]);
169 val = arr[i * stride];
170 arr[i * stride] = arr[perm * stride];
171 arr[perm * stride] = val;
189 template<
typename DataType >
195 typename DataType::value_type do_swap;
196 typename DataType::value_type sgn;
197 for(
unsigned int i = 0; i < N; i++)
199 perm = permutation_index_arr[i];
200 do_swap = (i < perm);
201 sgn = (i < perm) - (i >= perm);
206 b = do_swap * a - sgn * b;
226 template<
typename DataType >
233 typename DataType::value_type do_swap;
234 typename DataType::value_type sgn;
235 for(
unsigned int i = 0; i < N; i++)
238 perm = permutation_index_arr[i];
239 do_swap = (i < perm);
240 sgn = (i < perm) - (i >= perm);
242 b = arr[perm * stride];
245 b = do_swap * a - sgn * b;
249 arr[perm * stride] = b;
bit reversal permutation function for power-of-two FFTs
Definition: MHO_BitReversalPermutation.hh:24
static unsigned int RaiseBaseToThePower(unsigned int B, unsigned int N)
Calculates B raised to the power N.
Definition: MHO_BitReversalPermutation.cc:82
MHO_BitReversalPermutation()
Definition: MHO_BitReversalPermutation.hh:26
static void ComputeBitReversedIndicesBaseTwo(unsigned int N, unsigned int *index_arr)
Computes bit-reversed indices using Buneman algorithm for input N, must have N = 2^P,...
Definition: MHO_BitReversalPermutation.cc:119
static unsigned int NextLowestPowerOfTwo(unsigned int N)
Calculates the next lowest power of two for a given unsigned integer.
Definition: MHO_BitReversalPermutation.cc:35
static unsigned int ReverseIndexBits(unsigned int nbits, unsigned int x)
Reverses the bit indices of a given unsigned integer.
Definition: MHO_BitReversalPermutation.cc:50
static void PermuteArrayBranchFree(unsigned int N, const unsigned int *permutation_index_arr, DataType *arr)
Function PermuteArrayBranchFree non-strided data access pattern branch free (this is actually slower ...
Definition: MHO_BitReversalPermutation.hh:190
virtual ~MHO_BitReversalPermutation()
Definition: MHO_BitReversalPermutation.hh:27
static void PermuteArray(unsigned int N, const unsigned int *permutation_index_arr, DataType *arr, unsigned int stride)
Permutes a DataType array using an index permutation (strided data access version)
Definition: MHO_BitReversalPermutation.hh:156
static bool IsPowerOfBase(unsigned int N, unsigned int B)
Checks if an unsigned integer N is a perfect power of another unsigned integer B.
Definition: MHO_BitReversalPermutation.cc:60
static void PermuteArray(unsigned int N, const unsigned int *permutation_index_arr, DataType *arr)
Permutes an array using a given permutation index array (non-strided data access pattern).
Definition: MHO_BitReversalPermutation.hh:124
static unsigned int TwoToThePowerOf(unsigned int N)
Calculates 2 raised to the power of N using bit shifting.
Definition: MHO_BitReversalPermutation.cc:29
static unsigned int LogBaseB(unsigned int N, unsigned int B)
Calculates the logarithm base B of N, assuming N is a perfect power of B.
Definition: MHO_BitReversalPermutation.cc:92
static bool IsPowerOfTwo(unsigned int N)
Checks if an unsigned integer is a power of two.
Definition: MHO_BitReversalPermutation.cc:10
static void PermuteArrayBranchFree(unsigned int N, const unsigned int *permutation_index_arr, DataType *arr, unsigned int stride)
Function PermuteArrayBranchFree strided data access version branch free (this is actually slower on C...
Definition: MHO_BitReversalPermutation.hh:227
static unsigned int LogBaseTwo(unsigned int N)
Calculates the logarithm base two of an unsigned integer N using bitwise operations.
Definition: MHO_BitReversalPermutation.cc:17
Definition: MHO_ChannelLabeler.hh:17