2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_TESTLIB_EZBENCH_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_TESTLIB_EZBENCH_H_
|
2023-06-03 15:12:13 +00:00
|
|
|
#include "libc/macros.internal.h"
|
|
|
|
#include "libc/math.h"
|
2022-04-25 15:30:14 +00:00
|
|
|
#include "libc/nexgen32e/bench.h"
|
2021-09-28 05:58:51 +00:00
|
|
|
#include "libc/nexgen32e/x86feature.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/testlib/bench.h"
|
2020-07-02 20:46:08 +00:00
|
|
|
#include "libc/testlib/testlib.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
COSMOPOLITAN_C_START_
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2022-09-13 21:57:38 +00:00
|
|
|
#ifndef EZBENCH_COUNT
|
2022-04-25 15:30:14 +00:00
|
|
|
#define EZBENCH_COUNT 128
|
2022-09-13 21:57:38 +00:00
|
|
|
#endif
|
|
|
|
|
2022-04-25 15:30:14 +00:00
|
|
|
#define EZBENCH_TRIES 10
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
#define EZBENCH(INIT, EXPR) EZBENCH2(#EXPR, INIT, EXPR)
|
2021-02-07 14:11:44 +00:00
|
|
|
|
2022-04-25 15:30:14 +00:00
|
|
|
#define EZBENCH2(NAME, INIT, EXPR) \
|
|
|
|
do { \
|
|
|
|
int Core, Tries, Interrupts; \
|
2023-06-03 15:12:13 +00:00
|
|
|
double Speculative, MemoryStrict; \
|
2022-04-25 15:30:14 +00:00
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
INIT; \
|
|
|
|
EXPR; \
|
|
|
|
Speculative = BENCHLOOP(__startbench, __endbench, EZBENCH_COUNT, ({ \
|
|
|
|
INIT; \
|
|
|
|
__polluteregisters(); \
|
|
|
|
}), \
|
|
|
|
(EXPR)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && \
|
|
|
|
(__testlib_getcore() != Core && \
|
|
|
|
__testlib_getinterrupts() > Interrupts)); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" speculative"); \
|
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
INIT; \
|
|
|
|
EXPR; \
|
|
|
|
MemoryStrict = BENCHLOOP(__startbench_m, __endbench_m, 32, ({ \
|
|
|
|
INIT; \
|
|
|
|
__polluteregisters(); \
|
|
|
|
}), \
|
|
|
|
(EXPR)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && \
|
|
|
|
(__testlib_getcore() != Core && \
|
|
|
|
__testlib_getinterrupts() > Interrupts)); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" memory strict"); \
|
|
|
|
__testlib_ezbenchreport( \
|
2023-06-03 15:12:13 +00:00
|
|
|
NAME, MAX(.001, Speculative - __testlib_ezbenchcontrol()), \
|
|
|
|
MAX(.001, MemoryStrict - __testlib_ezbenchcontrol())); \
|
2020-06-15 14:18:57 +00:00
|
|
|
} while (0)
|
2021-09-28 05:58:51 +00:00
|
|
|
|
2022-04-25 15:30:14 +00:00
|
|
|
#define EZBENCH3(NAME, NUM, INIT, EXPR) \
|
|
|
|
do { \
|
|
|
|
int Core, Tries, Interrupts; \
|
2023-06-03 15:12:13 +00:00
|
|
|
double Speculative, MemoryStrict; \
|
2022-04-25 15:30:14 +00:00
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
INIT; \
|
|
|
|
EXPR; \
|
|
|
|
Speculative = BENCHLOOP(__startbench, __endbench, NUM, ({ \
|
|
|
|
INIT; \
|
|
|
|
__polluteregisters(); \
|
|
|
|
}), \
|
|
|
|
(EXPR)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && \
|
|
|
|
(__testlib_getcore() != Core && \
|
|
|
|
__testlib_getinterrupts() > Interrupts)); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" speculative"); \
|
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
INIT; \
|
|
|
|
EXPR; \
|
|
|
|
MemoryStrict = BENCHLOOP(__startbench_m, __endbench_m, NUM, ({ \
|
|
|
|
INIT; \
|
|
|
|
__polluteregisters(); \
|
|
|
|
}), \
|
|
|
|
(EXPR)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && \
|
|
|
|
(__testlib_getcore() != Core && \
|
|
|
|
__testlib_getinterrupts() > Interrupts)); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" memory strict"); \
|
|
|
|
__testlib_ezbenchreport( \
|
2023-06-03 15:12:13 +00:00
|
|
|
NAME, MAX(.001, Speculative - __testlib_ezbenchcontrol()), \
|
|
|
|
MAX(.001, MemoryStrict - __testlib_ezbenchcontrol())); \
|
2021-02-07 14:11:44 +00:00
|
|
|
} while (0)
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2023-07-10 11:29:46 +00:00
|
|
|
#define EZBENCH_C(NAME, CONTROL, EXPR) \
|
|
|
|
do { \
|
|
|
|
int Core, Tries, Interrupts; \
|
|
|
|
double Control, Speculative, MemoryStrict; \
|
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
Control = BENCHLOOP(__startbench_m, __endbench_m, EZBENCH_COUNT, \
|
|
|
|
({ __polluteregisters(); }), (CONTROL)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && \
|
|
|
|
(__testlib_getcore() != Core && \
|
|
|
|
__testlib_getinterrupts() > Interrupts)); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" control"); \
|
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
EXPR; \
|
|
|
|
Speculative = BENCHLOOP(__startbench, __endbench, EZBENCH_COUNT, \
|
|
|
|
__polluteregisters(), (EXPR)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && \
|
|
|
|
(__testlib_getcore() != Core && \
|
|
|
|
__testlib_getinterrupts() > Interrupts)); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" speculative"); \
|
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
EXPR; \
|
|
|
|
MemoryStrict = BENCHLOOP(__startbench_m, __endbench_m, 8, \
|
|
|
|
({ __polluteregisters(); }), (EXPR)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && \
|
|
|
|
(__testlib_getcore() != Core && \
|
|
|
|
__testlib_getinterrupts() > Interrupts)); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" memory strict"); \
|
|
|
|
__testlib_ezbenchreport(NAME, MAX(.001, Speculative - Control), \
|
|
|
|
MAX(.001, MemoryStrict - Control)); \
|
2021-09-28 05:58:51 +00:00
|
|
|
} while (0)
|
|
|
|
|
2023-06-03 15:12:13 +00:00
|
|
|
#define EZBENCH_N(NAME, N, EXPR) \
|
|
|
|
do { \
|
|
|
|
double Speculative, Toto; \
|
|
|
|
int Core, Tries, Interrupts; \
|
|
|
|
Tries = 0; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
Interrupts = __testlib_getinterrupts(); \
|
|
|
|
EXPR; \
|
|
|
|
Speculative = BENCHLOOPER(__startbench, __endbench, 32, (EXPR)); \
|
|
|
|
} while (++Tries < EZBENCH_TRIES && !Speculative); \
|
|
|
|
if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(""); \
|
|
|
|
__testlib_ezbenchreport_n(NAME, 'n', N, Speculative); \
|
2021-09-28 05:58:51 +00:00
|
|
|
} while (0)
|
|
|
|
|
2023-06-03 15:12:13 +00:00
|
|
|
#define EZBENCH_K(NAME, K, EXPR) \
|
|
|
|
do { \
|
|
|
|
int Core; \
|
|
|
|
double Speculative; \
|
|
|
|
do { \
|
|
|
|
__testlib_yield(); \
|
|
|
|
Core = __testlib_getcore(); \
|
|
|
|
EXPR; \
|
|
|
|
Speculative = \
|
|
|
|
BENCHLOOPER(__startbench, __endbench, EZBENCH_COUNT, (EXPR)); \
|
|
|
|
} while (Core != __testlib_getcore()); \
|
|
|
|
__testlib_ezbenchreport_n(NAME, 'k', K, Speculative); \
|
2021-09-28 05:58:51 +00:00
|
|
|
} while (0)
|
|
|
|
|
2022-04-25 15:30:14 +00:00
|
|
|
void __polluteregisters(void);
|
2021-09-28 05:58:51 +00:00
|
|
|
void __testlib_yield(void);
|
|
|
|
int __testlib_getcore(void);
|
|
|
|
int64_t __testlib_getinterrupts(void);
|
2023-06-03 15:12:13 +00:00
|
|
|
double __testlib_ezbenchcontrol(void);
|
2021-09-28 05:58:51 +00:00
|
|
|
void __testlib_ezbenchwarn(const char *);
|
2023-06-03 15:12:13 +00:00
|
|
|
void __testlib_ezbenchreport(const char *, double, double);
|
|
|
|
void __testlib_ezbenchreport_n(const char *, char, size_t, double);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-09-28 05:58:51 +00:00
|
|
|
#ifdef __STRICT_ANSI__
|
|
|
|
#undef EZBENCH2
|
|
|
|
#undef EZBENCH3
|
|
|
|
#undef EZBENCH_N
|
|
|
|
#undef EZBENCH_K
|
|
|
|
#define EZBENCH2(NAME, INIT, EXPR) (void)0
|
|
|
|
#define EZBENCH3(NAME, NUM, INIT, EXPR) (void)0
|
|
|
|
#define EZBENCH_N(NAME, N, EXPR) (void)0
|
|
|
|
#define EZBENCH_K(NAME, K, EXPR) (void)0
|
|
|
|
#endif
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
2020-06-15 14:18:57 +00:00
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_TESTLIB_EZBENCH_H_ */
|