Changeset 04e6f93 for doc/papers/concurrency/examples/PingPong.c
- Timestamp:
- Feb 27, 2020, 4:04:25 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- a037f85
- Parents:
- 41efd33 (diff), 930b504 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/PingPong.c
r41efd33 r04e6f93 2 2 3 3 typedef struct PingPong { 4 int restart; // style 1 5 int N, i; 4 6 const char * name; 5 int N, i;6 7 struct PingPong * partner; 7 void * next; 8 void * next; // style 2 8 9 } PingPong; 9 #define PPCtor( name, N ) { name, N, 0, NULL, NULL } 10 #define PPCtor( name, N ) { 0, N, 0, name, NULL, NULL } 11 10 12 void comain( PingPong * pp ) __attribute__(( noinline )); 11 13 void comain( PingPong * pp ) { 14 #if 0 12 15 if ( __builtin_expect(pp->next != 0, 1) ) goto *pp->next; 13 #if 014 pp->next = &&here;15 asm( "mov %0,%%rdi" : "=m" (pp) );16 asm( "mov %rdi,%rax" );17 #ifndef OPT18 #ifdef PRINT19 asm( "add $16, %rsp" );20 #endif // PRINT21 asm( "popq %rbp" );22 #endif // ! OPT23 24 #ifdef OPT25 #ifdef PRINT26 asm( "popq %rbx" );27 #endif // PRINT28 #endif // OPT29 asm( "jmp comain" );30 here: ;31 #endif // 032 33 16 pp->next = &&cycle; 34 17 for ( ; pp->i < pp->N; pp->i += 1 ) { … … 53 36 cycle: ; 54 37 } // for 38 #endif // 0 39 40 #if 1 41 static void * states[] = {&&s0, &&s1}; 42 goto *states[pp->restart]; 43 s0: pp->restart = 1; 44 for ( ; pp->i < pp->N; pp->i += 1 ) { 45 #ifdef PRINT 46 printf( "%s %d\n", pp->name, pp->i ); 47 #endif // PRINT 48 asm( "mov %0,%%rdi" : "=m" (pp->partner) ); 49 asm( "mov %rdi,%rax" ); 50 #ifndef OPT 51 #ifdef PRINT 52 asm( "add $16, %rsp" ); 53 #endif // PRINT 54 asm( "popq %rbp" ); 55 #endif // ! OPT 56 57 #ifdef OPT 58 #ifdef PRINT 59 asm( "popq %rbx" ); 60 #endif // PRINT 61 #endif // OPT 62 asm( "jmp comain" ); 63 s1: ; 64 } // for 65 #endif // 0 55 66 } 56 67 … … 70 81 // Local Variables: // 71 82 // tab-width: 4 // 72 // compile-command: "gcc- 8-g -DPRINT PingPong.c" //83 // compile-command: "gcc-9 -g -DPRINT PingPong.c" // 73 84 // End: //
Note: See TracChangeset
for help on using the changeset viewer.