Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /tests/vec-tests/test.cxx
ViewVC logotype

View of /tests/vec-tests/test.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4640 - (download) (as text) (annotate)
Tue Sep 27 20:54:47 2016 UTC (2 years, 8 months ago) by glk
File size: 1638 byte(s)
initial result of svn export --username anonsvn --password=anonsvn https://svn.smlnj-gforge.cs.uchicago.edu/svn/diderot/branches/vis15/src/tests/
#include <iostream>

typedef float raw2f __attribute__ ((vector_size (8)));
typedef float raw4f __attribute__ ((vector_size (16)));
typedef float raw8f __attribute__ ((vector_size (32)));
typedef float raw16f __attribute__ ((vector_size (64)));

template <typename T, typename R, int d>
struct Vec
{
    R _rep;

    Vec (R const &r) : _rep(r) { }
    Vec (const T *mem);

    void load (const T *mem);
    void store (T *mem);
};

struct rep2f {
    raw2f v0;
    rep2f (const raw2f &v) : v0(v) { }
    rep2f (float a, float b) : v0((raw2f){a, b}) { }
};

typedef Vec<float,rep2f,2> vec2f;

inline rep2f vec_add (rep2f const &a, rep2f const &b) { return rep2f(a.v0 + b.v0); }
inline rep2f vec_sub (rep2f const &a, rep2f const &b) { return rep2f(a.v0 - b.v0); }
inline rep2f vec_scale (float s, rep2f const &a) { return rep2f((raw2f){s, s} * a.v0); }
inline rep2f vec_mul (rep2f const &a, rep2f const &b) { return rep2f(a.v0 * b.v0); }

template <typename T, typename R, int d>
inline Vec<T,R,d> operator+ (Vec<T,R,d> const &a, Vec<T,R,d> const &b)
{
    return Vec<T,R,d>(vec_add (a._rep, b._rep));
}

template<>
inline Vec<float,rep2f,2>::Vec (const float *mem) : _rep(mem[0],mem[1]) { }

template<>
inline void Vec<float,rep2f,2>::load (const float *mem)
{
    this->_rep = rep2f(mem[0],mem[1]);
}

static float Data[] = {0.0f, 1.0f, 12.5f, -3.0f};

int main (int argc, const char **argv)
{
//    vec2f u(rep2f (0.0f, 1.0f));
//    vec2f v(rep2f (12.5f, -3.0f));
    vec2f u(&Data[0]);
    vec2f v(&Data[2]);

    vec2f w = u + v;

    std::cout << "w = [" << w._rep.v0[0] << ", " << w._rep.v0[1] << "]" << std::endl;

    return 0;
}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0