Hi,

On 2019/08/04 1:00, Michael wrote:
On Sat, 3 Aug 2019 14:46:32 +0900
Rin Okuyama <[email protected]> wrote:

Maybe it's time to remove all non-32bit access to fb.
I expect it is not a very hard work for now ;-).

I seriously doubt that's the problem, because:
- 32bit powerpc doesn't really do 64bit accesses ( unlike sparc for
   example ) and altivec is disabled for kernel code ( since gcc started
   using altivec for optimized, inlined memcpy )
- at least one of the putchar_aa() methods used memcpy() in order to
   speed things up by rendering scanlines into cached memory and then
   quickly copying them into slow & uncached video memory, which worked
   just fine everywhere I tried ( that is, mips, powerpc, sparc, sparc64
   and arm )

Thank you for your suggestive comments!

I probably found the cause of failure; new rasops allocates buffer and
stamp dynamically via kmem_alloc. This may not work in early stages
during boot.

I removed dynamical allocations. Could you please test the attached patch?

PS
I ordered Mac Mini G4, although serial console is hopeless...

They're nice little machines which usually don't cause much trouble.
Opening them is quite painful though.

Yeah, I look to forward to playing with it :-).

Thanks,
rin
Index: sys/dev/rasops/rasops.c
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops.c,v
retrieving revision 1.108
diff -p -u -r1.108 rasops.c
--- sys/dev/rasops/rasops.c     2 Aug 2019 23:24:37 -0000       1.108
+++ sys/dev/rasops/rasops.c     4 Aug 2019 02:19:31 -0000
@@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1
 
 #define        _RASOPS_PRIVATE
 #include <dev/rasops/rasops.h>
+#include <dev/rasops/rasops_masks.h>   /* XXX for MBE */
 
 #ifndef _KERNEL
 #include <errno.h>
@@ -69,6 +70,16 @@ struct rasops_matchdata {
        int ident;
 };     
 
+static const uint32_t rasops_lmask32[4 + 1] = {
+       MBE(0x00000000), MBE(0x00ffffff), MBE(0x0000ffff), MBE(0x000000ff),
+       MBE(0x00000000),
+};
+
+static const uint32_t rasops_rmask32[4 + 1] = {
+       MBE(0x00000000), MBE(0xff000000), MBE(0xffff0000), MBE(0xffffff00),
+       MBE(0xffffffff),
+};
+
 /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
 const uint8_t rasops_cmap[256 * 3] = {
        0x00, 0x00, 0x00, /* black */
@@ -429,7 +440,7 @@ rasops_reconfig(struct rasops_info *ri, 
 
        /* Clear the entire display */
        if ((ri->ri_flg & RI_CLEAR) != 0)
-               memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
+               rasops_memset32(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
 
        /* Now centre our window if needs be */
        if ((ri->ri_flg & RI_CENTER) != 0) {
@@ -495,21 +506,6 @@ rasops_reconfig(struct rasops_info *ri, 
                    WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
        }
 
-       if (ri->ri_buf != NULL) {
-               kmem_free(ri->ri_buf, ri->ri_buflen);
-               ri->ri_buf = NULL;
-       }
-       len = (ri->ri_flg & RI_FULLCLEAR) ? ri->ri_stride : ri->ri_emustride;
-       ri->ri_buflen = len;
-       ri->ri_buf = kmem_alloc(len, KM_SLEEP);
-
-#ifndef RASOPS_SMALL
-       if (ri->ri_stamp != NULL) {
-               kmem_free(ri->ri_stamp, ri->ri_stamp_len);
-               ri->ri_stamp = NULL;
-       }
-#endif
-
        switch (ri->ri_depth) {
 #if NRASOPS1 > 0
        case 1:
@@ -980,9 +976,8 @@ void
 rasops_eraserows(void *cookie, int row, int num, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
-       uint32_t *buf = (uint32_t *)ri->ri_buf;
        uint32_t *rp, *hp, clr;
-       int stride, cnt;
+       int stride;
 
        hp = NULL;      /* XXX GCC */
 
@@ -1021,13 +1016,10 @@ rasops_eraserows(void *cookie, int row, 
                        hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale);
        }
 
-       for (cnt = 0; cnt < stride >> 2; cnt++)
-               buf[cnt] = clr;
-
        while (num--) {
-               memcpy(rp, buf, stride);
+               rasops_memset32(rp, clr, stride);
                if (ri->ri_hwbits) {
-                       memcpy(hp, buf, stride);
+                       memcpy(hp, rp, stride);
                        DELTA(hp, ri->ri_stride, uint32_t *);
                }
                DELTA(rp, ri->ri_stride, uint32_t *);
@@ -1042,9 +1034,8 @@ static void
 rasops_do_cursor(struct rasops_info *ri)
 {
        int full, height, cnt, slop1, slop2, row, col;
-       uint32_t tmp32, msk1, msk2;
-       uint8_t tmp8;
-       uint8_t *dp, *rp, *hp;
+       uint32_t mask1, mask2, *dp;
+       uint8_t tmp8, *rp, *hp;
 
        hp = NULL;      /* XXX GCC */
 
@@ -1108,28 +1099,24 @@ rasops_do_cursor(struct rasops_info *ri)
        rp = (uint8_t *)((uintptr_t)rp & ~3);
        hp = (uint8_t *)((uintptr_t)hp & ~3);
 
-       msk1 = !slop1 ? 0 : be32toh(0xffffffffU >> (32 - (8 * slop1)));
-       msk2 = !slop2 ? 0 : be32toh(0xffffffffU << (32 - (8 * slop2)));
+       mask1 = rasops_lmask32[4 - slop1];
+       mask2 = rasops_rmask32[slop2];
 
        while (height--) {
-               dp = rp;
+               dp = (uint32_t *)rp;
 
                if (slop1) {
-                       tmp32 = *(uint32_t *)dp ^ msk1;
-                       *(uint32_t *)dp = tmp32;
-                       dp += 4;
+                       *dp = *dp ^ mask1;
+                       dp++;
                }
 
                for (cnt = full; cnt; cnt--) {
-                       tmp32 = ~*(uint32_t *)dp;
-                       *(uint32_t *)dp = tmp32;
-                       dp += 4;
+                       *dp = ~*(uint32_t *)dp;
+                       dp++;
                }
 
-               if (slop2) {
-                       tmp32 = *(uint32_t *)dp ^ msk2;
-                       *(uint32_t *)dp = tmp32;
-               }
+               if (slop2)
+                       *dp = *dp ^ mask2;
 
                if (ri->ri_hwbits) {
                        memcpy(hp, rp, ((slop1 != 0) + full +
@@ -1147,9 +1134,8 @@ void
 rasops_erasecols(void *cookie, int row, int col, int num, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
-       uint32_t *buf = ri->ri_buf;
-       int height, cnt, clr;
-       uint32_t *dp, *rp, *hp;
+       int height, clr;
+       uint32_t *rp, *hp;
 
        hp = NULL;      /* XXX GCC */
 
@@ -1177,25 +1163,13 @@ rasops_erasecols(void *cookie, int row, 
        height = ri->ri_font->fontheight;
        clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
 
-       dp = buf;
-
-       /* Write 4 bytes per loop */
-       for (cnt = num >> 2; cnt; cnt--)
-               *dp++ = clr;
-
-       /* Write unaligned trailing slop */
-       for (cnt = num & 3; cnt; cnt--) {
-               *(uint8_t *)dp = clr;
-               DELTA(dp, 1, uint32_t *);
-       }
-
        while (height--) {
-               memcpy(rp, buf, num);
-               DELTA(rp, ri->ri_stride, uint32_t *);
+               rasops_memset32(rp, clr, num);
                if (ri->ri_hwbits) {
-                       memcpy(hp, buf, num);
+                       memcpy(hp, rp, num);
                        DELTA(hp, ri->ri_stride, uint32_t *);
                }
+               DELTA(rp, ri->ri_stride, uint32_t *);
        }
 }
 
@@ -1670,15 +1644,3 @@ rasops_get_cmap(struct rasops_info *ri, 
                memcpy(palette, rasops_cmap, uimin(bytes, sizeof(rasops_cmap)));
        return 0;
 }
-
-#ifndef RASOPS_SMALL
-void
-rasops_allocstamp(struct rasops_info *ri, size_t len)
-{
-
-       KASSERT(ri->ri_stamp == NULL);
-       ri->ri_stamp_len = len;
-       ri->ri_stamp = kmem_zalloc(len, KM_SLEEP);
-       ri->ri_stamp_attr = 0;
-}
-#endif
Index: sys/dev/rasops/rasops.h
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops.h,v
retrieving revision 1.43
diff -p -u -r1.43 rasops.h
--- sys/dev/rasops/rasops.h     3 Aug 2019 06:29:52 -0000       1.43
+++ sys/dev/rasops/rasops.h     4 Aug 2019 02:19:31 -0000
@@ -131,15 +131,6 @@ struct rasops_info {
        /* Callbacks so we can share some code */
        void    (*ri_do_cursor)(struct rasops_info *);
 
-       /* buffer capable of single-row pixels */
-       void    *ri_buf;
-       size_t  ri_buflen;
-
-       /* 4x1 stamp for optimized character blitting */
-       void    *ri_stamp;
-       long    ri_stamp_attr;
-       size_t  ri_stamp_len;
-
 #if NRASOPS_ROTATION > 0
        /* Used to intercept putchar to permit display rotation */
        struct  wsdisplay_emulops ri_real_ops;
@@ -199,6 +190,45 @@ void       rasops_allocstamp(struct rasops_inf
        ((uint8_t *)(font)->data + ((uc) - ((font)->firstchar)) *       \
            (ri)->ri_fontscale)
 
+static __inline void
+rasops_memset32(void *p, uint32_t val, size_t bytes)
+{
+       int slop1, slop2, full;
+       uint8_t *dp = (uint8_t *)p;
+
+       if (bytes == 1) {
+               *dp = val;
+               return;
+       }
+
+       slop1 = (4 - ((uintptr_t)dp & 3)) & 3;
+       slop2 = (bytes - slop1) & 3;
+       full = (bytes - slop1 /* - slop2 */) >> 2;
+
+       if (slop1 & 1)
+               *dp++ = val;
+
+       if (slop1 & 2) {
+               *(uint16_t *)dp = val;
+               dp += 2;
+       }
+
+       for (; full; full--) {
+               *(uint32_t *)dp = val;
+               dp += 4;
+       }
+
+       if (slop2 & 2) {
+               *(uint16_t *)dp = val;
+               dp += 2;
+       }
+
+       if (slop1 & 1)
+               *dp = val;
+
+       return;
+}
+
 static __inline uint32_t
 be32uatoh(uint8_t *p)
 {
Index: sys/dev/rasops/rasops15.c
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops15.c,v
retrieving revision 1.34
diff -p -u -r1.34 rasops15.c
--- sys/dev/rasops/rasops15.c   2 Aug 2019 04:40:53 -0000       1.34
+++ sys/dev/rasops/rasops15.c   4 Aug 2019 02:19:31 -0000
@@ -55,6 +55,11 @@ static void  rasops15_makestamp(struct ra
 #endif
 
 #ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint32_t                        stamp[32];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination uint32_t[0] = STAMP_READ(offset)
@@ -104,7 +109,8 @@ rasops15_init(struct rasops_info *ri)
        }
 
 #ifndef RASOPS_SMALL
-       rasops_allocstamp(ri, sizeof(uint32_t) * 32);
+       stamp_attr = 0;
+       stamp_ri = NULL;
 #endif
 }
 
@@ -118,13 +124,14 @@ rasops15_init(struct rasops_info *ri)
 static void
 rasops15_makestamp(struct rasops_info *ri, long attr)
 {
-       uint32_t *stamp = (uint32_t *)ri->ri_stamp;
        uint32_t fg, bg;
        int i;
 
+       stamp_attr = attr;
+       stamp_ri = ri;
+
        fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffff;
        bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffff;
-       ri->ri_stamp_attr = attr;
 
        for (i = 0; i < 32; i += 2) {
 #if BYTE_ORDER == LITTLE_ENDIAN
Index: sys/dev/rasops/rasops2.c
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops2.c,v
retrieving revision 1.29
diff -p -u -r1.29 rasops2.c
--- sys/dev/rasops/rasops2.c    2 Aug 2019 04:39:09 -0000       1.29
+++ sys/dev/rasops/rasops2.c    4 Aug 2019 02:19:31 -0000
@@ -58,6 +58,12 @@ static void  rasops2_putchar16(void *, in
 static void    rasops2_makestamp(struct rasops_info *, long);
 #endif
 
+#ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint8_t                 stamp[16];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination = STAMP_READ(offset)
@@ -65,6 +71,7 @@ static void   rasops2_makestamp(struct ras
 #define        STAMP_SHIFT(fb, n)      ((n) ? (fb) >> 4 : (fb))
 #define        STAMP_MASK              0xf
 #define        STAMP_READ(o)           stamp[o]
+#endif
 
 /*
  * Initialize rasops_info struct for this colordepth.
@@ -90,14 +97,15 @@ rasops2_init(struct rasops_info *ri)
        case 16:
                ri->ri_ops.putchar = rasops2_putchar16;
                break;
-#endif /* !RASOPS_SMALL */
+#endif
        default:
                ri->ri_ops.putchar = rasops2_putchar;
                return;
        }
 
 #ifndef RASOPS_SMALL
-       rasops_allocstamp(ri, sizeof(uint8_t) * 16);
+       stamp_attr = 0;
+       stamp_ri = NULL;
 #endif
 }
 
@@ -108,12 +116,13 @@ rasops2_init(struct rasops_info *ri)
 static void
 rasops2_makestamp(struct rasops_info *ri, long attr)
 {
-       uint8_t *stamp = (uint8_t *)ri->ri_stamp;
        int i, fg, bg;
 
+       stamp_attr = attr;
+       stamp_ri = ri;
+
        fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 3;
        bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 3;
-       ri->ri_stamp_attr = attr;
 
        for (i = 0; i < 16; i++) {
 #if BYTE_ORDER == BIG_ENDIAN
Index: sys/dev/rasops/rasops24.c
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops24.c,v
retrieving revision 1.46
diff -p -u -r1.46 rasops24.c
--- sys/dev/rasops/rasops24.c   2 Aug 2019 23:24:37 -0000       1.46
+++ sys/dev/rasops/rasops24.c   4 Aug 2019 02:19:32 -0000
@@ -62,6 +62,12 @@ static void  rasops24_putchar16(void *, 
 static void    rasops24_makestamp(struct rasops_info *, long);
 #endif
 
+#ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint32_t                        stamp[64];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination uint32_t[0] = STAMP_READ(offset)
@@ -71,6 +77,7 @@ static void   rasops24_makestamp(struct ra
 #define        STAMP_SHIFT(fb, n)      ((n) ? (fb) : (fb) << 4)
 #define        STAMP_MASK              (0xf << 4)
 #define        STAMP_READ(o)           (*(uint32_t *)((uint8_t *)stamp + (o)))
+#endif
 
 /*
  * Initialize rasops_info struct for this colordepth.
@@ -113,7 +120,8 @@ rasops24_init(struct rasops_info *ri)
        }
 
 #ifndef RASOPS_SMALL
-       rasops_allocstamp(ri, sizeof(uint32_t) * 64);
+       stamp_attr = 0;
+       stamp_ri = NULL;
 #endif
 }
 
@@ -121,13 +129,13 @@ rasops24_init(struct rasops_info *ri)
 #include "rasops_putchar_aa.h"
 
 static __inline void
-rasops24_makestamp1(struct rasops_info *ri, uint32_t *stamp,
+rasops24_makestamp1(struct rasops_info *ri, uint32_t *xstamp,
     uint32_t c1, uint32_t c2, uint32_t c3, uint32_t c4)
 {
 
-       stamp[0] = (c1 <<  8) | (c2 >> 16);
-       stamp[1] = (c2 << 16) | (c3 >>  8);
-       stamp[2] = (c3 << 24) |  c4;
+       xstamp[0] = (c1 <<  8) | (c2 >> 16);
+       xstamp[1] = (c2 << 16) | (c3 >>  8);
+       xstamp[2] = (c3 << 24) |  c4;
 
 #if BYTE_ORDER == LITTLE_ENDIAN
        if ((ri->ri_flg & RI_BSWAP) == 0)
@@ -135,9 +143,9 @@ rasops24_makestamp1(struct rasops_info *
        if ((ri->ri_flg & RI_BSWAP) != 0)
 #endif
        {
-               stamp[0] = bswap32(stamp[0]);
-               stamp[1] = bswap32(stamp[1]);
-               stamp[2] = bswap32(stamp[2]);
+               xstamp[0] = bswap32(xstamp[0]);
+               xstamp[1] = bswap32(xstamp[1]);
+               xstamp[2] = bswap32(xstamp[2]);
        }
 }
 
@@ -148,13 +156,14 @@ rasops24_makestamp1(struct rasops_info *
 static void
 rasops24_makestamp(struct rasops_info *ri, long attr)
 {
-       uint32_t *stamp = (uint32_t *)ri->ri_stamp;
        uint32_t fg, bg, c1, c2, c3, c4;
        int i;
 
+       stamp_attr = attr;
+       stamp_ri = ri;
+
        fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffffff;
        bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffffff;
-       ri->ri_stamp_attr = attr;
 
        for (i = 0; i < 64; i += 4) {
 #if BYTE_ORDER == LITTLE_ENDIAN
@@ -193,9 +202,8 @@ static void
 rasops24_eraserows(void *cookie, int row, int num, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
-       uint32_t *buf = (uint32_t *)ri->ri_buf;
        int full, slop, cnt, stride;
-       uint32_t *rp, *dp, *hp, clr, stamp[3];
+       uint32_t *rp, *dp, *hp, clr, xstamp[3];
 
        hp = NULL;      /* XXX GCC */
 
@@ -222,7 +230,7 @@ rasops24_eraserows(void *cookie, int row
 #endif
 
        clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffffff;
-       rasops24_makestamp1(ri, stamp, clr, clr, clr, clr);
+       rasops24_makestamp1(ri, xstamp, clr, clr, clr, clr);
 
        /*
         * XXX the wsdisplay_emulops interface seems a little deficient in
@@ -247,25 +255,23 @@ rasops24_eraserows(void *cookie, int row
        full = stride / (4 * 3);
        slop = (stride - full * (4 * 3)) / 4;
 
-       dp = buf;
-
-       for (cnt = full; cnt; cnt--) {
-               dp[0] = stamp[0];
-               dp[1] = stamp[1];
-               dp[2] = stamp[2];
-               dp += 3;
-       }
-
-       for (cnt = 0; cnt < slop; cnt++)
-               *dp++ = stamp[cnt];
-
        while (num--) {
-               memcpy(rp, buf, stride);
-               DELTA(rp, ri->ri_stride, uint32_t *);
+               dp = rp;
+               for (cnt = full; cnt; cnt--) {
+                       dp[0] = xstamp[0];
+                       dp[1] = xstamp[1];
+                       dp[2] = xstamp[2];
+                       dp += 3;
+               }
+               for (cnt = 0; cnt < slop; cnt++)
+                       *dp++ = xstamp[cnt];
+
                if (ri->ri_hwbits) {
-                       memcpy(hp, buf, stride);
+                       memcpy(hp, rp, stride);
                        DELTA(hp, ri->ri_stride, uint32_t *);
                }
+
+               DELTA(rp, ri->ri_stride, uint32_t *);
        }
 }
 
@@ -276,9 +282,8 @@ static void
 rasops24_erasecols(void *cookie, int row, int col, int num, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
-       void *buf = ri->ri_buf;
-       int height, cnt, clr, stamp[3];
-       uint32_t *dp;
+       int height, cnt, slop1, slop2, full;
+       uint32_t clr, xstamp[3], *dp;
        uint8_t *rp, *hp, *dbp;
 
        hp = NULL;      /* XXX GCC */
@@ -317,33 +322,46 @@ rasops24_erasecols(void *cookie, int row
        height = ri->ri_font->fontheight;
 
        clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffffff;
-       rasops24_makestamp1(ri, stamp, clr, clr, clr, clr);
-
-       /* 4 pels per loop */
-       dp = (uint32_t *)buf;
-       for (cnt = num >> 2; cnt; cnt--) {
-               dp[0] = stamp[0];
-               dp[1] = stamp[1];
-               dp[2] = stamp[2];
-               dp += 3;
-       }
-
-       /* Trailing slop */
-       dbp = (uint8_t *)dp;
-       for (cnt = num & 3; cnt; cnt--) {
-               *dbp++ = (clr >> 16);
-               *dbp++ = (clr >> 8);
-               *dbp++ =  clr;
-       }
+       rasops24_makestamp1(ri, xstamp, clr, clr, clr, clr);
 
+       slop1 = (uintptr_t)rp & 3;
+       cnt = slop1;
+       full = (num /* - cnt */) >> 2;
+       cnt += full << 2;
+       slop2 = num - cnt;
        num *= 3;
 
        while (height--) {
-               memcpy(rp, buf, num);
-               rp += ri->ri_stride;
+               /* Align to word boundary */
+               dbp = rp;
+               for (cnt = slop1; cnt; cnt--) {
+                       *dbp++ = (clr >> 16);
+                       *dbp++ = (clr >> 8);
+                       *dbp++ = clr;
+               }
+
+               /* 4 pels per loop */
+               dp = (uint32_t *)dbp;
+               for (cnt = full; cnt; cnt--) {
+                       dp[0] = xstamp[0];
+                       dp[1] = xstamp[1];
+                       dp[2] = xstamp[2];
+                       dp += 3;
+               }
+
+               /* Trailing slop */
+               dbp = (uint8_t *)dp;
+               for (cnt = slop2; cnt; cnt--) {
+                       *dbp++ = (clr >> 16);
+                       *dbp++ = (clr >> 8);
+                       *dbp++ = clr;
+               }
+
                if (ri->ri_hwbits) {
-                       memcpy(hp, buf, num);
+                       memcpy(hp, rp, num);
                        hp += ri->ri_stride;
                }
+
+               rp += ri->ri_stride;
        }
 }
Index: sys/dev/rasops/rasops32.c
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops32.c,v
retrieving revision 1.42
diff -p -u -r1.42 rasops32.c
--- sys/dev/rasops/rasops32.c   2 Aug 2019 04:40:53 -0000       1.42
+++ sys/dev/rasops/rasops32.c   4 Aug 2019 02:19:32 -0000
@@ -54,6 +54,12 @@ static void  rasops32_putchar16(void *, i
 static void    rasops32_makestamp(struct rasops_info *, long);
 #endif
 
+#ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint32_t                        stamp[64];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination uint32_t[0] = STAMP_READ(offset)
@@ -64,6 +70,7 @@ static void   rasops32_makestamp(struct ra
 #define        STAMP_SHIFT(fb, n)      ((n) ? (fb) : (fb) << 4)
 #define        STAMP_MASK              (0xf << 4)
 #define        STAMP_READ(o)           (*(uint32_t *)((uint8_t *)stamp + (o)))
+#endif
 
 /*
  * Initialize a 'rasops_info' descriptor for this depth.
@@ -103,7 +110,8 @@ rasops32_init(struct rasops_info *ri)
        }
 
 #ifndef RASOPS_SMALL
-       rasops_allocstamp(ri, sizeof(uint32_t) * 64);
+       stamp_attr = 0;
+       stamp_ri = NULL;
 #endif
 }
 
@@ -117,13 +125,14 @@ rasops32_init(struct rasops_info *ri)
 static void
 rasops32_makestamp(struct rasops_info *ri, long attr)
 {
-       uint32_t *stamp = (uint32_t *)ri->ri_stamp;
        uint32_t fg, bg;
        int i;
 
+       stamp_attr = attr;
+       stamp_ri = ri;
+
        fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
        bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
-       ri->ri_stamp_attr = attr;
 
        for (i = 0; i < 64; i += 4) {
                stamp[i + 0] = i & 32 ? fg : bg;
Index: sys/dev/rasops/rasops4.c
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops4.c,v
retrieving revision 1.24
diff -p -u -r1.24 rasops4.c
--- sys/dev/rasops/rasops4.c    2 Aug 2019 04:39:09 -0000       1.24
+++ sys/dev/rasops/rasops4.c    4 Aug 2019 02:19:32 -0000
@@ -58,6 +58,12 @@ static void  rasops4_putchar16(void *, in
 static void    rasops4_makestamp(struct rasops_info *, long);
 #endif
 
+#ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint16_t                        stamp[16];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination = STAMP_READ(offset)
@@ -65,6 +71,7 @@ static void   rasops4_makestamp(struct ras
 #define STAMP_SHIFT(fb, n)     ((n) ? (fb) >> 4 : (fb))
 #define STAMP_MASK             0xf
 #define STAMP_READ(o)          stamp[o]
+#endif
 
 /*
  * Initialize rasops_info struct for this colordepth.
@@ -97,7 +104,8 @@ rasops4_init(struct rasops_info *ri)
        }
 
 #ifndef RASOPS_SMALL
-       rasops_allocstamp(ri, sizeof(uint16_t) * 16);
+       stamp_attr = 0;
+       stamp_ri = NULL;
 #endif
 }
 
@@ -108,12 +116,13 @@ rasops4_init(struct rasops_info *ri)
 static void
 rasops4_makestamp(struct rasops_info *ri, long attr)
 {
-       uint16_t *stamp = (uint16_t *)ri->ri_stamp;
        int i, fg, bg;
 
+       stamp_attr = attr;
+       stamp_ri = ri;
+
        fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xf;
        bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xf;
-       ri->ri_stamp_attr = attr;
 
        for (i = 0; i < 16; i++) {
 #if BYTE_ORDER == BIG_ENDIAN
Index: sys/dev/rasops/rasops8.c
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops8.c,v
retrieving revision 1.47
diff -p -u -r1.47 rasops8.c
--- sys/dev/rasops/rasops8.c    2 Aug 2019 04:40:53 -0000       1.47
+++ sys/dev/rasops/rasops8.c    4 Aug 2019 02:19:32 -0000
@@ -54,6 +54,12 @@ static void  rasops8_putchar16(void *, i
 static void    rasops8_makestamp(struct rasops_info *ri, long);
 #endif
 
+#ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint32_t                        stamp[16];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination = STAMP_READ(offset)
@@ -61,6 +67,7 @@ static void   rasops8_makestamp(struct ras
 #define        STAMP_SHIFT(fb, n)      ((n) ? (fb) >> 2 : (fb) << 2)
 #define        STAMP_MASK              (0xf << 2)
 #define        STAMP_READ(o)           (*(uint32_t *)((uint8_t *)stamp + (o)))
+#endif
 
 /*
  * Initialize a 'rasops_info' descriptor for this depth.
@@ -101,7 +108,8 @@ rasops8_init(struct rasops_info *ri)
        }
 
 #ifndef RASOPS_SMALL
-       rasops_allocstamp(ri, sizeof(uint32_t) * 16);
+       stamp_attr = 0;
+       stamp_ri = NULL;
 #endif
 }
 
@@ -115,13 +123,14 @@ rasops8_init(struct rasops_info *ri)
 static void
 rasops8_makestamp(struct rasops_info *ri, long attr)
 {
-       uint32_t *stamp = (uint32_t *)ri->ri_stamp;
        uint32_t fg, bg;
        int i;
 
+       stamp_attr = attr;
+       stamp_ri = ri;
+
        fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xff;
        bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xff;
-       ri->ri_stamp_attr = attr;
 
        for (i = 0; i < 16; i++) {
 #if BYTE_ORDER == BIG_ENDIAN
Index: sys/dev/rasops/rasops_putchar_aa.h
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops_putchar_aa.h,v
retrieving revision 1.6
diff -p -u -r1.6 rasops_putchar_aa.h
--- sys/dev/rasops/rasops_putchar_aa.h  31 Jul 2019 04:45:44 -0000      1.6
+++ sys/dev/rasops/rasops_putchar_aa.h  4 Aug 2019 02:19:32 -0000
@@ -71,16 +71,18 @@
 #define        SET_WIDTH(p, c) memset(p, clr[c], width)
 #endif
 
+#define        MAX_WIDTH               32
+
 static void
 PUTCHAR_AA(RASOPS_DEPTH)(void *cookie, int row, int col, u_int uc, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
        struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       PIXEL_TYPE *buf = (PIXEL_TYPE *)ri->ri_buf;
        int height, width, x, y, off[2];
        uint16_t r[2], g[2], b[2];
        uint8_t *fr, aval;
        PIXEL_TYPE *rp, *hp, R, G, B;
+       PIXEL_TYPE buf[MAX_WIDTH * PIXEL_BYTES / sizeof(PIXEL_TYPE)];
        COLOR_TYPE clr[2];
 
        hp = NULL;      /* XXX GCC */
@@ -205,3 +207,5 @@ PUTCHAR_AA(RASOPS_DEPTH)(void *cookie, i
 #undef PIXEL_BYTES
 #undef SET_PIXEL
 #undef SET_WIDTH
+
+#undef MAX_WIDTH
Index: sys/dev/rasops/rasops_putchar_width.h
===================================================================
RCS file: /cvsroot/src/sys/dev/rasops/rasops_putchar_width.h,v
retrieving revision 1.10
diff -p -u -r1.10 rasops_putchar_width.h
--- sys/dev/rasops/rasops_putchar_width.h       31 Jul 2019 02:04:14 -0000      
1.10
+++ sys/dev/rasops/rasops_putchar_width.h       4 Aug 2019 02:19:33 -0000
@@ -204,7 +204,6 @@ PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
        struct wsdisplay_font *font = PICK_FONT(ri, uc);
-       STAMP_TYPE *stamp = (STAMP_TYPE *)ri->ri_stamp;
        int height, fs;
        uint8_t *fr;
        STAMP_TYPE *rp, *hp;
@@ -225,7 +224,7 @@ PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH
                return;
 
        /* Recompute stamp? */
-       if (attr != ri->ri_stamp_attr)
+       if (attr != stamp_attr || __predict_false(ri != stamp_ri))
                MAKESTAMP(RASOPS_DEPTH)(ri, attr);
 
        rp = (STAMP_TYPE *)(ri->ri_bits + row * ri->ri_yscale +

Reply via email to