Shadowrun: Awakened 29 September 2011 - Build 871
mac_ppc.h
Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
00003 
00004     This file is part of Threading Building Blocks.
00005 
00006     Threading Building Blocks is free software; you can redistribute it
00007     and/or modify it under the terms of the GNU General Public License
00008     version 2 as published by the Free Software Foundation.
00009 
00010     Threading Building Blocks is distributed in the hope that it will be
00011     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00012     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Threading Building Blocks; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019     As a special exception, you may use this file as part of a free software
00020     library without restriction.  Specifically, if other files instantiate
00021     templates or use macros or inline functions from this file, or you compile
00022     this file and link it with other files to produce an executable, this
00023     file does not by itself cause the resulting executable to be covered by
00024     the GNU General Public License.  This exception does not however
00025     invalidate any other reasons why the executable file might be covered by
00026     the GNU General Public License.
00027 */
00028 
00029 #ifndef __TBB_machine_H
00030 #error Do not include this file directly; include tbb_machine.h instead
00031 #endif
00032 
00033 #include <stdint.h>
00034 #include <unistd.h>
00035 
00036 #include <sched.h> // sched_yield
00037 
00038 inline int32_t __TBB_machine_cmpswp4 (volatile void *ptr, int32_t value, int32_t comparand )
00039 {
00040     int32_t result;
00041 
00042     __asm__ __volatile__("sync\n"
00043                          "0: lwarx %0,0,%2\n\t"  /* load w/ reservation */
00044                          "cmpw %0,%4\n\t"        /* compare against comparand */
00045                          "bne- 1f\n\t"           /* exit if not same */
00046                          "stwcx. %3,0,%2\n\t"    /* store new_value */
00047                          "bne- 0b\n"             /* retry if reservation lost */
00048                          "1: sync"               /* the exit */
00049                           : "=&r"(result), "=m"(* (int32_t*) ptr)
00050                           : "r"(ptr), "r"(value), "r"(comparand), "m"(* (int32_t*) ptr)
00051                           : "cr0");
00052     return result;
00053 }
00054 
00055 inline int64_t __TBB_machine_cmpswp8 (volatile void *ptr, int64_t value, int64_t comparand )
00056 {
00057     int64_t result;
00058     __asm__ __volatile__("sync\n"
00059                          "0: ldarx %0,0,%2\n\t"  /* load w/ reservation */
00060                          "cmpd %0,%4\n\t"        /* compare against comparand */
00061                          "bne- 1f\n\t"           /* exit if not same */
00062                          "stdcx. %3,0,%2\n\t"    /* store new_value */
00063                          "bne- 0b\n"             /* retry if reservation lost */
00064                          "1: sync"               /* the exit */
00065                           : "=&b"(result), "=m"(* (int64_t*) ptr)
00066                           : "r"(ptr), "r"(value), "r"(comparand), "m"(* (int64_t*) ptr)
00067                           : "cr0");
00068     return result;
00069 }
00070 
00071 #define __TBB_BIG_ENDIAN 1
00072 
00073 #if defined(powerpc64) || defined(__powerpc64__) || defined(__ppc64__)
00074 #define __TBB_WORDSIZE 8
00075 #define __TBB_CompareAndSwapW(P,V,C) __TBB_machine_cmpswp8(P,V,C)
00076 #else
00077 #define __TBB_WORDSIZE 4
00078 #define __TBB_CompareAndSwapW(P,V,C) __TBB_machine_cmpswp4(P,V,C)
00079 #endif
00080 
00081 #define __TBB_CompareAndSwap4(P,V,C) __TBB_machine_cmpswp4(P,V,C)
00082 #define __TBB_CompareAndSwap8(P,V,C) __TBB_machine_cmpswp8(P,V,C)
00083 #define __TBB_Yield() sched_yield()
00084 #define __TBB_rel_acq_fence() __asm__ __volatile__("lwsync": : :"memory")
00085 #define __TBB_release_consistency_helper() __TBB_rel_acq_fence()

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net