File: atomic-memory-1.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (44 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* { dg-do run } */

/* { dg-message "note: '__sync_nand_and_fetch' changed semantics in GCC 4.4" "" { target mips_llsc } 0 } */

extern void abort (void);
extern void exit (int);

NOMIPS16 int main ()
{
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
  unsigned v = 0;
  __sync_synchronize ();

  if (!__sync_bool_compare_and_swap (&v, 0, 30000))
    abort();
  if (30000 != __sync_val_compare_and_swap (&v, 30000, 100001))
    abort();
  __sync_sub_and_fetch (&v, 0x8001);
  __sync_sub_and_fetch (&v, 0x7fff);
  if (v != 34465)
    abort();
  if (__sync_nand_and_fetch (&v, 0xff) != -162)
    abort();
  if (__sync_fetch_and_add (&v, 262) != -162)
    abort();
  if (v != 100)
    abort();
  if (__sync_or_and_fetch (&v, 0xf001) != 0xf065)
    abort();
  if (__sync_and_and_fetch (&v, 0x1000) != 0x1000)
    abort();
  if (__sync_xor_and_fetch (&v, 0xa51040) != 0xa50040)
    abort();
  __sync_and_and_fetch (&v, 7);
  if (__sync_lock_test_and_set(&v, 1) != 0)
    abort();
  if (v != 1)
    abort();
  __sync_lock_release (&v);
  if (v != 0)
    abort();
#endif
  exit(0);
}