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/diderot.h
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 556 - (download) (as text) (annotate)
Tue Feb 22 19:58:28 2011 UTC (8 years, 9 months ago) by jhr
File size: 4244 byte(s)
  Move diderot.h header to include/Diderot
/*! \file diderot.h
 *
 * \author John Reppy
 *
 * This is the interface to the Diderot runtime for the C target.  For now,
 * we are targetting single-precision computations.
 */

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

#ifndef _DIDEROT_H_
#define _DIDEROT_H_

#define STATIC_INLINE	static inline

#include <stdint.h>
#include <stdbool.h>

/* library-call status */
typedef enum { DIDEROT_OK = 0, DIDEROT_FAIL = -1 } Status_t;

/* SSE vector types */
typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
typedef float vec2f __attribute__ ((vector_size (8)));
typedef float vec4f __attribute__ ((vector_size (16)));
typedef float vec8f __attribute__ ((vector_size (32)));

typedef float vec2d __attribute__ ((vector_size (16)));
typedef float vec4d __attribute__ ((vector_size (32)));
typedef float vec8d __attribute__ ((vector_size (64)));

typedef union { float r[2]; vec2f v; } union2f;
typedef union { float r[4]; vec4f v; } union4f;
typedef union { float r[8]; vec8f v; } union8f;

typedef union { double r[2]; vec2d v; } union2d;
typedef union { double r[4]; vec4d v; } union4d;
typedef union { double r[8]; vec8d v; } union8d;

/* vector lengths must be power of 2, but vec3 is useful, so we pad to 4 */
typedef vec4f vec3f;
typedef vec4d vec3d;

/* typedefs for Diderot types */
typedef int32_t Diderot_int_t;
typedef float Diderot_real_t;
typedef f4union Diderot_vec3_t;	// padded to fit in SSE register
typedef f4union Diderot_vec4_t;
typedef const char *Diderot_string_t;

typedef struct {		// wrapper for 1D image data
    uint32_t	dim;		// dimension (== 1)
    uint32_t	size[1];
    void	*data;
    Diderot_Mat2x2_t m;		// image to world-space transform
    Diderot_Mat2x2_t mInv;	// world to image-space transform (m inverse)
} Diderot_image1D_t;

typedef struct {		// wrapper for 2D image data
    uint32_t	dim;		// dimension (== 2)
    uint32_t	size[2];	// sizes (fast to slow)
    void	*data;
    Diderot_Mat3x3_t m;		// image to world-space transform
    Diderot_Mat3x3_t mInv;	// world to image-space transform (m inverse)
    Diderot_Mat3x3_t mInvT;	// image to world-space transform for gradients
				// (m inverse transpose)
} Diderot_image2D_t;

typedef struct {		// wrapper for 3D image data
    uint32_t	dim;		// dimension (== 3)
    uint32_t	size[3];	// sizes (fast to slow)
    void	*data;
    Diderot_Mat4x4_t m;		// image to world-space transform
    Diderot_Mat4x4_t mInv;	// world to image-space transform (m inverse)
    Diderot_Mat4x4_t mInvT;	// image to world-space transform for gradients
				// (m inverse transpose)
} Diderot_image3D_t;

/* Diderot library functions */

/* load image data from Nrrd files */
extern Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t **img);
extern Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t **img);
extern Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t **img);

/* functions to get input-parameter values */
extern Status_t Diderot_InputString (const char *, const char **, bool);
extern Status_t Diderot_InputReal (const char *, Diderot_real_t *, bool);
extern Status_t Diderot_InputVec3 (const char *, Diderot_vec3_t *, bool);

/* inline vector arithmetic functions */
STATIC_INLINE vec3f Diderot_Vec3 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c)
{
    return __extension__ (vec4f){ a, b, c, 0.0f };
}

STATIC_INLINE vec4f Diderot_Vec4 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c, Diderot_real_t d)
{
    return __extension__ (vec4f){ a, b, c, d };
}

STATIC_INLINE vec4f Diderot_ScaleV3 (vec4f dstV, Diderot_real_t s, vec4f v)
{
    return Diderot_Vec3(s, s, s) * v;
}

// check if pos is inside the img, assuming that we have a border of width s.
//
STATIC_INLINE bool Diderot_Inside3D (Diderot_vec3_t pos, Diderot_image3D_t *img, int s)
{
// NOTE: there might be a vectorized way to do this compare!
// cvtps2pi -- converts vector of floats to vector of int32_t values

    return ((s <= pos.f[0]) && (pos.f[0] < (img->size[0] - s))
	&&  (s <= pos.f[1]) && (pos.f[1] < (img->size[1] - s))
	&&  (s <= pos.f[2]) && (pos.f[2] < (img->size[2] - s)));
}

#endif /* !_DIDEROT_H_ */

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