Changeset 42


Ignore:
Timestamp:
Feb 11, 2008, 7:53:48 AM (11 years ago)
Author:
cameron
Message:

lib_simd: refactored allocation, bitstream_scan

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/altivec_simd.h

    r41 r42  
    1 /*  Idealized SIMD Operations with Altivec, SSE and MMX versions
    2     Copyright (C) 2006, Robert D. Cameron
    3     Licensed to International Characters Inc.
     1/*  Idealized SIMD Operations - Altivec versions
     2    Copyright (C) 2006, 2008, Robert D. Cameron
     3    Licensed to the public under the Open Software License 3.0.
     4    Licensed to International Characters Inc.
    45       under the Academic Free License version 3.0.
    5        October 30, 2006 */
     6*/
    67
    78/*------------------------------------------------------------*/
     
    376377
    377378
    378 
    379 /* Scans for a 1 as long as it takes.  Use a sentinel to fence. */
    380 static inline int bitstream_scan(SIMD_type * stream, int bit_posn) {
    381   unsigned long * bitstream_ptr = (unsigned long *) (((intptr_t) stream) + bit_posn/8);
    382   unsigned long bitstream_slice = *bitstream_ptr << (bit_posn % 8);
    383   if (bitstream_slice != 0) return bit_posn + __builtin_clzl(bitstream_slice);
    384   else {
    385     do {
    386       bitstream_ptr++;
    387       bitstream_slice = *bitstream_ptr;
    388     } while (bitstream_slice == 0);
    389     int base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) stream);
    390     return base_posn + __builtin_clzl(bitstream_slice);
    391   }
    392 }
    393 
    394 // static inline int bitstream_scan(SIMD_type * stream, int bit_posn) {
    395 //   unsigned long * bitstream_ptr = (unsigned long *) (((intptr_t) stream) + bit_posn/8);
    396 //   unsigned long bitstream_slice = *bitstream_ptr >> bit_posn % 8;
    397 //   int base_posn = bit_posn;
    398 //   if (bitstream_slice == 0) {
    399 //     do {
    400 //       bitstream_ptr++;
    401 //       bitstream_slice = *bitstream_ptr;
    402 //     } while (bitstream_slice == 0);
    403 //     base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) stream);
    404 //   }
    405 //   return base_posn + __builtin_clzl(bitstream_slice);
    406 // }
    407 
    408 static inline int bitstream_scan0(SIMD_type * stream) {
    409   unsigned long * bitstream_ptr = (unsigned long *) stream;
    410   unsigned long bitstream_slice = *bitstream_ptr;
    411   int base_posn = 0;
    412   while (bitstream_slice == 0) {
    413     bitstream_ptr++;
    414     bitstream_slice = *bitstream_ptr;
    415 #ifdef BITSTREAM_SCAN_ACCUM_POSN
    416     base_posn += 8 * sizeof(unsigned long);
    417379#endif
    418   }
    419 #ifndef BITSTREAM_SCAN_ACCUM_POSN
    420   base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) stream);
    421 #endif
    422   return base_posn + __builtin_clzl(bitstream_slice);
    423 }
    424 
    425 /* Faked posix_memalign for PPC/MacOS X */
    426 static inline int posix_memalign(void ** ptr, size_t align, size_t bytes) {
    427         if (align > 16) {
    428                 printf("Alignment greater than 16 not supported.\n");
    429                 exit(-1);
    430         }
    431         *ptr = (void *) new char[bytes];
    432         return 0;
    433 }
    434 
    435 #endif
    436 
  • trunk/lib/sse_simd.h

    r34 r42  
    1 
    21/*  Idealized SIMD Operations with SSE versions
    32    Copyright (C) 2006, 2007, 2008, Robert D. Cameron
     
    663662}
    664663
    665 
    666 /* Scans for a 1 as long as it takes.  Use a sentinel to fence. */
    667 static inline int bitstream_scan(SIMD_type * stream, int bit_posn) {
    668   unsigned long * bitstream_ptr = (unsigned long *) (((intptr_t) stream) + bit_posn/8);
    669   unsigned long bitstream_slice = *bitstream_ptr & (-1L << bit_posn % 8);
    670   int base_posn;
    671   if (bitstream_slice == 0) {
    672     do {
    673       bitstream_ptr++;
    674       bitstream_slice = *bitstream_ptr;
    675     } while (bitstream_slice == 0);
    676   }
    677   base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) stream);
    678   return base_posn + __builtin_ctzl(bitstream_slice);
    679 }
    680 
    681 // static inline int bitstream_scan(SIMD_type * stream, int bit_posn) {
    682 //   unsigned long * bitstream_ptr = (unsigned long *) (((intptr_t) stream) + bit_posn/8);
    683 //   unsigned long bitstream_slice = *bitstream_ptr >> bit_posn % 8;
    684 //   int base_posn = bit_posn;
    685 //   if (bitstream_slice == 0) {
    686 //     do {
    687 //       bitstream_ptr++;
    688 //       bitstream_slice = *bitstream_ptr;
    689 //     } while (bitstream_slice == 0);
    690 //     base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) stream);
    691 //   }
    692 //   return base_posn + __builtin_ctzl(bitstream_slice);
    693 // }
    694 
    695 static inline int bitstream_scan0(SIMD_type * stream) {
    696   unsigned long * bitstream_ptr = (unsigned long *) stream;
    697   unsigned long bitstream_slice = *bitstream_ptr;
    698   int base_posn = 0;
    699   while (bitstream_slice == 0) {
    700     bitstream_ptr++;
    701     bitstream_slice = *bitstream_ptr;
    702 #ifdef BITSTREAM_SCAN_ACCUM_POSN
    703     base_posn += 8 * sizeof(unsigned long);
    704 #endif
    705   }
    706 #ifndef BITSTREAM_SCAN_ACCUM_POSN
    707   base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) stream);
    708 #endif
    709   return base_posn + __builtin_ctzl(bitstream_slice);
    710 }
    711 
    712 #endif
     664#endif
  • trunk/src/bitlex.c

    r40 r42  
    88
    99#include "bitlex.h"
    10 
    11 #ifdef __i386
    12 #include "../lib/sse_simd.h"
    13 #endif
    14 #ifdef _ARCH_PPC
    15 #include "../lib/altivec_simd.h"
    16 #endif
    17 
    18 #if BYTE_ORDER == BIG_ENDIAN
    19 #define sisd_sfl(blk, n) sisd_srl(blk, n)
    20 #define sisd_sbl(blk, n) sisd_sll(blk, n)
    21 #define sisd_sfli(blk, n) sisd_srli(blk, n)
    22 #define sisd_sbli(blk, n) sisd_slli(blk, n)
    23 #endif
    24 #if BYTE_ORDER == LITTLE_ENDIAN
    25 #define sisd_sfl(blk, n) sisd_sll(blk, n)
    26 #define sisd_sbl(blk, n) sisd_srl(blk, n)
    27 #define sisd_sfli(blk, n) sisd_slli(blk, n)
    28 #define sisd_sbli(blk, n) sisd_srli(blk, n)
    29 #endif
     10#include "../lib/lib_simd.h"
    3011
    3112
     
    3314        xml_buf = b;
    3415        parsing_engine_data = l;
    35         posix_memalign((void **) &x8basis, sizeof(BitBlock), BUFFER_SIZE);
     16        x8basis = (BitBlockBasis *) simd_new(BUFFER_SIZE/PACKSIZE);
    3617};
    3718
     
    450431
    451432void UTF_8_Lexer::Do_CharsetValidation() {
    452         printf("UTF_8_Lexer::Do_CharsetValidation not yet implemented; assuming OK.\n");
     433        //printf("UTF_8_Lexer::Do_CharsetValidation not yet implemented; assuming OK.\n");
    453434};
    454435
  • trunk/src/engine.c

    r37 r42  
    7171        scanner_timer = init_BOM_timer(BUFFER_BLOCKS * BLOCKSIZE);
    7272#endif
    73 /*      buf = new LexicalStreamSet;*/
    74         posix_memalign((void **) &buf, sizeof(BitBlock), sizeof(LexicalStreamSet));
    75 #ifdef DEBUG
    76         printf("parser->buf addr = %x\n", (int) buf);
    77 #endif
     73        buf = (LexicalStreamSet *) simd_new(sizeof(LexicalStreamSet)/PACKSIZE);
    7874
    7975  /* Install sentinels for every lexical item stream*/
  • trunk/src/xmlbuffer.c

    r35 r42  
    1515#include "multiliteral.h"
    1616#include "bytelex.h"
    17 #ifdef __i386
    18 #include "../lib/sse_simd.h"
    19 #endif
    20 #ifdef _ARCH_PPC
    21 #include "../lib/altivec_simd.h"
    22 #endif
    2317
    2418XML_Buffer_Interface::XML_Buffer_Interface() {}
     
    5852                exit(-1);
    5953        }
    60         int byte_stream_size = total_blocks * BLOCKSIZE + LOOKAHEAD_POSITIONS;
    61         posix_memalign((void **) &x16hi, sizeof(BytePack), byte_stream_size);
    62         posix_memalign((void **) &x16lo, sizeof(BytePack), byte_stream_size);
    63 /*
    64         x16hi = new BytePack[8*total_blocks+LOOKAHEAD_PACKS];
    65         x16lo = new BytePack[8*total_blocks+LOOKAHEAD_PACKS];
    66 */
    67 #ifdef DEBUG
    68         printf("x16hi addr = %x\n", (int) x16hi);
    69         printf("x16lo addr = %x\n", (int) x16lo);
    70 #endif
     54        x16hi = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
     55        x16lo = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
    7156}
    7257
     
    8974                exit(-1);
    9075        }
    91         int byte_stream_size = total_blocks * BLOCKSIZE + LOOKAHEAD_POSITIONS;
    92         posix_memalign((void **) &x32hh, sizeof(BytePack), byte_stream_size);
    93         posix_memalign((void **) &x32hl, sizeof(BytePack), byte_stream_size);
    94         posix_memalign((void **) &x32lh, sizeof(BytePack), byte_stream_size);
    95         posix_memalign((void **) &x32ll, sizeof(BytePack), byte_stream_size);
    96 /*      x32hh = new BytePack[8*total_blocks+LOOKAHEAD_PACKS];
    97         x32hl = new BytePack[8*total_blocks+LOOKAHEAD_PACKS];
    98         x32lh = new BytePack[8*total_blocks+LOOKAHEAD_PACKS];
    99         x32ll = new BytePack[8*total_blocks+LOOKAHEAD_PACKS];
    100 */
    101 #ifdef DEBUG
    102         printf("x32hh addr = %x\n", (int) x32hh);
    103         printf("x32hl addr = %x\n", (int) x32hl);
    104         printf("x32lh addr = %x\n", (int) x32lh);
    105         printf("x32ll addr = %x\n", (int) x32ll);
    106 #endif
     76        x32hh = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
     77        x32hl = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
     78        x32lh = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
     79        x32ll = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
    10780}
    10881
     
    143116        int total_packs = 8*total_blocks + LOOKAHEAD_PACKS;
    144117        for (int pk = 0; pk < total_packs; pk++) {
    145 /*              BytePack s0 = sisd_load_unaligned(&src_data[2*pk]);
    146                 BytePack s1 = sisd_load_unaligned(&src_data[2*pk+1]);*/
    147118                BytePack s0 = src_data[2*pk];
    148119                BytePack s1 = src_data[2*pk+1];
     
    170141        int total_packs = 8*total_blocks + LOOKAHEAD_PACKS;
    171142        for (int pk = 0; pk < total_packs; pk++) {
    172 /*              BytePack s0 = sisd_load_unaligned(&src_data[4*pk]);
    173                 BytePack s1 = sisd_load_unaligned(&src_data[4*pk+1]);
    174                 BytePack s2 = sisd_load_unaligned(&src_data[4*pk+2]);
    175                 BytePack s3 = sisd_load_unaligned(&src_data[4*pk+3]);*/
    176143                BytePack s0 = src_data[4*pk];
    177144                BytePack s1 = src_data[4*pk+1];
     
    230197void U16_Buffer::PreparePseudoASCII_Stream() {
    231198        int total_packs = 8*(buffer_bytes/2 + BLOCKSIZE - 1)/BLOCKSIZE + LOOKAHEAD_PACKS;
    232         posix_memalign((void **) &x8data, sizeof(BytePack), total_packs * PACKSIZE);
    233 /*      x8data = new BytePack[total_packs];*/
     199        x8data = simd_new(total_packs);
    234200        for (int pk = 0; pk < total_packs; pk++) {
    235201                x8data[pk] = simd_or(x16lo[pk],
     
    241207void U32_Buffer::PreparePseudoASCII_Stream() {
    242208        int total_packs = 8*(buffer_bytes/2 + BLOCKSIZE - 1)/BLOCKSIZE + LOOKAHEAD_PACKS;
    243         posix_memalign((void **) &x8data, sizeof(BytePack), total_packs * PACKSIZE);
    244 /*      x8data = new BytePack[total_packs];*/
     209        x8data = simd_new(total_packs);
    245210        for (int pk = 0; pk < total_packs; pk++) {
    246211                BytePack hi = simd_or(simd_or(x32hh[pk], x32hl[pk]), x32lh[pk]);
     
    294259XML_Buffer_Interface * XML_Buffer_Interface::BufferFactory(char* filename) {
    295260        int chars_read;
    296         BytePack * src_data;
    297261        struct stat fileinfo;
    298262        stat(filename, &fileinfo);
    299         int buffer_size = fileinfo.st_size + BUFFER_PADDING;
    300         posix_memalign((void **) &src_data, sizeof(BytePack), buffer_size);
    301 /*      src_data = new BytePack [buffer_size/PACKSIZE+1];*/
    302 #ifdef DEBUG
    303         printf("__alignof(*src_data) = %i\n", __alignof(*src_data));
    304         printf("src_data addr = %x\n", (int) src_data);
    305 #endif
     263        int buffer_packs = (fileinfo.st_size + BUFFER_PADDING + PACKSIZE - 1)/PACKSIZE;
     264        BytePack * src_data = simd_new(buffer_packs);
    306265        unsigned char * bytedata = (unsigned char *) src_data;
    307266        FILE *infile;
  • trunk/src/xmlbuffer.h

    r35 r42  
    1010
    1111#include "xmlparam.h"
    12 
    13 #ifdef __i386
    14 #include "../lib/sse_simd.h"
    15 #endif
    16 #ifdef _ARCH_PPC
    17 #include "../lib/altivec_simd.h"
    18 #endif
    19 
     12#include "../lib/lib_simd.h"
    2013
    2114/* The BytePack and the BitBlock are the two fundamental
Note: See TracChangeset for help on using the changeset viewer.