/* Decode a (16-bit, signed or unsigned) short. */ uint sdecodeushort(const byte * p, int format) { int a = p[0], b = p[1]; return (num_is_lsb(format) ? (b << 8) + a : (a << 8) + b); }
/* to work around a gcc 4.2.1 bug on PowerPC, bug 689586 */ static void sdecodebits32(const byte * p, int format, bits32 *v) { int a = p[0], b = p[1], c = p[2], d = p[3]; *v = (num_is_lsb(format) ? ((long)d << 24) + ((long)c << 16) + (b << 8) + a : ((long)a << 24) + ((long)b << 16) + (c << 8) + d); }
/* Decode a (32-bit, signed) long. */ int sdecodeint32(const byte * p, int format) { int a = p[0], b = p[1], c = p[2], d = p[3]; int v = (num_is_lsb(format) ? ((int)d << 24) + ((int)c << 16) + (b << 8) + a : ((int)a << 24) + ((int)b << 16) + (c << 8) + d); return v; }
/* Decode a (16-bit, signed) short. */ short sdecodeshort(register const byte *p, int format) { int a = p[0], b = p[1]; short v = (num_is_lsb(format) ? (b << 8) + a : (a << 8) + b); #if arch_sizeof_short == 2 return v; #else /* Sign-extend if sizeof(short) > 2. */ return (v & 0x7fff) - (v & 0x8000); #endif }
/* Decode a (32-bit, signed) long. */ long sdecodelong(register const byte *p, int format) { int a = p[0], b = p[1], c = p[2], d = p[3]; long v = (num_is_lsb(format) ? ((long)d << 24) + ((long)c << 16) + (b << 8) + a : ((long)a << 24) + ((long)b << 16) + (c << 8) + d); #if arch_sizeof_long == 4 return v; #else /* Sign-extend if sizeof(long) > 4. */ return (v & 0x7fffffffL) - (v & 0x80000000L); #endif }
/* Decode a (32-bit, signed) long. */ int32_t sdecodelong(const byte * p, int format) { int a = p[0], b = p[1], c = p[2], d = p[3]; int32_t v = (num_is_lsb(format) ? ((int32_t)d << 24) + ((int32_t)c << 16) + (b << 8) + a : ((int32_t)a << 24) + ((int32_t)b << 16) + (c << 8) + d); #if arch_sizeof_long > 4 /* Propagate bit 31 as the sign. */ v = (v ^ 0x80000000L) - 0x80000000L; #endif return v; }