Module Name:    src
Committed By:   rin
Date:           Thu Jul 25 15:18:54 UTC 2019

Modified Files:
        src/sys/dev/rasops: rasops15.c rasops24.c rasops32.c rasops8.c
Added Files:
        src/sys/dev/rasops: rasops_putchar.h rasops_putchar_width.h

Log Message:
Factor out putchar and width-optimized putchar functions into
rasops_putchar.h and rasops_putchar_width.h, respectively.

XXX
Possibly, we can do the same for putchar_aa functions. But it is
currently missing for 24-bpp.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/rasops/rasops15.c
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/rasops/rasops24.c
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/rasops/rasops32.c
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/rasops/rasops8.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/rasops/rasops_putchar.h \
    src/sys/dev/rasops/rasops_putchar_width.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/rasops/rasops15.c
diff -u src/sys/dev/rasops/rasops15.c:1.27 src/sys/dev/rasops/rasops15.c:1.28
--- src/sys/dev/rasops/rasops15.c:1.27	Thu Jul 25 03:02:44 2019
+++ src/sys/dev/rasops/rasops15.c	Thu Jul 25 15:18:53 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD: rasops15.c,v 1.27 2019/07/25 03:02:44 rin Exp $	*/
+/* 	$NetBSD: rasops15.c,v 1.28 2019/07/25 15:18:53 rin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.27 2019/07/25 03:02:44 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.28 2019/07/25 15:18:53 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -112,101 +112,8 @@ rasops15_init(struct rasops_info *ri)
 	}
 }
 
-/*
- * Paint a single character.
- */
-static void
-rasops15_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-	int fb, width, height, cnt, clr[2];
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	uint8_t *dp, *rp, *hp, *hrp, *fr;
-
-	hp = hrp = NULL;
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
-	if (ri->ri_hwbits)
-		hrp = ri->ri_hwbits + row * ri->ri_yscale +
-		    col * ri->ri_xscale;
-	height = font->fontheight;
-	width = font->fontwidth;
-
-	clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
-	clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 0xf];
-
-	if (uc == ' ') {
-		uint16_t c = (uint16_t)clr[0];
-		while (height--) {
-			dp = rp;
-			rp += ri->ri_stride;
-			if (ri->ri_hwbits) {
-				hp = hrp;
-				hrp += ri->ri_stride;
-			}
-
-			for (cnt = width; cnt; cnt--) {
-				*(uint16_t *)dp = c;
-				dp += 2;
-				if (ri->ri_hwbits) {
-					*(uint16_t *)hp = c;
-					hp += 2;
-				}
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-
-		while (height--) {
-			dp = rp;
-			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
-			    (fr[0] << 24);
-			fr += font->stride;
-			rp += ri->ri_stride;
-			if (ri->ri_hwbits) {
-				hp = hrp;
-				hrp += ri->ri_stride;
-			}
-
-			for (cnt = width; cnt; cnt--) {
-				*(uint16_t *)dp = (uint16_t)clr[(fb >> 31) & 1];
-				if (ri->ri_hwbits)
-					*(uint16_t *)hp =
-					    (uint16_t)clr[(fb >> 31) & 1];
-				fb <<= 1;
-				dp += 2;
-				if (ri->ri_hwbits)
-					hp += 2;
-			}
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		uint16_t c = (uint16_t)clr[1];
-		rp -= ri->ri_stride << 1;
-		if (ri->ri_hwbits)
-			hrp -= ri->ri_stride << 1;
-
-		while (width--) {
-			*(uint16_t *)rp = c;
-			rp += 2;
-			if (ri->ri_hwbits) {
-				*(uint16_t *)hrp = c;
-				hrp += 2;
-			}
-		}
-	}
-}
+#define	RASOPS_DEPTH	15
+#include "rasops_putchar.h"
 
 static void
 rasops15_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
@@ -329,318 +236,16 @@ rasops15_makestamp(struct rasops_info *r
 	}
 }
 
-/*
- * Paint a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops15_putchar8(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);
-	int height, so, fs;
-	uint32_t *rp, *hrp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops15_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	hrp = NULL;
+#define	RASOPS_WIDTH	8
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	12
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	16
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
 
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops15_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == (u_int)-1) {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0] = hrp[1] = hrp[2] = hrp[3] = stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			rp[0] = STAMP_READ(so);
-			rp[1] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[0] = STAMP_READ(so);
-				hrp[1] = STAMP_READ(so + 4);
-			}
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			rp[2] = STAMP_READ(so);
-			rp[3] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[2] = STAMP_READ(so);
-				hrp[3] = STAMP_READ(so + 4);
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		uint32_t c = STAMP_READ(28);
-
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] = c;
-		if (ri->ri_hwbits) {
-			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-			hrp[0] = hrp[1] = hrp[2] = hrp[3] = c;
-		}
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Paint a single character. This is for 12-pixel wide fonts.
- */
-static void
-rasops15_putchar12(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);
-	int height, so, fs;
-	uint32_t *rp, *hrp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops15_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	hrp = NULL;
-
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops15_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == (u_int)-1) {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] =
-			    stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0] = hrp[1] = hrp[2] = hrp[3] = hrp[4] =
-				    hrp[5] = stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			rp[0] = STAMP_READ(so);
-			rp[1] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[0] = STAMP_READ(so);
-				hrp[1] = STAMP_READ(so + 4);
-			}
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			rp[2] = STAMP_READ(so);
-			rp[3] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[2] = STAMP_READ(so);
-				hrp[3] = STAMP_READ(so + 4);
-			}
-
-			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
-			rp[4] = STAMP_READ(so);
-			rp[5] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[4] = STAMP_READ(so);
-				hrp[5] = STAMP_READ(so + 4);
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if (attr & WSATTR_UNDERLINE) {
-		uint32_t c = STAMP_READ(28);
-
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = c;
-		if (ri->ri_hwbits) {
-			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-			hrp[0] = hrp[1] = hrp[2] = hrp[3] = hrp[4] = hrp[5] = c;
-		}
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Paint a single character. This is for 16-pixel wide fonts.
- */
-static void
-rasops15_putchar16(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);
-	int height, so, fs;
-	uint32_t *rp, *hrp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops15_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	hrp = NULL;
-
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops15_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == (u_int)-1) {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] =
-			rp[4] = rp[5] = rp[6] = rp[7] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0] = hrp[1] = hrp[2] = hrp[3] =
-				hrp[4] = hrp[5] = hrp[6] = hrp[7] = stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			rp[0] = STAMP_READ(so);
-			rp[1] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[0] = STAMP_READ(so);
-				hrp[1] = STAMP_READ(so + 4);
-			}
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			rp[2] = STAMP_READ(so);
-			rp[3] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[2] = STAMP_READ(so);
-				hrp[3] = STAMP_READ(so + 4);
-			}
-
-			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
-			rp[4] = STAMP_READ(so);
-			rp[5] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[4] = STAMP_READ(so);
-				hrp[5] = STAMP_READ(so + 4);
-			}
-
-			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
-			rp[6] = STAMP_READ(so);
-			rp[7] = STAMP_READ(so + 4);
-			if (ri->ri_hwbits) {
-				hrp[6] = STAMP_READ(so);
-				hrp[7] = STAMP_READ(so + 4);
-			}
-
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			fr += fs;
-		}
-	}
-
-	/* Do underline */
-	if (attr & WSATTR_UNDERLINE) {
-		uint32_t c = STAMP_READ(28);
-
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] =
-		rp[4] = rp[5] = rp[6] = rp[7] = c;
-		if (ri->ri_hwbits) {
-			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-			hrp[0] = hrp[1] = hrp[2] = hrp[3] =
-			hrp[4] = hrp[5] = hrp[6] = hrp[7] = c;
-		}
-	}
-
-	stamp_mutex--;
-}
-#endif	/* !RASOPS_SMALL */
+#endif /* !RASOPS_SMALL */

Index: src/sys/dev/rasops/rasops24.c
diff -u src/sys/dev/rasops/rasops24.c:1.34 src/sys/dev/rasops/rasops24.c:1.35
--- src/sys/dev/rasops/rasops24.c:1.34	Thu Jul 25 03:02:44 2019
+++ src/sys/dev/rasops/rasops24.c	Thu Jul 25 15:18:53 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD: rasops24.c,v 1.34 2019/07/25 03:02:44 rin Exp $	*/
+/* 	$NetBSD: rasops24.c,v 1.35 2019/07/25 15:18:53 rin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.34 2019/07/25 03:02:44 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.35 2019/07/25 15:18:53 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -112,83 +112,8 @@ rasops24_init(struct rasops_info *ri)
 	ri->ri_ops.eraserows = rasops24_eraserows;
 }
 
-/*
- * Put a single character. This is the generic version.
- * XXX this bites - we should use masks.
- */
-static void
-rasops24_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-	int fb, width, height, cnt, clr[2];
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	uint8_t *dp, *rp, *fr;
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
-	height = font->fontheight;
-	width = font->fontwidth;
-
-	clr[1] = ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
-	clr[0] = ri->ri_devcmap[((u_int)attr >> 16) & 0xf];
-
-	if (uc == ' ') {
-		uint8_t c = clr[0];
-		while (height--) {
-			dp = rp;
-			rp += ri->ri_stride;
-
-			for (cnt = width; cnt; cnt--) {
-				*dp++ = c >> 16;
-				*dp++ = c >> 8;
-				*dp++ = c;
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-
-		while (height--) {
-			dp = rp;
-			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
-			    (fr[0] << 24);
-			fr += font->stride;
-			rp += ri->ri_stride;
-
-			for (cnt = width; cnt; cnt--, fb <<= 1) {
-				if ((fb >> 31) & 1) {
-					*dp++ = clr[1] >> 16;
-					*dp++ = clr[1] >> 8;
-					*dp++ = clr[1];
-				} else {
-					*dp++ = clr[0] >> 16;
-					*dp++ = clr[0] >> 8;
-					*dp++ = clr[0];
-				}
-			}
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		uint8_t c = clr[1];
-
-		rp -= ri->ri_stride << 1;
-
-		while (width--) {
-			*rp++ = c >> 16;
-			*rp++ = c >> 8;
-			*rp++ = c;
-		}
-	}
-}
+#define	RASOPS_DEPTH	24
+#include "rasops_putchar.h"
 
 #ifndef RASOPS_SMALL
 /*
@@ -232,243 +157,18 @@ rasops24_makestamp(struct rasops_info *r
 	}
 }
 
-/*
- * Put a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops24_putchar8(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);
-	int height, so, fs;
-	uint32_t *rp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops24_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops24_makestamp(ri, attr);
+#define	RASOPS_WIDTH	8
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	12
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	16
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
 
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == (u_int)-1) {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] =
-			    stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			rp[0] = STAMP_READ(so);
-			rp[1] = STAMP_READ(so + 4);
-			rp[2] = STAMP_READ(so + 8);
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			rp[3] = STAMP_READ(so);
-			rp[4] = STAMP_READ(so + 4);
-			rp[5] = STAMP_READ(so + 8);
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] = rp[4] = rp[5] = STAMP_READ(52);
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 12-pixel wide fonts.
- */
-static void
-rasops24_putchar12(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);
-	int height, so, fs;
-	uint32_t *rp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops24_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops24_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == (u_int)-1) {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] =
-			rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			rp[0] = STAMP_READ(so);
-			rp[1] = STAMP_READ(so + 4);
-			rp[2] = STAMP_READ(so + 8);
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			rp[3] = STAMP_READ(so);
-			rp[4] = STAMP_READ(so + 4);
-			rp[5] = STAMP_READ(so + 8);
-
-			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
-			rp[6] = STAMP_READ(so);
-			rp[7] = STAMP_READ(so + 4);
-			rp[8] = STAMP_READ(so + 8);
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] =
-		rp[4] = rp[5] = rp[6] = rp[7] = rp[8] = STAMP_READ(52);
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 16-pixel wide fonts.
- */
-static void
-rasops24_putchar16(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);
-	int height, so, fs;
-	uint32_t *rp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops24_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops24_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == (u_int)-1) {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] =
-			rp[4] = rp[5] = rp[6] = rp[7] =
-			rp[8] = rp[9] = rp[10] = rp[11] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			rp[0] = STAMP_READ(so);
-			rp[1] = STAMP_READ(so + 4);
-			rp[2] = STAMP_READ(so + 8);
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			rp[3] = STAMP_READ(so);
-			rp[4] = STAMP_READ(so + 4);
-			rp[5] = STAMP_READ(so + 8);
-
-			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
-			rp[6] = STAMP_READ(so);
-			rp[7] = STAMP_READ(so + 4);
-			rp[8] = STAMP_READ(so + 8);
-
-			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
-			rp[9] = STAMP_READ(so);
-			rp[10] = STAMP_READ(so + 4);
-			rp[11] = STAMP_READ(so + 8);
-
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			fr += fs;
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] =
-		rp[4] = rp[5] = rp[6] = rp[7] =
-		rp[8] = rp[9] = rp[10] = rp[11] = STAMP_READ(52);
-	}
-
-	stamp_mutex--;
-}
 #endif	/* !RASOPS_SMALL */
 
 /*

Index: src/sys/dev/rasops/rasops32.c
diff -u src/sys/dev/rasops/rasops32.c:1.36 src/sys/dev/rasops/rasops32.c:1.37
--- src/sys/dev/rasops/rasops32.c:1.36	Thu Jul 25 15:12:47 2019
+++ src/sys/dev/rasops/rasops32.c	Thu Jul 25 15:18:53 2019
@@ -1,4 +1,4 @@
-/*	 $NetBSD: rasops32.c,v 1.36 2019/07/25 15:12:47 rin Exp $	*/
+/*	 $NetBSD: rasops32.c,v 1.37 2019/07/25 15:18:53 rin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.36 2019/07/25 15:12:47 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.37 2019/07/25 15:18:53 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -108,97 +108,8 @@ rasops32_init(struct rasops_info *ri)
 	}
 }
 
-/*
- * Paint a single character.
- */
-
-static void
-rasops32_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-	int width, height, cnt, fs, fb, clr[2];
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-	uint32_t *dp, *rp, *hp, *hrp;
-	uint8_t *fr;
-
-	hp = hrp = NULL;
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	/* check if character fits into font limits */
-	if (!CHAR_IN_FONT(uc, font))
-		return;
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-
-	height = font->fontheight;
-	width = font->fontwidth;
-
-	clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
-	clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
-
-	if (uc == ' ') {
-		while (height--) {
-			dp = rp;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hp = hrp;
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-
-			for (cnt = width; cnt; cnt--) {
-				*dp++ = clr[0];
-				if (ri->ri_hwbits)
-					*hp++ = clr[0];
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			dp = rp;
-			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
-			    (fr[0] << 24);
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hp = hrp;
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-
-			for (cnt = width; cnt; cnt--) {
-				*dp++ = clr[(fb >> 31) & 1];
-				if (ri->ri_hwbits)
-					*hp++ = clr[(fb >> 31) & 1];
-				fb <<= 1;
-			}
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		if (ri->ri_hwbits)
-			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-
-		while (width--) {
-			*rp++ = clr[1];
-			if (ri->ri_hwbits)
-				*hrp++ = clr[1];
-		}
-	}
-}
+#define	RASOPS_DEPTH	32
+#include "rasops_putchar.h"
 
 static void
 rasops32_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
@@ -307,410 +218,16 @@ rasops32_makestamp(struct rasops_info *r
 	}
 }
 
-/*
- * Put a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops32_putchar8(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);
-	int height, so, fs;
-	uint32_t *rp, *hrp = NULL;
-	uint8_t *fr;
-
-	hrp = NULL; /* XXX GCC */
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	/* check if character fits into font limits */
-	if (!CHAR_IN_FONT(uc, font))
-		return;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops32_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops32_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-
-	height = font->fontheight;
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] =
-			rp[4] = rp[5] = rp[6] = rp[7] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0] = hrp[1] = hrp[2] = hrp[3] =
-				hrp[4] = hrp[5] = hrp[6] = hrp[7] = stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			uint32_t tmp0, tmp1, tmp2, tmp3;
-
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[0] = tmp0;
-			rp[1] = tmp1;
-			rp[2] = tmp2;
-			rp[3] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[0] = tmp0;
-				hrp[1] = tmp1;
-				hrp[2] = tmp2;
-				hrp[3] = tmp3;
-			}
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[4] = tmp0;
-			rp[5] = tmp1;
-			rp[6] = tmp2;
-			rp[7] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[4] = tmp0;
-				hrp[5] = tmp1;
-				hrp[6] = tmp2;
-				hrp[7] = tmp3;
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] =
-		rp[4] = rp[5] = rp[6] = rp[7] = stamp[60];
-		if (ri->ri_hwbits)
-			hrp[0] = hrp[1] = hrp[2] = hrp[3] =
-			hrp[4] = hrp[5] = hrp[6] = hrp[7] = stamp[60];
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 12-pixel wide fonts.
- */
-static void
-rasops32_putchar12(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);
-	int height, so, fs;
-	uint32_t *rp, *hrp = NULL;
-	uint8_t *fr;
-
-	hrp = NULL; /* XXX GCC */
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	/* check if character fits into font limits */
-	if (!CHAR_IN_FONT(uc, font))
-		return;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops32_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops32_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-
-	height = font->fontheight;
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0]  = rp[1]  = rp[2]  = rp[3]  =
-			rp[4]  = rp[5]  = rp[6]  = rp[7]  =
-			rp[8]  = rp[9]  = rp[10] = rp[11] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0]  = hrp[1]  = hrp[2]  = hrp[3]  =
-				hrp[4]  = hrp[5]  = hrp[6]  = hrp[7]  =
-				hrp[8]  = hrp[9]  = hrp[10] = hrp[11] =
-				    stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			uint32_t tmp0, tmp1, tmp2, tmp3;
-
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[0] = tmp0;
-			rp[1] = tmp1;
-			rp[2] = tmp2;
-			rp[3] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[0] = tmp0;
-				hrp[1] = tmp1;
-				hrp[2] = tmp2;
-				hrp[3] = tmp3;
-			}
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[4] = tmp0;
-			rp[5] = tmp1;
-			rp[6] = tmp2;
-			rp[7] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[4] = tmp0;
-				hrp[5] = tmp1;
-				hrp[6] = tmp2;
-				hrp[7] = tmp3;
-			}
-
-			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[8] = tmp0;
-			rp[9] = tmp1;
-			rp[10] = tmp2;
-			rp[11] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[8] = tmp0;
-				hrp[9] = tmp1;
-				hrp[10] = tmp2;
-				hrp[11] = tmp3;
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0]  = rp[1]  = rp[2]  = rp[3]  =
-		rp[4]  = rp[5]  = rp[6]  = rp[7]  =
-		rp[8]  = rp[9]  = rp[10] = rp[11] = stamp[60];
-		if (ri->ri_hwbits)
-			hrp[0]  = hrp[1]  = hrp[2]  = hrp[3]  =
-			hrp[4]  = hrp[5]  = hrp[6]  = hrp[7]  =
-			hrp[8]  = hrp[9]  = hrp[10] = hrp[11] = stamp[60];
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 16-pixel wide fonts.
- */
-static void
-rasops32_putchar16(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);
-	int height, so, fs;
-	uint32_t *rp, *hrp = NULL;
-	uint8_t *fr;
-
-	hrp = NULL; /* XXX GCC */
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-
-	/* check if character fits into font limits */
-	if (!CHAR_IN_FONT(uc, font))
-		return;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops32_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops32_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-
-	height = font->fontheight;
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0]  = rp[1]  = rp[2]  = rp[3]  =
-			rp[4]  = rp[5]  = rp[6]  = rp[7]  =
-			rp[8]  = rp[9]  = rp[10] = rp[11] =
-			rp[12] = rp[13] = rp[14] = rp[15] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0]  = hrp[1]  = hrp[2]  = hrp[3]  =
-				hrp[4]  = hrp[5]  = hrp[6]  = hrp[7]  =
-				hrp[8]  = hrp[9]  = hrp[10] = hrp[11] =
-				hrp[12] = hrp[13] = hrp[14] = hrp[15] =
-				    stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
+#define	RASOPS_WIDTH	8
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	12
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	16
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
 
-		while (height--) {
-			uint32_t tmp0, tmp1, tmp2, tmp3;
-
-			so = STAMP_SHIFT(fr[0], 1) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[0] = tmp0;
-			rp[1] = tmp1;
-			rp[2] = tmp2;
-			rp[3] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[0] = tmp0;
-				hrp[1] = tmp1;
-				hrp[2] = tmp2;
-				hrp[3] = tmp3;
-			}
-
-			so = STAMP_SHIFT(fr[0], 0) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[4] = tmp0;
-			rp[5] = tmp1;
-			rp[6] = tmp2;
-			rp[7] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[4] = tmp0;
-				hrp[5] = tmp1;
-				hrp[6] = tmp2;
-				hrp[7] = tmp3;
-			}
-
-			so = STAMP_SHIFT(fr[1], 1) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[8] = tmp0;
-			rp[9] = tmp1;
-			rp[10] = tmp2;
-			rp[11] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[8] = tmp0;
-				hrp[9] = tmp1;
-				hrp[10] = tmp2;
-				hrp[11] = tmp3;
-			}
-
-			so = STAMP_SHIFT(fr[1], 0) & STAMP_MASK;
-			tmp0 = STAMP_READ(so);
-			tmp1 = STAMP_READ(so +  4);
-			tmp2 = STAMP_READ(so +  8);
-			tmp3 = STAMP_READ(so + 12);
-			rp[12] = tmp0;
-			rp[13] = tmp1;
-			rp[14] = tmp2;
-			rp[15] = tmp3;
-			if (ri->ri_hwbits) {
-				hrp[12] = tmp0;
-				hrp[13] = tmp1;
-				hrp[14] = tmp2;
-				hrp[15] = tmp3;
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0]  = rp[1]  = rp[2]  = rp[3]  =
-		rp[4]  = rp[5]  = rp[6]  = rp[7]  =
-		rp[8]  = rp[9]  = rp[10] = rp[11] =
-		rp[12] = rp[13] = rp[14] = rp[15] = stamp[60];
-		if (ri->ri_hwbits)
-			hrp[0]  = hrp[1]  = hrp[2]  = hrp[3]  =
-			hrp[4]  = hrp[5]  = hrp[6]  = hrp[7]  =
-			hrp[8]  = hrp[9]  = hrp[10] = hrp[11] =
-			hrp[12] = hrp[13] = hrp[14] = hrp[15] = stamp[60];
-	}
-
-	stamp_mutex--;
-}
-#endif
+#endif /* !RASOPS_SMALL */

Index: src/sys/dev/rasops/rasops8.c
diff -u src/sys/dev/rasops/rasops8.c:1.41 src/sys/dev/rasops/rasops8.c:1.42
--- src/sys/dev/rasops/rasops8.c:1.41	Thu Jul 25 03:02:44 2019
+++ src/sys/dev/rasops/rasops8.c	Thu Jul 25 15:18:53 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp $	*/
+/* 	$NetBSD: rasops8.c,v 1.42 2019/07/25 15:18:53 rin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.42 2019/07/25 15:18:53 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -106,90 +106,8 @@ rasops8_init(struct rasops_info *ri)
 	}
 }
 
-/*
- * Put a single character.
- */
-static void
-rasops8_putchar(void *cookie, int row, int col, u_int uc, long attr)
-{
-	int width, height, cnt, fs, fb;
-	uint8_t *dp, *rp, *hp, *hrp, *fr, clr[2];
-	struct rasops_info *ri = (struct rasops_info *)cookie;
-	struct wsdisplay_font *font = PICK_FONT(ri, uc);
-
-	hp = hrp = NULL;
-
-	if (!CHAR_IN_FONT(uc, font))
-		return;
-
-#ifdef RASOPS_CLIPPING
-	/* Catches 'row < 0' case too */
-	if ((unsigned)row >= (unsigned)ri->ri_rows)
-		return;
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols)
-		return;
-#endif
-	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
-	if (ri->ri_hwbits)
-		hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
-		    ri->ri_xscale;
-
-	height = font->fontheight;
-	width = font->fontwidth;
-	clr[0] = (uint8_t)ri->ri_devcmap[(attr >> 16) & 0xf];
-	clr[1] = (uint8_t)ri->ri_devcmap[(attr >> 24) & 0xf];
-
-	if (uc == ' ') {
-		uint8_t c = clr[0];
-
-		while (height--) {
-			memset(rp, c, width);
-			if (ri->ri_hwbits) {
-				memset(hrp, c, width);
-				hrp += ri->ri_stride;
-			}
-			rp += ri->ri_stride;
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			dp = rp;
-			if (ri->ri_hwbits)
-				hp = hrp;
-			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
-			    (fr[0] << 24);
-			fr += fs;
-			rp += ri->ri_stride;
-			if (ri->ri_hwbits)
-				hrp += ri->ri_stride;
-
-			for (cnt = width; cnt; cnt--) {
-				*dp++ = clr[(fb >> 31) & 1];
-				if (ri->ri_hwbits)
-					*hp++ = clr[(fb >> 31) & 1];
-				fb <<= 1;
-			}
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		uint8_t c = clr[1];
-
-		rp -= (ri->ri_stride << 1);
-		if (ri->ri_hwbits)
-			hrp -= (ri->ri_stride << 1);
-
-		while (width--) {
-			*rp++ = c;
-			if (ri->ri_hwbits)
-				*hrp++ = c;
-		}
-	}
-}
+#define	RASOPS_DEPTH	8
+#include "rasops_putchar.h"
 
 static void
 rasops8_putchar_aa(void *cookie, int row, int col, u_int uc, long attr)
@@ -329,279 +247,16 @@ rasops8_makestamp(struct rasops_info *ri
 	}
 }
 
-/*
- * Put a single character. This is for 8-pixel wide fonts.
- */
-static void
-rasops8_putchar8(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);
-	int height, fs;
-	uint32_t *rp, *hp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops8_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	hp = NULL;
-
-	if (!CHAR_IN_FONT(uc, font))
-		return;
-
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops8_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hp[0] = hp[1] = stamp[0];
-				DELTA(hp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
-			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
-			if (ri->ri_hwbits) {
-				hp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
-				    STAMP_MASK);
-				hp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
-				    STAMP_MASK);
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = stamp[15];
-		if (ri->ri_hwbits) {
-			DELTA(hp, -(ri->ri_stride << 1), uint32_t *);
-			hp[0] = hp[1] = stamp[15];
-		}
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 12-pixel wide fonts.
- */
-static void
-rasops8_putchar12(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);
-	int height, fs;
-	uint32_t *rp,  *hrp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops8_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	hrp = NULL;
-
-	if (!CHAR_IN_FONT(uc, font))
-		return;
-
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
-#endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops8_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0] = hrp[1] = hrp[2] = stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
-			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
-			rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
-			if (ri->ri_hwbits) {
-				hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
-				    STAMP_MASK);
-				hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
-				    STAMP_MASK);
-				hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) &
-				    STAMP_MASK);
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = stamp[15];
-		if (ri->ri_hwbits) {
-			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-			hrp[0] = hrp[1] = hrp[2] = stamp[15];
-		}
-	}
-
-	stamp_mutex--;
-}
-
-/*
- * Put a single character. This is for 16-pixel wide fonts.
- */
-static void
-rasops8_putchar16(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);
-	int height, fs;
-	uint32_t *rp, *hrp;
-	uint8_t *fr;
-
-	/* Can't risk remaking the stamp if it's already in use */
-	if (stamp_mutex++) {
-		stamp_mutex--;
-		rasops8_putchar(cookie, row, col, uc, attr);
-		return;
-	}
-
-	hrp = NULL;
-
-	if (!CHAR_IN_FONT(uc, font))
-		return;
+#define	RASOPS_WIDTH	8
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	12
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
+
+#define	RASOPS_WIDTH	16
+#include "rasops_putchar_width.h"
+#undef	RASOPS_WIDTH
 
-#ifdef RASOPS_CLIPPING
-	if ((unsigned)row >= (unsigned)ri->ri_rows) {
-		stamp_mutex--;
-		return;
-	}
-
-	if ((unsigned)col >= (unsigned)ri->ri_cols) {
-		stamp_mutex--;
-		return;
-	}
 #endif
-
-	/* Recompute stamp? */
-	if (attr != stamp_attr)
-		rasops8_makestamp(ri, attr);
-
-	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
-	if (ri->ri_hwbits)
-		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
-		    col*ri->ri_xscale);
-	height = font->fontheight;
-
-	if (uc == ' ') {
-		while (height--) {
-			rp[0] = rp[1] = rp[2] = rp[3] = stamp[0];
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits) {
-				hrp[0] = hrp[1] = hrp[2] = hrp[3] = stamp[0];
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-			}
-		}
-	} else {
-		fr = FONT_GLYPH(uc, font, ri);
-		fs = font->stride;
-
-		while (height--) {
-			rp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) & STAMP_MASK);
-			rp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) & STAMP_MASK);
-			rp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) & STAMP_MASK);
-			rp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) & STAMP_MASK);
-			if (ri->ri_hwbits) {
-				hrp[0] = STAMP_READ(STAMP_SHIFT(fr[0], 1) &
-				    STAMP_MASK);
-				hrp[1] = STAMP_READ(STAMP_SHIFT(fr[0], 0) &
-				    STAMP_MASK);
-				hrp[2] = STAMP_READ(STAMP_SHIFT(fr[1], 1) &
-				    STAMP_MASK);
-				hrp[3] = STAMP_READ(STAMP_SHIFT(fr[1], 0) &
-				    STAMP_MASK);
-			}
-
-			fr += fs;
-			DELTA(rp, ri->ri_stride, uint32_t *);
-			if (ri->ri_hwbits)
-				DELTA(hrp, ri->ri_stride, uint32_t *);
-		}
-	}
-
-	/* Do underline */
-	if ((attr & WSATTR_UNDERLINE) != 0) {
-		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
-		rp[0] = rp[1] = rp[2] = rp[3] = stamp[15];
-		if (ri->ri_hwbits) {
-			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
-			hrp[0] = hrp[1] = hrp[2] = hrp[3] = stamp[15];
-		}
-	}
-
-	stamp_mutex--;
-}
-#endif /* !RASOPS_SMALL */

Added files:

Index: src/sys/dev/rasops/rasops_putchar.h
diff -u /dev/null src/sys/dev/rasops/rasops_putchar.h:1.1
--- /dev/null	Thu Jul 25 15:18:54 2019
+++ src/sys/dev/rasops/rasops_putchar.h	Thu Jul 25 15:18:53 2019
@@ -0,0 +1,166 @@
+/* $NetBSD: rasops_putchar.h,v 1.1 2019/07/25 15:18:53 rin Exp $ */
+
+/* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp  */
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if RASOPS_DEPTH != 8 && RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && \
+    RASOPS_DEPTH != 32
+#error "Depth not supported"
+#endif
+
+#define PUTCHAR(depth)	PUTCHAR1(depth)
+#define PUTCHAR1(depth)	rasops ## depth ## _putchar
+
+#if RASOPS_DEPTH == 8
+#define	CLR_TYPE	uint8_t
+#elif RASOPS_DEPTH ==  15
+#define	CLR_TYPE	uint16_t
+#else
+#define	CLR_TYPE	uint32_t
+#endif
+
+#if RASOPS_DEPTH == 24
+#define	SUBST_CLR(p, index)						\
+	do {								\
+		CLR_TYPE c = clr[index];				\
+		*(p)++ = c >> 16;					\
+		*(p)++ = c >> 8;					\
+		*(p)++ = c;						\
+	} while (0 /* CONSTCOND */)
+#else
+#define	SUBST_CLR(p, index)						\
+	do {								\
+		*(CLR_TYPE *)(p) = clr[index];				\
+		(p) += sizeof(CLR_TYPE);				\
+	} while (0 /* CONSTCOND */)
+#endif
+
+/*
+ * Put a single character.
+ */
+static void
+PUTCHAR(RASOPS_DEPTH)(void *cookie, int row, int col, u_int uc, long attr)
+{
+	int width, height, cnt, fs, fb;
+	uint8_t *dp, *rp, *hp, *hrp, *fr;
+	struct rasops_info *ri = (struct rasops_info *)cookie;
+	struct wsdisplay_font *font = PICK_FONT(ri, uc);
+	CLR_TYPE clr[2];
+
+	hp = hrp = NULL;
+
+	if (!CHAR_IN_FONT(uc, font))
+		return;
+
+#ifdef RASOPS_CLIPPING
+	/* Catches 'row < 0' case too */
+	if ((unsigned)row >= (unsigned)ri->ri_rows)
+		return;
+
+	if ((unsigned)col >= (unsigned)ri->ri_cols)
+		return;
+#endif
+
+	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
+	if (ri->ri_hwbits)
+		hrp = ri->ri_hwbits + row * ri->ri_yscale + col *
+		    ri->ri_xscale;
+
+	height = font->fontheight;
+	width = font->fontwidth;
+
+	clr[0] = (CLR_TYPE)ri->ri_devcmap[(attr >> 16) & 0xf];
+	clr[1] = (CLR_TYPE)ri->ri_devcmap[(attr >> 24) & 0xf];
+
+	if (uc == ' ') {
+		while (height--) {
+#if RASOPS_DEPTH == 8
+			memset(rp, clr[0], width);
+			if (ri->ri_hwbits)
+				memset(hrp, clr[0], width);
+#else
+			dp = rp;
+			if (ri->ri_hwbits)
+				hp = hrp;
+			for (cnt = width; cnt; cnt--) {
+				SUBST_CLR(dp, 0);
+				if (ri->ri_hwbits)
+					SUBST_CLR(hp, 0);
+			}
+#endif
+			rp += ri->ri_stride;
+			if (ri->ri_hwbits)
+				hrp += ri->ri_stride;
+		}
+	} else {
+		fr = FONT_GLYPH(uc, font, ri);
+		fs = font->stride;
+
+		while (height--) {
+			dp = rp;
+			rp += ri->ri_stride;
+			if (ri->ri_hwbits) {
+				hp = hrp;
+				hrp += ri->ri_stride;
+			}
+			fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) |
+			    (fr[0] << 24);
+			fr += fs;
+			for (cnt = width; cnt; cnt--) {
+				SUBST_CLR(dp, (fb >> 31) & 1);
+				if (ri->ri_hwbits)
+					SUBST_CLR(hp, (fb >> 31) & 1);
+				fb <<= 1;
+			}
+		}
+	}
+
+	/* Do underline */
+	if ((attr & WSATTR_UNDERLINE) != 0) {
+		rp -= (ri->ri_stride << 1);
+		if (ri->ri_hwbits)
+			hrp -= (ri->ri_stride << 1);
+#if RASOPS_DEPTH == 8
+		memset(rp, clr[1], width);
+		if (ri->ri_hwbits)
+			memset(hrp, clr[1], width);
+#else
+		while (width--) {
+			SUBST_CLR(rp, 1);
+			if (ri->ri_hwbits)
+				SUBST_CLR(hrp, 1);
+		}
+#endif
+	}
+}
+
+#undef	PUTCHAR
+#undef	CLR_TYPE
+#undef	SUBST_CLR
Index: src/sys/dev/rasops/rasops_putchar_width.h
diff -u /dev/null src/sys/dev/rasops/rasops_putchar_width.h:1.1
--- /dev/null	Thu Jul 25 15:18:54 2019
+++ src/sys/dev/rasops/rasops_putchar_width.h	Thu Jul 25 15:18:54 2019
@@ -0,0 +1,265 @@
+/* $NetBSD: rasops_putchar_width.h,v 1.1 2019/07/25 15:18:54 rin Exp $ */
+
+/* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp  */
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if RASOPS_DEPTH != 8 && RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && \
+    RASOPS_DEPTH != 32
+#error "Depth not supported"
+#endif
+
+#if RASOPS_WIDTH != 8 && RASOPS_WIDTH != 12 && RASOPS_WIDTH != 16
+#error "Width not supported"
+#endif
+
+#if   RASOPS_DEPTH == 8
+#define	FILLED_STAMP	15
+#elif RASOPS_DEPTH == 15
+#define	FILLED_STAMP	30
+#else
+#define	FILLED_STAMP	60
+#endif
+
+#define	PUTCHAR_WIDTH1(depth, width)	rasops ## depth ## _putchar ## width
+#define	PUTCHAR_WIDTH(depth, width)	PUTCHAR_WIDTH1(depth, width)
+
+#define	PUTCHAR1(depth)			rasops ## depth ## _putchar
+#define	PUTCHAR(depth)			PUTCHAR1(depth)
+
+#define	MAKESTAMP1(depth)		rasops ## depth ## _makestamp
+#define	MAKESTAMP(depth)		MAKESTAMP1(depth)
+
+/* ################################################################### */
+
+#if RASOPS_DEPTH == 8
+
+#define	SUBST_STAMP1(p, off)						\
+	(p)[(off) * 1 + 0] =
+
+#define	SUBST_GLYPH1(index, nibble, off)				\
+	do {								\
+		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
+		rp[(off) * 1 + 0] = STAMP_READ(so);			\
+		if (ri->ri_hwbits) {					\
+			hrp[(off) * 1 + 0] = STAMP_READ(so);		\
+		}							\
+	} while (0 /* CONSTCOND */);
+
+#endif /* RASOPS_DEPTH == 8 */
+
+/* ################################################################### */
+
+#if RASOPS_DEPTH == 15
+
+#define	SUBST_STAMP1(p, off)						\
+	(p)[(off) * 2 + 0] = (p)[(off) * 2 + 1] =
+
+#define	SUBST_GLYPH1(index, nibble, off)				\
+	do {								\
+		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
+		rp[(off) * 2 + 0] = STAMP_READ(so);			\
+		rp[(off) * 2 + 1] = STAMP_READ(so +  4);		\
+		if (ri->ri_hwbits) {					\
+			hrp[(off) * 2 + 0] = STAMP_READ(so);		\
+			hrp[(off) * 2 + 1] = STAMP_READ(so +  4);	\
+		}							\
+	} while (0 /* CONSTCOND */);
+
+#endif /* RASOPS_DEPTH == 15 */
+
+/* ################################################################### */
+
+#if RASOPS_DEPTH == 24
+
+#define	SUBST_STAMP1(p, off)						\
+	(p)[(off) * 3 + 0] = (p)[(off) * 3 + 1] = (p)[(off) * 3 + 2] =
+
+#define	SUBST_GLYPH1(index, nibble, off)				\
+	do {								\
+		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
+		rp[(off) * 3 + 0] = STAMP_READ(so);			\
+		rp[(off) * 3 + 1] = STAMP_READ(so +  4);		\
+		rp[(off) * 3 + 2] = STAMP_READ(so +  8);		\
+		if (ri->ri_hwbits) {					\
+			hrp[(off) * 3 + 0] = STAMP_READ(so);		\
+			hrp[(off) * 3 + 1] = STAMP_READ(so +  4);	\
+			hrp[(off) * 3 + 2] = STAMP_READ(so +  8);	\
+		}							\
+	} while (0 /* CONSTCOND */);
+
+#endif /* RASOPS_DEPTH == 24 */
+
+/* ################################################################### */
+
+#if RASOPS_DEPTH == 32
+
+#define	SUBST_STAMP1(p, off)						\
+	(p)[(off) * 4 + 0] = (p)[(off) * 4 + 1] =			\
+	(p)[(off) * 4 + 2] = (p)[(off) * 4 + 3] =
+
+#define	SUBST_GLYPH1(index, nibble, off)				\
+	do {								\
+		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
+		rp[(off) * 4 + 0] = STAMP_READ(so);			\
+		rp[(off) * 4 + 1] = STAMP_READ(so +  4);		\
+		rp[(off) * 4 + 2] = STAMP_READ(so +  8);		\
+		rp[(off) * 4 + 3] = STAMP_READ(so + 12);		\
+		if (ri->ri_hwbits) {					\
+			hrp[(off) * 4 + 0] = STAMP_READ(so);		\
+			hrp[(off) * 4 + 1] = STAMP_READ(so +  4);	\
+			hrp[(off) * 4 + 2] = STAMP_READ(so +  8);	\
+			hrp[(off) * 4 + 3] = STAMP_READ(so + 12);	\
+		}							\
+	} while (0 /* CONSTCOND */);
+
+#endif /* RASOPS_DEPTH == 32 */
+
+/* ################################################################### */
+
+#if   RASOPS_WIDTH == 8
+#define	SUBST_STAMP(p, val) \
+	SUBST_STAMP1(p, 0) SUBST_STAMP1(p, 1) (val)
+#elif RASOPS_WIDTH == 12
+#define	SUBST_STAMP(p, val) \
+	SUBST_STAMP1(p, 0) SUBST_STAMP1(p, 1) SUBST_STAMP1(p, 2) (val)
+#elif RASOPS_WIDTH == 16
+#define	SUBST_STAMP(p, val) \
+	SUBST_STAMP1(p, 0) SUBST_STAMP1(p, 1) SUBST_STAMP1(p, 2) \
+	SUBST_STAMP1(p, 3) (val)
+#endif
+
+#if   RASOPS_WIDTH == 8
+#define	SUBST_GLYPH \
+	SUBST_GLYPH1(0, 1, 0) SUBST_GLYPH1(0, 0, 1)
+#elif RASOPS_WIDTH == 12
+#define	SUBST_GLYPH \
+	SUBST_GLYPH1(0, 1, 0) SUBST_GLYPH1(0, 0, 1) SUBST_GLYPH1(1, 1, 2)
+#elif RASOPS_WIDTH == 16
+#define	SUBST_GLYPH \
+	SUBST_GLYPH1(0, 1, 0) SUBST_GLYPH1(0, 0, 1) SUBST_GLYPH1(1, 1, 2) \
+	SUBST_GLYPH1(1, 0, 3)
+#endif
+
+/*
+ * Width-optimized putchar function.
+ */
+static void
+PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH)(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);
+	int height, so, fs;
+	uint32_t *rp, *hrp = NULL;
+	uint8_t *fr;
+
+	hrp = NULL; /* XXX GCC */
+
+#ifdef RASOPS_CLIPPING
+	/* Catches 'row < 0' case too */
+	if ((unsigned)row >= (unsigned)ri->ri_rows)
+		return;
+
+	if ((unsigned)col >= (unsigned)ri->ri_cols)
+		return;
+#endif
+
+	/* check if character fits into font limits */
+	if (!CHAR_IN_FONT(uc, font))
+		return;
+
+	/* Can't risk remaking the stamp if it's already in use */
+	if (stamp_mutex++) {
+		stamp_mutex--;
+		PUTCHAR(RASOPS_DEPTH)(cookie, row, col, uc, attr);
+		return;
+	}
+
+	/* Recompute stamp? */
+	if (attr != stamp_attr)
+		MAKESTAMP(RASOPS_DEPTH)(ri, attr);
+
+	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
+	if (ri->ri_hwbits)
+		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
+		    col*ri->ri_xscale);
+
+	height = font->fontheight;
+
+	if (uc == ' ') {
+		while (height--) {
+			SUBST_STAMP(rp, stamp[0]);
+			DELTA(rp, ri->ri_stride, uint32_t *);
+			if (ri->ri_hwbits) {
+				SUBST_STAMP(hrp, stamp[0]);
+				DELTA(hrp, ri->ri_stride, uint32_t *);
+			}
+		}
+	} else {
+		fr = FONT_GLYPH(uc, font, ri);
+		fs = font->stride;
+
+		while (height--) {
+			SUBST_GLYPH
+
+			fr += fs;
+			DELTA(rp, ri->ri_stride, uint32_t *);
+			if (ri->ri_hwbits)
+				DELTA(hrp, ri->ri_stride, uint32_t *);
+		}
+	}
+
+	/* Do underline */
+	if ((attr & WSATTR_UNDERLINE) != 0) {
+		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
+		SUBST_STAMP(rp, stamp[FILLED_STAMP]);
+		if (ri->ri_hwbits)
+			SUBST_STAMP(hrp, stamp[FILLED_STAMP]);
+	}
+
+	stamp_mutex--;
+}
+
+#undef	FILLED_STAMP
+
+#undef	PUTCHAR_WIDTH1
+#undef	PUTCHAR_WIDTH
+
+#undef	PUTCHAR1
+#undef	PUTCHAR
+
+#undef	MAKESTAMP1
+#undef	MAKESTAMP
+
+#undef	SUBST_STAMP1
+#undef	SUBST_STAMP
+
+#undef	SUBST_GLYPH1
+#undef	SUBST_GLYPH

Reply via email to