From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D6A393858405; Thu, 16 Dec 2021 21:31:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6A393858405 From: "fxcoudert at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/98076] Increase speed of integer I/O Date: Thu, 16 Dec 2021 21:31:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: fxcoudert at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Dec 2021 21:31:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98076 Francois-Xavier Coudert changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |fxcoudert at gcc dot gnu.o= rg --- Comment #4 from Francois-Xavier Coudert = --- Benchmarking of the formatting of 100 million times a value of the order of medium-sized number (INT_MAX/2) by gfc_itoa. On the 64-bit target I have at hand (aarch64-apple-darwin), depending on whether the function is implement= ed as: __int128 : 3.91 seconds int64_t : 0.86 seconds int32_t : 0.84 seconds __int128 relies on a function call of the division (___divti3), others don'= t. This would allow for a very simple optimisation, that does not require to change the current I/O workflow, i.e., passing all integer values as the largest type (usually int128_t): - have a fast itoa64() function that takes an uint64_t arg - have gfc_itoa() call itoa64() if the argument fits - otherwise, divide by a large power of ten, and recursively apply itoa64() For small values, itoa64() will be called once per gfc_itoa() call. Worst c= ase behaviour (very large 128-bit values) is 2 division calls to itoa64(), whic= h is still faster than doing the 38 128-bit divisions in the current version.=