CMM2: CSUB BitOrderReverse

Author Message
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1102
 Posted: 12:57pm 10 Sep 2020

Hi Chis,

thanks for your attention! Good find!
You are absolutely right, if you don't use pointer indirection, it's faster (~ 15%)!
I need it to convert around 10,000 integers for a project - in a reasonable time (<500ms). I relied on the smartness of the compiler (Note: Never use pointer indirection in large loops!).

Result:
BitOrderReverse Demo

Input:
0010111100101111001011110010111100101111001011110010111100101111
Output:
1111010011110100111101001111010011110100111101001111010011110100
10000 loops:  CSUB          FUNC          Empty      1x CSUB  1x FUNC
206ms         545ms         22ms         18us     52us

#include "ARMCFunctions.h"
// Bitorderreversal for CMM2 v1.01 (thanks to Chris@TBS)
// needs ~18us @400Mhz
// Usage: CSUB BitOrderReverse(nInput, nBits, RetValue)
// CSUB BitOrderReverse integer, integer, integer

void Bitorderreverse(long long *orig, long long *nbits, long long *reversed)
{
int i       = 1;
int n       = *nbits;
long long r = 0;
long long o = *orig;
unsigned long long bit_mask = 1;

for(;i<=n;i++)
{
if ((o & (bit_mask<<(i-1))) > 0)
}
*reversed=r;
}

CSUB Bitorderreverse INTEGER,INTEGER,INTEGER
00000000
'Bitorderreverse
0FF0E92D AF00B090 61396178 230160FA 693B63FB 2300E9D3 62FB4613 0200F04F
0300F04F 230CE9C7 E9D3697B E9C72300 F04F2308 F04F0201 E9C70300 E03E2306
1E596BFB 2306E9D7 0620F1A1 0020F1C1 F501FA03 F606FA02 FA224335 4305F000