… | |
… | |
449 | attachable::check_mortals (); |
449 | attachable::check_mortals (); |
450 | |
450 | |
451 | ++pticks; |
451 | ++pticks; |
452 | } |
452 | } |
453 | |
453 | |
454 | #if 0 |
|
|
455 | // used fro benchmarking (x86/amd64-specific) |
|
|
456 | typedef unsigned long tval; |
|
|
457 | typedef unsigned long long stamp64; |
|
|
458 | |
|
|
459 | extern inline tval |
|
|
460 | stamp (void) |
|
|
461 | { |
|
|
462 | tval tsc; |
|
|
463 | asm volatile ("rdtsc":"=a" (tsc)::"edx"); |
|
|
464 | |
|
|
465 | return tsc; |
|
|
466 | } |
|
|
467 | |
|
|
468 | extern inline tval |
|
|
469 | measure (tval t) |
|
|
470 | { |
|
|
471 | tval tsc; |
|
|
472 | asm volatile ("rdtsc":"=a" (tsc)::"edx"); |
|
|
473 | |
|
|
474 | if (tsc > t) |
|
|
475 | return tsc - t; |
|
|
476 | else |
|
|
477 | return t - tsc; |
|
|
478 | } |
|
|
479 | |
|
|
480 | int |
|
|
481 | main (int argc, char **argv) |
|
|
482 | { |
|
|
483 | rand_gen rg(0); |
|
|
484 | tval fastest = 0x7fffffff; |
|
|
485 | for (int loop = 10000; loop--; ) |
|
|
486 | { |
|
|
487 | tval s = stamp (); |
|
|
488 | volatile int i = rg.get_int(25); |
|
|
489 | fastest = min (fastest, measure (s)); |
|
|
490 | } |
|
|
491 | |
|
|
492 | //printf ("fastest %d\n", fastest); |
|
|
493 | for (int i = 0; i < 1024*1024*3; ++i) |
|
|
494 | { |
|
|
495 | char c = rg.get_int (256); |
|
|
496 | write (2, &c, 1); |
|
|
497 | } |
|
|
498 | } |
|
|
499 | |
|
|
500 | #else |
|
|
501 | |
|
|
502 | #if 0 // just goofing around, look elsewhere |
|
|
503 | |
|
|
504 | #include <malloc.h> |
|
|
505 | #include <execinfo.h> |
|
|
506 | |
|
|
507 | static void tr_on (); |
|
|
508 | static void tr_off (); |
|
|
509 | |
|
|
510 | static SMUTEX(tr_mutex); |
|
|
511 | |
|
|
512 | #define ltr_off() SMUTEX_LOCK (tr_mutex); tr_off () |
|
|
513 | #define ltr_on() tr_on (); SMUTEX_UNLOCK (tr_mutex); |
|
|
514 | |
|
|
515 | static void * |
|
|
516 | tr_malloc (size_t size, const void *caller) |
|
|
517 | { |
|
|
518 | ltr_off (); |
|
|
519 | |
|
|
520 | void *bt [8]; |
|
|
521 | backtrace (bt, 8); |
|
|
522 | |
|
|
523 | void *ptr = malloc (size); |
|
|
524 | |
|
|
525 | ltr_on (); |
|
|
526 | return (char *)ptr; |
|
|
527 | } |
|
|
528 | |
|
|
529 | static void |
|
|
530 | tr_free (void *ptr, const void *caller) |
|
|
531 | { |
|
|
532 | ltr_off (); |
|
|
533 | |
|
|
534 | free (ptr); |
|
|
535 | |
|
|
536 | ltr_on (); |
|
|
537 | } |
|
|
538 | |
|
|
539 | void static * |
|
|
540 | tr_realloc (void *ptr, size_t size, const void *caller) |
|
|
541 | { |
|
|
542 | ltr_off (); |
|
|
543 | |
|
|
544 | void *nptr = realloc (ptr, size); |
|
|
545 | |
|
|
546 | ltr_on (); |
|
|
547 | return nptr; |
|
|
548 | } |
|
|
549 | |
|
|
550 | static void * |
|
|
551 | tr_memalign (size_t size, size_t alignment, const void *caller) |
|
|
552 | { |
|
|
553 | ltr_off (); |
|
|
554 | |
|
|
555 | void *ptr = memalign (size, alignment < 16 ? 16 : alignment); |
|
|
556 | |
|
|
557 | ltr_on (); |
|
|
558 | return ptr; |
|
|
559 | } |
|
|
560 | |
|
|
561 | static void |
|
|
562 | tr_on () |
|
|
563 | { |
|
|
564 | __malloc_hook = tr_malloc; |
|
|
565 | __realloc_hook = tr_realloc; |
|
|
566 | __free_hook = tr_free; |
|
|
567 | __memalign_hook = tr_memalign; |
|
|
568 | } |
|
|
569 | |
|
|
570 | static void |
|
|
571 | tr_off () |
|
|
572 | { |
|
|
573 | __malloc_hook = 0; |
|
|
574 | __realloc_hook = 0; |
|
|
575 | __free_hook = 0; |
|
|
576 | __memalign_hook = 0; |
|
|
577 | } |
|
|
578 | |
|
|
579 | void (*__malloc_initialize_hook)(void) = tr_on; |
|
|
580 | |
|
|
581 | #endif |
|
|
582 | |
|
|
583 | // normal main |
454 | // normal main |
584 | int |
455 | int |
585 | main (int argc, char **argv) |
456 | main (int argc, char **argv) |
586 | { |
457 | { |
587 | settings.argc = argc; |
458 | settings.argc = argc; |
… | |
… | |
593 | init (argc, argv); |
464 | init (argc, argv); |
594 | |
465 | |
595 | for (;;) |
466 | for (;;) |
596 | cfperl_main (); |
467 | cfperl_main (); |
597 | } |
468 | } |
598 | #endif |
|
|
599 | |
469 | |
600 | #if 0 |
|
|
601 | int xyzzy () |
|
|
602 | { |
|
|
603 | return rndm(8); |
|
|
604 | } |
|
|
605 | |
|
|
606 | void xyzzy (object_ptr &a, object_ptr &o) |
|
|
607 | { |
|
|
608 | asm volatile ("int3"); |
|
|
609 | a = o; |
|
|
610 | asm volatile ("int3"); |
|
|
611 | } |
|
|
612 | #endif |
|
|
613 | |
|
|