/* Convert a signed 32-bit integer to a signed n-bit integer.  */
static u32 s32ton(__s32 value, unsigned n)
/* Convert a signed 32-bit integer to a signed n-bit integer.  */
static u32 s32ton(__s32 value, unsigned n)
{
	s32 a = value >> (n - 1);
	if (a && a != -1)
		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
	return value & ((1 << n) - 1);
}