added QSE_ALIGNTO(), QSE_ALIGNTO_POW2(), QSE_IS_UNALIGNED_POW2(), QSE_IS_ALIGNED_POW2()
This commit is contained in:
parent
8b417bab8f
commit
632a4d7181
@ -80,12 +80,12 @@ host_triplet = @host@
|
||||
subdir = .
|
||||
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
|
||||
$(top_srcdir)/configure $(am__configure_deps) \
|
||||
$(srcdir)/README.in README ac/ar-lib ac/compile \
|
||||
ac/config.guess ac/config.sub ac/depcomp ac/install-sh \
|
||||
ac/missing ac/ltmain.sh $(top_srcdir)/ac/ar-lib \
|
||||
$(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \
|
||||
$(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \
|
||||
$(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing
|
||||
$(srcdir)/README.in ac/ar-lib ac/compile ac/config.guess \
|
||||
ac/config.sub ac/depcomp ac/install-sh ac/missing ac/ltmain.sh \
|
||||
$(top_srcdir)/ac/ar-lib $(top_srcdir)/ac/compile \
|
||||
$(top_srcdir)/ac/config.guess $(top_srcdir)/ac/config.sub \
|
||||
$(top_srcdir)/ac/install-sh $(top_srcdir)/ac/ltmain.sh \
|
||||
$(top_srcdir)/ac/missing
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \
|
||||
$(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
|
2
qse/configure
vendored
2
qse/configure
vendored
@ -18534,7 +18534,7 @@ fi
|
||||
|
||||
done
|
||||
|
||||
for ac_header in ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h
|
||||
for ac_header in ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h netpacket/packet.h
|
||||
do :
|
||||
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
||||
|
@ -125,7 +125,7 @@ AC_CHECK_HEADERS([time.h sys/time.h utime.h spawn.h execinfo.h ucontext.h])
|
||||
AC_CHECK_HEADERS([sys/resource.h sys/wait.h sys/syscall.h sys/ioctl.h])
|
||||
AC_CHECK_HEADERS([sys/sendfile.h sys/epoll.h sys/event.h])
|
||||
AC_CHECK_HEADERS([sys/sysctl.h sys/socket.h sys/sockio.h sys/un.h])
|
||||
AC_CHECK_HEADERS([ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h])
|
||||
AC_CHECK_HEADERS([ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h netpacket/packet.h])
|
||||
AC_CHECK_HEADERS([net/if.h net/if_dl.h], [], [], [
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>])
|
||||
|
@ -401,6 +401,9 @@
|
||||
/* Define to 1 if you have the <netinet/sctp.h> header file. */
|
||||
#undef HAVE_NETINET_SCTP_H
|
||||
|
||||
/* Define to 1 if you have the <netpacket/packet.h> header file. */
|
||||
#undef HAVE_NETPACKET_PACKET_H
|
||||
|
||||
/* Define to 1 if you have the <net/if_dl.h> header file. */
|
||||
#undef HAVE_NET_IF_DL_H
|
||||
|
||||
|
@ -126,6 +126,28 @@
|
||||
#define QSE_ALIGNOF(type) QSE_OFFSETOF(struct { qse_uint8_t d1; type d2; }, d2)
|
||||
/*(sizeof(struct { qse_uint8_t d1; type d2; }) - sizeof(type))*/
|
||||
|
||||
/**
|
||||
* The QSE_ALIGNTO() macro rounds up a positive integer to the nearest
|
||||
* multiple of 'align'.
|
||||
*/
|
||||
#define QSE_ALIGNTO(num,align) ((((num) + (align) - 1) / (align)) * (align))
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Round up a number, both positive and negative, to the nearest multiple of 'align'
|
||||
*/
|
||||
#define QSE_ALIGNTO(num,align) ((((num) + (num >= 0? 1: -1) * (align) - 1) / (align)) * (align))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The QSE_ALIGNTO_POW2() macro rounds up a positive integer to to the
|
||||
* nearest multiple of 'align' which should be a multiple of a power of 2
|
||||
*/
|
||||
#define QSE_ALIGNTO_POW2(num,align) ((((num) + (align) - 1)) & ~((align) - 1))
|
||||
|
||||
#define QSE_IS_UNALIGNED_POW2(num,align) ((num) & ((align) - 1))
|
||||
#define QSE_IS_ALIGNED_POW2(num,align) (!QSE_IS_UNALIGNED_POW2(num,align))
|
||||
|
||||
/**
|
||||
* The QSE_TYPE_IS_SIGNED() macro determines if a type is signed.
|
||||
* \code
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user