From 84ad2e3c12cb505e3c5e3dd29d05edb529b82174 Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Sat, 30 Jan 2021 16:47:48 -0500 Subject: Try to squeeze out a little more performance ``Common wisdom'' dictates that placements are often better than stack moves, so we bias the generated move list in this fashion. Seems to be a little faster. --- include/actions.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'include/actions.c') diff --git a/include/actions.c b/include/actions.c index 800a2d4..316b19f 100644 --- a/include/actions.c +++ b/include/actions.c @@ -30,6 +30,11 @@ list_append(action_list_t *list, const enum A_TYPE type, const int8_t loc, const uint8_t data0, const uint8_t data1); +static inline void +list_prepend(action_list_t *list, const enum A_TYPE type, + const int8_t loc, const uint8_t data0, + const uint8_t data1); + static inline void inline_next_ply(void); @@ -82,6 +87,8 @@ void action_list_init(void) { move_deltas[3] = +1; } +// We bias place over move by prepending place actions and appending +// move actions to the generated list action_list_t *action_list_generate(void) { action_list_t *list = malloc(sizeof(struct action_list_s)); @@ -198,12 +205,12 @@ action_list_t *action_list_generate(void) { else if (material) { // Empty square, generate placements if (flat) { - list_append(list, A_PLACE, loc, STONE_FLAT, 0); + list_prepend(list, A_PLACE, loc, STONE_FLAT, 0); if (standing) - list_append(list, A_PLACE, loc, STONE_STANDING,0); + list_prepend(list, A_PLACE, loc, STONE_STANDING,0); } if (cap) - list_append(list, A_PLACE, loc, STONE_CAPSTONE, 0); + list_prepend(list, A_PLACE, loc, STONE_CAPSTONE, 0); } } } @@ -396,6 +403,24 @@ list_append(action_list_t *list, const enum A_TYPE type, list->length++; } +static inline void +list_prepend(action_list_t *list, const enum A_TYPE type, + const int8_t loc, const uint8_t data0, + const uint8_t data1) { + action_node_t *new = malloc(sizeof(action_list_t)); + // TODO: trap errno + + new->next = list->head; + list->head = new; + new->action = A_BUILD(type, loc, data0, data1); + + if (list->length == 0) { + list->tail = new; + } + + list->length++; +} + static inline void inline_next_ply(void) { ply++; -- cgit v1.2.3