ReactOS  0.4.13-dev-464-g6b95727
mem.h File Reference
#include <stddef.h>
#include <string.h>
#include <limits.h>
Include dependency graph for mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MEM_STATIC   static /* this version may generate warnings for unused static functions; disable the relevant warning */
 
#define __has_builtin(x)   0 /* compat. with non-clang compilers */
 
#define MEM_STATIC_ASSERT(c)   { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
 

Typedefs

typedef unsigned char BYTE
 
typedef unsigned short U16
 
typedef signed short S16
 
typedef unsigned int U32
 
typedef signed int S32
 
typedef unsigned long long U64
 
typedef signed long long S64
 

Functions

MEM_STATIC void MEM_check (void)
 
MEM_STATIC unsigned MEM_32bits (void)
 
MEM_STATIC unsigned MEM_64bits (void)
 
MEM_STATIC unsigned MEM_isLittleEndian (void)
 
MEM_STATIC U16 MEM_read16 (const void *memPtr)
 
MEM_STATIC U32 MEM_read32 (const void *memPtr)
 
MEM_STATIC U64 MEM_read64 (const void *memPtr)
 
MEM_STATIC size_t MEM_readST (const void *memPtr)
 
MEM_STATIC void MEM_write16 (void *memPtr, U16 value)
 
MEM_STATIC void MEM_write32 (void *memPtr, U32 value)
 
MEM_STATIC void MEM_write64 (void *memPtr, U64 value)
 
MEM_STATIC U32 MEM_swap32 (U32 in)
 
MEM_STATIC U64 MEM_swap64 (U64 in)
 
MEM_STATIC size_t MEM_swapST (size_t in)
 
MEM_STATIC U16 MEM_readLE16 (const void *memPtr)
 
MEM_STATIC void MEM_writeLE16 (void *memPtr, U16 val)
 
MEM_STATIC U32 MEM_readLE24 (const void *memPtr)
 
MEM_STATIC void MEM_writeLE24 (void *memPtr, U32 val)
 
MEM_STATIC U32 MEM_readLE32 (const void *memPtr)
 
MEM_STATIC void MEM_writeLE32 (void *memPtr, U32 val32)
 
MEM_STATIC U64 MEM_readLE64 (const void *memPtr)
 
MEM_STATIC void MEM_writeLE64 (void *memPtr, U64 val64)
 
MEM_STATIC size_t MEM_readLEST (const void *memPtr)
 
MEM_STATIC void MEM_writeLEST (void *memPtr, size_t val)
 
MEM_STATIC U32 MEM_readBE32 (const void *memPtr)
 
MEM_STATIC void MEM_writeBE32 (void *memPtr, U32 val32)
 
MEM_STATIC U64 MEM_readBE64 (const void *memPtr)
 
MEM_STATIC void MEM_writeBE64 (void *memPtr, U64 val64)
 
MEM_STATIC size_t MEM_readBEST (const void *memPtr)
 
MEM_STATIC void MEM_writeBEST (void *memPtr, size_t val)
 

Macro Definition Documentation

◆ __has_builtin

#define __has_builtin (   x)    0 /* compat. with non-clang compilers */

Definition at line 43 of file mem.h.

◆ MEM_STATIC

#define MEM_STATIC   static /* this version may generate warnings for unused static functions; disable the relevant warning */

Definition at line 39 of file mem.h.

◆ MEM_STATIC_ASSERT

#define MEM_STATIC_ASSERT (   c)    { enum { MEM_static_assert = 1/(int)(!!(c)) }; }

Definition at line 47 of file mem.h.

Typedef Documentation

◆ BYTE

typedef BYTE

Definition at line 68 of file mem.h.

◆ S16

typedef signed short S16

Definition at line 73 of file mem.h.

◆ S32

typedef signed int S32

Definition at line 78 of file mem.h.

◆ S64

typedef signed long long S64

Definition at line 82 of file mem.h.

◆ U16

typedef unsigned short U16

Definition at line 72 of file mem.h.

◆ U32

typedef unsigned int U32

Definition at line 77 of file mem.h.

◆ U64

typedef unsigned long long U64

Definition at line 81 of file mem.h.

Function Documentation

◆ MEM_32bits()

MEM_STATIC unsigned MEM_32bits ( void  )

◆ MEM_64bits()

MEM_STATIC unsigned MEM_64bits ( void  )

Definition at line 111 of file mem.h.

111 { return sizeof(size_t)==8; }
__kernel_size_t size_t
Definition: linux.h:237

Referenced by ZSTD_count(), ZSTD_decodeSequence(), ZSTD_decodeSequenceLong(), ZSTD_decompressBlock_internal(), and ZSTD_NbCommonBytes().

◆ MEM_check()

MEM_STATIC void MEM_check ( void  )

Definition at line 48 of file mem.h.

48 { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
#define MEM_STATIC_ASSERT(c)
Definition: mem.h:47

◆ MEM_isLittleEndian()

MEM_STATIC unsigned MEM_isLittleEndian ( void  )

Definition at line 113 of file mem.h.

114 {
115  const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
116  return one.c[0];
117 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
unsigned int U32
Definition: mem.h:77
static double one
Definition: j0_y0.c:80
const GLubyte * c
Definition: glext.h:8905
unsigned char BYTE
Definition: mem.h:68

Referenced by MEM_readBE32(), MEM_readBE64(), MEM_readLE16(), MEM_readLE32(), MEM_readLE64(), MEM_writeBE32(), MEM_writeBE64(), MEM_writeLE16(), MEM_writeLE32(), MEM_writeLE64(), ZSTD_NbCommonBytes(), and ZSTD_readMINMATCH().

◆ MEM_read16()

MEM_STATIC U16 MEM_read16 ( const void memPtr)

Definition at line 164 of file mem.h.

165 {
166  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
167 }
unsigned short U16
Definition: mem.h:72
GLuint GLfloat * val
Definition: glext.h:7180
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by MEM_readLE16(), ZSTD_count(), and ZSTD_getFSEMaxSymbolValue().

◆ MEM_read32()

◆ MEM_read64()

MEM_STATIC U64 MEM_read64 ( const void memPtr)

Definition at line 174 of file mem.h.

175 {
176  U64 val; memcpy(&val, memPtr, sizeof(val)); return val;
177 }
GLuint GLfloat * val
Definition: glext.h:7180
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned long long U64
Definition: mem.h:81

Referenced by MEM_readBE64(), MEM_readLE64(), ZSTD_compressBlock_doubleFast_extDict_generic(), and ZSTD_compressBlock_doubleFast_generic().

◆ MEM_readBE32()

MEM_STATIC U32 MEM_readBE32 ( const void memPtr)

Definition at line 323 of file mem.h.

324 {
325  if (MEM_isLittleEndian())
326  return MEM_swap32(MEM_read32(memPtr));
327  else
328  return MEM_read32(memPtr);
329 }
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC U32 MEM_swap32(U32 in)
Definition: mem.h:201
MEM_STATIC U32 MEM_read32(const void *memPtr)
Definition: mem.h:169

Referenced by MEM_readBEST().

◆ MEM_readBE64()

MEM_STATIC U64 MEM_readBE64 ( const void memPtr)

Definition at line 339 of file mem.h.

340 {
341  if (MEM_isLittleEndian())
342  return MEM_swap64(MEM_read64(memPtr));
343  else
344  return MEM_read64(memPtr);
345 }
MEM_STATIC U64 MEM_swap64(U64 in)
Definition: mem.h:214
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC U64 MEM_read64(const void *memPtr)
Definition: mem.h:174

Referenced by MEM_readBEST().

◆ MEM_readBEST()

MEM_STATIC size_t MEM_readBEST ( const void memPtr)

Definition at line 355 of file mem.h.

356 {
357  if (MEM_32bits())
358  return (size_t)MEM_readBE32(memPtr);
359  else
360  return (size_t)MEM_readBE64(memPtr);
361 }
MEM_STATIC U64 MEM_readBE64(const void *memPtr)
Definition: mem.h:339
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
MEM_STATIC U32 MEM_readBE32(const void *memPtr)
Definition: mem.h:323

◆ MEM_readLE16()

MEM_STATIC U16 MEM_readLE16 ( const void memPtr)

Definition at line 241 of file mem.h.

242 {
243  if (MEM_isLittleEndian())
244  return MEM_read16(memPtr);
245  else {
246  const BYTE* p = (const BYTE*)memPtr;
247  return (U16)(p[0] + (p[1]<<8));
248  }
249 }
unsigned short U16
Definition: mem.h:72
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
unsigned char BYTE
Definition: mem.h:68
GLfloat GLfloat p
Definition: glext.h:8902
MEM_STATIC U16 MEM_read16(const void *memPtr)
Definition: mem.h:164

Referenced by HUF_decompress4X1_usingDTable_internal_body(), HUF_decompress4X2_usingDTable_internal_body(), MEM_readLE24(), ZSTD_decodeLiteralsBlock(), ZSTD_decodeSeqHeaders(), and ZSTD_getFrameHeader_advanced().

◆ MEM_readLE24()

MEM_STATIC U32 MEM_readLE24 ( const void memPtr)

Definition at line 262 of file mem.h.

263 {
264  return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16);
265 }
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
Definition: mem.h:241
unsigned char BYTE
Definition: mem.h:68

Referenced by ZSTD_decodeLiteralsBlock(), and ZSTD_getcBlockSize().

◆ MEM_readLE32()

◆ MEM_readLE64()

MEM_STATIC U64 MEM_readLE64 ( const void memPtr)

Definition at line 289 of file mem.h.

290 {
291  if (MEM_isLittleEndian())
292  return MEM_read64(memPtr);
293  else
294  return MEM_swap64(MEM_read64(memPtr));
295 }
MEM_STATIC U64 MEM_swap64(U64 in)
Definition: mem.h:214
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC U64 MEM_read64(const void *memPtr)
Definition: mem.h:174

Referenced by MEM_readLEST(), ZSTD_getFrameHeader_advanced(), ZSTD_hash5Ptr(), ZSTD_hash6Ptr(), ZSTD_hash7Ptr(), and ZSTD_hash8Ptr().

◆ MEM_readLEST()

MEM_STATIC size_t MEM_readLEST ( const void memPtr)

Definition at line 305 of file mem.h.

306 {
307  if (MEM_32bits())
308  return (size_t)MEM_readLE32(memPtr);
309  else
310  return (size_t)MEM_readLE64(memPtr);
311 }
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
MEM_STATIC U64 MEM_readLE64(const void *memPtr)
Definition: mem.h:289

Referenced by BIT_initDStream(), and BIT_reloadDStream().

◆ MEM_readST()

MEM_STATIC size_t MEM_readST ( const void memPtr)

Definition at line 179 of file mem.h.

180 {
181  size_t val; memcpy(&val, memPtr, sizeof(val)); return val;
182 }
GLuint GLfloat * val
Definition: glext.h:7180
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by ZSTD_count().

◆ MEM_swap32()

MEM_STATIC U32 MEM_swap32 ( U32  in)

Definition at line 201 of file mem.h.

202 {
203 #if (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
204  || (defined(__clang__) && __has_builtin(__builtin_bswap32))
205  return __builtin_bswap32(in);
206 #else
207  return ((in << 24) & 0xff000000 ) |
208  ((in << 8) & 0x00ff0000 ) |
209  ((in >> 8) & 0x0000ff00 ) |
210  ((in >> 24) & 0x000000ff );
211 #endif
212 }
GLuint in
Definition: glext.h:9616

Referenced by MEM_readBE32(), MEM_readLE32(), MEM_swapST(), MEM_writeBE32(), and MEM_writeLE32().

◆ MEM_swap64()

MEM_STATIC U64 MEM_swap64 ( U64  in)

Definition at line 214 of file mem.h.

215 {
216 #if (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
217  || (defined(__clang__) && __has_builtin(__builtin_bswap64))
218  return __builtin_bswap64(in);
219 #else
220  return ((in << 56) & 0xff00000000000000ULL) |
221  ((in << 40) & 0x00ff000000000000ULL) |
222  ((in << 24) & 0x0000ff0000000000ULL) |
223  ((in << 8) & 0x000000ff00000000ULL) |
224  ((in >> 8) & 0x00000000ff000000ULL) |
225  ((in >> 24) & 0x0000000000ff0000ULL) |
226  ((in >> 40) & 0x000000000000ff00ULL) |
227  ((in >> 56) & 0x00000000000000ffULL);
228 #endif
229 }
GLuint in
Definition: glext.h:9616

Referenced by MEM_readBE64(), MEM_readLE64(), MEM_swapST(), MEM_writeBE64(), and MEM_writeLE64().

◆ MEM_swapST()

MEM_STATIC size_t MEM_swapST ( size_t  in)

Definition at line 231 of file mem.h.

232 {
233  if (MEM_32bits())
234  return (size_t)MEM_swap32((U32)in);
235  else
236  return (size_t)MEM_swap64((U64)in);
237 }
MEM_STATIC U64 MEM_swap64(U64 in)
Definition: mem.h:214
unsigned int U32
Definition: mem.h:77
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
MEM_STATIC U32 MEM_swap32(U32 in)
Definition: mem.h:201
GLuint in
Definition: glext.h:9616
unsigned long long U64
Definition: mem.h:81

◆ MEM_write16()

MEM_STATIC void MEM_write16 ( void memPtr,
U16  value 
)

Definition at line 184 of file mem.h.

185 {
186  memcpy(memPtr, &value, sizeof(value));
187 }
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by MEM_writeLE16().

◆ MEM_write32()

MEM_STATIC void MEM_write32 ( void memPtr,
U32  value 
)

Definition at line 189 of file mem.h.

190 {
191  memcpy(memPtr, &value, sizeof(value));
192 }
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by MEM_writeBE32(), and MEM_writeLE32().

◆ MEM_write64()

MEM_STATIC void MEM_write64 ( void memPtr,
U64  value 
)

Definition at line 194 of file mem.h.

195 {
196  memcpy(memPtr, &value, sizeof(value));
197 }
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by MEM_writeBE64(), and MEM_writeLE64().

◆ MEM_writeBE32()

MEM_STATIC void MEM_writeBE32 ( void memPtr,
U32  val32 
)

Definition at line 331 of file mem.h.

332 {
333  if (MEM_isLittleEndian())
334  MEM_write32(memPtr, MEM_swap32(val32));
335  else
336  MEM_write32(memPtr, val32);
337 }
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC U32 MEM_swap32(U32 in)
Definition: mem.h:201
MEM_STATIC void MEM_write32(void *memPtr, U32 value)
Definition: mem.h:189

Referenced by MEM_writeBEST().

◆ MEM_writeBE64()

MEM_STATIC void MEM_writeBE64 ( void memPtr,
U64  val64 
)

Definition at line 347 of file mem.h.

348 {
349  if (MEM_isLittleEndian())
350  MEM_write64(memPtr, MEM_swap64(val64));
351  else
352  MEM_write64(memPtr, val64);
353 }
MEM_STATIC U64 MEM_swap64(U64 in)
Definition: mem.h:214
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC void MEM_write64(void *memPtr, U64 value)
Definition: mem.h:194

Referenced by MEM_writeBEST().

◆ MEM_writeBEST()

MEM_STATIC void MEM_writeBEST ( void memPtr,
size_t  val 
)

Definition at line 363 of file mem.h.

364 {
365  if (MEM_32bits())
366  MEM_writeBE32(memPtr, (U32)val);
367  else
368  MEM_writeBE64(memPtr, (U64)val);
369 }
unsigned int U32
Definition: mem.h:77
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
GLuint GLfloat * val
Definition: glext.h:7180
MEM_STATIC void MEM_writeBE64(void *memPtr, U64 val64)
Definition: mem.h:347
MEM_STATIC void MEM_writeBE32(void *memPtr, U32 val32)
Definition: mem.h:331
unsigned long long U64
Definition: mem.h:81

◆ MEM_writeLE16()

MEM_STATIC void MEM_writeLE16 ( void memPtr,
U16  val 
)

Definition at line 251 of file mem.h.

252 {
253  if (MEM_isLittleEndian()) {
254  MEM_write16(memPtr, val);
255  } else {
256  BYTE* p = (BYTE*)memPtr;
257  p[0] = (BYTE)val;
258  p[1] = (BYTE)(val>>8);
259  }
260 }
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC void MEM_write16(void *memPtr, U16 value)
Definition: mem.h:184
GLuint GLfloat * val
Definition: glext.h:7180
unsigned char BYTE
Definition: mem.h:68
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by HUF_compress4X_usingCTable_internal(), HUF_fillDTableX2(), HUF_fillDTableX2Level2(), MEM_writeLE24(), ZSTD_compressRleLiteralsBlock(), ZSTD_compressSequences_internal(), ZSTD_noCompressLiterals(), and ZSTD_writeFrameHeader().

◆ MEM_writeLE24()

MEM_STATIC void MEM_writeLE24 ( void memPtr,
U32  val 
)

Definition at line 267 of file mem.h.

268 {
269  MEM_writeLE16(memPtr, (U16)val);
270  ((BYTE*)memPtr)[2] = (BYTE)(val>>16);
271 }
unsigned short U16
Definition: mem.h:72
MEM_STATIC void MEM_writeLE16(void *memPtr, U16 val)
Definition: mem.h:251
GLuint GLfloat * val
Definition: glext.h:7180
unsigned char BYTE
Definition: mem.h:68

Referenced by ZSTD_compress_frameChunk(), ZSTD_compressLiterals(), ZSTD_noCompressBlock(), and ZSTD_writeLastEmptyBlock().

◆ MEM_writeLE32()

MEM_STATIC void MEM_writeLE32 ( void memPtr,
U32  val32 
)

Definition at line 281 of file mem.h.

282 {
283  if (MEM_isLittleEndian())
284  MEM_write32(memPtr, val32);
285  else
286  MEM_write32(memPtr, MEM_swap32(val32));
287 }
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC U32 MEM_swap32(U32 in)
Definition: mem.h:201
MEM_STATIC void MEM_write32(void *memPtr, U32 value)
Definition: mem.h:189

Referenced by MEM_writeLEST(), ZSTD_compressLiterals(), ZSTD_compressRleLiteralsBlock(), ZSTD_noCompressLiterals(), ZSTD_writeEpilogue(), and ZSTD_writeFrameHeader().

◆ MEM_writeLE64()

MEM_STATIC void MEM_writeLE64 ( void memPtr,
U64  val64 
)

Definition at line 297 of file mem.h.

298 {
299  if (MEM_isLittleEndian())
300  MEM_write64(memPtr, val64);
301  else
302  MEM_write64(memPtr, MEM_swap64(val64));
303 }
MEM_STATIC U64 MEM_swap64(U64 in)
Definition: mem.h:214
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:113
MEM_STATIC void MEM_write64(void *memPtr, U64 value)
Definition: mem.h:194

Referenced by MEM_writeLEST(), and ZSTD_writeFrameHeader().

◆ MEM_writeLEST()

MEM_STATIC void MEM_writeLEST ( void memPtr,
size_t  val 
)

Definition at line 313 of file mem.h.

314 {
315  if (MEM_32bits())
316  MEM_writeLE32(memPtr, (U32)val);
317  else
318  MEM_writeLE64(memPtr, (U64)val);
319 }
unsigned int U32
Definition: mem.h:77
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:110
MEM_STATIC void MEM_writeLE64(void *memPtr, U64 val64)
Definition: mem.h:297
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
Definition: mem.h:281
GLuint GLfloat * val
Definition: glext.h:7180
unsigned long long U64
Definition: mem.h:81

Referenced by BIT_flushBits(), and BIT_flushBitsFast().