diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 596ec806..149fd608 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -1548,15 +1548,15 @@ QSE_EXPORT void qse_awk_close ( * The qse_awk_getmmgr() function gets the memory manager used in * qse_awk_open(). */ -#if defined(MOO_HAVE_INLINE) - static MOO_INLINE qse_mmgr_t* qse_awk_getmmgr (qse_awk_t* awk) { return awk->mmgr; } - static MOO_INLINE qse_cmgr_t* qse_awk_getcmgr (qse_awk_t* awk) { return awk->cmgr; } - static MOO_INLINE void qse_setcmgr (qse_awk_t* awk, qse_awk_cmgr_t* cmgr) { awk->cmgr = cmgr; } +#if defined(QSE_HAVE_INLINE) +static QSE_INLINE qse_mmgr_t* qse_awk_getmmgr (qse_awk_t* awk) { return ((qse_awk_alt_t*)awk)->mmgr; } +static QSE_INLINE qse_cmgr_t* qse_awk_getcmgr (qse_awk_t* awk) { return ((qse_awk_alt_t*)awk)->cmgr; } +static QSE_INLINE void qse_awk_setcmgr (qse_awk_t* awk, qse_cmgr_t* cmgr) { ((qse_awk_alt_t*)awk)->cmgr = cmgr; } #else # define qse_awk_getmmgr(awk) (((qse_awk_alt_t*)(awk))->mmgr) # define qse_awk_getcmgr(awk) (((qse_awk_alt_t*)(awk))->cmgr) -# define qse_awk_setcmgr(awk,mgr) (((qse_awk_alt_t*)(awk))->cmgr = (mgr)) -#endif +# define qse_awk_setcmgr(awk,_cmgr) (((qse_awk_alt_t*)(awk))->cmgr = (_cmgr)) +#endif /* QSE_HAVE_INLINE */ /** * The qse_awk_getxtn() function gets the poniter to the beginning @@ -2252,26 +2252,38 @@ QSE_EXPORT int qse_awk_rtx_setofilename ( qse_size_t len /**< name length */ ); + +#if defined(QSE_HAVE_INLINE) + /** * The qse_awk_rtx_getawk() function gets the owner of a runtime context \a rtx. * \return owner of a runtime context \a rtx. */ -QSE_EXPORT qse_awk_t* qse_awk_rtx_getawk ( - qse_awk_rtx_t* rtx /**< runtime context */ -); +static QSE_INLINE qse_awk_t* qse_awk_rtx_getawk (qse_awk_rtx_t* rtx) +{ + return ((qse_awk_rtx_alt_t*)rtx)->awk; +} /** * The qse_awk_rtx_getmmgr() function gets the memory manager of a runtime * context. */ -QSE_EXPORT qse_mmgr_t* qse_awk_rtx_getmmgr ( - qse_awk_rtx_t* rtx /**< runtime context */ -); +static QSE_INLINE qse_mmgr_t* qse_awk_rtx_getmmgr (qse_awk_rtx_t* rtx) +{ + return qse_awk_getmmgr(qse_awk_rtx_getawk(rtx)); +} -QSE_EXPORT qse_cmgr_t* qse_awk_rtx_getcmgr ( - qse_awk_rtx_t* rtx /**< runtime context */ -); +static QSE_INLINE qse_cmgr_t* qse_awk_rtx_getcmgr (qse_awk_rtx_t* rtx) +{ + return qse_awk_getcmgr(qse_awk_rtx_getawk(rtx)); +} +#else +# define qse_awk_rtx_getawk(rtx) (((qse_awk_rtx_alt_t*)(rtx))->awk) +# define qse_awk_rtx_getmmgr(rtx) (qse_awk_getmmgr(qse_awk_rtx_getawk(rtx))) +# define qse_awk_rtx_getcmgr(rtx) (qse_awk_getcmgr(qse_awk_rtx_getawk(rtx))) + +#endif /* QSE_HAVE_INLINE */ /** * The qse_awk_rtx_getxtn() function gets the pointer to the extension area diff --git a/qse/include/qse/cmn/hton.h b/qse/include/qse/cmn/hton.h index c42e921a..8b91368f 100644 --- a/qse/include/qse/cmn/hton.h +++ b/qse/include/qse/cmn/hton.h @@ -30,72 +30,337 @@ #include #include -#define QSE_CONST_SWAP16(x) \ - ((qse_uint16_t)((((qse_uint16_t)(x) & (qse_uint16_t)0x00ffU) << 8) | \ - (((qse_uint16_t)(x) & (qse_uint16_t)0xff00U) >> 8) )) +#define QSE_CONST_BSWAP16(x) \ + ((qse_uint16_t)((((qse_uint16_t)(x) & ((qse_uint16_t)0xff << 0)) << 8) | \ + (((qse_uint16_t)(x) & ((qse_uint16_t)0xff << 8)) >> 8))) -#define QSE_CONST_SWAP32(x) \ - ((qse_uint32_t)((((qse_uint32_t)(x) & (qse_uint32_t)0x000000ffUL) << 24) | \ - (((qse_uint32_t)(x) & (qse_uint32_t)0x0000ff00UL) << 8) | \ - (((qse_uint32_t)(x) & (qse_uint32_t)0x00ff0000UL) >> 8) | \ - (((qse_uint32_t)(x) & (qse_uint32_t)0xff000000UL) >> 24) )) +#define QSE_CONST_BSWAP32(x) \ + ((qse_uint32_t)((((qse_uint32_t)(x) & ((qse_uint32_t)0xff << 0)) << 24) | \ + (((qse_uint32_t)(x) & ((qse_uint32_t)0xff << 8)) << 8) | \ + (((qse_uint32_t)(x) & ((qse_uint32_t)0xff << 16)) >> 8) | \ + (((qse_uint32_t)(x) & ((qse_uint32_t)0xff << 24)) >> 24))) + +#if defined(QSE_HAVE_UINT64_T) +#define QSE_CONST_BSWAP64(x) \ + ((qse_uint64_t)((((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 0)) << 56) | \ + (((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 8)) << 40) | \ + (((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 16)) << 24) | \ + (((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 24)) << 8) | \ + (((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 32)) >> 8) | \ + (((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 40)) >> 24) | \ + (((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 48)) >> 40) | \ + (((qse_uint64_t)(x) & ((qse_uint64_t)0xff << 56)) >> 56))) +#endif + +#if defined(QSE_HAVE_UINT128_T) +#define QSE_CONST_BSWAP128(x) \ + ((qse_uint128_t)((((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 0)) << 120) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 8)) << 104) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 16)) << 88) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 24)) << 72) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 32)) << 56) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 40)) << 40) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 48)) << 24) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 56)) << 8) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 64)) >> 8) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 72)) >> 24) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 80)) >> 40) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 88)) >> 56) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 96)) >> 72) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 104)) >> 88) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 112)) >> 104) | \ + (((qse_uint128_t)(x) & ((qse_uint128_t)0xff << 120)) >> 120))) +#endif #if defined(QSE_ENDIAN_LITTLE) -# define QSE_CONST_NTOH16(x) QSE_CONST_SWAP16(x) -# define QSE_CONST_HTON16(x) QSE_CONST_SWAP16(x) -# define QSE_CONST_NTOH32(x) QSE_CONST_SWAP32(x) -# define QSE_CONST_HTON32(x) QSE_CONST_SWAP32(x) + +# if defined(QSE_HAVE_UINT16_T) +# define QSE_CONST_NTOH16(x) QSE_CONST_BSWAP16(x) +# define QSE_CONST_HTON16(x) QSE_CONST_BSWAP16(x) +# define QSE_CONST_HTOBE16(x) QSE_CONST_BSWAP16(x) +# define QSE_CONST_HTOLE16(x) (x) +# define QSE_CONST_BE16TOH(x) QSE_CONST_BSWAP16(x) +# define QSE_CONST_LE16TOH(x) (x) +# endif + +# if defined(QSE_HAVE_UINT32_T) +# define QSE_CONST_NTOH32(x) QSE_CONST_BSWAP32(x) +# define QSE_CONST_HTON32(x) QSE_CONST_BSWAP32(x) +# define QSE_CONST_HTOBE32(x) QSE_CONST_BSWAP32(x) +# define QSE_CONST_HTOLE32(x) (x) +# define QSE_CONST_BE32TOH(x) QSE_CONST_BSWAP32(x) +# define QSE_CONST_LE32TOH(x) (x) +# endif + +# if defined(QSE_HAVE_UINT64_T) +# define QSE_CONST_NTOH64(x) QSE_CONST_BSWAP64(x) +# define QSE_CONST_HTON64(x) QSE_CONST_BSWAP64(x) +# define QSE_CONST_HTOBE64(x) QSE_CONST_BSWAP64(x) +# define QSE_CONST_HTOLE64(x) (x) +# define QSE_CONST_BE64TOH(x) QSE_CONST_BSWAP64(x) +# define QSE_CONST_LE64TOH(x) (x) +# endif + +# if defined(QSE_HAVE_UINT128_T) +# define QSE_CONST_NTOH128(x) QSE_CONST_BSWAP128(x) +# define QSE_CONST_HTON128(x) QSE_CONST_BSWAP128(x) +# define QSE_CONST_HTOBE128(x) QSE_CONST_BSWAP128(x) +# define QSE_CONST_HTOLE128(x) (x) +# define QSE_CONST_BE128TOH(x) QSE_CONST_BSWAP128(x) +# define QSE_CONST_LE128TOH(x) (x) +#endif + #elif defined(QSE_ENDIAN_BIG) -# define QSE_CONST_NTOH16(x) (x) -# define QSE_CONST_HTON16(x) (x) -# define QSE_CONST_NTOH32(x) (x) -# define QSE_CONST_HTON32(x) (x) + +# if defined(QSE_HAVE_UINT16_T) +# define QSE_CONST_NTOH16(x) (x) +# define QSE_CONST_HTON16(x) (x) +# define QSE_CONST_HTOBE16(x) (x) +# define QSE_CONST_HTOLE16(x) QSE_CONST_BSWAP16(x) +# define QSE_CONST_BE16TOH(x) (x) +# define QSE_CONST_LE16TOH(x) QSE_CONST_BSWAP16(x) +# endif + +# if defined(QSE_HAVE_UINT32_T) +# define QSE_CONST_NTOH32(x) (x) +# define QSE_CONST_HTON32(x) (x) +# define QSE_CONST_HTOBE32(x) (x) +# define QSE_CONST_HTOLE32(x) QSE_CONST_BSWAP32(x) +# define QSE_CONST_BE32TOH(x) (x) +# define QSE_CONST_LE32TOH(x) QSE_CONST_BSWAP32(x) +# endif + +# if defined(QSE_HAVE_UINT64_T) +# define QSE_CONST_NTOH64(x) (x) +# define QSE_CONST_HTON64(x) (x) +# define QSE_CONST_HTOBE64(x) (x) +# define QSE_CONST_HTOLE64(x) QSE_CONST_BSWAP64(x) +# define QSE_CONST_BE64TOH(x) (x) +# define QSE_CONST_LE64TOH(x) QSE_CONST_BSWAP64(x) +# endif + +# if defined(QSE_HAVE_UINT128_T) +# define QSE_CONST_NTOH128(x) (x) +# define QSE_CONST_HTON128(x) (x) +# define QSE_CONST_HTOBE128(x) (x) +# define QSE_CONST_HTOLE128(x) QSE_CONST_BSWAP128(x) +# define QSE_CONST_BE128TOH(x) (x) +# define QSE_CONST_LE128TOH(x) QSE_CONST_BSWAP128(x) +# endif + #else -# error UNKNOWN ENDIAN +# error UNKNOWN ENDIAN #endif #if defined(__cplusplus) extern "C" { #endif -#if defined(QSE_HAVE_UINT16_T) -QSE_EXPORT qse_uint16_t qse_ntoh16 ( - qse_uint16_t x -); +#if defined(QSE_HAVE_INLINE) -QSE_EXPORT qse_uint16_t qse_hton16 ( - qse_uint16_t x -); +#if defined(QSE_HAVE_UINT16_T) +static QSE_INLINE qse_uint16_t qse_bswap16 (qse_uint16_t x) +{ +#if defined(QSE_HAVE_BUILTIN_BSWAP16) + return __builtin_bswap16(x); +#elif defined(__GNUC__) && (defined(__x86_64) || defined(__amd64) || defined(__i386) || defined(i386)) + __asm__ volatile ("xchgb %b0, %h0" : "=Q"(x): "0"(x)); + return x; +#else + return (x << 8) | (x >> 8); +#endif +} #endif #if defined(QSE_HAVE_UINT32_T) -QSE_EXPORT qse_uint32_t qse_ntoh32 ( - qse_uint32_t x -); - -QSE_EXPORT qse_uint32_t qse_hton32 ( - qse_uint32_t x -); +static QSE_INLINE qse_uint32_t qse_bswap32 (qse_uint32_t x) +{ +#if defined(QSE_HAVE_BUILTIN_BSWAP32) + return __builtin_bswap32(x); +#elif defined(__GNUC__) && (defined(__x86_64) || defined(__amd64) || defined(__i386) || defined(i386)) + __asm__ volatile ("bswapl %0" : "=r"(x) : "0"(x)); + return x; +#else + return ((x >> 24)) | + ((x >> 8) & ((qse_uint32_t)0xff << 8)) | + ((x << 8) & ((qse_uint32_t)0xff << 16)) | + ((x << 24)); +#endif +} #endif #if defined(QSE_HAVE_UINT64_T) -QSE_EXPORT qse_uint64_t qse_ntoh64 ( - qse_uint64_t x -); - -QSE_EXPORT qse_uint64_t qse_hton64 ( - qse_uint64_t x -); +static QSE_INLINE qse_uint64_t qse_bswap64 (qse_uint64_t x) +{ +#if defined(QSE_HAVE_BUILTIN_BSWAP64) + return __builtin_bswap64(x); +#elif defined(__GNUC__) && (defined(__x86_64) || defined(__amd64)) + __asm__ volatile ("bswapq %0" : "=r"(x) : "0"(x)); + return x; +#else + return ((x >> 56)) | + ((x >> 40) & ((qse_uint64_t)0xff << 8)) | + ((x >> 24) & ((qse_uint64_t)0xff << 16)) | + ((x >> 8) & ((qse_uint64_t)0xff << 24)) | + ((x << 8) & ((qse_uint64_t)0xff << 32)) | + ((x << 24) & ((qse_uint64_t)0xff << 40)) | + ((x << 40) & ((qse_uint64_t)0xff << 48)) | + ((x << 56)); +#endif +} #endif #if defined(QSE_HAVE_UINT128_T) -QSE_EXPORT qse_uint128_t qse_ntoh128 ( - qse_uint128_t x -); +static QSE_INLINE qse_uint128_t qse_bswap128 (qse_uint128_t x) +{ +#if defined(QSE_HAVE_BUILTIN_BSWAP128) + return __builtin_bswap128(x); +#else + return ((x >> 120)) | + ((x >> 104) & ((qse_uint128_t)0xff << 8)) | + ((x >> 88) & ((qse_uint128_t)0xff << 16)) | + ((x >> 72) & ((qse_uint128_t)0xff << 24)) | + ((x >> 56) & ((qse_uint128_t)0xff << 32)) | + ((x >> 40) & ((qse_uint128_t)0xff << 40)) | + ((x >> 24) & ((qse_uint128_t)0xff << 48)) | + ((x >> 8) & ((qse_uint128_t)0xff << 56)) | + ((x << 8) & ((qse_uint128_t)0xff << 64)) | + ((x << 24) & ((qse_uint128_t)0xff << 72)) | + ((x << 40) & ((qse_uint128_t)0xff << 80)) | + ((x << 56) & ((qse_uint128_t)0xff << 88)) | + ((x << 72) & ((qse_uint128_t)0xff << 96)) | + ((x << 88) & ((qse_uint128_t)0xff << 104)) | + ((x << 104) & ((qse_uint128_t)0xff << 112)) | + ((x << 120)); +#endif +} +#endif -QSE_EXPORT qse_uint128_t qse_hton128 ( - qse_uint128_t x -); +#else + +#if defined(QSE_HAVE_UINT16_T) +# define qse_bswap16(x) ((qse_uint16_t)(((qse_uint16_t)(x)) << 8) | (((qse_uint16_t)(x)) >> 8)) +#endif + +#if defined(QSE_HAVE_UINT32_T) +# define qse_bswap32(x) ((qse_uint32_t)(((((qse_uint32_t)(x)) >> 24)) | \ + ((((qse_uint32_t)(x)) >> 8) & ((qse_uint32_t)0xff << 8)) | \ + ((((qse_uint32_t)(x)) << 8) & ((qse_uint32_t)0xff << 16)) | \ + ((((qse_uint32_t)(x)) << 24)))) +#endif + +#if defined(QSE_HAVE_UINT64_T) +# define qse_bswap64(x) ((qse_uint64_t)(((((qse_uint64_t)(x)) >> 56)) | \ + ((((qse_uint64_t)(x)) >> 40) & ((qse_uint64_t)0xff << 8)) | \ + ((((qse_uint64_t)(x)) >> 24) & ((qse_uint64_t)0xff << 16)) | \ + ((((qse_uint64_t)(x)) >> 8) & ((qse_uint64_t)0xff << 24)) | \ + ((((qse_uint64_t)(x)) << 8) & ((qse_uint64_t)0xff << 32)) | \ + ((((qse_uint64_t)(x)) << 24) & ((qse_uint64_t)0xff << 40)) | \ + ((((qse_uint64_t)(x)) << 40) & ((qse_uint64_t)0xff << 48)) | \ + ((((qse_uint64_t)(x)) << 56)))) +#endif + +#if defined(QSE_HAVE_UINT128_T) +# define qse_bswap128(x) ((qse_uint128_t)(((((qse_uint128_t)(x)) >> 120)) | \ + ((((qse_uint128_t)(x)) >> 104) & ((qse_uint128_t)0xff << 8)) | \ + ((((qse_uint128_t)(x)) >> 88) & ((qse_uint128_t)0xff << 16)) | \ + ((((qse_uint128_t)(x)) >> 72) & ((qse_uint128_t)0xff << 24)) | \ + ((((qse_uint128_t)(x)) >> 56) & ((qse_uint128_t)0xff << 32)) | \ + ((((qse_uint128_t)(x)) >> 40) & ((qse_uint128_t)0xff << 40)) | \ + ((((qse_uint128_t)(x)) >> 24) & ((qse_uint128_t)0xff << 48)) | \ + ((((qse_uint128_t)(x)) >> 8) & ((qse_uint128_t)0xff << 56)) | \ + ((((qse_uint128_t)(x)) << 8) & ((qse_uint128_t)0xff << 64)) | \ + ((((qse_uint128_t)(x)) << 24) & ((qse_uint128_t)0xff << 72)) | \ + ((((qse_uint128_t)(x)) << 40) & ((qse_uint128_t)0xff << 80)) | \ + ((((qse_uint128_t)(x)) << 56) & ((qse_uint128_t)0xff << 88)) | \ + ((((qse_uint128_t)(x)) << 72) & ((qse_uint128_t)0xff << 96)) | \ + ((((qse_uint128_t)(x)) << 88) & ((qse_uint128_t)0xff << 104)) | \ + ((((qse_uint128_t)(x)) << 104) & ((qse_uint128_t)0xff << 112)) | \ + ((((qse_uint128_t)(x)) << 120)))) +#endif + +#endif /* QSE_HAVE_INLINE */ + + +#if defined(QSE_ENDIAN_LITTLE) + +# if defined(QSE_HAVE_UINT16_T) +# define qse_hton16(x) qse_bswap16(x) +# define qse_ntoh16(x) qse_bswap16(x) +# define qse_htobe16(x) qse_bswap16(x) +# define qse_be16toh(x) qse_bswap16(x) +# define qse_htole16(x) ((qse_uint16_t)(x)) +# define qse_le16toh(x) ((qse_uint16_t)(x)) +# endif + +# if defined(QSE_HAVE_UINT32_T) +# define qse_hton32(x) qse_bswap32(x) +# define qse_ntoh32(x) qse_bswap32(x) +# define qse_htobe32(x) qse_bswap32(x) +# define qse_be32toh(x) qse_bswap32(x) +# define qse_htole32(x) ((qse_uint32_t)(x)) +# define qse_le32toh(x) ((qse_uint32_t)(x)) +# endif + +# if defined(QSE_HAVE_UINT64_T) +# define qse_hton64(x) qse_bswap64(x) +# define qse_ntoh64(x) qse_bswap64(x) +# define qse_htobe64(x) qse_bswap64(x) +# define qse_be64toh(x) qse_bswap64(x) +# define qse_htole64(x) ((qse_uint64_t)(x)) +# define qse_le64toh(x) ((qse_uint64_t)(x)) +# endif + +# if defined(QSE_HAVE_UINT128_T) + +# define qse_hton128(x) qse_bswap128(x) +# define qse_ntoh128(x) qse_bswap128(x) +# define qse_htobe128(x) qse_bswap128(x) +# define qse_be128toh(x) qse_bswap128(x) +# define qse_htole128(x) ((qse_uint128_t)(x)) +# define qse_le128toh(x) ((qse_uint128_t)(x)) +# endif + +#elif defined(QSE_ENDIAN_BIG) + +# if defined(QSE_HAVE_UINT16_T) +# define qse_hton16(x) ((qse_uint16_t)(x)) +# define qse_ntoh16(x) ((qse_uint16_t)(x)) +# define qse_htobe16(x) ((qse_uint16_t)(x)) +# define qse_be16toh(x) ((qse_uint16_t)(x)) +# define qse_htole16(x) qse_bswap16(x) +# define qse_le16toh(x) qse_bswap16(x) +# endif + +# if defined(QSE_HAVE_UINT32_T) +# define qse_hton32(x) ((qse_uint32_t)(x)) +# define qse_ntoh32(x) ((qse_uint32_t)(x)) +# define qse_htobe32(x) ((qse_uint32_t)(x)) +# define qse_be32toh(x) ((qse_uint32_t)(x)) +# define qse_htole32(x) qse_bswap32(x) +# define qse_le32toh(x) qse_bswap32(x) +# endif + +# if defined(QSE_HAVE_UINT64_T) +# define qse_hton64(x) ((qse_uint64_t)(x)) +# define qse_ntoh64(x) ((qse_uint64_t)(x)) +# define qse_htobe64(x) ((qse_uint64_t)(x)) +# define qse_be64toh(x) ((qse_uint64_t)(x)) +# define qse_htole64(x) qse_bswap64(x) +# define qse_le64toh(x) qse_bswap64(x) +# endif + +# if defined(QSE_HAVE_UINT128_T) +# define qse_hton128(x) ((qse_uint128_t)(x)) +# define qse_ntoh128(x) ((qse_uint128_t)(x)) +# define qse_htobe128(x) ((qse_uint128_t)(x)) +# define qse_be128toh(x) ((qse_uint128_t)(x)) +# define qse_htole128(x) qse_bswap128(x) +# define qse_le128toh(x) qse_bswap128(x) +# endif + +#else +# error UNKNOWN ENDIAN #endif #if defined(__cplusplus) diff --git a/qse/include/qse/macros.h b/qse/include/qse/macros.h index 2669f25a..a4584c85 100644 --- a/qse/include/qse/macros.h +++ b/qse/include/qse/macros.h @@ -37,7 +37,7 @@ * This file contains various useful macro definitions. */ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L) +#if defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L)) # define QSE_INLINE inline # define QSE_HAVE_INLINE #elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) @@ -538,6 +538,16 @@ static inline qse_uint32_t QSE_ROTR32 (qse_uint32_t v, int i) #define QSE_HAVE_BUILTIN_CTZLL #endif + #if __has_builtin(__builtin_clz) + #define QSE_HAVE_BUILTIN_CLZ + #endif + #if __has_builtin(__builtin_clzl) + #define QSE_HAVE_BUILTIN_CLZL + #endif + #if __has_builtin(__builtin_clzll) + #define QSE_HAVE_BUILTIN_CLZLL + #endif + #if __has_builtin(__builtin_uadd_overflow) #define QSE_HAVE_BUILTIN_UADD_OVERFLOW #endif @@ -598,6 +608,19 @@ static inline qse_uint32_t QSE_ROTR32 (qse_uint32_t v, int i) #define QSE_HAVE_SYNC_VAL_COMPARE_AND_SWAP #endif + #if __has_builtin(__builtin_bswap16) + #define QSE_HAVE_BUILTIN_BSWAP16 + #endif + #if __has_builtin(__builtin_bswap32) + #define QSE_HAVE_BUILTIN_BSWAP32 + #endif + #if __has_builtin(__builtin_bswap64) + #define QSE_HAVE_BUILTIN_BSWAP64 + #endif + #if __has_builtin(__builtin_bswap128) + #define QSE_HAVE_BUILTIN_BSWAP128 + #endif + #elif defined(__GNUC__) && defined(__GNUC_MINOR__) #if (__GNUC__ >= 5) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) @@ -611,6 +634,11 @@ static inline qse_uint32_t QSE_ROTR32 (qse_uint32_t v, int i) #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) #define QSE_HAVE_BUILTIN_CTZ + #define QSE_HAVE_BUILTIN_CTZL + #define QSE_HAVE_BUILTIN_CTZLL + #define QSE_HAVE_BUILTIN_CLZ + #define QSE_HAVE_BUILTIN_CLZL + #define QSE_HAVE_BUILTIN_CLZLL #define QSE_HAVE_BUILTIN_EXPECT #endif @@ -630,6 +658,16 @@ static inline qse_uint32_t QSE_ROTR32 (qse_uint32_t v, int i) #define QSE_HAVE_BUILTIN_SMULLL_OVERFLOW #endif + #if (__GNUC__ >= 5) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + /* 4.8.0 or later */ + #define QSE_HAVE_BUILTIN_BSWAP16 + #endif + #if (__GNUC__ >= 5) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) + /* 4.3.0 or later */ + #define QSE_HAVE_BUILTIN_BSWAP32 + #define QSE_HAVE_BUILTIN_BSWAP64 + /*#define QSE_HAVE_BUILTIN_BSWAP128*/ + #endif #endif #if defined(QSE_HAVE_BUILTIN_EXPECT) diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 0a784489..faf39f4c 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -772,21 +772,6 @@ void* qse_awk_rtx_getxtn (qse_awk_rtx_t* rtx) return QSE_XTN(rtx); } -qse_awk_t* qse_awk_rtx_getawk (qse_awk_rtx_t* rtx) -{ - return rtx->awk; -} - -qse_mmgr_t* qse_awk_rtx_getmmgr (qse_awk_rtx_t* rtx) -{ - return MMGR(rtx); -} - -qse_cmgr_t* qse_awk_rtx_getcmgr (qse_awk_rtx_t* rtx) -{ - return CMGR(rtx); -} - qse_htb_t* qse_awk_rtx_getnvmap (qse_awk_rtx_t* rtx) { return rtx->named; diff --git a/qse/lib/cmn/hton.c b/qse/lib/cmn/hton.c index e061ac9d..0d193064 100644 --- a/qse/lib/cmn/hton.c +++ b/qse/lib/cmn/hton.c @@ -26,184 +26,4 @@ #include - -/* --------------------------------------------------------------- */ - -#if defined(QSE_HAVE_UINT16_T) - -qse_uint16_t qse_ntoh16 (qse_uint16_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint16_t)( - ((qse_uint16_t)c[0] << 8) | - ((qse_uint16_t)c[1] << 0)); -#else -# error Unknown endian -#endif -} - -qse_uint16_t qse_hton16 (qse_uint16_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint16_t)( - ((qse_uint16_t)c[0] << 8) | - ((qse_uint16_t)c[1] << 0)); -#else -# error Unknown endian -#endif -} - -#endif - -/* --------------------------------------------------------------- */ - -#if defined(QSE_HAVE_UINT32_T) - -qse_uint32_t qse_ntoh32 (qse_uint32_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint32_t)( - ((qse_uint32_t)c[0] << 24) | - ((qse_uint32_t)c[1] << 16) | - ((qse_uint32_t)c[2] << 8) | - ((qse_uint32_t)c[3] << 0)); -#else -# error Unknown endian -#endif -} - -qse_uint32_t qse_hton32 (qse_uint32_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint32_t)( - ((qse_uint32_t)c[0] << 24) | - ((qse_uint32_t)c[1] << 16) | - ((qse_uint32_t)c[2] << 8) | - ((qse_uint32_t)c[3] << 0)); -#else -# error Unknown endian -#endif -} -#endif - -/* --------------------------------------------------------------- */ - -#if defined(QSE_HAVE_UINT64_T) - -qse_uint64_t qse_ntoh64 (qse_uint64_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint64_t)( - ((qse_uint64_t)c[0] << 56) | - ((qse_uint64_t)c[1] << 48) | - ((qse_uint64_t)c[2] << 40) | - ((qse_uint64_t)c[3] << 32) | - ((qse_uint64_t)c[4] << 24) | - ((qse_uint64_t)c[5] << 16) | - ((qse_uint64_t)c[6] << 8) | - ((qse_uint64_t)c[7] << 0)); -#else -# error Unknown endian -#endif -} - -qse_uint64_t qse_hton64 (qse_uint64_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint64_t)( - ((qse_uint64_t)c[0] << 56) | - ((qse_uint64_t)c[1] << 48) | - ((qse_uint64_t)c[2] << 40) | - ((qse_uint64_t)c[3] << 32) | - ((qse_uint64_t)c[4] << 24) | - ((qse_uint64_t)c[5] << 16) | - ((qse_uint64_t)c[6] << 8) | - ((qse_uint64_t)c[7] << 0)); -#else -# error Unknown endian -#endif -} - -#endif - -/* --------------------------------------------------------------- */ - -#if defined(QSE_HAVE_UINT128_T) - -qse_uint128_t qse_ntoh128 (qse_uint128_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint128_t)( - ((qse_uint128_t)c[0] << 120) | - ((qse_uint128_t)c[1] << 112) | - ((qse_uint128_t)c[2] << 104) | - ((qse_uint128_t)c[3] << 96) | - ((qse_uint128_t)c[4] << 88) | - ((qse_uint128_t)c[5] << 80) | - ((qse_uint128_t)c[6] << 72) | - ((qse_uint128_t)c[7] << 64) | - ((qse_uint128_t)c[8] << 56) | - ((qse_uint128_t)c[9] << 48) | - ((qse_uint128_t)c[10] << 40) | - ((qse_uint128_t)c[11] << 32) | - ((qse_uint128_t)c[12] << 24) | - ((qse_uint128_t)c[13] << 16) | - ((qse_uint128_t)c[14] << 8) | - ((qse_uint128_t)c[15] << 0)); -#else -# error Unknown endian -#endif -} - -qse_uint128_t qse_hton128 (qse_uint128_t x) -{ -#if defined(QSE_ENDIAN_BIG) - return x; -#elif defined(QSE_ENDIAN_LITTLE) - qse_uint8_t* c = (qse_uint8_t*)&x; - return (qse_uint128_t)( - ((qse_uint128_t)c[0] << 120) | - ((qse_uint128_t)c[1] << 112) | - ((qse_uint128_t)c[2] << 104) | - ((qse_uint128_t)c[3] << 96) | - ((qse_uint128_t)c[4] << 88) | - ((qse_uint128_t)c[5] << 80) | - ((qse_uint128_t)c[6] << 72) | - ((qse_uint128_t)c[7] << 64) | - ((qse_uint128_t)c[8] << 56) | - ((qse_uint128_t)c[9] << 48) | - ((qse_uint128_t)c[10] << 40) | - ((qse_uint128_t)c[11] << 32) | - ((qse_uint128_t)c[12] << 24) | - ((qse_uint128_t)c[13] << 16) | - ((qse_uint128_t)c[14] << 8) | - ((qse_uint128_t)c[15] << 0)); -#else -# error Unknown endian -#endif -} - -#endif - -/* --------------------------------------------------------------- */ +/* NO CODE HERE. THIS FILE IS JUST A PLACEHOLDER AS OF NOW */