further optimised check of mask validity

master
Avril 4 years ago
parent 1507040d0c
commit 5356d95a1c
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -7,6 +7,8 @@
#include <stdlib.h>
#include <string.h>
#define noreturn __attribute__((noreturn))
#define noinline __attribute__((noinline))
#define BUFFER_SIZE 4096
#define IGNORE(param) do { (void)(param); } while(0)
#define LIKELY(ex) __builtin_expect((ex), 1)
@ -35,19 +37,21 @@ static inline void pbits(char out[restrict 8], unsigned char byte, const char bi
for(register int i=8; i --> 0; byte >>= 1) *out++=bit[byte & 1];
}
// Light assertion (likely to succeed)
static inline int lcheck(int val, const char* msg)
static noinline noreturn void die(const char* msg)
{
LIF(val) return val;
fprintf(stderr, "error: %s\n", msg);
exit(1);
}
// Light assertion (likely to succeed)
//TODO: Where do we have the __builtin_expect here? On the inside or the outside of the expression? Or both? For now, both.
#define Lcheck(value, message) (LIKELY(LIKELY(!!(value)) ? 1 : (die(message), 0)))
int main(int argc, char **argv)
{
IGNORE(argc);
const char* mask = argv[1] && lcheck(argv[1][0] && argv[1][1], "expected 2 character mask") ? argv[1] : "01";
const char* mask = argv[1] && Lcheck(argv[1][0] && argv[1][1], "expected 2 character mask") ? argv[1] : "01";
unsigned char buf[BUFFER_SIZE];
char tbuf[BUFFER_SIZE * 8];
size_t bsz = BUFFER_SIZE;

Loading…
Cancel
Save