1 /* Copyright (C) 1995, 1996, 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: gsbittab.h,v 1.2.6.1.2.1 2003/01/17 00:49:02 giles Exp $ */ 20 /* Interface to tables for bit operations */ 21 22 #ifndef gsbittab_INCLUDED 23 # define gsbittab_INCLUDED 24 25 /* 26 * Generate tables for transforming 2, 4, 6, or 8 bits. 27 */ 28 #define btab2_(v0,v2,v1)\ 29 v0,v1+v0,v2+v0,v2+v1+v0 30 #define bit_table_2(v0,v2,v1) btab2_(v0,v2,v1) 31 #define btab4_(v0,v8,v4,v2,v1)\ 32 btab2_(v0,v2,v1), btab2_(v4+v0,v2,v1),\ 33 btab2_(v8+v0,v2,v1), btab2_(v8+v4+v0,v2,v1) 34 #define bit_table_4(v0,v8,v4,v2,v1) btab4_(v0,v8,v4,v2,v1) 35 #define btab6_(v0,v20,v10,v8,v4,v2,v1)\ 36 btab4_(v0,v8,v4,v2,v1), btab4_(v10+v0,v8,v4,v2,v1),\ 37 btab4_(v20+v0,v8,v4,v2,v1), btab4_(v20+v10+v0,v8,v4,v2,v1) 38 #define bit_table_6(v0,v20,v10,v8,v4,v2,v1) btab6_(v0,v20,v10,v8,v4,v2,v1) 39 #define bit_table_8(v0,v80,v40,v20,v10,v8,v4,v2,v1)\ 40 btab6_(v0,v20,v10,v8,v4,v2,v1), btab6_(v40+v0,v20,v10,v8,v4,v2,v1),\ 41 btab6_(v80+v0,v20,v10,v8,v4,v2,v1), btab6_(v80+v40+v0,v20,v10,v8,v4,v2,v1) 42 43 /* 44 * byte_reverse_bits[B] = the byte B with the order of bits reversed. 45 */ 46 extern const byte byte_reverse_bits[256]; 47 48 /* 49 * byte_right_mask[N] = a byte with N trailing 1s, 0 <= N <= 8. 50 */ 51 extern const byte byte_right_mask[9]; 52 53 /* 54 * byte_count_bits[B] = the number of 1-bits in a byte with value B. 55 */ 56 extern const byte byte_count_bits[256]; 57 58 /* 59 * byte_bit_run_length_N[B], for 0 <= N <= 7, gives the length of the 60 * run of 1-bits starting at bit N in a byte with value B, 61 * numbering the bits in the byte as 01234567. If the run includes 62 * the low-order bit (i.e., might be continued into a following byte), 63 * the run length is increased by 8. 64 */ 65 extern const byte 66 byte_bit_run_length_0[256], byte_bit_run_length_1[256], 67 byte_bit_run_length_2[256], byte_bit_run_length_3[256], 68 byte_bit_run_length_4[256], byte_bit_run_length_5[256], 69 byte_bit_run_length_6[256], byte_bit_run_length_7[256]; 70 71 /* 72 * byte_bit_run_length[N] points to byte_bit_run_length_N. 73 * byte_bit_run_length_neg[N] = byte_bit_run_length[-N & 7]. 74 */ 75 extern const byte *const byte_bit_run_length[8]; 76 extern const byte *const byte_bit_run_length_neg[8]; 77 78 /* 79 * byte_acegbdfh_to_abcdefgh[acegbdfh] = abcdefgh, where the letters 80 * denote the individual bits of the byte. 81 */ 82 extern const byte byte_acegbdfh_to_abcdefgh[256]; 83 84 #endif /* gsbittab_INCLUDED */ 85