<commit_before>#ifndef _DHT_H_
#define _DHT_H_

#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>

#if defined(LOCKS)
#  include "lock_if.h"
#endif


#define true 1
#define false 0

#define CACHE_LINE_SIZE 64
#define ENTRIES_PER_BUCKET 15

#ifndef ALIGNED
#  if __GNUC__ && !SCC
#    define ALIGNED(N) __attribute__ ((aligned (N)))
#  else
#    define ALIGNED(N)
#  endif
#endif

#if defined(__sparc__)
#define PREFETCHW(x) 
#define PREFETCH(x) 
#define PREFETCHNTA(x) 
#define PREFETCHT0(x) 
#define PREFETCHT1(x) 
#define PREFETCHT2(x) 

#  define PAUSE    asm volatile("rd    %%ccr, %%g0\n\t" \
				::: "memory")
#define _mm_pause() PAUSE
#define _mm_mfence() __asm__ __volatile__("membar #LoadLoad | #LoadStore | #StoreLoad | #StoreStore");
#define _mm_lfence() __asm__ __volatile__("membar #LoadLoad | #LoadStore");
#define _mm_sfence() __asm__ __volatile__("membar #StoreLoad | #StoreStore");


#elif defined(__tile__)
#define _mm_lfence() arch_atomic_read_barrier()
#define _mm_sfence() arch_atomic_write_barrier()
#define _mm_mfence() arch_atomic_full_barrier()
#define _mm_pause() cycle_relax()
#endif

typedef uintptr_t ssht_addr_t;

typedef struct ALIGNED(CACHE_LINE_SIZE) bucket_s
{
  ssht_addr_t key[ENTRIES_PER_BUCKET];
  struct bucket_s *next;
} bucket_t;

#if defined(LOCKS)
typedef struct ALIGNED(64) hashtable_s
{
  uint32_t capacity;
  volatile global_data the_locks;
  ALIGNED(CACHE_LINE_SIZE) bucket_t *table;
} hashtable_t;

#elif defined(MESSAGE_PASSING)
typedef struct ALIGNED(64) hashtable_s
{
  uint32_t capacity;
#  if defined(__tile__)
  bucket_t *table;
#  else
  ALIGNED(CACHE_LINE_SIZE) bucket_t *table;
#  endif
} hashtable_t;

#else 
#  error "defined either LOCKS or MESSAGE_PASSING"
#endif


/* Create a new hashtable. */
hashtable_t* ht_create(uint32_t capacity );

/* Hash a key for a particular hashtable. */
uint32_t ht_hash( hashtable_t *hashtable, uint64_t key );

/* Insert a key-value pair into a hashtable. */
uint32_t ht_put( hashtable_t *hashtable, uint64_t key, void *value, uint32_t bin);
<commit_msg>bucket size = 14 for xeon<commit_after>#ifndef _DHT_H_
#define _DHT_H_

#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>

#if defined(LOCKS)
#  include "lock_if.h"
#endif


#define true 1
#define false 0

#define CACHE_LINE_SIZE 64
#if defined(XEON)
#  define ENTRIES_PER_BUCKET 14
#else
#  define ENTRIES_PER_BUCKET 6
#endif

#ifndef ALIGNED
#  if __GNUC__ && !SCC
#    define ALIGNED(N) __attribute__ ((aligned (N)))
#  else
#    define ALIGNED(N)
#  endif
#endif

#if defined(__sparc__)
#define PREFETCHW(x) 
#define PREFETCH(x) 
#define PREFETCHNTA(x) 
#define PREFETCHT0(x) 
#define PREFETCHT1(x) 
#define PREFETCHT2(x) 

#  define PAUSE    asm volatile("rd    %%ccr, %%g0\n\t" \
				::: "memory")
#define _mm_pause() PAUSE
#define _mm_mfence() __asm__ __volatile__("membar #LoadLoad | #LoadStore | #StoreLoad | #StoreStore");
#define _mm_lfence() __asm__ __volatile__("membar #LoadLoad | #LoadStore");
#define _mm_sfence() __asm__ __volatile__("membar #StoreLoad | #StoreStore");


#elif defined(__tile__)
#define _mm_lfence() arch_atomic_read_barrier()
#define _mm_sfence() arch_atomic_write_barrier()
#define _mm_mfence() arch_atomic_full_barrier()
#define _mm_pause() cycle_relax()
#endif

typedef uintptr_t ssht_addr_t;

typedef struct ALIGNED(CACHE_LINE_SIZE) bucket_s
{
  ssht_addr_t key[ENTRIES_PER_BUCKET];
  struct bucket_s *next;
} bucket_t;

#if defined(LOCKS)
typedef struct ALIGNED(64) hashtable_s
{
  uint32_t capacity;
  volatile global_data the_locks;
  ALIGNED(CACHE_LINE_SIZE) bucket_t *table;
} hashtable_t;

#elif defined(MESSAGE_PASSING)
typedef struct ALIGNED(64) hashtable_s
{
  uint32_t capacity;
#  if defined(__tile__)
  bucket_t *table;
#  else
  ALIGNED(CACHE_LINE_SIZE) bucket_t *table;
#  endif
} hashtable_t;




static inline void
_mm_pause_rep(uint64_t w)
{
  while (w--)
    {
      _mm_pause();
    }
}

  /* while (!CAS_U64_BOOL(lock, 0, 1))		\ */

/* #define TTAS */

#if defined(TTAS)
#define LOCK_ACQ(lock)				\
  while (*lock != 0)				\
    {						\
      _mm_lfence();				\
      _mm_pause();				\
    }						\
  while (FAI_U64(lock))				\
    {						\
      _mm_pause();				\
      DPP(put_num_restarts);			\
    }						

#define LOCK_RLS(lock)				\
  _mm_mfence();					\
  *lock = 0;	  
#else
#define LOCK_ACQ(lock)				\
  while (FAI_U64(lock))				\
    {						\
      _mm_pause();				\
      DPP(put_num_restarts);			\
    }						

#define LOCK_RLS(lock)				\
  _mm_mfence();					\
  *lock = 0;	  
#endif


/* Create a new hashtable. */
hashtable_t* ht_create(uint32_t capacity );

/* Hash a key for a particular hashtable. */
uint32_t ht_hash( hashtable_t *hashtable, uint64_t key );

/* Insert a key-value pair into a hashtable. */
uint32_t ht_put( hashtable_t *hashtable, uint64_t key, void *value, uint32_t bin);

{'fraction_non_alphanumeric': 0.12130605497003513, 'fraction_numerical': 0.015705724323207274, 'mean_word_length': 4.283842794759825, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4958740', 'n_tokens_mistral': 2157, 'n_tokens_neox': 1956, 'n_words': 432}