-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathllvm_template.c.in
444 lines (347 loc) · 9.82 KB
/
llvm_template.c.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/*
* llvm_template.c.in
*
* MathMap
*
* Copyright (C) 2002-2009 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <math.h>
#include <complex.h>
#include <stdio.h>
/*
#if !$g
#define OPENSTEP
#endif
*/
#define IN_COMPILED_CODE
#include "opmacros.h"
#include "lispreader/pools.h"
$def_mmpools
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)<(b))?(b):(a))
#endif
#define M_PI 3.14159265358979323846 /* pi */
$def_edge_behaviour
$def_userval_image
$def_num_floatmap_channels
$def_userval_points
$def_max_debug_tuples
$def_tuple
typedef unsigned int color_t;
#define MAKE_RGBA_COLOR(r,g,b,a) ((((color_t)(r))<<24)|(((color_t)(g))<<16)|(((color_t)(b))<<8)|((color_t)(a)))
#define RED(c) ((c)>>24)
#define GREEN(c) (((c)>>16)&0xff)
#define BLUE(c) (((c)>>8)&0xff)
#define ALPHA(c) ((c)&0xff)
$def_image_types
struct _mathmap_invocation_t;
struct _mathmap_frame_t;
struct _mathmap_slice_t;
struct _userval_t;
struct _image_t;
$def_filter_funcs
typedef struct
{
double r, g, b, a;
} GimpRGB;
typedef struct _GtkObject GtkObject;
$def_userval
struct _input_drawable_t;
struct _mathfuncs_t;
$def_image
typedef struct _filter_t filter_t;
typedef struct _interpreter_insn_t interpreter_insn_t;
typedef struct _GArray GArray;
typedef void* initfunc_t;
$def_mathmap
$def_mathfuncs
$def_orig_val_pixel_func
/* dummy declarations - we never need those here */
typedef void* GMutex;
typedef void* GCond;
typedef void* native_filter_cache_entry_t;
$def_invocation_frame_slice
$def_builtins
$def_image_new_id
$def_make_resize_image
$def_libnoise
typedef struct _tree_vector_t tree_vector_t;
$def_tree_vector_funcs
double g_random_double_range (double min, double max);
struct _gsl_vector;
typedef struct _gsl_vector gsl_vector;
struct _gsl_matrix;
typedef struct _gsl_matrix gsl_matrix;
gsl_matrix * gsl_matrix_alloc (const size_t n1, const size_t n2);
void gsl_matrix_free (gsl_matrix * m);
void gsl_matrix_set(gsl_matrix * m, const size_t i, const size_t j, const double x);
gsl_vector *gsl_vector_alloc (const size_t n);
void gsl_vector_free (gsl_vector * v);
double gsl_vector_get (const gsl_vector * v, const size_t i);
void gsl_vector_set (gsl_vector * v, const size_t i, double x);
int gsl_linalg_HH_solve (gsl_matrix * A, const gsl_vector * b, gsl_vector * x);
#define GSL_PREC_SINGLE 1
double gsl_sf_ellint_Kcomp (double k, unsigned int mode);
double gsl_sf_ellint_Ecomp (double k, unsigned int mode);
double gsl_sf_ellint_F (double phi, double k, unsigned int mode);
double gsl_sf_ellint_E (double phi, double k, unsigned int mode);
double gsl_sf_ellint_P (double phi, double k, double n, unsigned int mode);
double gsl_sf_ellint_D (double phi, double k, double n, unsigned int mode);
double gsl_sf_ellint_RC (double x, double y, unsigned int mode);
double gsl_sf_ellint_RD (double x, double y, double z, unsigned int mode);
double gsl_sf_ellint_RF (double x, double y, double z, unsigned int mode);
double gsl_sf_ellint_RJ (double x, double y, double z, double p, unsigned int mode);
int gsl_sf_elljac_e (double u, double m, double *sn, double *cn, double *dn);
complex float cgamma (complex float z);
double gsl_sf_beta (double a, double b);
double gsl_sf_gamma (double x);
extern void save_debug_tuples (mathmap_invocation_t *invocation, int row, int col);
#undef OUTPUT_TUPLE
#define OUTPUT_TUPLE(t) ((*return_tuple = (t)), 0)
complex float
make_complex (float r, float i)
{
return COMPLEX(r, i);
}
color_t
make_color (int r, int g, int b, int a)
{
return MAKE_RGBA_COLOR(r, g, b, a);
}
float*
alloc_tuple (mathmap_pools_t *pools, int n)
{
return ALLOC_TUPLE(n);
}
void
tuple_set (float *tuple, int n, float x)
{
TUPLE_SET(tuple, n, x);
}
tree_vector_t*
alloc_tree_vector (mathmap_pools_t *pools, int n, float *v)
{
return new_tree_vector(pools, n, v);
}
mathmap_frame_t*
get_slice_frame (mathmap_slice_t *slice)
{
return slice->frame;
}
mathmap_pools_t*
get_slice_pools (mathmap_slice_t *slice)
{
return &slice->pools;
}
mathmap_invocation_t*
get_frame_invocation (mathmap_frame_t *frame)
{
return frame->invocation;
}
void
set_frame_xy_vars (mathmap_frame_t *frame, void *xy_vars)
{
frame->xy_vars = xy_vars;
}
void*
get_frame_xy_vars (mathmap_frame_t *frame)
{
return frame->xy_vars;
}
float
get_frame_t (mathmap_frame_t *frame)
{
return frame->current_t;
}
mathmap_pools_t*
get_frame_pools (mathmap_frame_t *frame)
{
return &frame->pools;
}
int
get_invocation_img_width (mathmap_invocation_t *invocation)
{
return invocation->img_width;
}
int
get_invocation_img_height (mathmap_invocation_t *invocation)
{
return invocation->img_height;
}
int
get_invocation_render_width (mathmap_invocation_t *invocation)
{
return invocation->render_width;
}
int
get_invocation_render_height (mathmap_invocation_t *invocation)
{
return invocation->render_height;
}
float
get_invocation_image_R (mathmap_invocation_t *invocation)
{
return invocation->image_R;
}
void*
calc_closure_xy_vars (mathmap_invocation_t *invocation, image_t *closure, float t,
void* (*init_frame) (mathmap_invocation_t*, image_t*, float, mathmap_pools_t*))
{
if (!closure->v.closure.xy_vars)
{
#ifdef POOLS_DEBUG_OUTPUT
printf("calcing xy_vars of closure %p with pools %p\n", closure, closure->v.closure.pools);
#endif
closure->v.closure.xy_vars = init_frame(invocation, closure, t, closure->v.closure.pools);
#ifdef POOLS_DEBUG_OUTPUT
printf("done calcing xy_vars of closure %p\n", closure);
#endif
}
return closure->v.closure.xy_vars;
}
float
promote_int_to_float (int x)
{
return (float)x;
}
complex float
promote_int_to_complex (int x)
{
return (complex float)x;
}
complex float
promote_float_to_complex (float x)
{
return x;
}
image_t*
get_uninited_image (void)
{
return UNINITED_IMAGE;
}
$def_llvm_mathfuncs
image_t*
alloc_closure_image (mathmap_invocation_t *invocation, mathmap_pools_t *pools, int num_args, filter_func_t filter_func,
llvm_init_frame_func_t init_frame_func, llvm_filter_func_t main_filter_func,
init_x_or_y_func_t init_x_func, init_x_or_y_func_t init_y_func)
{
image_t *image = ALLOC_CLOSURE_IMAGE(num_args);
mathfuncs_t *funcs = (mathfuncs_t*)mathmap_pools_alloc(pools, sizeof(mathfuncs_t));
#ifdef POOLS_DEBUG_OUTPUT
printf("alloced closure %p from pools %p\n", image, pools);
#endif
funcs->init_frame = llvm_filter_init_frame;
funcs->init_slice = llvm_filter_init_slice;
funcs->calc_lines = llvm_filter_calc_lines;
funcs->llvm_init_frame_func = init_frame_func;
funcs->main_filter_func = main_filter_func;
funcs->init_x_func = init_x_func;
funcs->init_y_func = init_y_func;
image->v.closure.funcs = NULL;
image->v.closure.pools = pools;
image->v.closure.funcs = funcs;
image->v.closure.func = filter_func;
image->v.closure.xy_vars = NULL;
return image;
}
userval_t*
alloc_uservals (mathmap_pools_t *pools, int num)
{
return (userval_t*)mathmap_pools_alloc(pools, sizeof(userval_t) * num);
}
userval_t*
get_closure_uservals (image_t *image)
{
return image->v.closure.args;
}
void
set_userval_int (userval_t *uservals, int index, int arg)
{
uservals[index].v.int_const = arg;
}
void
set_userval_float (userval_t *uservals, int index, float arg)
{
uservals[index].v.float_const = arg;
}
void
set_userval_bool (userval_t *uservals, int index, float arg)
{
uservals[index].v.bool_const = arg;
}
void
set_userval_color (userval_t *uservals, int index, color_t arg)
{
uservals[index].v.color.value = arg;
}
void
set_userval_curve (userval_t *uservals, int index, curve_t *arg)
{
uservals[index].v.curve = arg;
}
void
set_userval_gradient (userval_t *uservals, int index, gradient_t *arg)
{
uservals[index].v.gradient = arg;
}
void
set_userval_image (userval_t *uservals, int index, image_t *arg)
{
uservals[index].v.image = arg;
}
void
set_closure_size_from_image (image_t *image, image_t *arg)
{
image->pixel_width = IMAGE_PIXEL_WIDTH(arg);
image->pixel_height = IMAGE_PIXEL_HEIGHT(arg);
}
void
set_closure_pixel_size (image_t *image, int width, int height)
{
image->pixel_width = width;
image->pixel_height = height;
}
$def_native_filters
image_t*
llvm_native_filter_gaussian_blur (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_gaussian_blur(invocation, args, pools);
}
image_t*
llvm_native_filter_convolve (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_convolve(invocation, args, pools);
}
image_t*
llvm_native_filter_half_convolve (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_half_convolve(invocation, args, pools);
}
image_t*
llvm_native_filter_visualize_fft (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_visualize_fft(invocation, args, pools);
}
#undef OUTPUT_TUPLE
#define OUTPUT_TUPLE(x) 0
#define get_orig_val_pixel_func (invocation->orig_val_func)
#define ARG(n) (closure->v.closure.args[(n)])
#include "llvm-ops.h"