From 0ede6b5ad77c4791a513ab312b9e278dafc2bff9 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Wed, 31 May 2023 23:40:11 +0100 Subject: Refactor wi::bswap as a function (instead of a method). This patch implements Richard Sandiford's suggestion from https://gcc.gnu.org/pipermail/gcc-patches/2023-May/618215.html that wi::bswap (and a new wi::bitreverse) should be functions, and ideally only accessors are member functions. This patch implements the first step, moving/refactoring wi::bswap. 2023-05-31 Roger Sayle Richard Sandiford gcc/ChangeLog * fold-const-call.cc (fold_const_call_ss) : Update call to wi::bswap. * simplify-rtx.cc (simplify_const_unary_operation) : Update call to wi::bswap. * tree-ssa-ccp.cc (evaluate_stmt) : Update calls to wi::bswap. * wide-int.cc (wide_int_storage::bswap): Remove/rename to... (wi::bswap_large): New function, with revised API. * wide-int.h (wi::bswap): New (template) function prototype. (wide_int_storage::bswap): Remove method. (sext_large, zext_large): Consistent indentation/line wrapping. (bswap_large): Prototype helper function containing implementation. (wi::bswap): New template wrapper around bswap_large. --- gcc/wide-int.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'gcc/wide-int.cc') diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc index c0987aa..1e4c046 100644 --- a/gcc/wide-int.cc +++ b/gcc/wide-int.cc @@ -731,16 +731,13 @@ wi::set_bit_large (HOST_WIDE_INT *val, const HOST_WIDE_INT *xval, } } -/* 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. */ @@ -758,7 +755,7 @@ wide_int_storage::bswap () const 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); @@ -766,8 +763,7 @@ wide_int_storage::bswap () const 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 -- cgit v1.1