/* * cl_bitmap_src.h * * Created on: 14/02/2017 * Author: pedro */ #if CL_D_TYPE == CL_BITMAP #ifndef __OPENCL_VERSION__ #include #include #include #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 * */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_new_vals)(M1 cl_bitmap* d, M2 int* d_vals, int n_vals TTL_CTR) { int i; #if CL_N_WORDS == 1 (*d) = 0; #else for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 104) (*d)[i] = 0; } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_is_empty)(bool* empty, M1 cl_bitmap* d TTL_CTR) { #if CL_N_WORDS == 1 *empty = ((*d) == 0); CHECK_TTL(ttl_ctr, 207) #else *empty = 1; 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; } } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_calc_min_val)(int* min, M1 cl_bitmap* d TTL_CTR) { #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) if ((*d)[j] != 0) { empty = 0; j = CL_N_WORDS; } } #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 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 }; #else // 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 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, 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 }; #endif #if CL_N_WORDS == 1 && CL_WORD == 32 CHECK_TTL(ttl_ctr, 209) *min = mult_bit_pos_32[(CL_WORD_TYPE) (((*d) & -(*d)) * 0x077CB531U) >> 27]; #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) if ((*d)[i] != 0) { #if CL_WORD == 32 *min = mult_bit_pos_32[(CL_WORD_TYPE) (((*d)[i] & -((*d)[i])) * 0x077CB531U) >> 27] + (i << CL_DIV); #else *min = mult_bit_pos_64[(CL_WORD_TYPE) (((*d)[i] & -((*d)[i])) * 0x26752B916FC7B0DUL) >> 58] + (i << CL_DIV); #endif i = CL_N_WORDS; } } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_calc_min_val)(M1 cl_var_p_bitmap* v TTL_CTR) { #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 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 }; #else // 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 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, 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 }; #endif #if CL_N_WORDS == 1 && CL_WORD == 32 CHECK_TTL(ttl_ctr, 211) v->min = mult_bit_pos_32[(CL_WORD_TYPE) ((v->prop_d & -(v->prop_d)) * 0x077CB531U) >> 27]; #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) if (v->prop_d[i] != 0) { #if CL_WORD == 32 v->min = mult_bit_pos_32[(CL_WORD_TYPE) ((v->prop_d[i] & -(v->prop_d[i])) * 0x077CB531U) >> 27] + (i << CL_DIV); #else v->min = convert_ushort(mult_bit_pos_64[(CL_WORD_TYPE) ((v->prop_d[i] & -(v->prop_d[i])) * 0x26752B916FC7B0DUL) >> 58] + (i << CL_DIV)); #endif i = CL_N_WORDS; } } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_calc_max_val)(int* max, M1 cl_bitmap* d TTL_CTR) { #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) if ((*d)[j] != 0) { empty = 0; j = CL_N_WORDS; } } #endif if (empty) { printf((__constant char *)"\n###error 5\n"); } #endif #if CL_N_WORDS == 1 CHECK_TTL(ttl_ctr, 229) *max = convert_int((CL_WORD - clz((*d)) - 1)); #else *max = 0; int i; for (i = CL_N_WORDS - 1; i >= 0; i--) { CHECK_TTL(ttl_ctr, 107) if ((*d)[i] != 0) { *max = convert_int(CL_WORD - 1 + (i << CL_DIV) - convert_int(clz((*d)[i]))); i = -1; } } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_calc_max_val)(M1 cl_var_p_bitmap* v TTL_CTR) { #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) if (v->prop_d[j] != 0) { empty = 0; j = CL_N_WORDS; } } #endif if (empty) { printf((__constant char *)"\n###error 6\n"); } #endif #if CL_N_WORDS == 1 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; } return; } #endif v->max = convert_ushort((CL_WORD - clz(v->prop_d) - 1)); #else #if CL_BOOLEAN_VS 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) 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; } } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_cnt_vals)(M1 cl_bitmap* d, int* n_vals TTL_CTR) { #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) if ((*d)[j] != 0) { empty = 0; j = CL_N_WORDS; } } #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 unsigned short count; CL_WORD_TYPE d_aux = (*d); for (count = 0; d_aux; count++) { CHECK_TTL(ttl_ctr, 108) d_aux &= d_aux - 1; } (*n_vals) = count; #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) count += convert_ushort(popcount((*d)[i])); } (*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) d_aux = (*d)[i]; for (count_aux = 0; d_aux; count_aux++) { CHECK_TTL(ttl_ctr, 111) d_aux &= d_aux - 1; } 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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_cnt_vals)(M1 cl_var_p_bitmap* v TTL_CTR) { #if CL_N_WORDS == 1 #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; } return; } #endif #if __OPENCL_VERSION__ > 110 v->n_vals = convert_ushort(popcount(v->prop_d)); #else int count; CL_WORD_TYPE d_aux = v->prop_d; for (count = 0; d_aux; count++) { CHECK_TTL(ttl_ctr, 108) d_aux &= d_aux - 1; } v->n_vals = convert_ushort(count); #endif #else #if CL_BOOLEAN_VS 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) count += convert_ushort(popcount(v->prop_d[i])); } 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) d_aux = v->prop_d[i]; for (count_aux = 0; d_aux; count_aux++) { CHECK_TTL(ttl_ctr, 111) d_aux &= d_aux - 1; } count += count_aux; } v->n_vals = convert_ushort(count); #endif #endif } #endif #if SUFFIX == _m3 || SUFFIX == _n || SUFFIX == _bd || SUFFIX == _vsg /* * 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 */ 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) { #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) if ((*d)[j] != 0) { empty = 0; j = CL_N_WORDS; } } #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 int vals_ctr = 0; int vals_idx = 0; int i; #if CL_N_WORDS == 1 for (i = 0; i <= CL_D_MAX; i++) { CHECK_TTL(ttl_ctr, 10) if ((*d) & (CL_ONE_ << i)) { vals_ctr++; if (vals_ctr >= first_nth) { vals[vals_idx++] = i; if (vals_ctr == last_nth) { i = CL_D_MAX + 1; } } } } #else int word_idx; for (word_idx = 0; word_idx < CL_N_WORDS; word_idx++) { CHECK_TTL(ttl_ctr, 113) if ((*d)[word_idx] != 0) { for (i = 0; i < CL_WORD; i++) { CHECK_TTL(ttl_ctr, 114) if ((*d)[word_idx] & (CL_ONE_ << i)) { vals_ctr++; if (vals_ctr >= first_nth) { vals[vals_idx++] = (word_idx << CL_DIV) + i; if (vals_ctr == last_nth) { i = CL_WORD; word_idx = CL_N_WORDS; } } } } } } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_ds_equal)(bool* equal, 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); empty2 = ((*d2) == 0); #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; for (j = 0; j < CL_N_WORDS; j++) { CHECK_TTL(ttl_ctr, 115) if ((*d2)[j] != 0) { empty2 = 0; j = CL_N_WORDS; } } #endif if (empty1 || empty2) { printf((__constant char *)"\n###error 11\n"); } #endif #if CL_N_WORDS == 1 *equal = 0; CHECK_TTL(ttl_ctr, 215) if ((*d1) == (*d2)) { *equal = 1; } #else int i; *equal = 1; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 116) if ((*d1)[i] != (*d2)[i]) { *equal = 0; i = CL_N_WORDS; } } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_d_copy)(M1 cl_bitmap* d_dest, M2 cl_bitmap* d_src TTL_CTR) { #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) if ((*d_src)[j] != 0) { empty = 0; j = CL_N_WORDS; } } #endif if (empty) { printf((__constant char *)"\n###error 12\n"); } #endif #if CL_N_WORDS == 1 CHECK_TTL(ttl_ctr, 216) (*d_dest) = (*d_src); #else int i; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 117) (*d_dest)[i] = (*d_src)[i]; } #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 */ 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) { #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) if (v_src->prop_d[j] != 0) { empty = 0; j = CL_N_WORDS; } } #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 #if CL_BOOLEAN_VS v_dest->boolean = v_src->boolean; #endif 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; #if CL_N_WORDS == 1 CHECK_TTL(ttl_ctr, 217) v_dest->prop_d = v_src->prop_d; #else int i; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 118) v_dest->prop_d[i] = v_src->prop_d[i]; } #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_contains_val)(bool* contains, 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 || val < 0 || val > CL_D_MAX) { printf((__constant char *)"\n###error 14\n"); } #endif #if CL_N_WORDS == 1 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); #endif } #endif #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) int i; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 119) (*d)[i] = 0; } #endif } #endif #if SUFFIX == _m || SUFFIX == _n /* * 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 /* * 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 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); empty2 = ((*d2) == 0); #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; for (j = 0; j < CL_N_WORDS; j++) { CHECK_TTL(ttl_ctr, 115) if ((*d2)[j] != 0) { empty2 = 0; j = CL_N_WORDS; } } #endif if (empty1 || empty2) { printf((__constant char *)"\n###error 15\n"); } #endif *changed = 0; #if CL_N_WORDS == 1 CHECK_TTL(ttl_ctr, 221) CL_WORD_TYPE d_prev = *d1; (*d1) &= (*d2); if ((*d1) != d_prev) { *changed = 1; } #else CL_WORD_TYPE d_prev; int i; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 120) d_prev = (*d1)[i]; (*d1)[i] &= (*d2)[i]; (*changed) |= (*d1)[i] != d_prev; } #endif } #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); empty2 = (v2->prop_d == 0); #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; for (j = 0; j < CL_N_WORDS; j++) { CHECK_TTL(ttl_ctr, 115) if (v2->prop_d[j] != 0) { empty2 = 0; j = CL_N_WORDS; } } #endif 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"); } #endif *changed = 0; #if CL_N_WORDS == 1 CHECK_TTL(ttl_ctr, 222) CL_WORD_TYPE d_prev = v1->prop_d; v1->prop_d &= v2->prop_d; if (v1->prop_d != d_prev) { if (v1->prop_d != 0) { FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V); FUNC(cl_v_calc_min_val)(v1 TTL_CTR_V); FUNC(cl_v_calc_max_val)(v1 TTL_CTR_V); } else { v1->n_vals = 0; } *changed = 1; } #else CL_WORD_TYPE d_prev; int i; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 120) d_prev = v1->prop_d[i]; v1->prop_d[i] &= v2->prop_d[i]; (*changed) |= v1->prop_d[i] != d_prev; } if (*changed) { FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V); 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); empty2 = ((*d2) == 0); #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; for (j = 0; j < CL_N_WORDS; j++) { CHECK_TTL(ttl_ctr, 115) if ((*d2)[j] != 0) { empty2 = 0; j = CL_N_WORDS; } } #endif if (empty1 || empty2) { printf((__constant char *)"\n###error 17\n"); } #endif *changed = 0; #if CL_N_WORDS == 1 CHECK_TTL(ttl_ctr, 223) CL_WORD_TYPE d_prev = *d1; (*d1) |= (*d2); if ((*d1) != d_prev) { *changed = 1; } #else CL_WORD_TYPE d_prev; int i; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 120) d_prev = (*d1)[i]; (*d1)[i] |= (*d2)[i]; (*changed) |= (*d1)[i] != d_prev; } #endif } #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); empty2 = (v2->prop_d == 0); #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; for (j = 0; j < CL_N_WORDS; j++) { CHECK_TTL(ttl_ctr, 115) if (v2->prop_d[j] != 0) { empty2 = 0; j = CL_N_WORDS; } } #endif 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"); } #endif *changed = 0; #if CL_N_WORDS == 1 CL_WORD_TYPE d_prev = v1->prop_d; v1->prop_d |= v2->prop_d; if (v1->prop_d != d_prev) { FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V); FUNC(cl_v_calc_min_val)(v1 TTL_CTR_V); FUNC(cl_v_calc_max_val)(v1 TTL_CTR_V); *changed = 1; } #else CL_WORD_TYPE d_prev; int i; for (i = 0; i < CL_N_WORDS; i++) { CHECK_TTL(ttl_ctr, 121) d_prev = v1->prop_d[i]; v1->prop_d[i] |= v2->prop_d[i]; (*changed) |= v1->prop_d[i] != d_prev; } if (*changed) { FUNC(cl_v_cnt_vals)(v1 TTL_CTR_V); 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 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 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 #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); #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 (empty) { printf((__constant char *)"\n###error 20\n"); } #endif *changed = 0; if (val >= 0 && val <= CL_D_MAX) { #if CL_N_WORDS == 1 CL_WORD_TYPE d_prev = (*d); (*d) &= ~(CL_ONE_ << val); *changed = ((*d) != d_prev); #else int word_idx = val >> CL_DIV; CL_WORD_TYPE d_prev = ((*d)[word_idx]); (*d)[word_idx] &= ~(CL_ONE_ << (val - ((val >> CL_DIV) << CL_DIV))); *changed = ((*d)[word_idx] != d_prev); #endif } } #endif #if SUFFIX == _m /* * remove value from reification (boolean) variable when it has always 2 values (0 and 1) * 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); #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 != 2 || v->min != 0 || v->max != 1 || val < 0 || val > 1) { printf((__constant char *)"\n###error 21\n"); } #endif #if CL_N_WORDS == 1 CHECK_TTL(ttl_ctr, 224) if (val == 0) { v->prop_d = 2; v->min = 1; v->n_vals = 1; } else { v->prop_d = 1; v->max = 0; v->n_vals = 1; } #else CHECK_TTL(ttl_ctr, 225) if (val == 0) { 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 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 22\n"); } #endif *changed = 0; if (val >= v->min && val <= v->max) { #if CL_N_WORDS == 1 CL_WORD_TYPE d_prev = v->prop_d; v->prop_d &= ~(CL_ONE_ << val); if (v->prop_d != d_prev) { v->n_vals--; if (v->n_vals != 0) { if (val == v->min) { FUNC(cl_v_calc_min_val)(v TTL_CTR_V); } else if (val == v->max) { FUNC(cl_v_calc_max_val)(v TTL_CTR_V); } } *changed = 1; } #else #if CL_BOOLEAN_VS if (v->boolean) { *changed = 1; v->n_vals--; if (v->n_vals == 1) { v->prop_d[0] &= ~(CL_ONE_ << val); if (val == 0) { v->min = 1; } else { v->max = 0; } } return; } #endif int word_idx = val >> CL_DIV; CL_WORD_TYPE d_prev = v->prop_d[word_idx]; 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 /* * 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 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 (empty || val < 0 || val > CL_D_MAX) { printf((__constant char *)"\n###error 24\n"); } #endif *changed = 0; if (val > CL_D_MAX) { FUNC(cl_d_clear)(d TTL_CTR_V); *changed = 1; } if (val > 0 && val <= CL_D_MAX) { #if CL_N_WORDS == 1 CL_WORD_TYPE d_prev = (*d); (*d) &= (CL_ALL_ONES << val); *changed = ((*d) != d_prev); #else CL_WORD_TYPE w; int limit = val >> CL_DIV; int word_idx; 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; } } 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; *changed = 1; } #endif } } #endif #if SUFFIX == _m || SUFFIX == _n /* * 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 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 || 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); } #endif *changed = 0; if (val > v->max) { FUNC(cl_v_clear)(v); *changed = 1; return; } if (val > v->min) { #if CL_N_WORDS == 1 CL_WORD_TYPE d_prev = v->prop_d; v->prop_d &= (CL_ALL_ONES << val); if (v->prop_d != d_prev) { FUNC(cl_v_cnt_vals)(v TTL_CTR_V); FUNC(cl_v_calc_min_val)(v TTL_CTR_V); *changed = 1; } #else #if CL_BOOLEAN_VS if (v->boolean) { v->prop_d[0] = 2; 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; 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; } } #ifndef __OPENCL_VERSION__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" #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 /* * 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"); } #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 /* * 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 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 (empty || val < 0 || val > CL_D_MAX) { printf((__constant char *)"\n###error 27\n"); } #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 CL_WORD_TYPE d_prev = (*d); (*d) &= (CL_ALL_ONES >> (CL_REM - val)); *changed = ((*d) != d_prev); #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)))); 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 } } #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) { #if CL_CHECK_ERRORS bool contains; 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 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 #if CL_BOOLEAN_VS if (v->boolean) { v->prop_d = 1; v->max = 0; v->n_vals = 1; return; } #endif v->prop_d &= (CL_ALL_ONES >> (CL_WORD - 1 - val)); FUNC(cl_v_cnt_vals)(v TTL_CTR_V); FUNC(cl_v_calc_max_val)(v TTL_CTR_V); #else #if CL_BOOLEAN_VS if (v->boolean) { v->prop_d[0] = 1; v->max = 0; v->n_vals--; return; } #endif 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; } FUNC(cl_v_cnt_vals)(v TTL_CTR_V); FUNC(cl_v_calc_max_val)(v TTL_CTR_V); #endif } #endif #if SUFFIX == _m || SUFFIX == _n /* * Remove from the variable all the values greater than val * 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 *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) { v->prop_d[0] = 1; v->max = 0; v->n_vals--; (*changed) = 1; return; } #endif CL_WORD_TYPE w; int word_idx = val >> CL_DIV; 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; } } 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_max_val)(v TTL_CTR_V); } (*changed) = 1; } #endif } } #endif #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 */ FUNC_PREFIX CUDA_FUNC void FUNC(cl_v_del_ge)(bool* changed, M1 cl_var_p_bitmap* v, int val TTL_CTR) { FUNC(cl_v_del_gt)(changed, v, --val TTL_CTR_V); } #endif #if SUFFIX == _m || SUFFIX == _n /* * Clear all values from variable, except val if present * 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) { 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 || 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; } else { #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; } else { v->n_vals = 1; v->min = convert_ushort(val); v->max = convert_ushort(val); } *changed = 1; } #else #if CL_BOOLEAN_VS if (v->boolean) { if (v->n_vals == 2) { v->prop_d[0] &= (CL_ONE_ << val); v->max = convert_ushort(val); v->min = convert_ushort(val); v->n_vals = 1; *changed = 1; } return; } #endif int word_idx = val >> CL_DIV; int min_idx = v->min >> CL_DIV; CL_WORD_TYPE d_prev = v->prop_d[word_idx]; int i; for (i = min_idx; i < word_idx; i++) { CHECK_TTL(ttl_ctr, 128) if (v->prop_d[i] != 0) { v->prop_d[i] = 0; (*changed) = 1; } } 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) { 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 { v->n_vals = 1; v->min = convert_ushort(val); v->max = convert_ushort(val); } (*changed) = 1; } #endif } } #endif #undef FUNC #undef FUNC_NAME #undef CONCAT #endif