10 void *m_RefPointA, *m_RefPointB;
13 static inline int IsSignedIntConstrained(
int value,
int bits)
15 int mask = -1 << bits;
16 int refVal = ~(((value >> (bits - 1)) & 1) - 1);
17 return (value & mask) == (refVal & mask);
20 static inline int IsUnsignedIntConstrained(
unsigned value,
int bits)
22 int mask = -1 << bits;
23 return (value & mask) == 0;
26 inline bool WriteSmallInteger(
int value,
int byteCount)
28 if (byteCount > (m_BufferSize - m_Offset))
31 #if defined(ARM_MATH_CM3) || defined(ARM_MATH_CM4)
35 *((
char *)(m_pBuffer + m_Offset)) = (
char)value;
38 *((
short *)(m_pBuffer + m_Offset)) = (
short)value;
41 *((
int *)(m_pBuffer + m_Offset)) = (
int)value;
47 for (
int i = 0; i < byteCount; i++)
48 *((
char *)(m_pBuffer + m_Offset + i)) = ((
char *)&value)[i];
51 m_Offset += byteCount;
57 : m_pBuffer((char *)pBuffer), m_BufferSize(size), m_Offset(0), m_RefPointA(pRefPointA), m_RefPointB(pRefPointB)
63 if (IsSignedIntConstrained(value, 6))
65 unsigned b = value << 2 | (!!flag << 1);
66 return WriteSmallInteger(b, 1);
68 else if (IsSignedIntConstrained(value, 12))
70 unsigned w = (value << 4) | (!!flag << 1) | (1 << 2) | 1;
71 return WriteSmallInteger(w, 2);
73 else if (IsSignedIntConstrained(value, 28))
75 unsigned dw = (value << 4) | (!!flag << 1) | (2 << 2) | 1;
76 return WriteSmallInteger(dw, 4);
80 unsigned b = (!!flag << 1) | (3 << 2) | 1;
81 if (!WriteSmallInteger(b, 1))
83 if (!WriteSmallInteger(value, 4))
91 if (IsSignedIntConstrained(value, 7))
93 unsigned b = (value << 1);
94 return WriteSmallInteger(b, 1);
96 else if (IsSignedIntConstrained(value, 14))
98 unsigned w = (value << 2) | 1;
99 return WriteSmallInteger(w, 2);
103 unsigned dw = (value << 2) | 3;
104 return WriteSmallInteger(dw, 4);
110 int signBit = (value >> 31) & 1;
111 int permutatedValue = (int)((value & 0xffff0000) | ((value & 0xffff) >> 1) | (((value & 1) ^ signBit) << 15));
113 if (IsSignedIntConstrained(permutatedValue, 15))
115 unsigned w = permutatedValue << 1;
116 return WriteSmallInteger(w, 2);
118 else if (IsSignedIntConstrained(permutatedValue, 30))
120 unsigned dw = (permutatedValue << 2) | 1;
121 return WriteSmallInteger(dw, 4);
126 if (!WriteSmallInteger(b, 1))
128 return WriteSmallInteger(permutatedValue, 4);
134 if (IsUnsignedIntConstrained(value, 15))
136 unsigned w = value << 1;
137 return WriteSmallInteger(w, 2);
139 else if (IsUnsignedIntConstrained(value, 30))
141 unsigned dw = (value << 2) | 1;
142 return WriteSmallInteger(dw, 4);
147 if (!WriteSmallInteger(b, 1))
149 return WriteSmallInteger(value, 4);
155 if (IsUnsignedIntConstrained(value, 14))
157 unsigned w = value << 2 | (!!flag << 1);
158 return WriteSmallInteger(w, 2);
160 else if (IsUnsignedIntConstrained(value, 29))
162 unsigned dw = (value << 3) | 1 | (!!flag << 2);
163 return WriteSmallInteger(dw, 4);
167 unsigned b = flag ? 0xff : 0x7f;
168 if (!WriteSmallInteger(b, 1))
170 return WriteSmallInteger(value, 4);
176 if (IsSignedIntConstrained(value, 14))
178 unsigned w = value << 2 | (!!flag << 1);
179 return WriteSmallInteger(w, 2);
181 else if (IsSignedIntConstrained(value, 29))
183 unsigned dw = (value << 3) | 1 | (!!flag << 2);
184 return WriteSmallInteger(dw, 4);
188 unsigned b = flag ? 0xff : 0x7f;
189 if (!WriteSmallInteger(b, 1))
191 return WriteSmallInteger(value, 4);
197 if (largerInt < 16 && smallerInt < 14)
199 unsigned b = largerInt << 4 | smallerInt;
200 return WriteSmallInteger(b, 1);
202 else if (largerInt < 256 && smallerInt < 256)
204 if (!WriteSmallInteger(0xFE, 1))
206 if (!WriteSmallInteger(largerInt, 1))
208 if (!WriteSmallInteger(smallerInt, 1))
214 if (!WriteSmallInteger(0xFF, 1))
216 if (!WriteSmallInteger(largerInt, 2))
218 if (!WriteSmallInteger(smallerInt, 2))
229 dist = (int)value - (
int)m_RefPointB;
234 dist = (int)value - (
int)m_RefPointA;
255 *pRefPointA = m_RefPointA;
256 *pRefPointB = m_RefPointB;
266 return m_BufferSize - m_Offset;
273 const char *m_pBuffer;
277 char *m_RefPointA, *m_RefPointB;
280 static int SignExtend(
int value,
int bits)
282 return ((~(((value >> (bits - 1)) & 1) - 1)) << bits) | value;
285 inline unsigned PeekInt32(
int delta = 0)
287 int offset = m_Offset + delta;
288 #if defined(ARM_MATH_CM3) || defined(ARM_MATH_CM4)
289 return *((
unsigned *)(m_pBuffer + offset));
291 return (((
unsigned char *)(m_pBuffer + offset))[0] << 0) | (((
unsigned char *)(m_pBuffer + offset))[1] << 8) | (((
unsigned char *)(m_pBuffer + offset))[2] << 16) | (((
unsigned char *)(m_pBuffer + offset))[3] << 24);
295 inline unsigned PeekInt16(
int delta = 0)
297 int offset = m_Offset + delta;
298 #if defined(ARM_MATH_CM3) || defined(ARM_MATH_CM4)
299 return *((
unsigned short *)(m_pBuffer + offset));
301 return (((
unsigned char *)(m_pBuffer + offset))[0] << 0) | (((
unsigned char *)(m_pBuffer + offset))[1] << 8);
307 : m_pBuffer((char *)pBuffer), m_BufferSize(size), m_Offset(0), m_RefPointA((char *)pRefPointA), m_RefPointB((char *)pRefPointB)
313 if ((m_Offset + 1) > m_BufferSize)
316 unsigned char b = (
unsigned char)m_pBuffer[m_Offset];
320 *pValue = SignExtend(b >> 2, 6);
321 *pFlag = (b & 0x02) != 0;
325 else if (((b >> 2) & 0x03) == 1)
327 if ((m_Offset + 2) > m_BufferSize)
329 unsigned w = PeekInt16();
331 *pValue = SignExtend(w >> 4, 12);
332 *pFlag = (w & 0x02) != 0;
336 else if (((b >> 2) & 0x03) == 2)
338 if ((m_Offset + 4) > m_BufferSize)
340 unsigned dw = PeekInt32();
342 *pValue = SignExtend(dw >> 4, 28);
343 *pFlag = (dw & 0x02) != 0;
349 if ((m_Offset + 5) > m_BufferSize)
351 *pValue = PeekInt32(1);
352 *pFlag = (b & 0x02) != 0;
360 if ((m_Offset + 1) > m_BufferSize)
363 unsigned char b = (
unsigned char)m_pBuffer[m_Offset];
368 if ((m_Offset + 2) > m_BufferSize)
370 short w = PeekInt16();
371 permutatedValue = w >> 1;
374 else if ((b & 0x03) == 0x01)
376 if ((m_Offset + 4) > m_BufferSize)
378 int dw = PeekInt32();
379 permutatedValue = dw >> 2;
384 if ((m_Offset + 5) > m_BufferSize)
386 int dw = PeekInt32(1);
387 permutatedValue = dw >> 2;
391 int signBit = (permutatedValue >> 31) & 1;
392 *pValue = (int)(((
unsigned)permutatedValue & 0xffff0000) | ((((
unsigned)permutatedValue & 0x8000) >> 15) ^ signBit) | (((
unsigned)permutatedValue & 0x7fff) << 1));
408 *pValue = (m_RefPointB += dist);
410 *pValue = (m_RefPointA += dist);
412 *pInOutStackAddr += indexDelta;
Definition: SmallNumberCoder.h:3
unsigned RemainingSize()
Definition: SmallNumberCoder.h:264
bool WriteTinySIntWithFlag(int value, bool flag)
Definition: SmallNumberCoder.h:61
int GetOffset()
Definition: SmallNumberCoder.h:243
bool ReadSmallMostlyEvenSInt(int *pValue)
Definition: SmallNumberCoder.h:358
bool ReadStackEntry(void ***pInOutStackAddr, void **pValue)
Definition: SmallNumberCoder.h:396
bool WriteSmallMostLikelyEvenSInt(int value)
Definition: SmallNumberCoder.h:108
bool WritePackedUIntPair(unsigned short largerInt, unsigned short smallerInt)
Definition: SmallNumberCoder.h:195
bool WriteSmallUnsignedInt(unsigned value)
Definition: SmallNumberCoder.h:132
bool WriteStackEntry(int indexDelta, void *value, bool useRefPointB)
Definition: SmallNumberCoder.h:224
Definition: SmallNumberCoder.h:270
bool WriteTinySInt(int value)
Definition: SmallNumberCoder.h:89
void ExportState(void **pRefPointA, void **pRefPointB)
Definition: SmallNumberCoder.h:253
bool WriteSmallUnsignedIntWithFlag(unsigned value, bool flag)
Definition: SmallNumberCoder.h:153
SmallNumberCoder(void *pBuffer, unsigned size, void *pRefPointA, void *pRefPointB)
Definition: SmallNumberCoder.h:56
bool WriteSmallSignedIntWithFlag(int value, bool flag)
Definition: SmallNumberCoder.h:174
void * GetBuffer()
Definition: SmallNumberCoder.h:248
void SetOffset(int offset)
Definition: SmallNumberCoder.h:259
bool ReadTinySIntWithFlag(int *pValue, bool *pFlag)
Definition: SmallNumberCoder.h:311
SmallNumberDecoder(const void *pBuffer, unsigned size, void *pRefPointA, void *pRefPointB)
Definition: SmallNumberCoder.h:306