~ubuntu-branches/ubuntu/quantal/libgc/quantal

« back to all changes in this revision

Viewing changes to libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc/s390.h

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-19 12:19:56 UTC
  • mfrom: (1.3.2 upstream) (0.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110219121956-67rb69xlt5nud3v2
Tags: 1:7.1-5
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
 
3
 * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
 
4
 * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved.
 
5
 *
 
6
 *
 
7
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 
8
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 
9
 *
 
10
 * Permission is hereby granted to use or copy this program
 
11
 * for any purpose,  provided the above notices are retained on all copies.
 
12
 * Permission to modify the code and to distribute modified code is granted,
 
13
 * provided the above notices are retained, and a notice that the code was
 
14
 * modified is included with the above copyright notice.
 
15
 *
 
16
 */
 
17
 
 
18
/* FIXME: untested.                                             */
 
19
/* The relevant documentation appears to be at                  */
 
20
/* http://publibz.boulder.ibm.com/epubs/pdf/dz9zr003.pdf        */
 
21
/* around page 5-96.  Apparently:                               */
 
22
/* - Memory references in general are atomic only for a single  */
 
23
/*   byte.  But it appears that the most common load/store      */
 
24
/*   instructions also guarantee atomicity for aligned          */
 
25
/*   operands of standard types.  WE FOOLISHLY ASSUME that      */
 
26
/*   compilers only generate those.  If that turns out to be    */
 
27
/*   wrong, we need inline assembly code for AO_load and        */
 
28
/*   AO_store.                                                  */
 
29
/* - A store followed by a load is unordered since the store    */
 
30
/*   may be delayed.  Otherwise everything is ordered.          */
 
31
/* - There is a hardware compare-and-swap (CS) instruction.     */
 
32
 
 
33
#include "ordered_except_wr.h"
 
34
#include "all_aligned_atomic_load_store.h"
 
35
 
 
36
#include "../test_and_set_t_is_ao_t.h"
 
37
/* FIXME: Is there a way to do byte-sized test-and-set? */
 
38
 
 
39
/* FIXME: AO_nop_full should probably be implemented directly.  */
 
40
/* It appears that certain BCR instructions have that effect.   */
 
41
/* Presumably they're cheaper than CS?                          */
 
42
 
 
43
AO_INLINE AO_t AO_compare_and_swap_full(volatile AO_t *addr,
 
44
                                               AO_t old, AO_t new_val)
 
45
{
 
46
  int retval;
 
47
  __asm__ __volatile__ (
 
48
# ifndef __s390x__
 
49
    "     cs  %1,%2,0(%3)\n"
 
50
# else
 
51
    "     csg %1,%2,0(%3)\n"
 
52
# endif
 
53
  "     ipm %0\n"
 
54
  "     srl %0,28\n"
 
55
  : "=&d" (retval), "+d" (old)
 
56
  : "d" (new_val), "a" (addr)
 
57
  : "cc", "memory");
 
58
  return retval == 0;
 
59
}
 
60
 
 
61
#define AO_HAVE_compare_and_swap_full
 
62
 
 
63
/* FIXME: Add double-wide compare-and-swap for 32-bit executables.      */