| 1 |
/* PR target/11044 */ |
| 2 |
/* Originator: Tim McGrath <[email protected]> */ |
| 3 |
/* Testcase contributed by Eric Botcazou <[email protected]> */ |
| 4 |
/* { dg-do run } */ |
| 5 |
/* { dg-require-effective-target ia32 } */ |
| 6 |
/* { dg-options "-mtune=k6 -O3 -ffast-math -funroll-loops" } */ |
| 7 |
|
| 8 |
extern void *memset (void *, int, __SIZE_TYPE__); |
| 9 |
extern void abort (void); |
| 10 |
|
| 11 |
typedef struct |
| 12 |
{ |
| 13 |
unsigned char colormod; |
| 14 |
} entity_state_t; |
| 15 |
|
| 16 |
typedef struct |
| 17 |
{ |
| 18 |
int num_entities; |
| 19 |
entity_state_t *entities; |
| 20 |
} packet_entities_t; |
| 21 |
|
| 22 |
typedef struct |
| 23 |
{ |
| 24 |
double senttime; |
| 25 |
float ping_time; |
| 26 |
packet_entities_t entities; |
| 27 |
} client_frame_t; |
| 28 |
|
| 29 |
typedef enum |
| 30 |
{ |
| 31 |
cs_free, |
| 32 |
cs_server, |
| 33 |
cs_zombie, |
| 34 |
cs_connected, |
| 35 |
cs_spawned |
| 36 |
} sv_client_state_t; |
| 37 |
|
| 38 |
typedef struct client_s |
| 39 |
{ |
| 40 |
sv_client_state_t state; |
| 41 |
int ping; |
| 42 |
client_frame_t frames[64]; |
| 43 |
} client_t; |
| 44 |
|
| 45 |
int CalcPing (client_t *cl) |
| 46 |
{ |
| 47 |
float ping; |
| 48 |
int count, i; |
| 49 |
register client_frame_t *frame; |
| 50 |
|
| 51 |
if (cl->state == cs_server) |
| 52 |
return cl->ping; |
| 53 |
ping = 0; |
| 54 |
count = 0; |
| 55 |
for (frame = cl->frames, i = 0; i < 64; i++, frame++) { |
| 56 |
if (frame->ping_time > 0) { |
| 57 |
ping += frame->ping_time; |
| 58 |
count++; |
| 59 |
} |
| 60 |
} |
| 61 |
if (!count) |
| 62 |
return 9999; |
| 63 |
ping /= count; |
| 64 |
|
| 65 |
return ping * 1000; |
| 66 |
} |
| 67 |
|
| 68 |
int main(void) |
| 69 |
{ |
| 70 |
client_t cl; |
| 71 |
|
| 72 |
memset(&cl, 0, sizeof(cl)); |
| 73 |
|
| 74 |
cl.frames[0].ping_time = 1.0f; |
| 75 |
|
| 76 |
if (CalcPing(&cl) != 1000) |
| 77 |
abort(); |
| 78 |
|
| 79 |
return 0; |
| 80 |
} |