Optimize 128-bit decimal formatting

Chiusa
#5,006 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 8 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
performance

Direzione di ricerca

Start by locating count_digits(native_uint128) and do_format_decimal, then trace how the 64-bit formatter returns the start of its output. Check the existing tests and benchmarks for 128-bit decimal formatting before changing the division path. Done means the proposed operations are removed or replaced without changing formatting results, and benchmarks confirm the performance impact.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hi..

current 128-bit decimal formatting path uses division and modulo by 10^19 to reduce values into 64-bit chunks........ and GCC emits __udivti3 and __udivmodti4 calls for these operations.

During this i found two probably redundant operations - please correct me if i'm wrong or missed a point to review here :

  • count_digits(native_uint128) performs a second 128-bit division when the result is already known to have 39 digits.
  • do_format_decimal counts the remaining digits again, although the 64-bit formatter already returns the start of the formatted output.

so can we remove these redundant operations and replacing division by 10^19 with an exact three-multiply reciprocal implementation .... 10^19 = 2^19 * 5^19.

anyway in my testing GCC (12.2.0)benchmarks show a 14.6% improvement in fmt::format_to for uniformly distributed 128-bit values and 24.8% for the upper 39-digit range.

Lingua principale
C++
Stelle
25.9k
Fork
3.1k
Merge medio
9g 17h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fmtlib/fmt

Tutte le issue di fmtlib/fmt

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.