diff options
author | John Naylor <john.naylor@postgresql.org> | 2022-08-03 11:07:40 +0700 |
---|---|---|
committer | John Naylor <john.naylor@postgresql.org> | 2022-08-04 13:49:18 +0700 |
commit | 56f2c7b58bda00ea5ecc56a93467ed9eae6b3db7 (patch) | |
tree | 095acd0e25e9b7e56cbb3965be31d4b634d7505c | |
parent | 1aa8dad41ffad99923a658389ee948e88394491c (diff) | |
download | postgresql-56f2c7b58bda00ea5ecc56a93467ed9eae6b3db7.tar.gz postgresql-56f2c7b58bda00ea5ecc56a93467ed9eae6b3db7.zip |
Support SSE2 intrinsics where available
SSE2 vector instructions are part of the spec for the 64-bit x86
architecture. Until now we have relied on the compiler to autovectorize
in some limited situations, but some useful coding idioms can only be
expressed explicitly via compiler intrinsics. To this end, add a header
that defines USE_SSE2 where available. While x86-only for now, we can
add other architectures in the future. This will also be the intended
place for helper functions that use vector operations.
Reviewed by Nathan Bossart and Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/CAFBsxsE2G_H_5Wbw%2BNOPm70-BK4xxKf86-mRzY%3DL2sLoQqM%2B-Q%40mail.gmail.com
-rw-r--r-- | src/include/port/simd.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/include/port/simd.h b/src/include/port/simd.h new file mode 100644 index 00000000000..a571e79f574 --- /dev/null +++ b/src/include/port/simd.h @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * + * simd.h + * Support for platform-specific vector operations. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/port/simd.h + * + *------------------------------------------------------------------------- + */ +#ifndef SIMD_H +#define SIMD_H + +/* + * SSE2 instructions are part of the spec for the 64-bit x86 ISA. We assume + * that compilers targeting this architecture understand SSE2 intrinsics. + * + * We use emmintrin.h rather than the comprehensive header immintrin.h in + * order to exclude extensions beyond SSE2. This is because MSVC, at least, + * will allow the use of intrinsics that haven't been enabled at compile + * time. + */ +#if (defined(__x86_64__) || defined(_M_AMD64)) +#include <emmintrin.h> +#define USE_SSE2 +#endif + +#endif /* SIMD_H */ |