ReactOS 0.4.16-dev-336-gb667d82
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 unsigned char BYTE

Definition at line 141 of file mem.h.

◆ S16

typedef signed short S16

Definition at line 146 of file mem.h.

◆ S32

typedef signed int S32

Definition at line 151 of file mem.h.

◆ S64

typedef signed long long S64

Definition at line 155 of file mem.h.

◆ U16

typedef unsigned short U16

Definition at line 145 of file mem.h.

◆ U32

typedef unsigned int U32

Definition at line 150 of file mem.h.

◆ U64

typedef unsigned long long U64

Definition at line 154 of file mem.h.

Function Documentation

◆ MEM_32bits()

MEM_STATIC unsigned MEM_32bits ( void  )

Definition at line 183 of file mem.h.

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

Referenced by HUF_decodeStreamX1(), MEM_readBEST(), MEM_readLEST(), MEM_swapST(), MEM_writeBEST(), MEM_writeLEST(), and ZSTD_encodeSequences_body().

◆ MEM_64bits()

MEM_STATIC unsigned MEM_64bits ( void  )

Definition at line 184 of file mem.h.

184{ return sizeof(size_t)==8; }

◆ 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 186 of file mem.h.

187{
188 const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
189 return one.c[0];
190}
const GLubyte * c
Definition: glext.h:8905
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
int one
Definition: sehframes.cpp:28
unsigned char BYTE
Definition: xxhash.c:193
unsigned int U32
Definition: xxhash.c:195

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

◆ MEM_read16()

MEM_STATIC U16 MEM_read16 ( const void memPtr)

Definition at line 237 of file mem.h.

238{
239 U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
240}
GLuint GLfloat * val
Definition: glext.h:7180
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned short U16
Definition: xxhash.c:194

Referenced by MEM_readLE16(), and ZSTD_getFSEMaxSymbolValue().

◆ MEM_read32()

◆ MEM_read64()

MEM_STATIC U64 MEM_read64 ( const void memPtr)

Definition at line 247 of file mem.h.

248{
249 U64 val; memcpy(&val, memPtr, sizeof(val)); return val;
250}
unsigned long long U64
Definition: xxhash.c:197

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 396 of file mem.h.

397{
398 if (MEM_isLittleEndian())
399 return MEM_swap32(MEM_read32(memPtr));
400 else
401 return MEM_read32(memPtr);
402}
MEM_STATIC U32 MEM_read32(const void *memPtr)
Definition: mem.h:242
MEM_STATIC U32 MEM_swap32(U32 in)
Definition: mem.h:274
MEM_STATIC unsigned MEM_isLittleEndian(void)
Definition: mem.h:186

Referenced by MEM_readBEST().

◆ MEM_readBE64()

MEM_STATIC U64 MEM_readBE64 ( const void memPtr)

Definition at line 412 of file mem.h.

413{
414 if (MEM_isLittleEndian())
415 return MEM_swap64(MEM_read64(memPtr));
416 else
417 return MEM_read64(memPtr);
418}
MEM_STATIC U64 MEM_swap64(U64 in)
Definition: mem.h:287
MEM_STATIC U64 MEM_read64(const void *memPtr)
Definition: mem.h:247

Referenced by MEM_readBEST().

◆ MEM_readBEST()

MEM_STATIC size_t MEM_readBEST ( const void memPtr)

Definition at line 428 of file mem.h.

429{
430 if (MEM_32bits())
431 return (size_t)MEM_readBE32(memPtr);
432 else
433 return (size_t)MEM_readBE64(memPtr);
434}
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:183
MEM_STATIC U64 MEM_readBE64(const void *memPtr)
Definition: mem.h:412
MEM_STATIC U32 MEM_readBE32(const void *memPtr)
Definition: mem.h:396

◆ MEM_readLE16()

MEM_STATIC U16 MEM_readLE16 ( const void memPtr)

Definition at line 314 of file mem.h.

315{
316 if (MEM_isLittleEndian())
317 return MEM_read16(memPtr);
318 else {
319 const BYTE* p = (const BYTE*)memPtr;
320 return (U16)(p[0] + (p[1]<<8));
321 }
322}
MEM_STATIC U16 MEM_read16(const void *memPtr)
Definition: mem.h:237
GLfloat GLfloat p
Definition: glext.h:8902

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

◆ MEM_readLE24()

MEM_STATIC U32 MEM_readLE24 ( const void memPtr)

Definition at line 335 of file mem.h.

336{
337 return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16);
338}
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
Definition: mem.h:314

Referenced by ZSTD_getcBlockSize().

◆ MEM_readLE32()

◆ MEM_readLE64()

MEM_STATIC U64 MEM_readLE64 ( const void memPtr)

Definition at line 362 of file mem.h.

363{
364 if (MEM_isLittleEndian())
365 return MEM_read64(memPtr);
366 else
367 return MEM_swap64(MEM_read64(memPtr));
368}

Referenced by MEM_readLEST(), ZSTD_getFrameHeader_advanced(), and ZSTD_hashPtr().

◆ MEM_readLEST()

MEM_STATIC size_t MEM_readLEST ( const void memPtr)

Definition at line 378 of file mem.h.

379{
380 if (MEM_32bits())
381 return (size_t)MEM_readLE32(memPtr);
382 else
383 return (size_t)MEM_readLE64(memPtr);
384}
MEM_STATIC U64 MEM_readLE64(const void *memPtr)
Definition: mem.h:362
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:346

Referenced by BIT_initDStream(), BIT_reloadDStream(), and BIT_reloadDStreamFast().

◆ MEM_readST()

MEM_STATIC size_t MEM_readST ( const void memPtr)

Definition at line 252 of file mem.h.

253{
254 size_t val; memcpy(&val, memPtr, sizeof(val)); return val;
255}

◆ MEM_swap32()

MEM_STATIC U32 MEM_swap32 ( U32  in)

Definition at line 274 of file mem.h.

275{
276#if (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
277 || (defined(__clang__) && __has_builtin(__builtin_bswap32))
278 return __builtin_bswap32(in);
279#else
280 return ((in << 24) & 0xff000000 ) |
281 ((in << 8) & 0x00ff0000 ) |
282 ((in >> 8) & 0x0000ff00 ) |
283 ((in >> 24) & 0x000000ff );
284#endif
285}
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 287 of file mem.h.

288{
289#if (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
290 || (defined(__clang__) && __has_builtin(__builtin_bswap64))
291 return __builtin_bswap64(in);
292#else
293 return ((in << 56) & 0xff00000000000000ULL) |
294 ((in << 40) & 0x00ff000000000000ULL) |
295 ((in << 24) & 0x0000ff0000000000ULL) |
296 ((in << 8) & 0x000000ff00000000ULL) |
297 ((in >> 8) & 0x00000000ff000000ULL) |
298 ((in >> 24) & 0x0000000000ff0000ULL) |
299 ((in >> 40) & 0x000000000000ff00ULL) |
300 ((in >> 56) & 0x00000000000000ffULL);
301#endif
302}

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 304 of file mem.h.

305{
306 if (MEM_32bits())
307 return (size_t)MEM_swap32((U32)in);
308 else
309 return (size_t)MEM_swap64((U64)in);
310}

◆ MEM_write16()

MEM_STATIC void MEM_write16 ( void memPtr,
U16  value 
)

Definition at line 257 of file mem.h.

258{
259 memcpy(memPtr, &value, sizeof(value));
260}
Definition: pdh_main.c:94

Referenced by MEM_writeLE16().

◆ MEM_write32()

MEM_STATIC void MEM_write32 ( void memPtr,
U32  value 
)

Definition at line 262 of file mem.h.

263{
264 memcpy(memPtr, &value, sizeof(value));
265}

Referenced by MEM_writeBE32(), and MEM_writeLE32().

◆ MEM_write64()

MEM_STATIC void MEM_write64 ( void memPtr,
U64  value 
)

Definition at line 267 of file mem.h.

268{
269 memcpy(memPtr, &value, sizeof(value));
270}

Referenced by MEM_writeBE64(), and MEM_writeLE64().

◆ MEM_writeBE32()

MEM_STATIC void MEM_writeBE32 ( void memPtr,
U32  val32 
)

Definition at line 404 of file mem.h.

405{
406 if (MEM_isLittleEndian())
407 MEM_write32(memPtr, MEM_swap32(val32));
408 else
409 MEM_write32(memPtr, val32);
410}
MEM_STATIC void MEM_write32(void *memPtr, U32 value)
Definition: mem.h:262

Referenced by MEM_writeBEST().

◆ MEM_writeBE64()

MEM_STATIC void MEM_writeBE64 ( void memPtr,
U64  val64 
)

Definition at line 420 of file mem.h.

421{
422 if (MEM_isLittleEndian())
423 MEM_write64(memPtr, MEM_swap64(val64));
424 else
425 MEM_write64(memPtr, val64);
426}
MEM_STATIC void MEM_write64(void *memPtr, U64 value)
Definition: mem.h:267

Referenced by MEM_writeBEST().

◆ MEM_writeBEST()

MEM_STATIC void MEM_writeBEST ( void memPtr,
size_t  val 
)

Definition at line 436 of file mem.h.

437{
438 if (MEM_32bits())
439 MEM_writeBE32(memPtr, (U32)val);
440 else
441 MEM_writeBE64(memPtr, (U64)val);
442}
MEM_STATIC void MEM_writeBE32(void *memPtr, U32 val32)
Definition: mem.h:404
MEM_STATIC void MEM_writeBE64(void *memPtr, U64 val64)
Definition: mem.h:420

◆ MEM_writeLE16()

MEM_STATIC void MEM_writeLE16 ( void memPtr,
U16  val 
)

Definition at line 324 of file mem.h.

325{
326 if (MEM_isLittleEndian()) {
327 MEM_write16(memPtr, val);
328 } else {
329 BYTE* p = (BYTE*)memPtr;
330 p[0] = (BYTE)val;
331 p[1] = (BYTE)(val>>8);
332 }
333}
unsigned char BYTE
Definition: mem.h:141
MEM_STATIC void MEM_write16(void *memPtr, U16 value)
Definition: mem.h:257

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

◆ MEM_writeLE24()

MEM_STATIC void MEM_writeLE24 ( void memPtr,
U32  val 
)

Definition at line 340 of file mem.h.

341{
342 MEM_writeLE16(memPtr, (U16)val);
343 ((BYTE*)memPtr)[2] = (BYTE)(val>>16);
344}
MEM_STATIC void MEM_writeLE16(void *memPtr, U16 val)
Definition: mem.h:324

Referenced by ZSTD_compress_frameChunk(), ZSTD_compressLiterals(), ZSTD_compressSubBlock(), ZSTD_compressSubBlock_literal(), and ZSTD_writeLastEmptyBlock().

◆ MEM_writeLE32()

MEM_STATIC void MEM_writeLE32 ( void memPtr,
U32  val32 
)

◆ MEM_writeLE64()

MEM_STATIC void MEM_writeLE64 ( void memPtr,
U64  val64 
)

Definition at line 370 of file mem.h.

371{
372 if (MEM_isLittleEndian())
373 MEM_write64(memPtr, val64);
374 else
375 MEM_write64(memPtr, MEM_swap64(val64));
376}

Referenced by MEM_writeLEST(), and ZSTD_writeFrameHeader().

◆ MEM_writeLEST()

MEM_STATIC void MEM_writeLEST ( void memPtr,
size_t  val 
)

Definition at line 386 of file mem.h.

387{
388 if (MEM_32bits())
389 MEM_writeLE32(memPtr, (U32)val);
390 else
391 MEM_writeLE64(memPtr, (U64)val);
392}
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
Definition: mem.h:354
MEM_STATIC void MEM_writeLE64(void *memPtr, U64 val64)
Definition: mem.h:370

Referenced by BIT_flushBits(), and BIT_flushBitsFast().