Hello, everyone.
I'm looking for an efficient implementation of functions like memcpy, memset, etc. Is there anything like that available? I don't need a full C library, just the memory/string code.
Thanks in advance
Looking for an efficient string implementation.
Looking for an efficient string implementation.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: Looking for an efficient string implementation.
The most efficient, and easily obtained, implementation are the compiler builtins. Check your compiler manual for details; it is very unlikely a homegrown implementation can beat those.
Every good solution is obvious once you've found it.
-
- Member
- Posts: 5587
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Looking for an efficient string implementation.
Perhaps these optimized subroutines are what you are looking for? The code is GPL, so that may affect whether or not you can use it.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Looking for an efficient string implementation.
The most space-efficient implementations are the REP ~~~~ opcodes, which cover a good deal of the mem/str functionality in single instructions. It scores the same lack of portability points as using compiler-specific builtins though, so if that is an issue you might want to use a proper C implementation anyway, and let the compiler optimise it based on your architectural constraints.
Re: Looking for an efficient string implementation.
+1 on using compiler builtins. I optimized a program to run in half the time by replacing std::string::find(X) with strstr(str.c_str(), X); because the former does not resolve to a builtin and the latter does.Solar wrote:The most efficient, and easily obtained, implementation are the compiler builtins. Check your compiler manual for details; it is very unlikely a homegrown implementation can beat those.
Re: Looking for an efficient string implementation.
There's a code on the forum, I've got my mem* functions from it. I don't remember that thread, but see code in my repo - string.h.Roman wrote:Hello, everyone.
I'm looking for an efficient implementation of functions like memcpy, memset, etc. Is there anything like that available? I don't need a full C library, just the memory/string code.
Thanks in advance
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: Looking for an efficient string implementation.
Thanks everyone for the answers.
Regarding other answers,
1) a permissive license would be preferred, but I will have a look at that GPL code;
2) what do you mean by using compiler builtins? LLVM in my case (Rust, armv7) just inserts calls to memcpy.
Your code is just generic C code, I could implement that myself. What I'm looking for is an efficient architecture-optimized code.catnikita255 wrote:There's a code on the forum, I've got my mem* functions from it. I don't remember that thread, but see code in my repo - string.h.Roman wrote:Hello, everyone.
I'm looking for an efficient implementation of functions like memcpy, memset, etc. Is there anything like that available? I don't need a full C library, just the memory/string code.
Thanks in advance
Regarding other answers,
1) a permissive license would be preferred, but I will have a look at that GPL code;
2) what do you mean by using compiler builtins? LLVM in my case (Rust, armv7) just inserts calls to memcpy.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: Looking for an efficient string implementation.
Most compilers offer build-in implementations of the basic memory functions that are highly optimized already. Seeing how much of the code generated by the compiler deals with moving memory around, that is only logical. Since this code ends up in EVERY binary anyway, it is usually exempt from the licensing scheme of the compiler itself.
I don't know the specifics for ARM / LLVM, but builtins are definitely what you are looking for. They are usually named like __memcpy, __builtin_memcpy or something like that.
I don't know the specifics for ARM / LLVM, but builtins are definitely what you are looking for. They are usually named like __memcpy, __builtin_memcpy or something like that.
Every good solution is obvious once you've found it.