crypto: Keep the safegcd 128-bit sums out of intx::uint128

Abierto
#1,808 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp

Línea de trabajo

Read modarith.cpp and compare the safegcd matrix sum helpers with the two options described in the issue. First check the intx dependency status for chfast/intx#374 and whether it changes the addmul() workaround in #1803; otherwise, assess using unsigned __int128 under INTX_HAS_BUILTIN_INT128 while retaining the existing helpers for 32-bit targets. Done means the chosen approach preserves 32-bit support and is checked against the reported inversion benchmarks.

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

Descripción

The safegcd inversion (#1806) accumulates its matrix products in intx::uint128. GCC splits their carry chains (20 setb in modinv_scaled<uint256>) and keeps the sums partly in stack slots, the same problem as #1801.

Per inversion, Zen 3, random inputs over 4 moduli:

GCC 16 Clang 23
intx v0.15.0 (current) 4640 cycles 4119 cycles
intx master, with chfast/intx#374 (builtin add/sub for GCC, unreleased) −2.2% ±0
intx master, helpers using builtin signed multiply and shift −4.8% +0.8%
sums as unsigned __int128 −5.9% −3.4%

Options:

  1. Release intx with chfast/intx#374 and upgrade it here. Check whether this also makes the GCC workaround in addmul() (#1803) unnecessary.
  2. In modarith.cpp, use unsigned __int128 for the sums when INTX_HAS_BUILTIN_INT128, keeping the intx::uint128 helpers for 32-bit targets. This needs a second set of the 128-bit helpers:
#if INTX_HAS_BUILTIN_INT128
using Int128 = intx::builtin_uint128;  // Two's complement.
uint64_t lo(Int128 x) noexcept { return static_cast<uint64_t>(x); }
uint64_t hi(Int128 x) noexcept { return static_cast<uint64_t>(x >> 64); }
Int128 mul_su(int64_t a, uint64_t b) noexcept
{
    return Int128{static_cast<uint64_t>(a)} * b - (Int128{b & static_cast<uint64_t>(a >> 63)} << 64);
}
Int128 mul_ss(int64_t a, int64_t b) noexcept { return static_cast<Int128>(static_cast<__int128>(a) * b); }
Int128 sar64(Int128 x) noexcept { return static_cast<Int128>(static_cast<__int128>(x) >> 64); }
Int128 sext(int64_t x) noexcept { return static_cast<Int128>(static_cast<__int128>(x)); }
#else
// The current intx::uint128 versions.
#endif

A single generic version, with only the type alias under #if, gives −2.1% (GCC) and −1.7% (Clang). The rest of the gap cannot be closed in intx without changing the storage of uint<128>, whose constexpr word access needs the two uint64_t words.

Lenguaje dominante
C++
Estrellas
979
Forks
340
Merge medio
12 h 16 min
PR fusionados (30 d)
25

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

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 ipsilon/evmone

Todos los issues de ipsilon/evmone

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.