Changeset 959 for trunk/lib/lib_simd.h


Ignore:
Timestamp:
Mar 21, 2011, 5:14:08 PM (8 years ago)
Author:
cameron
Message:

SIMD library for AVX; initial check-in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/lib_simd.h

    r948 r959  
    11/*  lib_simd_h:  SIMD Library including idealized SIMD operations
    2     Copyright (C) 2008, Robert D. Cameron
     2    Copyright (C) 2011, Robert D. Cameron
    33    Licensed to the public under the Open Software License 3.0.
    44    Licensed to International Characters Inc.
     
    1616#include <limits.h>
    1717
    18 #ifndef LONG_BIT
    19 #if ULONG_MAX == 0xFFFFFFFF
    20 #define LONG_BIT 32
    21 #endif
    22 #if ULONG_MAX == 0xFFFFFFFFFFFFFFFF
    2318#define LONG_BIT 64
    24 #endif
    25 #endif
    26 
    27 #if (defined(__i386) || defined(__x86_64))
    28 #ifdef TEMPLATED_SIMD_LIB
    29 #include "sse_simd_t.h"
    30 #endif
    31 #ifndef TEMPLATED_SIMD_LIB
    32 #include "sse_simd.h"
    33 #endif
    34 #endif
    35 #ifdef _ARCH_PPC
    36 #include "altivec_simd.h"
    37 #endif
    38 
    39 /* Useful definitions from Linux kernel*/
    40 #ifdef __GNUC__
    41 /*
    42 #define likely(x) __builtin_expect((x),1)
    43 #define unlikely(x) __builtin_expect((x),0)
    44 */
    45 static inline long likely(long x) {
    46         return __builtin_expect(x, 1);
    47 }
    48 static inline long unlikely(long x) {
    49         return __builtin_expect(x, 0);
    50 }
    51 
    52 #endif
    53 #ifdef _MSC_VER
    54 #define inline __inline
    55 #include "lib/sse_simd.h"
    56 #define likely(x) (x)
    57 #define unlikely(x) (x)
    58 #endif
    59 
    60 #ifdef TEMPLATED_SIMD_LIB
    61 static inline SIMD_type sisd_sll(SIMD_type blk, SIMD_type n) {
    62         return simd<128>::sll(blk, n);
    63 }
    64 static inline SIMD_type sisd_srl(SIMD_type blk, SIMD_type n) {
    65         return simd<128>::srl(blk, n);
    66 }
    67 #define sisd_slli(blk, n) simd<128>::slli<n>(blk)
    68 #define sisd_srli(blk, n) simd<128>::srli<n>(blk)
    69 #endif
    70 
    71 
    72 /* Shift forward and back operations, based on endianness */
    73 #if BYTE_ORDER == BIG_ENDIAN
    74 #define sisd_sfl(blk, n) sisd_srl(blk, n)
    75 #define sisd_sbl(blk, n) sisd_sll(blk, n)
    76 #define sisd_sfli(blk, n) sisd_srli(blk, n)
    77 #define sisd_sbli(blk, n) sisd_slli(blk, n)
    78 #define sb_op(x, n) ((x)<<(n))
    79 #define sf_op(x, n) ((x)>>(n))
    80 #define cfzl __builtin_clzl
    81 #define cbzl __builtin_ctzl
    82 #endif
     19
     20#include "../lib/avx_simd.h"
    8321
    8422#if BYTE_ORDER == LITTLE_ENDIAN
     
    8927#define sb_op(x, n) ((x)>>(n))
    9028#define sf_op(x, n) ((x)<<(n))
     29
    9130#ifdef __GNUC__
    9231#define cfzl __builtin_ctzl
    9332#define cbzl __builtin_clzl
     33#define likely(x) __builtin_expect((x),1)
     34#define unlikely(x) __builtin_expect((x),0)
    9435#endif
    9536#ifdef _MSC_VER
     
    11657  if (v.elems[0] != 0) return cfzl(v.elems[0]);
    11758  else if (v.elems[1] != 0) return LONG_BIT + cfzl(v.elems[1]);
    118 #ifdef _MSC_VER
    11959  else if (v.elems[2] != 0) return 2*LONG_BIT + cfzl(v.elems[2]);
    12060  else if (v.elems[3] != 0) return 3*LONG_BIT + cfzl(v.elems[3]);
    121 #endif
    122 #ifndef _MSC_VER
    123 #if LONG_BIT < 64
    124   else if (v.elems[2] != 0) return 2*LONG_BIT + cfzl(v.elems[2]);
    125   else if (v.elems[3] != 0) return 3*LONG_BIT + cfzl(v.elems[3]);
    126 #endif
    127 #endif
    12861  else return 8*sizeof(SIMD_type);
    12962}
     
    13265  union {SIMD_type vec; unsigned long elems[sizeof(SIMD_type)/sizeof(long)];} v;
    13366  v.vec = bits;
    134 #if LONG_BIT == 64
    135   if (v.elems[1] != 0) return cbzl(v.elems[1]);
    136   else if (v.elems[0] != 0) return LONG_BIT + cbzl(v.elems[0]);
    137 #endif
    138 #if LONG_BIT < 64
    13967  if (v.elems[3] != 0) return cbzl(v.elems[3]);
    14068  else if (v.elems[2] != 0) return LONG_BIT + cbzl(v.elems[2]);
    14169  else if (v.elems[1] != 0) return 2*LONG_BIT + cbzl(v.elems[1]);
    14270  else if (v.elems[0] != 0) return 3*LONG_BIT + cbzl(v.elems[0]);
    143 #endif
    14471  else return 8*sizeof(SIMD_type);
    14572}
Note: See TracChangeset for help on using the changeset viewer.