Module Name: src Committed By: tsutsui Date: Mon Dec 2 14:05:51 UTC 2013
Modified Files: src/sys/dev/rasops: README rasops_bitops.h rasops_masks.c rasops_masks.h Log Message: Fix 1 bpp rasops copycols() op: - fix inverted shift direction in MBL() and MBR() macro in BE case (used by GETBITS() and PUTBITS() in copycols() function in rasops_bitops.h) - make all bitmask values unsigned and use proper uint32_t types for bitmap variables (to avoid arithmetic right shift) - fix various botches in right-to-left copy op (logic is taken from hp300) Tested on bwtwo(4) on NetBSD/sparc. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/rasops/README cvs rdiff -u -r1.14 -r1.15 src/sys/dev/rasops/rasops_bitops.h cvs rdiff -u -r1.8 -r1.9 src/sys/dev/rasops/rasops_masks.c cvs rdiff -u -r1.7 -r1.8 src/sys/dev/rasops/rasops_masks.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/README diff -u src/sys/dev/rasops/README:1.5 src/sys/dev/rasops/README:1.6 --- src/sys/dev/rasops/README:1.5 Mon Jan 7 00:25:19 2008 +++ src/sys/dev/rasops/README Mon Dec 2 14:05:51 2013 @@ -1,4 +1,4 @@ -$NetBSD: README,v 1.5 2008/01/07 00:25:19 bjs Exp $ +$NetBSD: README,v 1.6 2013/12/02 14:05:51 tsutsui Exp $ This directory contains `rasops', a set of raster operations intended to replace the dev/rcons/raster stuff for both wscons and rcons. It yields @@ -8,7 +8,6 @@ Issues/TODO: - There is no generic `putchar' function for 2bpp - Color handling for 2bpp is broken -- copycols() from rasops_bitops.h is broken in right->left case - 64-bit types are not used on machines that are 64-bit - We should never be doing reads/writes of less than 32-bits - Flags in attribute values are hardcoded Index: src/sys/dev/rasops/rasops_bitops.h diff -u src/sys/dev/rasops/rasops_bitops.h:1.14 src/sys/dev/rasops/rasops_bitops.h:1.15 --- src/sys/dev/rasops/rasops_bitops.h:1.14 Tue May 21 15:57:21 2013 +++ src/sys/dev/rasops/rasops_bitops.h Mon Dec 2 14:05:51 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops_bitops.h,v 1.14 2013/05/21 15:57:21 tsutsui Exp $ */ +/* $NetBSD: rasops_bitops.h,v 1.15 2013/12/02 14:05:51 tsutsui Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -38,9 +38,9 @@ static void NAME(erasecols)(void *cookie, int row, int col, int num, long attr) { - int lmask, rmask, lclr, rclr, clr; + int lclr, rclr, clr; struct rasops_info *ri; - int32_t *dp, *rp, *hrp = NULL, *hp = NULL, tmp; + uint32_t *dp, *rp, *hrp = NULL, *hp = NULL, tmp, lmask, rmask; int height, cnt; ri = (struct rasops_info *)cookie; @@ -64,9 +64,9 @@ NAME(erasecols)(void *cookie, int row, i num *= ri->ri_font->fontwidth << PIXEL_SHIFT; height = ri->ri_font->fontheight; clr = ri->ri_devcmap[(attr >> 16) & 0xf]; - rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3)); + rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3)); if (ri->ri_hwbits) - hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale + + hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale + ((col >> 3) & ~3)); if ((col & 31) + num <= 32) { lmask = ~rasops_pmask[col & 31][num]; @@ -74,13 +74,13 @@ NAME(erasecols)(void *cookie, int row, i while (height--) { dp = rp; - DELTA(rp, ri->ri_stride, int32_t *); + DELTA(rp, ri->ri_stride, uint32_t *); tmp = (*dp & lmask) | lclr; *dp = tmp; if (ri->ri_hwbits) { *hrp = tmp; - DELTA(hrp, ri->ri_stride, int32_t *); + DELTA(hrp, ri->ri_stride, uint32_t *); } } } else { @@ -97,10 +97,10 @@ NAME(erasecols)(void *cookie, int row, i while (height--) { dp = rp; - DELTA(rp, ri->ri_stride, int32_t *); + DELTA(rp, ri->ri_stride, uint32_t *); if (ri->ri_hwbits) { hp = hrp; - DELTA(hrp, ri->ri_stride, int32_t *); + DELTA(hrp, ri->ri_stride, uint32_t *); } if (lmask) { @@ -136,16 +136,16 @@ NAME(erasecols)(void *cookie, int row, i static void NAME(do_cursor)(struct rasops_info *ri) { - int lmask, rmask, height, row, col, num; - int32_t *dp, *rp, *hp = NULL, *hrp = NULL, tmp; + int height, row, col, num; + uint32_t *dp, *rp, *hp = NULL, *hrp = NULL, tmp, lmask, rmask; row = ri->ri_crow; col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT; height = ri->ri_font->fontheight; num = ri->ri_font->fontwidth << PIXEL_SHIFT; - rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); + rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); if (ri->ri_hwbits) - hrp = (int32_t *)(ri->ri_hwbits + row * ri->ri_yscale + + hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale + ((col >> 3) & ~3)); if ((col & 31) + num <= 32) { @@ -153,14 +153,14 @@ NAME(do_cursor)(struct rasops_info *ri) while (height--) { dp = rp; - DELTA(rp, ri->ri_stride, int32_t *); + DELTA(rp, ri->ri_stride, uint32_t *); *dp ^= lmask; } if (ri->ri_hwbits) { height = ri->ri_font->fontheight; while (height--) { hp = hrp; - DELTA(hrp, ri->ri_stride, int32_t *); + DELTA(hrp, ri->ri_stride, uint32_t *); *hp ^= lmask; } } @@ -170,10 +170,10 @@ NAME(do_cursor)(struct rasops_info *ri) while (height--) { dp = rp; - DELTA(rp, ri->ri_stride, int32_t *); + DELTA(rp, ri->ri_stride, uint32_t *); if (ri->ri_hwbits) { hp = hrp; - DELTA(hrp, ri->ri_stride, int32_t *); + DELTA(hrp, ri->ri_stride, uint32_t *); } if (lmask != -1) { tmp = *dp ^ lmask; @@ -201,8 +201,9 @@ NAME(do_cursor)(struct rasops_info *ri) static void NAME(copycols)(void *cookie, int row, int src, int dst, int num) { - int tmp, lmask, rmask, height, lnum, rnum, sb, db, cnt, full; - int32_t *sp, *dp, *srp, *drp, *dhp = NULL, *hp = NULL; + int height, lnum, rnum, sb, db, cnt, full; + uint32_t tmp, lmask, rmask; + uint32_t *sp, *dp, *srp, *drp, *dhp = NULL, *hp = NULL; struct rasops_info *ri; ri = (struct rasops_info *)cookie; @@ -245,10 +246,10 @@ NAME(copycols)(void *cookie, int row, in if (db + num <= 32) { /* Destination is contained within a single word */ - srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); - drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); + srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); + drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); if (ri->ri_hwbits) - dhp = (int32_t *)(ri->ri_hwbits + row + + dhp = (uint32_t *)(ri->ri_hwbits + row + ((dst >> 3) & ~3)); sb = src & 31; @@ -257,10 +258,10 @@ NAME(copycols)(void *cookie, int row, in PUTBITS(tmp, db, num, drp); if (ri->ri_hwbits) { PUTBITS(tmp, db, num, dhp); - DELTA(dhp, ri->ri_stride, int32_t *); + DELTA(dhp, ri->ri_stride, uint32_t *); } - DELTA(srp, ri->ri_stride, int32_t *); - DELTA(drp, ri->ri_stride, int32_t *); + DELTA(srp, ri->ri_stride, uint32_t *); + DELTA(drp, ri->ri_stride, uint32_t *); } return; @@ -278,22 +279,23 @@ NAME(copycols)(void *cookie, int row, in if (src < dst && src + num > dst) { /* Copy right-to-left */ - sb = src & 31; - src = src + num; - dst = dst + num; - srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); - drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); - if (ri->ri_hwbits) - dhp = (int32_t *)(ri->ri_hwbits + row + - ((dst >> 3) & ~3)); + bool sbover; + int sboff; - src = src & 31; - rnum = 32 - lnum; - db = dst & 31; + srp = (uint32_t *)(ri->ri_bits + row + + (((src + num) >> 3) & ~3)); + drp = (uint32_t *)(ri->ri_bits + row + + (((dst + num) >> 3) & ~3)); + if (ri->ri_hwbits) + dhp = (uint32_t *)(ri->ri_hwbits + row + + (((dst + num) >> 3) & ~3)); - if ((src -= db) < 0) { + sb = src & 31; + sbover = (sb + lnum) >= 32; + sboff = (src + num) & 31; + if ((sboff -= rnum) < 0) { srp--; - src += 32; + sboff += 32; } while (height--) { @@ -301,47 +303,47 @@ NAME(copycols)(void *cookie, int row, in dp = drp; if (ri->ri_hwbits) { hp = dhp; - DELTA(dhp, ri->ri_stride, int32_t *); + DELTA(dhp, ri->ri_stride, uint32_t *); } - DELTA(srp, ri->ri_stride, int32_t *); - DELTA(drp, ri->ri_stride, int32_t *); + DELTA(srp, ri->ri_stride, uint32_t *); + DELTA(drp, ri->ri_stride, uint32_t *); - if (db) { - GETBITS(sp, src, db, tmp); - PUTBITS(tmp, 0, db, dp); + if (rnum) { + GETBITS(sp, sboff, rnum, tmp); + PUTBITS(tmp, 0, rnum, dp); if (ri->ri_hwbits) { - PUTBITS(tmp, 0, db, hp); - hp--; + PUTBITS(tmp, 0, rnum, hp); } - dp--; - sp--; } /* Now aligned to 32-bits wrt dp */ - for (cnt = full; cnt; cnt--, sp--) { - GETBITS(sp, src, 32, tmp); - *dp-- = tmp; - if (ri->ri_hwbits) - *hp-- = tmp; + for (cnt = full; cnt; cnt--) { + --dp; + --sp; + GETBITS(sp, sboff, 32, tmp); + *dp = tmp; + if (ri->ri_hwbits) { + --hp; + *hp = tmp; + } } if (lmask) { -#if 0 - if (src > sb) - sp++; -#endif + if (sbover) + --sp; + --dp; GETBITS(sp, sb, lnum, tmp); - PUTBITS(tmp, rnum, lnum, dp); + PUTBITS(tmp, db, lnum, dp); if (ri->ri_hwbits) - PUTBITS(tmp, rnum, lnum, hp); + PUTBITS(tmp, db, lnum, hp); } } } else { /* Copy left-to-right */ - srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); - drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); + srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); + drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); if (ri->ri_hwbits) - dhp = (int32_t *)(ri->ri_hwbits + row + + dhp = (uint32_t *)(ri->ri_hwbits + row + ((dst >> 3) & ~3)); db = dst & 31; @@ -351,10 +353,10 @@ NAME(copycols)(void *cookie, int row, in dp = drp; if (ri->ri_hwbits) { hp = dhp; - DELTA(dhp, ri->ri_stride, int32_t *); + DELTA(dhp, ri->ri_stride, uint32_t *); } - DELTA(srp, ri->ri_stride, int32_t *); - DELTA(drp, ri->ri_stride, int32_t *); + DELTA(srp, ri->ri_stride, uint32_t *); + DELTA(drp, ri->ri_stride, uint32_t *); if (lmask) { GETBITS(sp, sb, lnum, tmp); Index: src/sys/dev/rasops/rasops_masks.c diff -u src/sys/dev/rasops/rasops_masks.c:1.8 src/sys/dev/rasops/rasops_masks.c:1.9 --- src/sys/dev/rasops/rasops_masks.c:1.8 Mon Apr 28 20:23:57 2008 +++ src/sys/dev/rasops/rasops_masks.c Mon Dec 2 14:05:51 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops_masks.c,v 1.8 2008/04/28 20:23:57 martin Exp $ */ +/* $NetBSD: rasops_masks.c,v 1.9 2013/12/02 14:05:51 tsutsui Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,12 +30,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops_masks.c,v 1.8 2008/04/28 20:23:57 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops_masks.c,v 1.9 2013/12/02 14:05:51 tsutsui Exp $"); #include "rasops_masks.h" /* `ragged edge' bitmasks */ -const int32_t rasops_lmask[32+1] = { +const uint32_t rasops_lmask[32+1] = { MBE(0x00000000), MBE(0x7fffffff), MBE(0x3fffffff), MBE(0x1fffffff), MBE(0x0fffffff), MBE(0x07ffffff), MBE(0x03ffffff), MBE(0x01ffffff), MBE(0x00ffffff), MBE(0x007fffff), MBE(0x003fffff), MBE(0x001fffff), @@ -47,7 +47,7 @@ const int32_t rasops_lmask[32+1] = { MBE(0x00000000) }; -const int32_t rasops_rmask[32+1] = { +const uint32_t rasops_rmask[32+1] = { MBE(0x00000000), MBE(0x80000000), MBE(0xc0000000), MBE(0xe0000000), MBE(0xf0000000), MBE(0xf8000000), MBE(0xfc000000), MBE(0xfe000000), MBE(0xff000000), MBE(0xff800000), MBE(0xffc00000), MBE(0xffe00000), @@ -60,7 +60,7 @@ const int32_t rasops_rmask[32+1] = { }; /* Part bitmasks */ -const int32_t rasops_pmask[32][32] = { +const uint32_t rasops_pmask[32][32] = { { MBE(0xffffffff), MBE(0x80000000), MBE(0xc0000000), MBE(0xe0000000), MBE(0xf0000000), MBE(0xf8000000), MBE(0xfc000000), MBE(0xfe000000), MBE(0xff000000), MBE(0xff800000), MBE(0xffc00000), MBE(0xffe00000), Index: src/sys/dev/rasops/rasops_masks.h diff -u src/sys/dev/rasops/rasops_masks.h:1.7 src/sys/dev/rasops/rasops_masks.h:1.8 --- src/sys/dev/rasops/rasops_masks.h:1.7 Mon Apr 28 20:23:57 2008 +++ src/sys/dev/rasops/rasops_masks.h Mon Dec 2 14:05:51 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops_masks.h,v 1.7 2008/04/28 20:23:57 martin Exp $ */ +/* $NetBSD: rasops_masks.h,v 1.8 2013/12/02 14:05:51 tsutsui Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -46,8 +46,8 @@ */ #if BYTE_ORDER == BIG_ENDIAN -#define MBL(x,y) ((y) > 31 ? 0 : (x) >> (y)) -#define MBR(x,y) ((y) > 31 ? 0 : (x) << (y)) +#define MBL(x,y) ((y) > 31 ? 0 : (x) << (y)) +#define MBR(x,y) ((y) > 31 ? 0 : (x) >> (y)) #define MBE(x) (x) #else @@ -88,8 +88,8 @@ } while(0); /* rasops_masks.c */ -extern const int32_t rasops_lmask[32+1]; -extern const int32_t rasops_rmask[32+1]; -extern const int32_t rasops_pmask[32][32]; +extern const uint32_t rasops_lmask[32+1]; +extern const uint32_t rasops_rmask[32+1]; +extern const uint32_t rasops_pmask[32][32]; #endif /* _RASOPS_MASKS_H_ */