Skip to content

[SIMD] Move native/vec code to C++#138525

Merged
ldematte merged 5 commits intoelastic:mainfrom
ldematte:simd/move-to-cpp
Nov 25, 2025
Merged

[SIMD] Move native/vec code to C++#138525
ldematte merged 5 commits intoelastic:mainfrom
ldematte:simd/move-to-cpp

Conversation

@ldematte
Copy link
Contributor

@ldematte ldematte commented Nov 24, 2025

Native code in the simdvec library is currently a mix of C and C++ code.
We found that C++ templates are helpful to reduce source code duplication while retaining a great (sometime even greater) code inlining and expansion (e.g. loop unrolling) that we use to maximize performance.

This PR moves all existing C code to C++; in general, it's just a matter of renaming + disabling name mangling, plus renaming of the exported functions. This last operation is needed as they name clash with the "extended" math functions (e.g. cosf32 which is the cosine function over float32_t types). Now all the exported symbols have a vec_ prefix.

Relates to: #139057

@ldematte ldematte added the test-arm Pull Requests that should be tested against arm agents label Nov 24, 2025
@ldematte ldematte changed the title [SIMD] Move to cpp Nov 25, 2025
@ldematte ldematte marked this pull request as ready for review November 25, 2025 08:58
@ldematte ldematte requested a review from a team as a code owner November 25, 2025 08:58
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Nov 25, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@ldematte
Copy link
Contributor Author

This is a preliminary step for #138552

Copy link
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

LGTM. I do prefer the simple C functions, but the value we gain from being able to use C++ templates is worth it. And we largely keep the same simplicity anyway, given the structure of the functions.

@ldematte
Copy link
Contributor Author

I do prefer the simple C functions

Yes :) I do promise to keep templating at a minimum, where it makes our code cleaner.
Our C or C++ is more like assembly anyway, with all the intrinsics :)

@ldematte ldematte enabled auto-merge (squash) November 25, 2025 14:21
@ldematte ldematte merged commit 440ae58 into elastic:main Nov 25, 2025
40 checks passed
@ldematte ldematte deleted the simd/move-to-cpp branch November 25, 2025 16:36
ncordon pushed a commit to ncordon/elasticsearch that referenced this pull request Nov 26, 2025
Native code in the simdvec library is currently a mix of C and C++ code.
We found that C++ templates are helpful to reduce source code duplication while retaining a great (sometime even greater) code inlining and expansion (e.g. loop unrolling) that we use to maximize performance.

This PR moves all existing C code to C++; in general, it's just a matter of renaming + disabling name mangling, plus renaming of the exported functions. This last operation is needed as they name clash with the "extended" math functions (e.g. cosf32 which is the cosine function over float32_t types). Now all the exported symbols have a vec_ prefix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>refactoring :Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch test-arm Pull Requests that should be tested against arm agents v9.3.0

3 participants