Removed function call in part2 hot loop. This enabled full parallelisation for part 1 and 2 Fortune for aoc2021's current commit: Small blessing − 小吉master
parent
c705154f09
commit
66df1b2e0a
@ -0,0 +1,24 @@
|
||||
#ifndef _PAIRS_H
|
||||
#define _PAIRS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <input.h>
|
||||
|
||||
struct ipair {
|
||||
input_t prev;
|
||||
input_t next;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
uint64_t chk_pair(const ipair* __restrict__ pair) __attribute__((pure));
|
||||
uint64_t sum_pairs(uint64_t length, const input_t input[const __restrict__ length]) __attribute__((pure));
|
||||
}
|
||||
#else
|
||||
uint64_t chk_pair(const struct ipair* restrict pair) __attribute__((pure));
|
||||
uint64_t sum_pairs(uint64_t length, const input_t input[const restrict length]) __attribute__((pure));
|
||||
#endif
|
||||
|
||||
#endif /* _PAIRS_H */
|
@ -1,18 +1,27 @@
|
||||
|
||||
#include <input.h>
|
||||
|
||||
#include <pairs.h>
|
||||
|
||||
__attribute__((pure))
|
||||
uint64_t chk_pair(const struct ipair* restrict pair)
|
||||
{
|
||||
return pair->prev < pair->next;
|
||||
}
|
||||
|
||||
int part1(uint64_t* restrict _res)
|
||||
__attribute__((pure))
|
||||
uint64_t sum_pairs(uint64_t length, const input_t input[const restrict length])
|
||||
{
|
||||
uint64_t res = 0;
|
||||
for(size_t i=0;i<INPUT_SIZE-1;i++)
|
||||
for(size_t i=0;i<length-1;i++)
|
||||
{
|
||||
res += chk_pair((const struct ipair*)(INPUT+i));
|
||||
res += chk_pair((const struct ipair*)(input+i));
|
||||
}
|
||||
*_res = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
int part1(uint64_t* restrict _res)
|
||||
{
|
||||
*_res = sum_pairs(INPUT_SIZE, INPUT);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,11 +1,30 @@
|
||||
#include <input.h>
|
||||
|
||||
#include <tracem/macros.h>
|
||||
#include <pairs.h>
|
||||
|
||||
struct window {
|
||||
input_t pre, cur, suc;
|
||||
};
|
||||
|
||||
__attribute__((pure))
|
||||
inline static input_t sum_window(const struct window* restrict w)
|
||||
{
|
||||
return w->pre + w->cur + w->suc;
|
||||
}
|
||||
|
||||
int part2(uint64_t* restrict _res)
|
||||
{
|
||||
uint64_t res=0;
|
||||
TODO("unimplemented");
|
||||
|
||||
for(size_t i=0;i<INPUT_SIZE-2;i++)
|
||||
{
|
||||
struct ipair w6;
|
||||
w6.prev = sum_window((const struct window*)(INPUT+i));
|
||||
w6.next = sum_window((const struct window*)(INPUT+i+1));
|
||||
|
||||
res += (w6.prev < w6.next);
|
||||
}
|
||||
|
||||
*_res = res;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in new issue