Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib, stdio: improve float string parsing #370

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

jmaksymowicz
Copy link
Contributor

Description

  • strtof, strtod and strtold can parse infinity and NaN string representations, as well as hexadecimal floating point representations
  • Code size was reduced by extracting operations done multiple times into functions.
  • Performance of strtof and strtod was improved. Now uint64_t is used as an intermediate container for digits that were read, instead of long double used previously. This reduces the number of long double multiplications necessary.
  • Reading of floating point numbers in scanf was reworked, fixing some bugs and improving performance (e.g. previously the conversion was performed twice, with one result being discarded).
  • Fix buffer over-read bug in scanf for %c format.

Motivation and Context

Fix phoenix-rtos/phoenix-rtos-project#634, phoenix-rtos/phoenix-rtos-project#657, phoenix-rtos/phoenix-rtos-project#703, phoenix-rtos/phoenix-rtos-project#704, phoenix-rtos/phoenix-rtos-project#652, phoenix-rtos/phoenix-rtos-project#1116

Partially fix phoenix-rtos/phoenix-rtos-project#681 (supports width specifier for "%f" up to 31)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: ia32-generic-qemu

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

Copy link

github-actions bot commented Jul 23, 2024

Unit Test Results

7 949 tests  ±0   7 231 ✅ ±0   40m 11s ⏱️ -7s
  461 suites ±0     718 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 7b6fa8f. ± Comparison against base commit c6a334b.

♻️ This comment has been updated with latest results.

@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/float-parsing branch from 13adb84 to 216557c Compare August 2, 2024 09:17
stdlib/strtod.c Outdated Show resolved Hide resolved
@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/float-parsing branch from 216557c to 5a267af Compare August 2, 2024 10:20
@jmaksymowicz jmaksymowicz changed the title WIP stdlib, stdio: improve float string parsing stdlib, stdio: improve float string parsing Aug 2, 2024
@jmaksymowicz jmaksymowicz requested a review from Darchiv August 13, 2024 10:09
Copy link
Member

@Darchiv Darchiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments.

Tests related to the fixed issues are disabled (https://github.com/phoenix-rtos/phoenix-rtos-tests/blob/master/libc/stdlib/stdlib_strto.c#L68 - all #ifdefs for 703 and 704 issues) and can be enabled now.

stdlib/strtod.c Outdated Show resolved Hide resolved
stdlib/strtod.c Outdated Show resolved Hide resolved
stdlib/strtod.c Outdated Show resolved Hide resolved
stdlib/strtod.c Show resolved Hide resolved
stdlib/strtod.c Outdated Show resolved Hide resolved
stdlib/strtod.c Show resolved Hide resolved
stdlib/strtod.c Outdated Show resolved Hide resolved
stdlib/strtod.c Outdated Show resolved Hide resolved
stdlib/strtod.c Show resolved Hide resolved
@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/float-parsing branch from 4f99eaa to 7e510ae Compare November 6, 2024 16:36
Darchiv
Darchiv previously approved these changes Nov 7, 2024
Add parsing of infinity and NaN strings.
Add parsing of hexadecimal floating point numbers.
Improve performance and reduce code size.

JIRA: RTOS-868
Parse input string directly instead of copying it to a buffer unless
necessary.
Perform conversion once instead of twice.

JIRA: RTOS-868
Over-read was possible if width was greater than remaining input length
when using %c format.

JIRA: RTOS-868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scanf doesn't support output size modifiers. Scanf Inf and Nan handling problem
2 participants