30 const void*
src,
size_t srcSize)
34 unsigned maxSymbolValue = *maxSymbolValuePtr;
35 unsigned largestCount=0;
38 if (srcSize==0) { *maxSymbolValuePtr = 0;
return 0; }
45 while (!
count[maxSymbolValue]) maxSymbolValue--;
46 *maxSymbolValuePtr = maxSymbolValue;
49 for (
s=0;
s<=maxSymbolValue;
s++)
67 unsigned*
count,
unsigned* maxSymbolValuePtr,
68 const void*
source,
size_t sourceSize,
73 const BYTE*
const iend =
ip+sourceSize;
74 unsigned maxSymbolValue = *maxSymbolValuePtr;
76 U32*
const Counting1 = workSpace;
77 U32*
const Counting2 = Counting1 + 256;
78 U32*
const Counting3 = Counting2 + 256;
79 U32*
const Counting4 = Counting3 + 256;
81 memset(workSpace, 0, 4*256*
sizeof(
unsigned));
86 *maxSymbolValuePtr = 0;
89 if (!maxSymbolValue) maxSymbolValue = 255;
93 while (
ip < iend-15) {
95 Counting1[(
BYTE)
c ]++;
96 Counting2[(
BYTE)(
c>>8) ]++;
97 Counting3[(
BYTE)(
c>>16)]++;
100 Counting1[(
BYTE)
c ]++;
101 Counting2[(
BYTE)(
c>>8) ]++;
102 Counting3[(
BYTE)(
c>>16)]++;
103 Counting4[
c>>24 ]++;
105 Counting1[(
BYTE)
c ]++;
106 Counting2[(
BYTE)(
c>>8) ]++;
107 Counting3[(
BYTE)(
c>>16)]++;
108 Counting4[
c>>24 ]++;
110 Counting1[(
BYTE)
c ]++;
111 Counting2[(
BYTE)(
c>>8) ]++;
112 Counting3[(
BYTE)(
c>>16)]++;
113 Counting4[
c>>24 ]++;
119 while (
ip<iend) Counting1[*
ip++]++;
122 U32 s;
for (
s=255;
s>maxSymbolValue;
s--) {
123 Counting1[
s] += Counting2[
s] + Counting3[
s] + Counting4[
s];
124 if (Counting1[
s])
return ERROR(maxSymbolValue_tooSmall);
128 if (maxSymbolValue > 255) maxSymbolValue = 255;
129 for (
s=0;
s<=maxSymbolValue;
s++) {
130 count[
s] = Counting1[
s] + Counting2[
s] + Counting3[
s] + Counting4[
s];
134 while (!
count[maxSymbolValue]) maxSymbolValue--;
135 *maxSymbolValuePtr = maxSymbolValue;
145 const void*
source,
size_t sourceSize,
146 void* workSpace,
size_t workSpaceSize)
148 if (sourceSize < 1500)
150 if ((
size_t)workSpace & 3)
return ERROR(GENERIC);
157 const void*
source,
size_t sourceSize)
167 const void*
source,
size_t sourceSize,
168 void* workSpace,
size_t workSpaceSize)
170 if ((
size_t)workSpace & 3)
return ERROR(GENERIC);
172 if (*maxSymbolValuePtr < 255)
174 *maxSymbolValuePtr = 255;
179 const void*
src,
size_t srcSize)
#define check(expected, result)
MEM_STATIC U32 MEM_read32(const void *memPtr)
ERR_STATIC unsigned ERR_isError(size_t code)
GLuint GLuint GLsizei count
size_t HIST_countFast(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize)
size_t HIST_count_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, void *workSpace, size_t workSpaceSize)
static size_t HIST_count_parallel_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, HIST_checkInput_e check, U32 *const workSpace)
size_t HIST_count(unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize)
size_t HIST_countFast_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, void *workSpace, size_t workSpaceSize)
unsigned HIST_isError(size_t code)
unsigned HIST_count_simple(unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize)
#define HIST_WKSP_SIZE_U32