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

Reference implementation of Blake3 for generic 16/32/64 bit CPUs? #364

Open
G8TIC opened this issue Nov 25, 2023 · 3 comments
Open

Reference implementation of Blake3 for generic 16/32/64 bit CPUs? #364

G8TIC opened this issue Nov 25, 2023 · 3 comments

Comments

@G8TIC
Copy link

G8TIC commented Nov 25, 2023

While BLAKE3 is fantastic in terms of performance and optimisations across CPUs and operating systems with support for SSE, AVX, NEON etc. there doesn't appear to be a generic implementation, i.e. a non-optimised version that just works on any CPU, for example STM32, ESP32, ESP8266, ArmHF, i386 or anything else released in the last 25-30 years...

Can we have a "reference implementation" of BLAKE3 with just two files "blake3.c" and "blake3.h" that is written in pure C and compiles on any hardware with uint32_t and C99?

To me, the "refrence implementation" should come with a test harness and test vectors and should be the basis of an RFC for what looks to be a solid foundation. The optimised versions could be derivatives of the reference implementation...

A reference "baseline" implementation would be of huge benefit to low bandwidth and IoT type applications where the complexities of libraries and hand-crafted assembler optimisations are either not appropriate or warranted.

@oconnor663
Copy link
Member

The C and Rust implementations of BLAKE3 should both be portable to ~any CPU. The portable implementations are blake3_portable.c and portable.rs. You might also be interested in the reference_impl.

@BurningEnlightenment
Copy link
Collaborator

There is a pure C99 implementation in c/blake3_portable.c. It shares infrastructure/some code with the various SIMD implementations, but I don't see why that'd be a problem. Sure, it isn't condensed in one TU, but otherwise it should readily fulfill your requirements.

@divinity76
Copy link
Contributor

divinity76 commented Mar 16, 2024

fwiw

cc -DBLAKE3_NO_AVX512 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_SSE2 -DBLAKE3_USE_NEON=0 c/blake3.c c/blake3_dispatch.c c/blake3_portable.c

should compile pretty much anywhere with a pure C implementation :)

(until BLAKE3_NO_RISCV_P comes along anyway.. maybe a BLAKE3_PORTABLE flag could be useful? idk)

divinity76 added a commit to divinity76/BLAKE3 that referenced this issue Mar 16, 2024
simple flag to only compile the portable implementation

got the idea from BLAKE3-team#364 (comment)

could name it BLAKE3_PORTABLE instead, maybe, idk
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

No branches or pull requests

4 participants