From a4b6748cb5eaa6a9269f4437fc31230b893cd03a Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Tue, 23 Jul 2019 14:20:31 +0800 Subject: [PATCH] new: meet armv7 bus alignment requirements fixed: ambiguous variable names. --- ikcp.c | 12 ++++++------ ikcp.h | 13 ++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ikcp.c b/ikcp.c index bb1a0c6..42e3a18 100644 --- a/ikcp.c +++ b/ikcp.c @@ -66,7 +66,7 @@ static inline const char *ikcp_decode8u(const char *p, unsigned char *c) /* encode 16 bits unsigned int (lsb) */ static inline char *ikcp_encode16u(char *p, unsigned short w) { -#if IWORDS_BIG_ENDIAN +#if IWORDS_BIG_ENDIAN || IWORDS_MUST_ALIGN *(unsigned char*)(p + 0) = (w & 255); *(unsigned char*)(p + 1) = (w >> 8); #else @@ -79,7 +79,7 @@ static inline char *ikcp_encode16u(char *p, unsigned short w) /* decode 16 bits unsigned int (lsb) */ static inline const char *ikcp_decode16u(const char *p, unsigned short *w) { -#if IWORDS_BIG_ENDIAN +#if IWORDS_BIG_ENDIAN || IWORDS_MUST_ALIGN *w = *(const unsigned char*)(p + 1); *w = *(const unsigned char*)(p + 0) + (*w << 8); #else @@ -92,7 +92,7 @@ static inline const char *ikcp_decode16u(const char *p, unsigned short *w) /* encode 32 bits unsigned int (lsb) */ static inline char *ikcp_encode32u(char *p, IUINT32 l) { -#if IWORDS_BIG_ENDIAN +#if IWORDS_BIG_ENDIAN || IWORDS_MUST_ALIGN *(unsigned char*)(p + 0) = (unsigned char)((l >> 0) & 0xff); *(unsigned char*)(p + 1) = (unsigned char)((l >> 8) & 0xff); *(unsigned char*)(p + 2) = (unsigned char)((l >> 16) & 0xff); @@ -107,7 +107,7 @@ static inline char *ikcp_encode32u(char *p, IUINT32 l) /* decode 32 bits unsigned int (lsb) */ static inline const char *ikcp_decode32u(const char *p, IUINT32 *l) { -#if IWORDS_BIG_ENDIAN +#if IWORDS_BIG_ENDIAN || IWORDS_MUST_ALIGN *l = *(const unsigned char*)(p + 3); *l = *(const unsigned char*)(p + 2) + (*l << 8); *l = *(const unsigned char*)(p + 1) + (*l << 8); @@ -741,7 +741,7 @@ void ikcp_parse_data(ikcpcb *kcp, IKCPSEG *newseg) //--------------------------------------------------------------------- int ikcp_input(ikcpcb *kcp, const char *data, long size) { - IUINT32 una = kcp->snd_una; + IUINT32 prev_una = kcp->snd_una; IUINT32 maxack = 0; int flag = 0; @@ -856,7 +856,7 @@ int ikcp_input(ikcpcb *kcp, const char *data, long size) ikcp_parse_fastack(kcp, maxack); } - if (_itimediff(kcp->snd_una, una) > 0) { + if (_itimediff(kcp->snd_una, prev_una) > 0) { if (kcp->cwnd < kcp->rmt_wnd) { IUINT32 mss = kcp->mss; if (kcp->cwnd < kcp->ssthresh) { diff --git a/ikcp.h b/ikcp.h index 866d188..5652ae2 100644 --- a/ikcp.h +++ b/ikcp.h @@ -225,7 +225,7 @@ typedef struct IQUEUEHEAD iqueue_head; //--------------------------------------------------------------------- -// WORD ORDER +// BYTE ORDER & ALIGNMENT //--------------------------------------------------------------------- #ifndef IWORDS_BIG_ENDIAN #ifdef _BIG_ENDIAN_ @@ -248,6 +248,17 @@ typedef struct IQUEUEHEAD iqueue_head; #endif #endif +#ifndef IWORDS_MUST_ALIGN + #if defined(__i386__) || defined(__i386) || defined(_i386_) + #define IWORDS_MUST_ALIGN 0 + #elif defined(_M_IX86) || defined(_X86_) || defined(__x86_64__) + #define IWORDS_MUST_ALIGN 0 + #elif defined(__amd64) || defined(__amd64__) + #define IWORDS_MUST_ALIGN 0 + #else + #define IWORDS_MUST_ALIGN 1 + #endif +#endif //=====================================================================