Skip to content

SimdOps and NativeSimd ops refactored to remove duplicate code, Vecto… #498

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 5 commits into from
Jul 29, 2025

Conversation

tjake
Copy link
Member

@tjake tjake commented Jul 9, 2025

…rUtilSupport simplified for Native vs Panama

@@ -100,9 +100,9 @@ private static class check_compatibility {
public static final FunctionDescriptor DESC = FunctionDescriptor.of(
NativeSimdOps.C_BOOL );

public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(
Copy link
Member Author

Choose a reason for hiding this comment

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

I think I must have a newer version of jextract?

Copy link
Contributor

Choose a reason for hiding this comment

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

These are generated with a version from February 2024, so very possible. Maybe we should make a note of the version used in the README so that we can avoid unnecessary churn if someone uses an old version again?

@marianotepper
Copy link
Collaborator

This is awesome. Looks really good to me.

@marianotepper marianotepper requested a review from jkni July 9, 2025 21:39

import java.util.List;

final class PanamaVectorUtilSupport implements VectorUtilSupport {
class PanamaVectorUtilSupport implements VectorUtilSupport {
protected final SimdOps simdOps;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it needed to keep here an instance of SimdOps? It looks like previously it was static which is more efficient when no state is required to keep for method calls.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the PR is using inheritance and function overloading for fromVectorFloat, I think we need runtime method resolution.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need separate SimdOps classes etc, we can move things to VectorSupportUtils implementations?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not a bad idea. It might work.

static final int PREFERRED_BIT_SIZE = FloatVector.SPECIES_PREFERRED.vectorBitSize();
static final IntVector BYTE_TO_INT_MASK_512 = IntVector.broadcast(IntVector.SPECIES_512, 0xff);
static final IntVector BYTE_TO_INT_MASK_256 = IntVector.broadcast(IntVector.SPECIES_256, 0xff);

static final ThreadLocal<int[]> scratchInt512 = ThreadLocal.withInitial(() -> new int[IntVector.SPECIES_512.length()]);
static final ThreadLocal<int[]> scratchInt256 = ThreadLocal.withInitial(() -> new int[IntVector.SPECIES_256.length()]);

static float sum(ArrayVectorFloat vector) {
protected FloatVector fromVectorFloat(VectorSpecies<Float> SPEC, VectorFloat<?> vector, int offset) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No local member variables in this class, why not make methods static?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The method fromVectorFloat is solved at runtime using inheritance and overloading. Unless I'm missing a key Java feature, I think the methods cannot be static.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, we need the inheritance

import java.util.List;

final class SimdOps {
class SimdOps {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor suggestion: Maybe having SimdOps as a singleton class would not be a bad idea

Copy link
Contributor

@jkni jkni 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 think the consolidation here will ease future changes in this area. It's worth some basic benchmarking on this; this is touching areas that were fairly sensitive to small changes having major impact on how well C2 did. I'll defer on more minor questions around moving things out of SimdOps into VectorUtilSupport to those who are working with the codebase more frequently. Thanks!

@tjake
Copy link
Member Author

tjake commented Jul 17, 2025

Consensus seems to be we should remove the SimdOps stuff and move it into VectorSupport classes. I'll do that

@marianotepper
Copy link
Collaborator

@MarkWolters is running some benchmarks on this branch to see if it is as performant as the previous version.

@tjake
Copy link
Member Author

tjake commented Jul 17, 2025

I forgot to say, I ran the jmh benchmarks and saw no difference FYI

@tjake
Copy link
Member Author

tjake commented Jul 23, 2025

Ok I reverted the jmh change and moved SimdOps and NativeSimdOps logic to VectorUtilSupport

@tlwillke
Copy link
Collaborator

Additional performance testing by @MarkWolters looks good.

Copy link
Collaborator

@tlwillke tlwillke left a comment

Choose a reason for hiding this comment

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

Looks good. Nice simplification.

@tlwillke tlwillke merged commit 51d4f0b into main Jul 29, 2025
8 checks passed
@tlwillke tlwillke deleted the refactor-panama branch July 29, 2025 20:57
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.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy