Qore Programming Language  0.8.3
include/qore/macros-x86_64.h (4311)
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */
00002 /*
00003   Qore Programming Language
00004 
00005   Copyright 2003 - 2011 David Nichols
00006 
00007   This library is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU Lesser General Public
00009   License as published by the Free Software Foundation; either
00010   version 2.1 of the License, or (at your option) any later version.
00011 
00012   This library is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   Lesser General Public License for more details.
00016 
00017   You should have received a copy of the GNU Lesser General Public
00018   License along with this library; if not, write to the Free Software
00019   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 */
00021 
00022 #ifndef _QORE_MACHINE_MACROS_H
00023 #define _QORE_MACHINE_MACROS_H
00024 
00025 #define STACK_DIRECTION_DOWN 1
00026 
00027 #ifdef __GNUC__
00028 
00029 #define HAVE_ATOMIC_MACROS
00030 #define HAVE_CHECK_STACK_POS
00031 
00032 // returns 1 when counter reaches zero, 0 if not
00033 static inline int atomic_dec(volatile int *a) {
00034    unsigned char rc;
00035 
00036    __asm(
00037         "lock; decl %0; sete %1"
00038         : "=m" (*a), "=qm" (rc)
00039         : "m" (*a) : "memory"
00040       );
00041    return rc != 0;
00042 }
00043 
00044 static inline void atomic_inc(volatile int *a) {
00045    __asm(
00046         "lock; incl %0"
00047         : "=m" (*a)
00048    );
00049 }
00050 
00051 static inline size_t get_stack_pos() {
00052    size_t addr;
00053    __asm("movq %%rsp, %0" : "=g" (addr) );
00054    return addr;
00055 }
00056 
00057 #endif // #ifdef __GNUC__
00058 
00059 #ifdef __SUNPRO_CC
00060 
00061 #define HAVE_ATOMIC_MACROS
00062 #define HAVE_CHECK_STACK_POS
00063 
00064 // these routines are implemented in assembler
00065 extern "C" int atomic_dec(volatile int *a);
00066 extern "C" void atomic_inc(volatile int *a);
00067 
00068 extern "C" size_t get_stack_pos();
00069 
00070 #endif // #ifdef __SUNPRO_CC
00071 
00072 #endif // #ifndef _QORE_MACHINE_MACROS_H
00073 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines