added QSE_ALIGNTO(), QSE_ALIGNTO_POW2(), QSE_IS_UNALIGNED_POW2(), QSE_IS_ALIGNED_POW2()
This commit is contained in:
@ -43,8 +43,8 @@
|
||||
#define SPU_VUC_SIZE QSE_SIZEOF(vector unsigned char)
|
||||
#endif
|
||||
|
||||
/*#define IS_UNALIGNED(ptr) (((qse_size_t)ptr)%QSE_SIZEOF(qse_size_t))*/
|
||||
#define IS_UNALIGNED(ptr) (((qse_size_t)ptr)&(QSE_SIZEOF(qse_size_t)-1))
|
||||
#define IS_UNALIGNED(ptr) \
|
||||
QSE_IS_UNALIGNED_POW2((qse_size_t)ptr, QSE_SIZEOF(qse_size_t))
|
||||
#define IS_ALIGNED(ptr) (!IS_UNALIGNED(ptr))
|
||||
|
||||
#define IS_EITHER_UNALIGNED(ptr1,ptr2) \
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <qse/cmn/xma.h>
|
||||
#include "mem.h"
|
||||
|
||||
#define ALIGN QSE_SIZEOF(qse_size_t)
|
||||
#define ALIGN QSE_SIZEOF(qse_size_t) /* this must be a power of 2 */
|
||||
#define HDRSIZE QSE_SIZEOF(qse_xma_blk_t)
|
||||
#define MINBLKLEN (HDRSIZE + ALIGN)
|
||||
|
||||
@ -144,7 +144,7 @@ int qse_xma_init (qse_xma_t* xma, qse_mmgr_t* mmgr, qse_size_t zonesize)
|
||||
qse_size_t xfi;
|
||||
|
||||
/* round 'zonesize' to be the multiples of ALIGN */
|
||||
zonesize = ((zonesize + ALIGN - 1) / ALIGN) * ALIGN;
|
||||
zonesize = QSE_ALIGNTO_POW2(zonesize, ALIGN);
|
||||
|
||||
/* adjust 'zonesize' to be large enough to hold a single smallest block */
|
||||
if (zonesize < MINBLKLEN) zonesize = MINBLKLEN;
|
||||
@ -332,8 +332,7 @@ void* qse_xma_alloc (qse_xma_t* xma, qse_size_t size)
|
||||
if (size <= 0) size = 1;
|
||||
|
||||
/* round up 'size' to the multiples of ALIGN */
|
||||
/*size = (size + ALIGN - 1) & ~(ALIGN - 1); */
|
||||
size = ((size + ALIGN - 1) / ALIGN) * ALIGN;
|
||||
size = QSE_ALIGNTO_POW2(size, ALIGN);
|
||||
|
||||
QSE_ASSERT (size >= ALIGN);
|
||||
xfi = getxfi(xma,size);
|
||||
@ -402,7 +401,7 @@ static void* _realloc_merge (qse_xma_t* xma, void* b, qse_size_t size)
|
||||
qse_xma_blk_t* blk = USR_TO_SYS(b);
|
||||
|
||||
/* rounds up 'size' to be multiples of ALIGN */
|
||||
size = ((size + ALIGN - 1) / ALIGN) * ALIGN;
|
||||
size = QSE_ALIGNTO_POW2 (size, ALIGN);
|
||||
|
||||
if (size > blk->size)
|
||||
{
|
||||
|
@ -464,8 +464,6 @@ qse_mux_errnum_t qse_mux_geterrnum (qse_mux_t* mux)
|
||||
return mux->errnum;
|
||||
}
|
||||
|
||||
#define ALIGN_TO(num,align) ((((num) + (align) - 1) / (align)) * (align))
|
||||
|
||||
int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
{
|
||||
#if defined(USE_SELECT)
|
||||
@ -499,7 +497,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
int ubound;
|
||||
|
||||
ubound = evt->hnd + 1;
|
||||
ubound = ALIGN_TO (ubound, 128);
|
||||
ubound = QSE_ALIGNTO_POW2 (ubound, 128);
|
||||
|
||||
tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound);
|
||||
if (tmp == QSE_NULL)
|
||||
@ -557,7 +555,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
int ubound;
|
||||
|
||||
ubound = evt->hnd + 1;
|
||||
ubound = ALIGN_TO (ubound, 128);
|
||||
ubound = QSE_ALIGNTO_POW2 (ubound, 128);
|
||||
|
||||
tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound);
|
||||
if (tmp == QSE_NULL)
|
||||
@ -606,7 +604,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
int ubound;
|
||||
|
||||
ubound = evt->hnd + 1;
|
||||
ubound = ALIGN_TO (ubound, 128);
|
||||
ubound = QSE_ALIGNTO_POW2 (ubound, 128);
|
||||
|
||||
tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound);
|
||||
if (tmp == QSE_NULL)
|
||||
@ -639,7 +637,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
qse_size_t newcapa;
|
||||
|
||||
newcapa = (mux->ee.capa + 1) * 2;
|
||||
newcapa = ALIGN_TO (newcapa, 256);
|
||||
newcapa = QSE_ALIGNTO_POW2 (newcapa, 256);
|
||||
|
||||
tmp = QSE_MMGR_REALLOC (
|
||||
mux->mmgr, mux->ee.ptr,
|
||||
@ -673,7 +671,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
int ubound;
|
||||
|
||||
ubound = evt->hnd + 1;
|
||||
ubound = ALIGN_TO (ubound, 128);
|
||||
ubound = QSE_ALIGNTO_POW2 (ubound, 128);
|
||||
|
||||
tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound);
|
||||
if (tmp == QSE_NULL)
|
||||
|
Reference in New Issue
Block a user