Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13829
Modified Files: Tag: devel_0_38 m_fifo.c Log Message: cas/cas2 optimizing (untested on win32) & cas for ppc (untested, as well)
Index: m_fifo.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/m_fifo.c,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** m_fifo.c 11 Dec 2004 10:34:55 -0000 1.1.2.3 --- m_fifo.c 15 Dec 2004 22:05:59 -0000 1.1.2.4 *************** *** 30,48 **** /* gcc on i386 */
! #define CAS(mem, old, new) \ ! ({ __asm__ __volatile__( \ ! "lock cmpxchg %2,%0 \n" \ ! : : \ ! "m" (*mem), "a" (old), "r" (new) ); \ ! (void*)old != (void*)(*mem); \ })
! #define CAS2(mem, old1, old2, new1, new2) \ ! ({ __asm__ __volatile__( \ ! "lock cmpxchg8b %0 \n" \ ! : : \ ! "m" (*mem), "a" (old1), "d" (old2), \ ! "b" (new1), "c"(new2)); \ ! (void*) old1 != (void*) (*mem); \ })
--- 30,56 ---- /* gcc on i386 */
! #define CAS(mem, old, new) \ ! ({ int ret = 0; \ ! __asm__ __volatile__( \ ! "lock cmpxchg %3,%1 \n" \ ! "jnz 1f \n" \ ! "inc %0 \n" \ ! "1: \n" \ ! :"=r"(ret) : \ ! "m" (*mem), "a" (old), "r" (new), "0"(ret) ); \ ! ret; \ })
! #define CAS2(mem, old1, old2, new1, new2) \ ! ({ int ret = 0; \ ! __asm__ __volatile__( \ ! "lock cmpxchg8b %1 \n" \ ! "jnz 1f \n" \ ! "inc %0 \n" \ ! "1: \n" \ ! :"=r"(ret) : \ ! "m" (*mem), "a" (old1), "d" (old2), \ ! "b" (new1), "c"(new2), "0"(ret)); \ ! ret; \ })
*************** *** 51,56 **** /* msvc on i386 */
! __inline int CAS(void** mem, void* old, void* new1) { __asm { mov eax, old --- 59,65 ---- /* msvc on i386 */
! int CAS(void** mem, void* old, void* new1) { + int ret = 0; __asm { mov eax, old *************** *** 58,67 **** mov esi, mem lock cmpxchg dword ptr [esi], ebx ! } ! return ((void*) old != (void*)(*mem)); }
! __inline int CAS2(void** mem, void* old1, unsigned long old2, void* new1, unsigned long new2) { __asm { mov eax, old1 --- 67,80 ---- mov esi, mem lock cmpxchg dword ptr [esi], ebx ! jnz end ! inc [ret] ! end: ! } ! return ret; }
! int CAS2(void** mem, void* old1, unsigned long old2, void* new1, unsigned long new2) { + int ret = 0; __asm { mov eax, old1 *************** *** 71,78 **** mov esi, mem lock cmpxchg8b qword ptr [esi] ! } ! return ((void*) old1 != (void*)(*mem)); }
#else
--- 84,116 ---- mov esi, mem lock cmpxchg8b qword ptr [esi] ! jnz end ! inc [ret] ! end: ! } ! return ret; }
+ #elif defined(__POWERPC__) + + /* gcc on ppc */ \ + #define CAS(mem, old, new) \ + ({ __typeof__(old) tmp; \ + int ret = 0; \ + __asm__ __volatile__( \ + "1: \n" \ + "lwarx %0,0,%2 \n" \ + "cmpw %0,%3 \n" \ + "bne 1f \n" \ + "stwcx %0,0,%4 \n" \ + "bne 1b \n" \ + "li %1,1 \n" \ + "1: \n" \ + :"=&r"(tmp), "=r"(ret) : \ + "m" (*mem), "r" (old), "r" (new) ); \ + ret; \ + }) + + #error CAS2 hasn't been implemented for ppc, yet + #else
*************** *** 235,239 **** }
! /* fifo_put() and fifo_get are the only threadsafe functions!!! */ void fifo_put(t_fifo* fifo, void* data) { --- 273,277 ---- }
! /* fifo_put and fifo_get are the only threadsafe functions!!! */ void fifo_put(t_fifo* fifo, void* data) {