Micro-optimization of DICT_OA

by reducing the number of cmp instructions.
This commit is contained in:
Patrick Pelissier committed 2021-02-13 11:45:16 +01:00
1 parent 517da1b999
commit a73bee2650
2 files changed
+10 -8

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
#include "../common.c" #include "../common.c"
#define DICTI_OA_PROBING(s) 1 #define M_USE_DICT_OA_PROBING(s) 1
#include "m-dict.h" #include "m-dict.h"
static inline bool oor_equal_p(unsigned int k, unsigned char n) static inline bool oor_equal_p(unsigned int k, unsigned char n)
+9 -7
View File
@@ -1175,8 +1175,10 @@ enum M_D1CT_oa_element_e {
/* Performing Quadratic probing /* Performing Quadratic probing
Replace it by '1' to perform linear probing */ Replace it by '1' to perform linear probing */
#ifndef M_D1CT_OA_PROBING #ifdef M_USE_DICT_OA_PROBING
#define M_D1CT_OA_PROBING(s) ((s)++) # define M_D1CT_OA_PROBING M_USE_DICT_OA_PROBING
#else
# define M_D1CT_OA_PROBING(s) ((s)++)
#endif #endif
/* Lower Bound of the hash table (TODO: Common macro for both dictionnary) */ /* Lower Bound of the hash table (TODO: Common macro for both dictionnary) */
@@ -1309,7 +1311,7 @@ enum M_D1CT_oa_element_e {
M_D1CT_OA_CONTRACT(dict); \ M_D1CT_OA_CONTRACT(dict); \
for(size_t i = 0; i <= dict->mask; i++) { \ for(size_t i = 0; i <= dict->mask; i++) { \
if (!M_CALL_OOR_EQUAL(key_oplist, dict->data[i].key, M_D1CT_OA_EMPTY) \ if (!M_CALL_OOR_EQUAL(key_oplist, dict->data[i].key, M_D1CT_OA_EMPTY) \
&& !M_CALL_OOR_EQUAL(key_oplist, dict->data[i].key, M_D1CT_OA_DELETED)) { \ & !M_CALL_OOR_EQUAL(key_oplist, dict->data[i].key, M_D1CT_OA_DELETED)) { \
M_CALL_CLEAR(key_oplist, dict->data[i].key); \ M_CALL_CLEAR(key_oplist, dict->data[i].key); \
M_CALL_CLEAR(value_oplist, dict->data[i].value); \ M_CALL_CLEAR(value_oplist, dict->data[i].value); \
} \ } \
@@ -1405,10 +1407,10 @@ enum M_D1CT_oa_element_e {
const size_t mask = (newSize -1); \ const size_t mask = (newSize -1); \
\ \
for(size_t i = 0 ; i < oldSize; i++) { \ for(size_t i = 0 ; i < oldSize; i++) { \
if (!M_CALL_OOR_EQUAL(key_oplist, data[i].key, M_D1CT_OA_DELETED) && !M_CALL_OOR_EQUAL(key_oplist, data[i].key, M_D1CT_OA_EMPTY)) { \ if (!M_CALL_OOR_EQUAL(key_oplist, data[i].key, M_D1CT_OA_DELETED) & !M_CALL_OOR_EQUAL(key_oplist, data[i].key, M_D1CT_OA_EMPTY)) { \
size_t p = M_CALL_HASH(key_oplist, data[i].key) & mask; \ size_t p = M_CALL_HASH(key_oplist, data[i].key) & mask; \
if (p != i) { \ if (p != i) { \
if (M_LIKELY (M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) || M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_DELETED))) { \ if (M_LIKELY (M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) | M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_DELETED))) { \
M_DO_INIT_MOVE(key_oplist, data[p].key, data[i].key); \ M_DO_INIT_MOVE(key_oplist, data[p].key, data[i].key); \
M_DO_INIT_MOVE(value_oplist, data[p].value, data[i].value); \ M_DO_INIT_MOVE(value_oplist, data[p].value, data[i].value); \
} else { \ } else { \
@@ -1482,7 +1484,7 @@ enum M_D1CT_oa_element_e {
return; \ return; \
} \ } \
M_ASSERT (s <= dict->mask); \ M_ASSERT (s <= dict->mask); \
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_DELETED) && delPos == (size_t)-1) delPos = p; \ if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_DELETED) & (delPos == (size_t)-1)) delPos = p; \
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) ); \ } while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) ); \
if (delPos != SIZE_MAX) { \ if (delPos != SIZE_MAX) { \
p = delPos; \ p = delPos; \
@@ -1533,7 +1535,7 @@ enum M_D1CT_oa_element_e {
return &data[p].M_IF(isSet)(key, value); \ return &data[p].M_IF(isSet)(key, value); \
} \ } \
M_ASSERT (s <= dict->mask); \ M_ASSERT (s <= dict->mask); \
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_DELETED) && delPos == (size_t)-1) delPos = p; \ if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_DELETED) & (delPos == (size_t)-1)) delPos = p; \
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) ); \ } while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) ); \
if (delPos != SIZE_MAX) { \ if (delPos != SIZE_MAX) { \
p = delPos; \ p = delPos; \