示例#1
0
/* but the ANSI standard declaration uses int. */
void *
gs_memset(void *dest, register int ch, size_t len)
{
    /*
     * This procedure is used a lot to fill large regions of images,
     * so we take some trouble to optimize it.
     */
    register char *p = dest;
    register size_t count = len;

    ch &= 255;
    if (len >= sizeof(long) * 3) {
        long wd = (ch << 24) | (ch << 16) | (ch << 8) | ch;

        while (ALIGNMENT_MOD(p, sizeof(long)))
            *p++ = (char)ch, --count;
        for (; count >= sizeof(long) * 4;
             p += sizeof(long) * 4, count -= sizeof(long) * 4
             )
            ((long *)p)[3] = ((long *)p)[2] = ((long *)p)[1] =
                ((long *)p)[0] = wd;
        switch (count >> ARCH_LOG2_SIZEOF_LONG) {
        case 3:
            *((long *)p) = wd; p += sizeof(long);
        case 2:
            *((long *)p) = wd; p += sizeof(long);
        case 1:
            *((long *)p) = wd; p += sizeof(long);
            count &= sizeof(long) - 1;
        case 0:
        default:                /* can't happen */
            DO_NOTHING;
        }
    }
示例#2
0
/* Align a byte pointer on the next Nth byte */
static void
ptr_align_to(
            const byte ** src,	/* pointer to align */
            unsigned alignment	/* alignment, must be power of 2 */
)
{
    *src += -(int)ALIGNMENT_MOD(*src, alignment) & (alignment - 1);
}