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 560 - (view) (download) (as text)

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 : jhr 558 #include <stdlib.h>
22 :     #include <math.h>
23 : jhr 438
24 :     /* library-call status */
25 :     typedef enum { DIDEROT_OK = 0, DIDEROT_FAIL = -1 } Status_t;
26 :    
27 :     /* SSE vector types */
28 : jhr 441 typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
29 : jhr 545 typedef float vec2f __attribute__ ((vector_size (8)));
30 :     typedef float vec4f __attribute__ ((vector_size (16)));
31 :     typedef float vec8f __attribute__ ((vector_size (32)));
32 : jhr 438
33 : jhr 560 typedef int32_t vec2i __attribute__ ((vector_size (8)));
34 :     typedef int32_t vec4i __attribute__ ((vector_size (16)));
35 :     typedef int32_t vec8i __attribute__ ((vector_size (32)));
36 :    
37 : jhr 545 typedef float vec2d __attribute__ ((vector_size (16)));
38 :     typedef float vec4d __attribute__ ((vector_size (32)));
39 :     typedef float vec8d __attribute__ ((vector_size (64)));
40 : jhr 438
41 : jhr 560 typedef int64_t vec2l __attribute__ ((vector_size (16)));
42 :     typedef int64_t vec4l __attribute__ ((vector_size (32)));
43 :     typedef int64_t vec8l __attribute__ ((vector_size (64)));
44 :    
45 : jhr 545 typedef union { float r[2]; vec2f v; } union2f;
46 :     typedef union { float r[4]; vec4f v; } union4f;
47 :     typedef union { float r[8]; vec8f v; } union8f;
48 : jhr 438
49 : jhr 560 typedef union { int32_t i[2]; vec2i v; } union2i;
50 :     typedef union { int32_t i[4]; vec4i v; } union4i;
51 :     typedef union { int32_t i[8]; vec8i v; } union8i;
52 :    
53 : jhr 545 typedef union { double r[2]; vec2d v; } union2d;
54 :     typedef union { double r[4]; vec4d v; } union4d;
55 :     typedef union { double r[8]; vec8d v; } union8d;
56 :    
57 : jhr 560 typedef union { int64_t r[2]; vec2l v; } union2l;
58 :     typedef union { int64_t r[4]; vec4l v; } union4l;
59 :     typedef union { int64_t r[8]; vec8l v; } union8l;
60 : jhr 558
61 : jhr 545 /* vector lengths must be power of 2, but vec3 is useful, so we pad to 4 */
62 :     typedef vec4f vec3f;
63 :     typedef vec4d vec3d;
64 : jhr 560 typedef vec4i vec3i;
65 :     typedef vec4l vec3l;
66 : jhr 545
67 : jhr 438 /* typedefs for Diderot types */
68 : jhr 560 #if defined(DIDEROT_SINGLE_PRECISION)
69 : jhr 438 typedef int32_t Diderot_int_t;
70 :     typedef float Diderot_real_t;
71 : jhr 557 typedef union4f Diderot_vec3_t; // padded to fit in SSE register
72 :     typedef union4f Diderot_vec4_t;
73 : jhr 560 #else
74 :     typedef int64_t Diderot_int_t;
75 :     typedef double Diderot_real_t;
76 :     typedef union4d Diderot_vec3_t; // padded to fit in SSE register
77 :     typedef union4d Diderot_vec4_t;
78 :     #endif
79 : jhr 438 typedef const char *Diderot_string_t;
80 :    
81 : jhr 557 typedef Diderot_real_t Diderot_Mat2x2_t[4];
82 :     typedef Diderot_real_t Diderot_Mat3x3_t[9];
83 :     typedef Diderot_real_t Diderot_Mat4x4_t[16];
84 :    
85 : jhr 438 typedef struct { // wrapper for 1D image data
86 :     uint32_t dim; // dimension (== 1)
87 :     uint32_t size[1];
88 :     void *data;
89 : jhr 444 Diderot_Mat2x2_t m; // image to world-space transform
90 :     Diderot_Mat2x2_t mInv; // world to image-space transform (m inverse)
91 : jhr 438 } Diderot_image1D_t;
92 :    
93 :     typedef struct { // wrapper for 2D image data
94 :     uint32_t dim; // dimension (== 2)
95 :     uint32_t size[2]; // sizes (fast to slow)
96 :     void *data;
97 : jhr 444 Diderot_Mat3x3_t m; // image to world-space transform
98 :     Diderot_Mat3x3_t mInv; // world to image-space transform (m inverse)
99 :     Diderot_Mat3x3_t mInvT; // image to world-space transform for gradients
100 :     // (m inverse transpose)
101 : jhr 438 } Diderot_image2D_t;
102 :    
103 :     typedef struct { // wrapper for 3D image data
104 :     uint32_t dim; // dimension (== 3)
105 :     uint32_t size[3]; // sizes (fast to slow)
106 :     void *data;
107 : jhr 444 Diderot_Mat4x4_t m; // image to world-space transform
108 :     Diderot_Mat4x4_t mInv; // world to image-space transform (m inverse)
109 :     Diderot_Mat4x4_t mInvT; // image to world-space transform for gradients
110 :     // (m inverse transpose)
111 : jhr 438 } Diderot_image3D_t;
112 :    
113 :     /* Diderot library functions */
114 :    
115 :     /* load image data from Nrrd files */
116 : jhr 558 extern Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t *img);
117 :     extern Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t *img);
118 :     extern Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t *img);
119 : jhr 438
120 : jhr 439 /* functions to get input-parameter values */
121 : jhr 438 extern Status_t Diderot_InputString (const char *, const char **, bool);
122 :     extern Status_t Diderot_InputReal (const char *, Diderot_real_t *, bool);
123 : jhr 545 extern Status_t Diderot_InputVec3 (const char *, Diderot_vec3_t *, bool);
124 : jhr 438
125 : jhr 560 /********** 3-element vector functions **********/
126 :    
127 : jhr 550 STATIC_INLINE vec3f Diderot_Vec3 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c)
128 : jhr 440 {
129 : jhr 545 return __extension__ (vec4f){ a, b, c, 0.0f };
130 : jhr 440 }
131 :    
132 : jhr 560 STATIC_INLINE vec4f Diderot_ScaleV3 (Diderot_real_t s, vec4f v)
133 : jhr 440 {
134 : jhr 560 return Diderot_Vec3(s, s, s) * v;
135 : jhr 440 }
136 :    
137 : jhr 560 STATIC_INLINE vec3i Diderot_TruncToIntV3 (vec3f v)
138 : jhr 440 {
139 : jhr 560 union4f t;
140 :     t.v = v;
141 :     return __extension__ (vec4i){
142 :     (int32_t)truncf(t.r[0]),
143 :     (int32_t)truncf(t.r[1]),
144 :     (int32_t)truncf(t.r[2]),
145 :     0 };
146 : jhr 440 }
147 :    
148 : jhr 560
149 :     /********** 4-element vector functions **********/
150 :    
151 :     STATIC_INLINE vec4f Diderot_Vec4 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c, Diderot_real_t d)
152 :     {
153 :     return __extension__ (vec4f){ a, b, c, d };
154 :     }
155 :    
156 :    
157 :     /********** other Diderot support functions **********/
158 :    
159 : jhr 441 // check if pos is inside the img, assuming that we have a border of width s.
160 :     //
161 :     STATIC_INLINE bool Diderot_Inside3D (Diderot_vec3_t pos, Diderot_image3D_t *img, int s)
162 :     {
163 :     // NOTE: there might be a vectorized way to do this compare!
164 : jhr 449 // cvtps2pi -- converts vector of floats to vector of int32_t values
165 :    
166 : jhr 557 return ((s <= pos.r[0]) && (pos.r[0] < (img->size[0] - s))
167 :     && (s <= pos.r[1]) && (pos.r[1] < (img->size[1] - s))
168 :     && (s <= pos.r[2]) && (pos.r[2] < (img->size[2] - s)));
169 : jhr 441 }
170 :    
171 : jhr 438 #endif /* !_DIDEROT_H_ */

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