Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/rasops Fix 1 bpp rasops copycols() op:



details:   https://anonhg.NetBSD.org/src/rev/6c6c5579e0fd
branches:  trunk
changeset: 325061:6c6c5579e0fd
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Mon Dec 02 14:05:51 2013 +0000

description:
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.

diffstat:

 sys/dev/rasops/README          |    3 +-
 sys/dev/rasops/rasops_bitops.h |  132 ++++++++++++++++++++--------------------
 sys/dev/rasops/rasops_masks.c  |   10 +-
 sys/dev/rasops/rasops_masks.h  |   12 +-
 4 files changed, 79 insertions(+), 78 deletions(-)

diffs (truncated from 367 to 300 lines):

diff -r 3ec51048cafb -r 6c6c5579e0fd sys/dev/rasops/README
--- a/sys/dev/rasops/README     Mon Dec 02 13:45:40 2013 +0000
+++ b/sys/dev/rasops/README     Mon Dec 02 14:05:51 2013 +0000
@@ -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 @@
 
 - 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
diff -r 3ec51048cafb -r 6c6c5579e0fd sys/dev/rasops/rasops_bitops.h
--- a/sys/dev/rasops/rasops_bitops.h    Mon Dec 02 13:45:40 2013 +0000
+++ b/sys/dev/rasops/rasops_bitops.h    Mon Dec 02 14:05:51 2013 +0000
@@ -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 @@
        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 @@
 
                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 @@
 
                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 @@
 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 @@
 
                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 @@
 
                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 @@
 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 @@
 
        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 @@
                        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 @@
 
        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));
+               bool sbover;
+               int sboff;
+
+               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 = (int32_t *)(ri->ri_hwbits + row +
-                           ((dst >> 3) & ~3));
+                       dhp = (uint32_t *)(ri->ri_hwbits + row +
+                           (((dst + num) >> 3) & ~3));
 
-               src = src & 31;
-               rnum = 32 - lnum;
-               db = dst & 31;
-
-               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 @@
                        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 @@
                        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);
diff -r 3ec51048cafb -r 6c6c5579e0fd sys/dev/rasops/rasops_masks.c
--- a/sys/dev/rasops/rasops_masks.c     Mon Dec 02 13:45:40 2013 +0000
+++ b/sys/dev/rasops/rasops_masks.c     Mon Dec 02 14:05:51 2013 +0000
@@ -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 $ */
 



Home | Main Index | Thread Index | Old Index