Skip to content

Conversation

@kmclaughlin-arm
Copy link
Contributor


name: Pull request
about: Technical issues, document format problems, bugs in scripts or feature proposal.


Thank you for submitting a pull request!

If this PR is about a bugfix:

Please use the bugfix label and make sure to go through the checklist below.

If this PR is about a proposal:

We are looking forward to evaluate your proposal, and if possible to
make it part of the Arm C Language Extension (ACLE) specifications.

We would like to encourage you reading through the contribution
guidelines
, in particular the section on submitting
a proposal
.

Please use the proposal label.

As for any pull request, please make sure to go through the below
checklist.

Checklist: (mark with X those which apply)

  • If an issue reporting the bug exists, I have mentioned it in the
    PR (do not bother creating the issue if all you want to do is
    fixing the bug yourself).
  • I have added/updated the SPDX-FileCopyrightText lines on top
    of any file I have edited. Format is SPDX-FileCopyrightText: Copyright {year} {entity or name} <{contact informations}>
    (Please update existing copyright lines if applicable. You can
    specify year ranges with hyphen , as in 2017-2019, and use
    commas to separate gaps, as in 2018-2020, 2022).
  • I have updated the Copyright section of the sources of the
    specification I have edited (this will show up in the text
    rendered in the PDF and other output format supported). The
    format is the same described in the previous item.
  • I have run the CI scripts (if applicable, as they might be
    tricky to set up on non-*nix machines). The sequence can be
    found in the contribution
    guidelines
    . Don't
    worry if you cannot run these scripts on your machine, your
    patch will be automatically checked in the Actions of the pull
    request.
  • I have added an item that describes the changes I have
    introduced in this PR in the section Changes for next
    release
    of the section Change Control/Document history
    of the document. Create Changes for next release if it does
    not exist. Notice that changes that are not modifying the
    content and rendering of the specifications (both HTML and PDF)
    do not need to be listed.
  • When modifying content and/or its rendering, I have checked the
    correctness of the result in the PDF output (please refer to the
    instructions on how to build the PDFs
    locally
    ).
  • The variable draftversion is set to true in the YAML header
    of the sources of the specifications I have modified.
  • Please DO NOT add my GitHub profile to the list of contributors
    in the README page of the project.

kmclaughlin-arm added a commit to kmclaughlin-arm/llvm-project that referenced this pull request Dec 3, 2025
This patch adds support in Clang for the RPRFM instruction, which is
available when FEAT_RPRFM is defined:

  void __rpld(int64_t access_kind, uint64_t retention_policy
              uint64_t reuse distance, int64_t stride,
              uint64_t count, int64_t length, void const *addr);

If FEAT_RPRFM is not available, this instruction is a NOP.

This implements the following ACLE proposal:
ARM-software/acle#423
main/acle.md Outdated
Comment on lines 3622 to 3625
/*constant*/ unsigned int /*reuse distance*/,
/*constant*/ signed int /*stride*/,
/*constant*/ unsigned int /*count*/,
/*constant*/ signed int /*length*/,

Choose a reason for hiding this comment

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

These parameters are not linked to the opcode and thus don't need to be constant?

I don't know the expected usage so perhaps making these variable is asking for trouble? In which case I think it's worth adding a variant where the metadata is an opaque value so at least there's a way to generate the prefetch for the non-constant use case without needing to use inline asm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed /*constant*/ from the metadata arguments, as there was no specific reason requiring them to be constant.

Choose a reason for hiding this comment

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

I doubt it'll be this easy. By allowing variable arguments the compiler will then need to sanitise their values, which I think will be non-trivial and potentially result in adding a prefetch causing performance regressions due to the unexpected overhead. This is why I suggested a separate builtin where the metadata is a single opaque value, because then the user can see the overhead, because they've had to compute it manually.

Copy link

Choose a reason for hiding this comment

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

are you worried about extra spills which may cause changes to the memory and the provided values won't match the memory pattern the prefetched instruction is using?

Choose a reason for hiding this comment

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

Not specifically, just any extra work required to construct the metadata that would be invisible to the user and thus might surprise them.

main/acle.md Outdated
Comment on lines 3652 to 3656
| Reuse Distance | 0 to 15 | Maximum number of bytes to be accessed before executing the |
| | | next RPRFM instruction that specifies the same range. Values |
| | | from 1 to 15 represent decreasing powers of two in the range |
| | | 512MiB to 32KiB. A value of 0 indicates distance not known. |
| | | Note: This value is ignored if a streaming prefetch is specified. |

Choose a reason for hiding this comment

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

Similar to the change to Count it will be more user friendly to accept the real world value and let the compiler encode it.

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've changed this to accept either 0 (for distance not known) or a value representing the number of bytes instead.

main/acle.md Outdated
| KEEP | 0 | Temporal fetch of the addressed location (that is, allocate in cache normally) |
| STRM | 1 | Streaming fetch of the addressed location (that is, memory used only once) |

The following intrinsic is also available when `__ARM_FEATURE_RPRFM` is defined:

Choose a reason for hiding this comment

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

Is the expectation for the builtin to fail compilation when this feature is not present? or be treated as a NOP? The existing _pld documentation suggests the latter.

I guess it comes down to whether the builtin provides useful information that can be used even if RPRFM is not available (e.g. by emitting other prefetch instructions, or non-temporal accesses).

The reason I mention this is because if there's only a weak link to the underlying instruction then we'll not want to use a feature macro, but instead something that just says the builtin is available, like __ARM_PREFIX_RANGE.

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 the existing documentation above the _pld builtin applies here too, in that the range builtin should not fail when the feature is not present and is treated as a nop.

Copy link

Choose a reason for hiding this comment

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

Yeah I think I agree with Paul, I think we should have a __ARM_PREFETCH_RANGE macro to tell the user if this part of the ACLE is currently implemented for the compiler and is available. Then it can be used for conditional compilation?

I think we could also have a __ARM_FEATURE_RPRFM macro, to indicate if the actual feat is enabled though?

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've updated this to describe the __ARM_PREFETCH_RANGE macro.

@AlfGalf Given that the __ARM_FEATURE_RPRFM macro should be used to query whether this is implemented, I'm not sure why we would also want to add __ARM_FEATURE_RPRFM if the instruction does not require something like +rprfm?

Copy link

Choose a reason for hiding this comment

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

I support @kmclaughlin-arm , the FEAT_RPRFM is OPTIONAL from Armv8.0, and not guarded by any dedicated feature flag, moreover it looks like RPRFM is a preferred disassembly for PRFM with UXTW, as guarded by this test https://github.com/llvm/llvm-project/blob/f9a3076180bfa1ebffd518971eefd30939a5ced6/llvm/test/MC/AArch64/rprfm.s#L273 , so not sure what we would achieve with having __ARM_FEATURE_RPRFM.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah, okay, agreed best to not have __ARM_FEATURE_RPRFM

- Remove const from metadata arguments
- Change Reuse Distance to take a number of bytes
main/acle.md Outdated
Comment on lines 3622 to 3625
/*constant*/ unsigned int /*reuse distance*/,
/*constant*/ signed int /*stride*/,
/*constant*/ unsigned int /*count*/,
/*constant*/ signed int /*length*/,

Choose a reason for hiding this comment

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

I doubt it'll be this easy. By allowing variable arguments the compiler will then need to sanitise their values, which I think will be non-trivial and potentially result in adding a prefetch causing performance regressions due to the unexpected overhead. This is why I suggested a separate builtin where the metadata is a single opaque value, because then the user can see the overhead, because they've had to compute it manually.

main/acle.md Outdated
Comment on lines 3652 to 3656
| Reuse Distance | 0 or [2**15, 2**29] | Maximum number of bytes to be accessed before executing the |
| | | next RPRFM instruction that specifies the same range. Values |
| | | are powers of two representing the number of bytes in the range |
| | | 32KiB to 512MiB. A value of 0 indicates distance not known. |
| | | Note: This value is ignored if a streaming prefetch is specified. |

Choose a reason for hiding this comment

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

Do you know how accurate Reuse Distance needs to be? It says "Maximum number of bytes" so I take that to mean you can access less. I ask because perhaps this can be freeform, with the compiler selecting the lowest compatible value, or 0 for values above the maximum allowed.

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 haven't found anything to say that ReuseDistance needs to be accurate, so my understanding is also that it could access less than the number of bytes requested.

Choose a reason for hiding this comment

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

Does that mean the range information can be removed because the compiler can do the necessary rounding for free. Then just call out 0 and values over 512MiB are treated as unknown?

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 the range information is still accurate though, as long as it's in the description that any value outside the range will use 0 for unknown distance?

Choose a reason for hiding this comment

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

To me the range information is specifying the builtin's acceptable values for that parameter, with everything else resulting in a diagnostic. With the compiler doing implicit rounding, all values are acceptable and so there is no range. The summary can then document how values will be interpreted (e.g. All values are rounded up to the nearest power-of-two in the range low - high, with the exception of ....).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think it makes sense to remove the range given that the rounding means there won't be any diagnostics shown for invalid values.

Copy link

@AlfGalf AlfGalf left a comment

Choose a reason for hiding this comment

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

The intrinsic itself looks good to me, slight question about the macro though

main/acle.md Outdated
| KEEP | 0 | Temporal fetch of the addressed location (that is, allocate in cache normally) |
| STRM | 1 | Streaming fetch of the addressed location (that is, memory used only once) |

The following intrinsic is also available when `__ARM_FEATURE_RPRFM` is defined:
Copy link

Choose a reason for hiding this comment

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

Yeah I think I agree with Paul, I think we should have a __ARM_PREFETCH_RANGE macro to tell the user if this part of the ACLE is currently implemented for the compiler and is available. Then it can be used for conditional compilation?

I think we could also have a __ARM_FEATURE_RPRFM macro, to indicate if the actual feat is enabled though?


| **Metadata** | **Range** | **Summary** |
| -------------- | ------------------- | -------------------------------------------------------------------- |
| Reuse Distance | | Maximum number of bytes to be accessed before executing the next |
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add the Range here for Reuse Distance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @CarolineConcatto, the reason for removing the Reuse Distance range was discussed here: #423 (comment)

- Add description of the __ARM_PREFETCH_RANGE macro
Copy link

@paulwalker-arm paulwalker-arm left a comment

Choose a reason for hiding this comment

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

I'm mostly happy, with one last query.

main/acle.md Outdated
Comment on lines 3623 to 3626
/*constant*/ size_t /*reuse distance*/,
/*constant*/ signed int /*stride*/,
/*constant*/ unsigned int /*count*/,
/*constant*/ signed int /*length*/,

Choose a reason for hiding this comment

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

Not a strongly held view, but after reading the description of __pld_range I do feel its "parameters" have a more natural order (i.e. length, count, stride, reuse distance). What do you think to using the same order for __pldx_range?

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 it would be better if the order is consistent for both of the intrinsics, and it makes sense to keep the ordering from bits 0-63 used by __pld_range.

Copy link
Contributor

@AlfieRichardsArm AlfieRichardsArm left a comment

Choose a reason for hiding this comment

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

LGTM

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.

6 participants