|
| From: | Richard Henderson |
| Subject: | Re: [PATCH 1/2] include/exec: Make ld*_p and st*_p functions available for generic code, too |
| Date: | Wed, 17 May 2023 06:20:26 -0700 |
| User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 |
On 5/17/23 00:42, Thomas Huth wrote:
+static inline int ldl_p(const void *ptr)
+{
+ return tswap32(ldl_he_p(ptr));
Not an ideal formulation for some hosts, e.g. Power < 3.0, because there is no separate bswap instruction. Power 2.07 only has bswapping-load/store. Keeping the bswap adjacent to the memory operation helps the compiler.
+static inline uint64_t ldn_p(const void *ptr, int sz)
+{
+ if (target_needs_bswap()) {
+#if HOST_BIG_ENDIAN
+ return ldn_le_p(ptr, sz);
+#else
+ return ldn_be_p(ptr, sz);
+#endif
+ } else {
+ return ldn_he_p(ptr, sz);
+ }
Better to avoid #if for if. And even better to merge to one test:
if (HOST_BIG_ENDIAN ^ target_needs_bswap()) {
return ldn_le_p(ptr, sz);
} else {
return ldn_be_p(ptr, sz);
}
r~
| [Prev in Thread] | Current Thread | [Next in Thread] |