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 441 - (view) (download) (as text)
Original Path: trunk/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 438 typedef float float4 __attribute__ ((__vector_size__ (16)));
28 : jhr 441 //typedef double double2 __attribute__ ((__vector_size__ (16)));
29 : jhr 438
30 :     /* union types for converting extracting vector data */
31 :     typedef union {
32 :     float f[4];
33 :     float4 v;
34 :     } f4union;
35 :    
36 :     typedef union {
37 :     double d[2];
38 :     double2 v;
39 :     } d2union;
40 :    
41 :     /* typedefs for Diderot types */
42 :     typedef int32_t Diderot_int_t;
43 :     typedef float Diderot_real_t;
44 :     typedef f4union Diderot_vec3_t; // padded to fit in SSE register
45 :     typedef f4union Diderot_vec4_t;
46 :     typedef const char *Diderot_string_t;
47 :    
48 :     typedef struct { // wrapper for 1D image data
49 :     uint32_t dim; // dimension (== 1)
50 :     uint32_t size[1];
51 :     void *data;
52 :     } Diderot_image1D_t;
53 :    
54 :     typedef struct { // wrapper for 2D image data
55 :     uint32_t dim; // dimension (== 2)
56 :     uint32_t size[2]; // sizes (fast to slow)
57 :     void *data;
58 :     } Diderot_image2D_t;
59 :    
60 :     typedef struct { // wrapper for 3D image data
61 :     uint32_t dim; // dimension (== 3)
62 :     uint32_t size[3]; // sizes (fast to slow)
63 :     void *data;
64 :     } Diderot_image3D_t;
65 :    
66 :     /* Diderot library functions */
67 :    
68 :     /* load image data from Nrrd files */
69 :     extern Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t *img);
70 :     extern Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t *img);
71 :     extern Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t *img);
72 :    
73 : jhr 439 /* functions to get input-parameter values */
74 : jhr 438 extern Status_t Diderot_InputString (const char *, const char **, bool);
75 :     extern Status_t Diderot_InputReal (const char *, Diderot_real_t *, bool);
76 :     extern Status_t Diderot_InputVec3 (const char *, Diderot_vec3_t *v);
77 :    
78 : jhr 440 /* inline vector arithmetic functions */
79 : jhr 441 STATIC_INLINE float4 Diderot_Vec3 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c)
80 : jhr 440 {
81 : jhr 441 return __extension__ (float4){ a, b, c, 0.0f };
82 : jhr 440 }
83 :    
84 : jhr 441 STATIC_INLINE float4 Diderot_Vec4 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c, Diderot_real_t d)
85 : jhr 440 {
86 : jhr 441 return __extension__ (float4){ a, b, c, d };
87 : jhr 440 }
88 :    
89 : jhr 441 STATIC_INLINE float4 Diderot_ScaleV3 (float4 dstV, Diderot_real_t s, float4 v)
90 : jhr 440 {
91 : jhr 441 return Diderot_Vec3(s, s, s) * v;
92 : jhr 440 }
93 :    
94 : jhr 441 STATIC_INLINE float4 Diderot_AddV3 (float4 a, float4 b)
95 :     {
96 :     return a + b;
97 :     }
98 :    
99 :     STATIC_INLINE float4 Diderot_MulV3 (float4 a, float4 b)
100 :     {
101 :     return a + b;
102 :     }
103 :    
104 :     // check if pos is inside the img, assuming that we have a border of width s.
105 :     //
106 :     STATIC_INLINE bool Diderot_Inside3D (Diderot_vec3_t pos, Diderot_image3D_t *img, int s)
107 :     {
108 :     // NOTE: there might be a vectorized way to do this compare!
109 :     return ((s <= pos.f[0]) && (pos.f[0] < (img->size[0] - s))
110 :     && (s <= pos.f[1]) && (pos.f[1] < (img->size[1] - s))
111 :     && (s <= pos.f[2]) && (pos.f[2] < (img->size[2] - s)));
112 :     }
113 :    
114 : jhr 438 #endif /* !_DIDEROT_H_ */

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