added QSE_ALIGNTO(), QSE_ALIGNTO_POW2(), QSE_IS_UNALIGNED_POW2(), QSE_IS_ALIGNED_POW2()

This commit is contained in:
2016-04-27 06:54:18 +00:00
parent 8b417bab8f
commit 632a4d7181
8 changed files with 44 additions and 22 deletions

View File

@ -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

View File

@ -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