new: meet armv7 bus alignment requirements

fixed: ambiguous variable names.
This commit is contained in:
skywind3000 2019-07-23 14:20:31 +08:00
parent 19dbf3af05
commit a4b6748cb5
2 changed files with 18 additions and 7 deletions

12
ikcp.c
View File

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

13
ikcp.h
View File

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