Changeset 87


Ignore:
Timestamp:
Apr 2, 2008, 3:44:45 PM (11 years ago)
Author:
cameron
Message:

Adaptations for MSVC

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/altivec_simd.h

    r58 r87  
    266266
    267267
    268 static inline int count_forward_zeroes(SIMD_type bits) {
    269   union {SIMD_type vec; unsigned long elems[sizeof(SIMD_type)/LONG_BIT];} v;
    270   v.vec = bits;
    271   if (v.elems[0] != 0) return __builtin_clzl(v.elems[0]);
    272   else if (v.elems[1] != 0) return LONG_BIT + __builtin_clzl(v.elems[1]);
    273 #if LONG_BIT < 64
    274   else if (v.elems[2] != 0) return 2*LONG_BIT + __builtin_clzl(v.elems[2]);
    275   else if (v.elems[3] != 0) return 3*LONG_BIT + __builtin_clzl(v.elems[3]);
    276 #endif
    277   else return 8*sizeof(SIMD_type);
    278 }
    279 
    280 
    281 
    282 
    283268void print_bit_block(char * var_name, SIMD_type v) {
    284269  union {SIMD_type vec; unsigned char elems[16];} x;
  • trunk/lib/lib_simd.h

    r75 r87  
    2424
    2525/* Useful definitions from Linux kernel*/
     26#ifdef __GNUC__
    2627#define likely(x) __builtin_expect((x),1)
    2728#define unlikely(x) __builtin_expect((x),0)
     29#endif
     30#ifdef _MSC_VER
     31#define likely(x) (x)
     32#define unlikely(x) (x)
     33#endif
    2834
    2935/* Shift forward and back operations, based on endianness */
     
    4450#define sb_op(x, n) ((x)>>(n))
    4551#define sf_op(x, n) ((x)<<(n))
     52#ifdef __GNUC__
    4653#define cfzl __builtin_ctzl
    4754#endif
     55#ifdef _MSC_VER
     56#include <intrin.h>
     57#pragma intrinsic(_BitScanForward)
     58//  precondition: x > 0
     59static inline unsigned long cfzl(unsigned long x) {
     60        unsigned long zeroes;
     61        _BitScanForward(&zeroes, x);
     62        return zeroes;
     63}
     64#endif
     65#endif
     66
     67
     68static inline int count_forward_zeroes(SIMD_type bits) {
     69  union {SIMD_type vec; unsigned long elems[sizeof(SIMD_type)/sizeof(long)];} v;
     70  v.vec = bits;
     71  if (v.elems[0] != 0) return cfzl(v.elems[0]);
     72  else if (v.elems[1] != 0) return LONG_BIT + cfzl(v.elems[1]);
     73#if LONG_BIT < 64
     74  else if (v.elems[2] != 0) return 2*LONG_BIT + cfzl(v.elems[2]);
     75  else if (v.elems[3] != 0) return 3*LONG_BIT + cfzl(v.elems[3]);
     76#endif
     77  else return 8*sizeof(SIMD_type);
     78}
     79
    4880
    4981/* Scans for a 1 as long as it takes.  Use a sentinel to fence.
     
    87119        return new SIMD_type [SIMD_packs];
    88120#endif
    89 #ifndef __APPLE__
     121#ifdef _MSC_VER
     122        SIMD_type * v = (SIMD_type*)_aligned_malloc(sizeof(SIMD_type) * SIMD_packs, sizeof(SIMD_type));
     123        if (v != 0) return v;
     124        else {
     125                printf("Failed to allocated new array of %i SIMD packs.\n", SIMD_packs);
     126                exit(-1);
     127        }
     128#endif
     129#if !defined(__APPLE__) && !defined(_MSC_VER)
    90130        SIMD_type * v;
    91131        int rslt = posix_memalign((void **) &v,
     
    94134        if (rslt == 0) return v;
    95135        else {
    96                 printf("Failed to allocated new array of %i SIMD packs.\n");
     136                printf("Failed to allocated new array of %i SIMD packs.\n", SIMD_packs);
    97137                exit(-1);
    98138        }
  • trunk/lib/sse_simd.h

    r58 r87  
    2828#define simd_if(cond, then_val, else_val) \
    2929  simd_or(simd_and(then_val, cond), simd_andc(else_val, cond))
    30 #define simd_not(b) (~b)
    31 #define simd_nor(a,b) (~simd_or(a,b))
     30#define simd_not(b) (simd_xor(b, _mm_set1_epi32(0xFFFFFFFF)))
     31#define simd_nor(a,b) (simd_not(simd_or(a,b)))
    3232
    3333
     
    186186#define sisd_from_int(n) _mm_cvtsi32_si128(n)
    187187
    188 char mask_x55 [16] __attribute__ ((aligned(16))) =
    189     {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
    190 char mask_x33 [16] __attribute__ ((aligned(16))) =
    191     {0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33};
    192 char mask_x0F [16] __attribute__ ((aligned(16))) =
    193     {0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F};
    194 
    195188static inline int simd_all_true_8(SIMD_type v) {
    196189  return _mm_movemask_epi8(v) == 0xFFFF;
     
    637630  return _mm_shuffle_epi32(x,0);
    638631}
    639 
    640 
    641632
    642633
     
    665656}
    666657
    667 
    668 static inline int count_forward_zeroes(SIMD_type bits) {
    669   union {SIMD_type vec; unsigned long elems[sizeof(SIMD_type)/LONG_BIT];} v;
    670   v.vec = bits;
    671   if (v.elems[0] != 0) return __builtin_ctzl(v.elems[0]);
    672   else if (v.elems[1] != 0) return LONG_BIT + __builtin_ctzl(v.elems[1]);
    673 #if LONG_BIT < 64
    674   else if (v.elems[2] != 0) return 2*LONG_BIT + __builtin_ctzl(v.elems[2]);
    675   else if (v.elems[3] != 0) return 3*LONG_BIT + __builtin_ctzl(v.elems[3]);
    676 #endif
    677   else return 8*sizeof(SIMD_type);
    678 }
    679 
    680 #endif
     658#endif
     659
  • trunk/markup_stats.cxx

    r81 r87  
    1313#include <sys/types.h>
    1414#include <sys/stat.h>
    15 #include <unistd.h>
    1615#include <string>
    1716#include <iostream>
  • trunk/src/byteplex.h

    r83 r87  
    9090protected:
    9191
    92         unsigned int packs_in_buffer;
     92        int packs_in_buffer;
    9393        void Set_limits(int units_in_buffer);
    9494
Note: See TracChangeset for help on using the changeset viewer.