2 * Test CDSG instruction.
4 * Increment the first half of aligned_quadword by 1, and the second half by 2
5 * from 2 threads. Verify that the result is consistent.
7 * SPDX-License-Identifier: GPL-2.0-or-later
14 static volatile bool start
;
15 typedef unsigned long aligned_quadword
[2] __attribute__((__aligned__(16)));
16 static aligned_quadword val
;
17 static const int n_iterations
= 1000000;
19 static inline int cdsg(unsigned long *orig0
, unsigned long *orig1
,
20 unsigned long new0
, unsigned long new1
,
21 aligned_quadword
*mem
)
23 register unsigned long r0
asm("r0");
24 register unsigned long r1
asm("r1");
25 register unsigned long r2
asm("r2");
26 register unsigned long r3
asm("r3");
33 asm("cdsg %[r0],%[r2],%[db2]\n"
45 return (cc
>> 28) & 3;
48 void *cdsg_loop(void *arg
)
50 unsigned long orig0
, orig1
, new0
, new1
;
59 for (i
= 0; i
< n_iterations
;) {
63 cc
= cdsg(&orig0
, &orig1
, new0
, new1
, &val
);
82 ret
= pthread_create(&thread
, NULL
, cdsg_loop
, NULL
);
86 ret
= pthread_join(thread
, NULL
);
89 assert(val
[0] == n_iterations
* 2);
90 assert(val
[1] == n_iterations
* 4);