|
12 | 12 | * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
13 | 13 | * Portions Copyright (c) 1994, Regents of the University of California
|
14 | 14 | *
|
15 |
| - * $Id: c.h,v 1.133 2002/12/05 04:04:48 momjian Exp $ |
| 15 | + * $Id: c.h,v 1.134 2002/12/16 16:22:46 tgl Exp $ |
16 | 16 | *
|
17 | 17 | *-------------------------------------------------------------------------
|
18 | 18 | */
|
@@ -579,38 +579,78 @@ typedef NameData *Name;
|
579 | 579 | * memset() functions. More research needs to be done, perhaps with
|
580 | 580 | * platform-specific MEMSET_LOOP_LIMIT values or tests in configure.
|
581 | 581 | *
|
582 |
| - * MemSet has been split into two parts so MemSetTest can be optimized |
583 |
| - * away for constant 'val' and 'len'. This is used by palloc0(). |
584 |
| - * |
585 |
| - * Note, arguments are evaluated more than once. |
586 |
| - * |
587 | 582 | * bjm 2002-10-08
|
588 | 583 | */
|
| 584 | +#define MemSet(start, val, len) \ |
| 585 | + do \ |
| 586 | + { \ |
| 587 | + int32 * _start = (int32 *) (start); \ |
| 588 | + int _val = (val); \ |
| 589 | + Size _len = (len); \ |
| 590 | +\ |
| 591 | + if ((((long) _start) & INT_ALIGN_MASK) == 0 && \ |
| 592 | + (_len & INT_ALIGN_MASK) == 0 && \ |
| 593 | + _val == 0 && \ |
| 594 | + _len <= MEMSET_LOOP_LIMIT) \ |
| 595 | + { \ |
| 596 | + int32 * _stop = (int32 *) ((char *) _start + _len); \ |
| 597 | + while (_start < _stop) \ |
| 598 | + *_start++ = 0; \ |
| 599 | + } \ |
| 600 | + else \ |
| 601 | + memset((char *) _start, _val, _len); \ |
| 602 | + } while (0) |
| 603 | + |
| 604 | +#define MEMSET_LOOP_LIMIT 1024 |
| 605 | + |
| 606 | +/* |
| 607 | + * MemSetAligned is the same as MemSet except it omits the test to see if |
| 608 | + * "start" is word-aligned. This is okay to use if the caller knows a-priori |
| 609 | + * that the pointer is suitably aligned (typically, because he just got it |
| 610 | + * from palloc(), which always delivers a max-aligned pointer). |
| 611 | + */ |
| 612 | +#define MemSetAligned(start, val, len) \ |
| 613 | + do \ |
| 614 | + { \ |
| 615 | + int32 * _start = (int32 *) (start); \ |
| 616 | + int _val = (val); \ |
| 617 | + Size _len = (len); \ |
| 618 | +\ |
| 619 | + if ((_len & INT_ALIGN_MASK) == 0 && \ |
| 620 | + _val == 0 && \ |
| 621 | + _len <= MEMSET_LOOP_LIMIT) \ |
| 622 | + { \ |
| 623 | + int32 * _stop = (int32 *) ((char *) _start + _len); \ |
| 624 | + while (_start < _stop) \ |
| 625 | + *_start++ = 0; \ |
| 626 | + } \ |
| 627 | + else \ |
| 628 | + memset((char *) _start, _val, _len); \ |
| 629 | + } while (0) |
| 630 | + |
| 631 | + |
| 632 | +/* |
| 633 | + * MemSetTest/MemSetLoop are a variant version that allow all the tests in |
| 634 | + * MemSet to be done at compile time in cases where "val" and "len" are |
| 635 | + * constants *and* we know the "start" pointer must be word-aligned. |
| 636 | + * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use |
| 637 | + * MemSetAligned. Beware of multiple evaluations of the arguments when using |
| 638 | + * this approach. |
| 639 | + */ |
589 | 640 | #define MemSetTest(val, len) \
|
590 | 641 | ( ((len) & INT_ALIGN_MASK) == 0 && \
|
591 | 642 | (len) <= MEMSET_LOOP_LIMIT && \
|
592 | 643 | (val) == 0 )
|
593 | 644 |
|
594 | 645 | #define MemSetLoop(start, val, len) \
|
595 |
| -do \ |
596 |
| -{ \ |
597 |
| - int32 * _start = (int32 *) (start); \ |
598 |
| - int32 * _stop = (int32 *) ((char *) _start + (len)); \ |
599 |
| -\ |
600 |
| - while (_start < _stop) \ |
601 |
| - *_start++ = 0; \ |
602 |
| -} while (0) |
603 |
| - |
604 |
| -#define MemSet(start, val, len) \ |
605 |
| -do \ |
606 |
| -{ \ |
607 |
| - if (MemSetTest(val, len) && ((long)(start) & INT_ALIGN_MASK) == 0 ) \ |
608 |
| - MemSetLoop(start, val, len); \ |
609 |
| - else \ |
610 |
| - memset((char *)(start), (val), (len)); \ |
611 |
| -} while (0) |
612 |
| - |
613 |
| -#define MEMSET_LOOP_LIMIT 1024 |
| 646 | + do \ |
| 647 | + { \ |
| 648 | + int32 * _start = (int32 *) (start); \ |
| 649 | + int32 * _stop = (int32 *) ((char *) _start + (Size) (len)); \ |
| 650 | + \ |
| 651 | + while (_start < _stop) \ |
| 652 | + *_start++ = 0; \ |
| 653 | + } while (0) |
614 | 654 |
|
615 | 655 |
|
616 | 656 | /* ----------------------------------------------------------------
|
|
0 commit comments