5 /* An ultra-lame test program for RTM support, as available
8 /* Attempt to run f(arg) as a transaction, and return a Boolean
9 indicating success or otherwise. */
11 __attribute__((noinline
))
12 static int transactionally_apply ( void(*f
)(void*), void* arg
)
16 " xbegin .Lzzqqfail" );
19 /* This is a bit tricky. If the transaction succeeds, control
20 will flow to this point. If it fails, control continues at
21 .Lzzqqfail, with the machine state looking the same as it did
22 immediately before the xbegin was executed. */
23 " xend \n\t" /* declare the transaction to be complete */
24 " movl $1,%0 \n\t" /* "ok = 1" */
25 " jmp .Lzzqqout \n\t" /* jump to the merge point */
26 ".Lzzqqfail: \n\t" /* it failed .. */
27 " movl $0,%0 \n\t" /* "ok = 0" */
28 ".Lzzqqout: \n\t" /* this is the merge point */
29 : "=r"(ok
) : : "cc", "rax"
34 void testfn ( void* arg
)
40 long long int ok
= transactionally_apply ( testfn
, NULL
);
41 printf("transactionally_apply: ok = %lld (expected %d)\n", ok
, 0);
48 : "=r"(ok
) : : "cc","rax"
50 printf("xtest: rflags.Z = %lld (expected %d)\n", ok
, 1);
53 printf("testing XACQUIRE / XRELEASE\n");
56 "xacquire lock incl (%0) \n\t"
57 "xrelease lock decl (%0) \n\t"
58 : : "r"(&n) : "cc", "memory"
62 __asm__
__volatile__( "xabort $0x1" );
63 printf("xabort: outside transaction is nop.\n");