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

SCM Repository

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

View of /trunk/src/include/Diderot/inline-vec4.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1115 - (download) (as text) (annotate)
Thu May 5 04:42:18 2011 UTC (8 years, 11 months ago) by jhr
File size: 1757 byte(s)
  More merging of pure-cfg back into trunk
/*! \file inline-vec4.h
 *
 * \author John Reppy
 *
 * \brief inline functions for 4D vectors
 */

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

#ifndef _DIDEROT_INLINE_VEC4_H_
#define _DIDEROT_INLINE_VEC4_H_

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

STATIC_INLINE vec4f_t vec4f (float a, float b, float c, float d)
{
    return __extension__ (vec4f_t){ a, b, c, d };
}

STATIC_INLINE vec4i_t vec4ftoi (vec4f_t v)
{
    union4f_t u;
    u.v = v;
    return __extension__ (vec4i_t){ (int32_t)u.r[0], (int32_t)u.r[1], (int32_t)u.r[2], (int32_t)u.r[3] };
}

STATIC_INLINE vec4f_t vec4itof (vec4i_t v)
{
    union4i_t u;
    u.v = v;
    return __extension__ (vec4f_t){ (float)u.i[0], (float)u.i[1], (float)u.i[2], (float)u.i[3] };
}

STATIC_INLINE vec4f_t scale4f (float s, vec4f_t v)
{
    return vec4f(s, s, s, s) * v;
}

STATIC_INLINE vec4f_t lerp4f (vec4f_t a, vec4f_t b, float t)
{
    return a + scale4f(t, b - a);
}

STATIC_INLINE vec4f_t floor4f (vec4f_t v)
{
    union4f_t u;
    u.v = v;
    return vec4f(floorf(u.r[0]), floorf(u.r[1]), floorf(u.r[2]), floorf(u.r[3]));
}

STATIC_INLINE vec4i_t truncToInt4f (vec4f_t v)
{
    union4f_t t;
    t.v = v;
    return __extension__ (vec4i_t){
	(int32_t)truncf(t.r[0]),
	(int32_t)truncf(t.r[1]),
	(int32_t)truncf(t.r[2]),
	(int32_t)truncf(t.r[4]) };
}

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

STATIC_INLINE float length4f (vec4f_t v)
{
    return sqrtf(dot4f(v, v));
}

STATIC_INLINE vec4f_t normalize4f (vec4f_t v)
{
    return scale4f(1.0 / length4f(v), v);
}

#endif /* !_DIDEROT_INLINE_VEC4_H_ */

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