Blame view

src/kernels/cl_bitmap_src.h 39.7 KB
94b2b13d   Pedro Roque   PHACT source
1
2
3
4
/*
 * cl_bitmap_src.h
 *
 *  Created on: 14/02/2017
4d26a735   Pedro Roque   Increased recogni...
5
 *      Author: pedro
94b2b13d   Pedro Roque   PHACT source
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
 */

#if CL_D_TYPE == CL_BITMAP

#ifndef __OPENCL_VERSION__
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
#include "../utils/cl_syntax.h"
#endif

#include "../domains.h"
#include "cl_aux_functions.h"
#include "cl_bitmaps.h"
#include "cl_variables.h"

#include "../config.h"
#include "cl_ttl.h"

#ifndef M1
#define M1 NOTHING
#endif

#ifndef M2
#define M2 NOTHING
#endif

#ifndef M3
#define M3 NOTHING
#endif

#ifndef M4
#define M4 NOTHING
#endif

#ifndef FUNC_NAME
#	define CONCAT(name, suffix) name ## suffix
#	define FUNC_NAME(name, suffix) CONCAT(name, suffix)
#	define FUNC(name) FUNC_NAME(name, SUFFIX)
#endif

#if SUFFIX == _pg || SUFFIX == _gp || SUFFIX == _mg || SUFFIX == _n
/*
 * Create a new domain with the received values
 * d - new domain to create
 * d_vals - vector with all the values allowed for the new variable. The values must be ordered by increasing order
 * n_vals - number of domain values in values vector
 * */
4d26a735   Pedro Roque   Increased recogni...
54
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_new_vals)(M1 cl_bitmap* d, M2 int* d_vals, int n_vals TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
55
56
57
58
59
60
61
62

	int i;

#if CL_N_WORDS == 1
	(*d) = 0;
#else
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 104)
4d26a735   Pedro Roque   Increased recogni...
63
		(*d)[i] = 0;
94b2b13d   Pedro Roque   PHACT source
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
	}
#endif

	for (i = 0; i < n_vals; i++) {
		CHECK_TTL(ttl_ctr, 9)

#if CL_CHECK_ERRORS
		if (d_vals[i] < 0 || d_vals[i] > CL_D_MAX) {
			printf((__constant char *)"\n###error 2\n");
		}
#endif

#if CL_N_WORDS == 1
		(*d) |= CL_ONE_ << d_vals[i];
#else
		(*d)[d_vals[i] >> CL_DIV] |= (CL_ONE_ << (d_vals[i] - ((d_vals[i] >> CL_DIV) << CL_DIV)));
#endif
	}
}
#endif

#if SUFFIX == _m || SUFFIX == _n || SUFFIX == _g
/*
 * Check if domain is empty
 * empty - will be 1 if domain is empty or 0 if not
 * d - domain to check if empty
 */
4d26a735   Pedro Roque   Increased recogni...
91
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_is_empty)(bool* empty, M1 cl_bitmap* d TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
92
93
#if CL_N_WORDS == 1
	*empty = ((*d) == 0);
4d26a735   Pedro Roque   Increased recogni...
94
	CHECK_TTL(ttl_ctr, 207)
94b2b13d   Pedro Roque   PHACT source
95
#else
4d26a735   Pedro Roque   Increased recogni...
96
	*empty = 1;
94b2b13d   Pedro Roque   PHACT source
97

4d26a735   Pedro Roque   Increased recogni...
98
99
100
101
102
103
	int i;
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d)[i] != 0) {
			*empty = 0;
			i = CL_N_WORDS;
94b2b13d   Pedro Roque   PHACT source
104
		}
4d26a735   Pedro Roque   Increased recogni...
105
	}
94b2b13d   Pedro Roque   PHACT source
106
107
108
109
110
111
112
113
114
115
#endif
}
#endif

#if SUFFIX == _g
/*
 * calculate the minimum of the domain. (Assume domain is not empty)
 * min - the minimum value will be placed here
 * d - domain to calculate minimum value
 */
4d26a735   Pedro Roque   Increased recogni...
116
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_calc_min_val)(int* min, M1 cl_bitmap* d TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
117
118
119
120
121
122
123
124
125
126
127

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = ((*d) == 0);
	CHECK_TTL(ttl_ctr, 208)
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
128
129
130
131
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
132
133
134
135
136
137
138
139
140
	}
#endif
	if (empty) {
		printf((__constant char *)"\n###error 3\n");
	}
#endif

#if CL_WORD == 32
// vector for speeding up the finding of a domain minimum 32 bits. De Bruijn sequence https://en.wikipedia.org/wiki/De_Bruijn_sequence
4d26a735   Pedro Roque   Increased recogni...
141
	unsigned short mult_bit_pos_32[32] = { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 };
94b2b13d   Pedro Roque   PHACT source
142
#else
4d26a735   Pedro Roque   Increased recogni...
143
// vector for speeding up the finding of a domain minimum 64 bits. De Bruijn sequence http://commsys.ijs.si/~matjaz/maxclique/MaxCliquePara/source_MaxCliquePara_v2.2/BitSet.h
94b2b13d   Pedro Roque   PHACT source
144
	unsigned short mult_bit_pos_64[64] = { 0, 1, 2, 56, 3, 32, 57, 46, 29, 4, 20, 33, 7, 58, 11, 47, 62, 30, 18, 5, 16, 21, 34, 23, 53, 8, 59, 36, 25, 12, 48, 39, 63, 55, 31,
4d26a735   Pedro Roque   Increased recogni...
145
		45, 28, 19, 6, 10, 61, 17, 15, 22, 52, 35, 24, 38, 54, 44, 27, 9, 60, 14, 51, 37, 43, 26, 13, 50, 42, 49, 41, 40 };
94b2b13d   Pedro Roque   PHACT source
146
147
148
#endif

#if CL_N_WORDS == 1 && CL_WORD == 32
4d26a735   Pedro Roque   Increased recogni...
149
	CHECK_TTL(ttl_ctr, 209)
94b2b13d   Pedro Roque   PHACT source
150

4d26a735   Pedro Roque   Increased recogni...
151
	*min = mult_bit_pos_32[(CL_WORD_TYPE) (((*d) & -(*d)) * 0x077CB531U) >> 27];
94b2b13d   Pedro Roque   PHACT source
152
153
154
155
156
157
158
159
160
161
#elif CL_N_WORDS == 1 && CL_WORD == 64
	CHECK_TTL(ttl_ctr, 210)

	*min = mult_bit_pos_64[(CL_WORD_TYPE) (((*d) & -(*d)) * 0x26752B916FC7B0DUL) >> 58];
#else
	*min = 0;
	int i;

	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 105)
4d26a735   Pedro Roque   Increased recogni...
162
		if ((*d)[i] != 0) {
94b2b13d   Pedro Roque   PHACT source
163
#if CL_WORD == 32
4d26a735   Pedro Roque   Increased recogni...
164
			*min = mult_bit_pos_32[(CL_WORD_TYPE) (((*d)[i] & -((*d)[i])) * 0x077CB531U) >> 27] + (i << CL_DIV);
94b2b13d   Pedro Roque   PHACT source
165
#else
4d26a735   Pedro Roque   Increased recogni...
166
			*min = mult_bit_pos_64[(CL_WORD_TYPE) (((*d)[i] & -((*d)[i])) * 0x26752B916FC7B0DUL) >> 58] + (i << CL_DIV);
94b2b13d   Pedro Roque   PHACT source
167
#endif
4d26a735   Pedro Roque   Increased recogni...
168
169
			i = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
170
171
172
173
174
175
176
177
178
179
180
	}

#endif
}
#endif

#if SUFFIX == _m || SUFFIX == _pm || SUFFIX == _mp || SUFFIX == _n
/*
 * calculate the minimum of the variable domain. (Assume variable is not empty)
 * v - variable to calculate minimum value
 */
4d26a735   Pedro Roque   Increased recogni...
181
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_calc_min_val)(M1 cl_var_p_bitmap* v TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
182
183
184
185
186
187
188
189
190
191
192

#if CL_CHECK_ERRORS
	bool empty;
	FUNC(cl_d_is_empty)(&empty, &v->prop_d TTL_CTR_V);
	if (empty) {
		printf((__constant char *)"\n###error 4\n");
	}
#endif

#if CL_WORD == 32
// vector for speeding up the finding of a domain minimum 32 bits. De Bruijn sequence https://en.wikipedia.org/wiki/De_Bruijn_sequence
4d26a735   Pedro Roque   Increased recogni...
193
	unsigned short mult_bit_pos_32[32] = { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 };
94b2b13d   Pedro Roque   PHACT source
194
#else
4d26a735   Pedro Roque   Increased recogni...
195
// vector for speeding up the finding of a domain minimum 64 bits. De Bruijn sequence http://commsys.ijs.si/~matjaz/maxclique/MaxCliquePara/source_MaxCliquePara_v2.2/BitSet.h
94b2b13d   Pedro Roque   PHACT source
196
	unsigned short mult_bit_pos_64[64] = { 0, 1, 2, 56, 3, 32, 57, 46, 29, 4, 20, 33, 7, 58, 11, 47, 62, 30, 18, 5, 16, 21, 34, 23, 53, 8, 59, 36, 25, 12, 48, 39, 63, 55, 31,
4d26a735   Pedro Roque   Increased recogni...
197
		45, 28, 19, 6, 10, 61, 17, 15, 22, 52, 35, 24, 38, 54, 44, 27, 9, 60, 14, 51, 37, 43, 26, 13, 50, 42, 49, 41, 40 };
94b2b13d   Pedro Roque   PHACT source
198
199
200
#endif

#if CL_N_WORDS == 1 && CL_WORD == 32
4d26a735   Pedro Roque   Increased recogni...
201
	CHECK_TTL(ttl_ctr, 211)
94b2b13d   Pedro Roque   PHACT source
202

4d26a735   Pedro Roque   Increased recogni...
203
	v->min = mult_bit_pos_32[(CL_WORD_TYPE) ((v->prop_d & -(v->prop_d)) * 0x077CB531U) >> 27];
94b2b13d   Pedro Roque   PHACT source
204
205
206
207
208
209
210
211
212
213
214
#elif CL_N_WORDS == 1 && CL_WORD == 64
	CHECK_TTL(ttl_ctr, 212)

	v->min = mult_bit_pos_64[(CL_WORD_TYPE) ((v->prop_d & -(v->prop_d)) * 0x26752B916FC7B0DUL) >> 58];
#else

	v->min = 0;
	int i;

	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 106)
4d26a735   Pedro Roque   Increased recogni...
215
		if (v->prop_d[i] != 0) {
94b2b13d   Pedro Roque   PHACT source
216
#if CL_WORD == 32
4d26a735   Pedro Roque   Increased recogni...
217
			v->min = mult_bit_pos_32[(CL_WORD_TYPE) ((v->prop_d[i] & -(v->prop_d[i])) * 0x077CB531U) >> 27] + (i << CL_DIV);
94b2b13d   Pedro Roque   PHACT source
218
#else
4d26a735   Pedro Roque   Increased recogni...
219
			v->min = convert_ushort(mult_bit_pos_64[(CL_WORD_TYPE) ((v->prop_d[i] & -(v->prop_d[i])) * 0x26752B916FC7B0DUL) >> 58] + (i << CL_DIV));
94b2b13d   Pedro Roque   PHACT source
220
#endif
4d26a735   Pedro Roque   Increased recogni...
221
222
			i = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
223
224
225
226
227
228
229
230
231
232
233
234
	}

#endif
}
#endif

#if SUFFIX == _n
/*
 * calculate the maximum of the domain. (Assume domain is not empty)
 * max - the maximum value will be placed here
 * d - domain to calculate maximum value
 */
4d26a735   Pedro Roque   Increased recogni...
235
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_calc_max_val)(int* max, M1 cl_bitmap* d TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
236
237
238
239
240
241
242
243
244
245
246

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = ((*d) == 0);
	CHECK_TTL(ttl_ctr, 213)
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
247
248
249
250
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
251
252
253
254
255
256
257
258
259
	}
#endif
	if (empty) {
		printf((__constant char *)"\n###error 5\n");
	}
#endif

#if CL_N_WORDS == 1

4d26a735   Pedro Roque   Increased recogni...
260
261
	CHECK_TTL(ttl_ctr, 229)
	*max = convert_int((CL_WORD - clz((*d)) - 1));
94b2b13d   Pedro Roque   PHACT source
262
263
264
265
266
267
268

#else
	*max = 0;
	int i;

	for (i = CL_N_WORDS - 1; i >= 0; i--) {
		CHECK_TTL(ttl_ctr, 107)
4d26a735   Pedro Roque   Increased recogni...
269
270
271
272
		if ((*d)[i] != 0) {
			*max = convert_int(CL_WORD - 1 + (i << CL_DIV) - convert_int(clz((*d)[i])));
			i = -1;
		}
94b2b13d   Pedro Roque   PHACT source
273
274
275
276
277
278
279
280
281
282
	}
#endif
}
#endif

#if SUFFIX == _m || SUFFIX == _pm || SUFFIX == _mp || SUFFIX == _n
/*
 * calculate the maximum value of the variable domain. (Assume variable is not empty)
 * v - variable to calculate and return the maximum value
 */
4d26a735   Pedro Roque   Increased recogni...
283
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_calc_max_val)(M1 cl_var_p_bitmap* v TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
284
285
286
287
288
289
290
291
292
293
294

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = (v->prop_d == 0);
	CHECK_TTL(ttl_ctr, 214)
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
295
296
297
298
		if (v->prop_d[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
299
300
301
302
303
304
305
306
307
	}
#endif
	if (empty) {
		printf((__constant char *)"\n###error 6\n");
	}
#endif

#if CL_N_WORDS == 1

4d26a735   Pedro Roque   Increased recogni...
308
309
310
311
312
313
314
	CHECK_TTL(ttl_ctr, 230)
#if CL_BOOLEAN_VS
	if (v->boolean) {
		if ((v->prop_d & 2) == 2) {
			v->max = 1;
		} else {
			v->max = 0;
94b2b13d   Pedro Roque   PHACT source
315
		}
4d26a735   Pedro Roque   Increased recogni...
316
317
		return;
	}
94b2b13d   Pedro Roque   PHACT source
318
319
#endif

4d26a735   Pedro Roque   Increased recogni...
320
	v->max = convert_ushort((CL_WORD - clz(v->prop_d) - 1));
94b2b13d   Pedro Roque   PHACT source
321
322
#else

4d26a735   Pedro Roque   Increased recogni...
323
#if CL_BOOLEAN_VS
94b2b13d   Pedro Roque   PHACT source
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
	if (v->boolean) {
		if ((v->prop_d[0] & 2) == 2) {
			v->max = 1;
		} else {
			v->max = 0;
		}
		return;
	}
#endif

	int i;
	v->max = 0;

	for (i = CL_N_WORDS - 1; i >= 0; i--) {
		CHECK_TTL(ttl_ctr, 107)
4d26a735   Pedro Roque   Increased recogni...
339
340
341
342
		if (v->prop_d[i] != 0) {
			v->max = convert_ushort(CL_WORD - 1 + (i << CL_DIV) - convert_int(clz(v->prop_d[i])));
			i = -1;
		}
94b2b13d   Pedro Roque   PHACT source
343
344
345
346
347
348
349
350
351
352
353
354
	}
#endif
}
#endif

#if SUFFIX == _n || SUFFIX == _m
/*
 * Count the number of values in the variable domain
 * (uses popcount if OpenCL version is 1.2 or newer)
 * d - domain to count values
 * n_vals - where to place the calculated number of values
 */
4d26a735   Pedro Roque   Increased recogni...
355
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_cnt_vals)(M1 cl_bitmap* d, int* n_vals TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
356
357
358
359
360
361
362
363
364
365

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = ((*d) == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
366
367
368
369
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
370
371
372
373
374
375
376
377
378
379
380
381
	}
#endif
	if (empty) {
		printf((__constant char *)"\n###error 7\n");
	}
#endif

#if CL_N_WORDS == 1

#if __OPENCL_VERSION__ > 110
	(*n_vals) = convert_int(popcount((*d)));
#else
4d26a735   Pedro Roque   Increased recogni...
382
383
	unsigned short count;
	CL_WORD_TYPE d_aux = (*d);
94b2b13d   Pedro Roque   PHACT source
384

4d26a735   Pedro Roque   Increased recogni...
385
386
387
388
389
	for (count = 0; d_aux; count++) {
		CHECK_TTL(ttl_ctr, 108)
		d_aux &= d_aux - 1;
	}
	(*n_vals) = count;
94b2b13d   Pedro Roque   PHACT source
390
391
392
393
394
395
396
397
398
399
#endif

#else

#if __OPENCL_VERSION__ > 110
	int i;
	unsigned short count = 0;

	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 109)
4d26a735   Pedro Roque   Increased recogni...
400
		count += convert_ushort(popcount((*d)[i]));
94b2b13d   Pedro Roque   PHACT source
401
402
403
404
405
406
407
408
409
410
411
	}

	(*n_vals) = count;
#else
	int count = 0;
	int count_aux;
	CL_WORD_TYPE d_aux;
	int i;

	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 110)
4d26a735   Pedro Roque   Increased recogni...
412
		d_aux = (*d)[i];
94b2b13d   Pedro Roque   PHACT source
413
414
		for (count_aux = 0; d_aux; count_aux++) {
			CHECK_TTL(ttl_ctr, 111)
4d26a735   Pedro Roque   Increased recogni...
415
			d_aux &= d_aux - 1;
94b2b13d   Pedro Roque   PHACT source
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
		}
		count += count_aux;
	}
	(*n_vals) = count;
#endif

#endif
}
#endif

#if SUFFIX == _m || SUFFIX == _pm || SUFFIX == _mp || SUFFIX == _n
/*
 * Count the number of values in the variable domain
 * (uses popcount if OpenCL version is 1.2 or newer)
 * v - variable to count values
 */
4d26a735   Pedro Roque   Increased recogni...
432
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_cnt_vals)(M1 cl_var_p_bitmap* v TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
433
434
435

#if CL_N_WORDS == 1

4d26a735   Pedro Roque   Increased recogni...
436
437
438
439
440
441
442
443
#if CL_BOOLEAN_VS
	if (v->boolean) {
		if (v->prop_d == 3) {
			v->n_vals = 2;
		} else if (v->prop_d != 0) {
			v->n_vals = 1;
		} else {
			v->n_vals = 0;
94b2b13d   Pedro Roque   PHACT source
444
		}
4d26a735   Pedro Roque   Increased recogni...
445
446
		return;
	}
94b2b13d   Pedro Roque   PHACT source
447
448
449
450
451
#endif

#if __OPENCL_VERSION__ > 110
	v->n_vals = convert_ushort(popcount(v->prop_d));
#else
4d26a735   Pedro Roque   Increased recogni...
452
453
	int count;
	CL_WORD_TYPE d_aux = v->prop_d;
94b2b13d   Pedro Roque   PHACT source
454

4d26a735   Pedro Roque   Increased recogni...
455
456
457
458
459
	for (count = 0; d_aux; count++) {
		CHECK_TTL(ttl_ctr, 108)
		d_aux &= d_aux - 1;
	}
	v->n_vals = convert_ushort(count);
94b2b13d   Pedro Roque   PHACT source
460
461
462
463
#endif

#else

4d26a735   Pedro Roque   Increased recogni...
464
#if CL_BOOLEAN_VS
94b2b13d   Pedro Roque   PHACT source
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
	if (v->boolean) {
		if (v->prop_d[0] == 3) {
			v->n_vals = 2;
		} else if (v->prop_d[0] != 0) {
			v->n_vals = 1;
		} else {
			v->n_vals = 0;
		}
		return;
	}
#endif

#if __OPENCL_VERSION__ > 110
	int i;
	unsigned short count = 0;

	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 109)
4d26a735   Pedro Roque   Increased recogni...
483
		count += convert_ushort(popcount(v->prop_d[i]));
94b2b13d   Pedro Roque   PHACT source
484
485
486
487
488
489
490
491
492
493
494
	}

	v->n_vals = count;
#else
	int count = 0;
	int count_aux;
	CL_WORD_TYPE d_aux;
	int i;

	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 110)
4d26a735   Pedro Roque   Increased recogni...
495
		d_aux = v->prop_d[i];
94b2b13d   Pedro Roque   PHACT source
496
497
		for (count_aux = 0; d_aux; count_aux++) {
			CHECK_TTL(ttl_ctr, 111)
4d26a735   Pedro Roque   Increased recogni...
498
			d_aux &= d_aux - 1;
94b2b13d   Pedro Roque   PHACT source
499
500
501
502
503
504
505
506
507
508
		}
		count += count_aux;
	}
	v->n_vals = convert_ushort(count);
#endif

#endif
}
#endif

4d26a735   Pedro Roque   Increased recogni...
509
#if SUFFIX == _m3 || SUFFIX == _n || SUFFIX == _bd || SUFFIX == _vsg
94b2b13d   Pedro Roque   PHACT source
510
511
512
513
514
515
516
/*
 * Place the nth values of the domain in vals array. (Assume domain is not empty)
 * d - domain to get nth value from
 * first_nth - first nth value to get from the domain (from 1 to max value)
 * last_nth - last nth value to get from the domain (from 1 to max value)
 * vals - array where to save values
 */
4d26a735   Pedro Roque   Increased recogni...
517
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_get_nth_vals)(M3 cl_bitmap* d, int first_nth, int last_nth, M4 int* vals TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
518
519
520
521
522
523
524
525
526
527

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = ((*d) == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
528
529
530
531
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
532
533
534
535
536
537
538
	}
#endif
	if (empty || first_nth < 1 || first_nth > CL_D_MAX + 1 || last_nth < 1 || last_nth > CL_D_MAX + 1) {
		printf((__constant char *)"\n###error 10\n");
	}
#endif

4d26a735   Pedro Roque   Increased recogni...
539
540
541
	int vals_ctr = 0;
	int vals_idx = 0;
	int i;
94b2b13d   Pedro Roque   PHACT source
542
543
544

#if CL_N_WORDS == 1

4d26a735   Pedro Roque   Increased recogni...
545
546
	for (i = 0; i <= CL_D_MAX; i++) {
		CHECK_TTL(ttl_ctr, 10)
94b2b13d   Pedro Roque   PHACT source
547

4d26a735   Pedro Roque   Increased recogni...
548
549
		if ((*d) & (CL_ONE_ << i)) {
			vals_ctr++;
94b2b13d   Pedro Roque   PHACT source
550

4d26a735   Pedro Roque   Increased recogni...
551
552
			if (vals_ctr >= first_nth) {
				vals[vals_idx++] = i;
94b2b13d   Pedro Roque   PHACT source
553

4d26a735   Pedro Roque   Increased recogni...
554
555
				if (vals_ctr == last_nth) {
					i = CL_D_MAX + 1;
94b2b13d   Pedro Roque   PHACT source
556
557
558
				}
			}
		}
4d26a735   Pedro Roque   Increased recogni...
559
	}
94b2b13d   Pedro Roque   PHACT source
560
561
562
563
564
565
#else
	int word_idx;

	for (word_idx = 0; word_idx < CL_N_WORDS; word_idx++) {
		CHECK_TTL(ttl_ctr, 113)

4d26a735   Pedro Roque   Increased recogni...
566
		if ((*d)[word_idx] != 0) {
94b2b13d   Pedro Roque   PHACT source
567

4d26a735   Pedro Roque   Increased recogni...
568
569
			for (i = 0; i < CL_WORD; i++) {
				CHECK_TTL(ttl_ctr, 114)
94b2b13d   Pedro Roque   PHACT source
570

4d26a735   Pedro Roque   Increased recogni...
571
572
				if ((*d)[word_idx] & (CL_ONE_ << i)) {
					vals_ctr++;
94b2b13d   Pedro Roque   PHACT source
573

4d26a735   Pedro Roque   Increased recogni...
574
575
					if (vals_ctr >= first_nth) {
						vals[vals_idx++] = (word_idx << CL_DIV) + i;
94b2b13d   Pedro Roque   PHACT source
576

4d26a735   Pedro Roque   Increased recogni...
577
578
579
580
581
						if (vals_ctr == last_nth) {
							i = CL_WORD;
							word_idx = CL_N_WORDS;
						}
					}
94b2b13d   Pedro Roque   PHACT source
582
583
584
				}
			}
		}
94b2b13d   Pedro Roque   PHACT source
585
586
587
588
589
590
591
592
593
594
595
596
	}
#endif
}
#endif

#if SUFFIX == _pm
/*
 * Check if domains are equal
 * equal - will be 1 if domains are equal or 0 if not
 * d1 - domain 1
 * d2 - domain 2
 */
4d26a735   Pedro Roque   Increased recogni...
597
FUNC_PREFIX CUDA_FUNC void FUNC(cl_ds_equal)(bool* equal, M1 cl_bitmap* d1, M2 cl_bitmap* d2 TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
598
599
600
601
602
603
604
605
606
607
608

#if CL_CHECK_ERRORS
	bool empty1, empty2;
#if CL_N_WORDS == 1
	empty1 = ((*d1) == 0);
	empty2 = ((*d2) == 0);
#else
	empty1 = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
609
610
611
612
		if ((*d1)[j] != 0) {
			empty1 = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
613
614
615
616
	}
	empty2 = 1;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
617
618
619
620
		if ((*d2)[j] != 0) {
			empty2 = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
621
622
623
624
625
626
627
628
	}
#endif
	if (empty1 || empty2) {
		printf((__constant char *)"\n###error 11\n");
	}
#endif

#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
629
630
	*equal = 0;
	CHECK_TTL(ttl_ctr, 215)
94b2b13d   Pedro Roque   PHACT source
631

4d26a735   Pedro Roque   Increased recogni...
632
633
634
	if ((*d1) == (*d2)) {
		*equal = 1;
	}
94b2b13d   Pedro Roque   PHACT source
635
636
637
638
639
640
#else
	int i;

	*equal = 1;
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 116)
4d26a735   Pedro Roque   Increased recogni...
641
642
643
644
		if ((*d1)[i] != (*d2)[i]) {
			*equal = 0;
			i = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
645
646
647
648
649
650
651
652
653
654
655
	}
#endif
}
#endif

#if SUFFIX == _mg || SUFFIX == _g || SUFFIX == _gm || SUFFIX == _mbd || SUFFIX == _mvs
/*
 * Copy d_src domain to d_dest domain
 * d_dest - where to copy the values
 * d_src - domain to copy
 */
4d26a735   Pedro Roque   Increased recogni...
656
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_copy)(M1 cl_bitmap* d_dest, M2 cl_bitmap* d_src TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
657
658
659
660
661
662
663
664
665
666

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = ((*d_src) == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
667
668
669
670
		if ((*d_src)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
671
672
673
674
675
676
677
678
	}
#endif
	if (empty) {
		printf((__constant char *)"\n###error 12\n");
	}
#endif

#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
679
680
	CHECK_TTL(ttl_ctr, 216)
	(*d_dest) = (*d_src);
94b2b13d   Pedro Roque   PHACT source
681
682
683
684
#else
	int i;
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 117)
4d26a735   Pedro Roque   Increased recogni...
685
		(*d_dest)[i] = (*d_src)[i];
94b2b13d   Pedro Roque   PHACT source
686
687
688
689
690
691
692
693
694
695
696
	}
#endif
}
#endif

#if SUFFIX == _pm || SUFFIX == _m
/*
 * Copy v_src variable to v_dest variable (including to_prop and to_label)
 * v_dest - where to copy the values
 * v_src - variable to copy
 */
4d26a735   Pedro Roque   Increased recogni...
697
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_copy)(M1 cl_var_p_bitmap* v_dest, M2 cl_var_p_bitmap* v_src TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
698
699
700
701
702
703
704
705
706
707

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = (v_src->prop_d == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
708
709
710
711
		if (v_src->prop_d[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
712
713
714
715
716
717
718
	}
#endif
	if (empty || v_src->n_vals == 0 || v_src->n_vals > v_src->max + 1 || v_src->min > v_src->max || v_src->max > CL_D_MAX) {
		printf((__constant char *)"\n###error 13\n");
	}
#endif

4d26a735   Pedro Roque   Increased recogni...
719
720
#if CL_BOOLEAN_VS
	v_dest->boolean = v_src->boolean;
94b2b13d   Pedro Roque   PHACT source
721
722
#endif

4d26a735   Pedro Roque   Increased recogni...
723
724
725
726
	v_dest->max = v_src->max;
	v_dest->min = v_src->min;
	v_dest->n_vals = v_src->n_vals;
	v_dest->to_prop = v_src->to_prop;
94b2b13d   Pedro Roque   PHACT source
727
728

#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
729
730
	CHECK_TTL(ttl_ctr, 217)
	v_dest->prop_d = v_src->prop_d;
94b2b13d   Pedro Roque   PHACT source
731
732
733
734
735

#else
	int i;
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 118)
4d26a735   Pedro Roque   Increased recogni...
736
		v_dest->prop_d[i] = v_src->prop_d[i];
94b2b13d   Pedro Roque   PHACT source
737
738
739
740
741
742
743
744
745
746
747
748
749
	}

#endif
}
#endif

#if SUFFIX == _m
/*
 * Check if the variable contains the value
 * contains - will be 1 if domain contains the value or 0 if not
 * v - variable to check if contains value
 * val - value to check if contained
 */
4d26a735   Pedro Roque   Increased recogni...
750
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_contains_val)(bool* contains, M1 cl_var_p_bitmap* v, int val TTL_CTR) {
94b2b13d   Pedro Roque   PHACT source
751
752
753
754
755
756
757
758
759
760

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = (v->prop_d == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
4d26a735   Pedro Roque   Increased recogni...
761
762
763
764
		if (v->prop_d[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
94b2b13d   Pedro Roque   PHACT source
765
766
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
767
	if (empty || v->n_vals == 0 || v->n_vals > v->max + 1 || v->min > v->max || v->max > CL_D_MAX || val < 0 || val > CL_D_MAX) {
94b2b13d   Pedro Roque   PHACT source
768
		printf((__constant char *)"\n###error 14\n");
4d26a735   Pedro Roque   Increased recogni...
769
	}
94b2b13d   Pedro Roque   PHACT source
770
771
772
#endif

#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
773
774
775
776
777
	CHECK_TTL(ttl_ctr, 218)
	*contains = ((v->prop_d & (CL_ONE_ << val)) != 0);
#else
	CHECK_TTL(ttl_ctr, 219)
	*contains = ((v->prop_d[val >> CL_DIV] & (CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV)))) != 0);
94b2b13d   Pedro Roque   PHACT source
778
#endif
4d26a735   Pedro Roque   Increased recogni...
779
780
}
#endif
94b2b13d   Pedro Roque   PHACT source
781
782
783
784
785
786
787
788
789
790
791
792

#if SUFFIX == _n || SUFFIX == _g
/*
 * Set domain to empty
 * d - domain to clear
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_clear)(M1 cl_bitmap* d TTL_CTR) {
#if CL_N_WORDS == 1
	CHECK_TTL(ttl_ctr, 231)
	(*d) = 0;
#else
	CHECK_TTL(ttl_ctr, 220)
4d26a735   Pedro Roque   Increased recogni...
793
	int i;
94b2b13d   Pedro Roque   PHACT source
794
	for (i = 0; i < CL_N_WORDS; i++) {
4d26a735   Pedro Roque   Increased recogni...
795
796
		CHECK_TTL(ttl_ctr, 119)
		(*d)[i] = 0;
94b2b13d   Pedro Roque   PHACT source
797
798
799
800
801
	}
#endif
}
#endif

4d26a735   Pedro Roque   Increased recogni...
802
#if SUFFIX == _m || SUFFIX == _n
94b2b13d   Pedro Roque   PHACT source
803
804
805
806
807
808
809
810
811
812
/*
 * set the variable as empty (n_vals == 0)
 * v - variable to clear
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_clear)(M1 cl_var_p_bitmap* v) {
	v->n_vals = 0;
}
#endif

#if SUFFIX == _mp || SUFFIX == _pm
4d26a735   Pedro Roque   Increased recogni...
813
814
/*
 * Do operation d1 = d1 & d2
94b2b13d   Pedro Roque   PHACT source
815
816
817
818
819
820
821
822
823
824
 * changed - will be 1 if domain was changed or 0 if not
 * d1 - domain to save operation
 * d2 - domain to do AND with
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_intersect_d)(bool* changed, M1 cl_bitmap* d1, M2 cl_bitmap* d2 TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty1, empty2;
#if CL_N_WORDS == 1
	empty1 = ((*d1) == 0);
4d26a735   Pedro Roque   Increased recogni...
825
	empty2 = ((*d2) == 0);
94b2b13d   Pedro Roque   PHACT source
826
827
828
829
830
831
832
833
834
835
836
#else
	empty1 = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d1)[j] != 0) {
			empty1 = 0;
			j = CL_N_WORDS;
		}
	}
	empty2 = 1;
4d26a735   Pedro Roque   Increased recogni...
837
838
839
840
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d2)[j] != 0) {
			empty2 = 0;
94b2b13d   Pedro Roque   PHACT source
841
842
843
844
			j = CL_N_WORDS;
		}
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
845
846
847
848
	if (empty1 || empty2) {
		printf((__constant char *)"\n###error 15\n");
	}
#endif
94b2b13d   Pedro Roque   PHACT source
849
850
851
852
853
854
855

	*changed = 0;

#if CL_N_WORDS == 1
	CHECK_TTL(ttl_ctr, 221)
	CL_WORD_TYPE d_prev = *d1;

4d26a735   Pedro Roque   Increased recogni...
856
	(*d1) &= (*d2);
94b2b13d   Pedro Roque   PHACT source
857
858

	if ((*d1) != d_prev) {
4d26a735   Pedro Roque   Increased recogni...
859
860
		*changed = 1;
	}
94b2b13d   Pedro Roque   PHACT source
861
#else
4d26a735   Pedro Roque   Increased recogni...
862
	CL_WORD_TYPE d_prev;
94b2b13d   Pedro Roque   PHACT source
863

4d26a735   Pedro Roque   Increased recogni...
864
865
866
	int i;
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 120)
94b2b13d   Pedro Roque   PHACT source
867
868
869
870
871
872
		d_prev = (*d1)[i];

		(*d1)[i] &= (*d2)[i];
		(*changed) |= (*d1)[i] != d_prev;
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
873
}
94b2b13d   Pedro Roque   PHACT source
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
#endif

#if SUFFIX == _m || SUFFIX == _pm || SUFFIX == _mp
/*
 * Do operation v1 = v1 & v2
 * changed - will be 1 if domain was changed or 0 if not
 * v1 - variable to save operation
 * v2 - variable to do AND with
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_intersect_v)(bool* changed, M1 cl_var_p_bitmap* v1, M2 cl_var_p_bitmap* v2 TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty1, empty2;
#if CL_N_WORDS == 1
	empty1 = (v1->prop_d == 0);
4d26a735   Pedro Roque   Increased recogni...
889
	empty2 = (v2->prop_d == 0);
94b2b13d   Pedro Roque   PHACT source
890
891
892
893
894
895
896
897
898
899
900
#else
	empty1 = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v1->prop_d[j] != 0) {
			empty1 = 0;
			j = CL_N_WORDS;
		}
	}
	empty2 = 1;
4d26a735   Pedro Roque   Increased recogni...
901
902
903
904
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v2->prop_d[j] != 0) {
			empty2 = 0;
94b2b13d   Pedro Roque   PHACT source
905
906
907
908
			j = CL_N_WORDS;
		}
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
909
910
911
912
	if (empty1 || v1->n_vals == 0 || v1->n_vals > v1->max + 1 || v1->min > v1->max || v1->max > CL_D_MAX
			|| empty2 || v2->n_vals == 0 || v2->n_vals > v2->max + 1 || v2->min > v2->max || v2->max > CL_D_MAX) {
		printf((__constant char *)"\n###error 16\n");
	}
94b2b13d   Pedro Roque   PHACT source
913
914
915
916
917
918
919
920
#endif

	*changed = 0;

#if CL_N_WORDS == 1
	CHECK_TTL(ttl_ctr, 222)

	CL_WORD_TYPE d_prev = v1->prop_d;
4d26a735   Pedro Roque   Increased recogni...
921

94b2b13d   Pedro Roque   PHACT source
922
923
	v1->prop_d &= v2->prop_d;

4d26a735   Pedro Roque   Increased recogni...
924
	if (v1->prop_d != d_prev) {
94b2b13d   Pedro Roque   PHACT source
925
		if (v1->prop_d != 0) {
4d26a735   Pedro Roque   Increased recogni...
926
			FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
927
			FUNC(cl_v_calc_min_val)(v1 TTL_CTR_V);
4d26a735   Pedro Roque   Increased recogni...
928
			FUNC(cl_v_calc_max_val)(v1 TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
929
		} else {
4d26a735   Pedro Roque   Increased recogni...
930
931
932
933
934
935
936
			v1->n_vals = 0;
		}
		*changed = 1;
	}
#else
	CL_WORD_TYPE d_prev;

94b2b13d   Pedro Roque   PHACT source
937
	int i;
4d26a735   Pedro Roque   Increased recogni...
938
939
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 120)
94b2b13d   Pedro Roque   PHACT source
940
941
942
943
944
945
		d_prev = v1->prop_d[i];

		v1->prop_d[i] &= v2->prop_d[i];
		(*changed) |= v1->prop_d[i] != d_prev;
	}
	if (*changed) {
4d26a735   Pedro Roque   Increased recogni...
946
		FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
		if (v1->n_vals != 0) {
			FUNC(cl_v_calc_min_val)(v1 TTL_CTR_V);
			FUNC(cl_v_calc_max_val)(v1 TTL_CTR_V);
		}
	}
#endif
}
#endif

#if SUFFIX == _pm
/*
 * Do operation d1 = d1 | d2
 * changed - will be 1 if domain was changed or 0 if not
 * d1 - domain to save operation
 * d2 - domain to do OR with
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_union_d)(bool* changed, M1 cl_bitmap* d1, M2 cl_bitmap* d2 TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty1, empty2;
#if CL_N_WORDS == 1
	empty1 = ((*d1) == 0);
4d26a735   Pedro Roque   Increased recogni...
969
	empty2 = ((*d2) == 0);
94b2b13d   Pedro Roque   PHACT source
970
971
972
973
974
975
976
977
978
979
980
#else
	empty1 = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d1)[j] != 0) {
			empty1 = 0;
			j = CL_N_WORDS;
		}
	}
	empty2 = 1;
4d26a735   Pedro Roque   Increased recogni...
981
982
983
984
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d2)[j] != 0) {
			empty2 = 0;
94b2b13d   Pedro Roque   PHACT source
985
986
987
988
			j = CL_N_WORDS;
		}
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
989
990
991
992
	if (empty1 || empty2) {
		printf((__constant char *)"\n###error 17\n");
	}
#endif
94b2b13d   Pedro Roque   PHACT source
993
994
995
996
997
998
999

	*changed = 0;

#if CL_N_WORDS == 1

	CHECK_TTL(ttl_ctr, 223)
	CL_WORD_TYPE d_prev = *d1;
4d26a735   Pedro Roque   Increased recogni...
1000

94b2b13d   Pedro Roque   PHACT source
1001
1002
1003
	(*d1) |= (*d2);

	if ((*d1) != d_prev) {
4d26a735   Pedro Roque   Increased recogni...
1004
1005
		*changed = 1;
	}
94b2b13d   Pedro Roque   PHACT source
1006
#else
4d26a735   Pedro Roque   Increased recogni...
1007
	CL_WORD_TYPE d_prev;
94b2b13d   Pedro Roque   PHACT source
1008

4d26a735   Pedro Roque   Increased recogni...
1009
1010
1011
	int i;
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 120)
94b2b13d   Pedro Roque   PHACT source
1012
1013
1014
1015
1016
1017
		d_prev = (*d1)[i];

		(*d1)[i] |= (*d2)[i];
		(*changed) |= (*d1)[i] != d_prev;
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
1018
}
94b2b13d   Pedro Roque   PHACT source
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
#endif

#if SUFFIX == _pm
/*
 * Do operation v1 = v1 | v2
 * changed - will be 1 if domain was changed or 0 if not
 * v1 - variable to save operation
 * v2 - variable to do or with
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_union_v)(bool* changed, M1 cl_var_p_bitmap* v1, M2 cl_var_p_bitmap* v2 TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty1, empty2;
#if CL_N_WORDS == 1
	empty1 = (v1->prop_d == 0);
4d26a735   Pedro Roque   Increased recogni...
1034
	empty2 = (v2->prop_d == 0);
94b2b13d   Pedro Roque   PHACT source
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
#else
	empty1 = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v1->prop_d[j] != 0) {
			empty1 = 0;
			j = CL_N_WORDS;
		}
	}
	empty2 = 1;
4d26a735   Pedro Roque   Increased recogni...
1046
1047
1048
1049
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v2->prop_d[j] != 0) {
			empty2 = 0;
94b2b13d   Pedro Roque   PHACT source
1050
1051
1052
1053
			j = CL_N_WORDS;
		}
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
1054
1055
1056
1057
	if (empty1 || v1->n_vals == 0 || v1->n_vals > v1->max + 1 || v1->min > v1->max || v1->max > CL_D_MAX
			|| empty2 || v2->n_vals == 0 || v2->n_vals > v2->max + 1 || v2->min > v2->max || v2->max > CL_D_MAX) {
		printf((__constant char *)"\n###error 18\n");
	}
94b2b13d   Pedro Roque   PHACT source
1058
1059
1060
1061
1062
1063
1064
1065
#endif

	*changed = 0;

#if CL_N_WORDS == 1
	CL_WORD_TYPE d_prev = v1->prop_d;

	v1->prop_d |= v2->prop_d;
4d26a735   Pedro Roque   Increased recogni...
1066

94b2b13d   Pedro Roque   PHACT source
1067
1068
	if (v1->prop_d != d_prev) {
		FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V);
4d26a735   Pedro Roque   Increased recogni...
1069
		FUNC(cl_v_calc_min_val)(v1 TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
1070
		FUNC(cl_v_calc_max_val)(v1 TTL_CTR_V);
4d26a735   Pedro Roque   Increased recogni...
1071
		*changed = 1;
94b2b13d   Pedro Roque   PHACT source
1072
	}
4d26a735   Pedro Roque   Increased recogni...
1073
1074
1075
1076
1077
1078
#else
	CL_WORD_TYPE d_prev;

	int i;
	for (i = 0; i < CL_N_WORDS; i++) {
		CHECK_TTL(ttl_ctr, 121)
94b2b13d   Pedro Roque   PHACT source
1079
1080
1081
1082
1083
1084
		d_prev = v1->prop_d[i];

		v1->prop_d[i] |= v2->prop_d[i];
		(*changed) |= v1->prop_d[i] != d_prev;
	}
	if (*changed) {
4d26a735   Pedro Roque   Increased recogni...
1085
		FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
		FUNC(cl_v_calc_min_val)(v1 TTL_CTR_V);
		FUNC(cl_v_calc_max_val)(v1 TTL_CTR_V);

		*changed = 1;
	}
#endif
}
#endif

#if SUFFIX == _g
/*
 * remove value from domain. Doesn't test if domain changes neither if it has the value
 * d - domain to remove value from
 * val - value to remove from domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_del_val_no_tests)(M1 cl_bitmap* d, int val) {

#if CL_CHECK_ERRORS
	bool contains;
	bool empty;
#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
1107
	empty = ((*d) == 0);
94b2b13d   Pedro Roque   PHACT source
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
1119
1120
1121
1122

#if CL_N_WORDS == 1
	contains = (((*d) & (CL_ONE_ << val)) != 0);
#else
94b2b13d   Pedro Roque   PHACT source
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
	contains = (((*d)[val >> CL_DIV] & (CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV)))) != 0);
#endif
	if (!contains || empty || val < 0 || val > CL_D_MAX) {
		printf((__constant char *)"\n###error 19\n");
	}
#endif

#if CL_N_WORDS == 1
	(*d) &= ~(CL_ONE_ << val);
#else
	(*d)[val >> CL_DIV] &= ~(CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV)));
#endif
}
#endif
4d26a735   Pedro Roque   Increased recogni...
1137

94b2b13d   Pedro Roque   PHACT source
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
#if SUFFIX == _g
/*
 * remove value from domain
 * changed - will be 1 if domain was changed or 0 if not
 * d - domain to remove value from
 * val - value to remove from domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_del_val)(bool* changed, M1 cl_bitmap* d, int val) {

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = ((*d) == 0);
4d26a735   Pedro Roque   Increased recogni...
1151
#else
94b2b13d   Pedro Roque   PHACT source
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
1162
1163
1164
1165
	if (empty) {
		printf((__constant char *)"\n###error 20\n");
	}
#endif
94b2b13d   Pedro Roque   PHACT source
1166
1167
1168
1169
1170
1171
1172

	*changed = 0;

	if (val >= 0 && val <= CL_D_MAX) {

#if CL_N_WORDS == 1
		CL_WORD_TYPE d_prev = (*d);
4d26a735   Pedro Roque   Increased recogni...
1173

94b2b13d   Pedro Roque   PHACT source
1174
		(*d) &= ~(CL_ONE_ << val);
4d26a735   Pedro Roque   Increased recogni...
1175

94b2b13d   Pedro Roque   PHACT source
1176
1177
		*changed = ((*d) != d_prev);
#else
4d26a735   Pedro Roque   Increased recogni...
1178
		int word_idx = val >> CL_DIV;
94b2b13d   Pedro Roque   PHACT source
1179
		CL_WORD_TYPE d_prev = ((*d)[word_idx]);
4d26a735   Pedro Roque   Increased recogni...
1180

94b2b13d   Pedro Roque   PHACT source
1181
		(*d)[word_idx] &= ~(CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV)));
4d26a735   Pedro Roque   Increased recogni...
1182

94b2b13d   Pedro Roque   PHACT source
1183
1184
1185
1186
1187
1188
1189
1190
		*changed = ((*d)[word_idx] != d_prev);
#endif
	}
}
#endif

#if SUFFIX == _m
/*
4d26a735   Pedro Roque   Increased recogni...
1191
 * remove value from reification (boolean) variable when it has always 2 values (0 and 1)
94b2b13d   Pedro Roque   PHACT source
1192
1193
1194
1195
1196
1197
1198
1199
1200
 * v - reification variable with values 0 and 1 to remove value from
 * val - value to remove from variable
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_bool_del_val)(M1 cl_var_p_bitmap* v, int val TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = (v->prop_d == 0);
4d26a735   Pedro Roque   Increased recogni...
1201
#else
94b2b13d   Pedro Roque   PHACT source
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v->prop_d[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
1212
1213
1214
1215
	if (empty || v->n_vals != 2 || v->min != 0 || v->max != 1 || val < 0 || val > 1) {
		printf((__constant char *)"\n###error 21\n");
	}
#endif
94b2b13d   Pedro Roque   PHACT source
1216
1217
1218
1219
1220
1221
1222
1223

#if CL_N_WORDS == 1
	CHECK_TTL(ttl_ctr, 224)

	if (val == 0) {
		v->prop_d = 2;
		v->min = 1;
		v->n_vals = 1;
4d26a735   Pedro Roque   Increased recogni...
1224

94b2b13d   Pedro Roque   PHACT source
1225
	} else {
4d26a735   Pedro Roque   Increased recogni...
1226
1227
1228
		v->prop_d = 1;
		v->max = 0;
		v->n_vals = 1;
94b2b13d   Pedro Roque   PHACT source
1229
	}
4d26a735   Pedro Roque   Increased recogni...
1230
1231
1232
1233
1234

#else

	CHECK_TTL(ttl_ctr, 225)
	if (val == 0) {
94b2b13d   Pedro Roque   PHACT source
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
		v->prop_d[0] = 2;
		v->min = 1;

	} else {
		v->prop_d[0] = 1;
		v->max = 0;
	}
	v->n_vals = 1;

#endif
}
#endif

#if SUFFIX == _m || SUFFIX == _n
/*
 * remove value from variable
 * changed - will be 1 if domain was changed or 0 if not
 * v - variable to remove value from
 * val - value to remove from variable
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_val)(bool* changed, M1 cl_var_p_bitmap* v, int val TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
1260
	empty = (v->prop_d == 0);
94b2b13d   Pedro Roque   PHACT source
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v->prop_d[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
4d26a735   Pedro Roque   Increased recogni...
1271
1272
1273
1274
#endif
	if (empty || v->n_vals == 0 || v->n_vals > v->max + 1 || v->min > v->max || v->max > CL_D_MAX) {
		printf((__constant char *)"\n###error 22\n");
	}
94b2b13d   Pedro Roque   PHACT source
1275
1276
1277
1278
1279
1280
1281
#endif

	*changed = 0;

	if (val >= v->min && val <= v->max) {
#if CL_N_WORDS == 1

4d26a735   Pedro Roque   Increased recogni...
1282
		CL_WORD_TYPE d_prev = v->prop_d;
94b2b13d   Pedro Roque   PHACT source
1283

4d26a735   Pedro Roque   Increased recogni...
1284
		v->prop_d &= ~(CL_ONE_ << val);
94b2b13d   Pedro Roque   PHACT source
1285
1286

		if (v->prop_d != d_prev) {
4d26a735   Pedro Roque   Increased recogni...
1287
			v->n_vals--;
94b2b13d   Pedro Roque   PHACT source
1288
			if (v->n_vals != 0) {
4d26a735   Pedro Roque   Increased recogni...
1289
				if (val == v->min) {
94b2b13d   Pedro Roque   PHACT source
1290
					FUNC(cl_v_calc_min_val)(v TTL_CTR_V);
4d26a735   Pedro Roque   Increased recogni...
1291
1292
1293
1294
1295

				} else if (val == v->max) {
					FUNC(cl_v_calc_max_val)(v TTL_CTR_V);
				}
			}
94b2b13d   Pedro Roque   PHACT source
1296
			*changed = 1;
4d26a735   Pedro Roque   Increased recogni...
1297
1298
		}
#else
94b2b13d   Pedro Roque   PHACT source
1299

94b2b13d   Pedro Roque   PHACT source
1300
#if CL_BOOLEAN_VS
4d26a735   Pedro Roque   Increased recogni...
1301
1302
	if (v->boolean) {
		*changed = 1;
94b2b13d   Pedro Roque   PHACT source
1303
1304
		v->n_vals--;

4d26a735   Pedro Roque   Increased recogni...
1305
1306
1307
1308
		if (v->n_vals == 1) {
			v->prop_d[0] &= ~(CL_ONE_ << val);

			if (val == 0) {
94b2b13d   Pedro Roque   PHACT source
1309
				v->min = 1;
4d26a735   Pedro Roque   Increased recogni...
1310
1311
			} else {
				v->max = 0;
94b2b13d   Pedro Roque   PHACT source
1312
			}
4d26a735   Pedro Roque   Increased recogni...
1313
1314
1315
1316
1317
		}
		return;
	}
#endif

94b2b13d   Pedro Roque   PHACT source
1318
		int word_idx = val >> CL_DIV;
4d26a735   Pedro Roque   Increased recogni...
1319
		CL_WORD_TYPE d_prev = v->prop_d[word_idx];
94b2b13d   Pedro Roque   PHACT source
1320

94b2b13d   Pedro Roque   PHACT source
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
		v->prop_d[word_idx] &= ~(CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV)));

		if (v->prop_d[word_idx] != d_prev) {
			v->n_vals--;
			if (v->n_vals != 0) {
				if (v->min == val) {
					FUNC(cl_v_calc_min_val)(v TTL_CTR_V);

				} else if (v->max == val) {
					FUNC(cl_v_calc_max_val)(v TTL_CTR_V);
				}
			}
			*changed = 1;
		}
#endif
	}
}
#endif

#if SUFFIX == _g
4d26a735   Pedro Roque   Increased recogni...
1341
/*
94b2b13d   Pedro Roque   PHACT source
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
 * Remove from the domain all the values less than val
 * changed - will be 1 if domain was changed or 0 if not
 * d - domain to remove values from
 * val - minimum value to keep at domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_del_lt)(bool* changed, M1 cl_bitmap* d, int val TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
1352
	empty = ((*d) == 0);
94b2b13d   Pedro Roque   PHACT source
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
4d26a735   Pedro Roque   Increased recogni...
1363
1364
1365
1366
#endif
	if (empty || val < 0 || val > CL_D_MAX) {
		printf((__constant char *)"\n###error 24\n");
	}
94b2b13d   Pedro Roque   PHACT source
1367
1368
1369
1370
1371
1372
1373
#endif

	*changed = 0;

	if (val > CL_D_MAX) {
		FUNC(cl_d_clear)(d TTL_CTR_V);
		*changed = 1;
4d26a735   Pedro Roque   Increased recogni...
1374
	}
94b2b13d   Pedro Roque   PHACT source
1375

4d26a735   Pedro Roque   Increased recogni...
1376
1377
1378
1379
	if (val > 0 && val <= CL_D_MAX) {
#if CL_N_WORDS == 1

		CL_WORD_TYPE d_prev = (*d);
94b2b13d   Pedro Roque   PHACT source
1380

4d26a735   Pedro Roque   Increased recogni...
1381
		(*d) &= (CL_ALL_ONES << val);
94b2b13d   Pedro Roque   PHACT source
1382
1383

		*changed = ((*d) != d_prev);
4d26a735   Pedro Roque   Increased recogni...
1384
#else
94b2b13d   Pedro Roque   PHACT source
1385
		CL_WORD_TYPE w;
4d26a735   Pedro Roque   Increased recogni...
1386
		int limit = val >> CL_DIV;
94b2b13d   Pedro Roque   PHACT source
1387
		int word_idx;
4d26a735   Pedro Roque   Increased recogni...
1388

94b2b13d   Pedro Roque   PHACT source
1389
1390
1391
1392
1393
1394
1395
		for (word_idx = 0; word_idx < limit; word_idx++) {
			CHECK_TTL(ttl_ctr, 122)
			if ((*d)[word_idx] != 0) {
				(*d)[word_idx] = 0;
				(*changed) = 1;
			}
		}
4d26a735   Pedro Roque   Increased recogni...
1396
1397
1398
1399
		w = (*d)[word_idx] & (CL_ALL_ONES << ((val - ((val >> CL_DIV) << CL_DIV)) & CL_REM));

		if ((*changed) || w != (*d)[word_idx]) {
			(*d)[word_idx] = w;
94b2b13d   Pedro Roque   PHACT source
1400
1401
1402
1403
1404
1405
1406
1407
			*changed = 1;
		}
#endif
	}
}
#endif

#if SUFFIX == _m || SUFFIX == _n
4d26a735   Pedro Roque   Increased recogni...
1408
/*
94b2b13d   Pedro Roque   PHACT source
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
 * Remove from the variable all the values less than val
 * changed - will be 1 if domain was changed or 0 if not
 * v - variable to remove values from
 * val - minimum value to keep at domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_lt)(bool* changed, M1 cl_var_p_bitmap* v, int val TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
1419
	empty = (v->prop_d == 0);
94b2b13d   Pedro Roque   PHACT source
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v->prop_d[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
4d26a735   Pedro Roque   Increased recogni...
1430
1431
1432
1433
#endif
	if (empty || v->n_vals == 0 || v->n_vals > v->max + 1 || v->min > v->max || v->max > CL_D_MAX || val < 0) {
		printf((__constant char *)"\n###error 25\n");
		printf((__constant char *)"\n### empty=%d v->n_vals=%u v->max=%u v->min=%u val=%d\n", empty, v->n_vals, v->max, v->min, val);
94b2b13d   Pedro Roque   PHACT source
1434
1435
	}
#endif
4d26a735   Pedro Roque   Increased recogni...
1436
1437

	*changed = 0;
94b2b13d   Pedro Roque   PHACT source
1438
1439
1440
1441

	if (val > v->max) {
		FUNC(cl_v_clear)(v);
		*changed = 1;
4d26a735   Pedro Roque   Increased recogni...
1442
		return;
94b2b13d   Pedro Roque   PHACT source
1443
	}
4d26a735   Pedro Roque   Increased recogni...
1444
1445
1446
1447
1448

	if (val > v->min) {
#if CL_N_WORDS == 1

		CL_WORD_TYPE d_prev = v->prop_d;
94b2b13d   Pedro Roque   PHACT source
1449

4d26a735   Pedro Roque   Increased recogni...
1450
		v->prop_d &= (CL_ALL_ONES << val);
94b2b13d   Pedro Roque   PHACT source
1451
1452

		if (v->prop_d != d_prev) {
4d26a735   Pedro Roque   Increased recogni...
1453
			FUNC(cl_v_cnt_vals)(v TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
1454
			FUNC(cl_v_calc_min_val)(v TTL_CTR_V);
4d26a735   Pedro Roque   Increased recogni...
1455
			*changed = 1;
94b2b13d   Pedro Roque   PHACT source
1456
		}
4d26a735   Pedro Roque   Increased recogni...
1457
1458
1459
#else

#if CL_BOOLEAN_VS
94b2b13d   Pedro Roque   PHACT source
1460
	if (v->boolean) {
94b2b13d   Pedro Roque   PHACT source
1461
		v->prop_d[0] = 2;
4d26a735   Pedro Roque   Increased recogni...
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
		v->min = 1;
		v->n_vals--;
		*changed = 1;
		return;
	}
#endif

		CL_WORD_TYPE w;
		int limit = val >> CL_DIV;
		int min_idx = v->min >> CL_DIV;
94b2b13d   Pedro Roque   PHACT source
1472
1473
1474
1475
1476
1477
1478
1479
1480
		int word_idx;

		for (word_idx = min_idx; word_idx < limit; word_idx++) {
			CHECK_TTL(ttl_ctr, 123)
			if (v->prop_d[word_idx] != 0) {
				v->prop_d[word_idx] = 0;
				(*changed) = 1;
			}
		}
4d26a735   Pedro Roque   Increased recogni...
1481
1482
1483
1484

#ifndef __OPENCL_VERSION__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
94b2b13d   Pedro Roque   PHACT source
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
#endif
		w = v->prop_d[word_idx] & (CL_ALL_ONES << ((val - ((val >> CL_DIV) << CL_DIV)) & CL_REM));

#ifndef __OPENCL_VERSION__
#pragma GCC diagnostic pop
#endif

		if ((*changed) || w != v->prop_d[word_idx]) {
			v->prop_d[word_idx] = w;

			FUNC(cl_v_cnt_vals)(v TTL_CTR_V);
			if (v->n_vals != 0) {
				FUNC(cl_v_calc_min_val)(v TTL_CTR_V);
			}
			(*changed) = 1;
		}
#endif
	}
}
#endif

#if SUFFIX == _g
4d26a735   Pedro Roque   Increased recogni...
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
/*
 * Remove from the domain all the values less or equal to val. Doesn't test if domain changes neither if it has values for deletion
 * d - domain to remove values from
 * val - minimum value to remove from domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_del_le_no_tests)(M1 cl_bitmap* d, int val TTL_CTR) {

#if CL_CHECK_ERRORS
	bool contains;
	bool empty;
#if CL_N_WORDS == 1
	empty = ((*d) == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
#endif
#if CL_N_WORDS == 1
	contains = (((*d) & (CL_ONE_ << val)) != 0);
#else
	contains = (((*d)[val >> CL_DIV] & (CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV)))) != 0);
#endif
	if (!contains || empty || val < 0 || val > CL_D_MAX) {
		printf((__constant char *)"\n###error 26\n");
94b2b13d   Pedro Roque   PHACT source
1537
	}
4d26a735   Pedro Roque   Increased recogni...
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
#endif

	val++;

#if CL_N_WORDS == 1
	CHECK_TTL(ttl_ctr, 226)
	(*d) &= (CL_ALL_ONES << val);
#else
	int limit = val >> CL_DIV;
	int word_idx;

	for (word_idx = 0; word_idx < limit; word_idx++) {
		CHECK_TTL(ttl_ctr, 124)
		(*d)[word_idx] = 0;
	}
	(*d)[word_idx] = (*d)[word_idx] & (CL_ALL_ONES << ((val - ((val >> CL_DIV) << CL_DIV)) & CL_REM));
#endif
}
#endif

#if SUFFIX == _g
/*
 * Remove from the domain all the values less or equal to val
 * changed - will be 1 if domain was changed or 0 if not
 * d - domain to remove values from
 * val - minimum value to remove from domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_del_le)(bool* changed, M1 cl_bitmap* d, int val TTL_CTR) {
	FUNC(cl_d_del_lt)(changed, d, ++val TTL_CTR_V);
}
#endif

#if SUFFIX == _m
/*
 * Remove from the variable all the values less or equal to val
 * changed - will be 1 if domain was changed or 0 if not
 * v - variable to remove values from
 * val - minimum value to remove from domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_le)(bool* changed, M1 cl_var_p_bitmap* v, int val TTL_CTR) {
	FUNC(cl_v_del_lt)(changed, v, ++val TTL_CTR_V);
}
#endif

#if SUFFIX == _g
94b2b13d   Pedro Roque   PHACT source
1583
1584
1585
1586
1587
1588
1589
1590
1591
/*
 * Remove from the domain all the values greater than val
 * changed - will be 1 if domain was changed or 0 if not
 * d - domain to remove values from
 * val - maximum value to keep at domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_del_gt)(bool* changed, M1 cl_bitmap* d, int val TTL_CTR) {

#if CL_CHECK_ERRORS
4d26a735   Pedro Roque   Increased recogni...
1592
	bool empty;
94b2b13d   Pedro Roque   PHACT source
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
#if CL_N_WORDS == 1
	empty = ((*d) == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if ((*d)[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
4d26a735   Pedro Roque   Increased recogni...
1604
1605
1606
1607
	}
#endif
	if (empty || val < 0 || val > CL_D_MAX) {
		printf((__constant char *)"\n###error 27\n");
94b2b13d   Pedro Roque   PHACT source
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
	}
#endif

	*changed = 0;

	if (val < 0) {
		FUNC(cl_d_clear)(d TTL_CTR_V);
		*changed = 1;
	}

	if (val < CL_D_MAX && val >= 0) {
#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
1620

94b2b13d   Pedro Roque   PHACT source
1621
1622
		CL_WORD_TYPE d_prev = (*d);
		(*d) &= (CL_ALL_ONES >> (CL_REM - val));
4d26a735   Pedro Roque   Increased recogni...
1623
1624

		*changed = ((*d) != d_prev);
94b2b13d   Pedro Roque   PHACT source
1625
1626
1627
1628
1629
1630
#else
		CL_WORD_TYPE w;
		int word_idx = val >> CL_DIV;
		int i;

		w = (*d)[word_idx] & ((CL_ALL_ONES >> (CL_REM - ((val - ((val >> CL_DIV) << CL_DIV)) & CL_REM))));
4d26a735   Pedro Roque   Increased recogni...
1631

94b2b13d   Pedro Roque   PHACT source
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
		for (i = word_idx + 1; i < CL_N_WORDS; i++) {
			CHECK_TTL(ttl_ctr, 125)
			if ((*d)[i] != 0) {
				(*d)[i] = 0;
				(*changed) = 1;
			}
		}

		if ((*changed) || w != (*d)[word_idx]) {
			(*d)[word_idx] = w;
			*changed = 1;
		}
#endif
4d26a735   Pedro Roque   Increased recogni...
1645
1646
	}
}
94b2b13d   Pedro Roque   PHACT source
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
#endif

#if SUFFIX == _m
/*
 * Remove from the variable all the values greater than val. Doesn't test if domain changes neither if it has values for deletion
 * v - variable to remove values from
 * val - maximum value to keep at domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_gt_no_tests)(M1 cl_var_p_bitmap* v, int val TTL_CTR) {

4d26a735   Pedro Roque   Increased recogni...
1657
1658
#if CL_CHECK_ERRORS
	bool contains;
94b2b13d   Pedro Roque   PHACT source
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
	bool empty;
#if CL_N_WORDS == 1
	empty = (v->prop_d == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v->prop_d[j] != 0) {
			empty = 0;
4d26a735   Pedro Roque   Increased recogni...
1669
			j = CL_N_WORDS;
94b2b13d   Pedro Roque   PHACT source
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
		}
	}
#endif
	FUNC(cl_v_contains_val)(&contains, v, val TTL_CTR_V);
	if (!contains || empty || v->n_vals == 0 || v->n_vals > v->max + 1 || v->min > v->max || v->max > CL_D_MAX || val < 0 || val > CL_D_MAX) {
		printf((__constant char *)"\n###error 28\n");
	}
#endif

#if CL_N_WORDS == 1
4d26a735   Pedro Roque   Increased recogni...
1680
1681
1682
1683

#if CL_BOOLEAN_VS
	if (v->boolean) {
		v->prop_d = 1;
94b2b13d   Pedro Roque   PHACT source
1684
1685
1686
1687
1688
1689
1690
		v->max = 0;
		v->n_vals = 1;
		return;
	}
#endif

	v->prop_d &= (CL_ALL_ONES >> (CL_WORD - 1 - val));
4d26a735   Pedro Roque   Increased recogni...
1691

94b2b13d   Pedro Roque   PHACT source
1692
	FUNC(cl_v_cnt_vals)(v TTL_CTR_V);
4d26a735   Pedro Roque   Increased recogni...
1693
1694
1695
1696
	FUNC(cl_v_calc_max_val)(v TTL_CTR_V);
#else

#if CL_BOOLEAN_VS
94b2b13d   Pedro Roque   PHACT source
1697
	if (v->boolean) {
4d26a735   Pedro Roque   Increased recogni...
1698
		v->prop_d[0] = 1;
94b2b13d   Pedro Roque   PHACT source
1699
1700
		v->max = 0;
		v->n_vals--;
4d26a735   Pedro Roque   Increased recogni...
1701
1702
		return;
	}
94b2b13d   Pedro Roque   PHACT source
1703
#endif
4d26a735   Pedro Roque   Increased recogni...
1704

94b2b13d   Pedro Roque   PHACT source
1705
1706
1707
1708
1709
1710
1711
1712
1713
	int word_idx = val >> CL_DIV;
	int max_idx = v->max >> CL_DIV;
	int i;

	v->prop_d[word_idx] = v->prop_d[word_idx] & ((CL_ALL_ONES >> (CL_REM - ((val - ((val >> CL_DIV) << CL_DIV)) & CL_REM))));

	for (i = word_idx + 1; i <= max_idx; i++) {
		CHECK_TTL(ttl_ctr, 126)
		v->prop_d[i] = 0;
4d26a735   Pedro Roque   Increased recogni...
1714
1715
1716
1717
	}

	FUNC(cl_v_cnt_vals)(v TTL_CTR_V);
	FUNC(cl_v_calc_max_val)(v TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
1718
1719
1720
1721
1722
1723
1724
#endif
}
#endif

#if SUFFIX == _m || SUFFIX == _n
/*
 * Remove from the variable all the values greater than val
4d26a735   Pedro Roque   Increased recogni...
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
 * changed - will be 1 if domain was changed or 0 if not
 * v - variable to remove values from
 * val - maximum value to keep at domain
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_gt)(bool* changed, M1 cl_var_p_bitmap* v, int val TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = (v->prop_d == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v->prop_d[j] != 0) {
			empty = 0;
			j = CL_N_WORDS;
		}
	}
#endif
	if (empty || v->n_vals == 0 || v->n_vals > v->max + 1 || v->min > v->max || v->max > CL_D_MAX) {
		printf((__constant char *)"\n###error 29\n");
	}
#endif
94b2b13d   Pedro Roque   PHACT source
1750

4d26a735   Pedro Roque   Increased recogni...
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
	*changed = 0;

	if (val < v->min) {
		FUNC(cl_v_clear)(v);
		*changed = 1;
		return;
	}

	if (val < v->max) {
#if CL_N_WORDS == 1

		CL_WORD_TYPE d_prev = v->prop_d;
		v->prop_d &= (CL_ALL_ONES >> (CL_WORD - 1 - val));

		if (v->prop_d != d_prev) {
			FUNC(cl_v_cnt_vals)(v TTL_CTR_V);
			FUNC(cl_v_calc_max_val)(v TTL_CTR_V);
			*changed = 1;
		}
#else

#if CL_BOOLEAN_VS
	if (v->boolean) {
94b2b13d   Pedro Roque   PHACT source
1774
1775
1776
1777
1778
1779
1780
1781
1782
		v->prop_d[0] = 1;
		v->max = 0;
		v->n_vals--;
		(*changed) = 1;
		return;
	}
#endif

		CL_WORD_TYPE w;
4d26a735   Pedro Roque   Increased recogni...
1783
		int word_idx = val >> CL_DIV;
94b2b13d   Pedro Roque   PHACT source
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
		int i;

		w = v->prop_d[word_idx] & ((CL_ALL_ONES >> (CL_REM - ((val - ((val >> CL_DIV) << CL_DIV)) & CL_REM))));

		for (i = word_idx + 1; i < CL_N_WORDS; i++) {
			CHECK_TTL(ttl_ctr, 127)
			if (v->prop_d[i] != 0) {
				v->prop_d[i] = 0;
				(*changed) = 1;
			}
		}
4d26a735   Pedro Roque   Increased recogni...
1795
1796
1797
1798

		if ((*changed) || w != v->prop_d[word_idx]) {
			v->prop_d[word_idx] = w;

94b2b13d   Pedro Roque   PHACT source
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
			FUNC(cl_v_cnt_vals)(v TTL_CTR_V);
			if (v->n_vals != 0) {
				FUNC(cl_v_calc_max_val)(v TTL_CTR_V);
			}
			(*changed) = 1;
		}
#endif
	}
}
#endif
4d26a735   Pedro Roque   Increased recogni...
1809
1810
1811
1812
1813
1814
1815

#if SUFFIX == _m
/*
 * Remove from the variable all the values lesser than val
 * changed - will be 1 if domain was changed or 0 if not
 * v - variable to remove values from
 * val - maximum value to remove from the domain
94b2b13d   Pedro Roque   PHACT source
1816
1817
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_ge)(bool* changed, M1 cl_var_p_bitmap* v, int val TTL_CTR) {
4d26a735   Pedro Roque   Increased recogni...
1818
	FUNC(cl_v_del_gt)(changed, v, --val TTL_CTR_V);
94b2b13d   Pedro Roque   PHACT source
1819
}
4d26a735   Pedro Roque   Increased recogni...
1820
1821
#endif

94b2b13d   Pedro Roque   PHACT source
1822
1823
#if SUFFIX == _m || SUFFIX == _n
/*
4d26a735   Pedro Roque   Increased recogni...
1824
 * Clear all values from variable, except val if present
94b2b13d   Pedro Roque   PHACT source
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
 * changed - will be 1 if domain was changed or 0 if not
 * v - variable to clear all values except val
 * val - value to keep in variable if present
 */
FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_all_except_val)(bool* changed, M1 cl_var_p_bitmap* v, int val TTL_CTR) {

#if CL_CHECK_ERRORS
	bool empty;
#if CL_N_WORDS == 1
	empty = (v->prop_d == 0);
#else
	empty = 1;
	int j;
	for (j = 0; j < CL_N_WORDS; j++) {
		CHECK_TTL(ttl_ctr, 115)
		if (v->prop_d[j] != 0) {
4d26a735   Pedro Roque   Increased recogni...
1841
			empty = 0;
94b2b13d   Pedro Roque   PHACT source
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
			j = CL_N_WORDS;
		}
	}
#endif
	if (empty || v->n_vals == 0 || v->n_vals > v->max + 1 || v->min > v->max || v->max > CL_D_MAX || val < 0 || val > CL_D_MAX) {
		printf((__constant char *)"\n###error 30\n");
	}
#endif

	*changed = 0;

	if (val < v->min || val > v->max) {
		FUNC(cl_v_clear)(v);
		*changed = 1;

4d26a735   Pedro Roque   Increased recogni...
1857
	} else {
94b2b13d   Pedro Roque   PHACT source
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
#if CL_N_WORDS == 1

		CHECK_TTL(ttl_ctr, 228)
		CL_WORD_TYPE d_prev = v->prop_d;

		v->prop_d &= (CL_WORD_TYPE) (CL_ONE_ << val);

		if (v->prop_d != d_prev) {
			if (v->prop_d == 0) {
				v->n_vals = 0;
4d26a735   Pedro Roque   Increased recogni...
1868
1869
1870
1871

			} else {
				v->n_vals = 1;
				v->min = convert_ushort(val);
94b2b13d   Pedro Roque   PHACT source
1872
1873
1874
1875
1876
1877
1878
				v->max = convert_ushort(val);
			}
			*changed = 1;
		}
#else

#if CL_BOOLEAN_VS
4d26a735   Pedro Roque   Increased recogni...
1879
		if (v->boolean) {
94b2b13d   Pedro Roque   PHACT source
1880
			if (v->n_vals == 2) {
4d26a735   Pedro Roque   Increased recogni...
1881
1882
1883
1884
1885
				v->prop_d[0] &= (CL_ONE_ << val);
				v->max = convert_ushort(val);
				v->min = convert_ushort(val);
				v->n_vals = 1;
				*changed = 1;
94b2b13d   Pedro Roque   PHACT source
1886
			}
4d26a735   Pedro Roque   Increased recogni...
1887
			return;
94b2b13d   Pedro Roque   PHACT source
1888
1889
		}
#endif
4d26a735   Pedro Roque   Increased recogni...
1890
1891
		int word_idx = val >> CL_DIV;
		int min_idx = v->min >> CL_DIV;
94b2b13d   Pedro Roque   PHACT source
1892
		CL_WORD_TYPE d_prev = v->prop_d[word_idx];
4d26a735   Pedro Roque   Increased recogni...
1893
1894
1895
1896
1897
		int i;

		for (i = min_idx; i < word_idx; i++) {
			CHECK_TTL(ttl_ctr, 128)
			if (v->prop_d[i] != 0) {
94b2b13d   Pedro Roque   PHACT source
1898
1899
				v->prop_d[i] = 0;
				(*changed) = 1;
4d26a735   Pedro Roque   Increased recogni...
1900
1901
1902
1903
1904
1905
1906
1907
			}
		}
		v->prop_d[word_idx] = d_prev & (CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV)));

		for (i = word_idx + 1; i < CL_N_WORDS; i++) {
			CHECK_TTL(ttl_ctr, 129)

			if (v->prop_d[i] != 0) {
94b2b13d   Pedro Roque   PHACT source
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
				v->prop_d[i] = 0;
				(*changed) = 1;
			}
		}

		if ((*changed) || v->prop_d[word_idx] != d_prev) {
			if (v->prop_d[word_idx] == 0) {
				v->n_vals = 0;

			} else {
4d26a735   Pedro Roque   Increased recogni...
1918
1919
1920
1921
				v->n_vals = 1;
				v->min = convert_ushort(val);
				v->max = convert_ushort(val);
			}
94b2b13d   Pedro Roque   PHACT source
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
			(*changed) = 1;
		}
#endif
	}
}
#endif

#undef FUNC
#undef FUNC_NAME
#undef CONCAT

#endif
4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source

4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source