2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_DCE_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_DCE_H_
|
|
|
|
/*─────────────────────────────────────────────────────────────────────────────╗
|
|
|
|
│ cosmopolitan § autotune » dead code elimination │
|
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
|
|
|
2020-12-26 10:09:07 +00:00
|
|
|
#ifndef SUPPORT_VECTOR
|
2023-05-09 08:56:56 +00:00
|
|
|
#ifdef __x86_64__
|
2020-06-15 14:18:57 +00:00
|
|
|
/**
|
|
|
|
* Supported Platforms Tuning Knob (Runtime & Compile-Time)
|
2021-02-05 14:16:20 +00:00
|
|
|
* Tuning this bitmask will remove platform polyfills at compile-time.
|
2020-06-15 14:18:57 +00:00
|
|
|
*/
|
2021-02-08 12:04:42 +00:00
|
|
|
#define SUPPORT_VECTOR 255
|
2023-05-09 08:56:56 +00:00
|
|
|
#else
|
2023-05-19 02:05:08 +00:00
|
|
|
#define SUPPORT_VECTOR (_HOSTLINUX | _HOSTXNU)
|
2023-05-09 08:56:56 +00:00
|
|
|
#endif
|
2020-06-15 14:18:57 +00:00
|
|
|
#endif
|
2021-02-05 14:16:20 +00:00
|
|
|
|
2022-10-11 03:31:25 +00:00
|
|
|
#define _HOSTLINUX 1
|
|
|
|
#define _HOSTMETAL 2
|
|
|
|
#define _HOSTWINDOWS 4
|
|
|
|
#define _HOSTXNU 8
|
|
|
|
#define _HOSTOPENBSD 16
|
|
|
|
#define _HOSTFREEBSD 32
|
|
|
|
#define _HOSTNETBSD 64
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define NoDebug() 1
|
|
|
|
#else
|
|
|
|
#define NoDebug() 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODE_DBG
|
|
|
|
#define IsModeDbg() 1
|
|
|
|
#else
|
|
|
|
#define IsModeDbg() 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __MFENTRY__
|
|
|
|
#define HaveFentry() 1
|
|
|
|
#else
|
|
|
|
#define HaveFentry() 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TRUSTWORTHY
|
|
|
|
#define IsTrustworthy() 1
|
|
|
|
#else
|
|
|
|
#define IsTrustworthy() 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TINY
|
|
|
|
#define IsTiny() 1
|
|
|
|
#else
|
|
|
|
#define IsTiny() 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __OPTIMIZE__
|
|
|
|
#define IsOptimized() 1
|
|
|
|
#else
|
|
|
|
#define IsOptimized() 0
|
|
|
|
#endif
|
|
|
|
|
2022-03-21 10:46:16 +00:00
|
|
|
#ifdef __SANITIZE_ADDRESS__
|
2021-05-14 12:36:58 +00:00
|
|
|
#define IsAsan() 1
|
|
|
|
#else
|
|
|
|
#define IsAsan() 0
|
|
|
|
#endif
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
#if defined(__PIE__) || defined(__PIC__)
|
|
|
|
#define IsPositionIndependent() 1
|
|
|
|
#else
|
|
|
|
#define IsPositionIndependent() 0
|
|
|
|
#endif
|
|
|
|
|
2022-10-11 03:31:25 +00:00
|
|
|
#define SupportsLinux() ((SUPPORT_VECTOR & _HOSTLINUX) == _HOSTLINUX)
|
|
|
|
#define SupportsMetal() ((SUPPORT_VECTOR & _HOSTMETAL) == _HOSTMETAL)
|
|
|
|
#define SupportsWindows() ((SUPPORT_VECTOR & _HOSTWINDOWS) == _HOSTWINDOWS)
|
|
|
|
#define SupportsXnu() ((SUPPORT_VECTOR & _HOSTXNU) == _HOSTXNU)
|
|
|
|
#define SupportsFreebsd() ((SUPPORT_VECTOR & _HOSTFREEBSD) == _HOSTFREEBSD)
|
|
|
|
#define SupportsOpenbsd() ((SUPPORT_VECTOR & _HOSTOPENBSD) == _HOSTOPENBSD)
|
|
|
|
#define SupportsNetbsd() ((SUPPORT_VECTOR & _HOSTNETBSD) == _HOSTNETBSD)
|
2022-11-02 13:49:42 +00:00
|
|
|
#define SupportsBsd() \
|
|
|
|
(!!(SUPPORT_VECTOR & (_HOSTXNU | _HOSTFREEBSD | _HOSTOPENBSD | _HOSTNETBSD)))
|
2020-06-15 14:18:57 +00:00
|
|
|
#define SupportsSystemv() \
|
2022-11-02 13:49:42 +00:00
|
|
|
(!!(SUPPORT_VECTOR & \
|
|
|
|
(_HOSTLINUX | _HOSTXNU | _HOSTOPENBSD | _HOSTFREEBSD | _HOSTNETBSD)))
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
#ifndef __ASSEMBLER__
|
2022-10-11 03:31:25 +00:00
|
|
|
#define IsLinux() (SupportsLinux() && (__hostos & _HOSTLINUX))
|
|
|
|
#define IsMetal() (SupportsMetal() && (__hostos & _HOSTMETAL))
|
|
|
|
#define IsWindows() (SupportsWindows() && (__hostos & _HOSTWINDOWS))
|
|
|
|
#define IsXnu() (SupportsXnu() && (__hostos & _HOSTXNU))
|
|
|
|
#define IsFreebsd() (SupportsFreebsd() && (__hostos & _HOSTFREEBSD))
|
|
|
|
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & _HOSTOPENBSD))
|
|
|
|
#define IsNetbsd() (SupportsNetbsd() && (__hostos & _HOSTNETBSD))
|
2021-02-07 14:11:44 +00:00
|
|
|
#define IsBsd() (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
|
2020-06-15 14:18:57 +00:00
|
|
|
#else
|
|
|
|
/* clang-format off */
|
2022-10-11 03:31:25 +00:00
|
|
|
#define IsLinux() $_HOSTLINUX,__hostos(%rip)
|
|
|
|
#define IsMetal() $_HOSTMETAL,__hostos(%rip)
|
|
|
|
#define IsWindows() $_HOSTWINDOWS,__hostos(%rip)
|
|
|
|
#define IsBsd() $_HOSTXNU|_HOSTFREEBSD|_HOSTOPENBSD|_HOSTNETBSD,__hostos(%rip)
|
|
|
|
#define IsXnu() $_HOSTXNU,__hostos(%rip)
|
|
|
|
#define IsFreebsd() $_HOSTFREEBSD,__hostos(%rip)
|
|
|
|
#define IsOpenbsd() $_HOSTOPENBSD,__hostos(%rip)
|
|
|
|
#define IsNetbsd() $_HOSTNETBSD,__hostos(%rip)
|
2020-06-15 14:18:57 +00:00
|
|
|
/* clang-format on */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2020-11-25 16:19:00 +00:00
|
|
|
extern const int __hostos;
|
2023-05-19 02:05:08 +00:00
|
|
|
|
|
|
|
#ifdef __x86_64__
|
2023-05-10 08:10:28 +00:00
|
|
|
bool IsWsl1(void);
|
2023-05-02 02:43:59 +00:00
|
|
|
#else
|
2023-05-10 08:10:28 +00:00
|
|
|
#define IsWsl1() false
|
2023-05-02 02:43:59 +00:00
|
|
|
#endif
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */
|