OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.dg/] [simulate-thread/] [subfields.c] - Blame information for rev 749

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 689 jeremybenn
/* { dg-do link } */
2
/* { dg-options "--param allow-packed-store-data-races=0" } */
3
/* { dg-final { simulate-thread } } */
4
 
5
#include <stdio.h>
6
#include "simulate-thread.h"
7
 
8
/* This test verifies that data races aren't introduced by structure subfield
9
   stores. */
10
 
11
struct test_struct {
12
  char a;
13
  char b;
14
  char c;
15
  char d;
16
} var = {0,0,0,0};
17
 
18
 
19
/* This routine sets field a to 'x'.  If executed properly, it will
20
   not affect any of the other fields in the structure.  An improper
21
   implementation may load an entire word, change the 8 bits for field
22
   'a' and write the entire word back out. */
23
__attribute__((noinline))
24
void set_a(char x)
25
{
26
  var.a = x;
27
}
28
 
29
static int global = 0;
30
 
31
/* The other thread increments the value of each of the other fields
32
   in the structure every cycle.  If the store to the 'a' field does
33
   an incorrect full or partial word load, mask and store, it will
34
   write back an incorrect value to one or more of the other
35
   fields.  */
36
void simulate_thread_other_threads()
37
{
38
  global++;
39
  var.b = global;
40
  var.c = global;
41
  var.d = global;
42
}
43
 
44
 
45
/* Make sure that none of the other fields have been changed.  */
46
int simulate_thread_step_verify()
47
{
48
  int ret = 0;
49
  if (var.b != global)
50
    {
51
      printf("FAIL: Unexpected value. var.b is %d, should be %d\n",
52
             var.b, global);
53
      ret = 1;
54
    }
55
  if (var.c != global)
56
    {
57
      printf("FAIL: Unexpected value. var.c is %d, should be %d\n",
58
             var.c, global);
59
      ret = 1;
60
    }
61
  if (var.d != global)
62
    {
63
      printf("FAIL: Unexpected value. var.d is %d, should be %d\n",
64
             var.d, global);
65
      ret = 1;
66
    }
67
  return ret;
68
}
69
 
70
/* Verify that every variable has the correct value.  */
71
int simulate_thread_final_verify()
72
{
73
  int ret = simulate_thread_step_verify();
74
  if (var.a != 1)
75
    {
76
      printf("FAIL: Unexpected value. var.a is %d, should be %d\n", var.a, 1);
77
      ret = 1;
78
    }
79
  return ret;
80
}
81
 
82
__attribute__((noinline))
83
void simulate_thread_main()
84
{
85
  set_a(1);
86
}
87
 
88
int main ()
89
{
90
  simulate_thread_main();
91
  simulate_thread_done();
92
  return 0;
93
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.