- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/PingPong.c
ra573c22 rd7a02ae 2 2 3 3 typedef struct PingPong { 4 int restart; // style 14 const char * name; 5 5 int N, i; 6 const char * name;7 6 struct PingPong * partner; 8 void * next; // style 27 void * next; 9 8 } PingPong; 10 #define PPCtor( name, N ) { 0, N, 0, name, NULL, NULL } 11 9 #define PPCtor( name, N ) { name, N, 0, NULL, NULL } 12 10 void comain( PingPong * pp ) __attribute__(( noinline )); 13 11 void comain( PingPong * pp ) { 12 if ( __builtin_expect(pp->next != 0, 1) ) goto *pp->next; 14 13 #if 0 15 if ( __builtin_expect(pp->next != 0, 1) ) goto *pp->next; 14 pp->next = &&here; 15 asm( "mov %0,%%rdi" : "=m" (pp) ); 16 asm( "mov %rdi,%rax" ); 17 #ifndef OPT 18 #ifdef PRINT 19 asm( "add $16, %rsp" ); 20 #endif // PRINT 21 asm( "popq %rbp" ); 22 #endif // ! OPT 23 24 #ifdef OPT 25 #ifdef PRINT 26 asm( "popq %rbx" ); 27 #endif // PRINT 28 #endif // OPT 29 asm( "jmp comain" ); 30 here: ; 31 #endif // 0 32 16 33 pp->next = &&cycle; 17 34 for ( ; pp->i < pp->N; pp->i += 1 ) { … … 36 53 cycle: ; 37 54 } // for 38 #endif // 039 40 #if 141 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 PRINT46 printf( "%s %d\n", pp->name, pp->i );47 #endif // PRINT48 asm( "mov %0,%%rdi" : "=m" (pp->partner) );49 asm( "mov %rdi,%rax" );50 #ifndef OPT51 #ifdef PRINT52 asm( "add $16, %rsp" );53 #endif // PRINT54 asm( "popq %rbp" );55 #endif // ! OPT56 57 #ifdef OPT58 #ifdef PRINT59 asm( "popq %rbx" );60 #endif // PRINT61 #endif // OPT62 asm( "jmp comain" );63 s1: ;64 } // for65 #endif // 066 55 } 67 56 … … 81 70 // Local Variables: // 82 71 // tab-width: 4 // 83 // compile-command: "gcc- 9-g -DPRINT PingPong.c" //72 // compile-command: "gcc-8 -g -DPRINT PingPong.c" // 84 73 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.