Skip to content

Improve strlen #213

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

Merged
merged 2 commits into from
Jun 3, 2025
Merged

Improve strlen #213

merged 2 commits into from
Jun 3, 2025

Conversation

jserv
Copy link
Collaborator

@jserv jserv commented Jun 3, 2025

The original loop had to check, increment, and jump for every single character. The new loop does this for every 4 characters.

It can load a full 32-bit word directly once 'unsigned' is implemented properly later.

Summary by Bito

This pull request enhances the performance of the strlen function in lib/c.c by processing four characters at a time, improving string handling efficiency. Minor adjustments were also made to the Makefile for clearer compiler flag settings, optimizing performance while ensuring code readability.

@jserv jserv force-pushed the improve-strlen branch 7 times, most recently from 8d45e91 to 09d361a Compare June 3, 2025 10:50
Replace character-by-character iteration with 4-character blocks,
reducing check/increment/jump operations. Prepared for future 32-bit
word loading once unsigned type support is complete.
@jserv jserv force-pushed the improve-strlen branch from b85cda3 to b92b136 Compare June 3, 2025 11:04
Suppress compilation warnings that occur when characters with values
> 127 are assigned to char variables on x86 platforms. Since x86(-64)
treats char as signed by default and there is no 'unsigned' support at
the moment, these assignments trigger signedness warnings. This commit
adds a compiler option to suppress these warnings.
@jserv jserv force-pushed the improve-strlen branch from b92b136 to d510ca4 Compare June 3, 2025 11:11
@jserv jserv merged commit 4f35440 into master Jun 3, 2025
12 checks passed
@jserv jserv deleted the improve-strlen branch June 3, 2025 11:14
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.

1 participant