1 /* Copyright (C) 1997, 1998 artofcode LLC. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify it 4 under the terms of the GNU General Public License as published by the 5 Free Software Foundation; either version 2 of the License, or (at your 6 option) any later version. 7 8 This program is distributed in the hope that it will be useful, but 9 WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along 14 with this program; if not, write to the Free Software Foundation, Inc., 15 59 Temple Place, Suite 330, Boston, MA, 02111-1307. 16 17 */ 18 19 /*$Id: gxbitops.h,v 1.2.6.1.2.1 2003/01/17 00:49:03 giles Exp $ */ 20 /* Internal definitions for bitmap operations */ 21 22 #ifndef gxbitops_INCLUDED 23 # define gxbitops_INCLUDED 24 25 #include "gsbitops.h" 26 27 /* 28 * Macros for processing bitmaps in the largest possible chunks. 29 * Bits within a byte are always stored big-endian; 30 * bytes are likewise stored in left-to-right order, i.e., big-endian. 31 * Note that this is the format used for the source of copy_mono. 32 * It used to be the case that bytes were stored in the natural 33 * platform order, and the client had force them into big-endian order 34 * by calling gdev_mem_ensure_byte_order, but this no longer necessary. 35 * 36 * Note that we use type uint for register variables holding a chunk: 37 * for this reason, the chunk size cannot be larger than uint. 38 */ 39 /* Generic macros for chunk accessing. */ 40 #define cbytes(ct) size_of(ct) /* sizeof may be unsigned */ 41 # define chunk_bytes cbytes(chunk) 42 /* The clog2_bytes macro assumes that ints are 2, 4, or 8 bytes in size. */ 43 #define clog2_bytes(ct) (size_of(ct) == 8 ? 3 : size_of(ct)>>1) 44 # define chunk_log2_bytes clog2_bytes(chunk) 45 #define cbits(ct) (size_of(ct)*8) /* sizeof may be unsigned */ 46 # define chunk_bits cbits(chunk) 47 #define clog2_bits(ct) (clog2_bytes(ct)+3) 48 # define chunk_log2_bits clog2_bits(chunk) 49 #define cbit_mask(ct) (cbits(ct)-1) 50 # define chunk_bit_mask cbit_mask(chunk) 51 #define calign_bytes(ct)\ 52 (sizeof(ct) == 1 ? 1:\ 53 sizeof(ct) == sizeof(short) ? arch_align_short_mod :\ 54 sizeof(ct) == sizeof(int) ? arch_align_int_mod : arch_align_long_mod) 55 # define chunk_align_bytes calign_bytes(chunk) 56 #define calign_bit_mask(ct) (calign_bytes(ct)*8-1) 57 # define chunk_align_bit_mask calign_bit_mask(chunk) 58 /* 59 * The obvious definition for cmask is: 60 * #define cmask(ct) ((ct)~(ct)0) 61 * but this doesn't work on the VAX/VMS compiler, which fails to truncate 62 * the value to 16 bits when ct is ushort. 63 * Instead, we have to generate the mask with no extra 1-bits. 64 * We can't do this in the obvious way: 65 * #define cmask(ct) ((1 << (size_of(ct) * 8)) - 1) 66 * because some compilers won't allow a shift of the full type size. 67 * Instead, we have to do something really awkward: 68 */ 69 #define cmask(ct) ((ct) (((((ct)1 << (size_of(ct)*8-2)) - 1) << 2) + 3)) 70 # define chunk_all_bits cmask(chunk) 71 /* 72 * The obvious definition for chi_bits is: 73 * #define chi_bits(ct,n) (cmask(ct)-(cmask(ct)>>(n))) 74 * but this doesn't work on the DEC/MIPS compilers. 75 * Instead, we have to restrict chi_bits to only working for values of n 76 * between 0 and cbits(ct)-1, and use 77 */ 78 #define chi_bits(ct,n) (ct)(~(ct)1 << (cbits(ct)-1 - (n))) 79 # define chunk_hi_bits(n) chi_bits(chunk,n) 80 81 /* Define whether this is a machine where chunks are long, */ 82 /* but the machine can't shift a long by its full width. */ 83 #define arch_cant_shift_full_chunk\ 84 (arch_is_big_endian && !arch_ints_are_short && !arch_can_shift_full_long) 85 86 /* Pointer arithmetic macros. */ 87 #define inc_ptr(ptr,delta)\ 88 (ptr = (void *)((byte *)ptr + (delta))) 89 90 /* Define macros for setting up left- and right-end masks. */ 91 /* These are used for monobit operations, and for filling */ 92 /* with 2- and 4-bit-per-pixel patterns. */ 93 94 /* 95 * Define the chunk size for monobit copying operations. 96 */ 97 #if arch_is_big_endian 98 # define mono_copy_chunk uint 99 # define set_mono_right_mask(var, w)\ 100 (var = ((w) == chunk_bits ? chunk_all_bits : chunk_hi_bits(w))) 101 /* 102 * We have to split the following statement because of a bug in the Xenix C 103 * compiler (it produces a signed rather than an unsigned shift if we don't 104 * split). 105 */ 106 # define set_mono_thin_mask(var, w, bit)\ 107 set_mono_right_mask(var, w), var >>= (bit) 108 /* 109 * We have to split the following statement in two because of a bug 110 * in the DEC VAX/VMS C compiler. 111 */ 112 # define set_mono_left_mask(var, bit)\ 113 (var = chunk_all_bits, var >>= (bit)) 114 #else 115 # define mono_copy_chunk bits16 116 extern const bits16 mono_copy_masks[17]; 117 118 # if mono_fill_chunk_bytes == 2 119 # define mono_fill_masks mono_copy_masks 120 # else 121 extern const bits32 mono_fill_masks[33]; 122 123 # endif 124 /* 125 * We define mono_masks as either mono_fill_masks or 126 * mono_copy_masks before using the following macros. 127 */ 128 # define set_mono_left_mask(var, bit)\ 129 (var = mono_masks[bit]) 130 # define set_mono_thin_mask(var, w, bit)\ 131 (var = ~mono_masks[(w) + (bit)] & mono_masks[bit]) 132 # define set_mono_right_mask(var, ebit)\ 133 (var = ~mono_masks[ebit]) 134 #endif 135 136 #endif /* gxbitops_INCLUDED */ 137