/*! \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 clamp4f (vec4f_t lo, vec4f_t hi, vec4f_t v) { // FIXME: there is probably a vectorized way to compute this union4f_t a, b, c; a.v = lo; b.v = hi; c.v = v; return vec4f( clampf(a.r[0], b.r[0], c.r[0]), clampf(a.r[1], b.r[1], c.r[1]), clampf(a.r[2], b.r[2], c.r[2]), clampf(a.r[3], b.r[3], c.r[3])); } 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_ */
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: e4f (vec4f_t v) { return scale4f(1.0 / length4f(v), v); } #endif /* !_DIDEROT_INLINE_VEC4_H_ */