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

SCM Repository

[diderot] View of /branches/lamont/src/include/Diderot/inline-vec6.h
ViewVC logotype

View of /branches/lamont/src/include/Diderot/inline-vec6.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2081 - (download) (as text) (annotate)
Mon Nov 5 23:26:06 2012 UTC (6 years, 11 months ago) by lamonts
File size: 1972 byte(s)
Creating new developmented branch based on vis12
/*! \file inline-vec6.h
 *
 * \author John Reppy
 *
 * \brief inline functions for 6-element vectors
 */

/*
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 */

#ifndef _DIDEROT_INLINE_VEC6_H_
#define _DIDEROT_INLINE_VEC6_H_

#ifndef _DIDEROT_TYPES_H_
#include "Diderot/types.h"
#endif

STATIC_INLINE Diderot_vec6_t vec6 (
    Diderot_real_t a, Diderot_real_t b, Diderot_real_t c,
    Diderot_real_t d, Diderot_real_t e, Diderot_real_t f)
{
  // Note that Diderot_vec6_t is represented as an 8-element vector
    return __extension__ (Diderot_vec6_t){ a, b, c, d, e, f, 0.0, 0.0 };
}

STATIC_INLINE Diderot_vec6_t scale6 (Diderot_real_t s, Diderot_vec6_t v)
{
    return vec6(s, s, s, s, s, s) * v;
}

STATIC_INLINE Diderot_vec6_t clamp6 (Diderot_vec6_t lo, Diderot_vec6_t hi, Diderot_vec6_t v)
{
  // FIXME: there is probably a vectorized way to compute this
    Diderot_union6_t a, b, c;
    a.v = lo; b.v = hi; c.v = v;
    return vec6(
	clamp(a.r[0], b.r[0], c.r[0]),
	clamp(a.r[1], b.r[1], c.r[1]),
	clamp(a.r[2], b.r[2], c.r[2]),
	clamp(a.r[3], b.r[3], c.r[3]),
	clamp(a.r[4], b.r[4], c.r[4]),
	clamp(a.r[5], b.r[5], c.r[5]));
}

STATIC_INLINE Diderot_vec6_t lerp6 (Diderot_vec6_t a, Diderot_vec6_t b, Diderot_real_t t)
{
    return a + scale6(t, b - a);
}

STATIC_INLINE Diderot_vec6_t floor6 (Diderot_vec6_t v)
{
    Diderot_union6_t u;
    u.v = v;
    return vec6(FLOOR(u.r[0]), FLOOR(u.r[1]), FLOOR(u.r[2]), FLOOR(u.r[3]), FLOOR(u.r[4]), FLOOR(u.r[5]));
}

STATIC_INLINE Diderot_real_t dot6 (Diderot_vec6_t u, Diderot_vec6_t v)
{
    Diderot_union6_t uv = __extension__ (Diderot_union6_t)(u*v);
    return uv.r[0] + uv.r[1] + uv.r[2] + uv.r[3] + uv.r[4] + uv.r[5];
}

STATIC_INLINE Diderot_real_t length6 (Diderot_vec6_t v)
{
    return SQRT(dot6(v, v));
}

STATIC_INLINE Diderot_vec6_t normalize6 (Diderot_vec6_t v)
{
    return scale6(1.0 / length6(v), v);
}

#endif /* !_DIDEROT_INLINE_VEC6_H_ */

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