#ifndef _SPECIFIC_COMM_H_ #define _SPECIFIC_COMM_H_ 1 /* Non standard include */ #include /* This is not an error, we need this two-macro system */ #define toString(x) doStringification(x) #define doStringification(x) #x __BEGIN_DECLS struct channel { volatile void *buf[2 * BUF_SIZE / sizeof(void *)] __attribute__ ((aligned (CACHE_LINE_SIZE))); volatile int state __attribute__ ((aligned (CACHE_LINE_SIZE))); int idx __attribute__ ((aligned (CACHE_LINE_SIZE))); }; struct cons { struct channel *channel; int receiver_idx; }; union comm { struct channel *channel; struct cons *cons; }; extern __thread union comm comm; extern int swap_buffer; static inline void send(void **addr) { asm volatile("mov %%gs:channel@NTPOFF + 2 *" toString(BUF_SIZE) " + " toString(CACHE_LINE_SIZE) ", %%eax\n\t" "mov %0, %%gs:cons.channel@NTPOFF(%%eax)\n\t" "addl $4, %%eax\n\t" "andl $(2*" toString(BUF_SIZE) "-1), %%eax\n\t" "mov %%eax, %%gs:cons.channel@NTPOFF + 2 * " toString(BUF_SIZE)" + " toString(CACHE_LINE_SIZE) "\n\t" "test $(" toString(BUF_SIZE) " - 1), %%eax\n\t" "mov $2f, %%eax\n\t" "jz swap_buffer\n\t" "2:" : : "r"(addr) : "%eax"); } __END_DECLS #endif