JunyuanShen943 opened a new pull request, #22216:
URL: https://github.com/apache/nuttx/pull/22216
## Summary
* Why: with the TASKING toolchain, `predict_true()` / `predict_false()`
expand to the plain expression, so the branch target alignment that
`--branch-target-align` (already set in `ToolchainTasking.defs` and
`tasking.cmake`) is meant to apply to the unlikely path never happens.
TASKING does not use `__builtin_expect` for code generation; only
`#pragma assume_if` gives it the hint.
* How: define the two macros as
`(_Pragma("assume_if true/false") (x) _Pragma("assume_if restore"))`,
so the hint covers only the guarded expression and the previous
setting is restored right after it. Other toolchains are unchanged.
## Impact
* New feature or changed behavior: TASKING builds only; generated code
now honors the branch hints. No functional change.
* User adaptation needed: NO.
* Build: NO.
* Hardware: TriCore with the TASKING toolchain.
* Documentation: NO.
* Security: NO.
* Compatibility: NO.
## Testing
I confirm that changes are verified on local setup and works as intended:
* Build Host: Ubuntu 22.04 x86_64, TASKING SmartCode v10.4r1 (ctc)
* Target: triboard_tc4x9_com:nsh with `CONFIG_TRICORE_TOOLCHAIN_TASKING=y`
(build only)
1. A small sample compiled with `ctc -O2 --branch-target-align`:
without the pragma the unlikely branch target has no alignment
directive; with `_Pragma("assume_if false") (x > 100)
_Pragma("assume_if restore")` the compiler emits `.align 8` in front
of it:
```
j .L3
.align 8
.L2:
```
2. triboard_tc4x9_com:nsh with TASKING builds on master and on this PR.
The set of compiler warnings is the same (no new warning from the
pragmas). Code size grows from 179822 to 181790 bytes (+1968, about
1.1%), which is the alignment padding of the hinted branch targets;
data and bss are unchanged.
3. sim:nsh (GCC) make and CMake builds pass and ostest exits with status
0; `tools/checkpatch.sh -m` is clean.
Not run on TriCore hardware. a2g-tc397-5v-tft:nsh could not be built
with TASKING on this host on master either (the installed toolchain has
no tc1.6.2 default libraries, `cctc E304`), so it is not covered.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]