day2: part1

named inline literals

Fortune for day2's current commit: Future small blessing − 末小吉
master
Avril 3 years ago
parent 388a3282a1
commit f11e8943a6
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -9,10 +9,12 @@ extern "C" {
typedef int64_t result_t; typedef int64_t result_t;
#define SUM_FIELDS 3
struct psum { struct psum {
union { union {
struct { result_t forward, up, down; }; struct { result_t forward, up, down; };
result_t _fields[3]; result_t _fields[SUM_FIELDS];
}; };
}; };

@ -32,26 +32,17 @@ static const unsigned char DIGITS[255] = {
['0' ... '9'] = 1, ['0' ... '9'] = 1,
}; };
inline static void _fresolv(result_t f[restrict 3], off_t field, result_t v) inline static void _fresolv(result_t f[restrict SUM_FIELDS], off_t field, result_t v)
{ {
f[field & 3] += v; f[field & SUM_FIELDS] += v;
} }
inline static void fresolv(result_t f[restrict 3], const struct proc* restrict p, result_t v) inline static void fresolv(result_t f[restrict SUM_FIELDS], const struct proc* restrict p, result_t v)
{ {
_fresolv(f, p->field, v); _fresolv(f, p->field, v);
//f[p->field] += v; //f[p->field] += v;
} }
inline static void mresolv(struct psum* restrict add, const struct proc* p, result_t v)
{
_fresolv((result_t* restrict)add, p->field, v);
//_fresolv((result_t(*)[3])add, p->field, v);
//*(((result_t*restrict)add)+p->field) += v;
}
inline static __attribute__((const, always_inline, artificial, gnu_inline)) bool is_digit(char c) inline static __attribute__((const, always_inline, artificial, gnu_inline)) bool is_digit(char c)
{ {
return !!c[DIGITS]; return !!c[DIGITS];

Loading…
Cancel
Save