Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created August 3, 2011 05:18
Show Gist options
  • Save chadbrewbaker/1121956 to your computer and use it in GitHub Desktop.
Save chadbrewbaker/1121956 to your computer and use it in GitHub Desktop.
32 bit 11 radix histogram
//Simple radix histogram
//
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#define HIST_SIZE 2048
#define _0(v) ((v) & 0x7FF)
#define _1(v) (((v) >> 11) & 0x7FF)
#define _2(v) (((v) >> 22) & 0x7FF)
template <class T>
void run_test32_11(T* a, T* b0, size_t sz){
T* dest;
size_t j;
size_t pos;
size_t n, sum0=0,sum1=0,sum2=0,tsum=0;
T *b1, *b2;
b1 = b0 + HIST_SIZE;
b2 = b1 + HIST_SIZE;
memset(b0,0,3 * HIST_SIZE*sizeof(T));
for (n=0; n < sz; n++) {
b0[_0(a[n])]++;
b1[_1(a[n])]++;
b2[_2(a[n])]++;
}
return;
};
int main(){
int i;
size_t sz = 10000000;
uint32_t* a;
uint32_t* b0;
a = (uint32_t*)malloc(sizeof(uint32_t)*sz);
b0 = (uint32_t*) malloc(HIST_SIZE * 3 * sizeof(uint32_t));
for(i=0;i<40;i++){
run_test32_11<uint32_t>(a, b0, sz);
}
free(a);
free(b0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment