Skip to content

MAINT: LoongArch: switch away from the __loongarch64 preprocessor macro #28092

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 1 commit into from
Jan 24, 2025

Conversation

xen0n
Copy link
Contributor

@xen0n xen0n commented Jan 3, 2025

According to the Toolchain Conventions of the LoongArch Architecture specification (v1.1) 1, the __loongarch64 preprocessor macro is in fact a legacy symbol retained for compatibility; the reason being that the GPR width and the calling convention in use are orthogonal to each other, and in reality we care about the calling convention (e.g. ILP32 or LP64) more often than about the hardware capability -- think of ILP32 code on 64-bit hardware, in which case the GPR is wider than what a pointer actually can occupy, for example.

As for the two modified places, the header change is actually concerned with the calling convention, and the implementation change is actually correct regardless of bitness or calling convention. So, use __loongarch_lp64 for the header, and just __loongarch__ for the implementation.

cc @ErnstPeng -- this polishes up the preprocessor usage of #27856.

Copy link

@ErnstPeng ErnstPeng left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. I have some suggestions.

@@ -668,7 +668,7 @@ npy__cpu_init_features(void)

/***************** LoongArch ******************/

#elif defined(__loongarch64)
#elif defined(__loongarch__)
Copy link

@ErnstPeng ErnstPeng Jan 3, 2025

Choose a reason for hiding this comment

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

We don't have an environment for loongarch32, so we only did validation on loongarch64. So, to be cautious, I recommend using the __loongarch_lp64 macro here. After the loongarch32 environment is validated in the future, we will replace it with __loongarch__ macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know. This is specifically for avoiding to have to make another change and wait for another release, in the likely case that the final ratified LA32 ABI requires no modification here.

Look: eventually this line is going to say __loongarch__, so if we do so right now, a future PR adding LA32 support would have one less line of change. As long as LA32's basic C and ELF ABI (sizeof(int), availability of libc functionality, AT_HWCAP definitions, this kind of thing) remains within expectation, we should be safe here.

Choose a reason for hiding this comment

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

I think if we support LA32 in the future, we can revise it uniformly. It is recommended to use LA64 now better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think if we support LA32 in the future, we can revise it uniformly. It is recommended to use LA64 now better.

I don't agree with your points, because to me it's overly conservative about future. Are you not confident enough the API is sensible enough to not change?

But if you insist, I'll change for one time to not block progress. Let's add some diffstat to the future LA32 patchset then... ¯\_(ツ)_/¯

@charris
Copy link
Member

charris commented Jan 16, 2025

Is this ready?

@@ -668,7 +668,7 @@ npy__cpu_init_features(void)

/***************** LoongArch ******************/

#elif defined(__loongarch64)
#elif defined(__loongarch__)

Choose a reason for hiding this comment

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

Suggested change
#elif defined(__loongarch__)
#elif defined(__loongarch_lp64)

@ErnstPeng
Copy link

Is this ready?

No, one suggestion has not yet been revised.

According to the *Toolchain Conventions of the LoongArch Architecture*
specification (v1.1) [1], the `__loongarch64` preprocessor macro is in
fact a legacy symbol retained for compatibility; the reason being that
the GPR width and the calling convention in use are orthogonal to each
other, and in reality we care about the calling convention (e.g. ILP32
or LP64) more often than about the hardware capability -- think of ILP32
code on 64-bit hardware, in which case the GPR is wider than what a
pointer actually can occupy, for example.

As for the two modified places, the header change is actually
concerned with the calling convention; and while the implementation
change is actually correct regardless of bitness or calling convention,
the Loongson maintainer prefers staying with `__loongarch_lp64` to be
extra safe against possible API changes for the future ILP32 ABI.

[1]: https://github.com/loongson/la-toolchain-conventions/blob/releases/v1.1/LoongArch-toolchain-conventions-EN.adoc
@xen0n
Copy link
Contributor Author

xen0n commented Jan 17, 2025

Is this ready?

No, one suggestion has not yet been revised.

I expressly don't agree with your point, but in order to not block progress, I've rebased with your suggestion applied. Fortunately the ILP32 enablement work is already underway so we'll be able to revisit this in short order.

@ErnstPeng
Copy link

ErnstPeng commented Jan 17, 2025

Is this ready?

No, one suggestion has not yet been revised.

I expressly don't agree with your point, but in order to not block progress, I've rebased with your suggestion applied. Fortunately the ILP32 enablement work is already underway so we'll be able to revisit this in short order.

LGTM. Now, it's safer to do that. In future patches of LA32, we wiil discuss it.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

LGTM, let's get this in since the two experts have agreed (or agreed to disagree). Either option would have been fine with us I think. In it goes, thanks @xen0n and @ErnstPeng!

@rgommers rgommers merged commit af9f607 into numpy:main Jan 24, 2025
67 checks passed
@rgommers rgommers added this to the 2.3.0 release milestone Jan 24, 2025
@xen0n xen0n deleted the loongarch-lp64 branch January 24, 2025 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants