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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 545 - (view) (download) (as text)
Original Path: branches/pure-cfg/src/lib/diderot.h

1 : jhr 438 /*! \file diderot.h
2 :     *
3 :     * \author John Reppy
4 : jhr 441 *
5 :     * This is the interface to the Diderot runtime for the C target. For now,
6 :     * we are targetting single-precision computations.
7 : jhr 438 */
8 :    
9 :     /*
10 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
11 :     * All rights reserved.
12 :     */
13 :    
14 :     #ifndef _DIDEROT_H_
15 :     #define _DIDEROT_H_
16 :    
17 : jhr 440 #define STATIC_INLINE static inline
18 :    
19 : jhr 438 #include <stdint.h>
20 :     #include <stdbool.h>
21 :    
22 :     /* library-call status */
23 :     typedef enum { DIDEROT_OK = 0, DIDEROT_FAIL = -1 } Status_t;
24 :    
25 :     /* SSE vector types */
26 : jhr 441 typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
27 : jhr 545 typedef float vec2f __attribute__ ((vector_size (8)));
28 :     typedef float vec4f __attribute__ ((vector_size (16)));
29 :     typedef float vec8f __attribute__ ((vector_size (32)));
30 : jhr 438
31 : jhr 545 typedef float vec2d __attribute__ ((vector_size (16)));
32 :     typedef float vec4d __attribute__ ((vector_size (32)));
33 :     typedef float vec8d __attribute__ ((vector_size (64)));
34 : jhr 438
35 : jhr 545 typedef union { float r[2]; vec2f v; } union2f;
36 :     typedef union { float r[4]; vec4f v; } union4f;
37 :     typedef union { float r[8]; vec8f v; } union8f;
38 : jhr 438
39 : jhr 545 typedef union { double r[2]; vec2d v; } union2d;
40 :     typedef union { double r[4]; vec4d v; } union4d;
41 :     typedef union { double r[8]; vec8d v; } union8d;
42 :    
43 :     /* vector lengths must be power of 2, but vec3 is useful, so we pad to 4 */
44 :     typedef vec4f vec3f;
45 :     typedef vec4d vec3d;
46 :    
47 : jhr 438 /* typedefs for Diderot types */
48 :     typedef int32_t Diderot_int_t;
49 :     typedef float Diderot_real_t;
50 :     typedef f4union Diderot_vec3_t; // padded to fit in SSE register
51 :     typedef f4union Diderot_vec4_t;
52 :     typedef const char *Diderot_string_t;
53 :    
54 :     typedef struct { // wrapper for 1D image data
55 :     uint32_t dim; // dimension (== 1)
56 :     uint32_t size[1];
57 :     void *data;
58 : jhr 444 Diderot_Mat2x2_t m; // image to world-space transform
59 :     Diderot_Mat2x2_t mInv; // world to image-space transform (m inverse)
60 : jhr 438 } Diderot_image1D_t;
61 :    
62 :     typedef struct { // wrapper for 2D image data
63 :     uint32_t dim; // dimension (== 2)
64 :     uint32_t size[2]; // sizes (fast to slow)
65 :     void *data;
66 : jhr 444 Diderot_Mat3x3_t m; // image to world-space transform
67 :     Diderot_Mat3x3_t mInv; // world to image-space transform (m inverse)
68 :     Diderot_Mat3x3_t mInvT; // image to world-space transform for gradients
69 :     // (m inverse transpose)
70 : jhr 438 } Diderot_image2D_t;
71 :    
72 :     typedef struct { // wrapper for 3D image data
73 :     uint32_t dim; // dimension (== 3)
74 :     uint32_t size[3]; // sizes (fast to slow)
75 :     void *data;
76 : jhr 444 Diderot_Mat4x4_t m; // image to world-space transform
77 :     Diderot_Mat4x4_t mInv; // world to image-space transform (m inverse)
78 :     Diderot_Mat4x4_t mInvT; // image to world-space transform for gradients
79 :     // (m inverse transpose)
80 : jhr 438 } Diderot_image3D_t;
81 :    
82 :     /* Diderot library functions */
83 :    
84 :     /* load image data from Nrrd files */
85 : jhr 545 extern Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t **img);
86 :     extern Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t **img);
87 :     extern Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t **img);
88 : jhr 438
89 : jhr 439 /* functions to get input-parameter values */
90 : jhr 438 extern Status_t Diderot_InputString (const char *, const char **, bool);
91 :     extern Status_t Diderot_InputReal (const char *, Diderot_real_t *, bool);
92 : jhr 545 extern Status_t Diderot_InputVec3 (const char *, Diderot_vec3_t *, bool);
93 : jhr 438
94 : jhr 440 /* inline vector arithmetic functions */
95 : jhr 545 STATIC_INLINE vec3d Diderot_Vec3 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c)
96 : jhr 440 {
97 : jhr 545 return __extension__ (vec4f){ a, b, c, 0.0f };
98 : jhr 440 }
99 :    
100 : jhr 545 STATIC_INLINE vec4f Diderot_Vec4 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c, Diderot_real_t d)
101 : jhr 440 {
102 : jhr 545 return __extension__ (vec4f){ a, b, c, d };
103 : jhr 440 }
104 :    
105 : jhr 545 STATIC_INLINE vec4f Diderot_ScaleV3 (vec4f dstV, Diderot_real_t s, vec4f v)
106 : jhr 440 {
107 : jhr 441 return Diderot_Vec3(s, s, s) * v;
108 : jhr 440 }
109 :    
110 : jhr 441 // check if pos is inside the img, assuming that we have a border of width s.
111 :     //
112 :     STATIC_INLINE bool Diderot_Inside3D (Diderot_vec3_t pos, Diderot_image3D_t *img, int s)
113 :     {
114 :     // NOTE: there might be a vectorized way to do this compare!
115 : jhr 449 // cvtps2pi -- converts vector of floats to vector of int32_t values
116 :    
117 : jhr 441 return ((s <= pos.f[0]) && (pos.f[0] < (img->size[0] - s))
118 :     && (s <= pos.f[1]) && (pos.f[1] < (img->size[1] - s))
119 :     && (s <= pos.f[2]) && (pos.f[2] < (img->size[2] - s)));
120 :     }
121 :    
122 : jhr 438 #endif /* !_DIDEROT_H_ */

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