Open Chirimen-Jako opened 5 years ago
Additional Info: lightning/external/libwally-core/src/ccan_config.h has also same logic.
31 #if HAVE_UNALIGNED_ACCESS
32 #define alignment_ok(p, n) 1
33 #else
34 #define alignment_ok(p, n) ((size_t)(p) % (n) == 0)
35 #endif
Sould be the following?
31 #if HAVE_UNALIGNED_ACCESS
32 #define alignment_ok(p, n) ((size_t)(p) % (n) == 0)
33 #else
34 #define alignment_ok(p, n) 1
35 #endif
Jako Chirimen notifications@github.com writes:
Now I'm chasing kind of the [-Wcast-align] warnings which happens when I build c-Lightning on 32bit armv7l machine.
ccan/ccan/crypto/sha256/sha256.c:213:22: warning: cast increases required alignment of target type [-Wcast-align] Transform(ctx->s, (const uint32_t *)data, blocks); ^
Interesting!
I noticed the 'HAVE_UNALIGNED_ACCESS' macro affects some many-bits calculation especially for crypto.
$ find . -name '*.h' | xargs grep "UNALIGNED" ./ccan/config.h:#define HAVE_UNALIGNED_ACCESS 1 ./external/libwally-core/src/config.h:#define HAVE_UNALIGNED_ACCESS 1 ./external/libwally-core/src/ccan_config.h:#if HAVE_UNALIGNED_ACCESS
It means the following in my understanding. Right? HAVE_UNALIGNED_ACCESS=0 --> pointers are aligned appropriately in advance. HAVE_UNALIGNED_ACCESS=1 --> pointers may not be aligned. need check and re-align.
No. HAVE_UNALIGNED_ACCESS=1 means you can access pointers with "unnatural" alignment. x86, for example, allows you to do this.
Interestingly, my rPi thinks it can do it too, but perhaps unaligned accesses actually trap, and it would perform better with this unset?
Cheers, Rusty.
Thank you very much for your comment. Sorry for late response.
Please forgive me what I can is leave some unorganized comments for now because this problem includes some composite and difficult issues.
HAVE_UNALIGNED_ACCESS=0 --> pointers are aligned appropriately in advance. HAVE_UNALIGNED_ACCESS=1 --> pointers may not be aligned. need check and re-align.
No. HAVE_UNALIGNED_ACCESS=1 means you can access pointers with "unnatural" alignment. x86, for example, allows you to do this.
movdqa
cannot unaligned access, if do it, raise exception. On the other hand, movdqu
can unaligned access. But it may slow down because it reads memory twice over the each aligned boundary.HAVE_UNALIGNED_ACCESS
is “unnatural” coding because it expects and relies on a processor exact behavior too much.__atribute__ ((aligned(x))
directives to the important pointers. Of caurse, CCAN can wrap that dicrectives by macro for compatibility.Interestingly, my rPi thinks it can do it too, but perhaps unaligned accesses actually trap, and it would perform better with this unset?
This is also my guess, it relates virtual memory allocates granularity, or, ARM processor’s failure. If the former, x86s allocates at least 4KB and didn’t touch non-commitment area by lucky. Anyway, As I told you at (3), to believe processor manufacturer’s document completely is sometimes risky in my opinion. I know Prof. Tanenbaum and David N. Cutler were consumed time by that kind of issues.
If I were you, when ARM processor detect by configure or make, I allocates alignment sensitive memory area by only aligned memory allocate functions. And, add __attribute__ ((aligned(x))
attributes to the all sensitive pointers. If target processor is x86(AMD), I don't change the result of processed code at all. I'll remove HAVE_UNALIGNED_ACCESS
macro (at least, statically).
I'm not sure for the other processors. (What's supported?)
Best Regards,
Now I'm chasing kind of the [-Wcast-align] warnings which happens when I build c-Lightning on 32bit armv7l machine.
Brief system info is:
Full information is the following. warning.txt system-info.txt
I noticed the 'HAVE_UNALIGNED_ACCESS' macro affects some many-bits calculation especially for crypto.
It means the following in my understanding. Right? HAVE_UNALIGNED_ACCESS=0 --> pointers are aligned appropriately in advance. HAVE_UNALIGNED_ACCESS=1 --> pointers may not be aligned. need check and re-align.
If my understanding is correct, the following logic is upside-down? CURRENT: lightning/ccan/ccan/crypto/sha256/sha256.c
should be:
the above code affects the following process.
Could you take a look at the codes and give me a comment? Thanks in advance.