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

SCM Repository

[diderot] View of /branches/pure-cfg/src/include/Diderot/inline-vec4.h
ViewVC logotype

View of /branches/pure-cfg/src/include/Diderot/inline-vec4.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (download) (as text) (annotate)
Tue Oct 27 15:16:36 2015 UTC (6 years ago) by jhr
File size: 2462 byte(s)
making copyrights consistent for all code in the repository
/*! \file inline-vec4.h
 *
 * \author John Reppy
 *
 * \brief inline functions for 4D vectors
 */

/*
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 */

#ifndef _DIDEROT_INLINE_VEC4_H_
#define _DIDEROT_INLINE_VEC4_H_

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

STATIC_INLINE Diderot_vec4_t vec4 (float a, float b, float c, float d)
{
    return __extension__ (Diderot_vec4_t){ a, b, c, d };
}

STATIC_INLINE Diderot_ivec4_t vec4rtoi (Diderot_vec4_t v)
{
    Diderot_union4_t u;
    u.v = v;
    return __extension__ (Diderot_ivec4_t){
            (Diderot_int_t)u.r[0],
            (Diderot_int_t)u.r[1],
            (Diderot_int_t)u.r[2],
            (Diderot_int_t)u.r[3]
        };
}

STATIC_INLINE Diderot_vec4_t vec4itor (Diderot_ivec4_t v)
{
    union4i_t u;
    u.v = v;
    return __extension__ (Diderot_vec4_t){ (float)u.i[0], (float)u.i[1], (float)u.i[2], (float)u.i[3] };
}

STATIC_INLINE Diderot_vec4_t scale4 (float s, Diderot_vec4_t v)
{
    return vec4(s, s, s, s) * v;
}

STATIC_INLINE Diderot_vec4_t clamp4 (Diderot_vec4_t lo, Diderot_vec4_t hi, Diderot_vec4_t v)
{
  // FIXME: there is probably a vectorized way to compute this
    Diderot_union4_t a, b, c;
    a.v = lo; b.v = hi; c.v = v;
    return vec4(
	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]));
}

STATIC_INLINE Diderot_vec4_t lerp4 (Diderot_vec4_t a, Diderot_vec4_t b, float t)
{
    return a + scale4(t, b - a);
}

STATIC_INLINE Diderot_vec4_t floor4 (Diderot_vec4_t v)
{
    Diderot_union4_t u;
    u.v = v;
    return vec4(FLOOR(u.r[0]), FLOOR(u.r[1]), FLOOR(u.r[2]), FLOOR(u.r[3]));
}

STATIC_INLINE Diderot_ivec4_t truncToInt4 (Diderot_vec4_t v)
{
    Diderot_union4_t t;
    t.v = v;
    return __extension__ (Diderot_ivec4_t){
	(Diderot_int_t)TRUNC(t.r[0]),
	(Diderot_int_t)TRUNC(t.r[1]),
	(Diderot_int_t)TRUNC(t.r[2]),
	(Diderot_int_t)TRUNC(t.r[3]) };
}

STATIC_INLINE float dot4 (Diderot_vec4_t u, Diderot_vec4_t v)
{
    Diderot_union4_t uv = __extension__ (Diderot_union4_t)(u*v);
    return uv.r[0] + uv.r[1] + uv.r[2] + uv.r[3];
}

STATIC_INLINE float length4 (Diderot_vec4_t v)
{
    return SQRT(dot4(v, v));
}

STATIC_INLINE Diderot_vec4_t normalize4 (Diderot_vec4_t v)
{
    return scale4(1.0 / length4(v), v);
}

#endif /* !_DIDEROT_INLINE_VEC4_H_ */

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