GCC rejects constexpr operations on cpp_int (> double_limb_type) initialized from a double_limb_type integer

Abierto
#768 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
cpp
Área
backend

Línea de trabajo

Comience en include/boost/multiprecision/cpp_int.hpp, en los casos de constructor alrededor de las líneas 231-235, 583-588 y 776-781. Compile el reproductor mínimo con GCC y confirme que el caso existente de 128-bit sigue funcionando, mientras que los casos de cpp_int fijo más amplios fallan. El trabajo estará terminado cuando los constexpr static_asserts para tipos más amplios compilen correctamente, con pruebas de regresión que cubran los casos de inicialización y aritmética indicados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Currently, gcc is rejecting to compile constexpr operations on fixed cpp_ints wider than double_limb_type. It says that the current initialized field is m_double_first_limb, even after we initialize m_data:

Here
https://github.com/boostorg/multiprecision/blob/df89bfdef1d7c6d4c142a8f8ef9dbb38286c7122/include/boost/multiprecision/cpp_int.hpp#L583-L588

And here
https://github.com/boostorg/multiprecision/blob/df89bfdef1d7c6d4c142a8f8ef9dbb38286c7122/include/boost/multiprecision/cpp_int.hpp#L776-L781

There's also this one, but it will only be an issue with constexpr dynamic allocations, I can fix it here or I can fix it at my PR #654. I also think the BOOST_MP_ENDIAN_LITTLE_BYTE check will not be needed anymore as the split will be explicit as in the other cases

https://github.com/boostorg/multiprecision/blob/df89bfdef1d7c6d4c142a8f8ef9dbb38286c7122/include/boost/multiprecision/cpp_int.hpp#L231-L235

Below is a minimal reproducible example

#include <boost/multiprecision/cpp_int.hpp>


template <int Bits>
inline constexpr auto repro = [] constexpr noexcept {
  namespace mp = boost::multiprecision;

  using ubits_t = mp::number<
    mp::cpp_int_backend<Bits, Bits, mp::unsigned_magnitude, mp::unchecked, void>,
    // also happens for mp::et_on
    mp::et_off
  >;

  ubits_t x = static_cast<unsigned __int128>(0);
  // ubits_t x = 0U;  // does not fail

  // x *= x;  // multiplication also fails
  x += x;
  return x;
}();

// DOES NOT FAIL
// static_assert(repro<128> == 0);

// FAIL
static_assert(repro<129> == 0);
// static_assert(repro<192> == 0);
// static_assert(repro<512> == 0);

Here's a link to compiler explorer. You can see that this is GCC only as clang works fine.

The solution is a simple change on how the cpp_ints are constructed on the m_double_first_limb (initialize m_data instead of m_double_first_limb on all cases). I can open a PR (with regression tests) if needed (I have a working version here that I used to locate the issue).

Lenguaje dominante
C++
Estrellas
268
Forks
130
Merge medio
1 d 15 h
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de boostorg/multiprecision

Todos los issues de boostorg/multiprecision

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.