Centralised architecture detection
Hi,
Catching up with the timing_clock_source thread (great work!), I saw
that Andres mentioned that it'd be nice to have PG_ARCH_X86 etc macros
to standardise our detection of CPUs[1]/messages/by-id/r5snevsnkyoifjqldu6gcssbnrnezpplq4ofcmekjfvzzu32dc@5rn26itd4ubr, and I remembered that I'd
already looked into that a couple of years ago and posted a patch...
and promptly forgot all about it. Then I remembered the surprising
discovery that motivated it[2]/messages/by-id/CA+hUKGKAf_i6w7hB_3pqZXQeqn+ixvY+CMps_n=mJ5HAatMjMw@mail.gmail.com, picked up in passing while working on
early versions of my <stdatomic.h> patch, that we still haven't done
anything about:
We are not detecting x86 in several places on Visual Studio, and the
one where we fail to include src/port/atomics/arch-x86.h can't be too
great for performance.
* pg_{read,write}_barrier() → pg_memory_barrier()!
* pg_spin_delay() → nothing!
* PG_HAVE_8BYTE_SINGLE_COPY_ATOMICITY → undefined
No Windows here but it's easy enough to confirm with CI: add #error to
arch-x86.h and you'll get a red MinGW task and a green Visual Studio
task. Presumably the Windows support was either written blind or
developed on MinGW.
Here's an update of my old patch. It just defines macros like this,
in c.h, though since then we gained port/pg_cpu.h, so perhaps it
belongs in there. Then we can deal with the underlying
compiler-defined macros in one central place. The names I came up
with were:
PG_ARCH_{ARM,LOONGARCH,MIPS,PPC,RISCV,S390,SPARC,X86}
PG_ARCH_{ARM,LOONGARCH,MIPS,PPC,RISCV,S390,SPARC,X86}_{32,64}
Lukas and John have both been doing similar sorts of things and may
have better ideas or patches, but I figured I should at least re-post
what I have.
I suppose we could also do something similar for PG_COMPILER_XXX and
PG_OS_XXX. I've made mistakes with those before too...
[1]: /messages/by-id/r5snevsnkyoifjqldu6gcssbnrnezpplq4ofcmekjfvzzu32dc@5rn26itd4ubr
[2]: /messages/by-id/CA+hUKGKAf_i6w7hB_3pqZXQeqn+ixvY+CMps_n=mJ5HAatMjMw@mail.gmail.com