ck_ht: Enable pointer packing only if explicitly enabled.

Pointer packing is only utilized on the x86_64 port.
ck_pring
Samy Al Bahra 13 years ago
parent 84f7136cbb
commit 8bed9627a6

@ -34,6 +34,7 @@
#include <ck_cc.h> #include <ck_cc.h>
#include <ck_malloc.h> #include <ck_malloc.h>
#include <ck_md.h>
#include <ck_stdint.h> #include <ck_stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
@ -48,8 +49,12 @@ enum ck_ht_mode {
CK_HT_MODE_BYTESTRING CK_HT_MODE_BYTESTRING
}; };
#if defined(__x86_64__) && defined(CK_MD_POINTER_PACK_ENABLE)
#define CK_HT_PP
#endif
struct ck_ht_entry { struct ck_ht_entry {
#ifdef __x86_64__ #ifdef CK_HT_PP
uintptr_t key; uintptr_t key;
uintptr_t value CK_CC_PACKED; uintptr_t value CK_CC_PACKED;
#else #else
@ -108,7 +113,7 @@ CK_CC_INLINE static void
ck_ht_entry_key_set(ck_ht_entry_t *entry, const void *key, uint16_t key_length) ck_ht_entry_key_set(ck_ht_entry_t *entry, const void *key, uint16_t key_length)
{ {
#ifdef __x86_64__ #ifdef CK_HT_PP
entry->key = (uintptr_t)key | ((uintptr_t)key_length << 48); entry->key = (uintptr_t)key | ((uintptr_t)key_length << 48);
#else #else
entry->key = (uintptr_t)key; entry->key = (uintptr_t)key;
@ -122,7 +127,7 @@ CK_CC_INLINE static void *
ck_ht_entry_key(ck_ht_entry_t *entry) ck_ht_entry_key(ck_ht_entry_t *entry)
{ {
#ifdef __x86_64__ #ifdef CK_HT_PP
return (void *)(entry->key & (((uintptr_t)1 << 48) - 1)); return (void *)(entry->key & (((uintptr_t)1 << 48) - 1));
#else #else
return (void *)entry->key; return (void *)entry->key;
@ -133,7 +138,7 @@ CK_CC_INLINE static uint16_t
ck_ht_entry_key_length(ck_ht_entry_t *entry) ck_ht_entry_key_length(ck_ht_entry_t *entry)
{ {
#ifdef __x86_64__ #ifdef CK_HT_PP
return entry->key >> 48; return entry->key >> 48;
#else #else
return entry->key_length; return entry->key_length;
@ -144,7 +149,7 @@ CK_CC_INLINE static void *
ck_ht_entry_value(ck_ht_entry_t *entry) ck_ht_entry_value(ck_ht_entry_t *entry)
{ {
#ifdef __x86_64__ #ifdef CK_HT_PP
return (void *)(entry->value & (((uintptr_t)1 << 48) - 1)); return (void *)(entry->value & (((uintptr_t)1 << 48) - 1));
#else #else
return (void *)entry->value; return (void *)entry->value;
@ -159,7 +164,7 @@ ck_ht_entry_set(struct ck_ht_entry *entry,
const void *value) const void *value)
{ {
#ifdef __x86_64__ #ifdef CK_HT_PP
entry->key = (uintptr_t)key | ((uintptr_t)key_length << 48); entry->key = (uintptr_t)key | ((uintptr_t)key_length << 48);
entry->value = (uintptr_t)value | ((uintptr_t)(h.value >> 32) << 48); entry->value = (uintptr_t)value | ((uintptr_t)(h.value >> 32) << 48);
#else #else

@ -46,7 +46,7 @@
#ifndef CK_HT_BUCKET_LENGTH #ifndef CK_HT_BUCKET_LENGTH
#ifdef __x86_64__ #ifdef CK_HT_PP
#define CK_HT_BUCKET_SHIFT 2ULL #define CK_HT_BUCKET_SHIFT 2ULL
#else #else
#define CK_HT_BUCKET_SHIFT 1ULL #define CK_HT_BUCKET_SHIFT 1ULL
@ -195,7 +195,7 @@ ck_ht_map_probe(struct ck_ht_map *map,
uint64_t probes = 0; uint64_t probes = 0;
uint64_t probe_maximum; uint64_t probe_maximum;
#ifndef __x86_64__ #ifndef CK_HT_PP
uint64_t d = 0; uint64_t d = 0;
uint64_t d_prime = 0; uint64_t d_prime = 0;
retry: retry:
@ -230,7 +230,7 @@ retry:
* it is worth the code duplication. * it is worth the code duplication.
*/ */
if (probe_limit == NULL) { if (probe_limit == NULL) {
#ifdef __x86_64__ #ifdef CK_HT_PP
snapshot->key = (uintptr_t)ck_pr_load_ptr(&cursor->key); snapshot->key = (uintptr_t)ck_pr_load_ptr(&cursor->key);
ck_pr_fence_load(); ck_pr_fence_load();
snapshot->value = (uintptr_t)ck_pr_load_ptr(&cursor->value); snapshot->value = (uintptr_t)ck_pr_load_ptr(&cursor->value);
@ -267,7 +267,7 @@ retry:
if (map->mode == CK_HT_MODE_BYTESTRING) { if (map->mode == CK_HT_MODE_BYTESTRING) {
void *pointer; void *pointer;
#ifndef __x86_64__ #ifndef CK_HT_PP
if (probe_limit == NULL) { if (probe_limit == NULL) {
d_prime = ck_pr_load_64(&map->deletions); d_prime = ck_pr_load_64(&map->deletions);
@ -288,7 +288,7 @@ retry:
if (k != key_length) if (k != key_length)
continue; continue;
#ifdef __x86_64__ #ifdef CK_HT_PP
if (snapshot->value >> 48 != ((h.value >> 32) & 0xFFFF)) if (snapshot->value >> 48 != ((h.value >> 32) & 0xFFFF))
continue; continue;
#else #else
@ -504,14 +504,14 @@ ck_ht_get_spmc(ck_ht_t *table,
struct ck_ht_entry *candidate, snapshot; struct ck_ht_entry *candidate, snapshot;
struct ck_ht_map *map; struct ck_ht_map *map;
#ifdef __x86_64__ #ifdef CK_HT_PP
uint64_t d, d_prime; uint64_t d, d_prime;
restart: restart:
#endif #endif
map = ck_pr_load_ptr(&table->map); map = ck_pr_load_ptr(&table->map);
#ifdef __x86_64__ #ifdef CK_HT_PP
/* /*
* Platforms that cannot read key and key_length atomically must reprobe * Platforms that cannot read key and key_length atomically must reprobe
* on the scan of any single entry. * on the scan of any single entry.
@ -527,7 +527,7 @@ restart:
(void *)entry->key, sizeof(entry->key), NULL); (void *)entry->key, sizeof(entry->key), NULL);
} }
#ifdef __x86_64__ #ifdef CK_HT_PP
d_prime = ck_pr_load_64(&map->deletions); d_prime = ck_pr_load_64(&map->deletions);
if (d != d_prime) { if (d != d_prime) {
/* /*
@ -590,7 +590,7 @@ ck_ht_set_spmc(ck_ht_t *table,
* before transitioning from K to T. (K, B) implies (K, B, D') * before transitioning from K to T. (K, B) implies (K, B, D')
* so we will reprobe successfully from this transient state. * so we will reprobe successfully from this transient state.
*/ */
#ifndef __x86_64__ #ifndef CK_HT_PP
ck_pr_store_64(&priority->key_length, entry->key_length); ck_pr_store_64(&priority->key_length, entry->key_length);
ck_pr_store_64(&priority->hash, entry->hash); ck_pr_store_64(&priority->hash, entry->hash);
#endif #endif
@ -611,7 +611,7 @@ ck_ht_set_spmc(ck_ht_t *table,
if (priority != NULL) if (priority != NULL)
candidate = priority; candidate = priority;
#ifdef __x86_64__ #ifdef CK_HT_PP
ck_pr_store_ptr(&candidate->value, (void *)entry->value); ck_pr_store_ptr(&candidate->value, (void *)entry->value);
ck_pr_fence_store(); ck_pr_fence_store();
ck_pr_store_ptr(&candidate->key, (void *)entry->key); ck_pr_store_ptr(&candidate->key, (void *)entry->key);
@ -688,7 +688,7 @@ ck_ht_put_spmc(ck_ht_t *table,
if (priority != NULL) if (priority != NULL)
candidate = priority; candidate = priority;
#ifdef __x86_64__ #ifdef CK_HT_PP
ck_pr_store_ptr(&candidate->value, (void *)entry->value); ck_pr_store_ptr(&candidate->value, (void *)entry->value);
ck_pr_fence_store(); ck_pr_fence_store();
ck_pr_store_ptr(&candidate->key, (void *)entry->key); ck_pr_store_ptr(&candidate->key, (void *)entry->key);

Loading…
Cancel
Save