prove coversion speed
This commit is contained in:
parent
60e056a2cb
commit
3031aeb9dd
|
@ -14,25 +14,12 @@
|
||||||
|
|
||||||
INLINE int bytesToInt_bigEndian(unsigned char* bytes)
|
INLINE int bytesToInt_bigEndian(unsigned char* bytes)
|
||||||
{
|
{
|
||||||
int temp = 0;
|
int res;
|
||||||
int res = 0;
|
unsigned char* des = (unsigned char*)&res;
|
||||||
|
des[0] = bytes[3];
|
||||||
res <<= 8;
|
des[1] = bytes[2];
|
||||||
temp = bytes[0] & 0xff;
|
des[2] = bytes[1];
|
||||||
res |= temp;
|
des[3] = bytes[0];
|
||||||
|
|
||||||
res <<= 8;
|
|
||||||
temp = bytes[1] & 0xff;
|
|
||||||
res |= temp;
|
|
||||||
|
|
||||||
res <<= 8;
|
|
||||||
temp = bytes[2] & 0xff;
|
|
||||||
res |= temp;
|
|
||||||
|
|
||||||
res <<= 8;
|
|
||||||
temp = bytes[3] & 0xff;
|
|
||||||
res |= temp;
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,20 +29,18 @@ INLINE int bytesToInt_bigEndian(unsigned char* bytes)
|
||||||
* */
|
* */
|
||||||
INLINE void intToBytes_bigEndian(unsigned char *b, unsigned int num)
|
INLINE void intToBytes_bigEndian(unsigned char *b, unsigned int num)
|
||||||
{
|
{
|
||||||
b[0] = (unsigned char)(num >> 24);
|
unsigned char* sou =(unsigned char*)#
|
||||||
b[1] = (unsigned char)(num >> 16);
|
b[0] = sou[3];
|
||||||
b[2] = (unsigned char)(num >> 8);
|
b[1] = sou[2];
|
||||||
b[3] = (unsigned char)(num);
|
b[2] = sou[1];
|
||||||
|
b[3] = sou[0];
|
||||||
//note: num >> xxx already considered endian_type...
|
|
||||||
//if(dataEndianType==LITTLE_ENDIAN_DATA)
|
|
||||||
// symTransform_4bytes(*b); //change to BIG_ENDIAN_DATA
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @endianType: refers to the endian_type of unsigned char* b.
|
* @endianType: refers to the endian_type of unsigned char* b.
|
||||||
* */
|
* */
|
||||||
INLINE long bytesToLong_bigEndian(unsigned char* b) {
|
INLINE long bytesToLong_bigEndian(unsigned char* b) {
|
||||||
|
|
||||||
long temp = 0;
|
long temp = 0;
|
||||||
long res = 0;
|
long res = 0;
|
||||||
|
|
||||||
|
@ -92,25 +77,29 @@ INLINE long bytesToLong_bigEndian(unsigned char* b) {
|
||||||
res |= temp;
|
res |= temp;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE void longToBytes_bigEndian(unsigned char *b, unsigned long num)
|
INLINE void longToBytes_bigEndian(unsigned char *b, long num)
|
||||||
{
|
{
|
||||||
// arm32
|
unsigned char* sou = (unsigned char*)#
|
||||||
#if defined(_TD_LINUX_64) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
|
#if defined(_TD_LINUX_64) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
|
||||||
b[0] = (unsigned char)(num>>56);
|
// 8 bytes
|
||||||
b[1] = (unsigned char)(num>>48);
|
b[7] = sou[0];
|
||||||
b[2] = (unsigned char)(num>>40);
|
b[6] = sou[1];
|
||||||
b[3] = (unsigned char)(num>>32);
|
b[5] = sou[2];
|
||||||
|
b[4] = sou[3];
|
||||||
|
b[3] = sou[4];
|
||||||
|
b[2] = sou[5];
|
||||||
|
b[1] = sou[6];
|
||||||
|
b[0] = sou[7];
|
||||||
#else
|
#else
|
||||||
memset(b, 0, 4);
|
memset(b, 0, 4);
|
||||||
|
b[7] = sou[0];
|
||||||
|
b[6] = sou[1];
|
||||||
|
b[5] = sou[2];
|
||||||
|
b[4] = sou[3];
|
||||||
#endif
|
#endif
|
||||||
b[4] = (unsigned char)(num>>24);
|
|
||||||
b[5] = (unsigned char)(num>>16);
|
|
||||||
b[6] = (unsigned char)(num>>8);
|
|
||||||
b[7] = (unsigned char)(num);
|
|
||||||
// if(dataEndianType==LITTLE_ENDIAN_DATA)
|
|
||||||
// symTransform_8bytes(*b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: debug: lfBuf.lvalue could be actually little_endian....
|
//TODO: debug: lfBuf.lvalue could be actually little_endian....
|
||||||
|
@ -135,9 +124,6 @@ INLINE short getPrecisionReqLength_float(float precision)
|
||||||
|
|
||||||
int expValue = (ivalue & 0x7F800000) >> 23;
|
int expValue = (ivalue & 0x7F800000) >> 23;
|
||||||
expValue -= 127;
|
expValue -= 127;
|
||||||
// unsigned char the1stManBit = (unsigned char)((ivalue & 0x00400000) >> 22);
|
|
||||||
// if(the1stManBit==1)
|
|
||||||
// expValue--;
|
|
||||||
return (short)expValue;
|
return (short)expValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue