From 15b5beea0c568857afbd235450e2f440db15878e Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Mon, 30 Oct 2023 17:13:54 +0000 Subject: [PATCH] Add note on platform-specific barriers Describe the approach of platform-specific code and draw a comparison with the constant-time module. Signed-off-by: David Horstmann --- docs/architecture/psa-shared-memory.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/psa-shared-memory.md b/docs/architecture/psa-shared-memory.md index fc179fa2ac..3968af142f 100644 --- a/docs/architecture/psa-shared-memory.md +++ b/docs/architecture/psa-shared-memory.md @@ -245,7 +245,7 @@ Once the copying code is implemented, it should be evaluated to see whether comp If copying behaviour is preserved by all major compilers then assume that compiler optimization is not a problem. -If copying behaviour is optimized away by the compiler, further investigation is needed. Experiment with using the `volatile` keyword to force the compiler not to optimize accesses to the copied buffers. +If copying behaviour is optimized away by the compiler, further investigation is needed. Experiment with using the `volatile` keyword to force the compiler not to optimize accesses to the copied buffers. If the `volatile` keyword is not sufficient, we may be able to use compiler or target-specific techniques to prevent optimization, for example memory barriers or empty `asm` blocks. These may be implemented and verified for important platforms while retaining a C implementation that is likely to be correct on most platforms as a fallback - the same approach taken by the constant-time module. **Open questions: Will the compiler optimize away copies? If so, can it be prevented from doing so in a portable way?**