sakurapyon’s blog

sakurapyon’s blog

難しい

何が原因なのかさっぱりわからん....

gcc バージョン 4.8.0 20130320 (Red Hat 4.8.0-0.18) (GCC)

#include        <stdint.h>
#include        <smmintrin.h>

typedef uint32_t        u32;

#define foreach_BitScan(b,var,proc)                             \
        {                                                               \
                u32     t;                                              \
                t = _mm_extract_epi32((b).mm, 0);                       \
                while(t){                                               \
                        var=__builtin_ctz(t);                           \
                        t&=(t-1);                                       \
                        proc;                                           \
                }                                                       \
                t = _mm_extract_epi32((b).mm, 1);                       \
                while(t){                                               \
                        var=__builtin_ctz(t)+27;                        \
                        t&=(t-1);                                       \
                        proc;                                           \
                }                                                       \
                t = _mm_extract_epi32((b).mm, 2);                       \
                while(t){                                               \
                        var=__builtin_ctz(t)+54;                        \
                        t&=(t-1);                                       \
                        proc;                                           \
                }                                                       \
        }
//
//
template        <int y>int x() { return y; }
template        <int y,int yy>int xx() { return yy; }

class   BitBoard {
public:
                union {
                        u32             bb[4];
                        __m128i         mm;
                } __attribute__ ((aligned));
};

main()
{
        BitBoard        a;
        int             b;

        foreach_BitScan(a,b,{
                x<1>();                 // ok
        });
        foreach_BitScan(a,b,{
                (xx<1,1>());            // ok
        });
        foreach_BitScan(a,b,{
                xx<1,1>();              // compile error
        });
}
g++ -m64 -msse4.2  b.cpp
b.cpp:54:3: エラー: マクロ "foreach_BitScan" に引数が 4 渡されましたが、3 しか受け取りません
  });
   ^
b.cpp: 関数 ‘int main()’ 内:
b.cpp:52:2: エラー: ‘foreach_BitScan’ was not declared in this scope
  foreach_BitScan(a,b,{
  ^