2021-09-28 05:58:51 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_
|
2022-03-18 09:33:37 +00:00
|
|
|
#include "libc/macros.internal.h"
|
2021-09-28 05:58:51 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
#define COUNTBRANCH(x) COUNTBRANCH_(x, #x, STRINGIFY(__FILE__), __LINE__)
|
|
|
|
#define COUNTBRANCH_(x, xs, file, line) \
|
2022-03-18 09:33:37 +00:00
|
|
|
COUNTBRANCH__(x, STRINGIFY(xs), STRINGIFY(xs), file, line)
|
2021-09-28 05:58:51 +00:00
|
|
|
#define COUNTBRANCH__(x, xs, xss, file, line) \
|
|
|
|
({ \
|
|
|
|
bool Cond; \
|
|
|
|
struct countbranch *Info; \
|
|
|
|
asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t" \
|
2023-05-19 02:05:08 +00:00
|
|
|
".balign\t1\n" \
|
2021-09-28 05:58:51 +00:00
|
|
|
"31338:\t" \
|
|
|
|
".asciz\t" xs "\n" \
|
|
|
|
"31339:\t" \
|
|
|
|
".asciz\t" xss "\n" \
|
|
|
|
"31340:\t" \
|
|
|
|
".asciz\t" file "\n\t" \
|
|
|
|
".previous\n\t" \
|
|
|
|
".section .yoink\n\t" \
|
|
|
|
"nopl\tcountbranch_data(%%rip)\n\t" \
|
|
|
|
".previous\n\t" \
|
|
|
|
".section .sort.data.countbranch.2,\"a\",@progbits\n\t" \
|
2023-05-19 02:05:08 +00:00
|
|
|
".balign\t8\n31337:\t" \
|
2021-09-28 05:58:51 +00:00
|
|
|
".quad\t0\n\t" \
|
|
|
|
".quad\t0\n\t" \
|
|
|
|
".quad\t31338b\n\t" \
|
|
|
|
".quad\t31339b\n\t" \
|
|
|
|
".quad\t31340b\n\t" \
|
|
|
|
".quad\t" #line "\n\t" \
|
|
|
|
".previous\n\t" \
|
|
|
|
"lea\t31337b(%%rip),%0" \
|
|
|
|
: "=r"(Info)); \
|
|
|
|
Cond = (x); \
|
|
|
|
++Info->total; \
|
|
|
|
if (Cond) ++Info->taken; \
|
|
|
|
Cond; \
|
|
|
|
})
|
|
|
|
|
|
|
|
struct countbranch {
|
|
|
|
long total;
|
|
|
|
long taken;
|
|
|
|
const char *code;
|
|
|
|
const char *xcode;
|
|
|
|
const char *file;
|
2022-03-18 09:33:37 +00:00
|
|
|
long line;
|
2021-09-28 05:58:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct countbranch countbranch_data[];
|
|
|
|
|
|
|
|
void countbranch_report(void);
|
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_ */
|