}
}
-/* bswap THIS. */
-wide_int
-wide_int_storage::bswap () const
+/* Byte swap the integer represented by XVAL and LEN into VAL. Return
+ the number of blocks in VAL. Both XVAL and VAL have PRECISION bits. */
+unsigned int
+wi::bswap_large (HOST_WIDE_INT *val, const HOST_WIDE_INT *xval,
+ unsigned int len, unsigned int precision)
{
- wide_int result = wide_int::create (precision);
unsigned int i, s;
- unsigned int len = BLOCKS_NEEDED (precision);
- unsigned int xlen = get_len ();
- const HOST_WIDE_INT *xval = get_val ();
- HOST_WIDE_INT *val = result.write_val ();
/* This is not a well defined operation if the precision is not a
multiple of 8. */
unsigned int block = s / HOST_BITS_PER_WIDE_INT;
unsigned int offset = s & (HOST_BITS_PER_WIDE_INT - 1);
- byte = (safe_uhwi (xval, xlen, block) >> offset) & 0xff;
+ byte = (safe_uhwi (xval, len, block) >> offset) & 0xff;
block = d / HOST_BITS_PER_WIDE_INT;
offset = d & (HOST_BITS_PER_WIDE_INT - 1);
val[block] |= byte << offset;
}
- result.set_len (canonize (val, len, precision));
- return result;
+ return canonize (val, len, precision);
}
/* Fill VAL with a mask where the lower WIDTH bits are ones and the bits
UNARY_FUNCTION sext (const T &, unsigned int);
UNARY_FUNCTION zext (const T &, unsigned int);
UNARY_FUNCTION set_bit (const T &, unsigned int);
+ UNARY_FUNCTION bswap (const T &);
BINARY_FUNCTION min (const T1 &, const T2 &, signop);
BINARY_FUNCTION smin (const T1 &, const T2 &);
static wide_int from_array (const HOST_WIDE_INT *, unsigned int,
unsigned int, bool = true);
static wide_int create (unsigned int);
-
- /* FIXME: target-dependent, so should disappear. */
- wide_int bswap () const;
};
namespace wi
int cmpu_large (const HOST_WIDE_INT *, unsigned int, unsigned int,
const HOST_WIDE_INT *, unsigned int);
unsigned int sext_large (HOST_WIDE_INT *, const HOST_WIDE_INT *,
- unsigned int,
- unsigned int, unsigned int);
+ unsigned int, unsigned int, unsigned int);
unsigned int zext_large (HOST_WIDE_INT *, const HOST_WIDE_INT *,
- unsigned int,
- unsigned int, unsigned int);
+ unsigned int, unsigned int, unsigned int);
unsigned int set_bit_large (HOST_WIDE_INT *, const HOST_WIDE_INT *,
unsigned int, unsigned int, unsigned int);
+ unsigned int bswap_large (HOST_WIDE_INT *, const HOST_WIDE_INT *,
+ unsigned int, unsigned int);
+
unsigned int lshift_large (HOST_WIDE_INT *, const HOST_WIDE_INT *,
unsigned int, unsigned int, unsigned int);
unsigned int lrshift_large (HOST_WIDE_INT *, const HOST_WIDE_INT *,
return result;
}
+/* Byte swap the integer X.
+ ??? This always swaps 8-bit octets, regardless of BITS_PER_UNIT.
+ This function requires X's precision to be a multiple of 16 bits,
+ so care needs to be taken for targets where BITS_PER_UNIT != 8. */
+template <typename T>
+inline WI_UNARY_RESULT (T)
+wi::bswap (const T &x)
+{
+ WI_UNARY_RESULT_VAR (result, val, T, x);
+ unsigned int precision = get_precision (result);
+ WIDE_INT_REF_FOR (T) xi (x, precision);
+ result.set_len (bswap_large (val, xi.val, xi.len, precision));
+ return result;
+}
+
/* Return the mininum of X and Y, treating them both as having
signedness SGN. */
template <typename T1, typename T2>