<commit_before>/* atomic/gcc_pcc.h
 *  Copyright (C) 2006-2008, Parrot Foundation.
 *  SVN Info
 *     $Id$
 *  Overview:
 *     This header provides an implementation of atomic
 *     operations on PowerPC platforms with GCC-style
 *     inline assembly suppport.
 *  Data Structure and Algorithms:
 *  History:
 *  Notes:
 *  References:
 */

#ifndef PARROT_ATOMIC_GCC_PCC_H_GUARD
#define PARROT_ATOMIC_GCC_PCC_H_GUARD

typedef struct Parrot_atomic_pointer {
    void * volatile val;
} Parrot_atomic_pointer;

#  define PARROT_ATOMIC_PTR_GET(result, a) (result) = (void *) (a).val

#  define PARROT_ATOMIC_PTR_SET(a, b) (a).val = (void *) (b)

inline static void *parrot_ppc_cmpset(void * volatile *ptr,
                                      void *expect, void *update)
{
    void *tmp;
    /* see http://www-128.ibm.com/developerworks/linux/library/pa-atom/ */
    __asm__ __volatile__(/*%0 = tmp, %1 = ptr, %2 = old, %3 = new */
                            "1:  lwarx %0, 0, %1\n"     /* tmp = *ptr, with reservation */
                            "    cmpw %2, %0\n" /* tmp == old ? */
                            "    bne 2f\n"      /* no, goto flush reservation, end */
                            /* "    sync\n" -- XXX needed on PPC 405, see
                             * http://www.kegel.com/xgcc3/ppc405erratum77.html */
                            "    stwcx. %3, 0, %1\n"    /* store new using reservation */
                            "    bne- 1b\n"     /* spin on failure of reservation; - is branch prediction hint */
                            "    b 3f\n" "2:  stwcx. %0, 0, %1\n"       /* flush reserveration */
                            "3:  \n"    /* end label */
                            :   /* output */
                            "=&r"(tmp)
                            :   /* input */
                            "r"(ptr), "r"(expect), "r"(update)
                            :   /* clobber */
                            "memory");
    return tmp;
}

inline static long parrot_ppc_add(volatile long *val, long what)
{<commit_msg>add C function documentation<commit_after>/* atomic/gcc_pcc.h
 *  Copyright (C) 2006-2010, Parrot Foundation.
 *  SVN Info
 *     $Id$
 *  Overview:
 *     This header provides an implementation of atomic
 *     operations on PowerPC platforms with GCC-style
 *     inline assembly suppport.
 *  Data Structure and Algorithms:
 *  History:
 *  Notes:
 *  References:
 */

#ifndef PARROT_ATOMIC_GCC_PCC_H_GUARD
#define PARROT_ATOMIC_GCC_PCC_H_GUARD

typedef struct Parrot_atomic_pointer {
    void * volatile val;
} Parrot_atomic_pointer;

#  define PARROT_ATOMIC_PTR_GET(result, a) (result) = (void *) (a).val

#  define PARROT_ATOMIC_PTR_SET(a, b) (a).val = (void *) (b)

/*

=over 4

=item C<inline static void *parrot_ppc_cmpset(void * volatile *ptr, void
*expect, void *update)>

Generate ppc cmpset

=cut

*/
inline static void *parrot_ppc_cmpset(void * volatile *ptr,
                                      void *expect, void *update)
{
    void *tmp;
    /* see http://www-128.ibm.com/developerworks/linux/library/pa-atom/ */
    __asm__ __volatile__(/*%0 = tmp, %1 = ptr, %2 = old, %3 = new */
                            "1:  lwarx %0, 0, %1\n"     /* tmp = *ptr, with reservation */
                            "    cmpw %2, %0\n" /* tmp == old ? */
                            "    bne 2f\n"      /* no, goto flush reservation, end */
                            /* "    sync\n" -- XXX needed on PPC 405, see
                             * http://www.kegel.com/xgcc3/ppc405erratum77.html */
                            "    stwcx. %3, 0, %1\n"    /* store new using reservation */
                            "    bne- 1b\n"     /* spin on failure of reservation; - is branch prediction hint */
                            "    b 3f\n" "2:  stwcx. %0, 0, %1\n"       /* flush reserveration */
                            "3:  \n"    /* end label */
                            :   /* output */
                            "=&r"(tmp)
                            :   /* input */
                            "r"(ptr), "r"(expect), "r"(update)
                            :   /* clobber */
                            "memory");
    return tmp;
}

/*

=item C<inline static long parrot_ppc_add(volatile long *val, long what)>

Generate ppc add

=back

=cut

*/

inline static long parrot_ppc_add(volatile long *val, long what)
{
{'fraction_non_alphanumeric': 0.12482946793997271, 'fraction_numerical': 0.018872214643019556, 'mean_word_length': 1.4506963788300835, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4602691', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1395, 'n_words': 352}