├── Makefile ├── README ├── coding_policy.c ├── coding_policy.h ├── coding_policy_helper.h ├── howtouse.c ├── pack.c ├── pack.h ├── pfordelta.c ├── pfordelta.h ├── s16.c ├── s16.h ├── unpack.c └── unpack.h /Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-Wall -O9 3 | LDFLAGS= 4 | SOURCES=howtouse.c pack.c pfordelta.c s16.c unpack.c coding_policy.c 5 | OBJECTS=$(SOURCES:.c=.o) 6 | EXECUTABLE=howtouse 7 | 8 | debug: CFLAGS+=-g 9 | debug: LDFLAGS+=-g 10 | 11 | all: $(SOURCES) $(EXECUTABLE) 12 | 13 | $(EXECUTABLE): $(OBJECTS) 14 | $(CC) $(LDFLAGS) $(OBJECTS) -o $@ 15 | 16 | .cpp.o: 17 | $(CC) $(CFLAGS) $< -o $@ 18 | 19 | clean: 20 | rm $(OBJECTS) $(EXECUTABLE) 21 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This repository contains algorithms to compress sorted integers arrays in C, 2 | forked from Poly IR Toolkit http://code.google.com/p/poly-ir-toolkit/ 3 | 4 | The algorithms already coded are: 5 | - Simple16 6 | - PForDelta 7 | 8 | More info on the header of each .c file. 9 | 10 | Note: This code is not threads safe. 11 | -------------------------------------------------------------------------------- /coding_policy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include"pfordelta.h" 3 | #include"coding_policy.h" 4 | 5 | extern int block_size; 6 | 7 | // The 'input' array size should be at least an upper multiple of 'block_size_'. 8 | int compress_pfordelta(unsigned int *input, unsigned int *output, int num_input_elements, int block_size_) { 9 | int num_whole_blocks = num_input_elements / block_size_; 10 | int encoded_offset = 0; 11 | int unencoded_offset = 0; 12 | 13 | int left_to_encode; 14 | int pad_until; 15 | int i; 16 | 17 | block_size = block_size_; 18 | 19 | while (num_whole_blocks-- > 0) { 20 | encoded_offset += pfor_compress(input + unencoded_offset, output + encoded_offset, block_size_); 21 | unencoded_offset += block_size_; 22 | } 23 | 24 | left_to_encode = num_input_elements % block_size_; 25 | if (left_to_encode != 0) { 26 | // Encode leftover portion with a blockwise coder, and pad it to the blocksize. 27 | // Assumption here is that the 'input' array size is at least an upper multiple of 'block_size_'. 28 | pad_until = block_size_ * ((num_input_elements / block_size_) + 1); 29 | 30 | for (i = num_input_elements; i < pad_until; ++i) { 31 | input[i] = 0; 32 | } 33 | encoded_offset += pfor_compress(input + unencoded_offset, output + encoded_offset, block_size_); 34 | unencoded_offset += block_size_; 35 | } 36 | 37 | return encoded_offset; 38 | } 39 | 40 | 41 | // The 'output' array size should be at least an upper multiple of 'block_size_'. 42 | int decompress_pfordelta(unsigned int* input, unsigned int* output, int num_input_elements, int _block_size) { 43 | int num_whole_blocks = num_input_elements / _block_size; 44 | int encoded_offset = 0; 45 | int unencoded_offset = 0; 46 | int left_to_encode; 47 | 48 | block_size = _block_size; 49 | 50 | //printf("num_input_elements: %d\n", num_input_elements); 51 | while (num_whole_blocks-- > 0) { 52 | encoded_offset += pfor_decompress(input + encoded_offset, output + unencoded_offset, _block_size); 53 | unencoded_offset += _block_size; 54 | } 55 | 56 | left_to_encode = num_input_elements % _block_size; 57 | if (left_to_encode != 0) { 58 | // Decode leftover portion with a blockwise coder, since it was padded to the blocksize. 59 | // Assumption here is that the 'output' array size is at least an upper multiple of 'block_size_'. 60 | encoded_offset += pfor_decompress(input + encoded_offset, output + unencoded_offset, _block_size); 61 | unencoded_offset += _block_size; 62 | } 63 | 64 | return encoded_offset; 65 | } 66 | -------------------------------------------------------------------------------- /coding_policy.h: -------------------------------------------------------------------------------- 1 | #ifndef CODING_POLICY_H_ 2 | #define CODING_POLICY_H_ 3 | 4 | // The 'input' array size should be at least an upper multiple of 'BLOCK_SIZE'. 5 | int compress_pfordelta(unsigned int *input, unsigned int *output, int num_input_elements, int _block_size); 6 | 7 | // The 'output' array size should be at least an upper multiple of 'block_size_'. 8 | int decompress_pfordelta(unsigned int* input, unsigned int* output, int num_input_elements, int _block_size); 9 | 10 | 11 | #endif /* CODING_POLICY_H_ */ 12 | -------------------------------------------------------------------------------- /coding_policy_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010, Roman Khmelichek 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // 6 | // 1. Redistributions of source code must retain the above copyright notice, 7 | // this list of conditions and the following disclaimer. 8 | // 2. Redistributions in binary form must reproduce the above copyright notice, 9 | // this list of conditions and the following disclaimer in the documentation 10 | // and/or other materials provided with the distribution. 11 | // 3. Neither the name of Roman Khmelichek nor the names of its contributors 12 | // may be used to endorse or promote products derived from this software 13 | // without specific prior written permission. 14 | // 15 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 16 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | //============================================================================================================================================================== 27 | // Author(s): Roman Khmelichek 28 | // 29 | // Some of the functions here are macros because many times we need to define local arrays on the stack for performance reasons, and a function is not 30 | // considered an integer compile-time constant (for the purposes of defining the array size). 31 | // These macros are for determining loose upperbounds to satisfy all the various coding policies. 32 | //============================================================================================================================================================== 33 | 34 | #ifndef CODING_POLICY_HELPER_H_ 35 | #define CODING_POLICY_HELPER_H_ 36 | 37 | // Determines the size of the input buffer that will be compressed. 38 | // It needs to be a multiple of the block size for when we use blockwise codings, because we need to pad the input buffer with 0s until the block size. 39 | // If the block size is 0, we have a non-blockwise coder, and don't need an upperbound. 40 | #define UncompressedInBufferUpperbound(buffer_size, block_size) ((((block_size) == 0) || ((buffer_size) % (block_size) == 0)) ? (buffer_size) : ((((buffer_size) / (block_size)) + 1) * (block_size))) 41 | 42 | // Determines size of the output buffer for decompressing to. 43 | // Normally, this wouldn't be necessary, since if you know the uncompressed length, you wouldn't need to do an upperbound. 44 | // However, S9 and S16 codings have a quirk that requires the output buffer array (to which we decompress) to have at least 28 empty slots; 45 | // this is because there is a case where a word will have a max of 28 integers compressed within, and we will access the output buffer 46 | // for all the 28 integers, even if some of those 28 integers are garbage which we haven't really compressed (but this was the case used to encode them). 47 | // So we need to round the number of compressed integers to a multiple of 28 and make sure there is at least 28 extra space at the end of the array 48 | // to ensure there is ample room for decompression. Here, we just use 32 instead of 28 for convenience, though it produces a slightly larger upperbound. 49 | #define UncompressedOutBufferUpperbound(buffer_size) ((((buffer_size) >> 5) + 2) << 5) 50 | 51 | // Determines size of output buffer for compression. 52 | // Here we just double it, but it could really be a tighter bound. 53 | #define CompressedOutBufferUpperbound(buffer_size) ((buffer_size) << 1) 54 | 55 | #endif /* CODING_POLICY_HELPER_H_ */ 56 | -------------------------------------------------------------------------------- /howtouse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "pfordelta.h" 6 | #include "s16.h" 7 | #include "coding_policy_helper.h" 8 | #include "coding_policy.h" 9 | 10 | int _block_size = 128; 11 | 12 | // Print unsigned integer in binary format with spaces separating each byte. 13 | void print_binary(unsigned int num) { 14 | int arr[32]; 15 | int i = 0; 16 | while (i++ < 32 || num / 2 != 0) { 17 | arr[i - 1] = num % 2; 18 | num /= 2; 19 | } 20 | 21 | for (i = 31; i >= 0; i--) { 22 | printf("%d", arr[i]); 23 | if (i % 8 == 0) 24 | printf(" "); 25 | } 26 | } 27 | 28 | void test_compression() { 29 | int num_blocks = 2; 30 | int size = 130; 31 | unsigned int ay[130] = {1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0}; 32 | unsigned int *array=NULL; 33 | unsigned int *decompressor_out=NULL; 34 | unsigned int *compressor_out=NULL; 35 | 36 | int a, b, i; 37 | 38 | array = malloc(sizeof(unsigned int)*_block_size*num_blocks); 39 | memcpy(array, ay, size); 40 | printf("size array: %d\n", sizeof(ay)/sizeof(unsigned int)); 41 | printf("size compressor out: %d\n", CompressedOutBufferUpperbound(_block_size) * num_blocks); 42 | printf("size decompressor out: %d\n", UncompressedOutBufferUpperbound(_block_size * num_blocks)); 43 | 44 | compressor_out = malloc( sizeof(unsigned int) * CompressedOutBufferUpperbound(_block_size) * num_blocks); 45 | a = compress_pfordelta(array, compressor_out, size, _block_size); 46 | for(i = 0; i < a; i++) { 47 | //print_binary(compressor_out[i]); 48 | } 49 | printf("space used by pfordelta: %d\n", a); 50 | free(compressor_out); 51 | free(array); 52 | return; 53 | 54 | *decompressor_out = malloc( sizeof(unsigned int) * UncompressedOutBufferUpperbound(_block_size * num_blocks)); 55 | printf("========== decompressing ==============\n"); 56 | b = decompress_pfordelta(compressor_out, decompressor_out, size, _block_size); 57 | printf("printing\n"); 58 | for(i = 0; i < size; i++) { 59 | // printf("%u -> %u\n", array[i], decompressor_out[i]); 60 | } 61 | 62 | printf("a: %d\nb: %d\n", a, b); 63 | } 64 | 65 | 66 | void test_pfordelta() { 67 | //unsigned int input[] = {2322231,2,3,4,5,6,7,8,9,10}; 68 | unsigned int input[128] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,10,10,10}; 69 | unsigned int *coded; 70 | unsigned int *output; 71 | 72 | int size = 128; 73 | int newsize; 74 | int finalsize; 75 | int i; 76 | 77 | coded = (unsigned int *) malloc( size * sizeof(unsigned int) ); 78 | output = (unsigned int *) malloc( size * sizeof(unsigned int) ); 79 | //printf("coded = %X\n", coded); 80 | //printf("output = %X\n", output); 81 | newsize = compress_pfordelta(input, coded, size, 32); 82 | finalsize = decompress_pfordelta(coded, output, size, 32); 83 | 84 | printf("Normal size: %d\n", size); 85 | printf("Compress size: %d\n", newsize); 86 | printf("Consumed size: %d\n", finalsize); 87 | for(i = 0; i < size; i++) { 88 | printf("%u -> %X -> %u\n", input[i], coded[i], output[i]); 89 | } 90 | } 91 | 92 | void test_s16() { 93 | unsigned int input[] = {2322231,2,3,4,5,6,7,8,9,10}; 94 | unsigned int *coded; 95 | unsigned int *output; 96 | 97 | int size = 10; 98 | int newsize; 99 | int finalsize; 100 | int i; 101 | 102 | coded = (unsigned int *) malloc( size * sizeof(unsigned int) ); 103 | output = (unsigned int *) malloc( size * sizeof(unsigned int) ); 104 | //printf("coded = %X\n", coded); 105 | //printf("output = %X\n", output); 106 | newsize = s16_compress(input, coded, size); 107 | finalsize = s16_decompress(coded, output, size); 108 | 109 | printf("Normal size: %d\n", size); 110 | printf("Compress size: %d\n", newsize); 111 | printf("Consumed size: %d\n", finalsize); 112 | for(i = 0; i < size; i++) { 113 | printf("%u -> %X -> %u\n", input[i], coded[i], output[i]); 114 | } 115 | } 116 | 117 | // Example of usage 118 | int main(int argc, char *argv[]) { 119 | //test_compression(); 120 | //test_pfordelta(); 121 | //test_s16(); 122 | int i; 123 | int a; 124 | unsigned int p[128]; 125 | unsigned int t[128]; 126 | p[0] = 2; 127 | p[1] = 2; 128 | p[2] = 3; 129 | p[3] = 0xffff; 130 | a = compress_pfordelta(p,t,4,32); 131 | 132 | printf("new size: %d\n",a); 133 | for (i = 0; i < a; i++ ) { print_binary(t[i]); printf("\n"); }; 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /pack.c: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | // 42 | 43 | #include "pack.h" 44 | 45 | void pack(unsigned int* v, unsigned int b, unsigned int n, unsigned int* w) { 46 | unsigned int i; 47 | int bp, wp, s; 48 | 49 | for (bp = 0, i = 0; i < n; i++, bp += b) { 50 | wp = bp >> 5; 51 | s = 32 - b - (bp & 31); 52 | if (s >= 0) 53 | w[wp] |= (v[i] << s); 54 | else { 55 | s = -s; 56 | w[wp] |= (v[i] >> s); 57 | w[wp + 1] = (v[i] << (32 - s)); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pack.h: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | 42 | //// 43 | // It includes some basic bitwise operations. 44 | 45 | #ifndef PACK_H_ 46 | #define PACK_H_ 47 | 48 | void pack(unsigned int* v, unsigned int b, unsigned int n, unsigned int* w); 49 | 50 | #endif /* PACK_H_ */ 51 | -------------------------------------------------------------------------------- /pfordelta.c: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | // 42 | 43 | //// 44 | // This is an implementation of PForDelta algorithm for sorted integer arrays. 45 | // The PForDelta coding method is fast but compression efficiency is not as good as Rice 46 | // coding. It is a blockwise coding, so you need to first set the block size to 47 | // either 32, 64, 128, or 256. The default block size is 128. If the input 48 | // buffer to the Compression() function is greater in size than the block size, 49 | // any integers past the block size will be discarded. 50 | // The meta data is stored as an uncompressed integer written at the beginning 51 | // of the buffer; it includes the number of bits used per integer, the block 52 | // size, and the number of integers coded without exceptions. 53 | // 54 | // 1. Original algorithm from: 55 | // http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.101.3316 and 56 | // http://dx.doi.org/10.1109/ICDE.2006.150 57 | // 58 | // 2. Optimizacion from: 59 | // http://www2008.org/papers/pdf/p387-zhangA.pdf 60 | // 61 | // Alternative implementations: 62 | // * C++ http://code.google.com/p/poly-ir-toolkit/source/browse/trunk/src/compression_toolkit/pfor_coding.cc 63 | // * Java https://github.com/hyan/kamikaze/blob/master/src/main/java/com/kamikaze/pfordelta/PForDelta.java 64 | // 65 | // This code is based on an implementation in C++ of the Poly-IR-Toolkit. 66 | // It's available at http://code.google.com/p/poly-ir-toolkit/source/browse/trunk/src/compression_toolkit/pfor_coding.cc 67 | // 68 | 69 | #include 70 | #include 71 | 72 | #include "pfordelta.h" 73 | #include "pack.h" //for pack function 74 | #include "unpack.h" 75 | 76 | extern pf unpack[17]; //array to the unpack functions defined in unpack.h 77 | 78 | // from pfor_coding.h 79 | int b; // b size 80 | int unpack_count; // 81 | int t; // code for exception size in bits 82 | int start; // first exception 83 | 84 | int block_size = 128; // can be 32, 64, 128, 256 85 | // depende del tamaño del size <64, <128, <256 86 | 87 | //All possible values of b in the PForDelta algorithm 88 | int pfor_cnum[17] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,16,20,32}; 89 | 90 | float FRAC = 0.1; // percent of exceptions in block_size 91 | 92 | // 93 | // Compress an integer array using PForDelta 94 | // Parameters: 95 | // input pointer to the array of integers to compress 96 | // output pointer to the array of compressed integers 97 | // size (not used) 98 | // Returns: 99 | // the number of 32-bits words used to compress the input 100 | int pfor_compress(unsigned int *input, unsigned int *output, int size) { 101 | int flag = -1; // ? 102 | unsigned int* w; 103 | int k; // ? 104 | for (k = 0; flag < 0; k++) { 105 | w = output + 1; 106 | flag = pfor_encode(&w, input, k); 107 | } 108 | 109 | *output = flag; 110 | return w - output; 111 | } 112 | 113 | // w: output 114 | // p: input 115 | // j: ? 116 | int pfor_encode(unsigned int** w, unsigned int* p, int num) { 117 | // bb bit size of exceptions 118 | // t code for bit size exceptions 119 | // i index to retrieve all numbers in block size 120 | // l index for last exception 121 | // n index for exceptions 122 | // s 123 | int i, l, n, bb, t, s; 124 | unsigned int m; // largest number in sequence 125 | int b = pfor_cnum[num + 1]; // the b value in pfordelta :) 126 | int start; // first exception ;) 127 | 128 | unsigned int out[block_size]; // array for non-exceptions 129 | unsigned int ex[block_size]; // array for exceptions 130 | 131 | //printf("unsing b = %d bits\n",b); 132 | 133 | // All numbers in 32bit code, worst case 134 | if (b == 32) { 135 | for (i = 0; i < block_size; i++) { 136 | (*w)[i] = p[i]; 137 | } 138 | *w += block_size; 139 | return ((num << 12) + (2 << 10) + block_size); 140 | } 141 | 142 | // Find the largest number we're encoding. 143 | for (m = 0, i = 0; i < block_size; i++) { 144 | if (p[i] > m) 145 | m = p[i]; 146 | } 147 | 148 | // Setting bit size for exceptions 8, 16 or 32 bits 149 | if (m < 256) { 150 | bb = 8; 151 | t = 0; 152 | } else if (m < 65536) { 153 | bb = 16; 154 | t = 1; 155 | } else { 156 | bb = 32; 157 | t = 2; 158 | } 159 | 160 | //printf("using %d bits for exceptions\n",bb); 161 | 162 | // Selecting exceptions and non-exceptions 163 | for (start = 0, n = 0, l = -1, i = 0; i < block_size; i++) { 164 | if ((p[i] >= (unsigned) (1 << b)) // p[i] fits in b bits? 165 | || ((l >= 0) && (i - l == (1 << b))) // the distance between this exception 166 | ) { // and the last exception fits in b bits 167 | if (l < 0) 168 | start = i; 169 | else 170 | out[l] = i - l - 1; 171 | 172 | ex[n++] = p[i]; 173 | l = i; 174 | } else { 175 | out[i] = p[i]; 176 | } 177 | } 178 | 179 | if (l >= 0) 180 | out[l] = (1 << b) - 1; 181 | else 182 | start = block_size; 183 | 184 | if ( (double) (n) <= FRAC * (double) (block_size)) { 185 | // non-exceptions in b bits 186 | 187 | // s*bytes is the size of the b-bits words non-exception 188 | s = ((b * block_size) >> 5); 189 | for (i = 0; i < s; i++) { 190 | (*w)[i] = 0; 191 | } 192 | pack(out, b, block_size, *w); 193 | *w += s; 194 | 195 | // exceptions in bb bits 196 | // size*4bytes of the excepcion array 197 | s = ((bb * n) >> 5) + ((((bb * n) & 31) > 0) ? 1 : 0); 198 | for (i = 0; i < s; i++) { 199 | (*w)[i] = 0; 200 | } 201 | pack(ex, bb, n, *w); 202 | *w += s; 203 | return ((num << 12) + (t << 10) + start); // this is the header!!! 204 | } 205 | 206 | return -1; 207 | } 208 | 209 | // 210 | // Decompress an integer array using PForDelta 211 | // Parameters: 212 | // input pointer to the array of compressed integers to decompress 213 | // output pointer to the array of integers 214 | // size (not used) 215 | // Returns: 216 | // the number of 32-bits consumed in input 217 | // 218 | int pfor_decompress(unsigned int* input, unsigned int* output, int size) { 219 | unsigned int* tmp = input; 220 | int flag = *tmp; 221 | 222 | b = pfor_cnum[((flag >> 12) & 15) + 1]; 223 | unpack_count = ((flag >> 12) & 15) + 1; 224 | t = (flag >> 10) & 3; 225 | start = flag & 1023; 226 | 227 | tmp++; 228 | tmp = pfor_decode(output, tmp, flag); 229 | return tmp - input; 230 | } 231 | 232 | unsigned* pfor_decode(unsigned int* _p, unsigned int* _w, int flag) { 233 | int i, s; 234 | unsigned int x; 235 | 236 | // Esta es una llamada a un arreglo de funciones de unpack. 237 | // La idea es ahorrarse un if o switch-case por cada una de 238 | // las funciones que dependenden de unpack_count. 239 | // La definición de arreglo unpack[] está en "coding.h" 240 | // El código equivalente con switch-case sería: 241 | // switch(unpack_count) { */ 242 | // case 0: unpack0(_p, _w, block_size); break; 243 | // case 1: unpack1(_p, _w, block_size); break; 244 | // ... 245 | // case n: unpack...; break; } 246 | (unpack[unpack_count])(_p, _w, block_size); 247 | 248 | _w += ((b * block_size) >> 5); 249 | 250 | switch (t) { 251 | case 0: 252 | for (s = start, i = 0; s < block_size; i++) { 253 | x = _p[s] + 1; 254 | _p[s] = (_w[i >> 2] >> (24 - ((i & 3) << 3))) & 255; 255 | s += x; 256 | } 257 | _w += (i >> 2); 258 | 259 | if ((i & 3) > 0) 260 | _w++; 261 | break; 262 | 263 | case 1: 264 | for (s = start, i = 0; s < block_size; i++) { 265 | x = _p[s] + 1; 266 | _p[s] = (_w[i >> 1] >> (16 - ((i & 1) << 4))) & 65535; 267 | s += x; 268 | } 269 | _w += (i >> 1); 270 | if ((i & 1) > 0) 271 | _w++; 272 | break; 273 | 274 | case 2: 275 | for (s = start, i = 0; s < block_size; i++) { 276 | x = _p[s] + 1; 277 | _p[s] = _w[i]; 278 | s += x; 279 | } 280 | _w += i; 281 | break; 282 | } 283 | return _w; 284 | } 285 | 286 | 287 | 288 | -------------------------------------------------------------------------------- /pfordelta.h: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | // 42 | 43 | #ifndef PFORDELTA_H_ 44 | #define PFORDELTA_H_ 45 | 46 | int pfor_compress(unsigned int *input, unsigned int *output, int size); 47 | int pfor_encode(unsigned int** w, unsigned int* p, int num); 48 | int pfor_decompress(unsigned int* input, unsigned int* output, int size); 49 | unsigned* pfor_decode(unsigned int* _p, unsigned int* _w, int flag); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /s16.c: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | // 42 | 43 | //// 44 | // This is an implementation of Simple16 algorithm for sorted integer arrays. 45 | // The basic ideas are based on papers from: 46 | // 1. http://www2008.org/papers/pdf/p387-zhangA.pdf 47 | // 2. http://www2009.org/proceedings/pdf/p401.pdf 48 | // 49 | // The maximum possible integer value Simple16 can encode is < 2^28 (this is 50 | // dertermined by the Simple16 algorithm itself). Therefore, in order to use 51 | // Simple16, the application must write their own code to encode numbers in 52 | // the range of [2^28, 2^32). A simple way is just write those numbers as 53 | // 32-bit integers (that is, no compression for very big numbers). 54 | // 55 | // Alternative implementations: 56 | // * C++ http://code.google.com/p/poly-ir-toolkit/source/browse/trunk/src/compression_toolkit/s16_coding.cc 57 | // * Java https://github.com/hyan/kamikaze/blob/master/src/main/java/com/kamikaze/pfordelta/Simple16.java 58 | // 59 | // This code is based on an implementation in C++ of the Poly-IR-Toolkit. 60 | // It's available at http://code.google.com/p/poly-ir-toolkit/source/browse/trunk/src/compression_toolkit/s16_coding.cc 61 | // 62 | 63 | #include 64 | #include 65 | #include"s16.h" 66 | 67 | unsigned int cbits[16][28] = 68 | { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 69 | {2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0}, 70 | {1,1,1,1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,1,1,1,0,0,0,0,0,0,0}, 71 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,0,0,0,0,0,0,0}, 72 | {2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 73 | {4,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 74 | {3,4,4,4,4,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 75 | {4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 76 | {5,5,5,5,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 77 | {4,4,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 78 | {6,6,6,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 79 | {5,5,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 80 | {7,7,7,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 81 | {10,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 82 | {14,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 83 | {28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; 84 | 85 | int s16_cnum[16] = {28, 21, 21, 21, 14, 9, 8, 7, 6, 6, 5, 5, 4, 3, 2, 1}; 86 | 87 | // 88 | // Compress an integer array using Simple16 89 | // Parameters: 90 | // input pointer to the array of integers to compress 91 | // output pointer to the array of compressed integers 92 | // size number of integers to compress 93 | // Returns: 94 | // the number of compressed integers 95 | // 96 | // Idea of compress algorithm: 97 | // 98 | // - do the next 28 numbers fit into one bit each? 99 | // - if yes: use that case 100 | // - if no: do the next 21 numbers fits in an array of 7 integers of 2 bits and 14 integers of 1 bit each? 101 | // - if yes: use that case 102 | // - if no: do the next 21 numbers fits in an array of 7 integers of 1 bit and 7 integers 2 bits and 7 integers of 1 bit each? 103 | // ... and so on . 104 | int s16_compress(unsigned int* input, unsigned int* output, int size) { 105 | int left = size; 106 | unsigned int* tmp = output; 107 | int ret; 108 | 109 | while (left > 0) { 110 | ret = s16_encode(tmp, input, left); 111 | input += ret; 112 | left -= ret; 113 | tmp++; 114 | } 115 | 116 | return tmp - output; 117 | } 118 | 119 | int s16_encode(unsigned int* _w, unsigned int* _p, unsigned int m) { 120 | unsigned int _k, _j, _m, _o; 121 | 122 | for (_k = 0; _k < 16; _k++) { 123 | (*_w) = _k << 28; 124 | _m = (s16_cnum[_k] < m) ? s16_cnum[_k] : m; 125 | 126 | for (_j = 0, _o = 0; (_j < _m) && (*(_p + _j) < (unsigned int) (1 << cbits[_k][_j]));) { 127 | (*_w) += ((*(_p + _j)) << _o); 128 | _o += cbits[_k][_j]; 129 | _j++; 130 | } 131 | if (_j == _m) { 132 | (_p) += _m; 133 | (_w)++; 134 | break; 135 | } 136 | } 137 | 138 | return _m; 139 | } 140 | 141 | 142 | // 143 | // Decompress an integer array using Simple16 144 | // Parameters: 145 | // input pointer to the array of compressed integers to decompress 146 | // output pointer to the array of integers 147 | // size number of integers to decompress 148 | // Returns: 149 | // the number of processed integers 150 | // 151 | int s16_decompress(unsigned int* input, unsigned int* output, int size) { 152 | unsigned int *_p = output; 153 | int num; 154 | unsigned int* tmp = input; 155 | int left = size; 156 | 157 | while (left > 0) { 158 | num = s16_decode(tmp, _p); 159 | _p += num; 160 | left -= num; 161 | tmp++; 162 | } 163 | 164 | return tmp - input; 165 | } 166 | 167 | int s16_decode(unsigned int *_w, unsigned int *_p) { 168 | int _k = (*_w) >> 28; 169 | switch (_k) { 170 | case 0: 171 | *_p = (*_w) & 1; 172 | _p++; 173 | *_p = (*_w >> 1) & 1; 174 | _p++; 175 | *_p = (*_w >> 2) & 1; 176 | _p++; 177 | *_p = (*_w >> 3) & 1; 178 | _p++; 179 | *_p = (*_w >> 4) & 1; 180 | _p++; 181 | *_p = (*_w >> 5) & 1; 182 | _p++; 183 | *_p = (*_w >> 6) & 1; 184 | _p++; 185 | *_p = (*_w >> 7) & 1; 186 | _p++; 187 | *_p = (*_w >> 8) & 1; 188 | _p++; 189 | *_p = (*_w >> 9) & 1; 190 | _p++; 191 | *_p = (*_w >> 10) & 1; 192 | _p++; 193 | *_p = (*_w >> 11) & 1; 194 | _p++; 195 | *_p = (*_w >> 12) & 1; 196 | _p++; 197 | *_p = (*_w >> 13) & 1; 198 | _p++; 199 | *_p = (*_w >> 14) & 1; 200 | _p++; 201 | *_p = (*_w >> 15) & 1; 202 | _p++; 203 | *_p = (*_w >> 16) & 1; 204 | _p++; 205 | *_p = (*_w >> 17) & 1; 206 | _p++; 207 | *_p = (*_w >> 18) & 1; 208 | _p++; 209 | *_p = (*_w >> 19) & 1; 210 | _p++; 211 | *_p = (*_w >> 20) & 1; 212 | _p++; 213 | *_p = (*_w >> 21) & 1; 214 | _p++; 215 | *_p = (*_w >> 22) & 1; 216 | _p++; 217 | *_p = (*_w >> 23) & 1; 218 | _p++; 219 | *_p = (*_w >> 24) & 1; 220 | _p++; 221 | *_p = (*_w >> 25) & 1; 222 | _p++; 223 | *_p = (*_w >> 26) & 1; 224 | _p++; 225 | *_p = (*_w >> 27) & 1; 226 | _p++; 227 | break; 228 | case 1: 229 | *_p = (*_w) & 3; 230 | _p++; 231 | *_p = (*_w >> 2) & 3; 232 | _p++; 233 | *_p = (*_w >> 4) & 3; 234 | _p++; 235 | *_p = (*_w >> 6) & 3; 236 | _p++; 237 | *_p = (*_w >> 8) & 3; 238 | _p++; 239 | *_p = (*_w >> 10) & 3; 240 | _p++; 241 | *_p = (*_w >> 12) & 3; 242 | _p++; 243 | *_p = (*_w >> 14) & 1; 244 | _p++; 245 | *_p = (*_w >> 15) & 1; 246 | _p++; 247 | *_p = (*_w >> 16) & 1; 248 | _p++; 249 | *_p = (*_w >> 17) & 1; 250 | _p++; 251 | *_p = (*_w >> 18) & 1; 252 | _p++; 253 | *_p = (*_w >> 19) & 1; 254 | _p++; 255 | *_p = (*_w >> 20) & 1; 256 | _p++; 257 | *_p = (*_w >> 21) & 1; 258 | _p++; 259 | *_p = (*_w >> 22) & 1; 260 | _p++; 261 | *_p = (*_w >> 23) & 1; 262 | _p++; 263 | *_p = (*_w >> 24) & 1; 264 | _p++; 265 | *_p = (*_w >> 25) & 1; 266 | _p++; 267 | *_p = (*_w >> 26) & 1; 268 | _p++; 269 | *_p = (*_w >> 27) & 1; 270 | _p++; 271 | break; 272 | case 2: 273 | *_p = (*_w) & 1; 274 | _p++; 275 | *_p = (*_w >> 1) & 1; 276 | _p++; 277 | *_p = (*_w >> 2) & 1; 278 | _p++; 279 | *_p = (*_w >> 3) & 1; 280 | _p++; 281 | *_p = (*_w >> 4) & 1; 282 | _p++; 283 | *_p = (*_w >> 5) & 1; 284 | _p++; 285 | *_p = (*_w >> 6) & 1; 286 | _p++; 287 | *_p = (*_w >> 7) & 3; 288 | _p++; 289 | *_p = (*_w >> 9) & 3; 290 | _p++; 291 | *_p = (*_w >> 11) & 3; 292 | _p++; 293 | *_p = (*_w >> 13) & 3; 294 | _p++; 295 | *_p = (*_w >> 15) & 3; 296 | _p++; 297 | *_p = (*_w >> 17) & 3; 298 | _p++; 299 | *_p = (*_w >> 19) & 3; 300 | _p++; 301 | *_p = (*_w >> 21) & 1; 302 | _p++; 303 | *_p = (*_w >> 22) & 1; 304 | _p++; 305 | *_p = (*_w >> 23) & 1; 306 | _p++; 307 | *_p = (*_w >> 24) & 1; 308 | _p++; 309 | *_p = (*_w >> 25) & 1; 310 | _p++; 311 | *_p = (*_w >> 26) & 1; 312 | _p++; 313 | *_p = (*_w >> 27) & 1; 314 | _p++; 315 | break; 316 | case 3: 317 | *_p = (*_w) & 1; 318 | _p++; 319 | *_p = (*_w >> 1) & 1; 320 | _p++; 321 | *_p = (*_w >> 2) & 1; 322 | _p++; 323 | *_p = (*_w >> 3) & 1; 324 | _p++; 325 | *_p = (*_w >> 4) & 1; 326 | _p++; 327 | *_p = (*_w >> 5) & 1; 328 | _p++; 329 | *_p = (*_w >> 6) & 1; 330 | _p++; 331 | *_p = (*_w >> 7) & 1; 332 | _p++; 333 | *_p = (*_w >> 8) & 1; 334 | _p++; 335 | *_p = (*_w >> 9) & 1; 336 | _p++; 337 | *_p = (*_w >> 10) & 1; 338 | _p++; 339 | *_p = (*_w >> 11) & 1; 340 | _p++; 341 | *_p = (*_w >> 12) & 1; 342 | _p++; 343 | *_p = (*_w >> 13) & 1; 344 | _p++; 345 | *_p = (*_w >> 14) & 3; 346 | _p++; 347 | *_p = (*_w >> 16) & 3; 348 | _p++; 349 | *_p = (*_w >> 18) & 3; 350 | _p++; 351 | *_p = (*_w >> 20) & 3; 352 | _p++; 353 | *_p = (*_w >> 22) & 3; 354 | _p++; 355 | *_p = (*_w >> 24) & 3; 356 | _p++; 357 | *_p = (*_w >> 26) & 3; 358 | _p++; 359 | break; 360 | case 4: 361 | *_p = (*_w) & 3; 362 | _p++; 363 | *_p = (*_w >> 2) & 3; 364 | _p++; 365 | *_p = (*_w >> 4) & 3; 366 | _p++; 367 | *_p = (*_w >> 6) & 3; 368 | _p++; 369 | *_p = (*_w >> 8) & 3; 370 | _p++; 371 | *_p = (*_w >> 10) & 3; 372 | _p++; 373 | *_p = (*_w >> 12) & 3; 374 | _p++; 375 | *_p = (*_w >> 14) & 3; 376 | _p++; 377 | *_p = (*_w >> 16) & 3; 378 | _p++; 379 | *_p = (*_w >> 18) & 3; 380 | _p++; 381 | *_p = (*_w >> 20) & 3; 382 | _p++; 383 | *_p = (*_w >> 22) & 3; 384 | _p++; 385 | *_p = (*_w >> 24) & 3; 386 | _p++; 387 | *_p = (*_w >> 26) & 3; 388 | _p++; 389 | break; 390 | case 5: 391 | *_p = (*_w) & 15; 392 | _p++; 393 | *_p = (*_w >> 4) & 7; 394 | _p++; 395 | *_p = (*_w >> 7) & 7; 396 | _p++; 397 | *_p = (*_w >> 10) & 7; 398 | _p++; 399 | *_p = (*_w >> 13) & 7; 400 | _p++; 401 | *_p = (*_w >> 16) & 7; 402 | _p++; 403 | *_p = (*_w >> 19) & 7; 404 | _p++; 405 | *_p = (*_w >> 22) & 7; 406 | _p++; 407 | *_p = (*_w >> 25) & 7; 408 | _p++; 409 | break; 410 | case 6: 411 | *_p = (*_w) & 7; 412 | _p++; 413 | *_p = (*_w >> 3) & 15; 414 | _p++; 415 | *_p = (*_w >> 7) & 15; 416 | _p++; 417 | *_p = (*_w >> 11) & 15; 418 | _p++; 419 | *_p = (*_w >> 15) & 15; 420 | _p++; 421 | *_p = (*_w >> 19) & 7; 422 | _p++; 423 | *_p = (*_w >> 22) & 7; 424 | _p++; 425 | *_p = (*_w >> 25) & 7; 426 | _p++; 427 | break; 428 | case 7: 429 | *_p = (*_w) & 15; 430 | _p++; 431 | *_p = (*_w >> 4) & 15; 432 | _p++; 433 | *_p = (*_w >> 8) & 15; 434 | _p++; 435 | *_p = (*_w >> 12) & 15; 436 | _p++; 437 | *_p = (*_w >> 16) & 15; 438 | _p++; 439 | *_p = (*_w >> 20) & 15; 440 | _p++; 441 | *_p = (*_w >> 24) & 15; 442 | _p++; 443 | break; 444 | case 8: 445 | *_p = (*_w) & 31; 446 | _p++; 447 | *_p = (*_w >> 5) & 31; 448 | _p++; 449 | *_p = (*_w >> 10) & 31; 450 | _p++; 451 | *_p = (*_w >> 15) & 31; 452 | _p++; 453 | *_p = (*_w >> 20) & 15; 454 | _p++; 455 | *_p = (*_w >> 24) & 15; 456 | _p++; 457 | break; 458 | case 9: 459 | *_p = (*_w) & 15; 460 | _p++; 461 | *_p = (*_w >> 4) & 15; 462 | _p++; 463 | *_p = (*_w >> 8) & 31; 464 | _p++; 465 | *_p = (*_w >> 13) & 31; 466 | _p++; 467 | *_p = (*_w >> 18) & 31; 468 | _p++; 469 | *_p = (*_w >> 23) & 31; 470 | _p++; 471 | break; 472 | case 10: 473 | *_p = (*_w) & 63; 474 | _p++; 475 | *_p = (*_w >> 6) & 63; 476 | _p++; 477 | *_p = (*_w >> 12) & 63; 478 | _p++; 479 | *_p = (*_w >> 18) & 31; 480 | _p++; 481 | *_p = (*_w >> 23) & 31; 482 | _p++; 483 | break; 484 | case 11: 485 | *_p = (*_w) & 31; 486 | _p++; 487 | *_p = (*_w >> 5) & 31; 488 | _p++; 489 | *_p = (*_w >> 10) & 63; 490 | _p++; 491 | *_p = (*_w >> 16) & 63; 492 | _p++; 493 | *_p = (*_w >> 22) & 63; 494 | _p++; 495 | break; 496 | case 12: 497 | *_p = (*_w) & 127; 498 | _p++; 499 | *_p = (*_w >> 7) & 127; 500 | _p++; 501 | *_p = (*_w >> 14) & 127; 502 | _p++; 503 | *_p = (*_w >> 21) & 127; 504 | _p++; 505 | break; 506 | case 13: 507 | *_p = (*_w) & 1023; 508 | _p++; 509 | *_p = (*_w >> 10) & 511; 510 | _p++; 511 | *_p = (*_w >> 19) & 511; 512 | _p++; 513 | break; 514 | case 14: 515 | *_p = (*_w) & 16383; 516 | _p++; 517 | *_p = (*_w >> 14) & 16383; 518 | _p++; 519 | break; 520 | case 15: 521 | *_p = (*_w) & ((1 << 28) - 1); 522 | _p++; 523 | break; 524 | } 525 | return s16_cnum[_k]; 526 | } 527 | 528 | -------------------------------------------------------------------------------- /s16.h: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | // 42 | 43 | #ifndef S16_H_ 44 | #define S16_H_ 45 | 46 | int s16_compress(unsigned int*, unsigned int*, int); 47 | int s16_encode(unsigned int*, unsigned int*, unsigned int); 48 | int s16_decompress(unsigned int*, unsigned int*, int); 49 | int s16_decode(unsigned int*, unsigned int*); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /unpack.c: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | // 42 | 43 | #include "unpack.h" 44 | 45 | pf unpack[17] = {unpack0, unpack1, unpack2, unpack3, unpack4, unpack5, unpack6, 46 | unpack7, unpack8, unpack9, unpack10, unpack11, unpack12, unpack13, 47 | unpack16, unpack20, unpack32}; 48 | 49 | void unpack0(unsigned int* p, unsigned int* w, int BS) { 50 | int i; 51 | for (i = 0; i < BS; i++) { 52 | p[i] = 0; 53 | } 54 | } 55 | 56 | void unpack1(unsigned int* p, unsigned int* w, int BS) { 57 | int i; 58 | for (i = 0; i < BS; i += 32, p += 32, w += 1) { 59 | p[0] = (w[0] >> 31); 60 | p[1] = (w[0] >> 30) & 1; 61 | p[2] = (w[0] >> 29) & 1; 62 | p[3] = (w[0] >> 28) & 1; 63 | p[4] = (w[0] >> 27) & 1; 64 | p[5] = (w[0] >> 26) & 1; 65 | p[6] = (w[0] >> 25) & 1; 66 | p[7] = (w[0] >> 24) & 1; 67 | p[8] = (w[0] >> 23) & 1; 68 | p[9] = (w[0] >> 22) & 1; 69 | p[10] = (w[0] >> 21) & 1; 70 | p[11] = (w[0] >> 20) & 1; 71 | p[12] = (w[0] >> 19) & 1; 72 | p[13] = (w[0] >> 18) & 1; 73 | p[14] = (w[0] >> 17) & 1; 74 | p[15] = (w[0] >> 16) & 1; 75 | p[16] = (w[0] >> 15) & 1; 76 | p[17] = (w[0] >> 14) & 1; 77 | p[18] = (w[0] >> 13) & 1; 78 | p[19] = (w[0] >> 12) & 1; 79 | p[20] = (w[0] >> 11) & 1; 80 | p[21] = (w[0] >> 10) & 1; 81 | p[22] = (w[0] >> 9) & 1; 82 | p[23] = (w[0] >> 8) & 1; 83 | p[24] = (w[0] >> 7) & 1; 84 | p[25] = (w[0] >> 6) & 1; 85 | p[26] = (w[0] >> 5) & 1; 86 | p[27] = (w[0] >> 4) & 1; 87 | p[28] = (w[0] >> 3) & 1; 88 | p[29] = (w[0] >> 2) & 1; 89 | p[30] = (w[0] >> 1) & 1; 90 | p[31] = (w[0]) & 1; 91 | } 92 | } 93 | 94 | void unpack2(unsigned int* p, unsigned int* w, int BS) { 95 | int i; 96 | for (i = 0; i < BS; i += 32, p += 32, w += 2) { 97 | p[0] = (w[0] >> 30); 98 | p[1] = (w[0] >> 28) & 3; 99 | p[2] = (w[0] >> 26) & 3; 100 | p[3] = (w[0] >> 24) & 3; 101 | p[4] = (w[0] >> 22) & 3; 102 | p[5] = (w[0] >> 20) & 3; 103 | p[6] = (w[0] >> 18) & 3; 104 | p[7] = (w[0] >> 16) & 3; 105 | p[8] = (w[0] >> 14) & 3; 106 | p[9] = (w[0] >> 12) & 3; 107 | p[10] = (w[0] >> 10) & 3; 108 | p[11] = (w[0] >> 8) & 3; 109 | p[12] = (w[0] >> 6) & 3; 110 | p[13] = (w[0] >> 4) & 3; 111 | p[14] = (w[0] >> 2) & 3; 112 | p[15] = (w[0]) & 3; 113 | p[16] = (w[1] >> 30); 114 | p[17] = (w[1] >> 28) & 3; 115 | p[18] = (w[1] >> 26) & 3; 116 | p[19] = (w[1] >> 24) & 3; 117 | p[20] = (w[1] >> 22) & 3; 118 | p[21] = (w[1] >> 20) & 3; 119 | p[22] = (w[1] >> 18) & 3; 120 | p[23] = (w[1] >> 16) & 3; 121 | p[24] = (w[1] >> 14) & 3; 122 | p[25] = (w[1] >> 12) & 3; 123 | p[26] = (w[1] >> 10) & 3; 124 | p[27] = (w[1] >> 8) & 3; 125 | p[28] = (w[1] >> 6) & 3; 126 | p[29] = (w[1] >> 4) & 3; 127 | p[30] = (w[1] >> 2) & 3; 128 | p[31] = (w[1]) & 3; 129 | } 130 | } 131 | 132 | void unpack3(unsigned int* p, unsigned int* w, int BS) { 133 | int i; 134 | for (i = 0; i < BS; i += 32, p += 32, w += 3) { 135 | p[0] = (w[0] >> 29); 136 | p[1] = (w[0] >> 26) & 7; 137 | p[2] = (w[0] >> 23) & 7; 138 | p[3] = (w[0] >> 20) & 7; 139 | p[4] = (w[0] >> 17) & 7; 140 | p[5] = (w[0] >> 14) & 7; 141 | p[6] = (w[0] >> 11) & 7; 142 | p[7] = (w[0] >> 8) & 7; 143 | p[8] = (w[0] >> 5) & 7; 144 | p[9] = (w[0] >> 2) & 7; 145 | p[10] = (w[0] << 1) & 7; 146 | p[10] |= (w[1] >> 31); 147 | p[11] = (w[1] >> 28) & 7; 148 | p[12] = (w[1] >> 25) & 7; 149 | p[13] = (w[1] >> 22) & 7; 150 | p[14] = (w[1] >> 19) & 7; 151 | p[15] = (w[1] >> 16) & 7; 152 | p[16] = (w[1] >> 13) & 7; 153 | p[17] = (w[1] >> 10) & 7; 154 | p[18] = (w[1] >> 7) & 7; 155 | p[19] = (w[1] >> 4) & 7; 156 | p[20] = (w[1] >> 1) & 7; 157 | p[21] = (w[1] << 2) & 7; 158 | p[21] |= (w[2] >> 30); 159 | p[22] = (w[2] >> 27) & 7; 160 | p[23] = (w[2] >> 24) & 7; 161 | p[24] = (w[2] >> 21) & 7; 162 | p[25] = (w[2] >> 18) & 7; 163 | p[26] = (w[2] >> 15) & 7; 164 | p[27] = (w[2] >> 12) & 7; 165 | p[28] = (w[2] >> 9) & 7; 166 | p[29] = (w[2] >> 6) & 7; 167 | p[30] = (w[2] >> 3) & 7; 168 | p[31] = (w[2]) & 7; 169 | } 170 | } 171 | 172 | void unpack4(unsigned int* p, unsigned int* w, int BS) { 173 | int i; 174 | for (i = 0; i < BS; i += 32, p += 32, w += 4) { 175 | p[0] = (w[0] >> 28); 176 | p[1] = (w[0] >> 24) & 15; 177 | p[2] = (w[0] >> 20) & 15; 178 | p[3] = (w[0] >> 16) & 15; 179 | p[4] = (w[0] >> 12) & 15; 180 | p[5] = (w[0] >> 8) & 15; 181 | p[6] = (w[0] >> 4) & 15; 182 | p[7] = (w[0]) & 15; 183 | p[8] = (w[1] >> 28); 184 | p[9] = (w[1] >> 24) & 15; 185 | p[10] = (w[1] >> 20) & 15; 186 | p[11] = (w[1] >> 16) & 15; 187 | p[12] = (w[1] >> 12) & 15; 188 | p[13] = (w[1] >> 8) & 15; 189 | p[14] = (w[1] >> 4) & 15; 190 | p[15] = (w[1]) & 15; 191 | p[16] = (w[2] >> 28); 192 | p[17] = (w[2] >> 24) & 15; 193 | p[18] = (w[2] >> 20) & 15; 194 | p[19] = (w[2] >> 16) & 15; 195 | p[20] = (w[2] >> 12) & 15; 196 | p[21] = (w[2] >> 8) & 15; 197 | p[22] = (w[2] >> 4) & 15; 198 | p[23] = (w[2]) & 15; 199 | p[24] = (w[3] >> 28); 200 | p[25] = (w[3] >> 24) & 15; 201 | p[26] = (w[3] >> 20) & 15; 202 | p[27] = (w[3] >> 16) & 15; 203 | p[28] = (w[3] >> 12) & 15; 204 | p[29] = (w[3] >> 8) & 15; 205 | p[30] = (w[3] >> 4) & 15; 206 | p[31] = (w[3]) & 15; 207 | } 208 | } 209 | 210 | void unpack5(unsigned int* p, unsigned int* w, int BS) { 211 | int i; 212 | for (i = 0; i < BS; i += 32, p += 32, w += 5) { 213 | p[0] = (w[0] >> 27); 214 | p[1] = (w[0] >> 22) & 31; 215 | p[2] = (w[0] >> 17) & 31; 216 | p[3] = (w[0] >> 12) & 31; 217 | p[4] = (w[0] >> 7) & 31; 218 | p[5] = (w[0] >> 2) & 31; 219 | p[6] = (w[0] << 3) & 31; 220 | p[6] |= (w[1] >> 29); 221 | p[7] = (w[1] >> 24) & 31; 222 | p[8] = (w[1] >> 19) & 31; 223 | p[9] = (w[1] >> 14) & 31; 224 | p[10] = (w[1] >> 9) & 31; 225 | p[11] = (w[1] >> 4) & 31; 226 | p[12] = (w[1] << 1) & 31; 227 | p[12] |= (w[2] >> 31); 228 | p[13] = (w[2] >> 26) & 31; 229 | p[14] = (w[2] >> 21) & 31; 230 | p[15] = (w[2] >> 16) & 31; 231 | p[16] = (w[2] >> 11) & 31; 232 | p[17] = (w[2] >> 6) & 31; 233 | p[18] = (w[2] >> 1) & 31; 234 | p[19] = (w[2] << 4) & 31; 235 | p[19] |= (w[3] >> 28); 236 | p[20] = (w[3] >> 23) & 31; 237 | p[21] = (w[3] >> 18) & 31; 238 | p[22] = (w[3] >> 13) & 31; 239 | p[23] = (w[3] >> 8) & 31; 240 | p[24] = (w[3] >> 3) & 31; 241 | p[25] = (w[3] << 2) & 31; 242 | p[25] |= (w[4] >> 30); 243 | p[26] = (w[4] >> 25) & 31; 244 | p[27] = (w[4] >> 20) & 31; 245 | p[28] = (w[4] >> 15) & 31; 246 | p[29] = (w[4] >> 10) & 31; 247 | p[30] = (w[4] >> 5) & 31; 248 | p[31] = (w[4]) & 31; 249 | } 250 | } 251 | 252 | void unpack6(unsigned int* p, unsigned int* w, int BS) { 253 | int i; 254 | for (i = 0; i < BS; i += 32, p += 32, w += 6) { 255 | p[0] = (w[0] >> 26); 256 | p[1] = (w[0] >> 20) & 63; 257 | p[2] = (w[0] >> 14) & 63; 258 | p[3] = (w[0] >> 8) & 63; 259 | p[4] = (w[0] >> 2) & 63; 260 | p[5] = (w[0] << 4) & 63; 261 | p[5] |= (w[1] >> 28); 262 | p[6] = (w[1] >> 22) & 63; 263 | p[7] = (w[1] >> 16) & 63; 264 | p[8] = (w[1] >> 10) & 63; 265 | p[9] = (w[1] >> 4) & 63; 266 | p[10] = (w[1] << 2) & 63; 267 | p[10] |= (w[2] >> 30); 268 | p[11] = (w[2] >> 24) & 63; 269 | p[12] = (w[2] >> 18) & 63; 270 | p[13] = (w[2] >> 12) & 63; 271 | p[14] = (w[2] >> 6) & 63; 272 | p[15] = (w[2]) & 63; 273 | p[16] = (w[3] >> 26); 274 | p[17] = (w[3] >> 20) & 63; 275 | p[18] = (w[3] >> 14) & 63; 276 | p[19] = (w[3] >> 8) & 63; 277 | p[20] = (w[3] >> 2) & 63; 278 | p[21] = (w[3] << 4) & 63; 279 | p[21] |= (w[4] >> 28); 280 | p[22] = (w[4] >> 22) & 63; 281 | p[23] = (w[4] >> 16) & 63; 282 | p[24] = (w[4] >> 10) & 63; 283 | p[25] = (w[4] >> 4) & 63; 284 | p[26] = (w[4] << 2) & 63; 285 | p[26] |= (w[5] >> 30); 286 | p[27] = (w[5] >> 24) & 63; 287 | p[28] = (w[5] >> 18) & 63; 288 | p[29] = (w[5] >> 12) & 63; 289 | p[30] = (w[5] >> 6) & 63; 290 | p[31] = (w[5]) & 63; 291 | } 292 | } 293 | 294 | void unpack7(unsigned int* p, unsigned int* w, int BS) { 295 | int i; 296 | for (i = 0; i < BS; i += 32, p += 32, w += 7) { 297 | p[0] = (w[0] >> 25); 298 | p[1] = (w[0] >> 18) & 127; 299 | p[2] = (w[0] >> 11) & 127; 300 | p[3] = (w[0] >> 4) & 127; 301 | p[4] = (w[0] << 3) & 127; 302 | p[4] |= (w[1] >> 29); 303 | p[5] = (w[1] >> 22) & 127; 304 | p[6] = (w[1] >> 15) & 127; 305 | p[7] = (w[1] >> 8) & 127; 306 | p[8] = (w[1] >> 1) & 127; 307 | p[9] = (w[1] << 6) & 127; 308 | p[9] |= (w[2] >> 26); 309 | p[10] = (w[2] >> 19) & 127; 310 | p[11] = (w[2] >> 12) & 127; 311 | p[12] = (w[2] >> 5) & 127; 312 | p[13] = (w[2] << 2) & 127; 313 | p[13] |= (w[3] >> 30); 314 | p[14] = (w[3] >> 23) & 127; 315 | p[15] = (w[3] >> 16) & 127; 316 | p[16] = (w[3] >> 9) & 127; 317 | p[17] = (w[3] >> 2) & 127; 318 | p[18] = (w[3] << 5) & 127; 319 | p[18] |= (w[4] >> 27); 320 | p[19] = (w[4] >> 20) & 127; 321 | p[20] = (w[4] >> 13) & 127; 322 | p[21] = (w[4] >> 6) & 127; 323 | p[22] = (w[4] << 1) & 127; 324 | p[22] |= (w[5] >> 31); 325 | p[23] = (w[5] >> 24) & 127; 326 | p[24] = (w[5] >> 17) & 127; 327 | p[25] = (w[5] >> 10) & 127; 328 | p[26] = (w[5] >> 3) & 127; 329 | p[27] = (w[5] << 4) & 127; 330 | p[27] |= (w[6] >> 28); 331 | p[28] = (w[6] >> 21) & 127; 332 | p[29] = (w[6] >> 14) & 127; 333 | p[30] = (w[6] >> 7) & 127; 334 | p[31] = (w[6]) & 127; 335 | } 336 | } 337 | 338 | void unpack8(unsigned int* p, unsigned int* w, int BS) { 339 | int i; 340 | for (i = 0; i < BS; i += 32, p += 32, w += 8) { 341 | p[0] = (w[0] >> 24); 342 | p[1] = (w[0] >> 16) & 255; 343 | p[2] = (w[0] >> 8) & 255; 344 | p[3] = (w[0]) & 255; 345 | p[4] = (w[1] >> 24); 346 | p[5] = (w[1] >> 16) & 255; 347 | p[6] = (w[1] >> 8) & 255; 348 | p[7] = (w[1]) & 255; 349 | p[8] = (w[2] >> 24); 350 | p[9] = (w[2] >> 16) & 255; 351 | p[10] = (w[2] >> 8) & 255; 352 | p[11] = (w[2]) & 255; 353 | p[12] = (w[3] >> 24); 354 | p[13] = (w[3] >> 16) & 255; 355 | p[14] = (w[3] >> 8) & 255; 356 | p[15] = (w[3]) & 255; 357 | p[16] = (w[4] >> 24); 358 | p[17] = (w[4] >> 16) & 255; 359 | p[18] = (w[4] >> 8) & 255; 360 | p[19] = (w[4]) & 255; 361 | p[20] = (w[5] >> 24); 362 | p[21] = (w[5] >> 16) & 255; 363 | p[22] = (w[5] >> 8) & 255; 364 | p[23] = (w[5]) & 255; 365 | p[24] = (w[6] >> 24); 366 | p[25] = (w[6] >> 16) & 255; 367 | p[26] = (w[6] >> 8) & 255; 368 | p[27] = (w[6]) & 255; 369 | p[28] = (w[7] >> 24); 370 | p[29] = (w[7] >> 16) & 255; 371 | p[30] = (w[7] >> 8) & 255; 372 | p[31] = (w[7]) & 255; 373 | } 374 | } 375 | 376 | void unpack9(unsigned int* p, unsigned int* w, int BS) { 377 | int i; 378 | for (i = 0; i < BS; i += 32, p += 32, w += 9) { 379 | p[0] = (w[0] >> 23); 380 | p[1] = (w[0] >> 14) & 511; 381 | p[2] = (w[0] >> 5) & 511; 382 | p[3] = (w[0] << 4) & 511; 383 | p[3] |= (w[1] >> 28); 384 | p[4] = (w[1] >> 19) & 511; 385 | p[5] = (w[1] >> 10) & 511; 386 | p[6] = (w[1] >> 1) & 511; 387 | p[7] = (w[1] << 8) & 511; 388 | p[7] |= (w[2] >> 24); 389 | p[8] = (w[2] >> 15) & 511; 390 | p[9] = (w[2] >> 6) & 511; 391 | p[10] = (w[2] << 3) & 511; 392 | p[10] |= (w[3] >> 29); 393 | p[11] = (w[3] >> 20) & 511; 394 | p[12] = (w[3] >> 11) & 511; 395 | p[13] = (w[3] >> 2) & 511; 396 | p[14] = (w[3] << 7) & 511; 397 | p[14] |= (w[4] >> 25); 398 | p[15] = (w[4] >> 16) & 511; 399 | p[16] = (w[4] >> 7) & 511; 400 | p[17] = (w[4] << 2) & 511; 401 | p[17] |= (w[5] >> 30); 402 | p[18] = (w[5] >> 21) & 511; 403 | p[19] = (w[5] >> 12) & 511; 404 | p[20] = (w[5] >> 3) & 511; 405 | p[21] = (w[5] << 6) & 511; 406 | p[21] |= (w[6] >> 26); 407 | p[22] = (w[6] >> 17) & 511; 408 | p[23] = (w[6] >> 8) & 511; 409 | p[24] = (w[6] << 1) & 511; 410 | p[24] |= (w[7] >> 31); 411 | p[25] = (w[7] >> 22) & 511; 412 | p[26] = (w[7] >> 13) & 511; 413 | p[27] = (w[7] >> 4) & 511; 414 | p[28] = (w[7] << 5) & 511; 415 | p[28] |= (w[8] >> 27); 416 | p[29] = (w[8] >> 18) & 511; 417 | p[30] = (w[8] >> 9) & 511; 418 | p[31] = (w[8]) & 511; 419 | } 420 | } 421 | 422 | void unpack10(unsigned int* p, unsigned int* w, int BS) { 423 | int i; 424 | for (i = 0; i < BS; i += 32, p += 32, w += 10) { 425 | p[0] = (w[0] >> 22); 426 | p[1] = (w[0] >> 12) & 1023; 427 | p[2] = (w[0] >> 2) & 1023; 428 | p[3] = (w[0] << 8) & 1023; 429 | p[3] |= (w[1] >> 24); 430 | p[4] = (w[1] >> 14) & 1023; 431 | p[5] = (w[1] >> 4) & 1023; 432 | p[6] = (w[1] << 6) & 1023; 433 | p[6] |= (w[2] >> 26); 434 | p[7] = (w[2] >> 16) & 1023; 435 | p[8] = (w[2] >> 6) & 1023; 436 | p[9] = (w[2] << 4) & 1023; 437 | p[9] |= (w[3] >> 28); 438 | p[10] = (w[3] >> 18) & 1023; 439 | p[11] = (w[3] >> 8) & 1023; 440 | p[12] = (w[3] << 2) & 1023; 441 | p[12] |= (w[4] >> 30); 442 | p[13] = (w[4] >> 20) & 1023; 443 | p[14] = (w[4] >> 10) & 1023; 444 | p[15] = (w[4]) & 1023; 445 | p[16] = (w[5] >> 22); 446 | p[17] = (w[5] >> 12) & 1023; 447 | p[18] = (w[5] >> 2) & 1023; 448 | p[19] = (w[5] << 8) & 1023; 449 | p[19] |= (w[6] >> 24); 450 | p[20] = (w[6] >> 14) & 1023; 451 | p[21] = (w[6] >> 4) & 1023; 452 | p[22] = (w[6] << 6) & 1023; 453 | p[22] |= (w[7] >> 26); 454 | p[23] = (w[7] >> 16) & 1023; 455 | p[24] = (w[7] >> 6) & 1023; 456 | p[25] = (w[7] << 4) & 1023; 457 | p[25] |= (w[8] >> 28); 458 | p[26] = (w[8] >> 18) & 1023; 459 | p[27] = (w[8] >> 8) & 1023; 460 | p[28] = (w[8] << 2) & 1023; 461 | p[28] |= (w[9] >> 30); 462 | p[29] = (w[9] >> 20) & 1023; 463 | p[30] = (w[9] >> 10) & 1023; 464 | p[31] = (w[9]) & 1023; 465 | } 466 | } 467 | 468 | void unpack11(unsigned int* p, unsigned int* w, int BS) { 469 | int i; 470 | for (i = 0; i < BS; i += 32, p += 32, w += 11) { 471 | p[0] = (w[0] >> 21); 472 | p[1] = (w[0] >> 10) & 2047; 473 | p[2] = (w[0] << 1) & 2047; 474 | p[2] |= (w[1] >> 31); 475 | p[3] = (w[1] >> 20) & 2047; 476 | p[4] = (w[1] >> 9) & 2047; 477 | p[5] = (w[1] << 2) & 2047; 478 | p[5] |= (w[2] >> 30); 479 | p[6] = (w[2] >> 19) & 2047; 480 | p[7] = (w[2] >> 8) & 2047; 481 | p[8] = (w[2] << 3) & 2047; 482 | p[8] |= (w[3] >> 29); 483 | p[9] = (w[3] >> 18) & 2047; 484 | p[10] = (w[3] >> 7) & 2047; 485 | p[11] = (w[3] << 4) & 2047; 486 | p[11] |= (w[4] >> 28); 487 | p[12] = (w[4] >> 17) & 2047; 488 | p[13] = (w[4] >> 6) & 2047; 489 | p[14] = (w[4] << 5) & 2047; 490 | p[14] |= (w[5] >> 27); 491 | p[15] = (w[5] >> 16) & 2047; 492 | p[16] = (w[5] >> 5) & 2047; 493 | p[17] = (w[5] << 6) & 2047; 494 | p[17] |= (w[6] >> 26); 495 | p[18] = (w[6] >> 15) & 2047; 496 | p[19] = (w[6] >> 4) & 2047; 497 | p[20] = (w[6] << 7) & 2047; 498 | p[20] |= (w[7] >> 25); 499 | p[21] = (w[7] >> 14) & 2047; 500 | p[22] = (w[7] >> 3) & 2047; 501 | p[23] = (w[7] << 8) & 2047; 502 | p[23] |= (w[8] >> 24); 503 | p[24] = (w[8] >> 13) & 2047; 504 | p[25] = (w[8] >> 2) & 2047; 505 | p[26] = (w[8] << 9) & 2047; 506 | p[26] |= (w[9] >> 23); 507 | p[27] = (w[9] >> 12) & 2047; 508 | p[28] = (w[9] >> 1) & 2047; 509 | p[29] = (w[9] << 10) & 2047; 510 | p[29] |= (w[10] >> 22); 511 | p[30] = (w[10] >> 11) & 2047; 512 | p[31] = (w[10]) & 2047; 513 | } 514 | } 515 | 516 | void unpack12(unsigned int* p, unsigned int* w, int BS) { 517 | int i; 518 | for (i = 0; i < BS; i += 32, p += 32, w += 12) { 519 | p[0] = (w[0] >> 20); 520 | p[1] = (w[0] >> 8) & 4095; 521 | p[2] = (w[0] << 4) & 4095; 522 | p[2] |= (w[1] >> 28); 523 | p[3] = (w[1] >> 16) & 4095; 524 | p[4] = (w[1] >> 4) & 4095; 525 | p[5] = (w[1] << 8) & 4095; 526 | p[5] |= (w[2] >> 24); 527 | p[6] = (w[2] >> 12) & 4095; 528 | p[7] = (w[2]) & 4095; 529 | p[8] = (w[3] >> 20); 530 | p[9] = (w[3] >> 8) & 4095; 531 | p[10] = (w[3] << 4) & 4095; 532 | p[10] |= (w[4] >> 28); 533 | p[11] = (w[4] >> 16) & 4095; 534 | p[12] = (w[4] >> 4) & 4095; 535 | p[13] = (w[4] << 8) & 4095; 536 | p[13] |= (w[5] >> 24); 537 | p[14] = (w[5] >> 12) & 4095; 538 | p[15] = (w[5]) & 4095; 539 | p[16] = (w[6] >> 20); 540 | p[17] = (w[6] >> 8) & 4095; 541 | p[18] = (w[6] << 4) & 4095; 542 | p[18] |= (w[7] >> 28); 543 | p[19] = (w[7] >> 16) & 4095; 544 | p[20] = (w[7] >> 4) & 4095; 545 | p[21] = (w[7] << 8) & 4095; 546 | p[21] |= (w[8] >> 24); 547 | p[22] = (w[8] >> 12) & 4095; 548 | p[23] = (w[8]) & 4095; 549 | p[24] = (w[9] >> 20); 550 | p[25] = (w[9] >> 8) & 4095; 551 | p[26] = (w[9] << 4) & 4095; 552 | p[26] |= (w[10] >> 28); 553 | p[27] = (w[10] >> 16) & 4095; 554 | p[28] = (w[10] >> 4) & 4095; 555 | p[29] = (w[10] << 8) & 4095; 556 | p[29] |= (w[11] >> 24); 557 | p[30] = (w[11] >> 12) & 4095; 558 | p[31] = (w[11]) & 4095; 559 | } 560 | } 561 | 562 | void unpack13(unsigned int* p, unsigned int* w, int BS) { 563 | int i; 564 | for (i = 0; i < BS; i += 32, p += 32, w += 13) { 565 | p[0] = (w[0] >> 19); 566 | p[1] = (w[0] >> 6) & 8191; 567 | p[2] = (w[0] << 7) & 8191; 568 | p[2] |= (w[1] >> 25); 569 | p[3] = (w[1] >> 12) & 8191; 570 | p[4] = (w[1] << 1) & 8191; 571 | p[4] |= (w[2] >> 31); 572 | p[5] = (w[2] >> 18) & 8191; 573 | p[6] = (w[2] >> 5) & 8191; 574 | p[7] = (w[2] << 8) & 8191; 575 | p[7] |= (w[3] >> 24); 576 | p[8] = (w[3] >> 11) & 8191; 577 | p[9] = (w[3] << 2) & 8191; 578 | p[9] |= (w[4] >> 30); 579 | p[10] = (w[4] >> 17) & 8191; 580 | p[11] = (w[4] >> 4) & 8191; 581 | p[12] = (w[4] << 9) & 8191; 582 | p[12] |= (w[5] >> 23); 583 | p[13] = (w[5] >> 10) & 8191; 584 | p[14] = (w[5] << 3) & 8191; 585 | p[14] |= (w[6] >> 29); 586 | p[15] = (w[6] >> 16) & 8191; 587 | p[16] = (w[6] >> 3) & 8191; 588 | p[17] = (w[6] << 10) & 8191; 589 | p[17] |= (w[7] >> 22); 590 | p[18] = (w[7] >> 9) & 8191; 591 | p[19] = (w[7] << 4) & 8191; 592 | p[19] |= (w[8] >> 28); 593 | p[20] = (w[8] >> 15) & 8191; 594 | p[21] = (w[8] >> 2) & 8191; 595 | p[22] = (w[8] << 11) & 8191; 596 | p[22] |= (w[9] >> 21); 597 | p[23] = (w[9] >> 8) & 8191; 598 | p[24] = (w[9] << 5) & 8191; 599 | p[24] |= (w[10] >> 27); 600 | p[25] = (w[10] >> 14) & 8191; 601 | p[26] = (w[10] >> 1) & 8191; 602 | p[27] = (w[10] << 12) & 8191; 603 | p[27] |= (w[11] >> 20); 604 | p[28] = (w[11] >> 7) & 8191; 605 | p[29] = (w[11] << 6) & 8191; 606 | p[29] |= (w[12] >> 26); 607 | p[30] = (w[12] >> 13) & 8191; 608 | p[31] = (w[12]) & 8191; 609 | } 610 | } 611 | 612 | void unpack16(unsigned int* p, unsigned int* w, int BS) { 613 | int i; 614 | for (i = 0; i < BS; i += 32, p += 32, w += 16) { 615 | p[0] = (w[0] >> 16); 616 | p[1] = (w[0]) & 65535; 617 | p[2] = (w[1] >> 16); 618 | p[3] = (w[1]) & 65535; 619 | p[4] = (w[2] >> 16); 620 | p[5] = (w[2]) & 65535; 621 | p[6] = (w[3] >> 16); 622 | p[7] = (w[3]) & 65535; 623 | p[8] = (w[4] >> 16); 624 | p[9] = (w[4]) & 65535; 625 | p[10] = (w[5] >> 16); 626 | p[11] = (w[5]) & 65535; 627 | p[12] = (w[6] >> 16); 628 | p[13] = (w[6]) & 65535; 629 | p[14] = (w[7] >> 16); 630 | p[15] = (w[7]) & 65535; 631 | p[16] = (w[8] >> 16); 632 | p[17] = (w[8]) & 65535; 633 | p[18] = (w[9] >> 16); 634 | p[19] = (w[9]) & 65535; 635 | p[20] = (w[10] >> 16); 636 | p[21] = (w[10]) & 65535; 637 | p[22] = (w[11] >> 16); 638 | p[23] = (w[11]) & 65535; 639 | p[24] = (w[12] >> 16); 640 | p[25] = (w[12]) & 65535; 641 | p[26] = (w[13] >> 16); 642 | p[27] = (w[13]) & 65535; 643 | p[28] = (w[14] >> 16); 644 | p[29] = (w[14]) & 65535; 645 | p[30] = (w[15] >> 16); 646 | p[31] = (w[15]) & 65535; 647 | } 648 | } 649 | 650 | void unpack20(unsigned int* p, unsigned int* w, int BS) { 651 | int i; 652 | for (i = 0; i < BS; i += 32, p += 32, w += 20) { 653 | p[0] = (w[0] >> 12); 654 | p[1] = (w[0] << 8) & ((1 << 20) - 1); 655 | p[1] |= (w[1] >> 24); 656 | p[2] = (w[1] >> 4) & ((1 << 20) - 1); 657 | p[3] = (w[1] << 16) & ((1 << 20) - 1); 658 | p[3] |= (w[2] >> 16); 659 | p[4] = (w[2] << 4) & ((1 << 20) - 1); 660 | p[4] |= (w[3] >> 28); 661 | p[5] = (w[3] >> 8) & ((1 << 20) - 1); 662 | p[6] = (w[3] << 12) & ((1 << 20) - 1); 663 | p[6] |= (w[4] >> 20); 664 | p[7] = (w[4]) & ((1 << 20) - 1); 665 | p[8] = (w[5] >> 12); 666 | p[9] = (w[5] << 8) & ((1 << 20) - 1); 667 | p[9] |= (w[6] >> 24); 668 | p[10] = (w[6] >> 4) & ((1 << 20) - 1); 669 | p[11] = (w[6] << 16) & ((1 << 20) - 1); 670 | p[11] |= (w[7] >> 16); 671 | p[12] = (w[7] << 4) & ((1 << 20) - 1); 672 | p[12] |= (w[8] >> 28); 673 | p[13] = (w[8] >> 8) & ((1 << 20) - 1); 674 | p[14] = (w[8] << 12) & ((1 << 20) - 1); 675 | p[14] |= (w[9] >> 20); 676 | p[15] = (w[9]) & ((1 << 20) - 1); 677 | p[16] = (w[10] >> 12); 678 | p[17] = (w[10] << 8) & ((1 << 20) - 1); 679 | p[17] |= (w[11] >> 24); 680 | p[18] = (w[11] >> 4) & ((1 << 20) - 1); 681 | p[19] = (w[11] << 16) & ((1 << 20) - 1); 682 | p[19] |= (w[12] >> 16); 683 | p[20] = (w[12] << 4) & ((1 << 20) - 1); 684 | p[20] |= (w[13] >> 28); 685 | p[21] = (w[13] >> 8) & ((1 << 20) - 1); 686 | p[22] = (w[13] << 12) & ((1 << 20) - 1); 687 | p[22] |= (w[14] >> 20); 688 | p[23] = (w[14]) & ((1 << 20) - 1); 689 | p[24] = (w[15] >> 12); 690 | p[25] = (w[15] << 8) & ((1 << 20) - 1); 691 | p[25] |= (w[16] >> 24); 692 | p[26] = (w[16] >> 4) & ((1 << 20) - 1); 693 | p[27] = (w[16] << 16) & ((1 << 20) - 1); 694 | p[27] |= (w[17] >> 16); 695 | p[28] = (w[17] << 4) & ((1 << 20) - 1); 696 | p[28] |= (w[18] >> 28); 697 | p[29] = (w[18] >> 8) & ((1 << 20) - 1); 698 | p[30] = (w[18] << 12) & ((1 << 20) - 1); 699 | p[30] |= (w[19] >> 20); 700 | p[31] = (w[19]) & ((1 << 20) - 1); 701 | } 702 | } 703 | 704 | void unpack32(unsigned int* p, unsigned int* w, int BS) { 705 | int i; 706 | for (i = 0; i < BS; i += 32, p += 32, w += 32) { 707 | p[0] = w[0]; 708 | p[1] = w[1]; 709 | p[2] = w[2]; 710 | p[3] = w[3]; 711 | p[4] = w[4]; 712 | p[5] = w[5]; 713 | p[6] = w[6]; 714 | p[7] = w[7]; 715 | p[8] = w[8]; 716 | p[9] = w[9]; 717 | p[10] = w[10]; 718 | p[11] = w[11]; 719 | p[12] = w[12]; 720 | p[13] = w[13]; 721 | p[14] = w[14]; 722 | p[15] = w[15]; 723 | p[16] = w[16]; 724 | p[17] = w[17]; 725 | p[18] = w[18]; 726 | p[19] = w[19]; 727 | p[20] = w[20]; 728 | p[21] = w[21]; 729 | p[22] = w[22]; 730 | p[23] = w[23]; 731 | p[24] = w[24]; 732 | p[25] = w[25]; 733 | p[26] = w[26]; 734 | p[27] = w[27]; 735 | p[28] = w[28]; 736 | p[29] = w[29]; 737 | p[30] = w[30]; 738 | p[31] = w[31]; 739 | } 740 | } 741 | -------------------------------------------------------------------------------- /unpack.h: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright (c) 2012 Universidad de Concepción, Chile. 3 | // 4 | // Author: Diego Caro 5 | // 6 | // @UDEC_LICENSE_HEADER_START@ 7 | // 8 | // @UDEC_LICENSE_HEADER_END@ 9 | 10 | //// 11 | // Copyright (c) 2008, WEST, Polytechnic Institute of NYU 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright notice, 17 | // this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 3. Neither the name of WEST, Polytechnic Institute of NYU nor the names 22 | // of its contributors may be used to endorse or promote products derived 23 | // from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | // 37 | // Author(s): Torsten Suel, Jiangong Zhang, Jinru He 38 | // 39 | // If you have any questions or problems with our code, please contact: 40 | // jhe@cis.poly.edu 41 | // 42 | 43 | #ifndef UNPACK_H_ 44 | #define UNPACK_H_ 45 | 46 | void unpack0(unsigned int* p, unsigned int* w, int BS); 47 | void unpack1(unsigned int* p, unsigned int* w, int BS); 48 | void unpack2(unsigned int* p, unsigned int* w, int BS); 49 | void unpack3(unsigned int* p, unsigned int* w, int BS); 50 | void unpack4(unsigned int* p, unsigned int* w, int BS); 51 | void unpack5(unsigned int* p, unsigned int* w, int BS); 52 | void unpack6(unsigned int* p, unsigned int* w, int BS); 53 | void unpack7(unsigned int* p, unsigned int* w, int BS); 54 | void unpack8(unsigned int* p, unsigned int* w, int BS); 55 | void unpack9(unsigned int* p, unsigned int* w, int BS); 56 | void unpack10(unsigned int* p, unsigned int* w, int BS); 57 | void unpack11(unsigned int* p, unsigned int* w, int BS); 58 | void unpack12(unsigned int* p, unsigned int* w, int BS); 59 | void unpack13(unsigned int* p, unsigned int* w, int BS); 60 | void unpack16(unsigned int* p, unsigned int* w, int BS); 61 | void unpack20(unsigned int* p, unsigned int* w, int BS); 62 | void unpack32(unsigned int* p, unsigned int* w, int BS); 63 | 64 | // Pointer to a function 65 | typedef void (*pf)(unsigned int* p, unsigned int* w, int BS); 66 | 67 | #endif /* UNPACK_H_ */ 68 | --------------------------------------------------------------------------------