1 1.1 tsutsui /* $NetBSD: maskbits.h,v 1.1 2023/02/11 05:59:39 tsutsui Exp $ */ 2 1.1 tsutsui /* $OpenBSD: maskbits.h,v 1.1 2006/08/05 10:00:30 miod Exp $ */ 3 1.1 tsutsui 4 1.1 tsutsui /*- 5 1.1 tsutsui * Copyright (c) 1994 6 1.1 tsutsui * The Regents of the University of California. All rights reserved. 7 1.1 tsutsui * 8 1.1 tsutsui * Redistribution and use in source and binary forms, with or without 9 1.1 tsutsui * modification, are permitted provided that the following conditions 10 1.1 tsutsui * are met: 11 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright 12 1.1 tsutsui * notice, this list of conditions and the following disclaimer. 13 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright 14 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the 15 1.1 tsutsui * documentation and/or other materials provided with the distribution. 16 1.1 tsutsui * 3. Neither the name of the University nor the names of its contributors 17 1.1 tsutsui * may be used to endorse or promote products derived from this software 18 1.1 tsutsui * without specific prior written permission. 19 1.1 tsutsui * 20 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 1.1 tsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 1.1 tsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 1.1 tsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 1.1 tsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 1.1 tsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 1.1 tsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 1.1 tsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 1.1 tsutsui * SUCH DAMAGE. 31 1.1 tsutsui * 32 1.1 tsutsui * @(#)maskbits.h 8.2 (Berkeley) 3/21/94 33 1.1 tsutsui */ 34 1.1 tsutsui 35 1.1 tsutsui /* 36 1.1 tsutsui * Derived from X11R4 37 1.1 tsutsui */ 38 1.1 tsutsui 39 1.1 tsutsui #define FASTGETBITS(psrc,x,w,dst) \ 40 1.1 tsutsui __asm__ ("extzv %1,%2,%3,%0" \ 41 1.1 tsutsui : "=g" (dst) \ 42 1.1 tsutsui : "g" (x), "g" (w), "m" (*(char *)(psrc))) 43 1.1 tsutsui 44 1.1 tsutsui #define FASTPUTBITS(src, x, w, pdst) \ 45 1.1 tsutsui __asm__ ("insv %3,%1,%2,%0" \ 46 1.1 tsutsui : "=m" (*(char *)(pdst)) \ 47 1.1 tsutsui : "g" (x), "g" (w), "g" (src)) 48 1.1 tsutsui 49 1.1 tsutsui #define RR_CLEAR 0x00 50 1.1 tsutsui #define RR_SET 0x01 51 1.1 tsutsui #define RR_COPY 0x02 52 1.1 tsutsui 53 1.1 tsutsui #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \ 54 1.1 tsutsui do { \ 55 1.1 tsutsui unsigned int _tmpdst; \ 56 1.1 tsutsui switch (rop) { \ 57 1.1 tsutsui case RR_CLEAR: \ 58 1.1 tsutsui _tmpdst = 0; \ 59 1.1 tsutsui break; \ 60 1.1 tsutsui case RR_SET: \ 61 1.1 tsutsui _tmpdst = ~0; \ 62 1.1 tsutsui break; \ 63 1.1 tsutsui default: \ 64 1.1 tsutsui FASTGETBITS(psrc, srcbit, width, _tmpdst); \ 65 1.1 tsutsui break; \ 66 1.1 tsutsui } \ 67 1.1 tsutsui FASTPUTBITS(_tmpdst, dstbit, width, pdst); \ 68 1.1 tsutsui } while (0) 69 1.1 tsutsui 70 1.1 tsutsui #define getunalignedword(psrc, x, dst) \ 71 1.1 tsutsui do { \ 72 1.1 tsutsui int _tmp; \ 73 1.1 tsutsui FASTGETBITS(psrc, x, 32, _tmp); \ 74 1.1 tsutsui dst = _tmp; \ 75 1.1 tsutsui } while (0) 76