1  /* Typedefs for polynomial integers used in GCC.
       2     Copyright (C) 2016-2023 Free Software Foundation, Inc.
       3  
       4  This file is part of GCC.
       5  
       6  GCC is free software; you can redistribute it and/or modify it under
       7  the terms of the GNU General Public License as published by the Free
       8  Software Foundation; either version 3, or (at your option) any later
       9  version.
      10  
      11  GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12  WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14  for more details.
      15  
      16  You should have received a copy of the GNU General Public License
      17  along with GCC; see the file COPYING3.  If not see
      18  <http://www.gnu.org/licenses/>.  */
      19  
      20  #ifndef HAVE_POLY_INT_TYPES_H
      21  #define HAVE_POLY_INT_TYPES_H
      22  
      23  typedef poly_int_pod<NUM_POLY_INT_COEFFS, unsigned short> poly_uint16_pod;
      24  typedef poly_int_pod<NUM_POLY_INT_COEFFS, HOST_WIDE_INT> poly_int64_pod;
      25  typedef poly_int_pod<NUM_POLY_INT_COEFFS,
      26  		     unsigned HOST_WIDE_INT> poly_uint64_pod;
      27  typedef poly_int_pod<NUM_POLY_INT_COEFFS, offset_int> poly_offset_int_pod;
      28  typedef poly_int_pod<NUM_POLY_INT_COEFFS, wide_int> poly_wide_int_pod;
      29  typedef poly_int_pod<NUM_POLY_INT_COEFFS, widest_int> poly_widest_int_pod;
      30  
      31  typedef poly_int<NUM_POLY_INT_COEFFS, unsigned short> poly_uint16;
      32  typedef poly_int<NUM_POLY_INT_COEFFS, HOST_WIDE_INT> poly_int64;
      33  typedef poly_int<NUM_POLY_INT_COEFFS, unsigned HOST_WIDE_INT> poly_uint64;
      34  typedef poly_int<NUM_POLY_INT_COEFFS, offset_int> poly_offset_int;
      35  typedef poly_int<NUM_POLY_INT_COEFFS, wide_int> poly_wide_int;
      36  typedef poly_int<NUM_POLY_INT_COEFFS, wide_int_ref> poly_wide_int_ref;
      37  typedef poly_int<NUM_POLY_INT_COEFFS, widest_int> poly_widest_int;
      38  
      39  /* Divide bit quantity X by BITS_PER_UNIT and round down (towards -Inf).
      40     If X is a bit size, this gives the number of whole bytes spanned by X.
      41  
      42     This is safe because non-constant mode sizes must be a whole number
      43     of bytes in size.  */
      44  #define bits_to_bytes_round_down(X) force_align_down_and_div (X, BITS_PER_UNIT)
      45  
      46  /* Divide bit quantity X by BITS_PER_UNIT and round up (towards +Inf).
      47     If X is a bit size, this gives the number of whole or partial bytes
      48     spanned by X.
      49  
      50     This is safe because non-constant mode sizes must be a whole number
      51     of bytes in size.  */
      52  #define bits_to_bytes_round_up(X) force_align_up_and_div (X, BITS_PER_UNIT)
      53  
      54  /* Return the number of bits in bit quantity X that do not belong to
      55     whole bytes.  This is equivalent to:
      56  
      57         X - bits_to_bytes_round_down (X) * BITS_PER_UNIT
      58  
      59     This is safe because non-constant mode sizes must be a whole number
      60     of bytes in size.  */
      61  #define num_trailing_bits(X) force_get_misalignment (X, BITS_PER_UNIT)
      62  
      63  /* Round bit quantity X down to the nearest byte boundary.
      64  
      65     This is safe because non-constant mode sizes must be a whole number
      66     of bytes in size.  */
      67  #define round_down_to_byte_boundary(X) force_align_down (X, BITS_PER_UNIT)
      68  
      69  /* Round bit quantity X up the nearest byte boundary.
      70  
      71     This is safe because non-constant mode sizes must be a whole number
      72     of bytes in size.  */
      73  #define round_up_to_byte_boundary(X) force_align_up (X, BITS_PER_UNIT)
      74  
      75  /* Return the size of an element in a vector of size SIZE, given that
      76     the vector has NELTS elements.  The return value is in the same units
      77     as SIZE (either bits or bytes).
      78  
      79     to_constant () is safe in this situation because vector elements are
      80     always constant-sized scalars.  */
      81  #define vector_element_size(SIZE, NELTS) \
      82    (exact_div (SIZE, NELTS).to_constant ())
      83  
      84  /* Return the number of unroll times when a vector that has NELTS1 elements
      85     is unrolled to vectors that have NELTS2 elements.
      86  
      87     to_constant () is safe in this situation because the multiples of the
      88     NELTS of two vectors are always constant-size scalars.  */
      89  #define vector_unroll_factor(NELTS1, NELTS2) \
      90    (exact_div (NELTS1, NELTS2).to_constant ())
      91  
      92  /* Wrapper for poly_int arguments to target macros, so that if a target
      93     doesn't need polynomial-sized modes, its header file can continue to
      94     treat the argument as a normal constant.  This should go away once
      95     macros are moved to target hooks.  It shouldn't be used in other
      96     contexts.  */
      97  #if NUM_POLY_INT_COEFFS == 1
      98  #define MACRO_INT(X) ((X).to_constant ())
      99  #else
     100  #define MACRO_INT(X) (X)
     101  #endif
     102  
     103  #endif