1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9#include "monetdb_config.h"
10#include "gdk.h"
11#include "gdk_private.h"
12#include "gdk_calc_private.h"
13#include <math.h>
14
15/* Define symbol FULL_IMPLEMENTATION to get implementations for all
16 * sensible output types for +, -, *, /. Without the symbol, all
17 * combinations of input types are supported, but only output types
18 * that are either the largest of the input types or one size larger
19 * (if available) for +, -, *. For division the output type can be
20 * either input type of flt or dbl. */
21
22#define FULL_IMPLEMENTATION
23
24/* Generally, the functions return a new BAT aligned with the input
25 * BAT(s). If there are multiple input BATs, they must be aligned.
26 * If there is a candidate list, the calculations are only done for
27 * the candidates, all other values are NIL (so that the output is
28 * still aligned). */
29
30/* format strings for the seven/eight basic types we deal with */
31#define FMTbte "%d"
32#define FMTsht "%d"
33#define FMTint "%d"
34#define FMTlng LLFMT
35#ifdef HAVE_HGE
36#define FMThge "%.40g"
37#endif
38#define FMTflt "%.9g"
39#define FMTdbl "%.17g"
40#define FMToid OIDFMT
41
42/* casts; only required for type hge, since there is no genuine format
43 * string for it (i.e., for __int128) (yet?) */
44#define CSTbte
45#define CSTsht
46#define CSTint
47#define CSTlng
48#ifdef HAVE_HGE
49#define CSThge (dbl)
50#endif
51#define CSTflt
52#define CSTdbl
53#define CSToid
54
55/* Most of the internal routines return a count of the number of NIL
56 * values they produced. They indicate an error by returning a value
57 * >= BUN_NONE. BUN_NONE means that the error was dealt with by
58 * calling GDKerror (generally for overflow or conversion errors).
59 * BUN_NONE+1 is returned by the DIV and MOD functions to indicate
60 * division by zero. */
61
62/* replace BATconstant with a version that produces a void bat for
63 * TYPE_oid/nil */
64#define BATconstantV(HSEQ, TAILTYPE, VALUE, CNT, ROLE) \
65 ((TAILTYPE) == TYPE_oid && ((CNT) == 0 || *(oid*)(VALUE) == oid_nil) \
66 ? BATconstant(HSEQ, TYPE_void, VALUE, CNT, ROLE) \
67 : BATconstant(HSEQ, TAILTYPE, VALUE, CNT, ROLE))
68
69static gdk_return
70checkbats(BAT *b1, BAT *b2, const char *func)
71{
72 if (b1->batCount != b2->batCount) {
73 GDKerror("%s: inputs not the same size.\n", func);
74 return GDK_FAIL;
75 }
76 return GDK_SUCCEED;
77}
78
79#define UNARY_2TYPE_FUNC(TYPE1, TYPE2, FUNC) \
80 do { \
81 const TYPE1 *restrict src = (const TYPE1 *) Tloc(b, 0); \
82 TYPE2 *restrict dst = (TYPE2 *) Tloc(bn, 0); \
83 x = canditer_next(&ci) - b->hseqbase; \
84 i = 0; \
85 do { \
86 while (i < x) { \
87 dst[i++] = TYPE2##_nil; \
88 nils++; \
89 } \
90 if (is_##TYPE1##_nil(src[i])) { \
91 nils++; \
92 dst[i] = TYPE2##_nil; \
93 } else { \
94 dst[i] = FUNC(src[i]); \
95 } \
96 i++; \
97 x = canditer_next(&ci); \
98 if (is_oid_nil(x)) \
99 break; \
100 x -= b->hseqbase; \
101 } while (i < cnt); \
102 while (i < cnt) { \
103 dst[i++] = TYPE2##_nil; \
104 nils++; \
105 } \
106 } while (0)
107
108#define BINARY_3TYPE_FUNC(TYPE1, TYPE2, TYPE3, FUNC) \
109 do { \
110 do { \
111 while (k < x) { \
112 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
113 nils++; \
114 } \
115 i = x * incr1; \
116 j = x * incr2; \
117 TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
118 TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
119 if (is_##TYPE1##_nil(v1) || is_##TYPE2##_nil(v2)) { \
120 nils++; \
121 ((TYPE3 *) dst)[k] = TYPE3##_nil; \
122 } else { \
123 ((TYPE3 *) dst)[k] = FUNC(v1, v2); \
124 } \
125 k++; \
126 x = canditer_next(ci); \
127 if (is_oid_nil(x)) \
128 break; \
129 x -= candoff; \
130 } while (k < cnt); \
131 while (k < cnt) { \
132 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
133 nils++; \
134 } \
135 } while (0)
136
137/* special case for EQ and NE where we have a nil_matches flag for
138 * when it is set */
139#define BINARY_3TYPE_FUNC_nilmatch(TYPE1, TYPE2, TYPE3, FUNC) \
140 do { \
141 do { \
142 while (k < x) { \
143 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
144 nils++; \
145 } \
146 i = x * incr1; \
147 j = x * incr2; \
148 TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
149 TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
150 if (is_##TYPE1##_nil(v1) || is_##TYPE2##_nil(v2)) { \
151 ((TYPE3 *) dst)[k] = FUNC(is_##TYPE1##_nil(v1), is_##TYPE2##_nil(v2)); \
152 } else { \
153 ((TYPE3 *) dst)[k] = FUNC(v1, v2); \
154 } \
155 k++; \
156 x = canditer_next(ci); \
157 if (is_oid_nil(x)) \
158 break; \
159 x -= candoff; \
160 } while (k < cnt); \
161 while (k < cnt) { \
162 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
163 nils++; \
164 } \
165 } while (0)
166
167#define BINARY_3TYPE_FUNC_nonil(TYPE1, TYPE2, TYPE3, FUNC) \
168 do { \
169 do { \
170 while (k < x) { \
171 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
172 nils++; \
173 } \
174 i = x * incr1; \
175 j = x * incr2; \
176 TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
177 TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
178 ((TYPE3 *) dst)[k] = FUNC(v1, v2); \
179 k++; \
180 x = canditer_next(ci); \
181 if (is_oid_nil(x)) \
182 break; \
183 x -= candoff; \
184 } while (k < cnt); \
185 while (k < cnt) { \
186 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
187 nils++; \
188 } \
189 } while (0)
190
191#define BINARY_3TYPE_FUNC_CHECK(TYPE1, TYPE2, TYPE3, FUNC, CHECK) \
192 do { \
193 do { \
194 while (k < x) { \
195 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
196 nils++; \
197 } \
198 i = x * incr1; \
199 j = x * incr2; \
200 TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
201 TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
202 if (is_##TYPE1##_nil(v1) || is_##TYPE2##_nil(v2)) { \
203 nils++; \
204 ((TYPE3 *) dst)[k] = TYPE3##_nil; \
205 } else if (CHECK(v1, v2)) { \
206 if (abort_on_error) { \
207 GDKerror("%s: shift operand too large in " \
208 #FUNC"("FMT##TYPE1","FMT##TYPE2").\n", \
209 func, \
210 CST##TYPE1 v1, \
211 CST##TYPE2 v2); \
212 goto checkfail; \
213 } \
214 ((TYPE3 *)dst)[k] = TYPE3##_nil; \
215 nils++; \
216 } else { \
217 ((TYPE3 *) dst)[k] = FUNC(v1, v2); \
218 } \
219 k++; \
220 x = canditer_next(ci); \
221 if (is_oid_nil(x)) \
222 break; \
223 x -= candoff; \
224 } while (k < cnt); \
225 while (k < cnt) { \
226 ((TYPE3 *) dst)[k++] = TYPE3##_nil; \
227 nils++; \
228 } \
229 } while (0)
230
231/* ---------------------------------------------------------------------- */
232/* logical (for type bit) or bitwise (for integral types) NOT */
233
234#define NOT(x) (~(x))
235#define NOTBIT(x) (!(x))
236
237BAT *
238BATcalcnot(BAT *b, BAT *s)
239{
240 BAT *bn;
241 BUN nils = 0;
242 BUN i, cnt, ncand;
243 oid x;
244 struct canditer ci;
245
246 BATcheck(b, __func__, NULL);
247 cnt = BATcount(b);
248 ncand = canditer_init(&ci, b, s);
249 if (ncand == 0)
250 return BATconstant(b->hseqbase, b->ttype,
251 ATOMnilptr(b->ttype), cnt, TRANSIENT);
252
253 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
254 if (bn == NULL)
255 return NULL;
256
257 switch (ATOMbasetype(b->ttype)) {
258 case TYPE_bte:
259 if (b->ttype == TYPE_bit) {
260 UNARY_2TYPE_FUNC(bit, bit, NOTBIT);
261 } else {
262 UNARY_2TYPE_FUNC(bte, bte, NOT);
263 }
264 break;
265 case TYPE_sht:
266 UNARY_2TYPE_FUNC(sht, sht, NOT);
267 break;
268 case TYPE_int:
269 UNARY_2TYPE_FUNC(int, int, NOT);
270 break;
271 case TYPE_lng:
272 UNARY_2TYPE_FUNC(lng, lng, NOT);
273 break;
274#ifdef HAVE_HGE
275 case TYPE_hge:
276 UNARY_2TYPE_FUNC(hge, hge, NOT);
277 break;
278#endif
279 default:
280 BBPunfix(bn->batCacheid);
281 GDKerror("%s: type %s not supported.\n",
282 __func__, ATOMname(b->ttype));
283 return NULL;
284 }
285
286 BATsetcount(bn, cnt);
287
288 /* NOT reverses the order, but NILs mess it up */
289 bn->tsorted = nils == 0 && b->trevsorted;
290 bn->trevsorted = nils == 0 && b->tsorted;
291 bn->tnil = nils != 0;
292 bn->tnonil = nils == 0;
293 bn->tkey = b->tkey && nils <= 1;
294
295 if (nils != 0 && !b->tnil) {
296 b->tnil = true;
297 b->batDirtydesc = true;
298 }
299 if (nils == 0 && !b->tnonil) {
300 b->tnonil = true;
301 b->batDirtydesc = true;
302 }
303
304 return bn;
305}
306
307gdk_return
308VARcalcnot(ValPtr ret, const ValRecord *v)
309{
310 ret->vtype = v->vtype;
311 switch (ATOMbasetype(v->vtype)) {
312 case TYPE_bte:
313 if (is_bit_nil(v->val.btval))
314 ret->val.btval = bit_nil;
315 else if (v->vtype == TYPE_bit)
316 ret->val.btval = !v->val.btval;
317 else
318 ret->val.btval = ~v->val.btval;
319 break;
320 case TYPE_sht:
321 if (is_sht_nil(v->val.shval))
322 ret->val.shval = sht_nil;
323 else
324 ret->val.shval = ~v->val.shval;
325 break;
326 case TYPE_int:
327 if (is_int_nil(v->val.ival))
328 ret->val.ival = int_nil;
329 else
330 ret->val.ival = ~v->val.ival;
331 break;
332 case TYPE_lng:
333 if (is_lng_nil(v->val.lval))
334 ret->val.lval = lng_nil;
335 else
336 ret->val.lval = ~v->val.lval;
337 break;
338#ifdef HAVE_HGE
339 case TYPE_hge:
340 if (is_hge_nil(v->val.hval))
341 ret->val.hval = hge_nil;
342 else
343 ret->val.hval = ~v->val.hval;
344 break;
345#endif
346 default:
347 GDKerror("VARcalcnot: bad input type %s.\n",
348 ATOMname(v->vtype));
349 return GDK_FAIL;
350 }
351 return GDK_SUCCEED;
352}
353
354/* ---------------------------------------------------------------------- */
355/* negate value (any numeric type) */
356
357#define NEGATE(x) (-(x))
358
359BAT *
360BATcalcnegate(BAT *b, BAT *s)
361{
362 BAT *bn;
363 BUN nils = 0;
364 BUN i, cnt, ncand;
365 oid x;
366 struct canditer ci;
367
368 BATcheck(b, __func__, NULL);
369 cnt = BATcount(b);
370 ncand = canditer_init(&ci, b, s);
371 if (ncand == 0)
372 return BATconstant(b->hseqbase, b->ttype,
373 ATOMnilptr(b->ttype), cnt, TRANSIENT);
374
375 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
376 if (bn == NULL)
377 return NULL;
378
379 switch (ATOMbasetype(b->ttype)) {
380 case TYPE_bte:
381 UNARY_2TYPE_FUNC(bte, bte, NEGATE);
382 break;
383 case TYPE_sht:
384 UNARY_2TYPE_FUNC(sht, sht, NEGATE);
385 break;
386 case TYPE_int:
387 UNARY_2TYPE_FUNC(int, int, NEGATE);
388 break;
389 case TYPE_lng:
390 UNARY_2TYPE_FUNC(lng, lng, NEGATE);
391 break;
392#ifdef HAVE_HGE
393 case TYPE_hge:
394 UNARY_2TYPE_FUNC(hge, hge, NEGATE);
395 break;
396#endif
397 case TYPE_flt:
398 UNARY_2TYPE_FUNC(flt, flt, NEGATE);
399 break;
400 case TYPE_dbl:
401 UNARY_2TYPE_FUNC(dbl, dbl, NEGATE);
402 break;
403 default:
404 BBPunfix(bn->batCacheid);
405 GDKerror("%s: type %s not supported.\n", __func__,
406 ATOMname(b->ttype));
407 return NULL;
408 }
409
410 BATsetcount(bn, cnt);
411
412 /* unary - reverses the order, but NILs mess it up */
413 bn->tsorted = nils == 0 && b->trevsorted;
414 bn->trevsorted = nils == 0 && b->tsorted;
415 bn->tnil = nils != 0;
416 bn->tnonil = nils == 0;
417 bn->tkey = b->tkey && nils <= 1;
418
419 if (nils != 0 && !b->tnil) {
420 b->tnil = true;
421 b->batDirtydesc = true;
422 }
423 if (nils == 0 && !b->tnonil) {
424 b->tnonil = true;
425 b->batDirtydesc = true;
426 }
427
428 return bn;
429}
430
431gdk_return
432VARcalcnegate(ValPtr ret, const ValRecord *v)
433{
434 ret->vtype = v->vtype;
435 switch (ATOMbasetype(v->vtype)) {
436 case TYPE_bte:
437 if (is_bte_nil(v->val.btval))
438 ret->val.btval = bte_nil;
439 else
440 ret->val.btval = -v->val.btval;
441 break;
442 case TYPE_sht:
443 if (is_sht_nil(v->val.shval))
444 ret->val.shval = sht_nil;
445 else
446 ret->val.shval = -v->val.shval;
447 break;
448 case TYPE_int:
449 if (is_int_nil(v->val.ival))
450 ret->val.ival = int_nil;
451 else
452 ret->val.ival = -v->val.ival;
453 break;
454 case TYPE_lng:
455 if (is_lng_nil(v->val.lval))
456 ret->val.lval = lng_nil;
457 else
458 ret->val.lval = -v->val.lval;
459 break;
460#ifdef HAVE_HGE
461 case TYPE_hge:
462 if (is_hge_nil(v->val.hval))
463 ret->val.hval = hge_nil;
464 else
465 ret->val.hval = -v->val.hval;
466 break;
467#endif
468 case TYPE_flt:
469 if (is_flt_nil(v->val.fval))
470 ret->val.fval = flt_nil;
471 else
472 ret->val.fval = -v->val.fval;
473 break;
474 case TYPE_dbl:
475 if (is_dbl_nil(v->val.dval))
476 ret->val.dval = dbl_nil;
477 else
478 ret->val.dval = -v->val.dval;
479 break;
480 default:
481 GDKerror("VARcalcnegate: bad input type %s.\n",
482 ATOMname(v->vtype));
483 return GDK_FAIL;
484 }
485 return GDK_SUCCEED;
486}
487
488/* ---------------------------------------------------------------------- */
489/* absolute value (any numeric type) */
490
491BAT *
492BATcalcabsolute(BAT *b, BAT *s)
493{
494 BAT *bn;
495 BUN nils= 0;
496 BUN i, cnt, ncand;
497 oid x;
498 struct canditer ci;
499
500 BATcheck(b, __func__, NULL);
501 cnt = BATcount(b);
502 ncand = canditer_init(&ci, b, s);
503 if (ncand == 0)
504 return BATconstant(b->hseqbase, b->ttype,
505 ATOMnilptr(b->ttype), cnt, TRANSIENT);
506
507 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
508 if (bn == NULL)
509 return NULL;
510
511 switch (ATOMbasetype(b->ttype)) {
512 case TYPE_bte:
513 UNARY_2TYPE_FUNC(bte, bte, (bte) abs);
514 break;
515 case TYPE_sht:
516 UNARY_2TYPE_FUNC(sht, sht, (sht) abs);
517 break;
518 case TYPE_int:
519 UNARY_2TYPE_FUNC(int, int, abs);
520 break;
521 case TYPE_lng:
522 UNARY_2TYPE_FUNC(lng, lng, llabs);
523 break;
524#ifdef HAVE_HGE
525 case TYPE_hge:
526 UNARY_2TYPE_FUNC(hge, hge, ABSOLUTE);
527 break;
528#endif
529 case TYPE_flt:
530 UNARY_2TYPE_FUNC(flt, flt, fabsf);
531 break;
532 case TYPE_dbl:
533 UNARY_2TYPE_FUNC(dbl, dbl, fabs);
534 break;
535 default:
536 BBPunfix(bn->batCacheid);
537 GDKerror("%s: bad input type %s.\n", __func__,
538 ATOMname(b->ttype));
539 return NULL;
540 }
541
542 BATsetcount(bn, cnt);
543
544 /* ABSOLUTE messes up order (unless all values were negative
545 * or all values were positive, but we don't know anything
546 * about that) */
547 bn->tsorted = cnt <= 1 || nils == cnt;
548 bn->trevsorted = cnt <= 1 || nils == cnt;
549 bn->tkey = cnt <= 1;
550 bn->tnil = nils != 0;
551 bn->tnonil = nils == 0;
552
553 if (nils && !b->tnil) {
554 b->tnil = true;
555 b->batDirtydesc = true;
556 }
557 if (nils == 0 && !b->tnonil) {
558 b->tnonil = true;
559 b->batDirtydesc = true;
560 }
561
562 return bn;
563}
564
565gdk_return
566VARcalcabsolute(ValPtr ret, const ValRecord *v)
567{
568 ret->vtype = v->vtype;
569 switch (ATOMbasetype(v->vtype)) {
570 case TYPE_bte:
571 if (is_bte_nil(v->val.btval))
572 ret->val.btval = bte_nil;
573 else
574 ret->val.btval = (bte) abs(v->val.btval);
575 break;
576 case TYPE_sht:
577 if (is_sht_nil(v->val.shval))
578 ret->val.shval = sht_nil;
579 else
580 ret->val.shval = (sht) abs(v->val.shval);
581 break;
582 case TYPE_int:
583 if (is_int_nil(v->val.ival))
584 ret->val.ival = int_nil;
585 else
586 ret->val.ival = abs(v->val.ival);
587 break;
588 case TYPE_lng:
589 if (is_lng_nil(v->val.lval))
590 ret->val.lval = lng_nil;
591 else
592 ret->val.lval = llabs(v->val.lval);
593 break;
594#ifdef HAVE_HGE
595 case TYPE_hge:
596 if (is_hge_nil(v->val.hval))
597 ret->val.hval = hge_nil;
598 else
599 ret->val.hval = ABSOLUTE(v->val.hval);
600 break;
601#endif
602 case TYPE_flt:
603 if (is_flt_nil(v->val.fval))
604 ret->val.fval = flt_nil;
605 else
606 ret->val.fval = fabsf(v->val.fval);
607 break;
608 case TYPE_dbl:
609 if (is_dbl_nil(v->val.dval))
610 ret->val.dval = dbl_nil;
611 else
612 ret->val.dval = fabs(v->val.dval);
613 break;
614 default:
615 GDKerror("VARcalcabsolute: bad input type %s.\n",
616 ATOMname(v->vtype));
617 return GDK_FAIL;
618 }
619 return GDK_SUCCEED;
620}
621
622/* ---------------------------------------------------------------------- */
623/* is the value equal to zero (any numeric type) */
624
625#define ISZERO(x) ((bit) ((x) == 0))
626
627BAT *
628BATcalciszero(BAT *b, BAT *s)
629{
630 BAT *bn;
631 BUN nils = 0;
632 BUN i, cnt, ncand;
633 oid x;
634 struct canditer ci;
635
636 BATcheck(b, __func__, NULL);
637 cnt = BATcount(b);
638 ncand = canditer_init(&ci, b, s);
639 if (ncand == 0)
640 return BATconstant(b->hseqbase, TYPE_bit,
641 ATOMnilptr(TYPE_bit), cnt, TRANSIENT);
642
643 bn = COLnew(b->hseqbase, TYPE_bit, cnt, TRANSIENT);
644 if (bn == NULL)
645 return NULL;
646
647 switch (ATOMbasetype(b->ttype)) {
648 case TYPE_bte:
649 UNARY_2TYPE_FUNC(bte, bit, ISZERO);
650 break;
651 case TYPE_sht:
652 UNARY_2TYPE_FUNC(sht, bit, ISZERO);
653 break;
654 case TYPE_int:
655 UNARY_2TYPE_FUNC(int, bit, ISZERO);
656 break;
657 case TYPE_lng:
658 UNARY_2TYPE_FUNC(lng, bit, ISZERO);
659 break;
660#ifdef HAVE_HGE
661 case TYPE_hge:
662 UNARY_2TYPE_FUNC(hge, bit, ISZERO);
663 break;
664#endif
665 case TYPE_flt:
666 UNARY_2TYPE_FUNC(flt, bit, ISZERO);
667 break;
668 case TYPE_dbl:
669 UNARY_2TYPE_FUNC(dbl, bit, ISZERO);
670 break;
671 default:
672 BBPunfix(bn->batCacheid);
673 GDKerror("%s: bad input type %s.\n", __func__,
674 ATOMname(b->ttype));
675 return NULL;
676 }
677
678 BATsetcount(bn, cnt);
679
680 bn->tsorted = cnt <= 1 || nils == cnt;
681 bn->trevsorted = cnt <= 1 || nils == cnt;
682 bn->tkey = cnt <= 1;
683 bn->tnil = nils != 0;
684 bn->tnonil = nils == 0;
685
686 if (nils != 0 && !b->tnil) {
687 b->tnil = true;
688 b->batDirtydesc = true;
689 }
690 if (nils == 0 && !b->tnonil) {
691 b->tnonil = true;
692 b->batDirtydesc = true;
693 }
694
695 return bn;
696}
697
698gdk_return
699VARcalciszero(ValPtr ret, const ValRecord *v)
700{
701 ret->vtype = TYPE_bit;
702 switch (ATOMbasetype(v->vtype)) {
703 case TYPE_bte:
704 if (is_bte_nil(v->val.btval))
705 ret->val.btval = bit_nil;
706 else
707 ret->val.btval = ISZERO(v->val.btval);
708 break;
709 case TYPE_sht:
710 if (is_sht_nil(v->val.shval))
711 ret->val.btval = bit_nil;
712 else
713 ret->val.btval = ISZERO(v->val.shval);
714 break;
715 case TYPE_int:
716 if (is_int_nil(v->val.ival))
717 ret->val.btval = bit_nil;
718 else
719 ret->val.btval = ISZERO(v->val.ival);
720 break;
721 case TYPE_lng:
722 if (is_lng_nil(v->val.lval))
723 ret->val.btval = bit_nil;
724 else
725 ret->val.btval = ISZERO(v->val.lval);
726 break;
727#ifdef HAVE_HGE
728 case TYPE_hge:
729 if (is_hge_nil(v->val.hval))
730 ret->val.btval = bit_nil;
731 else
732 ret->val.btval = ISZERO(v->val.hval);
733 break;
734#endif
735 case TYPE_flt:
736 if (is_flt_nil(v->val.fval))
737 ret->val.btval = bit_nil;
738 else
739 ret->val.btval = ISZERO(v->val.fval);
740 break;
741 case TYPE_dbl:
742 if (is_dbl_nil(v->val.dval))
743 ret->val.btval = bit_nil;
744 else
745 ret->val.btval = ISZERO(v->val.dval);
746 break;
747 default:
748 GDKerror("VARcalciszero: bad input type %s.\n",
749 ATOMname(v->vtype));
750 return GDK_FAIL;
751 }
752 return GDK_SUCCEED;
753}
754
755/* ---------------------------------------------------------------------- */
756/* sign of value (-1 for negative, 0 for 0, +1 for positive; any
757 * numeric type) */
758
759#define SIGN(x) ((bte) ((x) < 0 ? -1 : (x) > 0))
760
761BAT *
762BATcalcsign(BAT *b, BAT *s)
763{
764 BAT *bn;
765 BUN nils = 0;
766 BUN i, cnt, ncand;
767 oid x;
768 struct canditer ci;
769
770 BATcheck(b, __func__, NULL);
771 cnt = BATcount(b);
772 ncand = canditer_init(&ci, b, s);
773 if (ncand == 0)
774 return BATconstant(b->hseqbase, TYPE_bte,
775 ATOMnilptr(TYPE_bte), cnt, TRANSIENT);
776
777 bn = COLnew(b->hseqbase, TYPE_bte, cnt, TRANSIENT);
778 if (bn == NULL)
779 return NULL;
780
781 switch (ATOMbasetype(b->ttype)) {
782 case TYPE_bte:
783 UNARY_2TYPE_FUNC(bte, bte, SIGN);
784 break;
785 case TYPE_sht:
786 UNARY_2TYPE_FUNC(sht, bte, SIGN);
787 break;
788 case TYPE_int:
789 UNARY_2TYPE_FUNC(int, bte, SIGN);
790 break;
791 case TYPE_lng:
792 UNARY_2TYPE_FUNC(lng, bte, SIGN);
793 break;
794#ifdef HAVE_HGE
795 case TYPE_hge:
796 UNARY_2TYPE_FUNC(hge, bte, SIGN);
797 break;
798#endif
799 case TYPE_flt:
800 UNARY_2TYPE_FUNC(flt, bte, SIGN);
801 break;
802 case TYPE_dbl:
803 UNARY_2TYPE_FUNC(dbl, bte, SIGN);
804 break;
805 default:
806 BBPunfix(bn->batCacheid);
807 GDKerror("%s: bad input type %s.\n", __func__,
808 ATOMname(b->ttype));
809 return NULL;
810 }
811
812 BATsetcount(bn, cnt);
813
814 /* SIGN is ordered if the input is ordered (negative comes
815 * first, positive comes after) and NILs stay in the same
816 * position */
817 bn->tsorted = b->tsorted || cnt <= 1 || nils == cnt;
818 bn->trevsorted = b->trevsorted || cnt <= 1 || nils == cnt;
819 bn->tkey = cnt <= 1;
820 bn->tnil = nils != 0;
821 bn->tnonil = nils == 0;
822
823 if (nils != 0 && !b->tnil) {
824 b->tnil = true;
825 b->batDirtydesc = true;
826 }
827 if (nils == 0 && !b->tnonil) {
828 b->tnonil = true;
829 b->batDirtydesc = true;
830 }
831
832 return bn;
833}
834
835gdk_return
836VARcalcsign(ValPtr ret, const ValRecord *v)
837{
838 ret->vtype = TYPE_bte;
839 switch (ATOMbasetype(v->vtype)) {
840 case TYPE_bte:
841 if (is_bte_nil(v->val.btval))
842 ret->val.btval = bte_nil;
843 else
844 ret->val.btval = SIGN(v->val.btval);
845 break;
846 case TYPE_sht:
847 if (is_sht_nil(v->val.shval))
848 ret->val.btval = bte_nil;
849 else
850 ret->val.btval = SIGN(v->val.shval);
851 break;
852 case TYPE_int:
853 if (is_int_nil(v->val.ival))
854 ret->val.btval = bte_nil;
855 else
856 ret->val.btval = SIGN(v->val.ival);
857 break;
858 case TYPE_lng:
859 if (is_lng_nil(v->val.lval))
860 ret->val.btval = bte_nil;
861 else
862 ret->val.btval = SIGN(v->val.lval);
863 break;
864#ifdef HAVE_HGE
865 case TYPE_hge:
866 if (is_hge_nil(v->val.hval))
867 ret->val.btval = bte_nil;
868 else
869 ret->val.btval = SIGN(v->val.hval);
870 break;
871#endif
872 case TYPE_flt:
873 if (is_flt_nil(v->val.fval))
874 ret->val.btval = bte_nil;
875 else
876 ret->val.btval = SIGN(v->val.fval);
877 break;
878 case TYPE_dbl:
879 if (is_dbl_nil(v->val.dval))
880 ret->val.btval = bte_nil;
881 else
882 ret->val.btval = SIGN(v->val.dval);
883 break;
884 default:
885 GDKerror("VARcalcsign: bad input type %s.\n",
886 ATOMname(v->vtype));
887 return GDK_FAIL;
888 }
889 return GDK_SUCCEED;
890}
891
892/* ---------------------------------------------------------------------- */
893/* is the value nil (any type) */
894
895#define ISNIL_TYPE(TYPE, NOTNIL) \
896 do { \
897 const TYPE *restrict src = (const TYPE *) Tloc(b, 0); \
898 do { \
899 while (i < x) { \
900 dst[i++] = bit_nil; \
901 nils++; \
902 } \
903 dst[i] = (bit) ((is_##TYPE##_nil(src[i])) ^ NOTNIL); \
904 i++; \
905 x = canditer_next(&ci); \
906 if (is_oid_nil(x)) \
907 break; \
908 x -= b->hseqbase; \
909 } while (i < cnt); \
910 } while (0)
911
912static BAT *
913BATcalcisnil_implementation(BAT *b, BAT *s, int notnil)
914{
915 BAT *bn;
916 BUN i, cnt, ncand;
917 oid x;
918 struct canditer ci;
919 bit *restrict dst;
920 BUN nils = 0;
921
922 BATcheck(b, __func__, NULL);
923
924 cnt = BATcount(b);
925 ncand = canditer_init(&ci, b, s);
926 if (ncand == 0)
927 return BATconstant(b->hseqbase, TYPE_bit,
928 ATOMnilptr(TYPE_bit), cnt, TRANSIENT);
929
930 if (ncand == cnt) {
931 if (b->tnonil || BATtdense(b)) {
932 return BATconstant(b->hseqbase, TYPE_bit, &(bit){0},
933 cnt, TRANSIENT);
934 } else if (b->ttype == TYPE_void) {
935 /* non-nil handled above */
936 assert(is_oid_nil(b->tseqbase));
937 return BATconstant(b->hseqbase, TYPE_bit, &(bit){1},
938 cnt, TRANSIENT);
939 }
940 }
941
942 bn = COLnew(b->hseqbase, TYPE_bit, cnt, TRANSIENT);
943 if (bn == NULL)
944 return NULL;
945
946 dst = (bit *) Tloc(bn, 0);
947 x = canditer_next(&ci) - b->hseqbase;
948 i = 0;
949
950 switch (ATOMbasetype(b->ttype)) {
951 case TYPE_bte:
952 ISNIL_TYPE(bte, notnil);
953 break;
954 case TYPE_sht:
955 ISNIL_TYPE(sht, notnil);
956 break;
957 case TYPE_int:
958 ISNIL_TYPE(int, notnil);
959 break;
960 case TYPE_lng:
961 ISNIL_TYPE(lng, notnil);
962 break;
963#ifdef HAVE_HGE
964 case TYPE_hge:
965 ISNIL_TYPE(hge, notnil);
966 break;
967#endif
968 case TYPE_flt:
969 ISNIL_TYPE(flt, notnil);
970 break;
971 case TYPE_dbl:
972 ISNIL_TYPE(dbl, notnil);
973 break;
974 default:
975 {
976 BATiter bi = bat_iterator(b);
977 int (*atomcmp)(const void *, const void *) = ATOMcompare(b->ttype);
978 const void *nil = ATOMnilptr(b->ttype);
979
980 do {
981 while (i < x) {
982 dst[i++] = bit_nil;
983 nils++;
984 }
985 dst[i] = (bit) (((*atomcmp)(BUNtail(bi, i), nil) == 0) ^ notnil);
986 i++;
987 x = canditer_next(&ci);
988 if (is_oid_nil(x))
989 break;
990 x -= b->hseqbase;
991 } while (i < cnt);
992 break;
993 }
994 }
995 while (i < cnt) {
996 dst[i++] = bit_nil;
997 nils++;
998 }
999
1000 BATsetcount(bn, cnt);
1001
1002 /* If b sorted, all nils are at the start, i.e. bn starts with
1003 * 1's and ends with 0's, hence bn is revsorted. Similarly
1004 * for revsorted. This reasoning breaks down if there is a
1005 * candidate list. */
1006 bn->tsorted = s == NULL && b->trevsorted;
1007 bn->trevsorted = s == NULL && b->tsorted;
1008 bn->tnil = nils != 0;
1009 bn->tnonil = nils == 0;
1010 bn->tkey = cnt <= 1;
1011
1012 return bn;
1013}
1014
1015BAT *
1016BATcalcisnil(BAT *b, BAT *s)
1017{
1018 return BATcalcisnil_implementation(b, s, 0);
1019}
1020
1021BAT *
1022BATcalcisnotnil(BAT *b, BAT *s)
1023{
1024 return BATcalcisnil_implementation(b, s, 1);
1025}
1026
1027gdk_return
1028VARcalcisnil(ValPtr ret, const ValRecord *v)
1029{
1030 ret->vtype = TYPE_bit;
1031 ret->val.btval = (bit) VALisnil(v);
1032 return GDK_SUCCEED;
1033}
1034
1035gdk_return
1036VARcalcisnotnil(ValPtr ret, const ValRecord *v)
1037{
1038 ret->vtype = TYPE_bit;
1039 ret->val.btval = (bit) !VALisnil(v);
1040 return GDK_SUCCEED;
1041}
1042
1043BAT *
1044BATcalcmin(BAT *b1, BAT *b2, BAT *s)
1045{
1046 BAT *bn;
1047 BUN nils = 0;
1048 BUN cnt, ncand;
1049 BUN i;
1050 struct canditer ci;
1051 oid x;
1052 const void *restrict nil;
1053 const void *p1, *p2;
1054 BATiter b1i, b2i;
1055 int (*cmp)(const void *, const void *);
1056
1057 BATcheck(b1, __func__, NULL);
1058 BATcheck(b2, __func__, NULL);
1059
1060 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
1061 return NULL;
1062 if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
1063 GDKerror("%s: inputs have incompatible types\n", __func__);
1064 return NULL;
1065 }
1066
1067 cnt = BATcount(b1);
1068 nil = ATOMnilptr(b1->ttype);
1069 ncand = canditer_init(&ci, b1, s);
1070 if (ncand == 0)
1071 return BATconstantV(b1->hseqbase, b1->ttype,
1072 nil, cnt, TRANSIENT);
1073
1074 bn = COLnew(b1->hseqbase, ATOMtype(b1->ttype), cnt, TRANSIENT);
1075 if (bn == NULL)
1076 return NULL;
1077 cmp = ATOMcompare(b1->ttype);
1078 b1i = bat_iterator(b1);
1079 b2i = bat_iterator(b2);
1080
1081 x = canditer_next(&ci) - b1->hseqbase;
1082 i = 0;
1083 do {
1084 while (i < x) {
1085 bunfastapp(bn, nil);
1086 i++;
1087 nils++;
1088 }
1089 p1 = BUNtail(b1i, i);
1090 p2 = BUNtail(b2i, i);
1091 if (cmp(p1, nil) == 0 || cmp(p2, nil) == 0) {
1092 nils++;
1093 p1 = nil;
1094 } else if (cmp(p1, p2) > 0) {
1095 p1 = p2;
1096 }
1097 bunfastapp(bn, p1);
1098 i++;
1099 x = canditer_next(&ci);
1100 if (is_oid_nil(x))
1101 break;
1102 x -= b1->hseqbase;
1103 } while (i < cnt);
1104 while (i < cnt) {
1105 bunfastapp(bn, nil);
1106 i++;
1107 nils++;
1108 }
1109
1110 bn->theap.dirty = true;
1111 bn->tnil = nils > 0;
1112 bn->tnonil = nils == 0;
1113 if (cnt <= 1) {
1114 bn->tsorted = true;
1115 bn->trevsorted = true;
1116 bn->tkey = true;
1117 bn->tseqbase = ATOMtype(b1->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1118 } else {
1119 bn->tsorted = false;
1120 bn->trevsorted = false;
1121 bn->tkey = false;
1122 bn->tseqbase = oid_nil;
1123 }
1124 return bn;
1125 bunins_failed:
1126 BBPreclaim(bn);
1127 return NULL;
1128}
1129
1130BAT *
1131BATcalcmin_no_nil(BAT *b1, BAT *b2, BAT *s)
1132{
1133 BAT *bn;
1134 BUN nils = 0;
1135 BUN cnt, ncand;
1136 BUN i;
1137 struct canditer ci;
1138 oid x;
1139 const void *restrict nil;
1140 const void *p1, *p2;
1141 BATiter b1i, b2i;
1142 int (*cmp)(const void *, const void *);
1143
1144 BATcheck(b1, __func__, NULL);
1145 BATcheck(b2, __func__, NULL);
1146
1147 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
1148 return NULL;
1149 if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
1150 GDKerror("%s: inputs have incompatible types\n", __func__);
1151 return NULL;
1152 }
1153
1154 cnt = BATcount(b1);
1155 nil = ATOMnilptr(b1->ttype);
1156 ncand = canditer_init(&ci, b1, s);
1157 if (ncand == 0)
1158 return BATconstantV(b1->hseqbase, b1->ttype,
1159 nil, cnt, TRANSIENT);
1160
1161 bn = COLnew(b1->hseqbase, ATOMtype(b1->ttype), cnt, TRANSIENT);
1162 if (bn == NULL)
1163 return NULL;
1164 cmp = ATOMcompare(b1->ttype);
1165 b1i = bat_iterator(b1);
1166 b2i = bat_iterator(b2);
1167
1168 x = canditer_next(&ci) - b1->hseqbase;
1169 i = 0;
1170 do {
1171 while (i < x) {
1172 bunfastapp(bn, nil);
1173 i++;
1174 nils++;
1175 }
1176 p1 = BUNtail(b1i, i);
1177 p2 = BUNtail(b2i, i);
1178 if (cmp(p1, nil) == 0) {
1179 if (cmp(p2, nil) == 0) {
1180 /* both values are nil */
1181 nils++;
1182 } else {
1183 p1 = p2;
1184 }
1185 } else if (cmp(p2, nil) != 0 && cmp(p1, p2) > 0) {
1186 p1 = p2;
1187 }
1188 bunfastapp(bn, p1);
1189 i++;
1190 x = canditer_next(&ci);
1191 if (is_oid_nil(x))
1192 break;
1193 x -= b1->hseqbase;
1194 } while (i < cnt);
1195 while (i < cnt) {
1196 bunfastapp(bn, nil);
1197 i++;
1198 nils++;
1199 }
1200
1201 bn->theap.dirty = true;
1202 bn->tnil = nils > 0;
1203 bn->tnonil = nils == 0;
1204 if (cnt <= 1) {
1205 bn->tsorted = true;
1206 bn->trevsorted = true;
1207 bn->tkey = true;
1208 bn->tseqbase = ATOMtype(b1->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1209 } else {
1210 bn->tsorted = false;
1211 bn->trevsorted = false;
1212 bn->tkey = false;
1213 bn->tseqbase = oid_nil;
1214 }
1215 return bn;
1216 bunins_failed:
1217 BBPreclaim(bn);
1218 return NULL;
1219}
1220
1221BAT *
1222BATcalcmincst(BAT *b, const ValRecord *v, BAT *s)
1223{
1224 BAT *bn;
1225 BUN nils = 0;
1226 BUN cnt, ncand;
1227 BUN i;
1228 struct canditer ci;
1229 oid x;
1230 const void *restrict nil;
1231 const void *p1, *p2;
1232 BATiter bi;
1233 int (*cmp)(const void *, const void *);
1234
1235 BATcheck(b, __func__, NULL);
1236 if (ATOMtype(b->ttype) != v->vtype) {
1237 GDKerror("%s: inputs have incompatible types\n", __func__);
1238 return NULL;
1239 }
1240
1241 cnt = BATcount(b);
1242 nil = ATOMnilptr(b->ttype);
1243 ncand = canditer_init(&ci, b, s);
1244
1245 nil = ATOMnilptr(b->ttype);
1246 cmp = ATOMcompare(b->ttype);
1247 p2 = VALptr(v);
1248 if (ncand == 0 ||
1249 cmp(p2, nil) == 0 ||
1250 (b->ttype == TYPE_void && is_oid_nil(b->tseqbase)))
1251 return BATconstantV(b->hseqbase, b->ttype, nil, cnt, TRANSIENT);
1252
1253 bn = COLnew(b->hseqbase, ATOMtype(b->ttype), cnt, TRANSIENT);
1254 if (bn == NULL)
1255 return NULL;
1256 bi = bat_iterator(b);
1257
1258 x = canditer_next(&ci) - b->hseqbase;
1259 i = 0;
1260 do {
1261 while (i < x) {
1262 bunfastapp(bn, nil);
1263 i++;
1264 nils++;
1265 }
1266 p1 = BUNtail(bi, i);
1267 if (cmp(p1, nil) == 0) {
1268 nils++;
1269 p1 = nil;
1270 } else if (cmp(p1, p2) > 0) {
1271 p1 = p2;
1272 }
1273 bunfastapp(bn, p1);
1274 i++;
1275 x = canditer_next(&ci);
1276 if (is_oid_nil(x))
1277 break;
1278 x -= b->hseqbase;
1279 } while (i < cnt);
1280 while (i < cnt) {
1281 bunfastapp(bn, nil);
1282 i++;
1283 nils++;
1284 }
1285
1286 bn->theap.dirty = true;
1287 bn->tnil = nils > 0;
1288 bn->tnonil = nils == 0;
1289 if (cnt <= 1) {
1290 bn->tsorted = true;
1291 bn->trevsorted = true;
1292 bn->tkey = true;
1293 bn->tseqbase = ATOMtype(bn->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1294 } else {
1295 bn->tsorted = false;
1296 bn->trevsorted = false;
1297 bn->tkey = false;
1298 bn->tseqbase = oid_nil;
1299 }
1300 return bn;
1301 bunins_failed:
1302 BBPreclaim(bn);
1303 return NULL;
1304}
1305
1306BAT *
1307BATcalccstmin(const ValRecord *v, BAT *b, BAT *s)
1308{
1309 return BATcalcmincst(b, v, s);
1310}
1311
1312BAT *
1313BATcalcmincst_no_nil(BAT *b, const ValRecord *v, BAT *s)
1314{
1315 BAT *bn;
1316 BUN nils = 0;
1317 BUN cnt, ncand;
1318 BUN i;
1319 struct canditer ci;
1320 oid x;
1321 const void *restrict nil;
1322 const void *p1, *p2;
1323 BATiter bi;
1324 int (*cmp)(const void *, const void *);
1325
1326 BATcheck(b, __func__, NULL);
1327 if (ATOMtype(b->ttype) != v->vtype) {
1328 GDKerror("%s: inputs have incompatible types\n", __func__);
1329 return NULL;
1330 }
1331
1332 cnt = BATcount(b);
1333 nil = ATOMnilptr(b->ttype);
1334 ncand = canditer_init(&ci, b, s);
1335 if (ncand == 0)
1336 return BATconstantV(b->hseqbase, b->ttype,
1337 nil, cnt, TRANSIENT);
1338
1339 cmp = ATOMcompare(b->ttype);
1340 p2 = VALptr(v);
1341 if (b->ttype == TYPE_void &&
1342 is_oid_nil(b->tseqbase) &&
1343 is_oid_nil(* (const oid *) p2))
1344 return BATconstant(b->hseqbase, TYPE_void,
1345 &oid_nil, cnt, TRANSIENT);
1346
1347 bn = COLnew(b->hseqbase, ATOMtype(b->ttype), cnt, TRANSIENT);
1348 if (bn == NULL)
1349 return NULL;
1350 bi = bat_iterator(b);
1351 if (cmp(p2, nil) == 0)
1352 p2 = NULL;
1353
1354 x = canditer_next(&ci) - b->hseqbase;
1355 i = 0;
1356 do {
1357 while (i < x) {
1358 bunfastapp(bn, nil);
1359 i++;
1360 nils++;
1361 }
1362 p1 = BUNtail(bi, i);
1363 if (p2) {
1364 if (cmp(p1, nil) == 0) {
1365 p1 = p2;
1366 } else if (cmp(p1, p2) > 0) {
1367 p1 = p2;
1368 }
1369 }
1370 bunfastapp(bn, p1);
1371 i++;
1372 x = canditer_next(&ci);
1373 if (is_oid_nil(x))
1374 break;
1375 x -= b->hseqbase;
1376 } while (i < cnt);
1377 while (i < cnt) {
1378 bunfastapp(bn, nil);
1379 i++;
1380 nils++;
1381 }
1382 bn->theap.dirty = true;
1383 bn->tnil = nils > 0;
1384 bn->tnonil = nils == 0;
1385 if (cnt <= 1) {
1386 bn->tsorted = true;
1387 bn->trevsorted = true;
1388 bn->tkey = true;
1389 bn->tseqbase = ATOMtype(bn->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1390 } else {
1391 bn->tsorted = false;
1392 bn->trevsorted = false;
1393 bn->tkey = false;
1394 bn->tseqbase = oid_nil;
1395 }
1396 return bn;
1397 bunins_failed:
1398 BBPreclaim(bn);
1399 return NULL;
1400}
1401
1402BAT *
1403BATcalccstmin_no_nil(const ValRecord *v, BAT *b, BAT *s)
1404{
1405 return BATcalcmincst_no_nil(b, v, s);
1406}
1407
1408BAT *
1409BATcalcmax(BAT *b1, BAT *b2, BAT *s)
1410{
1411 BAT *bn;
1412 BUN nils = 0;
1413 BUN cnt, ncand;
1414 BUN i;
1415 struct canditer ci;
1416 oid x;
1417 const void *restrict nil;
1418 const void *p1, *p2;
1419 BATiter b1i, b2i;
1420 int (*cmp)(const void *, const void *);
1421
1422 BATcheck(b1, __func__, NULL);
1423 BATcheck(b2, __func__, NULL);
1424
1425 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
1426 return NULL;
1427 if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
1428 GDKerror("%s: inputs have incompatible types\n", __func__);
1429 return NULL;
1430 }
1431
1432 cnt = BATcount(b1);
1433 nil = ATOMnilptr(b1->ttype);
1434 ncand = canditer_init(&ci, b1, s);
1435 if (ncand == 0)
1436 return BATconstantV(b1->hseqbase, b1->ttype,
1437 nil, cnt, TRANSIENT);
1438
1439 bn = COLnew(b1->hseqbase, ATOMtype(b1->ttype), cnt, TRANSIENT);
1440 if (bn == NULL)
1441 return NULL;
1442 cmp = ATOMcompare(b1->ttype);
1443 b1i = bat_iterator(b1);
1444 b2i = bat_iterator(b2);
1445
1446 x = canditer_next(&ci) - b1->hseqbase;
1447 i = 0;
1448 do {
1449 while (i < x) {
1450 bunfastapp(bn, nil);
1451 i++;
1452 nils++;
1453 }
1454 p1 = BUNtail(b1i, i);
1455 p2 = BUNtail(b2i, i);
1456 if (cmp(p1, nil) == 0 || cmp(p2, nil) == 0) {
1457 nils++;
1458 p1 = nil;
1459 } else if (cmp(p1, p2) < 0) {
1460 p1 = p2;
1461 }
1462 bunfastapp(bn, p1);
1463 i++;
1464 x = canditer_next(&ci);
1465 if (is_oid_nil(x))
1466 break;
1467 x -= b1->hseqbase;
1468 } while (i < cnt);
1469 while (i < cnt) {
1470 bunfastapp(bn, nil);
1471 i++;
1472 nils++;
1473 }
1474
1475 bn->theap.dirty = true;
1476 bn->tnil = nils > 0;
1477 bn->tnonil = nils == 0;
1478 if (cnt <= 1) {
1479 bn->tsorted = true;
1480 bn->trevsorted = true;
1481 bn->tkey = true;
1482 bn->tseqbase = ATOMtype(b1->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1483 } else {
1484 bn->tsorted = false;
1485 bn->trevsorted = false;
1486 bn->tkey = false;
1487 bn->tseqbase = oid_nil;
1488 }
1489 return bn;
1490 bunins_failed:
1491 BBPreclaim(bn);
1492 return NULL;
1493}
1494
1495BAT *
1496BATcalcmax_no_nil(BAT *b1, BAT *b2, BAT *s)
1497{
1498 BAT *bn;
1499 BUN nils = 0;
1500 BUN cnt, ncand;
1501 BUN i;
1502 struct canditer ci;
1503 oid x;
1504 const void *restrict nil;
1505 const void *p1, *p2;
1506 BATiter b1i, b2i;
1507 int (*cmp)(const void *, const void *);
1508
1509 BATcheck(b1, __func__, NULL);
1510 BATcheck(b2, __func__, NULL);
1511
1512 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
1513 return NULL;
1514 if (ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
1515 GDKerror("%s: inputs have incompatible types\n", __func__);
1516 return NULL;
1517 }
1518
1519 cnt = BATcount(b1);
1520 nil = ATOMnilptr(b1->ttype);
1521 ncand = canditer_init(&ci, b1, s);
1522 if (ncand == 0)
1523 return BATconstantV(b1->hseqbase, b1->ttype,
1524 nil, cnt, TRANSIENT);
1525
1526 bn = COLnew(b1->hseqbase, ATOMtype(b1->ttype), cnt, TRANSIENT);
1527 if (bn == NULL)
1528 return NULL;
1529 cmp = ATOMcompare(b1->ttype);
1530 b1i = bat_iterator(b1);
1531 b2i = bat_iterator(b2);
1532
1533 x = canditer_next(&ci) - b1->hseqbase;
1534 i = 0;
1535 do {
1536 while (i < x) {
1537 bunfastapp(bn, nil);
1538 i++;
1539 nils++;
1540 }
1541 p1 = BUNtail(b1i, i);
1542 p2 = BUNtail(b2i, i);
1543 if (cmp(p1, nil) == 0) {
1544 if (cmp(p2, nil) == 0) {
1545 /* both values are nil */
1546 nils++;
1547 } else {
1548 p1 = p2;
1549 }
1550 } else if (cmp(p2, nil) != 0 && cmp(p1, p2) < 0) {
1551 p1 = p2;
1552 }
1553 bunfastapp(bn, p1);
1554 i++;
1555 x = canditer_next(&ci);
1556 if (is_oid_nil(x))
1557 break;
1558 x -= b1->hseqbase;
1559 } while (i < cnt);
1560 while (i < cnt) {
1561 bunfastapp(bn, nil);
1562 i++;
1563 nils++;
1564 }
1565
1566 bn->theap.dirty = true;
1567 bn->tnil = nils > 0;
1568 bn->tnonil = nils == 0;
1569 if (cnt <= 1) {
1570 bn->tsorted = true;
1571 bn->trevsorted = true;
1572 bn->tkey = true;
1573 bn->tseqbase = ATOMtype(b1->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1574 } else {
1575 bn->tsorted = false;
1576 bn->trevsorted = false;
1577 bn->tkey = false;
1578 bn->tseqbase = oid_nil;
1579 }
1580 return bn;
1581 bunins_failed:
1582 BBPreclaim(bn);
1583 return NULL;
1584}
1585
1586BAT *
1587BATcalcmaxcst(BAT *b, const ValRecord *v, BAT *s)
1588{
1589 BAT *bn;
1590 BUN nils = 0;
1591 BUN cnt, ncand;
1592 BUN i;
1593 struct canditer ci;
1594 oid x;
1595 const void *restrict nil;
1596 const void *p1, *p2;
1597 BATiter bi;
1598 int (*cmp)(const void *, const void *);
1599
1600 BATcheck(b, __func__, NULL);
1601 if (ATOMtype(b->ttype) != v->vtype) {
1602 GDKerror("%s: inputs have incompatible types\n", __func__);
1603 return NULL;
1604 }
1605
1606 cnt = BATcount(b);
1607 nil = ATOMnilptr(b->ttype);
1608 ncand = canditer_init(&ci, b, s);
1609
1610 nil = ATOMnilptr(b->ttype);
1611 cmp = ATOMcompare(b->ttype);
1612 p2 = VALptr(v);
1613 if (ncand == 0 ||
1614 cmp(p2, nil) == 0 ||
1615 (b->ttype == TYPE_void && is_oid_nil(b->tseqbase)))
1616 return BATconstantV(b->hseqbase, b->ttype, nil, cnt, TRANSIENT);
1617
1618 bn = COLnew(b->hseqbase, ATOMtype(b->ttype), cnt, TRANSIENT);
1619 if (bn == NULL)
1620 return NULL;
1621 bi = bat_iterator(b);
1622
1623 x = canditer_next(&ci) - b->hseqbase;
1624 i = 0;
1625 do {
1626 while (i < x) {
1627 bunfastapp(bn, nil);
1628 i++;
1629 nils++;
1630 }
1631 p1 = BUNtail(bi, i);
1632 if (cmp(p1, nil) == 0) {
1633 nils++;
1634 p1 = nil;
1635 } else if (cmp(p1, p2) < 0) {
1636 p1 = p2;
1637 }
1638 bunfastapp(bn, p1);
1639 i++;
1640 x = canditer_next(&ci);
1641 if (is_oid_nil(x))
1642 break;
1643 x -= b->hseqbase;
1644 } while (i < cnt);
1645 while (i < cnt) {
1646 bunfastapp(bn, nil);
1647 i++;
1648 nils++;
1649 }
1650
1651 bn->theap.dirty = true;
1652 bn->tnil = nils > 0;
1653 bn->tnonil = nils == 0;
1654 if (cnt <= 1) {
1655 bn->tsorted = true;
1656 bn->trevsorted = true;
1657 bn->tkey = true;
1658 bn->tseqbase = ATOMtype(bn->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1659 } else {
1660 bn->tsorted = false;
1661 bn->trevsorted = false;
1662 bn->tkey = false;
1663 bn->tseqbase = oid_nil;
1664 }
1665 return bn;
1666 bunins_failed:
1667 BBPreclaim(bn);
1668 return NULL;
1669}
1670
1671BAT *
1672BATcalccstmax(const ValRecord *v, BAT *b, BAT *s)
1673{
1674 return BATcalcmaxcst(b, v, s);
1675}
1676
1677BAT *
1678BATcalcmaxcst_no_nil(BAT *b, const ValRecord *v, BAT *s)
1679{
1680 BAT *bn;
1681 BUN nils = 0;
1682 BUN cnt, ncand;
1683 BUN i;
1684 struct canditer ci;
1685 oid x;
1686 const void *restrict nil;
1687 const void *p1, *p2;
1688 BATiter bi;
1689 int (*cmp)(const void *, const void *);
1690
1691 BATcheck(b, __func__, NULL);
1692 if (ATOMtype(b->ttype) != v->vtype) {
1693 GDKerror("%s: inputs have incompatible types\n", __func__);
1694 return NULL;
1695 }
1696
1697 cnt = BATcount(b);
1698 nil = ATOMnilptr(b->ttype);
1699 ncand = canditer_init(&ci, b, s);
1700 if (ncand == 0)
1701 return BATconstantV(b->hseqbase, b->ttype,
1702 nil, cnt, TRANSIENT);
1703
1704 cmp = ATOMcompare(b->ttype);
1705 p2 = VALptr(v);
1706 if (b->ttype == TYPE_void &&
1707 is_oid_nil(b->tseqbase) &&
1708 is_oid_nil(* (const oid *) p2))
1709 return BATconstant(b->hseqbase, TYPE_void,
1710 &oid_nil, cnt, TRANSIENT);
1711
1712 bn = COLnew(b->hseqbase, ATOMtype(b->ttype), cnt, TRANSIENT);
1713 if (bn == NULL)
1714 return NULL;
1715 bi = bat_iterator(b);
1716 if (cmp(p2, nil) == 0)
1717 p2 = NULL;
1718
1719 x = canditer_next(&ci) - b->hseqbase;
1720 i = 0;
1721 do {
1722 while (i < x) {
1723 bunfastapp(bn, nil);
1724 i++;
1725 nils++;
1726 }
1727 p1 = BUNtail(bi, i);
1728 if (p2) {
1729 if (cmp(p1, nil) == 0) {
1730 p1 = p2;
1731 } else if (cmp(p1, p2) < 0) {
1732 p1 = p2;
1733 }
1734 }
1735 bunfastapp(bn, p1);
1736 i++;
1737 x = canditer_next(&ci);
1738 if (is_oid_nil(x))
1739 break;
1740 x -= b->hseqbase;
1741 } while (i < cnt);
1742 while (i < cnt) {
1743 bunfastapp(bn, nil);
1744 i++;
1745 nils++;
1746 }
1747 bn->theap.dirty = true;
1748 bn->tnil = nils > 0;
1749 bn->tnonil = nils == 0;
1750 if (cnt <= 1) {
1751 bn->tsorted = true;
1752 bn->trevsorted = true;
1753 bn->tkey = true;
1754 bn->tseqbase = ATOMtype(bn->ttype) == TYPE_oid ? cnt == 1 ? *(oid*)Tloc(bn,0) : 0 : oid_nil;
1755 } else {
1756 bn->tsorted = false;
1757 bn->trevsorted = false;
1758 bn->tkey = false;
1759 bn->tseqbase = oid_nil;
1760 }
1761 return bn;
1762 bunins_failed:
1763 BBPreclaim(bn);
1764 return NULL;
1765}
1766
1767BAT *
1768BATcalccstmax_no_nil(const ValRecord *v, BAT *b, BAT *s)
1769{
1770 return BATcalcmaxcst_no_nil(b, v, s);
1771}
1772
1773/* ---------------------------------------------------------------------- */
1774/* addition (any numeric type) */
1775
1776#define ON_OVERFLOW(TYPE1, TYPE2, OP) \
1777 do { \
1778 GDKerror("22003!overflow in calculation " \
1779 FMT##TYPE1 OP FMT##TYPE2 ".\n", \
1780 CST##TYPE1 lft[i], CST##TYPE2 rgt[j]); \
1781 return BUN_NONE; \
1782 } while (0)
1783
1784#define ADD_3TYPE(TYPE1, TYPE2, TYPE3, IF) \
1785static BUN \
1786add_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
1787 const TYPE2 *rgt, int incr2, \
1788 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
1789 struct canditer *restrict ci, \
1790 oid candoff, bool abort_on_error) \
1791{ \
1792 oid x = canditer_next(ci) - candoff; \
1793 BUN i, j, k = 0; \
1794 BUN nils = 0; \
1795 \
1796 do { \
1797 while (k < x) { \
1798 dst[k++] = TYPE3##_nil; \
1799 nils++; \
1800 } \
1801 i = x * incr1; \
1802 j = x * incr2; \
1803 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
1804 dst[k] = TYPE3##_nil; \
1805 nils++; \
1806 } else { \
1807 ADD##IF##_WITH_CHECK(lft[i], rgt[j], \
1808 TYPE3, dst[k], \
1809 max, \
1810 ON_OVERFLOW(TYPE1, TYPE2, "+")); \
1811 } \
1812 k++; \
1813 x = canditer_next(ci); \
1814 if (is_oid_nil(x)) \
1815 break; \
1816 x -= candoff; \
1817 } while (k < cnt); \
1818 while (k < cnt) { \
1819 dst[k++] = TYPE3##_nil; \
1820 nils++; \
1821 } \
1822 return nils; \
1823}
1824
1825#define ADD_3TYPE_enlarge(TYPE1, TYPE2, TYPE3, IF) \
1826static BUN \
1827add_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
1828 const TYPE2 *rgt, int incr2, \
1829 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
1830 struct canditer *restrict ci, \
1831 oid candoff, bool abort_on_error) \
1832{ \
1833 oid x = canditer_next(ci) - candoff; \
1834 BUN i, j, k = 0; \
1835 BUN nils = 0; \
1836 const bool couldoverflow = (max < (TYPE3) GDK_##TYPE1##_max + (TYPE3) GDK_##TYPE2##_max); \
1837 \
1838 do { \
1839 while (k < x) { \
1840 dst[k++] = TYPE3##_nil; \
1841 nils++; \
1842 } \
1843 i = x * incr1; \
1844 j = x * incr2; \
1845 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
1846 dst[k] = TYPE3##_nil; \
1847 nils++; \
1848 } else if (couldoverflow) { \
1849 ADD##IF##_WITH_CHECK(lft[i], rgt[j], \
1850 TYPE3, dst[k], \
1851 max, \
1852 ON_OVERFLOW(TYPE1, TYPE2, "+")); \
1853 } else { \
1854 dst[k] = (TYPE3) lft[i] + rgt[j]; \
1855 } \
1856 k++; \
1857 x = canditer_next(ci); \
1858 if (is_oid_nil(x)) \
1859 break; \
1860 x -= candoff; \
1861 } while (k < cnt); \
1862 while (k < cnt) { \
1863 dst[k++] = TYPE3##_nil; \
1864 nils++; \
1865 } \
1866 return nils; \
1867}
1868
1869ADD_3TYPE(bte, bte, bte, I)
1870ADD_3TYPE_enlarge(bte, bte, sht, I)
1871#ifdef FULL_IMPLEMENTATION
1872ADD_3TYPE_enlarge(bte, bte, int, I)
1873ADD_3TYPE_enlarge(bte, bte, lng, I)
1874#ifdef HAVE_HGE
1875ADD_3TYPE_enlarge(bte, bte, hge, I)
1876#endif
1877ADD_3TYPE_enlarge(bte, bte, flt, F)
1878ADD_3TYPE_enlarge(bte, bte, dbl, F)
1879#endif
1880ADD_3TYPE(bte, sht, sht, I)
1881ADD_3TYPE_enlarge(bte, sht, int, I)
1882#ifdef FULL_IMPLEMENTATION
1883ADD_3TYPE_enlarge(bte, sht, lng, I)
1884#ifdef HAVE_HGE
1885ADD_3TYPE_enlarge(bte, sht, hge, I)
1886#endif
1887ADD_3TYPE_enlarge(bte, sht, flt, F)
1888ADD_3TYPE_enlarge(bte, sht, dbl, F)
1889#endif
1890ADD_3TYPE(bte, int, int, I)
1891ADD_3TYPE_enlarge(bte, int, lng, I)
1892#ifdef FULL_IMPLEMENTATION
1893#ifdef HAVE_HGE
1894ADD_3TYPE_enlarge(bte, int, hge, I)
1895#endif
1896ADD_3TYPE_enlarge(bte, int, flt, F)
1897ADD_3TYPE_enlarge(bte, int, dbl, F)
1898#endif
1899ADD_3TYPE(bte, lng, lng, I)
1900#ifdef HAVE_HGE
1901ADD_3TYPE_enlarge(bte, lng, hge, I)
1902#endif
1903#ifdef FULL_IMPLEMENTATION
1904ADD_3TYPE_enlarge(bte, lng, flt, F)
1905ADD_3TYPE_enlarge(bte, lng, dbl, F)
1906#endif
1907#ifdef HAVE_HGE
1908ADD_3TYPE(bte, hge, hge, I)
1909#ifdef FULL_IMPLEMENTATION
1910ADD_3TYPE_enlarge(bte, hge, flt, F)
1911ADD_3TYPE_enlarge(bte, hge, dbl, F)
1912#endif
1913#endif
1914ADD_3TYPE(bte, flt, flt, F)
1915ADD_3TYPE_enlarge(bte, flt, dbl, F)
1916ADD_3TYPE(bte, dbl, dbl, F)
1917ADD_3TYPE(sht, bte, sht, I)
1918ADD_3TYPE_enlarge(sht, bte, int, I)
1919#ifdef FULL_IMPLEMENTATION
1920ADD_3TYPE_enlarge(sht, bte, lng, I)
1921#ifdef HAVE_HGE
1922ADD_3TYPE_enlarge(sht, bte, hge, I)
1923#endif
1924ADD_3TYPE_enlarge(sht, bte, flt, F)
1925ADD_3TYPE_enlarge(sht, bte, dbl, F)
1926#endif
1927ADD_3TYPE(sht, sht, sht, I)
1928ADD_3TYPE_enlarge(sht, sht, int, I)
1929#ifdef FULL_IMPLEMENTATION
1930ADD_3TYPE_enlarge(sht, sht, lng, I)
1931#ifdef HAVE_HGE
1932ADD_3TYPE_enlarge(sht, sht, hge, I)
1933#endif
1934ADD_3TYPE_enlarge(sht, sht, flt, F)
1935ADD_3TYPE_enlarge(sht, sht, dbl, F)
1936#endif
1937ADD_3TYPE(sht, int, int, I)
1938ADD_3TYPE_enlarge(sht, int, lng, I)
1939#ifdef FULL_IMPLEMENTATION
1940#ifdef HAVE_HGE
1941ADD_3TYPE_enlarge(sht, int, hge, I)
1942#endif
1943ADD_3TYPE_enlarge(sht, int, flt, F)
1944ADD_3TYPE_enlarge(sht, int, dbl, F)
1945#endif
1946ADD_3TYPE(sht, lng, lng, I)
1947#ifdef HAVE_HGE
1948ADD_3TYPE_enlarge(sht, lng, hge, I)
1949#endif
1950#ifdef FULL_IMPLEMENTATION
1951ADD_3TYPE_enlarge(sht, lng, flt, F)
1952ADD_3TYPE_enlarge(sht, lng, dbl, F)
1953#endif
1954#ifdef HAVE_HGE
1955ADD_3TYPE(sht, hge, hge, I)
1956#ifdef FULL_IMPLEMENTATION
1957ADD_3TYPE_enlarge(sht, hge, flt, F)
1958ADD_3TYPE_enlarge(sht, hge, dbl, F)
1959#endif
1960#endif
1961ADD_3TYPE(sht, flt, flt, F)
1962ADD_3TYPE_enlarge(sht, flt, dbl, F)
1963ADD_3TYPE(sht, dbl, dbl, F)
1964ADD_3TYPE(int, bte, int, I)
1965ADD_3TYPE_enlarge(int, bte, lng, I)
1966#ifdef FULL_IMPLEMENTATION
1967#ifdef HAVE_HGE
1968ADD_3TYPE_enlarge(int, bte, hge, I)
1969#endif
1970ADD_3TYPE_enlarge(int, bte, flt, F)
1971ADD_3TYPE_enlarge(int, bte, dbl, F)
1972#endif
1973ADD_3TYPE(int, sht, int, I)
1974ADD_3TYPE_enlarge(int, sht, lng, I)
1975#ifdef FULL_IMPLEMENTATION
1976#ifdef HAVE_HGE
1977ADD_3TYPE_enlarge(int, sht, hge, I)
1978#endif
1979ADD_3TYPE_enlarge(int, sht, flt, F)
1980ADD_3TYPE_enlarge(int, sht, dbl, F)
1981#endif
1982ADD_3TYPE(int, int, int, I)
1983ADD_3TYPE_enlarge(int, int, lng, I)
1984#ifdef FULL_IMPLEMENTATION
1985#ifdef HAVE_HGE
1986ADD_3TYPE_enlarge(int, int, hge, I)
1987#endif
1988ADD_3TYPE_enlarge(int, int, flt, F)
1989ADD_3TYPE_enlarge(int, int, dbl, F)
1990#endif
1991ADD_3TYPE(int, lng, lng, I)
1992#ifdef HAVE_HGE
1993ADD_3TYPE_enlarge(int, lng, hge, I)
1994#endif
1995#ifdef FULL_IMPLEMENTATION
1996ADD_3TYPE_enlarge(int, lng, flt, F)
1997ADD_3TYPE_enlarge(int, lng, dbl, F)
1998#endif
1999#ifdef HAVE_HGE
2000ADD_3TYPE(int, hge, hge, I)
2001#ifdef FULL_IMPLEMENTATION
2002ADD_3TYPE_enlarge(int, hge, flt, F)
2003ADD_3TYPE_enlarge(int, hge, dbl, F)
2004#endif
2005#endif
2006ADD_3TYPE(int, flt, flt, F)
2007ADD_3TYPE_enlarge(int, flt, dbl, F)
2008ADD_3TYPE(int, dbl, dbl, F)
2009ADD_3TYPE(lng, bte, lng, I)
2010#ifdef HAVE_HGE
2011ADD_3TYPE_enlarge(lng, bte, hge, I)
2012#endif
2013#ifdef FULL_IMPLEMENTATION
2014ADD_3TYPE_enlarge(lng, bte, flt, F)
2015ADD_3TYPE_enlarge(lng, bte, dbl, F)
2016#endif
2017ADD_3TYPE(lng, sht, lng, I)
2018#ifdef HAVE_HGE
2019ADD_3TYPE_enlarge(lng, sht, hge, I)
2020#endif
2021#ifdef FULL_IMPLEMENTATION
2022ADD_3TYPE_enlarge(lng, sht, flt, F)
2023ADD_3TYPE_enlarge(lng, sht, dbl, F)
2024#endif
2025ADD_3TYPE(lng, int, lng, I)
2026#ifdef HAVE_HGE
2027ADD_3TYPE_enlarge(lng, int, hge, I)
2028#endif
2029#ifdef FULL_IMPLEMENTATION
2030ADD_3TYPE_enlarge(lng, int, flt, F)
2031ADD_3TYPE_enlarge(lng, int, dbl, F)
2032#endif
2033ADD_3TYPE(lng, lng, lng, I)
2034#ifdef HAVE_HGE
2035ADD_3TYPE_enlarge(lng, lng, hge, I)
2036#endif
2037#ifdef FULL_IMPLEMENTATION
2038ADD_3TYPE_enlarge(lng, lng, flt, F)
2039ADD_3TYPE_enlarge(lng, lng, dbl, F)
2040#endif
2041#ifdef HAVE_HGE
2042ADD_3TYPE(lng, hge, hge, I)
2043#ifdef FULL_IMPLEMENTATION
2044ADD_3TYPE_enlarge(lng, hge, flt, F)
2045ADD_3TYPE_enlarge(lng, hge, dbl, F)
2046#endif
2047#endif
2048ADD_3TYPE(lng, flt, flt, F)
2049ADD_3TYPE_enlarge(lng, flt, dbl, F)
2050ADD_3TYPE(lng, dbl, dbl, F)
2051#ifdef HAVE_HGE
2052ADD_3TYPE(hge, bte, hge, I)
2053#ifdef FULL_IMPLEMENTATION
2054ADD_3TYPE_enlarge(hge, bte, flt, F)
2055ADD_3TYPE_enlarge(hge, bte, dbl, F)
2056#endif
2057ADD_3TYPE(hge, sht, hge, I)
2058#ifdef FULL_IMPLEMENTATION
2059ADD_3TYPE_enlarge(hge, sht, flt, F)
2060ADD_3TYPE_enlarge(hge, sht, dbl, F)
2061#endif
2062ADD_3TYPE(hge, int, hge, I)
2063#ifdef FULL_IMPLEMENTATION
2064ADD_3TYPE_enlarge(hge, int, flt, F)
2065ADD_3TYPE_enlarge(hge, int, dbl, F)
2066#endif
2067ADD_3TYPE(hge, lng, hge, I)
2068#ifdef FULL_IMPLEMENTATION
2069ADD_3TYPE_enlarge(hge, lng, flt, F)
2070ADD_3TYPE_enlarge(hge, lng, dbl, F)
2071#endif
2072ADD_3TYPE(hge, hge, hge, I)
2073#ifdef FULL_IMPLEMENTATION
2074ADD_3TYPE_enlarge(hge, hge, flt, F)
2075ADD_3TYPE_enlarge(hge, hge, dbl, F)
2076#endif
2077ADD_3TYPE(hge, flt, flt, F)
2078ADD_3TYPE_enlarge(hge, flt, dbl, F)
2079ADD_3TYPE(hge, dbl, dbl, F)
2080#endif
2081ADD_3TYPE(flt, bte, flt, F)
2082ADD_3TYPE_enlarge(flt, bte, dbl, F)
2083ADD_3TYPE(flt, sht, flt, F)
2084ADD_3TYPE_enlarge(flt, sht, dbl, F)
2085ADD_3TYPE(flt, int, flt, F)
2086ADD_3TYPE_enlarge(flt, int, dbl, F)
2087ADD_3TYPE(flt, lng, flt, F)
2088ADD_3TYPE_enlarge(flt, lng, dbl, F)
2089#ifdef HAVE_HGE
2090ADD_3TYPE(flt, hge, flt, F)
2091ADD_3TYPE_enlarge(flt, hge, dbl, F)
2092#endif
2093ADD_3TYPE(flt, flt, flt, F)
2094ADD_3TYPE_enlarge(flt, flt, dbl, F)
2095ADD_3TYPE(flt, dbl, dbl, F)
2096ADD_3TYPE(dbl, bte, dbl, F)
2097ADD_3TYPE(dbl, sht, dbl, F)
2098ADD_3TYPE(dbl, int, dbl, F)
2099ADD_3TYPE(dbl, lng, dbl, F)
2100#ifdef HAVE_HGE
2101ADD_3TYPE(dbl, hge, dbl, F)
2102#endif
2103ADD_3TYPE(dbl, flt, dbl, F)
2104ADD_3TYPE(dbl, dbl, dbl, F)
2105
2106static BUN
2107add_typeswitchloop(const void *lft, int tp1, int incr1,
2108 const void *rgt, int tp2, int incr2,
2109 void *restrict dst, int tp, BUN cnt,
2110 struct canditer *restrict ci, oid candoff,
2111 bool abort_on_error, const char *func)
2112{
2113 BUN nils;
2114
2115 tp1 = ATOMbasetype(tp1);
2116 tp2 = ATOMbasetype(tp2);
2117 tp = ATOMbasetype(tp);
2118 switch (tp1) {
2119 case TYPE_bte:
2120 switch (tp2) {
2121 case TYPE_bte:
2122 switch (tp) {
2123 case TYPE_bte:
2124 nils = add_bte_bte_bte(lft, incr1, rgt, incr2,
2125 dst, GDK_bte_max, cnt,
2126 ci, candoff,
2127 abort_on_error);
2128 break;
2129 case TYPE_sht:
2130 nils = add_bte_bte_sht(lft, incr1, rgt, incr2,
2131 dst, GDK_sht_max, cnt,
2132 ci, candoff,
2133 abort_on_error);
2134 break;
2135#ifdef FULL_IMPLEMENTATION
2136 case TYPE_int:
2137 nils = add_bte_bte_int(lft, incr1, rgt, incr2,
2138 dst, GDK_int_max, cnt,
2139 ci, candoff,
2140 abort_on_error);
2141 break;
2142 case TYPE_lng:
2143 nils = add_bte_bte_lng(lft, incr1, rgt, incr2,
2144 dst, GDK_lng_max, cnt,
2145 ci, candoff,
2146 abort_on_error);
2147 break;
2148#ifdef HAVE_HGE
2149 case TYPE_hge:
2150 nils = add_bte_bte_hge(lft, incr1, rgt, incr2,
2151 dst, GDK_hge_max, cnt,
2152 ci, candoff,
2153 abort_on_error);
2154 break;
2155#endif
2156 case TYPE_flt:
2157 nils = add_bte_bte_flt(lft, incr1, rgt, incr2,
2158 dst, GDK_flt_max, cnt,
2159 ci, candoff,
2160 abort_on_error);
2161 break;
2162 case TYPE_dbl:
2163 nils = add_bte_bte_dbl(lft, incr1, rgt, incr2,
2164 dst, GDK_dbl_max, cnt,
2165 ci, candoff,
2166 abort_on_error);
2167 break;
2168#endif
2169 default:
2170 goto unsupported;
2171 }
2172 break;
2173 case TYPE_sht:
2174 switch (tp) {
2175 case TYPE_sht:
2176 nils = add_bte_sht_sht(lft, incr1, rgt, incr2,
2177 dst, GDK_sht_max, cnt,
2178 ci, candoff,
2179 abort_on_error);
2180 break;
2181 case TYPE_int:
2182 nils = add_bte_sht_int(lft, incr1, rgt, incr2,
2183 dst, GDK_int_max, cnt,
2184 ci, candoff,
2185 abort_on_error);
2186 break;
2187#ifdef FULL_IMPLEMENTATION
2188 case TYPE_lng:
2189 nils = add_bte_sht_lng(lft, incr1, rgt, incr2,
2190 dst, GDK_lng_max, cnt,
2191 ci, candoff,
2192 abort_on_error);
2193 break;
2194#ifdef HAVE_HGE
2195 case TYPE_hge:
2196 nils = add_bte_sht_hge(lft, incr1, rgt, incr2,
2197 dst, GDK_hge_max, cnt,
2198 ci, candoff,
2199 abort_on_error);
2200 break;
2201#endif
2202 case TYPE_flt:
2203 nils = add_bte_sht_flt(lft, incr1, rgt, incr2,
2204 dst, GDK_flt_max, cnt,
2205 ci, candoff,
2206 abort_on_error);
2207 break;
2208 case TYPE_dbl:
2209 nils = add_bte_sht_dbl(lft, incr1, rgt, incr2,
2210 dst, GDK_dbl_max, cnt,
2211 ci, candoff,
2212 abort_on_error);
2213 break;
2214#endif
2215 default:
2216 goto unsupported;
2217 }
2218 break;
2219 case TYPE_int:
2220 switch (tp) {
2221 case TYPE_int:
2222 nils = add_bte_int_int(lft, incr1, rgt, incr2,
2223 dst, GDK_int_max, cnt,
2224 ci, candoff,
2225 abort_on_error);
2226 break;
2227 case TYPE_lng:
2228 nils = add_bte_int_lng(lft, incr1, rgt, incr2,
2229 dst, GDK_lng_max, cnt,
2230 ci, candoff,
2231 abort_on_error);
2232 break;
2233#ifdef FULL_IMPLEMENTATION
2234#ifdef HAVE_HGE
2235 case TYPE_hge:
2236 nils = add_bte_int_hge(lft, incr1, rgt, incr2,
2237 dst, GDK_hge_max, cnt,
2238 ci, candoff,
2239 abort_on_error);
2240 break;
2241#endif
2242 case TYPE_flt:
2243 nils = add_bte_int_flt(lft, incr1, rgt, incr2,
2244 dst, GDK_flt_max, cnt,
2245 ci, candoff,
2246 abort_on_error);
2247 break;
2248 case TYPE_dbl:
2249 nils = add_bte_int_dbl(lft, incr1, rgt, incr2,
2250 dst, GDK_dbl_max, cnt,
2251 ci, candoff,
2252 abort_on_error);
2253 break;
2254#endif
2255 default:
2256 goto unsupported;
2257 }
2258 break;
2259 case TYPE_lng:
2260 switch (tp) {
2261 case TYPE_lng:
2262 nils = add_bte_lng_lng(lft, incr1, rgt, incr2,
2263 dst, GDK_lng_max, cnt,
2264 ci, candoff,
2265 abort_on_error);
2266 break;
2267#ifdef HAVE_HGE
2268 case TYPE_hge:
2269 nils = add_bte_lng_hge(lft, incr1, rgt, incr2,
2270 dst, GDK_hge_max, cnt,
2271 ci, candoff,
2272 abort_on_error);
2273 break;
2274#endif
2275#ifdef FULL_IMPLEMENTATION
2276 case TYPE_flt:
2277 nils = add_bte_lng_flt(lft, incr1, rgt, incr2,
2278 dst, GDK_flt_max, cnt,
2279 ci, candoff,
2280 abort_on_error);
2281 break;
2282 case TYPE_dbl:
2283 nils = add_bte_lng_dbl(lft, incr1, rgt, incr2,
2284 dst, GDK_dbl_max, cnt,
2285 ci, candoff,
2286 abort_on_error);
2287 break;
2288#endif
2289 default:
2290 goto unsupported;
2291 }
2292 break;
2293#ifdef HAVE_HGE
2294 case TYPE_hge:
2295 switch (tp) {
2296 case TYPE_hge:
2297 nils = add_bte_hge_hge(lft, incr1, rgt, incr2,
2298 dst, GDK_hge_max, cnt,
2299 ci, candoff,
2300 abort_on_error);
2301 break;
2302#ifdef FULL_IMPLEMENTATION
2303 case TYPE_flt:
2304 nils = add_bte_hge_flt(lft, incr1, rgt, incr2,
2305 dst, GDK_flt_max, cnt,
2306 ci, candoff,
2307 abort_on_error);
2308 break;
2309 case TYPE_dbl:
2310 nils = add_bte_hge_dbl(lft, incr1, rgt, incr2,
2311 dst, GDK_dbl_max, cnt,
2312 ci, candoff,
2313 abort_on_error);
2314 break;
2315#endif
2316 default:
2317 goto unsupported;
2318 }
2319 break;
2320#endif
2321 case TYPE_flt:
2322 switch (tp) {
2323 case TYPE_flt:
2324 nils = add_bte_flt_flt(lft, incr1, rgt, incr2,
2325 dst, GDK_flt_max, cnt,
2326 ci, candoff,
2327 abort_on_error);
2328 break;
2329 case TYPE_dbl:
2330 nils = add_bte_flt_dbl(lft, incr1, rgt, incr2,
2331 dst, GDK_dbl_max, cnt,
2332 ci, candoff,
2333 abort_on_error);
2334 break;
2335 default:
2336 goto unsupported;
2337 }
2338 break;
2339 case TYPE_dbl:
2340 switch (tp) {
2341 case TYPE_dbl:
2342 nils = add_bte_dbl_dbl(lft, incr1, rgt, incr2,
2343 dst, GDK_dbl_max, cnt,
2344 ci, candoff,
2345 abort_on_error);
2346 break;
2347 default:
2348 goto unsupported;
2349 }
2350 break;
2351 default:
2352 goto unsupported;
2353 }
2354 break;
2355 case TYPE_sht:
2356 switch (tp2) {
2357 case TYPE_bte:
2358 switch (tp) {
2359 case TYPE_sht:
2360 nils = add_sht_bte_sht(lft, incr1, rgt, incr2,
2361 dst, GDK_sht_max, cnt,
2362 ci, candoff,
2363 abort_on_error);
2364 break;
2365 case TYPE_int:
2366 nils = add_sht_bte_int(lft, incr1, rgt, incr2,
2367 dst, GDK_int_max, cnt,
2368 ci, candoff,
2369 abort_on_error);
2370 break;
2371#ifdef FULL_IMPLEMENTATION
2372 case TYPE_lng:
2373 nils = add_sht_bte_lng(lft, incr1, rgt, incr2,
2374 dst, GDK_lng_max, cnt,
2375 ci, candoff,
2376 abort_on_error);
2377 break;
2378#ifdef HAVE_HGE
2379 case TYPE_hge:
2380 nils = add_sht_bte_hge(lft, incr1, rgt, incr2,
2381 dst, GDK_hge_max, cnt,
2382 ci, candoff,
2383 abort_on_error);
2384 break;
2385#endif
2386 case TYPE_flt:
2387 nils = add_sht_bte_flt(lft, incr1, rgt, incr2,
2388 dst, GDK_flt_max, cnt,
2389 ci, candoff,
2390 abort_on_error);
2391 break;
2392 case TYPE_dbl:
2393 nils = add_sht_bte_dbl(lft, incr1, rgt, incr2,
2394 dst, GDK_dbl_max, cnt,
2395 ci, candoff,
2396 abort_on_error);
2397 break;
2398#endif
2399 default:
2400 goto unsupported;
2401 }
2402 break;
2403 case TYPE_sht:
2404 switch (tp) {
2405 case TYPE_sht:
2406 nils = add_sht_sht_sht(lft, incr1, rgt, incr2,
2407 dst, GDK_sht_max, cnt,
2408 ci, candoff,
2409 abort_on_error);
2410 break;
2411 case TYPE_int:
2412 nils = add_sht_sht_int(lft, incr1, rgt, incr2,
2413 dst, GDK_int_max, cnt,
2414 ci, candoff,
2415 abort_on_error);
2416 break;
2417#ifdef FULL_IMPLEMENTATION
2418 case TYPE_lng:
2419 nils = add_sht_sht_lng(lft, incr1, rgt, incr2,
2420 dst, GDK_lng_max, cnt,
2421 ci, candoff,
2422 abort_on_error);
2423 break;
2424#ifdef HAVE_HGE
2425 case TYPE_hge:
2426 nils = add_sht_sht_hge(lft, incr1, rgt, incr2,
2427 dst, GDK_hge_max, cnt,
2428 ci, candoff,
2429 abort_on_error);
2430 break;
2431#endif
2432 case TYPE_flt:
2433 nils = add_sht_sht_flt(lft, incr1, rgt, incr2,
2434 dst, GDK_flt_max, cnt,
2435 ci, candoff,
2436 abort_on_error);
2437 break;
2438 case TYPE_dbl:
2439 nils = add_sht_sht_dbl(lft, incr1, rgt, incr2,
2440 dst, GDK_dbl_max, cnt,
2441 ci, candoff,
2442 abort_on_error);
2443 break;
2444#endif
2445 default:
2446 goto unsupported;
2447 }
2448 break;
2449 case TYPE_int:
2450 switch (tp) {
2451 case TYPE_int:
2452 nils = add_sht_int_int(lft, incr1, rgt, incr2,
2453 dst, GDK_int_max, cnt,
2454 ci, candoff,
2455 abort_on_error);
2456 break;
2457 case TYPE_lng:
2458 nils = add_sht_int_lng(lft, incr1, rgt, incr2,
2459 dst, GDK_lng_max, cnt,
2460 ci, candoff,
2461 abort_on_error);
2462 break;
2463#ifdef FULL_IMPLEMENTATION
2464#ifdef HAVE_HGE
2465 case TYPE_hge:
2466 nils = add_sht_int_hge(lft, incr1, rgt, incr2,
2467 dst, GDK_hge_max, cnt,
2468 ci, candoff,
2469 abort_on_error);
2470 break;
2471#endif
2472 case TYPE_flt:
2473 nils = add_sht_int_flt(lft, incr1, rgt, incr2,
2474 dst, GDK_flt_max, cnt,
2475 ci, candoff,
2476 abort_on_error);
2477 break;
2478 case TYPE_dbl:
2479 nils = add_sht_int_dbl(lft, incr1, rgt, incr2,
2480 dst, GDK_dbl_max, cnt,
2481 ci, candoff,
2482 abort_on_error);
2483 break;
2484#endif
2485 default:
2486 goto unsupported;
2487 }
2488 break;
2489 case TYPE_lng:
2490 switch (tp) {
2491 case TYPE_lng:
2492 nils = add_sht_lng_lng(lft, incr1, rgt, incr2,
2493 dst, GDK_lng_max, cnt,
2494 ci, candoff,
2495 abort_on_error);
2496 break;
2497#ifdef HAVE_HGE
2498 case TYPE_hge:
2499 nils = add_sht_lng_hge(lft, incr1, rgt, incr2,
2500 dst, GDK_hge_max, cnt,
2501 ci, candoff,
2502 abort_on_error);
2503 break;
2504#endif
2505#ifdef FULL_IMPLEMENTATION
2506 case TYPE_flt:
2507 nils = add_sht_lng_flt(lft, incr1, rgt, incr2,
2508 dst, GDK_flt_max, cnt,
2509 ci, candoff,
2510 abort_on_error);
2511 break;
2512 case TYPE_dbl:
2513 nils = add_sht_lng_dbl(lft, incr1, rgt, incr2,
2514 dst, GDK_dbl_max, cnt,
2515 ci, candoff,
2516 abort_on_error);
2517 break;
2518#endif
2519 default:
2520 goto unsupported;
2521 }
2522 break;
2523#ifdef HAVE_HGE
2524 case TYPE_hge:
2525 switch (tp) {
2526 case TYPE_hge:
2527 nils = add_sht_hge_hge(lft, incr1, rgt, incr2,
2528 dst, GDK_hge_max, cnt,
2529 ci, candoff,
2530 abort_on_error);
2531 break;
2532#ifdef FULL_IMPLEMENTATION
2533 case TYPE_flt:
2534 nils = add_sht_hge_flt(lft, incr1, rgt, incr2,
2535 dst, GDK_flt_max, cnt,
2536 ci, candoff,
2537 abort_on_error);
2538 break;
2539 case TYPE_dbl:
2540 nils = add_sht_hge_dbl(lft, incr1, rgt, incr2,
2541 dst, GDK_dbl_max, cnt,
2542 ci, candoff,
2543 abort_on_error);
2544 break;
2545#endif
2546 default:
2547 goto unsupported;
2548 }
2549 break;
2550#endif
2551 case TYPE_flt:
2552 switch (tp) {
2553 case TYPE_flt:
2554 nils = add_sht_flt_flt(lft, incr1, rgt, incr2,
2555 dst, GDK_flt_max, cnt,
2556 ci, candoff,
2557 abort_on_error);
2558 break;
2559 case TYPE_dbl:
2560 nils = add_sht_flt_dbl(lft, incr1, rgt, incr2,
2561 dst, GDK_dbl_max, cnt,
2562 ci, candoff,
2563 abort_on_error);
2564 break;
2565 default:
2566 goto unsupported;
2567 }
2568 break;
2569 case TYPE_dbl:
2570 switch (tp) {
2571 case TYPE_dbl:
2572 nils = add_sht_dbl_dbl(lft, incr1, rgt, incr2,
2573 dst, GDK_dbl_max, cnt,
2574 ci, candoff,
2575 abort_on_error);
2576 break;
2577 default:
2578 goto unsupported;
2579 }
2580 break;
2581 default:
2582 goto unsupported;
2583 }
2584 break;
2585 case TYPE_int:
2586 switch (tp2) {
2587 case TYPE_bte:
2588 switch (tp) {
2589 case TYPE_int:
2590 nils = add_int_bte_int(lft, incr1, rgt, incr2,
2591 dst, GDK_int_max, cnt,
2592 ci, candoff,
2593 abort_on_error);
2594 break;
2595 case TYPE_lng:
2596 nils = add_int_bte_lng(lft, incr1, rgt, incr2,
2597 dst, GDK_lng_max, cnt,
2598 ci, candoff,
2599 abort_on_error);
2600 break;
2601#ifdef FULL_IMPLEMENTATION
2602#ifdef HAVE_HGE
2603 case TYPE_hge:
2604 nils = add_int_bte_hge(lft, incr1, rgt, incr2,
2605 dst, GDK_hge_max, cnt,
2606 ci, candoff,
2607 abort_on_error);
2608 break;
2609#endif
2610 case TYPE_flt:
2611 nils = add_int_bte_flt(lft, incr1, rgt, incr2,
2612 dst, GDK_flt_max, cnt,
2613 ci, candoff,
2614 abort_on_error);
2615 break;
2616 case TYPE_dbl:
2617 nils = add_int_bte_dbl(lft, incr1, rgt, incr2,
2618 dst, GDK_dbl_max, cnt,
2619 ci, candoff,
2620 abort_on_error);
2621 break;
2622#endif
2623 default:
2624 goto unsupported;
2625 }
2626 break;
2627 case TYPE_sht:
2628 switch (tp) {
2629 case TYPE_int:
2630 nils = add_int_sht_int(lft, incr1, rgt, incr2,
2631 dst, GDK_int_max, cnt,
2632 ci, candoff,
2633 abort_on_error);
2634 break;
2635 case TYPE_lng:
2636 nils = add_int_sht_lng(lft, incr1, rgt, incr2,
2637 dst, GDK_lng_max, cnt,
2638 ci, candoff,
2639 abort_on_error);
2640 break;
2641#ifdef FULL_IMPLEMENTATION
2642#ifdef HAVE_HGE
2643 case TYPE_hge:
2644 nils = add_int_sht_hge(lft, incr1, rgt, incr2,
2645 dst, GDK_hge_max, cnt,
2646 ci, candoff,
2647 abort_on_error);
2648 break;
2649#endif
2650 case TYPE_flt:
2651 nils = add_int_sht_flt(lft, incr1, rgt, incr2,
2652 dst, GDK_flt_max, cnt,
2653 ci, candoff,
2654 abort_on_error);
2655 break;
2656 case TYPE_dbl:
2657 nils = add_int_sht_dbl(lft, incr1, rgt, incr2,
2658 dst, GDK_dbl_max, cnt,
2659 ci, candoff,
2660 abort_on_error);
2661 break;
2662#endif
2663 default:
2664 goto unsupported;
2665 }
2666 break;
2667 case TYPE_int:
2668 switch (tp) {
2669 case TYPE_int:
2670 nils = add_int_int_int(lft, incr1, rgt, incr2,
2671 dst, GDK_int_max, cnt,
2672 ci, candoff,
2673 abort_on_error);
2674 break;
2675 case TYPE_lng:
2676 nils = add_int_int_lng(lft, incr1, rgt, incr2,
2677 dst, GDK_lng_max, cnt,
2678 ci, candoff,
2679 abort_on_error);
2680 break;
2681#ifdef FULL_IMPLEMENTATION
2682#ifdef HAVE_HGE
2683 case TYPE_hge:
2684 nils = add_int_int_hge(lft, incr1, rgt, incr2,
2685 dst, GDK_hge_max, cnt,
2686 ci, candoff,
2687 abort_on_error);
2688 break;
2689#endif
2690 case TYPE_flt:
2691 nils = add_int_int_flt(lft, incr1, rgt, incr2,
2692 dst, GDK_flt_max, cnt,
2693 ci, candoff,
2694 abort_on_error);
2695 break;
2696 case TYPE_dbl:
2697 nils = add_int_int_dbl(lft, incr1, rgt, incr2,
2698 dst, GDK_dbl_max, cnt,
2699 ci, candoff,
2700 abort_on_error);
2701 break;
2702#endif
2703 default:
2704 goto unsupported;
2705 }
2706 break;
2707 case TYPE_lng:
2708 switch (tp) {
2709 case TYPE_lng:
2710 nils = add_int_lng_lng(lft, incr1, rgt, incr2,
2711 dst, GDK_lng_max, cnt,
2712 ci, candoff,
2713 abort_on_error);
2714 break;
2715#ifdef HAVE_HGE
2716 case TYPE_hge:
2717 nils = add_int_lng_hge(lft, incr1, rgt, incr2,
2718 dst, GDK_hge_max, cnt,
2719 ci, candoff,
2720 abort_on_error);
2721 break;
2722#endif
2723#ifdef FULL_IMPLEMENTATION
2724 case TYPE_flt:
2725 nils = add_int_lng_flt(lft, incr1, rgt, incr2,
2726 dst, GDK_flt_max, cnt,
2727 ci, candoff,
2728 abort_on_error);
2729 break;
2730 case TYPE_dbl:
2731 nils = add_int_lng_dbl(lft, incr1, rgt, incr2,
2732 dst, GDK_dbl_max, cnt,
2733 ci, candoff,
2734 abort_on_error);
2735 break;
2736#endif
2737 default:
2738 goto unsupported;
2739 }
2740 break;
2741#ifdef HAVE_HGE
2742 case TYPE_hge:
2743 switch (tp) {
2744 case TYPE_hge:
2745 nils = add_int_hge_hge(lft, incr1, rgt, incr2,
2746 dst, GDK_hge_max, cnt,
2747 ci, candoff,
2748 abort_on_error);
2749 break;
2750#ifdef FULL_IMPLEMENTATION
2751 case TYPE_flt:
2752 nils = add_int_hge_flt(lft, incr1, rgt, incr2,
2753 dst, GDK_flt_max, cnt,
2754 ci, candoff,
2755 abort_on_error);
2756 break;
2757 case TYPE_dbl:
2758 nils = add_int_hge_dbl(lft, incr1, rgt, incr2,
2759 dst, GDK_dbl_max, cnt,
2760 ci, candoff,
2761 abort_on_error);
2762 break;
2763#endif
2764 default:
2765 goto unsupported;
2766 }
2767 break;
2768#endif
2769 case TYPE_flt:
2770 switch (tp) {
2771 case TYPE_flt:
2772 nils = add_int_flt_flt(lft, incr1, rgt, incr2,
2773 dst, GDK_flt_max, cnt,
2774 ci, candoff,
2775 abort_on_error);
2776 break;
2777 case TYPE_dbl:
2778 nils = add_int_flt_dbl(lft, incr1, rgt, incr2,
2779 dst, GDK_dbl_max, cnt,
2780 ci, candoff,
2781 abort_on_error);
2782 break;
2783 default:
2784 goto unsupported;
2785 }
2786 break;
2787 case TYPE_dbl:
2788 switch (tp) {
2789 case TYPE_dbl:
2790 nils = add_int_dbl_dbl(lft, incr1, rgt, incr2,
2791 dst, GDK_dbl_max, cnt,
2792 ci, candoff,
2793 abort_on_error);
2794 break;
2795 default:
2796 goto unsupported;
2797 }
2798 break;
2799 default:
2800 goto unsupported;
2801 }
2802 break;
2803 case TYPE_lng:
2804 switch (tp2) {
2805 case TYPE_bte:
2806 switch (tp) {
2807 case TYPE_lng:
2808 nils = add_lng_bte_lng(lft, incr1, rgt, incr2,
2809 dst, GDK_lng_max, cnt,
2810 ci, candoff,
2811 abort_on_error);
2812 break;
2813#ifdef HAVE_HGE
2814 case TYPE_hge:
2815 nils = add_lng_bte_hge(lft, incr1, rgt, incr2,
2816 dst, GDK_hge_max, cnt,
2817 ci, candoff,
2818 abort_on_error);
2819 break;
2820#endif
2821#ifdef FULL_IMPLEMENTATION
2822 case TYPE_flt:
2823 nils = add_lng_bte_flt(lft, incr1, rgt, incr2,
2824 dst, GDK_flt_max, cnt,
2825 ci, candoff,
2826 abort_on_error);
2827 break;
2828 case TYPE_dbl:
2829 nils = add_lng_bte_dbl(lft, incr1, rgt, incr2,
2830 dst, GDK_dbl_max, cnt,
2831 ci, candoff,
2832 abort_on_error);
2833 break;
2834#endif
2835 default:
2836 goto unsupported;
2837 }
2838 break;
2839 case TYPE_sht:
2840 switch (tp) {
2841 case TYPE_lng:
2842 nils = add_lng_sht_lng(lft, incr1, rgt, incr2,
2843 dst, GDK_lng_max, cnt,
2844 ci, candoff,
2845 abort_on_error);
2846 break;
2847#ifdef HAVE_HGE
2848 case TYPE_hge:
2849 nils = add_lng_sht_hge(lft, incr1, rgt, incr2,
2850 dst, GDK_hge_max, cnt,
2851 ci, candoff,
2852 abort_on_error);
2853 break;
2854#endif
2855#ifdef FULL_IMPLEMENTATION
2856 case TYPE_flt:
2857 nils = add_lng_sht_flt(lft, incr1, rgt, incr2,
2858 dst, GDK_flt_max, cnt,
2859 ci, candoff,
2860 abort_on_error);
2861 break;
2862 case TYPE_dbl:
2863 nils = add_lng_sht_dbl(lft, incr1, rgt, incr2,
2864 dst, GDK_dbl_max, cnt,
2865 ci, candoff,
2866 abort_on_error);
2867 break;
2868#endif
2869 default:
2870 goto unsupported;
2871 }
2872 break;
2873 case TYPE_int:
2874 switch (tp) {
2875 case TYPE_lng:
2876 nils = add_lng_int_lng(lft, incr1, rgt, incr2,
2877 dst, GDK_lng_max, cnt,
2878 ci, candoff,
2879 abort_on_error);
2880 break;
2881#ifdef HAVE_HGE
2882 case TYPE_hge:
2883 nils = add_lng_int_hge(lft, incr1, rgt, incr2,
2884 dst, GDK_hge_max, cnt,
2885 ci, candoff,
2886 abort_on_error);
2887 break;
2888#endif
2889#ifdef FULL_IMPLEMENTATION
2890 case TYPE_flt:
2891 nils = add_lng_int_flt(lft, incr1, rgt, incr2,
2892 dst, GDK_flt_max, cnt,
2893 ci, candoff,
2894 abort_on_error);
2895 break;
2896 case TYPE_dbl:
2897 nils = add_lng_int_dbl(lft, incr1, rgt, incr2,
2898 dst, GDK_dbl_max, cnt,
2899 ci, candoff,
2900 abort_on_error);
2901 break;
2902#endif
2903 default:
2904 goto unsupported;
2905 }
2906 break;
2907 case TYPE_lng:
2908 switch (tp) {
2909 case TYPE_lng:
2910 nils = add_lng_lng_lng(lft, incr1, rgt, incr2,
2911 dst, GDK_lng_max, cnt,
2912 ci, candoff,
2913 abort_on_error);
2914 break;
2915#ifdef HAVE_HGE
2916 case TYPE_hge:
2917 nils = add_lng_lng_hge(lft, incr1, rgt, incr2,
2918 dst, GDK_hge_max, cnt,
2919 ci, candoff,
2920 abort_on_error);
2921 break;
2922#endif
2923#ifdef FULL_IMPLEMENTATION
2924 case TYPE_flt:
2925 nils = add_lng_lng_flt(lft, incr1, rgt, incr2,
2926 dst, GDK_flt_max, cnt,
2927 ci, candoff,
2928 abort_on_error);
2929 break;
2930 case TYPE_dbl:
2931 nils = add_lng_lng_dbl(lft, incr1, rgt, incr2,
2932 dst, GDK_dbl_max, cnt,
2933 ci, candoff,
2934 abort_on_error);
2935 break;
2936#endif
2937 default:
2938 goto unsupported;
2939 }
2940 break;
2941#ifdef HAVE_HGE
2942 case TYPE_hge:
2943 switch (tp) {
2944 case TYPE_hge:
2945 nils = add_lng_hge_hge(lft, incr1, rgt, incr2,
2946 dst, GDK_hge_max, cnt,
2947 ci, candoff,
2948 abort_on_error);
2949 break;
2950#ifdef FULL_IMPLEMENTATION
2951 case TYPE_flt:
2952 nils = add_lng_hge_flt(lft, incr1, rgt, incr2,
2953 dst, GDK_flt_max, cnt,
2954 ci, candoff,
2955 abort_on_error);
2956 break;
2957 case TYPE_dbl:
2958 nils = add_lng_hge_dbl(lft, incr1, rgt, incr2,
2959 dst, GDK_dbl_max, cnt,
2960 ci, candoff,
2961 abort_on_error);
2962 break;
2963#endif
2964 default:
2965 goto unsupported;
2966 }
2967 break;
2968#endif
2969 case TYPE_flt:
2970 switch (tp) {
2971 case TYPE_flt:
2972 nils = add_lng_flt_flt(lft, incr1, rgt, incr2,
2973 dst, GDK_flt_max, cnt,
2974 ci, candoff,
2975 abort_on_error);
2976 break;
2977 case TYPE_dbl:
2978 nils = add_lng_flt_dbl(lft, incr1, rgt, incr2,
2979 dst, GDK_dbl_max, cnt,
2980 ci, candoff,
2981 abort_on_error);
2982 break;
2983 default:
2984 goto unsupported;
2985 }
2986 break;
2987 case TYPE_dbl:
2988 switch (tp) {
2989 case TYPE_dbl:
2990 nils = add_lng_dbl_dbl(lft, incr1, rgt, incr2,
2991 dst, GDK_dbl_max, cnt,
2992 ci, candoff,
2993 abort_on_error);
2994 break;
2995 default:
2996 goto unsupported;
2997 }
2998 break;
2999 default:
3000 goto unsupported;
3001 }
3002 break;
3003#ifdef HAVE_HGE
3004 case TYPE_hge:
3005 switch (tp2) {
3006 case TYPE_bte:
3007 switch (tp) {
3008 case TYPE_hge:
3009 nils = add_hge_bte_hge(lft, incr1, rgt, incr2,
3010 dst, GDK_hge_max, cnt,
3011 ci, candoff,
3012 abort_on_error);
3013 break;
3014#ifdef FULL_IMPLEMENTATION
3015 case TYPE_flt:
3016 nils = add_hge_bte_flt(lft, incr1, rgt, incr2,
3017 dst, GDK_flt_max, cnt,
3018 ci, candoff,
3019 abort_on_error);
3020 break;
3021 case TYPE_dbl:
3022 nils = add_hge_bte_dbl(lft, incr1, rgt, incr2,
3023 dst, GDK_dbl_max, cnt,
3024 ci, candoff,
3025 abort_on_error);
3026 break;
3027#endif
3028 default:
3029 goto unsupported;
3030 }
3031 break;
3032 case TYPE_sht:
3033 switch (tp) {
3034 case TYPE_hge:
3035 nils = add_hge_sht_hge(lft, incr1, rgt, incr2,
3036 dst, GDK_hge_max, cnt,
3037 ci, candoff,
3038 abort_on_error);
3039 break;
3040#ifdef FULL_IMPLEMENTATION
3041 case TYPE_flt:
3042 nils = add_hge_sht_flt(lft, incr1, rgt, incr2,
3043 dst, GDK_flt_max, cnt,
3044 ci, candoff,
3045 abort_on_error);
3046 break;
3047 case TYPE_dbl:
3048 nils = add_hge_sht_dbl(lft, incr1, rgt, incr2,
3049 dst, GDK_dbl_max, cnt,
3050 ci, candoff,
3051 abort_on_error);
3052 break;
3053#endif
3054 default:
3055 goto unsupported;
3056 }
3057 break;
3058 case TYPE_int:
3059 switch (tp) {
3060 case TYPE_hge:
3061 nils = add_hge_int_hge(lft, incr1, rgt, incr2,
3062 dst, GDK_hge_max, cnt,
3063 ci, candoff,
3064 abort_on_error);
3065 break;
3066#ifdef FULL_IMPLEMENTATION
3067 case TYPE_flt:
3068 nils = add_hge_int_flt(lft, incr1, rgt, incr2,
3069 dst, GDK_flt_max, cnt,
3070 ci, candoff,
3071 abort_on_error);
3072 break;
3073 case TYPE_dbl:
3074 nils = add_hge_int_dbl(lft, incr1, rgt, incr2,
3075 dst, GDK_dbl_max, cnt,
3076 ci, candoff,
3077 abort_on_error);
3078 break;
3079#endif
3080 default:
3081 goto unsupported;
3082 }
3083 break;
3084 case TYPE_lng:
3085 switch (tp) {
3086 case TYPE_hge:
3087 nils = add_hge_lng_hge(lft, incr1, rgt, incr2,
3088 dst, GDK_hge_max, cnt,
3089 ci, candoff,
3090 abort_on_error);
3091 break;
3092#ifdef FULL_IMPLEMENTATION
3093 case TYPE_flt:
3094 nils = add_hge_lng_flt(lft, incr1, rgt, incr2,
3095 dst, GDK_flt_max, cnt,
3096 ci, candoff,
3097 abort_on_error);
3098 break;
3099 case TYPE_dbl:
3100 nils = add_hge_lng_dbl(lft, incr1, rgt, incr2,
3101 dst, GDK_dbl_max, cnt,
3102 ci, candoff,
3103 abort_on_error);
3104 break;
3105#endif
3106 default:
3107 goto unsupported;
3108 }
3109 break;
3110 case TYPE_hge:
3111 switch (tp) {
3112 case TYPE_hge:
3113 nils = add_hge_hge_hge(lft, incr1, rgt, incr2,
3114 dst, GDK_hge_max, cnt,
3115 ci, candoff,
3116 abort_on_error);
3117 break;
3118#ifdef FULL_IMPLEMENTATION
3119 case TYPE_flt:
3120 nils = add_hge_hge_flt(lft, incr1, rgt, incr2,
3121 dst, GDK_flt_max, cnt,
3122 ci, candoff,
3123 abort_on_error);
3124 break;
3125 case TYPE_dbl:
3126 nils = add_hge_hge_dbl(lft, incr1, rgt, incr2,
3127 dst, GDK_dbl_max, cnt,
3128 ci, candoff,
3129 abort_on_error);
3130 break;
3131#endif
3132 default:
3133 goto unsupported;
3134 }
3135 break;
3136 case TYPE_flt:
3137 switch (tp) {
3138 case TYPE_flt:
3139 nils = add_hge_flt_flt(lft, incr1, rgt, incr2,
3140 dst, GDK_flt_max, cnt,
3141 ci, candoff,
3142 abort_on_error);
3143 break;
3144 case TYPE_dbl:
3145 nils = add_hge_flt_dbl(lft, incr1, rgt, incr2,
3146 dst, GDK_dbl_max, cnt,
3147 ci, candoff,
3148 abort_on_error);
3149 break;
3150 default:
3151 goto unsupported;
3152 }
3153 break;
3154 case TYPE_dbl:
3155 switch (tp) {
3156 case TYPE_dbl:
3157 nils = add_hge_dbl_dbl(lft, incr1, rgt, incr2,
3158 dst, GDK_dbl_max, cnt,
3159 ci, candoff,
3160 abort_on_error);
3161 break;
3162 default:
3163 goto unsupported;
3164 }
3165 break;
3166 default:
3167 goto unsupported;
3168 }
3169 break;
3170#endif
3171 case TYPE_flt:
3172 switch (tp2) {
3173 case TYPE_bte:
3174 switch (tp) {
3175 case TYPE_flt:
3176 nils = add_flt_bte_flt(lft, incr1, rgt, incr2,
3177 dst, GDK_flt_max, cnt,
3178 ci, candoff,
3179 abort_on_error);
3180 break;
3181 case TYPE_dbl:
3182 nils = add_flt_bte_dbl(lft, incr1, rgt, incr2,
3183 dst, GDK_dbl_max, cnt,
3184 ci, candoff,
3185 abort_on_error);
3186 break;
3187 default:
3188 goto unsupported;
3189 }
3190 break;
3191 case TYPE_sht:
3192 switch (tp) {
3193 case TYPE_flt:
3194 nils = add_flt_sht_flt(lft, incr1, rgt, incr2,
3195 dst, GDK_flt_max, cnt,
3196 ci, candoff,
3197 abort_on_error);
3198 break;
3199 case TYPE_dbl:
3200 nils = add_flt_sht_dbl(lft, incr1, rgt, incr2,
3201 dst, GDK_dbl_max, cnt,
3202 ci, candoff,
3203 abort_on_error);
3204 break;
3205 default:
3206 goto unsupported;
3207 }
3208 break;
3209 case TYPE_int:
3210 switch (tp) {
3211 case TYPE_flt:
3212 nils = add_flt_int_flt(lft, incr1, rgt, incr2,
3213 dst, GDK_flt_max, cnt,
3214 ci, candoff,
3215 abort_on_error);
3216 break;
3217 case TYPE_dbl:
3218 nils = add_flt_int_dbl(lft, incr1, rgt, incr2,
3219 dst, GDK_dbl_max, cnt,
3220 ci, candoff,
3221 abort_on_error);
3222 break;
3223 default:
3224 goto unsupported;
3225 }
3226 break;
3227 case TYPE_lng:
3228 switch (tp) {
3229 case TYPE_flt:
3230 nils = add_flt_lng_flt(lft, incr1, rgt, incr2,
3231 dst, GDK_flt_max, cnt,
3232 ci, candoff,
3233 abort_on_error);
3234 break;
3235 case TYPE_dbl:
3236 nils = add_flt_lng_dbl(lft, incr1, rgt, incr2,
3237 dst, GDK_dbl_max, cnt,
3238 ci, candoff,
3239 abort_on_error);
3240 break;
3241 default:
3242 goto unsupported;
3243 }
3244 break;
3245#ifdef HAVE_HGE
3246 case TYPE_hge:
3247 switch (tp) {
3248 case TYPE_flt:
3249 nils = add_flt_hge_flt(lft, incr1, rgt, incr2,
3250 dst, GDK_flt_max, cnt,
3251 ci, candoff,
3252 abort_on_error);
3253 break;
3254 case TYPE_dbl:
3255 nils = add_flt_hge_dbl(lft, incr1, rgt, incr2,
3256 dst, GDK_dbl_max, cnt,
3257 ci, candoff,
3258 abort_on_error);
3259 break;
3260 default:
3261 goto unsupported;
3262 }
3263 break;
3264#endif
3265 case TYPE_flt:
3266 switch (tp) {
3267 case TYPE_flt:
3268 nils = add_flt_flt_flt(lft, incr1, rgt, incr2,
3269 dst, GDK_flt_max, cnt,
3270 ci, candoff,
3271 abort_on_error);
3272 break;
3273 case TYPE_dbl:
3274 nils = add_flt_flt_dbl(lft, incr1, rgt, incr2,
3275 dst, GDK_dbl_max, cnt,
3276 ci, candoff,
3277 abort_on_error);
3278 break;
3279 default:
3280 goto unsupported;
3281 }
3282 break;
3283 case TYPE_dbl:
3284 switch (tp) {
3285 case TYPE_dbl:
3286 nils = add_flt_dbl_dbl(lft, incr1, rgt, incr2,
3287 dst, GDK_dbl_max, cnt,
3288 ci, candoff,
3289 abort_on_error);
3290 break;
3291 default:
3292 goto unsupported;
3293 }
3294 break;
3295 default:
3296 goto unsupported;
3297 }
3298 break;
3299 case TYPE_dbl:
3300 switch (tp2) {
3301 case TYPE_bte:
3302 switch (tp) {
3303 case TYPE_dbl:
3304 nils = add_dbl_bte_dbl(lft, incr1, rgt, incr2,
3305 dst, GDK_dbl_max, cnt,
3306 ci, candoff,
3307 abort_on_error);
3308 break;
3309 default:
3310 goto unsupported;
3311 }
3312 break;
3313 case TYPE_sht:
3314 switch (tp) {
3315 case TYPE_dbl:
3316 nils = add_dbl_sht_dbl(lft, incr1, rgt, incr2,
3317 dst, GDK_dbl_max, cnt,
3318 ci, candoff,
3319 abort_on_error);
3320 break;
3321 default:
3322 goto unsupported;
3323 }
3324 break;
3325 case TYPE_int:
3326 switch (tp) {
3327 case TYPE_dbl:
3328 nils = add_dbl_int_dbl(lft, incr1, rgt, incr2,
3329 dst, GDK_dbl_max, cnt,
3330 ci, candoff,
3331 abort_on_error);
3332 break;
3333 default:
3334 goto unsupported;
3335 }
3336 break;
3337 case TYPE_lng:
3338 switch (tp) {
3339 case TYPE_dbl:
3340 nils = add_dbl_lng_dbl(lft, incr1, rgt, incr2,
3341 dst, GDK_dbl_max, cnt,
3342 ci, candoff,
3343 abort_on_error);
3344 break;
3345 default:
3346 goto unsupported;
3347 }
3348 break;
3349#ifdef HAVE_HGE
3350 case TYPE_hge:
3351 switch (tp) {
3352 case TYPE_dbl:
3353 nils = add_dbl_hge_dbl(lft, incr1, rgt, incr2,
3354 dst, GDK_dbl_max, cnt,
3355 ci, candoff,
3356 abort_on_error);
3357 break;
3358 default:
3359 goto unsupported;
3360 }
3361 break;
3362#endif
3363 case TYPE_flt:
3364 switch (tp) {
3365 case TYPE_dbl:
3366 nils = add_dbl_flt_dbl(lft, incr1, rgt, incr2,
3367 dst, GDK_dbl_max, cnt,
3368 ci, candoff,
3369 abort_on_error);
3370 break;
3371 default:
3372 goto unsupported;
3373 }
3374 break;
3375 case TYPE_dbl:
3376 switch (tp) {
3377 case TYPE_dbl:
3378 nils = add_dbl_dbl_dbl(lft, incr1, rgt, incr2,
3379 dst, GDK_dbl_max, cnt,
3380 ci, candoff,
3381 abort_on_error);
3382 break;
3383 default:
3384 goto unsupported;
3385 }
3386 break;
3387 default:
3388 goto unsupported;
3389 }
3390 break;
3391 default:
3392 goto unsupported;
3393 }
3394
3395 return nils;
3396
3397 unsupported:
3398 GDKerror("%s: type combination (add(%s,%s)->%s) not supported.\n",
3399 func, ATOMname(tp1), ATOMname(tp2), ATOMname(tp));
3400 return BUN_NONE;
3401}
3402
3403static BUN
3404addstr_loop(BAT *b1, const char *l, BAT *b2, const char *r, BAT *bn,
3405 BUN cnt, struct canditer *restrict ci)
3406{
3407 BUN i;
3408 BUN nils = 0;
3409 char *s;
3410 size_t slen, llen, rlen;
3411 BATiter b1i, b2i;
3412 oid candoff;
3413
3414 assert(b1 != NULL || b2 != NULL); /* at least one not NULL */
3415 candoff = b1 ? b1->hseqbase : b2->hseqbase;
3416 b1i = bat_iterator(b1);
3417 b2i = bat_iterator(b2);
3418 oid x = canditer_next(ci) - candoff;
3419 slen = 1024;
3420 s = GDKmalloc(slen);
3421 if (s == NULL)
3422 goto bunins_failed;
3423 i = 0;
3424 do {
3425 while (i < x) {
3426 tfastins_nocheckVAR(bn, i, str_nil, Tsize(bn));
3427 nils++;
3428 i++;
3429 }
3430 if (b1)
3431 l = BUNtvar(b1i, i);
3432 if (b2)
3433 r = BUNtvar(b2i, i);
3434 if (strcmp(l, str_nil) == 0 || strcmp(r, str_nil) == 0) {
3435 nils++;
3436 tfastins_nocheckVAR(bn, i, str_nil, Tsize(bn));
3437 } else {
3438 llen = strlen(l);
3439 rlen = strlen(r);
3440 if (llen + rlen >= slen) {
3441 slen = llen + rlen + 1024;
3442 GDKfree(s);
3443 s = GDKmalloc(slen);
3444 if (s == NULL)
3445 goto bunins_failed;
3446 }
3447 (void) stpcpy(stpcpy(s, l), r);
3448 tfastins_nocheckVAR(bn, i, s, Tsize(bn));
3449 }
3450 i++;
3451 x = canditer_next(ci);
3452 if (is_oid_nil(x))
3453 break;
3454 x -= candoff;
3455 } while (i < cnt);
3456 GDKfree(s);
3457 while (i < cnt) {
3458 tfastins_nocheckVAR(bn, i, str_nil, Tsize(bn));
3459 nils++;
3460 i++;
3461 }
3462 bn->theap.dirty = true;
3463 return nils;
3464
3465 bunins_failed:
3466 GDKfree(s);
3467 return BUN_NONE;
3468}
3469
3470BAT *
3471BATcalcadd(BAT *b1, BAT *b2, BAT *s, int tp, bool abort_on_error)
3472{
3473 BAT *bn;
3474 BUN nils;
3475 BUN cnt, ncand;
3476 struct canditer ci;
3477
3478 BATcheck(b1, __func__, NULL);
3479 BATcheck(b2, __func__, NULL);
3480
3481 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
3482 return NULL;
3483
3484 cnt = BATcount(b1);
3485 ncand = canditer_init(&ci, b1, s);
3486 if (ncand == 0)
3487 return BATconstant(b1->hseqbase, tp, ATOMnilptr(tp),
3488 cnt, TRANSIENT);
3489
3490 bn = COLnew(b1->hseqbase, tp, cnt, TRANSIENT);
3491 if (bn == NULL)
3492 return NULL;
3493
3494 if (b1->ttype == TYPE_str && b2->ttype == TYPE_str && tp == TYPE_str) {
3495 nils = addstr_loop(b1, NULL, b2, NULL, bn, cnt, &ci);
3496 } else {
3497 nils = add_typeswitchloop(Tloc(b1, 0),
3498 b1->ttype, 1,
3499 Tloc(b2, 0),
3500 b2->ttype, 1,
3501 Tloc(bn, 0), tp,
3502 cnt, &ci, b1->hseqbase,
3503 abort_on_error, __func__);
3504 }
3505
3506 if (nils == BUN_NONE) {
3507 BBPunfix(bn->batCacheid);
3508 return NULL;
3509 }
3510
3511 BATsetcount(bn, cnt);
3512
3513 /* if both inputs are sorted the same way, and no overflow
3514 * occurred (we only know for sure if abort_on_error is set),
3515 * the result is also sorted */
3516 bn->tsorted = (abort_on_error && b1->tsorted & b2->tsorted && nils == 0) ||
3517 cnt <= 1 || nils == cnt;
3518 bn->trevsorted = (abort_on_error && b1->trevsorted & b2->trevsorted && nils == 0) ||
3519 cnt <= 1 || nils == cnt;
3520 bn->tkey = cnt <= 1;
3521 bn->tnil = nils != 0;
3522 bn->tnonil = nils == 0;
3523
3524 return bn;
3525}
3526
3527BAT *
3528BATcalcaddcst(BAT *b, const ValRecord *v, BAT *s, int tp, bool abort_on_error)
3529{
3530 BAT *bn;
3531 BUN nils;
3532 BUN cnt, ncand;
3533 struct canditer ci;
3534
3535 BATcheck(b, __func__, NULL);
3536
3537 cnt = BATcount(b);
3538 ncand = canditer_init(&ci, b, s);
3539 if (ncand == 0)
3540 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
3541 cnt, TRANSIENT);
3542
3543 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
3544 if (bn == NULL)
3545 return NULL;
3546
3547 if (b->ttype == TYPE_str && v->vtype == TYPE_str && tp == TYPE_str) {
3548 nils = addstr_loop(b, NULL, NULL, v->val.sval, bn, cnt, &ci);
3549 } else {
3550 nils = add_typeswitchloop(Tloc(b, 0), b->ttype, 1,
3551 VALptr(v), v->vtype, 0,
3552 Tloc(bn, 0), tp,
3553 cnt, &ci, b->hseqbase,
3554 abort_on_error, __func__);
3555 }
3556
3557 if (nils == BUN_NONE) {
3558 BBPunfix(bn->batCacheid);
3559 return NULL;
3560 }
3561
3562 BATsetcount(bn, cnt);
3563
3564 /* if the input is sorted, and no overflow occurred (we only
3565 * know for sure if abort_on_error is set), the result is also
3566 * sorted */
3567 bn->tsorted = (abort_on_error && b->tsorted && nils == 0) ||
3568 cnt <= 1 || nils == cnt;
3569 bn->trevsorted = (abort_on_error && b->trevsorted && nils == 0) ||
3570 cnt <= 1 || nils == cnt;
3571 bn->tkey = cnt <= 1;
3572 bn->tnil = nils != 0;
3573 bn->tnonil = nils == 0;
3574
3575 return bn;
3576}
3577
3578BAT *
3579BATcalccstadd(const ValRecord *v, BAT *b, BAT *s, int tp, bool abort_on_error)
3580{
3581 BAT *bn;
3582 BUN nils;
3583 BUN cnt, ncand;
3584 struct canditer ci;
3585
3586 BATcheck(b, __func__, NULL);
3587
3588 cnt = BATcount(b);
3589 ncand = canditer_init(&ci, b, s);
3590 if (ncand == 0)
3591 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
3592 cnt, TRANSIENT);
3593
3594 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
3595 if (bn == NULL)
3596 return NULL;
3597
3598 if (b->ttype == TYPE_str && v->vtype == TYPE_str && tp == TYPE_str) {
3599 nils = addstr_loop(NULL, v->val.sval, b, NULL, bn, cnt, &ci);
3600 } else {
3601 nils = add_typeswitchloop(VALptr(v), v->vtype, 0,
3602 Tloc(b, 0), b->ttype, 1,
3603 Tloc(bn, 0), tp,
3604 cnt, &ci, b->hseqbase,
3605 abort_on_error, __func__);
3606 }
3607
3608 if (nils == BUN_NONE) {
3609 BBPunfix(bn->batCacheid);
3610 return NULL;
3611 }
3612
3613 BATsetcount(bn, cnt);
3614
3615 /* if the input is sorted, and no overflow occurred (we only
3616 * know for sure if abort_on_error is set), the result is also
3617 * sorted */
3618 bn->tsorted = (abort_on_error && b->tsorted && nils == 0) ||
3619 cnt <= 1 || nils == cnt;
3620 bn->trevsorted = (abort_on_error && b->trevsorted && nils == 0) ||
3621 cnt <= 1 || nils == cnt;
3622 bn->tkey = cnt <= 1;
3623 bn->tnil = nils != 0;
3624 bn->tnonil = nils == 0;
3625
3626 return bn;
3627}
3628
3629gdk_return
3630VARcalcadd(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
3631 bool abort_on_error)
3632{
3633 if (add_typeswitchloop(VALptr(lft), lft->vtype, 0,
3634 VALptr(rgt), rgt->vtype, 0,
3635 VALget(ret), ret->vtype, 1,
3636 &(struct canditer){.tpe=cand_dense, .ncand=1},
3637 0, abort_on_error, __func__) == BUN_NONE)
3638 return GDK_FAIL;
3639 return GDK_SUCCEED;
3640}
3641
3642static BAT *
3643BATcalcincrdecr(BAT *b, BAT *s, bool abort_on_error,
3644 BUN (*typeswitchloop)(const void *, int, int,
3645 const void *, int, int,
3646 void *, int, BUN,
3647 struct canditer *restrict,
3648 oid, bool, const char *),
3649 const char *func)
3650{
3651 BAT *bn;
3652 BUN nils= 0;
3653 BUN cnt, ncand;
3654 struct canditer ci;
3655
3656 BATcheck(b, func, NULL);
3657
3658 cnt = BATcount(b);
3659 ncand = canditer_init(&ci, b, s);
3660 if (ncand == 0)
3661 return BATconstant(b->hseqbase, b->ttype, ATOMnilptr(b->ttype),
3662 cnt, TRANSIENT);
3663
3664 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
3665 if (bn == NULL)
3666 return NULL;
3667
3668 nils = (*typeswitchloop)(Tloc(b, 0), b->ttype, 1,
3669 &(bte){1}, TYPE_bte, 0,
3670 Tloc(bn, 0), bn->ttype,
3671 cnt, &ci, b->hseqbase,
3672 abort_on_error, func);
3673
3674 if (nils == BUN_NONE) {
3675 BBPunfix(bn->batCacheid);
3676 return NULL;
3677 }
3678
3679 BATsetcount(bn, cnt);
3680
3681 /* if the input is sorted, and no overflow occurred (we only
3682 * know for sure if abort_on_error is set), the result is also
3683 * sorted */
3684 bn->tsorted = (abort_on_error && b->tsorted) ||
3685 cnt <= 1 || nils == cnt;
3686 bn->trevsorted = (abort_on_error && b->trevsorted) ||
3687 cnt <= 1 || nils == cnt;
3688 bn->tkey = cnt <= 1;
3689 bn->tnil = nils != 0;
3690 bn->tnonil = nils == 0;
3691
3692 if (nils && !b->tnil) {
3693 b->tnil = true;
3694 b->batDirtydesc = true;
3695 }
3696 if (nils == 0 && !b->tnonil) {
3697 b->tnonil = true;
3698 b->batDirtydesc = true;
3699 }
3700
3701 return bn;
3702}
3703
3704BAT *
3705BATcalcincr(BAT *b, BAT *s, bool abort_on_error)
3706{
3707 return BATcalcincrdecr(b, s, abort_on_error, add_typeswitchloop,
3708 __func__);
3709}
3710
3711gdk_return
3712VARcalcincr(ValPtr ret, const ValRecord *v, bool abort_on_error)
3713{
3714 if (add_typeswitchloop(VALptr(v), v->vtype, 0,
3715 &(bte){1}, TYPE_bte, 0,
3716 VALget(ret), ret->vtype, 1,
3717 &(struct canditer){.tpe=cand_dense, .ncand=1},
3718 0, abort_on_error, __func__) == BUN_NONE)
3719 return GDK_FAIL;
3720 return GDK_SUCCEED;
3721}
3722
3723/* ---------------------------------------------------------------------- */
3724/* subtraction (any numeric type) */
3725
3726#define SUB_3TYPE(TYPE1, TYPE2, TYPE3, IF) \
3727static BUN \
3728sub_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
3729 const TYPE2 *rgt, int incr2, \
3730 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
3731 struct canditer *restrict ci, \
3732 oid candoff, bool abort_on_error) \
3733{ \
3734 oid x = canditer_next(ci) - candoff; \
3735 BUN i, j, k = 0; \
3736 BUN nils = 0; \
3737 \
3738 do { \
3739 while (k < x) { \
3740 dst[k++] = TYPE3##_nil; \
3741 nils++; \
3742 } \
3743 i = x * incr1; \
3744 j = x * incr2; \
3745 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
3746 dst[k] = TYPE3##_nil; \
3747 nils++; \
3748 } else { \
3749 SUB##IF##_WITH_CHECK(lft[i], rgt[j], \
3750 TYPE3, dst[k], \
3751 max, \
3752 ON_OVERFLOW(TYPE1, TYPE2, "-")); \
3753 } \
3754 k++; \
3755 x = canditer_next(ci); \
3756 if (is_oid_nil(x)) \
3757 break; \
3758 x -= candoff; \
3759 } while (k < cnt); \
3760 while (k < cnt) { \
3761 dst[k++] = TYPE3##_nil; \
3762 nils++; \
3763 } \
3764 return nils; \
3765}
3766
3767#define SUB_3TYPE_enlarge(TYPE1, TYPE2, TYPE3, IF) \
3768static BUN \
3769sub_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
3770 const TYPE2 *rgt, int incr2, \
3771 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
3772 struct canditer *restrict ci, \
3773 oid candoff, bool abort_on_error) \
3774{ \
3775 oid x = canditer_next(ci) - candoff; \
3776 BUN i, j, k = 0; \
3777 BUN nils = 0; \
3778 const bool couldoverflow = (max < (TYPE3) GDK_##TYPE1##_max + (TYPE3) GDK_##TYPE2##_max); \
3779 \
3780 do { \
3781 while (k < x) { \
3782 dst[k++] = TYPE3##_nil; \
3783 nils++; \
3784 } \
3785 i = x * incr1; \
3786 j = x * incr2; \
3787 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
3788 dst[k] = TYPE3##_nil; \
3789 nils++; \
3790 } else if (couldoverflow) { \
3791 SUB##IF##_WITH_CHECK(lft[i], rgt[j], \
3792 TYPE3, dst[k], \
3793 max, \
3794 ON_OVERFLOW(TYPE1, TYPE2, "-")); \
3795 } else { \
3796 dst[k] = (TYPE3) lft[i] + rgt[j]; \
3797 } \
3798 k++; \
3799 x = canditer_next(ci); \
3800 if (is_oid_nil(x)) \
3801 break; \
3802 x -= candoff; \
3803 } while (k < cnt); \
3804 while (k < cnt) { \
3805 dst[k++] = TYPE3##_nil; \
3806 nils++; \
3807 } \
3808 return nils; \
3809}
3810
3811SUB_3TYPE(bte, bte, bte, I)
3812SUB_3TYPE_enlarge(bte, bte, sht, I)
3813#ifdef FULL_IMPLEMENTATION
3814SUB_3TYPE_enlarge(bte, bte, int, I)
3815SUB_3TYPE_enlarge(bte, bte, lng, I)
3816#ifdef HAVE_HGE
3817SUB_3TYPE_enlarge(bte, bte, hge, I)
3818#endif
3819SUB_3TYPE_enlarge(bte, bte, flt, F)
3820SUB_3TYPE_enlarge(bte, bte, dbl, F)
3821#endif
3822SUB_3TYPE(bte, sht, sht, I)
3823SUB_3TYPE_enlarge(bte, sht, int, I)
3824#ifdef FULL_IMPLEMENTATION
3825SUB_3TYPE_enlarge(bte, sht, lng, I)
3826#ifdef HAVE_HGE
3827SUB_3TYPE_enlarge(bte, sht, hge, I)
3828#endif
3829SUB_3TYPE_enlarge(bte, sht, flt, F)
3830SUB_3TYPE_enlarge(bte, sht, dbl, F)
3831#endif
3832SUB_3TYPE(bte, int, int, I)
3833SUB_3TYPE_enlarge(bte, int, lng, I)
3834#ifdef FULL_IMPLEMENTATION
3835#ifdef HAVE_HGE
3836SUB_3TYPE_enlarge(bte, int, hge, I)
3837#endif
3838SUB_3TYPE_enlarge(bte, int, flt, F)
3839SUB_3TYPE_enlarge(bte, int, dbl, F)
3840#endif
3841SUB_3TYPE(bte, lng, lng, I)
3842#ifdef HAVE_HGE
3843SUB_3TYPE_enlarge(bte, lng, hge, I)
3844#endif
3845#ifdef FULL_IMPLEMENTATION
3846SUB_3TYPE_enlarge(bte, lng, flt, F)
3847SUB_3TYPE_enlarge(bte, lng, dbl, F)
3848#endif
3849#ifdef HAVE_HGE
3850SUB_3TYPE(bte, hge, hge, I)
3851#ifdef FULL_IMPLEMENTATION
3852SUB_3TYPE_enlarge(bte, hge, flt, F)
3853SUB_3TYPE_enlarge(bte, hge, dbl, F)
3854#endif
3855#endif
3856SUB_3TYPE(bte, flt, flt, F)
3857SUB_3TYPE_enlarge(bte, flt, dbl, F)
3858SUB_3TYPE(bte, dbl, dbl, F)
3859SUB_3TYPE(sht, bte, sht, I)
3860SUB_3TYPE_enlarge(sht, bte, int, I)
3861#ifdef FULL_IMPLEMENTATION
3862SUB_3TYPE_enlarge(sht, bte, lng, I)
3863#ifdef HAVE_HGE
3864SUB_3TYPE_enlarge(sht, bte, hge, I)
3865#endif
3866SUB_3TYPE_enlarge(sht, bte, flt, F)
3867SUB_3TYPE_enlarge(sht, bte, dbl, F)
3868#endif
3869SUB_3TYPE(sht, sht, sht, I)
3870SUB_3TYPE_enlarge(sht, sht, int, I)
3871#ifdef FULL_IMPLEMENTATION
3872SUB_3TYPE_enlarge(sht, sht, lng, I)
3873#ifdef HAVE_HGE
3874SUB_3TYPE_enlarge(sht, sht, hge, I)
3875#endif
3876SUB_3TYPE_enlarge(sht, sht, flt, F)
3877SUB_3TYPE_enlarge(sht, sht, dbl, F)
3878#endif
3879SUB_3TYPE(sht, int, int, I)
3880SUB_3TYPE_enlarge(sht, int, lng, I)
3881#ifdef FULL_IMPLEMENTATION
3882#ifdef HAVE_HGE
3883SUB_3TYPE_enlarge(sht, int, hge, I)
3884#endif
3885SUB_3TYPE_enlarge(sht, int, flt, F)
3886SUB_3TYPE_enlarge(sht, int, dbl, F)
3887#endif
3888SUB_3TYPE(sht, lng, lng, I)
3889#ifdef HAVE_HGE
3890SUB_3TYPE_enlarge(sht, lng, hge, I)
3891#endif
3892#ifdef FULL_IMPLEMENTATION
3893SUB_3TYPE_enlarge(sht, lng, flt, F)
3894SUB_3TYPE_enlarge(sht, lng, dbl, F)
3895#endif
3896#ifdef HAVE_HGE
3897SUB_3TYPE(sht, hge, hge, I)
3898#ifdef FULL_IMPLEMENTATION
3899SUB_3TYPE_enlarge(sht, hge, flt, F)
3900SUB_3TYPE_enlarge(sht, hge, dbl, F)
3901#endif
3902#endif
3903SUB_3TYPE(sht, flt, flt, F)
3904SUB_3TYPE_enlarge(sht, flt, dbl, F)
3905SUB_3TYPE(sht, dbl, dbl, F)
3906SUB_3TYPE(int, bte, int, I)
3907SUB_3TYPE_enlarge(int, bte, lng, I)
3908#ifdef FULL_IMPLEMENTATION
3909#ifdef HAVE_HGE
3910SUB_3TYPE_enlarge(int, bte, hge, I)
3911#endif
3912SUB_3TYPE_enlarge(int, bte, flt, F)
3913SUB_3TYPE_enlarge(int, bte, dbl, F)
3914#endif
3915SUB_3TYPE(int, sht, int, I)
3916SUB_3TYPE_enlarge(int, sht, lng, I)
3917#ifdef FULL_IMPLEMENTATION
3918#ifdef HAVE_HGE
3919SUB_3TYPE_enlarge(int, sht, hge, I)
3920#endif
3921SUB_3TYPE_enlarge(int, sht, flt, F)
3922SUB_3TYPE_enlarge(int, sht, dbl, F)
3923#endif
3924SUB_3TYPE(int, int, int, I)
3925SUB_3TYPE_enlarge(int, int, lng, I)
3926#ifdef FULL_IMPLEMENTATION
3927#ifdef HAVE_HGE
3928SUB_3TYPE_enlarge(int, int, hge, I)
3929#endif
3930SUB_3TYPE_enlarge(int, int, flt, F)
3931SUB_3TYPE_enlarge(int, int, dbl, F)
3932#endif
3933SUB_3TYPE(int, lng, lng, I)
3934#ifdef HAVE_HGE
3935SUB_3TYPE_enlarge(int, lng, hge, I)
3936#endif
3937#ifdef FULL_IMPLEMENTATION
3938SUB_3TYPE_enlarge(int, lng, flt, F)
3939SUB_3TYPE_enlarge(int, lng, dbl, F)
3940#endif
3941#ifdef HAVE_HGE
3942SUB_3TYPE(int, hge, hge, I)
3943#ifdef FULL_IMPLEMENTATION
3944SUB_3TYPE_enlarge(int, hge, flt, F)
3945SUB_3TYPE_enlarge(int, hge, dbl, F)
3946#endif
3947#endif
3948SUB_3TYPE(int, flt, flt, F)
3949SUB_3TYPE_enlarge(int, flt, dbl, F)
3950SUB_3TYPE(int, dbl, dbl, F)
3951SUB_3TYPE(lng, bte, lng, I)
3952#ifdef HAVE_HGE
3953SUB_3TYPE_enlarge(lng, bte, hge, I)
3954#endif
3955#ifdef FULL_IMPLEMENTATION
3956SUB_3TYPE_enlarge(lng, bte, flt, F)
3957SUB_3TYPE_enlarge(lng, bte, dbl, F)
3958#endif
3959SUB_3TYPE(lng, sht, lng, I)
3960#ifdef HAVE_HGE
3961SUB_3TYPE_enlarge(lng, sht, hge, I)
3962#endif
3963#ifdef FULL_IMPLEMENTATION
3964SUB_3TYPE_enlarge(lng, sht, flt, F)
3965SUB_3TYPE_enlarge(lng, sht, dbl, F)
3966#endif
3967SUB_3TYPE(lng, int, lng, I)
3968#ifdef HAVE_HGE
3969SUB_3TYPE_enlarge(lng, int, hge, I)
3970#endif
3971#ifdef FULL_IMPLEMENTATION
3972SUB_3TYPE_enlarge(lng, int, flt, F)
3973SUB_3TYPE_enlarge(lng, int, dbl, F)
3974#endif
3975SUB_3TYPE(lng, lng, lng, I)
3976#ifdef HAVE_HGE
3977SUB_3TYPE_enlarge(lng, lng, hge, I)
3978#endif
3979#ifdef FULL_IMPLEMENTATION
3980SUB_3TYPE_enlarge(lng, lng, flt, F)
3981SUB_3TYPE_enlarge(lng, lng, dbl, F)
3982#endif
3983#ifdef HAVE_HGE
3984SUB_3TYPE(lng, hge, hge, I)
3985#ifdef FULL_IMPLEMENTATION
3986SUB_3TYPE_enlarge(lng, hge, flt, F)
3987SUB_3TYPE_enlarge(lng, hge, dbl, F)
3988#endif
3989#endif
3990SUB_3TYPE(lng, flt, flt, F)
3991SUB_3TYPE_enlarge(lng, flt, dbl, F)
3992SUB_3TYPE(lng, dbl, dbl, F)
3993#ifdef HAVE_HGE
3994SUB_3TYPE(hge, bte, hge, I)
3995#ifdef FULL_IMPLEMENTATION
3996SUB_3TYPE_enlarge(hge, bte, flt, F)
3997SUB_3TYPE_enlarge(hge, bte, dbl, F)
3998#endif
3999SUB_3TYPE(hge, sht, hge, I)
4000#ifdef FULL_IMPLEMENTATION
4001SUB_3TYPE_enlarge(hge, sht, flt, F)
4002SUB_3TYPE_enlarge(hge, sht, dbl, F)
4003#endif
4004SUB_3TYPE(hge, int, hge, I)
4005#ifdef FULL_IMPLEMENTATION
4006SUB_3TYPE_enlarge(hge, int, flt, F)
4007SUB_3TYPE_enlarge(hge, int, dbl, F)
4008#endif
4009SUB_3TYPE(hge, lng, hge, I)
4010#ifdef FULL_IMPLEMENTATION
4011SUB_3TYPE_enlarge(hge, lng, flt, F)
4012SUB_3TYPE_enlarge(hge, lng, dbl, F)
4013#endif
4014SUB_3TYPE(hge, hge, hge, I)
4015#ifdef FULL_IMPLEMENTATION
4016SUB_3TYPE_enlarge(hge, hge, flt, F)
4017SUB_3TYPE_enlarge(hge, hge, dbl, F)
4018#endif
4019SUB_3TYPE(hge, flt, flt, F)
4020SUB_3TYPE_enlarge(hge, flt, dbl, F)
4021SUB_3TYPE(hge, dbl, dbl, F)
4022#endif
4023SUB_3TYPE(flt, bte, flt, F)
4024SUB_3TYPE_enlarge(flt, bte, dbl, F)
4025SUB_3TYPE(flt, sht, flt, F)
4026SUB_3TYPE_enlarge(flt, sht, dbl, F)
4027SUB_3TYPE(flt, int, flt, F)
4028SUB_3TYPE_enlarge(flt, int, dbl, F)
4029SUB_3TYPE(flt, lng, flt, F)
4030SUB_3TYPE_enlarge(flt, lng, dbl, F)
4031#ifdef HAVE_HGE
4032SUB_3TYPE(flt, hge, flt, F)
4033SUB_3TYPE_enlarge(flt, hge, dbl, F)
4034#endif
4035SUB_3TYPE(flt, flt, flt, F)
4036SUB_3TYPE_enlarge(flt, flt, dbl, F)
4037SUB_3TYPE(flt, dbl, dbl, F)
4038SUB_3TYPE(dbl, bte, dbl, F)
4039SUB_3TYPE(dbl, sht, dbl, F)
4040SUB_3TYPE(dbl, int, dbl, F)
4041SUB_3TYPE(dbl, lng, dbl, F)
4042#ifdef HAVE_HGE
4043SUB_3TYPE(dbl, hge, dbl, F)
4044#endif
4045SUB_3TYPE(dbl, flt, dbl, F)
4046SUB_3TYPE(dbl, dbl, dbl, F)
4047
4048static BUN
4049sub_typeswitchloop(const void *lft, int tp1, int incr1,
4050 const void *rgt, int tp2, int incr2,
4051 void *restrict dst, int tp, BUN cnt,
4052 struct canditer *restrict ci, oid candoff,
4053 bool abort_on_error, const char *func)
4054{
4055 BUN nils;
4056
4057 tp1 = ATOMbasetype(tp1);
4058 tp2 = ATOMbasetype(tp2);
4059 tp = ATOMbasetype(tp);
4060 switch (tp1) {
4061 case TYPE_bte:
4062 switch (tp2) {
4063 case TYPE_bte:
4064 switch (tp) {
4065 case TYPE_bte:
4066 nils = sub_bte_bte_bte(lft, incr1, rgt, incr2,
4067 dst, GDK_bte_max, cnt,
4068 ci, candoff,
4069 abort_on_error);
4070 break;
4071 case TYPE_sht:
4072 nils = sub_bte_bte_sht(lft, incr1, rgt, incr2,
4073 dst, GDK_sht_max, cnt,
4074 ci, candoff,
4075 abort_on_error);
4076 break;
4077#ifdef FULL_IMPLEMENTATION
4078 case TYPE_int:
4079 nils = sub_bte_bte_int(lft, incr1, rgt, incr2,
4080 dst, GDK_int_max, cnt,
4081 ci, candoff,
4082 abort_on_error);
4083 break;
4084 case TYPE_lng:
4085 nils = sub_bte_bte_lng(lft, incr1, rgt, incr2,
4086 dst, GDK_lng_max, cnt,
4087 ci, candoff,
4088 abort_on_error);
4089 break;
4090#ifdef HAVE_HGE
4091 case TYPE_hge:
4092 nils = sub_bte_bte_hge(lft, incr1, rgt, incr2,
4093 dst, GDK_hge_max, cnt,
4094 ci, candoff,
4095 abort_on_error);
4096 break;
4097#endif
4098 case TYPE_flt:
4099 nils = sub_bte_bte_flt(lft, incr1, rgt, incr2,
4100 dst, GDK_flt_max, cnt,
4101 ci, candoff,
4102 abort_on_error);
4103 break;
4104 case TYPE_dbl:
4105 nils = sub_bte_bte_dbl(lft, incr1, rgt, incr2,
4106 dst, GDK_dbl_max, cnt,
4107 ci, candoff,
4108 abort_on_error);
4109 break;
4110#endif
4111 default:
4112 goto unsupported;
4113 }
4114 break;
4115 case TYPE_sht:
4116 switch (tp) {
4117 case TYPE_sht:
4118 nils = sub_bte_sht_sht(lft, incr1, rgt, incr2,
4119 dst, GDK_sht_max, cnt,
4120 ci, candoff,
4121 abort_on_error);
4122 break;
4123 case TYPE_int:
4124 nils = sub_bte_sht_int(lft, incr1, rgt, incr2,
4125 dst, GDK_int_max, cnt,
4126 ci, candoff,
4127 abort_on_error);
4128 break;
4129#ifdef FULL_IMPLEMENTATION
4130 case TYPE_lng:
4131 nils = sub_bte_sht_lng(lft, incr1, rgt, incr2,
4132 dst, GDK_lng_max, cnt,
4133 ci, candoff,
4134 abort_on_error);
4135 break;
4136#ifdef HAVE_HGE
4137 case TYPE_hge:
4138 nils = sub_bte_sht_hge(lft, incr1, rgt, incr2,
4139 dst, GDK_hge_max, cnt,
4140 ci, candoff,
4141 abort_on_error);
4142 break;
4143#endif
4144 case TYPE_flt:
4145 nils = sub_bte_sht_flt(lft, incr1, rgt, incr2,
4146 dst, GDK_flt_max, cnt,
4147 ci, candoff,
4148 abort_on_error);
4149 break;
4150 case TYPE_dbl:
4151 nils = sub_bte_sht_dbl(lft, incr1, rgt, incr2,
4152 dst, GDK_dbl_max, cnt,
4153 ci, candoff,
4154 abort_on_error);
4155 break;
4156#endif
4157 default:
4158 goto unsupported;
4159 }
4160 break;
4161 case TYPE_int:
4162 switch (tp) {
4163 case TYPE_int:
4164 nils = sub_bte_int_int(lft, incr1, rgt, incr2,
4165 dst, GDK_int_max, cnt,
4166 ci, candoff,
4167 abort_on_error);
4168 break;
4169 case TYPE_lng:
4170 nils = sub_bte_int_lng(lft, incr1, rgt, incr2,
4171 dst, GDK_lng_max, cnt,
4172 ci, candoff,
4173 abort_on_error);
4174 break;
4175#ifdef FULL_IMPLEMENTATION
4176#ifdef HAVE_HGE
4177 case TYPE_hge:
4178 nils = sub_bte_int_hge(lft, incr1, rgt, incr2,
4179 dst, GDK_hge_max, cnt,
4180 ci, candoff,
4181 abort_on_error);
4182 break;
4183#endif
4184 case TYPE_flt:
4185 nils = sub_bte_int_flt(lft, incr1, rgt, incr2,
4186 dst, GDK_flt_max, cnt,
4187 ci, candoff,
4188 abort_on_error);
4189 break;
4190 case TYPE_dbl:
4191 nils = sub_bte_int_dbl(lft, incr1, rgt, incr2,
4192 dst, GDK_dbl_max, cnt,
4193 ci, candoff,
4194 abort_on_error);
4195 break;
4196#endif
4197 default:
4198 goto unsupported;
4199 }
4200 break;
4201 case TYPE_lng:
4202 switch (tp) {
4203 case TYPE_lng:
4204 nils = sub_bte_lng_lng(lft, incr1, rgt, incr2,
4205 dst, GDK_lng_max, cnt,
4206 ci, candoff,
4207 abort_on_error);
4208 break;
4209#ifdef HAVE_HGE
4210 case TYPE_hge:
4211 nils = sub_bte_lng_hge(lft, incr1, rgt, incr2,
4212 dst, GDK_hge_max, cnt,
4213 ci, candoff,
4214 abort_on_error);
4215 break;
4216#endif
4217#ifdef FULL_IMPLEMENTATION
4218 case TYPE_flt:
4219 nils = sub_bte_lng_flt(lft, incr1, rgt, incr2,
4220 dst, GDK_flt_max, cnt,
4221 ci, candoff,
4222 abort_on_error);
4223 break;
4224 case TYPE_dbl:
4225 nils = sub_bte_lng_dbl(lft, incr1, rgt, incr2,
4226 dst, GDK_dbl_max, cnt,
4227 ci, candoff,
4228 abort_on_error);
4229 break;
4230#endif
4231 default:
4232 goto unsupported;
4233 }
4234 break;
4235#ifdef HAVE_HGE
4236 case TYPE_hge:
4237 switch (tp) {
4238 case TYPE_hge:
4239 nils = sub_bte_hge_hge(lft, incr1, rgt, incr2,
4240 dst, GDK_hge_max, cnt,
4241 ci, candoff,
4242 abort_on_error);
4243 break;
4244#ifdef FULL_IMPLEMENTATION
4245 case TYPE_flt:
4246 nils = sub_bte_hge_flt(lft, incr1, rgt, incr2,
4247 dst, GDK_flt_max, cnt,
4248 ci, candoff,
4249 abort_on_error);
4250 break;
4251 case TYPE_dbl:
4252 nils = sub_bte_hge_dbl(lft, incr1, rgt, incr2,
4253 dst, GDK_dbl_max, cnt,
4254 ci, candoff,
4255 abort_on_error);
4256 break;
4257#endif
4258 default:
4259 goto unsupported;
4260 }
4261 break;
4262#endif
4263 case TYPE_flt:
4264 switch (tp) {
4265 case TYPE_flt:
4266 nils = sub_bte_flt_flt(lft, incr1, rgt, incr2,
4267 dst, GDK_flt_max, cnt,
4268 ci, candoff,
4269 abort_on_error);
4270 break;
4271 case TYPE_dbl:
4272 nils = sub_bte_flt_dbl(lft, incr1, rgt, incr2,
4273 dst, GDK_dbl_max, cnt,
4274 ci, candoff,
4275 abort_on_error);
4276 break;
4277 default:
4278 goto unsupported;
4279 }
4280 break;
4281 case TYPE_dbl:
4282 switch (tp) {
4283 case TYPE_dbl:
4284 nils = sub_bte_dbl_dbl(lft, incr1, rgt, incr2,
4285 dst, GDK_dbl_max, cnt,
4286 ci, candoff,
4287 abort_on_error);
4288 break;
4289 default:
4290 goto unsupported;
4291 }
4292 break;
4293 default:
4294 goto unsupported;
4295 }
4296 break;
4297 case TYPE_sht:
4298 switch (tp2) {
4299 case TYPE_bte:
4300 switch (tp) {
4301 case TYPE_sht:
4302 nils = sub_sht_bte_sht(lft, incr1, rgt, incr2,
4303 dst, GDK_sht_max, cnt,
4304 ci, candoff,
4305 abort_on_error);
4306 break;
4307 case TYPE_int:
4308 nils = sub_sht_bte_int(lft, incr1, rgt, incr2,
4309 dst, GDK_int_max, cnt,
4310 ci, candoff,
4311 abort_on_error);
4312 break;
4313#ifdef FULL_IMPLEMENTATION
4314 case TYPE_lng:
4315 nils = sub_sht_bte_lng(lft, incr1, rgt, incr2,
4316 dst, GDK_lng_max, cnt,
4317 ci, candoff,
4318 abort_on_error);
4319 break;
4320#ifdef HAVE_HGE
4321 case TYPE_hge:
4322 nils = sub_sht_bte_hge(lft, incr1, rgt, incr2,
4323 dst, GDK_hge_max, cnt,
4324 ci, candoff,
4325 abort_on_error);
4326 break;
4327#endif
4328 case TYPE_flt:
4329 nils = sub_sht_bte_flt(lft, incr1, rgt, incr2,
4330 dst, GDK_flt_max, cnt,
4331 ci, candoff,
4332 abort_on_error);
4333 break;
4334 case TYPE_dbl:
4335 nils = sub_sht_bte_dbl(lft, incr1, rgt, incr2,
4336 dst, GDK_dbl_max, cnt,
4337 ci, candoff,
4338 abort_on_error);
4339 break;
4340#endif
4341 default:
4342 goto unsupported;
4343 }
4344 break;
4345 case TYPE_sht:
4346 switch (tp) {
4347 case TYPE_sht:
4348 nils = sub_sht_sht_sht(lft, incr1, rgt, incr2,
4349 dst, GDK_sht_max, cnt,
4350 ci, candoff,
4351 abort_on_error);
4352 break;
4353 case TYPE_int:
4354 nils = sub_sht_sht_int(lft, incr1, rgt, incr2,
4355 dst, GDK_int_max, cnt,
4356 ci, candoff,
4357 abort_on_error);
4358 break;
4359#ifdef FULL_IMPLEMENTATION
4360 case TYPE_lng:
4361 nils = sub_sht_sht_lng(lft, incr1, rgt, incr2,
4362 dst, GDK_lng_max, cnt,
4363 ci, candoff,
4364 abort_on_error);
4365 break;
4366#ifdef HAVE_HGE
4367 case TYPE_hge:
4368 nils = sub_sht_sht_hge(lft, incr1, rgt, incr2,
4369 dst, GDK_hge_max, cnt,
4370 ci, candoff,
4371 abort_on_error);
4372 break;
4373#endif
4374 case TYPE_flt:
4375 nils = sub_sht_sht_flt(lft, incr1, rgt, incr2,
4376 dst, GDK_flt_max, cnt,
4377 ci, candoff,
4378 abort_on_error);
4379 break;
4380 case TYPE_dbl:
4381 nils = sub_sht_sht_dbl(lft, incr1, rgt, incr2,
4382 dst, GDK_dbl_max, cnt,
4383 ci, candoff,
4384 abort_on_error);
4385 break;
4386#endif
4387 default:
4388 goto unsupported;
4389 }
4390 break;
4391 case TYPE_int:
4392 switch (tp) {
4393 case TYPE_int:
4394 nils = sub_sht_int_int(lft, incr1, rgt, incr2,
4395 dst, GDK_int_max, cnt,
4396 ci, candoff,
4397 abort_on_error);
4398 break;
4399 case TYPE_lng:
4400 nils = sub_sht_int_lng(lft, incr1, rgt, incr2,
4401 dst, GDK_lng_max, cnt,
4402 ci, candoff,
4403 abort_on_error);
4404 break;
4405#ifdef FULL_IMPLEMENTATION
4406#ifdef HAVE_HGE
4407 case TYPE_hge:
4408 nils = sub_sht_int_hge(lft, incr1, rgt, incr2,
4409 dst, GDK_hge_max, cnt,
4410 ci, candoff,
4411 abort_on_error);
4412 break;
4413#endif
4414 case TYPE_flt:
4415 nils = sub_sht_int_flt(lft, incr1, rgt, incr2,
4416 dst, GDK_flt_max, cnt,
4417 ci, candoff,
4418 abort_on_error);
4419 break;
4420 case TYPE_dbl:
4421 nils = sub_sht_int_dbl(lft, incr1, rgt, incr2,
4422 dst, GDK_dbl_max, cnt,
4423 ci, candoff,
4424 abort_on_error);
4425 break;
4426#endif
4427 default:
4428 goto unsupported;
4429 }
4430 break;
4431 case TYPE_lng:
4432 switch (tp) {
4433 case TYPE_lng:
4434 nils = sub_sht_lng_lng(lft, incr1, rgt, incr2,
4435 dst, GDK_lng_max, cnt,
4436 ci, candoff,
4437 abort_on_error);
4438 break;
4439#ifdef HAVE_HGE
4440 case TYPE_hge:
4441 nils = sub_sht_lng_hge(lft, incr1, rgt, incr2,
4442 dst, GDK_hge_max, cnt,
4443 ci, candoff,
4444 abort_on_error);
4445 break;
4446#endif
4447#ifdef FULL_IMPLEMENTATION
4448 case TYPE_flt:
4449 nils = sub_sht_lng_flt(lft, incr1, rgt, incr2,
4450 dst, GDK_flt_max, cnt,
4451 ci, candoff,
4452 abort_on_error);
4453 break;
4454 case TYPE_dbl:
4455 nils = sub_sht_lng_dbl(lft, incr1, rgt, incr2,
4456 dst, GDK_dbl_max, cnt,
4457 ci, candoff,
4458 abort_on_error);
4459 break;
4460#endif
4461 default:
4462 goto unsupported;
4463 }
4464 break;
4465#ifdef HAVE_HGE
4466 case TYPE_hge:
4467 switch (tp) {
4468 case TYPE_hge:
4469 nils = sub_sht_hge_hge(lft, incr1, rgt, incr2,
4470 dst, GDK_hge_max, cnt,
4471 ci, candoff,
4472 abort_on_error);
4473 break;
4474#ifdef FULL_IMPLEMENTATION
4475 case TYPE_flt:
4476 nils = sub_sht_hge_flt(lft, incr1, rgt, incr2,
4477 dst, GDK_flt_max, cnt,
4478 ci, candoff,
4479 abort_on_error);
4480 break;
4481 case TYPE_dbl:
4482 nils = sub_sht_hge_dbl(lft, incr1, rgt, incr2,
4483 dst, GDK_dbl_max, cnt,
4484 ci, candoff,
4485 abort_on_error);
4486 break;
4487#endif
4488 default:
4489 goto unsupported;
4490 }
4491 break;
4492#endif
4493 case TYPE_flt:
4494 switch (tp) {
4495 case TYPE_flt:
4496 nils = sub_sht_flt_flt(lft, incr1, rgt, incr2,
4497 dst, GDK_flt_max, cnt,
4498 ci, candoff,
4499 abort_on_error);
4500 break;
4501 case TYPE_dbl:
4502 nils = sub_sht_flt_dbl(lft, incr1, rgt, incr2,
4503 dst, GDK_dbl_max, cnt,
4504 ci, candoff,
4505 abort_on_error);
4506 break;
4507 default:
4508 goto unsupported;
4509 }
4510 break;
4511 case TYPE_dbl:
4512 switch (tp) {
4513 case TYPE_dbl:
4514 nils = sub_sht_dbl_dbl(lft, incr1, rgt, incr2,
4515 dst, GDK_dbl_max, cnt,
4516 ci, candoff,
4517 abort_on_error);
4518 break;
4519 default:
4520 goto unsupported;
4521 }
4522 break;
4523 default:
4524 goto unsupported;
4525 }
4526 break;
4527 case TYPE_int:
4528 switch (tp2) {
4529 case TYPE_bte:
4530 switch (tp) {
4531 case TYPE_int:
4532 nils = sub_int_bte_int(lft, incr1, rgt, incr2,
4533 dst, GDK_int_max, cnt,
4534 ci, candoff,
4535 abort_on_error);
4536 break;
4537 case TYPE_lng:
4538 nils = sub_int_bte_lng(lft, incr1, rgt, incr2,
4539 dst, GDK_lng_max, cnt,
4540 ci, candoff,
4541 abort_on_error);
4542 break;
4543#ifdef FULL_IMPLEMENTATION
4544#ifdef HAVE_HGE
4545 case TYPE_hge:
4546 nils = sub_int_bte_hge(lft, incr1, rgt, incr2,
4547 dst, GDK_hge_max, cnt,
4548 ci, candoff,
4549 abort_on_error);
4550 break;
4551#endif
4552 case TYPE_flt:
4553 nils = sub_int_bte_flt(lft, incr1, rgt, incr2,
4554 dst, GDK_flt_max, cnt,
4555 ci, candoff,
4556 abort_on_error);
4557 break;
4558 case TYPE_dbl:
4559 nils = sub_int_bte_dbl(lft, incr1, rgt, incr2,
4560 dst, GDK_dbl_max, cnt,
4561 ci, candoff,
4562 abort_on_error);
4563 break;
4564#endif
4565 default:
4566 goto unsupported;
4567 }
4568 break;
4569 case TYPE_sht:
4570 switch (tp) {
4571 case TYPE_int:
4572 nils = sub_int_sht_int(lft, incr1, rgt, incr2,
4573 dst, GDK_int_max, cnt,
4574 ci, candoff,
4575 abort_on_error);
4576 break;
4577 case TYPE_lng:
4578 nils = sub_int_sht_lng(lft, incr1, rgt, incr2,
4579 dst, GDK_lng_max, cnt,
4580 ci, candoff,
4581 abort_on_error);
4582 break;
4583#ifdef FULL_IMPLEMENTATION
4584#ifdef HAVE_HGE
4585 case TYPE_hge:
4586 nils = sub_int_sht_hge(lft, incr1, rgt, incr2,
4587 dst, GDK_hge_max, cnt,
4588 ci, candoff,
4589 abort_on_error);
4590 break;
4591#endif
4592 case TYPE_flt:
4593 nils = sub_int_sht_flt(lft, incr1, rgt, incr2,
4594 dst, GDK_flt_max, cnt,
4595 ci, candoff,
4596 abort_on_error);
4597 break;
4598 case TYPE_dbl:
4599 nils = sub_int_sht_dbl(lft, incr1, rgt, incr2,
4600 dst, GDK_dbl_max, cnt,
4601 ci, candoff,
4602 abort_on_error);
4603 break;
4604#endif
4605 default:
4606 goto unsupported;
4607 }
4608 break;
4609 case TYPE_int:
4610 switch (tp) {
4611 case TYPE_int:
4612 nils = sub_int_int_int(lft, incr1, rgt, incr2,
4613 dst, GDK_int_max, cnt,
4614 ci, candoff,
4615 abort_on_error);
4616 break;
4617 case TYPE_lng:
4618 nils = sub_int_int_lng(lft, incr1, rgt, incr2,
4619 dst, GDK_lng_max, cnt,
4620 ci, candoff,
4621 abort_on_error);
4622 break;
4623#ifdef FULL_IMPLEMENTATION
4624#ifdef HAVE_HGE
4625 case TYPE_hge:
4626 nils = sub_int_int_hge(lft, incr1, rgt, incr2,
4627 dst, GDK_hge_max, cnt,
4628 ci, candoff,
4629 abort_on_error);
4630 break;
4631#endif
4632 case TYPE_flt:
4633 nils = sub_int_int_flt(lft, incr1, rgt, incr2,
4634 dst, GDK_flt_max, cnt,
4635 ci, candoff,
4636 abort_on_error);
4637 break;
4638 case TYPE_dbl:
4639 nils = sub_int_int_dbl(lft, incr1, rgt, incr2,
4640 dst, GDK_dbl_max, cnt,
4641 ci, candoff,
4642 abort_on_error);
4643 break;
4644#endif
4645 default:
4646 goto unsupported;
4647 }
4648 break;
4649 case TYPE_lng:
4650 switch (tp) {
4651 case TYPE_lng:
4652 nils = sub_int_lng_lng(lft, incr1, rgt, incr2,
4653 dst, GDK_lng_max, cnt,
4654 ci, candoff,
4655 abort_on_error);
4656 break;
4657#ifdef HAVE_HGE
4658 case TYPE_hge:
4659 nils = sub_int_lng_hge(lft, incr1, rgt, incr2,
4660 dst, GDK_hge_max, cnt,
4661 ci, candoff,
4662 abort_on_error);
4663 break;
4664#endif
4665#ifdef FULL_IMPLEMENTATION
4666 case TYPE_flt:
4667 nils = sub_int_lng_flt(lft, incr1, rgt, incr2,
4668 dst, GDK_flt_max, cnt,
4669 ci, candoff,
4670 abort_on_error);
4671 break;
4672 case TYPE_dbl:
4673 nils = sub_int_lng_dbl(lft, incr1, rgt, incr2,
4674 dst, GDK_dbl_max, cnt,
4675 ci, candoff,
4676 abort_on_error);
4677 break;
4678#endif
4679 default:
4680 goto unsupported;
4681 }
4682 break;
4683#ifdef HAVE_HGE
4684 case TYPE_hge:
4685 switch (tp) {
4686 case TYPE_hge:
4687 nils = sub_int_hge_hge(lft, incr1, rgt, incr2,
4688 dst, GDK_hge_max, cnt,
4689 ci, candoff,
4690 abort_on_error);
4691 break;
4692#ifdef FULL_IMPLEMENTATION
4693 case TYPE_flt:
4694 nils = sub_int_hge_flt(lft, incr1, rgt, incr2,
4695 dst, GDK_flt_max, cnt,
4696 ci, candoff,
4697 abort_on_error);
4698 break;
4699 case TYPE_dbl:
4700 nils = sub_int_hge_dbl(lft, incr1, rgt, incr2,
4701 dst, GDK_dbl_max, cnt,
4702 ci, candoff,
4703 abort_on_error);
4704 break;
4705#endif
4706 default:
4707 goto unsupported;
4708 }
4709 break;
4710#endif
4711 case TYPE_flt:
4712 switch (tp) {
4713 case TYPE_flt:
4714 nils = sub_int_flt_flt(lft, incr1, rgt, incr2,
4715 dst, GDK_flt_max, cnt,
4716 ci, candoff,
4717 abort_on_error);
4718 break;
4719 case TYPE_dbl:
4720 nils = sub_int_flt_dbl(lft, incr1, rgt, incr2,
4721 dst, GDK_dbl_max, cnt,
4722 ci, candoff,
4723 abort_on_error);
4724 break;
4725 default:
4726 goto unsupported;
4727 }
4728 break;
4729 case TYPE_dbl:
4730 switch (tp) {
4731 case TYPE_dbl:
4732 nils = sub_int_dbl_dbl(lft, incr1, rgt, incr2,
4733 dst, GDK_dbl_max, cnt,
4734 ci, candoff,
4735 abort_on_error);
4736 break;
4737 default:
4738 goto unsupported;
4739 }
4740 break;
4741 default:
4742 goto unsupported;
4743 }
4744 break;
4745 case TYPE_lng:
4746 switch (tp2) {
4747 case TYPE_bte:
4748 switch (tp) {
4749 case TYPE_lng:
4750 nils = sub_lng_bte_lng(lft, incr1, rgt, incr2,
4751 dst, GDK_lng_max, cnt,
4752 ci, candoff,
4753 abort_on_error);
4754 break;
4755#ifdef HAVE_HGE
4756 case TYPE_hge:
4757 nils = sub_lng_bte_hge(lft, incr1, rgt, incr2,
4758 dst, GDK_hge_max, cnt,
4759 ci, candoff,
4760 abort_on_error);
4761 break;
4762#endif
4763#ifdef FULL_IMPLEMENTATION
4764 case TYPE_flt:
4765 nils = sub_lng_bte_flt(lft, incr1, rgt, incr2,
4766 dst, GDK_flt_max, cnt,
4767 ci, candoff,
4768 abort_on_error);
4769 break;
4770 case TYPE_dbl:
4771 nils = sub_lng_bte_dbl(lft, incr1, rgt, incr2,
4772 dst, GDK_dbl_max, cnt,
4773 ci, candoff,
4774 abort_on_error);
4775 break;
4776#endif
4777 default:
4778 goto unsupported;
4779 }
4780 break;
4781 case TYPE_sht:
4782 switch (tp) {
4783 case TYPE_lng:
4784 nils = sub_lng_sht_lng(lft, incr1, rgt, incr2,
4785 dst, GDK_lng_max, cnt,
4786 ci, candoff,
4787 abort_on_error);
4788 break;
4789#ifdef HAVE_HGE
4790 case TYPE_hge:
4791 nils = sub_lng_sht_hge(lft, incr1, rgt, incr2,
4792 dst, GDK_hge_max, cnt,
4793 ci, candoff,
4794 abort_on_error);
4795 break;
4796#endif
4797#ifdef FULL_IMPLEMENTATION
4798 case TYPE_flt:
4799 nils = sub_lng_sht_flt(lft, incr1, rgt, incr2,
4800 dst, GDK_flt_max, cnt,
4801 ci, candoff,
4802 abort_on_error);
4803 break;
4804 case TYPE_dbl:
4805 nils = sub_lng_sht_dbl(lft, incr1, rgt, incr2,
4806 dst, GDK_dbl_max, cnt,
4807 ci, candoff,
4808 abort_on_error);
4809 break;
4810#endif
4811 default:
4812 goto unsupported;
4813 }
4814 break;
4815 case TYPE_int:
4816 switch (tp) {
4817 case TYPE_lng:
4818 nils = sub_lng_int_lng(lft, incr1, rgt, incr2,
4819 dst, GDK_lng_max, cnt,
4820 ci, candoff,
4821 abort_on_error);
4822 break;
4823#ifdef HAVE_HGE
4824 case TYPE_hge:
4825 nils = sub_lng_int_hge(lft, incr1, rgt, incr2,
4826 dst, GDK_hge_max, cnt,
4827 ci, candoff,
4828 abort_on_error);
4829 break;
4830#endif
4831#ifdef FULL_IMPLEMENTATION
4832 case TYPE_flt:
4833 nils = sub_lng_int_flt(lft, incr1, rgt, incr2,
4834 dst, GDK_flt_max, cnt,
4835 ci, candoff,
4836 abort_on_error);
4837 break;
4838 case TYPE_dbl:
4839 nils = sub_lng_int_dbl(lft, incr1, rgt, incr2,
4840 dst, GDK_dbl_max, cnt,
4841 ci, candoff,
4842 abort_on_error);
4843 break;
4844#endif
4845 default:
4846 goto unsupported;
4847 }
4848 break;
4849 case TYPE_lng:
4850 switch (tp) {
4851 case TYPE_lng:
4852 nils = sub_lng_lng_lng(lft, incr1, rgt, incr2,
4853 dst, GDK_lng_max, cnt,
4854 ci, candoff,
4855 abort_on_error);
4856 break;
4857#ifdef HAVE_HGE
4858 case TYPE_hge:
4859 nils = sub_lng_lng_hge(lft, incr1, rgt, incr2,
4860 dst, GDK_hge_max, cnt,
4861 ci, candoff,
4862 abort_on_error);
4863 break;
4864#endif
4865#ifdef FULL_IMPLEMENTATION
4866 case TYPE_flt:
4867 nils = sub_lng_lng_flt(lft, incr1, rgt, incr2,
4868 dst, GDK_flt_max, cnt,
4869 ci, candoff,
4870 abort_on_error);
4871 break;
4872 case TYPE_dbl:
4873 nils = sub_lng_lng_dbl(lft, incr1, rgt, incr2,
4874 dst, GDK_dbl_max, cnt,
4875 ci, candoff,
4876 abort_on_error);
4877 break;
4878#endif
4879 default:
4880 goto unsupported;
4881 }
4882 break;
4883#ifdef HAVE_HGE
4884 case TYPE_hge:
4885 switch (tp) {
4886 case TYPE_hge:
4887 nils = sub_lng_hge_hge(lft, incr1, rgt, incr2,
4888 dst, GDK_hge_max, cnt,
4889 ci, candoff,
4890 abort_on_error);
4891 break;
4892#ifdef FULL_IMPLEMENTATION
4893 case TYPE_flt:
4894 nils = sub_lng_hge_flt(lft, incr1, rgt, incr2,
4895 dst, GDK_flt_max, cnt,
4896 ci, candoff,
4897 abort_on_error);
4898 break;
4899 case TYPE_dbl:
4900 nils = sub_lng_hge_dbl(lft, incr1, rgt, incr2,
4901 dst, GDK_dbl_max, cnt,
4902 ci, candoff,
4903 abort_on_error);
4904 break;
4905#endif
4906 default:
4907 goto unsupported;
4908 }
4909 break;
4910#endif
4911 case TYPE_flt:
4912 switch (tp) {
4913 case TYPE_flt:
4914 nils = sub_lng_flt_flt(lft, incr1, rgt, incr2,
4915 dst, GDK_flt_max, cnt,
4916 ci, candoff,
4917 abort_on_error);
4918 break;
4919 case TYPE_dbl:
4920 nils = sub_lng_flt_dbl(lft, incr1, rgt, incr2,
4921 dst, GDK_dbl_max, cnt,
4922 ci, candoff,
4923 abort_on_error);
4924 break;
4925 default:
4926 goto unsupported;
4927 }
4928 break;
4929 case TYPE_dbl:
4930 switch (tp) {
4931 case TYPE_dbl:
4932 nils = sub_lng_dbl_dbl(lft, incr1, rgt, incr2,
4933 dst, GDK_dbl_max, cnt,
4934 ci, candoff,
4935 abort_on_error);
4936 break;
4937 default:
4938 goto unsupported;
4939 }
4940 break;
4941 default:
4942 goto unsupported;
4943 }
4944 break;
4945#ifdef HAVE_HGE
4946 case TYPE_hge:
4947 switch (tp2) {
4948 case TYPE_bte:
4949 switch (tp) {
4950 case TYPE_hge:
4951 nils = sub_hge_bte_hge(lft, incr1, rgt, incr2,
4952 dst, GDK_hge_max, cnt,
4953 ci, candoff,
4954 abort_on_error);
4955 break;
4956#ifdef FULL_IMPLEMENTATION
4957 case TYPE_flt:
4958 nils = sub_hge_bte_flt(lft, incr1, rgt, incr2,
4959 dst, GDK_flt_max, cnt,
4960 ci, candoff,
4961 abort_on_error);
4962 break;
4963 case TYPE_dbl:
4964 nils = sub_hge_bte_dbl(lft, incr1, rgt, incr2,
4965 dst, GDK_dbl_max, cnt,
4966 ci, candoff,
4967 abort_on_error);
4968 break;
4969#endif
4970 default:
4971 goto unsupported;
4972 }
4973 break;
4974 case TYPE_sht:
4975 switch (tp) {
4976 case TYPE_hge:
4977 nils = sub_hge_sht_hge(lft, incr1, rgt, incr2,
4978 dst, GDK_hge_max, cnt,
4979 ci, candoff,
4980 abort_on_error);
4981 break;
4982#ifdef FULL_IMPLEMENTATION
4983 case TYPE_flt:
4984 nils = sub_hge_sht_flt(lft, incr1, rgt, incr2,
4985 dst, GDK_flt_max, cnt,
4986 ci, candoff,
4987 abort_on_error);
4988 break;
4989 case TYPE_dbl:
4990 nils = sub_hge_sht_dbl(lft, incr1, rgt, incr2,
4991 dst, GDK_dbl_max, cnt,
4992 ci, candoff,
4993 abort_on_error);
4994 break;
4995#endif
4996 default:
4997 goto unsupported;
4998 }
4999 break;
5000 case TYPE_int:
5001 switch (tp) {
5002 case TYPE_hge:
5003 nils = sub_hge_int_hge(lft, incr1, rgt, incr2,
5004 dst, GDK_hge_max, cnt,
5005 ci, candoff,
5006 abort_on_error);
5007 break;
5008#ifdef FULL_IMPLEMENTATION
5009 case TYPE_flt:
5010 nils = sub_hge_int_flt(lft, incr1, rgt, incr2,
5011 dst, GDK_flt_max, cnt,
5012 ci, candoff,
5013 abort_on_error);
5014 break;
5015 case TYPE_dbl:
5016 nils = sub_hge_int_dbl(lft, incr1, rgt, incr2,
5017 dst, GDK_dbl_max, cnt,
5018 ci, candoff,
5019 abort_on_error);
5020 break;
5021#endif
5022 default:
5023 goto unsupported;
5024 }
5025 break;
5026 case TYPE_lng:
5027 switch (tp) {
5028 case TYPE_hge:
5029 nils = sub_hge_lng_hge(lft, incr1, rgt, incr2,
5030 dst, GDK_hge_max, cnt,
5031 ci, candoff,
5032 abort_on_error);
5033 break;
5034#ifdef FULL_IMPLEMENTATION
5035 case TYPE_flt:
5036 nils = sub_hge_lng_flt(lft, incr1, rgt, incr2,
5037 dst, GDK_flt_max, cnt,
5038 ci, candoff,
5039 abort_on_error);
5040 break;
5041 case TYPE_dbl:
5042 nils = sub_hge_lng_dbl(lft, incr1, rgt, incr2,
5043 dst, GDK_dbl_max, cnt,
5044 ci, candoff,
5045 abort_on_error);
5046 break;
5047#endif
5048 default:
5049 goto unsupported;
5050 }
5051 break;
5052 case TYPE_hge:
5053 switch (tp) {
5054 case TYPE_hge:
5055 nils = sub_hge_hge_hge(lft, incr1, rgt, incr2,
5056 dst, GDK_hge_max, cnt,
5057 ci, candoff,
5058 abort_on_error);
5059 break;
5060#ifdef FULL_IMPLEMENTATION
5061 case TYPE_flt:
5062 nils = sub_hge_hge_flt(lft, incr1, rgt, incr2,
5063 dst, GDK_flt_max, cnt,
5064 ci, candoff,
5065 abort_on_error);
5066 break;
5067 case TYPE_dbl:
5068 nils = sub_hge_hge_dbl(lft, incr1, rgt, incr2,
5069 dst, GDK_dbl_max, cnt,
5070 ci, candoff,
5071 abort_on_error);
5072 break;
5073#endif
5074 default:
5075 goto unsupported;
5076 }
5077 break;
5078 case TYPE_flt:
5079 switch (tp) {
5080 case TYPE_flt:
5081 nils = sub_hge_flt_flt(lft, incr1, rgt, incr2,
5082 dst, GDK_flt_max, cnt,
5083 ci, candoff,
5084 abort_on_error);
5085 break;
5086 case TYPE_dbl:
5087 nils = sub_hge_flt_dbl(lft, incr1, rgt, incr2,
5088 dst, GDK_dbl_max, cnt,
5089 ci, candoff,
5090 abort_on_error);
5091 break;
5092 default:
5093 goto unsupported;
5094 }
5095 break;
5096 case TYPE_dbl:
5097 switch (tp) {
5098 case TYPE_dbl:
5099 nils = sub_hge_dbl_dbl(lft, incr1, rgt, incr2,
5100 dst, GDK_dbl_max, cnt,
5101 ci, candoff,
5102 abort_on_error);
5103 break;
5104 default:
5105 goto unsupported;
5106 }
5107 break;
5108 default:
5109 goto unsupported;
5110 }
5111 break;
5112#endif
5113 case TYPE_flt:
5114 switch (tp2) {
5115 case TYPE_bte:
5116 switch (tp) {
5117 case TYPE_flt:
5118 nils = sub_flt_bte_flt(lft, incr1, rgt, incr2,
5119 dst, GDK_flt_max, cnt,
5120 ci, candoff,
5121 abort_on_error);
5122 break;
5123 case TYPE_dbl:
5124 nils = sub_flt_bte_dbl(lft, incr1, rgt, incr2,
5125 dst, GDK_dbl_max, cnt,
5126 ci, candoff,
5127 abort_on_error);
5128 break;
5129 default:
5130 goto unsupported;
5131 }
5132 break;
5133 case TYPE_sht:
5134 switch (tp) {
5135 case TYPE_flt:
5136 nils = sub_flt_sht_flt(lft, incr1, rgt, incr2,
5137 dst, GDK_flt_max, cnt,
5138 ci, candoff,
5139 abort_on_error);
5140 break;
5141 case TYPE_dbl:
5142 nils = sub_flt_sht_dbl(lft, incr1, rgt, incr2,
5143 dst, GDK_dbl_max, cnt,
5144 ci, candoff,
5145 abort_on_error);
5146 break;
5147 default:
5148 goto unsupported;
5149 }
5150 break;
5151 case TYPE_int:
5152 switch (tp) {
5153 case TYPE_flt:
5154 nils = sub_flt_int_flt(lft, incr1, rgt, incr2,
5155 dst, GDK_flt_max, cnt,
5156 ci, candoff,
5157 abort_on_error);
5158 break;
5159 case TYPE_dbl:
5160 nils = sub_flt_int_dbl(lft, incr1, rgt, incr2,
5161 dst, GDK_dbl_max, cnt,
5162 ci, candoff,
5163 abort_on_error);
5164 break;
5165 default:
5166 goto unsupported;
5167 }
5168 break;
5169 case TYPE_lng:
5170 switch (tp) {
5171 case TYPE_flt:
5172 nils = sub_flt_lng_flt(lft, incr1, rgt, incr2,
5173 dst, GDK_flt_max, cnt,
5174 ci, candoff,
5175 abort_on_error);
5176 break;
5177 case TYPE_dbl:
5178 nils = sub_flt_lng_dbl(lft, incr1, rgt, incr2,
5179 dst, GDK_dbl_max, cnt,
5180 ci, candoff,
5181 abort_on_error);
5182 break;
5183 default:
5184 goto unsupported;
5185 }
5186 break;
5187#ifdef HAVE_HGE
5188 case TYPE_hge:
5189 switch (tp) {
5190 case TYPE_flt:
5191 nils = sub_flt_hge_flt(lft, incr1, rgt, incr2,
5192 dst, GDK_flt_max, cnt,
5193 ci, candoff,
5194 abort_on_error);
5195 break;
5196 case TYPE_dbl:
5197 nils = sub_flt_hge_dbl(lft, incr1, rgt, incr2,
5198 dst, GDK_dbl_max, cnt,
5199 ci, candoff,
5200 abort_on_error);
5201 break;
5202 default:
5203 goto unsupported;
5204 }
5205 break;
5206#endif
5207 case TYPE_flt:
5208 switch (tp) {
5209 case TYPE_flt:
5210 nils = sub_flt_flt_flt(lft, incr1, rgt, incr2,
5211 dst, GDK_flt_max, cnt,
5212 ci, candoff,
5213 abort_on_error);
5214 break;
5215 case TYPE_dbl:
5216 nils = sub_flt_flt_dbl(lft, incr1, rgt, incr2,
5217 dst, GDK_dbl_max, cnt,
5218 ci, candoff,
5219 abort_on_error);
5220 break;
5221 default:
5222 goto unsupported;
5223 }
5224 break;
5225 case TYPE_dbl:
5226 switch (tp) {
5227 case TYPE_dbl:
5228 nils = sub_flt_dbl_dbl(lft, incr1, rgt, incr2,
5229 dst, GDK_dbl_max, cnt,
5230 ci, candoff,
5231 abort_on_error);
5232 break;
5233 default:
5234 goto unsupported;
5235 }
5236 break;
5237 default:
5238 goto unsupported;
5239 }
5240 break;
5241 case TYPE_dbl:
5242 switch (tp2) {
5243 case TYPE_bte:
5244 switch (tp) {
5245 case TYPE_dbl:
5246 nils = sub_dbl_bte_dbl(lft, incr1, rgt, incr2,
5247 dst, GDK_dbl_max, cnt,
5248 ci, candoff,
5249 abort_on_error);
5250 break;
5251 default:
5252 goto unsupported;
5253 }
5254 break;
5255 case TYPE_sht:
5256 switch (tp) {
5257 case TYPE_dbl:
5258 nils = sub_dbl_sht_dbl(lft, incr1, rgt, incr2,
5259 dst, GDK_dbl_max, cnt,
5260 ci, candoff,
5261 abort_on_error);
5262 break;
5263 default:
5264 goto unsupported;
5265 }
5266 break;
5267 case TYPE_int:
5268 switch (tp) {
5269 case TYPE_dbl:
5270 nils = sub_dbl_int_dbl(lft, incr1, rgt, incr2,
5271 dst, GDK_dbl_max, cnt,
5272 ci, candoff,
5273 abort_on_error);
5274 break;
5275 default:
5276 goto unsupported;
5277 }
5278 break;
5279 case TYPE_lng:
5280 switch (tp) {
5281 case TYPE_dbl:
5282 nils = sub_dbl_lng_dbl(lft, incr1, rgt, incr2,
5283 dst, GDK_dbl_max, cnt,
5284 ci, candoff,
5285 abort_on_error);
5286 break;
5287 default:
5288 goto unsupported;
5289 }
5290 break;
5291#ifdef HAVE_HGE
5292 case TYPE_hge:
5293 switch (tp) {
5294 case TYPE_dbl:
5295 nils = sub_dbl_hge_dbl(lft, incr1, rgt, incr2,
5296 dst, GDK_dbl_max, cnt,
5297 ci, candoff,
5298 abort_on_error);
5299 break;
5300 default:
5301 goto unsupported;
5302 }
5303 break;
5304#endif
5305 case TYPE_flt:
5306 switch (tp) {
5307 case TYPE_dbl:
5308 nils = sub_dbl_flt_dbl(lft, incr1, rgt, incr2,
5309 dst, GDK_dbl_max, cnt,
5310 ci, candoff,
5311 abort_on_error);
5312 break;
5313 default:
5314 goto unsupported;
5315 }
5316 break;
5317 case TYPE_dbl:
5318 switch (tp) {
5319 case TYPE_dbl:
5320 nils = sub_dbl_dbl_dbl(lft, incr1, rgt, incr2,
5321 dst, GDK_dbl_max, cnt,
5322 ci, candoff,
5323 abort_on_error);
5324 break;
5325 default:
5326 goto unsupported;
5327 }
5328 break;
5329 default:
5330 goto unsupported;
5331 }
5332 break;
5333 default:
5334 goto unsupported;
5335 }
5336
5337 return nils;
5338
5339 unsupported:
5340 GDKerror("%s: type combination (sub(%s,%s)->%s) not supported.\n",
5341 func, ATOMname(tp1), ATOMname(tp2), ATOMname(tp));
5342 return BUN_NONE;
5343}
5344
5345BAT *
5346BATcalcsub(BAT *b1, BAT *b2, BAT *s, int tp, bool abort_on_error)
5347{
5348 BAT *bn;
5349 BUN nils;
5350 BUN cnt, ncand;
5351 struct canditer ci;
5352
5353 BATcheck(b1, __func__, NULL);
5354 BATcheck(b2, __func__, NULL);
5355
5356 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
5357 return NULL;
5358
5359 cnt = BATcount(b1);
5360 ncand = canditer_init(&ci, b1, s);
5361 if (ncand == 0)
5362 return BATconstant(b1->hseqbase, tp, ATOMnilptr(tp),
5363 cnt, TRANSIENT);
5364
5365 bn = COLnew(b1->hseqbase, tp, cnt, TRANSIENT);
5366 if (bn == NULL)
5367 return NULL;
5368
5369 nils = sub_typeswitchloop(Tloc(b1, 0), b1->ttype, 1,
5370 Tloc(b2, 0), b2->ttype, 1,
5371 Tloc(bn, 0), tp,
5372 cnt, &ci, b1->hseqbase,
5373 abort_on_error, __func__);
5374
5375 if (nils == BUN_NONE) {
5376 BBPunfix(bn->batCacheid);
5377 return NULL;
5378 }
5379
5380 BATsetcount(bn, cnt);
5381
5382 bn->tsorted = cnt <= 1 || nils == cnt;
5383 bn->trevsorted = cnt <= 1 || nils == cnt;
5384 bn->tkey = cnt <= 1;
5385 bn->tnil = nils != 0;
5386 bn->tnonil = nils == 0;
5387
5388 return bn;
5389}
5390
5391BAT *
5392BATcalcsubcst(BAT *b, const ValRecord *v, BAT *s, int tp, bool abort_on_error)
5393{
5394 BAT *bn;
5395 BUN nils;
5396 BUN cnt, ncand;
5397 struct canditer ci;
5398
5399 BATcheck(b, __func__, NULL);
5400
5401 cnt = BATcount(b);
5402 ncand = canditer_init(&ci, b, s);
5403 if (ncand == 0)
5404 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
5405 cnt, TRANSIENT);
5406
5407 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
5408 if (bn == NULL)
5409 return NULL;
5410
5411 nils = sub_typeswitchloop(Tloc(b, 0), b->ttype, 1,
5412 VALptr(v), v->vtype, 0,
5413 Tloc(bn, 0), tp,
5414 cnt, &ci, b->hseqbase,
5415 abort_on_error, __func__);
5416
5417 if (nils == BUN_NONE) {
5418 BBPunfix(bn->batCacheid);
5419 return NULL;
5420 }
5421
5422 BATsetcount(bn, cnt);
5423
5424 /* if the input is sorted, and no overflow occurred (we only
5425 * know for sure if abort_on_error is set), the result is also
5426 * sorted */
5427 bn->tsorted = (abort_on_error && b->tsorted && nils == 0) ||
5428 cnt <= 1 || nils == cnt;
5429 bn->trevsorted = (abort_on_error && b->trevsorted && nils == 0) ||
5430 cnt <= 1 || nils == cnt;
5431 bn->tkey = cnt <= 1;
5432 bn->tnil = nils != 0;
5433 bn->tnonil = nils == 0;
5434
5435 return bn;
5436}
5437
5438BAT *
5439BATcalccstsub(const ValRecord *v, BAT *b, BAT *s, int tp, bool abort_on_error)
5440{
5441 BAT *bn;
5442 BUN nils;
5443 BUN cnt, ncand;
5444 struct canditer ci;
5445
5446 BATcheck(b, __func__, NULL);
5447
5448 cnt = BATcount(b);
5449 ncand = canditer_init(&ci, b, s);
5450 if (ncand == 0)
5451 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
5452 cnt, TRANSIENT);
5453
5454 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
5455 if (bn == NULL)
5456 return NULL;
5457
5458 nils = sub_typeswitchloop(VALptr(v), v->vtype, 0,
5459 Tloc(b, 0), b->ttype, 1,
5460 Tloc(bn, 0), tp,
5461 cnt, &ci, b->hseqbase,
5462 abort_on_error, __func__);
5463
5464 if (nils == BUN_NONE) {
5465 BBPunfix(bn->batCacheid);
5466 return NULL;
5467 }
5468
5469 BATsetcount(bn, cnt);
5470
5471 /* if the input is sorted, and no overflow occurred (we only
5472 * know for sure if abort_on_error is set), the result is
5473 * sorted in the opposite direction (except that NILs mess
5474 * things up */
5475 bn->tsorted = (abort_on_error && nils == 0 && b->trevsorted) ||
5476 cnt <= 1 || nils == cnt;
5477 bn->trevsorted = (abort_on_error && nils == 0 && b->tsorted) ||
5478 cnt <= 1 || nils == cnt;
5479 bn->tkey = cnt <= 1;
5480 bn->tnil = nils != 0;
5481 bn->tnonil = nils == 0;
5482
5483 return bn;
5484}
5485
5486gdk_return
5487VARcalcsub(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
5488 bool abort_on_error)
5489{
5490 if (sub_typeswitchloop(VALptr(lft), lft->vtype, 0,
5491 VALptr(rgt), rgt->vtype, 0,
5492 VALget(ret), ret->vtype, 1,
5493 &(struct canditer){.tpe=cand_dense, .ncand=1},
5494 0, abort_on_error, __func__) == BUN_NONE)
5495 return GDK_FAIL;
5496 return GDK_SUCCEED;
5497}
5498
5499BAT *
5500BATcalcdecr(BAT *b, BAT *s, bool abort_on_error)
5501{
5502 return BATcalcincrdecr(b, s, abort_on_error, sub_typeswitchloop,
5503 __func__);
5504}
5505
5506gdk_return
5507VARcalcdecr(ValPtr ret, const ValRecord *v, bool abort_on_error)
5508{
5509 if (sub_typeswitchloop(VALptr(v), v->vtype, 0,
5510 &(bte){1}, TYPE_bte, 0,
5511 VALget(ret), ret->vtype, 1,
5512 &(struct canditer){.tpe=cand_dense, .ncand=1},
5513 0, abort_on_error, __func__) == BUN_NONE)
5514 return GDK_FAIL;
5515 return GDK_SUCCEED;
5516}
5517
5518/* ---------------------------------------------------------------------- */
5519/* multiplication (any numeric type) */
5520
5521/* TYPE4 must be a type larger than both TYPE1 and TYPE2 so that
5522 * multiplying into it doesn't cause overflow */
5523#define MUL_4TYPE(TYPE1, TYPE2, TYPE3, TYPE4, IF) \
5524static BUN \
5525mul_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
5526 const TYPE2 *rgt, int incr2, \
5527 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
5528 struct canditer *restrict ci, \
5529 oid candoff, bool abort_on_error) \
5530{ \
5531 oid x = canditer_next(ci) - candoff; \
5532 BUN i, j, k = 0; \
5533 BUN nils = 0; \
5534 \
5535 do { \
5536 while (k < x) { \
5537 dst[k++] = TYPE3##_nil; \
5538 nils++; \
5539 } \
5540 i = x * incr1; \
5541 j = x * incr2; \
5542 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
5543 dst[k] = TYPE3##_nil; \
5544 nils++; \
5545 } else { \
5546 MUL##IF##4_WITH_CHECK(lft[i], rgt[j], \
5547 TYPE3, dst[k], \
5548 max, \
5549 TYPE4, \
5550 ON_OVERFLOW(TYPE1, TYPE2, "*")); \
5551 } \
5552 k++; \
5553 x = canditer_next(ci); \
5554 if (is_oid_nil(x)) \
5555 break; \
5556 x -= candoff; \
5557 } while (k < cnt); \
5558 while (k < cnt) { \
5559 dst[k++] = TYPE3##_nil; \
5560 nils++; \
5561 } \
5562 return nils; \
5563}
5564
5565#define MUL_3TYPE_enlarge(TYPE1, TYPE2, TYPE3, IF) \
5566static BUN \
5567mul_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
5568 const TYPE2 *rgt, int incr2, \
5569 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
5570 struct canditer *restrict ci, \
5571 oid candoff, bool abort_on_error) \
5572{ \
5573 oid x = canditer_next(ci) - candoff; \
5574 BUN i, j, k = 0; \
5575 BUN nils = 0; \
5576 const bool couldoverflow = (max < (TYPE3) GDK_##TYPE1##_max * (TYPE3) GDK_##TYPE2##_max); \
5577 \
5578 do { \
5579 while (k < x) { \
5580 dst[k++] = TYPE3##_nil; \
5581 nils++; \
5582 } \
5583 i = x * incr1; \
5584 j = x * incr2; \
5585 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
5586 dst[k] = TYPE3##_nil; \
5587 nils++; \
5588 } else if (couldoverflow) { \
5589 MUL##IF##4_WITH_CHECK(lft[i], rgt[j], \
5590 TYPE3, dst[k], \
5591 max, \
5592 TYPE3, \
5593 ON_OVERFLOW(TYPE1, TYPE2, "*")); \
5594 } else { \
5595 dst[k] = (TYPE3) lft[i] * rgt[j]; \
5596 } \
5597 k++; \
5598 x = canditer_next(ci); \
5599 if (is_oid_nil(x)) \
5600 break; \
5601 x -= candoff; \
5602 } while (k < cnt); \
5603 while (k < cnt) { \
5604 dst[k++] = TYPE3##_nil; \
5605 nils++; \
5606 } \
5607 return nils; \
5608}
5609
5610#ifdef HAVE_HGE
5611
5612#define MUL_2TYPE_lng(TYPE1, TYPE2) MUL_4TYPE(TYPE1, TYPE2, lng, hge, I)
5613
5614#define MUL_2TYPE_hge(TYPE1, TYPE2) \
5615static BUN \
5616mul_##TYPE1##_##TYPE2##_hge(const TYPE1 *lft, int incr1, \
5617 const TYPE2 *rgt, int incr2, \
5618 hge *restrict dst, hge max, BUN cnt, \
5619 struct canditer *restrict ci, \
5620 oid candoff, bool abort_on_error) \
5621{ \
5622 oid x = canditer_next(ci) - candoff; \
5623 BUN i, j, k = 0; \
5624 BUN nils = 0; \
5625 \
5626 do { \
5627 while (k < x) { \
5628 dst[k++] = hge_nil; \
5629 nils++; \
5630 } \
5631 i = x * incr1; \
5632 j = x * incr2; \
5633 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
5634 dst[k] = hge_nil; \
5635 nils++; \
5636 } else { \
5637 HGEMUL_CHECK(lft[i], rgt[j], \
5638 dst[k], \
5639 max, \
5640 ON_OVERFLOW(TYPE1, TYPE2, "*")); \
5641 } \
5642 k++; \
5643 x = canditer_next(ci); \
5644 if (is_oid_nil(x)) \
5645 break; \
5646 x -= candoff; \
5647 } while (k < cnt); \
5648 while (k < cnt) { \
5649 dst[k++] = hge_nil; \
5650 nils++; \
5651 } \
5652 return nils; \
5653}
5654
5655#else
5656
5657#define MUL_2TYPE_lng(TYPE1, TYPE2) \
5658static BUN \
5659mul_##TYPE1##_##TYPE2##_lng(const TYPE1 *lft, int incr1, \
5660 const TYPE2 *rgt, int incr2, \
5661 lng *restrict dst, lng max, BUN cnt, \
5662 struct canditer *restrict ci, \
5663 oid candoff, bool abort_on_error) \
5664{ \
5665 oid x = canditer_next(ci) - candoff; \
5666 BUN i, j, k = 0; \
5667 BUN nils = 0; \
5668 \
5669 do { \
5670 while (k < x) { \
5671 dst[k++] = lng_nil; \
5672 nils++; \
5673 } \
5674 i = x * incr1; \
5675 j = x * incr2; \
5676 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
5677 dst[k] = lng_nil; \
5678 nils++; \
5679 } else { \
5680 LNGMUL_CHECK(lft[i], rgt[j], \
5681 dst[k], \
5682 max, \
5683 ON_OVERFLOW(TYPE1, TYPE2, "*")); \
5684 } \
5685 k++; \
5686 x = canditer_next(ci); \
5687 if (is_oid_nil(x)) \
5688 break; \
5689 x -= candoff; \
5690 } while (k < cnt); \
5691 while (k < cnt) { \
5692 dst[k++] = lng_nil; \
5693 nils++; \
5694 } \
5695 return nils; \
5696}
5697
5698#endif
5699
5700#define MUL_2TYPE_float(TYPE1, TYPE2, TYPE3) \
5701static BUN \
5702mul_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
5703 const TYPE2 *rgt, int incr2, \
5704 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
5705 struct canditer *restrict ci, \
5706 oid candoff, bool abort_on_error) \
5707{ \
5708 oid x = canditer_next(ci) - candoff; \
5709 BUN i, j, k = 0; \
5710 BUN nils = 0; \
5711 \
5712 do { \
5713 while (k < x) { \
5714 dst[k++] = TYPE3##_nil; \
5715 nils++; \
5716 } \
5717 i = x * incr1; \
5718 j = x * incr2; \
5719 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
5720 dst[k] = TYPE3##_nil; \
5721 nils++; \
5722 } else { \
5723 /* only check for overflow, not for underflow */ \
5724 dst[k] = (TYPE3) (lft[i] * rgt[j]); \
5725 if (isinf(dst[k]) || ABSOLUTE(dst[k]) > max) { \
5726 if (abort_on_error) \
5727 ON_OVERFLOW(TYPE1, TYPE2, "*"); \
5728 dst[k] = TYPE3##_nil; \
5729 nils++; \
5730 } \
5731 } \
5732 k++; \
5733 x = canditer_next(ci); \
5734 if (is_oid_nil(x)) \
5735 break; \
5736 x -= candoff; \
5737 } while (k < cnt); \
5738 while (k < cnt) { \
5739 dst[k++] = TYPE3##_nil; \
5740 nils++; \
5741 } \
5742 return nils; \
5743}
5744
5745MUL_4TYPE(bte, bte, bte, sht, I)
5746MUL_3TYPE_enlarge(bte, bte, sht, I)
5747#ifdef FULL_IMPLEMENTATION
5748MUL_3TYPE_enlarge(bte, bte, int, I)
5749MUL_3TYPE_enlarge(bte, bte, lng, I)
5750#ifdef HAVE_HGE
5751MUL_3TYPE_enlarge(bte, bte, hge, I)
5752#endif
5753MUL_3TYPE_enlarge(bte, bte, flt, F)
5754MUL_3TYPE_enlarge(bte, bte, dbl, F)
5755#endif
5756MUL_4TYPE(bte, sht, sht, int, I)
5757MUL_3TYPE_enlarge(bte, sht, int, I)
5758#ifdef FULL_IMPLEMENTATION
5759MUL_3TYPE_enlarge(bte, sht, lng, I)
5760#ifdef HAVE_HGE
5761MUL_3TYPE_enlarge(bte, sht, hge, I)
5762#endif
5763MUL_3TYPE_enlarge(bte, sht, flt, F)
5764MUL_3TYPE_enlarge(bte, sht, dbl, F)
5765#endif
5766MUL_4TYPE(bte, int, int, lng, I)
5767MUL_3TYPE_enlarge(bte, int, lng, I)
5768#ifdef FULL_IMPLEMENTATION
5769#ifdef HAVE_HGE
5770MUL_3TYPE_enlarge(bte, int, hge, I)
5771#endif
5772MUL_3TYPE_enlarge(bte, int, flt, F)
5773MUL_3TYPE_enlarge(bte, int, dbl, F)
5774#endif
5775MUL_2TYPE_lng(bte, lng)
5776#ifdef HAVE_HGE
5777MUL_3TYPE_enlarge(bte, lng, hge, I)
5778#endif
5779#ifdef FULL_IMPLEMENTATION
5780MUL_3TYPE_enlarge(bte, lng, flt, F)
5781MUL_3TYPE_enlarge(bte, lng, dbl, F)
5782#endif
5783#ifdef HAVE_HGE
5784MUL_2TYPE_hge(bte, hge)
5785#ifdef FULL_IMPLEMENTATION
5786MUL_3TYPE_enlarge(bte, hge, flt, F)
5787MUL_3TYPE_enlarge(bte, hge, dbl, F)
5788#endif
5789#endif
5790MUL_2TYPE_float(bte, flt, flt)
5791MUL_3TYPE_enlarge(bte, flt, dbl, F)
5792MUL_2TYPE_float(bte, dbl, dbl)
5793MUL_4TYPE(sht, bte, sht, int, I)
5794MUL_3TYPE_enlarge(sht, bte, int, I)
5795#ifdef FULL_IMPLEMENTATION
5796MUL_3TYPE_enlarge(sht, bte, lng, I)
5797#ifdef HAVE_HGE
5798MUL_3TYPE_enlarge(sht, bte, hge, I)
5799#endif
5800MUL_3TYPE_enlarge(sht, bte, flt, F)
5801MUL_3TYPE_enlarge(sht, bte, dbl, F)
5802#endif
5803MUL_4TYPE(sht, sht, sht, int, I)
5804MUL_3TYPE_enlarge(sht, sht, int, I)
5805#ifdef FULL_IMPLEMENTATION
5806MUL_3TYPE_enlarge(sht, sht, lng, I)
5807#ifdef HAVE_HGE
5808MUL_3TYPE_enlarge(sht, sht, hge, I)
5809#endif
5810MUL_3TYPE_enlarge(sht, sht, flt, F)
5811MUL_3TYPE_enlarge(sht, sht, dbl, F)
5812#endif
5813MUL_4TYPE(sht, int, int, lng, I)
5814MUL_3TYPE_enlarge(sht, int, lng, I)
5815#ifdef FULL_IMPLEMENTATION
5816#ifdef HAVE_HGE
5817MUL_3TYPE_enlarge(sht, int, hge, I)
5818#endif
5819MUL_3TYPE_enlarge(sht, int, flt, F)
5820MUL_3TYPE_enlarge(sht, int, dbl, F)
5821#endif
5822MUL_2TYPE_lng(sht, lng)
5823#ifdef HAVE_HGE
5824MUL_3TYPE_enlarge(sht, lng, hge, I)
5825#endif
5826#ifdef FULL_IMPLEMENTATION
5827MUL_3TYPE_enlarge(sht, lng, flt, F)
5828MUL_3TYPE_enlarge(sht, lng, dbl, F)
5829#endif
5830#ifdef HAVE_HGE
5831MUL_2TYPE_hge(sht, hge)
5832#ifdef FULL_IMPLEMENTATION
5833MUL_3TYPE_enlarge(sht, hge, flt, F)
5834MUL_3TYPE_enlarge(sht, hge, dbl, F)
5835#endif
5836#endif
5837MUL_2TYPE_float(sht, flt, flt)
5838MUL_3TYPE_enlarge(sht, flt, dbl, F)
5839MUL_2TYPE_float(sht, dbl, dbl)
5840MUL_4TYPE(int, bte, int, lng, I)
5841MUL_3TYPE_enlarge(int, bte, lng, I)
5842#ifdef FULL_IMPLEMENTATION
5843#ifdef HAVE_HGE
5844MUL_3TYPE_enlarge(int, bte, hge, I)
5845#endif
5846MUL_3TYPE_enlarge(int, bte, flt, F)
5847MUL_3TYPE_enlarge(int, bte, dbl, F)
5848#endif
5849MUL_4TYPE(int, sht, int, lng, I)
5850MUL_3TYPE_enlarge(int, sht, lng, I)
5851#ifdef FULL_IMPLEMENTATION
5852#ifdef HAVE_HGE
5853MUL_3TYPE_enlarge(int, sht, hge, I)
5854#endif
5855MUL_3TYPE_enlarge(int, sht, flt, F)
5856MUL_3TYPE_enlarge(int, sht, dbl, F)
5857#endif
5858MUL_4TYPE(int, int, int, lng, I)
5859MUL_3TYPE_enlarge(int, int, lng, I)
5860#ifdef FULL_IMPLEMENTATION
5861#ifdef HAVE_HGE
5862MUL_3TYPE_enlarge(int, int, hge, I)
5863#endif
5864MUL_3TYPE_enlarge(int, int, flt, F)
5865MUL_3TYPE_enlarge(int, int, dbl, F)
5866#endif
5867MUL_2TYPE_lng(int, lng)
5868#ifdef HAVE_HGE
5869MUL_3TYPE_enlarge(int, lng, hge, I)
5870#endif
5871#ifdef FULL_IMPLEMENTATION
5872MUL_3TYPE_enlarge(int, lng, flt, F)
5873MUL_3TYPE_enlarge(int, lng, dbl, F)
5874#endif
5875#ifdef HAVE_HGE
5876MUL_2TYPE_hge(int, hge)
5877#ifdef FULL_IMPLEMENTATION
5878MUL_3TYPE_enlarge(int, hge, flt, F)
5879MUL_3TYPE_enlarge(int, hge, dbl, F)
5880#endif
5881#endif
5882MUL_2TYPE_float(int, flt, flt)
5883MUL_3TYPE_enlarge(int, flt, dbl, F)
5884MUL_2TYPE_float(int, dbl, dbl)
5885MUL_2TYPE_lng(lng, bte)
5886#ifdef HAVE_HGE
5887MUL_3TYPE_enlarge(lng, bte, hge, I)
5888#endif
5889#ifdef FULL_IMPLEMENTATION
5890MUL_3TYPE_enlarge(lng, bte, flt, F)
5891MUL_3TYPE_enlarge(lng, bte, dbl, F)
5892#endif
5893MUL_2TYPE_lng(lng, sht)
5894#ifdef HAVE_HGE
5895MUL_3TYPE_enlarge(lng, sht, hge, I)
5896#endif
5897#ifdef FULL_IMPLEMENTATION
5898MUL_3TYPE_enlarge(lng, sht, flt, F)
5899MUL_3TYPE_enlarge(lng, sht, dbl, F)
5900#endif
5901MUL_2TYPE_lng(lng, int)
5902#ifdef HAVE_HGE
5903MUL_3TYPE_enlarge(lng, int, hge, I)
5904#endif
5905#ifdef FULL_IMPLEMENTATION
5906MUL_3TYPE_enlarge(lng, int, flt, F)
5907MUL_3TYPE_enlarge(lng, int, dbl, F)
5908#endif
5909MUL_2TYPE_lng(lng, lng)
5910#ifdef HAVE_HGE
5911MUL_3TYPE_enlarge(lng, lng, hge, I)
5912#endif
5913#ifdef FULL_IMPLEMENTATION
5914MUL_3TYPE_enlarge(lng, lng, flt, F)
5915MUL_3TYPE_enlarge(lng, lng, dbl, F)
5916#endif
5917#ifdef HAVE_HGE
5918MUL_2TYPE_hge(lng, hge)
5919#ifdef FULL_IMPLEMENTATION
5920MUL_3TYPE_enlarge(lng, hge, flt, F)
5921MUL_3TYPE_enlarge(lng, hge, dbl, F)
5922#endif
5923#endif
5924MUL_2TYPE_float(lng, flt, flt)
5925MUL_3TYPE_enlarge(lng, flt, dbl, F)
5926MUL_2TYPE_float(lng, dbl, dbl)
5927#ifdef HAVE_HGE
5928MUL_2TYPE_hge(hge, bte)
5929#ifdef FULL_IMPLEMENTATION
5930MUL_3TYPE_enlarge(hge, bte, flt, F)
5931MUL_3TYPE_enlarge(hge, bte, dbl, F)
5932#endif
5933MUL_2TYPE_hge(hge, sht)
5934#ifdef FULL_IMPLEMENTATION
5935MUL_3TYPE_enlarge(hge, sht, flt, F)
5936MUL_3TYPE_enlarge(hge, sht, dbl, F)
5937#endif
5938MUL_2TYPE_hge(hge, int)
5939#ifdef FULL_IMPLEMENTATION
5940MUL_3TYPE_enlarge(hge, int, flt, F)
5941MUL_3TYPE_enlarge(hge, int, dbl, F)
5942#endif
5943MUL_2TYPE_hge(hge, lng)
5944#ifdef FULL_IMPLEMENTATION
5945MUL_3TYPE_enlarge(hge, lng, flt, F)
5946MUL_3TYPE_enlarge(hge, lng, dbl, F)
5947#endif
5948MUL_2TYPE_hge(hge, hge)
5949#ifdef FULL_IMPLEMENTATION
5950MUL_3TYPE_enlarge(hge, hge, flt, F)
5951MUL_3TYPE_enlarge(hge, hge, dbl, F)
5952#endif
5953MUL_2TYPE_float(hge, flt, flt)
5954MUL_3TYPE_enlarge(hge, flt, dbl, F)
5955MUL_2TYPE_float(hge, dbl, dbl)
5956#endif
5957MUL_2TYPE_float(flt, bte, flt)
5958MUL_3TYPE_enlarge(flt, bte, dbl, F)
5959MUL_2TYPE_float(flt, sht, flt)
5960MUL_3TYPE_enlarge(flt, sht, dbl, F)
5961MUL_2TYPE_float(flt, int, flt)
5962MUL_3TYPE_enlarge(flt, int, dbl, F)
5963MUL_2TYPE_float(flt, lng, flt)
5964MUL_3TYPE_enlarge(flt, lng, dbl, F)
5965#ifdef HAVE_HGE
5966MUL_2TYPE_float(flt, hge, flt)
5967MUL_3TYPE_enlarge(flt, hge, dbl, F)
5968#endif
5969MUL_2TYPE_float(flt, flt, flt)
5970MUL_3TYPE_enlarge(flt, flt, dbl, F)
5971MUL_2TYPE_float(flt, dbl, dbl)
5972MUL_2TYPE_float(dbl, bte, dbl)
5973MUL_2TYPE_float(dbl, sht, dbl)
5974MUL_2TYPE_float(dbl, int, dbl)
5975MUL_2TYPE_float(dbl, lng, dbl)
5976#ifdef HAVE_HGE
5977MUL_2TYPE_float(dbl, hge, dbl)
5978#endif
5979MUL_2TYPE_float(dbl, flt, dbl)
5980MUL_2TYPE_float(dbl, dbl, dbl)
5981
5982static BUN
5983mul_typeswitchloop(const void *lft, int tp1, int incr1,
5984 const void *rgt, int tp2, int incr2,
5985 void *restrict dst, int tp, BUN cnt,
5986 struct canditer *restrict ci, oid candoff,
5987 bool abort_on_error, const char *func)
5988{
5989 BUN nils;
5990
5991 tp1 = ATOMbasetype(tp1);
5992 tp2 = ATOMbasetype(tp2);
5993 tp = ATOMbasetype(tp);
5994 switch (tp1) {
5995 case TYPE_bte:
5996 switch (tp2) {
5997 case TYPE_bte:
5998 switch (tp) {
5999 case TYPE_bte:
6000 nils = mul_bte_bte_bte(lft, incr1, rgt, incr2,
6001 dst, GDK_bte_max, cnt,
6002 ci, candoff,
6003 abort_on_error);
6004 break;
6005 case TYPE_sht:
6006 nils = mul_bte_bte_sht(lft, incr1, rgt, incr2,
6007 dst, GDK_sht_max, cnt,
6008 ci, candoff,
6009 abort_on_error);
6010 break;
6011#ifdef FULL_IMPLEMENTATION
6012 case TYPE_int:
6013 nils = mul_bte_bte_int(lft, incr1, rgt, incr2,
6014 dst, GDK_int_max, cnt,
6015 ci, candoff,
6016 abort_on_error);
6017 break;
6018 case TYPE_lng:
6019 nils = mul_bte_bte_lng(lft, incr1, rgt, incr2,
6020 dst, GDK_lng_max, cnt,
6021 ci, candoff,
6022 abort_on_error);
6023 break;
6024#ifdef HAVE_HGE
6025 case TYPE_hge:
6026 nils = mul_bte_bte_hge(lft, incr1, rgt, incr2,
6027 dst, GDK_hge_max, cnt,
6028 ci, candoff,
6029 abort_on_error);
6030 break;
6031#endif
6032 case TYPE_flt:
6033 nils = mul_bte_bte_flt(lft, incr1, rgt, incr2,
6034 dst, GDK_flt_max, cnt,
6035 ci, candoff,
6036 abort_on_error);
6037 break;
6038 case TYPE_dbl:
6039 nils = mul_bte_bte_dbl(lft, incr1, rgt, incr2,
6040 dst, GDK_dbl_max, cnt,
6041 ci, candoff,
6042 abort_on_error);
6043 break;
6044#endif
6045 default:
6046 goto unsupported;
6047 }
6048 break;
6049 case TYPE_sht:
6050 switch (tp) {
6051 case TYPE_sht:
6052 nils = mul_bte_sht_sht(lft, incr1, rgt, incr2,
6053 dst, GDK_sht_max, cnt,
6054 ci, candoff,
6055 abort_on_error);
6056 break;
6057 case TYPE_int:
6058 nils = mul_bte_sht_int(lft, incr1, rgt, incr2,
6059 dst, GDK_int_max, cnt,
6060 ci, candoff,
6061 abort_on_error);
6062 break;
6063#ifdef FULL_IMPLEMENTATION
6064 case TYPE_lng:
6065 nils = mul_bte_sht_lng(lft, incr1, rgt, incr2,
6066 dst, GDK_lng_max, cnt,
6067 ci, candoff,
6068 abort_on_error);
6069 break;
6070#ifdef HAVE_HGE
6071 case TYPE_hge:
6072 nils = mul_bte_sht_hge(lft, incr1, rgt, incr2,
6073 dst, GDK_hge_max, cnt,
6074 ci, candoff,
6075 abort_on_error);
6076 break;
6077#endif
6078 case TYPE_flt:
6079 nils = mul_bte_sht_flt(lft, incr1, rgt, incr2,
6080 dst, GDK_flt_max, cnt,
6081 ci, candoff,
6082 abort_on_error);
6083 break;
6084 case TYPE_dbl:
6085 nils = mul_bte_sht_dbl(lft, incr1, rgt, incr2,
6086 dst, GDK_dbl_max, cnt,
6087 ci, candoff,
6088 abort_on_error);
6089 break;
6090#endif
6091 default:
6092 goto unsupported;
6093 }
6094 break;
6095 case TYPE_int:
6096 switch (tp) {
6097 case TYPE_int:
6098 nils = mul_bte_int_int(lft, incr1, rgt, incr2,
6099 dst, GDK_int_max, cnt,
6100 ci, candoff,
6101 abort_on_error);
6102 break;
6103 case TYPE_lng:
6104 nils = mul_bte_int_lng(lft, incr1, rgt, incr2,
6105 dst, GDK_lng_max, cnt,
6106 ci, candoff,
6107 abort_on_error);
6108 break;
6109#ifdef FULL_IMPLEMENTATION
6110#ifdef HAVE_HGE
6111 case TYPE_hge:
6112 nils = mul_bte_int_hge(lft, incr1, rgt, incr2,
6113 dst, GDK_hge_max, cnt,
6114 ci, candoff,
6115 abort_on_error);
6116 break;
6117#endif
6118 case TYPE_flt:
6119 nils = mul_bte_int_flt(lft, incr1, rgt, incr2,
6120 dst, GDK_flt_max, cnt,
6121 ci, candoff,
6122 abort_on_error);
6123 break;
6124 case TYPE_dbl:
6125 nils = mul_bte_int_dbl(lft, incr1, rgt, incr2,
6126 dst, GDK_dbl_max, cnt,
6127 ci, candoff,
6128 abort_on_error);
6129 break;
6130#endif
6131 default:
6132 goto unsupported;
6133 }
6134 break;
6135 case TYPE_lng:
6136 switch (tp) {
6137 case TYPE_lng:
6138 nils = mul_bte_lng_lng(lft, incr1, rgt, incr2,
6139 dst, GDK_lng_max, cnt,
6140 ci, candoff,
6141 abort_on_error);
6142 break;
6143#ifdef HAVE_HGE
6144 case TYPE_hge:
6145 nils = mul_bte_lng_hge(lft, incr1, rgt, incr2,
6146 dst, GDK_hge_max, cnt,
6147 ci, candoff,
6148 abort_on_error);
6149 break;
6150#endif
6151#ifdef FULL_IMPLEMENTATION
6152 case TYPE_flt:
6153 nils = mul_bte_lng_flt(lft, incr1, rgt, incr2,
6154 dst, GDK_flt_max, cnt,
6155 ci, candoff,
6156 abort_on_error);
6157 break;
6158 case TYPE_dbl:
6159 nils = mul_bte_lng_dbl(lft, incr1, rgt, incr2,
6160 dst, GDK_dbl_max, cnt,
6161 ci, candoff,
6162 abort_on_error);
6163 break;
6164#endif
6165 default:
6166 goto unsupported;
6167 }
6168 break;
6169#ifdef HAVE_HGE
6170 case TYPE_hge:
6171 switch (tp) {
6172 case TYPE_hge:
6173 nils = mul_bte_hge_hge(lft, incr1, rgt, incr2,
6174 dst, GDK_hge_max, cnt,
6175 ci, candoff,
6176 abort_on_error);
6177 break;
6178#ifdef FULL_IMPLEMENTATION
6179 case TYPE_flt:
6180 nils = mul_bte_hge_flt(lft, incr1, rgt, incr2,
6181 dst, GDK_flt_max, cnt,
6182 ci, candoff,
6183 abort_on_error);
6184 break;
6185 case TYPE_dbl:
6186 nils = mul_bte_hge_dbl(lft, incr1, rgt, incr2,
6187 dst, GDK_dbl_max, cnt,
6188 ci, candoff,
6189 abort_on_error);
6190 break;
6191#endif
6192 default:
6193 goto unsupported;
6194 }
6195 break;
6196#endif
6197 case TYPE_flt:
6198 switch (tp) {
6199 case TYPE_flt:
6200 nils = mul_bte_flt_flt(lft, incr1, rgt, incr2,
6201 dst, GDK_flt_max, cnt,
6202 ci, candoff,
6203 abort_on_error);
6204 break;
6205 case TYPE_dbl:
6206 nils = mul_bte_flt_dbl(lft, incr1, rgt, incr2,
6207 dst, GDK_dbl_max, cnt,
6208 ci, candoff,
6209 abort_on_error);
6210 break;
6211 default:
6212 goto unsupported;
6213 }
6214 break;
6215 case TYPE_dbl:
6216 switch (tp) {
6217 case TYPE_dbl:
6218 nils = mul_bte_dbl_dbl(lft, incr1, rgt, incr2,
6219 dst, GDK_dbl_max, cnt,
6220 ci, candoff,
6221 abort_on_error);
6222 break;
6223 default:
6224 goto unsupported;
6225 }
6226 break;
6227 default:
6228 goto unsupported;
6229 }
6230 break;
6231 case TYPE_sht:
6232 switch (tp2) {
6233 case TYPE_bte:
6234 switch (tp) {
6235 case TYPE_sht:
6236 nils = mul_sht_bte_sht(lft, incr1, rgt, incr2,
6237 dst, GDK_sht_max, cnt,
6238 ci, candoff,
6239 abort_on_error);
6240 break;
6241 case TYPE_int:
6242 nils = mul_sht_bte_int(lft, incr1, rgt, incr2,
6243 dst, GDK_int_max, cnt,
6244 ci, candoff,
6245 abort_on_error);
6246 break;
6247#ifdef FULL_IMPLEMENTATION
6248 case TYPE_lng:
6249 nils = mul_sht_bte_lng(lft, incr1, rgt, incr2,
6250 dst, GDK_lng_max, cnt,
6251 ci, candoff,
6252 abort_on_error);
6253 break;
6254#ifdef HAVE_HGE
6255 case TYPE_hge:
6256 nils = mul_sht_bte_hge(lft, incr1, rgt, incr2,
6257 dst, GDK_hge_max, cnt,
6258 ci, candoff,
6259 abort_on_error);
6260 break;
6261#endif
6262 case TYPE_flt:
6263 nils = mul_sht_bte_flt(lft, incr1, rgt, incr2,
6264 dst, GDK_flt_max, cnt,
6265 ci, candoff,
6266 abort_on_error);
6267 break;
6268 case TYPE_dbl:
6269 nils = mul_sht_bte_dbl(lft, incr1, rgt, incr2,
6270 dst, GDK_dbl_max, cnt,
6271 ci, candoff,
6272 abort_on_error);
6273 break;
6274#endif
6275 default:
6276 goto unsupported;
6277 }
6278 break;
6279 case TYPE_sht:
6280 switch (tp) {
6281 case TYPE_sht:
6282 nils = mul_sht_sht_sht(lft, incr1, rgt, incr2,
6283 dst, GDK_sht_max, cnt,
6284 ci, candoff,
6285 abort_on_error);
6286 break;
6287 case TYPE_int:
6288 nils = mul_sht_sht_int(lft, incr1, rgt, incr2,
6289 dst, GDK_int_max, cnt,
6290 ci, candoff,
6291 abort_on_error);
6292 break;
6293#ifdef FULL_IMPLEMENTATION
6294 case TYPE_lng:
6295 nils = mul_sht_sht_lng(lft, incr1, rgt, incr2,
6296 dst, GDK_lng_max, cnt,
6297 ci, candoff,
6298 abort_on_error);
6299 break;
6300#ifdef HAVE_HGE
6301 case TYPE_hge:
6302 nils = mul_sht_sht_hge(lft, incr1, rgt, incr2,
6303 dst, GDK_hge_max, cnt,
6304 ci, candoff,
6305 abort_on_error);
6306 break;
6307#endif
6308 case TYPE_flt:
6309 nils = mul_sht_sht_flt(lft, incr1, rgt, incr2,
6310 dst, GDK_flt_max, cnt,
6311 ci, candoff,
6312 abort_on_error);
6313 break;
6314 case TYPE_dbl:
6315 nils = mul_sht_sht_dbl(lft, incr1, rgt, incr2,
6316 dst, GDK_dbl_max, cnt,
6317 ci, candoff,
6318 abort_on_error);
6319 break;
6320#endif
6321 default:
6322 goto unsupported;
6323 }
6324 break;
6325 case TYPE_int:
6326 switch (tp) {
6327 case TYPE_int:
6328 nils = mul_sht_int_int(lft, incr1, rgt, incr2,
6329 dst, GDK_int_max, cnt,
6330 ci, candoff,
6331 abort_on_error);
6332 break;
6333 case TYPE_lng:
6334 nils = mul_sht_int_lng(lft, incr1, rgt, incr2,
6335 dst, GDK_lng_max, cnt,
6336 ci, candoff,
6337 abort_on_error);
6338 break;
6339#ifdef FULL_IMPLEMENTATION
6340#ifdef HAVE_HGE
6341 case TYPE_hge:
6342 nils = mul_sht_int_hge(lft, incr1, rgt, incr2,
6343 dst, GDK_hge_max, cnt,
6344 ci, candoff,
6345 abort_on_error);
6346 break;
6347#endif
6348 case TYPE_flt:
6349 nils = mul_sht_int_flt(lft, incr1, rgt, incr2,
6350 dst, GDK_flt_max, cnt,
6351 ci, candoff,
6352 abort_on_error);
6353 break;
6354 case TYPE_dbl:
6355 nils = mul_sht_int_dbl(lft, incr1, rgt, incr2,
6356 dst, GDK_dbl_max, cnt,
6357 ci, candoff,
6358 abort_on_error);
6359 break;
6360#endif
6361 default:
6362 goto unsupported;
6363 }
6364 break;
6365 case TYPE_lng:
6366 switch (tp) {
6367 case TYPE_lng:
6368 nils = mul_sht_lng_lng(lft, incr1, rgt, incr2,
6369 dst, GDK_lng_max, cnt,
6370 ci, candoff,
6371 abort_on_error);
6372 break;
6373#ifdef HAVE_HGE
6374 case TYPE_hge:
6375 nils = mul_sht_lng_hge(lft, incr1, rgt, incr2,
6376 dst, GDK_hge_max, cnt,
6377 ci, candoff,
6378 abort_on_error);
6379 break;
6380#endif
6381#ifdef FULL_IMPLEMENTATION
6382 case TYPE_flt:
6383 nils = mul_sht_lng_flt(lft, incr1, rgt, incr2,
6384 dst, GDK_flt_max, cnt,
6385 ci, candoff,
6386 abort_on_error);
6387 break;
6388 case TYPE_dbl:
6389 nils = mul_sht_lng_dbl(lft, incr1, rgt, incr2,
6390 dst, GDK_dbl_max, cnt,
6391 ci, candoff,
6392 abort_on_error);
6393 break;
6394#endif
6395 default:
6396 goto unsupported;
6397 }
6398 break;
6399#ifdef HAVE_HGE
6400 case TYPE_hge:
6401 switch (tp) {
6402 case TYPE_hge:
6403 nils = mul_sht_hge_hge(lft, incr1, rgt, incr2,
6404 dst, GDK_hge_max, cnt,
6405 ci, candoff,
6406 abort_on_error);
6407 break;
6408#ifdef FULL_IMPLEMENTATION
6409 case TYPE_flt:
6410 nils = mul_sht_hge_flt(lft, incr1, rgt, incr2,
6411 dst, GDK_flt_max, cnt,
6412 ci, candoff,
6413 abort_on_error);
6414 break;
6415 case TYPE_dbl:
6416 nils = mul_sht_hge_dbl(lft, incr1, rgt, incr2,
6417 dst, GDK_dbl_max, cnt,
6418 ci, candoff,
6419 abort_on_error);
6420 break;
6421#endif
6422 default:
6423 goto unsupported;
6424 }
6425 break;
6426#endif
6427 case TYPE_flt:
6428 switch (tp) {
6429 case TYPE_flt:
6430 nils = mul_sht_flt_flt(lft, incr1, rgt, incr2,
6431 dst, GDK_flt_max, cnt,
6432 ci, candoff,
6433 abort_on_error);
6434 break;
6435 case TYPE_dbl:
6436 nils = mul_sht_flt_dbl(lft, incr1, rgt, incr2,
6437 dst, GDK_dbl_max, cnt,
6438 ci, candoff,
6439 abort_on_error);
6440 break;
6441 default:
6442 goto unsupported;
6443 }
6444 break;
6445 case TYPE_dbl:
6446 switch (tp) {
6447 case TYPE_dbl:
6448 nils = mul_sht_dbl_dbl(lft, incr1, rgt, incr2,
6449 dst, GDK_dbl_max, cnt,
6450 ci, candoff,
6451 abort_on_error);
6452 break;
6453 default:
6454 goto unsupported;
6455 }
6456 break;
6457 default:
6458 goto unsupported;
6459 }
6460 break;
6461 case TYPE_int:
6462 switch (tp2) {
6463 case TYPE_bte:
6464 switch (tp) {
6465 case TYPE_int:
6466 nils = mul_int_bte_int(lft, incr1, rgt, incr2,
6467 dst, GDK_int_max, cnt,
6468 ci, candoff,
6469 abort_on_error);
6470 break;
6471 case TYPE_lng:
6472 nils = mul_int_bte_lng(lft, incr1, rgt, incr2,
6473 dst, GDK_lng_max, cnt,
6474 ci, candoff,
6475 abort_on_error);
6476 break;
6477#ifdef FULL_IMPLEMENTATION
6478#ifdef HAVE_HGE
6479 case TYPE_hge:
6480 nils = mul_int_bte_hge(lft, incr1, rgt, incr2,
6481 dst, GDK_hge_max, cnt,
6482 ci, candoff,
6483 abort_on_error);
6484 break;
6485#endif
6486 case TYPE_flt:
6487 nils = mul_int_bte_flt(lft, incr1, rgt, incr2,
6488 dst, GDK_flt_max, cnt,
6489 ci, candoff,
6490 abort_on_error);
6491 break;
6492 case TYPE_dbl:
6493 nils = mul_int_bte_dbl(lft, incr1, rgt, incr2,
6494 dst, GDK_dbl_max, cnt,
6495 ci, candoff,
6496 abort_on_error);
6497 break;
6498#endif
6499 default:
6500 goto unsupported;
6501 }
6502 break;
6503 case TYPE_sht:
6504 switch (tp) {
6505 case TYPE_int:
6506 nils = mul_int_sht_int(lft, incr1, rgt, incr2,
6507 dst, GDK_int_max, cnt,
6508 ci, candoff,
6509 abort_on_error);
6510 break;
6511 case TYPE_lng:
6512 nils = mul_int_sht_lng(lft, incr1, rgt, incr2,
6513 dst, GDK_lng_max, cnt,
6514 ci, candoff,
6515 abort_on_error);
6516 break;
6517#ifdef FULL_IMPLEMENTATION
6518#ifdef HAVE_HGE
6519 case TYPE_hge:
6520 nils = mul_int_sht_hge(lft, incr1, rgt, incr2,
6521 dst, GDK_hge_max, cnt,
6522 ci, candoff,
6523 abort_on_error);
6524 break;
6525#endif
6526 case TYPE_flt:
6527 nils = mul_int_sht_flt(lft, incr1, rgt, incr2,
6528 dst, GDK_flt_max, cnt,
6529 ci, candoff,
6530 abort_on_error);
6531 break;
6532 case TYPE_dbl:
6533 nils = mul_int_sht_dbl(lft, incr1, rgt, incr2,
6534 dst, GDK_dbl_max, cnt,
6535 ci, candoff,
6536 abort_on_error);
6537 break;
6538#endif
6539 default:
6540 goto unsupported;
6541 }
6542 break;
6543 case TYPE_int:
6544 switch (tp) {
6545 case TYPE_int:
6546 nils = mul_int_int_int(lft, incr1, rgt, incr2,
6547 dst, GDK_int_max, cnt,
6548 ci, candoff,
6549 abort_on_error);
6550 break;
6551 case TYPE_lng:
6552 nils = mul_int_int_lng(lft, incr1, rgt, incr2,
6553 dst, GDK_lng_max, cnt,
6554 ci, candoff,
6555 abort_on_error);
6556 break;
6557#ifdef FULL_IMPLEMENTATION
6558#ifdef HAVE_HGE
6559 case TYPE_hge:
6560 nils = mul_int_int_hge(lft, incr1, rgt, incr2,
6561 dst, GDK_hge_max, cnt,
6562 ci, candoff,
6563 abort_on_error);
6564 break;
6565#endif
6566 case TYPE_flt:
6567 nils = mul_int_int_flt(lft, incr1, rgt, incr2,
6568 dst, GDK_flt_max, cnt,
6569 ci, candoff,
6570 abort_on_error);
6571 break;
6572 case TYPE_dbl:
6573 nils = mul_int_int_dbl(lft, incr1, rgt, incr2,
6574 dst, GDK_dbl_max, cnt,
6575 ci, candoff,
6576 abort_on_error);
6577 break;
6578#endif
6579 default:
6580 goto unsupported;
6581 }
6582 break;
6583 case TYPE_lng:
6584 switch (tp) {
6585 case TYPE_lng:
6586 nils = mul_int_lng_lng(lft, incr1, rgt, incr2,
6587 dst, GDK_lng_max, cnt,
6588 ci, candoff,
6589 abort_on_error);
6590 break;
6591#ifdef HAVE_HGE
6592 case TYPE_hge:
6593 nils = mul_int_lng_hge(lft, incr1, rgt, incr2,
6594 dst, GDK_hge_max, cnt,
6595 ci, candoff,
6596 abort_on_error);
6597 break;
6598#endif
6599#ifdef FULL_IMPLEMENTATION
6600 case TYPE_flt:
6601 nils = mul_int_lng_flt(lft, incr1, rgt, incr2,
6602 dst, GDK_flt_max, cnt,
6603 ci, candoff,
6604 abort_on_error);
6605 break;
6606 case TYPE_dbl:
6607 nils = mul_int_lng_dbl(lft, incr1, rgt, incr2,
6608 dst, GDK_dbl_max, cnt,
6609 ci, candoff,
6610 abort_on_error);
6611 break;
6612#endif
6613 default:
6614 goto unsupported;
6615 }
6616 break;
6617#ifdef HAVE_HGE
6618 case TYPE_hge:
6619 switch (tp) {
6620 case TYPE_hge:
6621 nils = mul_int_hge_hge(lft, incr1, rgt, incr2,
6622 dst, GDK_hge_max, cnt,
6623 ci, candoff,
6624 abort_on_error);
6625 break;
6626#ifdef FULL_IMPLEMENTATION
6627 case TYPE_flt:
6628 nils = mul_int_hge_flt(lft, incr1, rgt, incr2,
6629 dst, GDK_flt_max, cnt,
6630 ci, candoff,
6631 abort_on_error);
6632 break;
6633 case TYPE_dbl:
6634 nils = mul_int_hge_dbl(lft, incr1, rgt, incr2,
6635 dst, GDK_dbl_max, cnt,
6636 ci, candoff,
6637 abort_on_error);
6638 break;
6639#endif
6640 default:
6641 goto unsupported;
6642 }
6643 break;
6644#endif
6645 case TYPE_flt:
6646 switch (tp) {
6647 case TYPE_flt:
6648 nils = mul_int_flt_flt(lft, incr1, rgt, incr2,
6649 dst, GDK_flt_max, cnt,
6650 ci, candoff,
6651 abort_on_error);
6652 break;
6653 case TYPE_dbl:
6654 nils = mul_int_flt_dbl(lft, incr1, rgt, incr2,
6655 dst, GDK_dbl_max, cnt,
6656 ci, candoff,
6657 abort_on_error);
6658 break;
6659 default:
6660 goto unsupported;
6661 }
6662 break;
6663 case TYPE_dbl:
6664 switch (tp) {
6665 case TYPE_dbl:
6666 nils = mul_int_dbl_dbl(lft, incr1, rgt, incr2,
6667 dst, GDK_dbl_max, cnt,
6668 ci, candoff,
6669 abort_on_error);
6670 break;
6671 default:
6672 goto unsupported;
6673 }
6674 break;
6675 default:
6676 goto unsupported;
6677 }
6678 break;
6679 case TYPE_lng:
6680 switch (tp2) {
6681 case TYPE_bte:
6682 switch (tp) {
6683 case TYPE_lng:
6684 nils = mul_lng_bte_lng(lft, incr1, rgt, incr2,
6685 dst, GDK_lng_max, cnt,
6686 ci, candoff,
6687 abort_on_error);
6688 break;
6689#ifdef HAVE_HGE
6690 case TYPE_hge:
6691 nils = mul_lng_bte_hge(lft, incr1, rgt, incr2,
6692 dst, GDK_hge_max, cnt,
6693 ci, candoff,
6694 abort_on_error);
6695 break;
6696#endif
6697#ifdef FULL_IMPLEMENTATION
6698 case TYPE_flt:
6699 nils = mul_lng_bte_flt(lft, incr1, rgt, incr2,
6700 dst, GDK_flt_max, cnt,
6701 ci, candoff,
6702 abort_on_error);
6703 break;
6704 case TYPE_dbl:
6705 nils = mul_lng_bte_dbl(lft, incr1, rgt, incr2,
6706 dst, GDK_dbl_max, cnt,
6707 ci, candoff,
6708 abort_on_error);
6709 break;
6710#endif
6711 default:
6712 goto unsupported;
6713 }
6714 break;
6715 case TYPE_sht:
6716 switch (tp) {
6717 case TYPE_lng:
6718 nils = mul_lng_sht_lng(lft, incr1, rgt, incr2,
6719 dst, GDK_lng_max, cnt,
6720 ci, candoff,
6721 abort_on_error);
6722 break;
6723#ifdef HAVE_HGE
6724 case TYPE_hge:
6725 nils = mul_lng_sht_hge(lft, incr1, rgt, incr2,
6726 dst, GDK_hge_max, cnt,
6727 ci, candoff,
6728 abort_on_error);
6729 break;
6730#endif
6731#ifdef FULL_IMPLEMENTATION
6732 case TYPE_flt:
6733 nils = mul_lng_sht_flt(lft, incr1, rgt, incr2,
6734 dst, GDK_flt_max, cnt,
6735 ci, candoff,
6736 abort_on_error);
6737 break;
6738 case TYPE_dbl:
6739 nils = mul_lng_sht_dbl(lft, incr1, rgt, incr2,
6740 dst, GDK_dbl_max, cnt,
6741 ci, candoff,
6742 abort_on_error);
6743 break;
6744#endif
6745 default:
6746 goto unsupported;
6747 }
6748 break;
6749 case TYPE_int:
6750 switch (tp) {
6751 case TYPE_lng:
6752 nils = mul_lng_int_lng(lft, incr1, rgt, incr2,
6753 dst, GDK_lng_max, cnt,
6754 ci, candoff,
6755 abort_on_error);
6756 break;
6757#ifdef HAVE_HGE
6758 case TYPE_hge:
6759 nils = mul_lng_int_hge(lft, incr1, rgt, incr2,
6760 dst, GDK_hge_max, cnt,
6761 ci, candoff,
6762 abort_on_error);
6763 break;
6764#endif
6765#ifdef FULL_IMPLEMENTATION
6766 case TYPE_flt:
6767 nils = mul_lng_int_flt(lft, incr1, rgt, incr2,
6768 dst, GDK_flt_max, cnt,
6769 ci, candoff,
6770 abort_on_error);
6771 break;
6772 case TYPE_dbl:
6773 nils = mul_lng_int_dbl(lft, incr1, rgt, incr2,
6774 dst, GDK_dbl_max, cnt,
6775 ci, candoff,
6776 abort_on_error);
6777 break;
6778#endif
6779 default:
6780 goto unsupported;
6781 }
6782 break;
6783 case TYPE_lng:
6784 switch (tp) {
6785 case TYPE_lng:
6786 nils = mul_lng_lng_lng(lft, incr1, rgt, incr2,
6787 dst, GDK_lng_max, cnt,
6788 ci, candoff,
6789 abort_on_error);
6790 break;
6791#ifdef HAVE_HGE
6792 case TYPE_hge:
6793 nils = mul_lng_lng_hge(lft, incr1, rgt, incr2,
6794 dst, GDK_hge_max, cnt,
6795 ci, candoff,
6796 abort_on_error);
6797 break;
6798#endif
6799#ifdef FULL_IMPLEMENTATION
6800 case TYPE_flt:
6801 nils = mul_lng_lng_flt(lft, incr1, rgt, incr2,
6802 dst, GDK_flt_max, cnt,
6803 ci, candoff,
6804 abort_on_error);
6805 break;
6806 case TYPE_dbl:
6807 nils = mul_lng_lng_dbl(lft, incr1, rgt, incr2,
6808 dst, GDK_dbl_max, cnt,
6809 ci, candoff,
6810 abort_on_error);
6811 break;
6812#endif
6813 default:
6814 goto unsupported;
6815 }
6816 break;
6817#ifdef HAVE_HGE
6818 case TYPE_hge:
6819 switch (tp) {
6820 case TYPE_hge:
6821 nils = mul_lng_hge_hge(lft, incr1, rgt, incr2,
6822 dst, GDK_hge_max, cnt,
6823 ci, candoff,
6824 abort_on_error);
6825 break;
6826#ifdef FULL_IMPLEMENTATION
6827 case TYPE_flt:
6828 nils = mul_lng_hge_flt(lft, incr1, rgt, incr2,
6829 dst, GDK_flt_max, cnt,
6830 ci, candoff,
6831 abort_on_error);
6832 break;
6833 case TYPE_dbl:
6834 nils = mul_lng_hge_dbl(lft, incr1, rgt, incr2,
6835 dst, GDK_dbl_max, cnt,
6836 ci, candoff,
6837 abort_on_error);
6838 break;
6839#endif
6840 default:
6841 goto unsupported;
6842 }
6843 break;
6844#endif
6845 case TYPE_flt:
6846 switch (tp) {
6847 case TYPE_flt:
6848 nils = mul_lng_flt_flt(lft, incr1, rgt, incr2,
6849 dst, GDK_flt_max, cnt,
6850 ci, candoff,
6851 abort_on_error);
6852 break;
6853 case TYPE_dbl:
6854 nils = mul_lng_flt_dbl(lft, incr1, rgt, incr2,
6855 dst, GDK_dbl_max, cnt,
6856 ci, candoff,
6857 abort_on_error);
6858 break;
6859 default:
6860 goto unsupported;
6861 }
6862 break;
6863 case TYPE_dbl:
6864 switch (tp) {
6865 case TYPE_dbl:
6866 nils = mul_lng_dbl_dbl(lft, incr1, rgt, incr2,
6867 dst, GDK_dbl_max, cnt,
6868 ci, candoff,
6869 abort_on_error);
6870 break;
6871 default:
6872 goto unsupported;
6873 }
6874 break;
6875 default:
6876 goto unsupported;
6877 }
6878 break;
6879#ifdef HAVE_HGE
6880 case TYPE_hge:
6881 switch (tp2) {
6882 case TYPE_bte:
6883 switch (tp) {
6884 case TYPE_hge:
6885 nils = mul_hge_bte_hge(lft, incr1, rgt, incr2,
6886 dst, GDK_hge_max, cnt,
6887 ci, candoff,
6888 abort_on_error);
6889 break;
6890#ifdef FULL_IMPLEMENTATION
6891 case TYPE_flt:
6892 nils = mul_hge_bte_flt(lft, incr1, rgt, incr2,
6893 dst, GDK_flt_max, cnt,
6894 ci, candoff,
6895 abort_on_error);
6896 break;
6897 case TYPE_dbl:
6898 nils = mul_hge_bte_dbl(lft, incr1, rgt, incr2,
6899 dst, GDK_dbl_max, cnt,
6900 ci, candoff,
6901 abort_on_error);
6902 break;
6903#endif
6904 default:
6905 goto unsupported;
6906 }
6907 break;
6908 case TYPE_sht:
6909 switch (tp) {
6910 case TYPE_hge:
6911 nils = mul_hge_sht_hge(lft, incr1, rgt, incr2,
6912 dst, GDK_hge_max, cnt,
6913 ci, candoff,
6914 abort_on_error);
6915 break;
6916#ifdef FULL_IMPLEMENTATION
6917 case TYPE_flt:
6918 nils = mul_hge_sht_flt(lft, incr1, rgt, incr2,
6919 dst, GDK_flt_max, cnt,
6920 ci, candoff,
6921 abort_on_error);
6922 break;
6923 case TYPE_dbl:
6924 nils = mul_hge_sht_dbl(lft, incr1, rgt, incr2,
6925 dst, GDK_dbl_max, cnt,
6926 ci, candoff,
6927 abort_on_error);
6928 break;
6929#endif
6930 default:
6931 goto unsupported;
6932 }
6933 break;
6934 case TYPE_int:
6935 switch (tp) {
6936 case TYPE_hge:
6937 nils = mul_hge_int_hge(lft, incr1, rgt, incr2,
6938 dst, GDK_hge_max, cnt,
6939 ci, candoff,
6940 abort_on_error);
6941 break;
6942#ifdef FULL_IMPLEMENTATION
6943 case TYPE_flt:
6944 nils = mul_hge_int_flt(lft, incr1, rgt, incr2,
6945 dst, GDK_flt_max, cnt,
6946 ci, candoff,
6947 abort_on_error);
6948 break;
6949 case TYPE_dbl:
6950 nils = mul_hge_int_dbl(lft, incr1, rgt, incr2,
6951 dst, GDK_dbl_max, cnt,
6952 ci, candoff,
6953 abort_on_error);
6954 break;
6955#endif
6956 default:
6957 goto unsupported;
6958 }
6959 break;
6960 case TYPE_lng:
6961 switch (tp) {
6962 case TYPE_hge:
6963 nils = mul_hge_lng_hge(lft, incr1, rgt, incr2,
6964 dst, GDK_hge_max, cnt,
6965 ci, candoff,
6966 abort_on_error);
6967 break;
6968#ifdef FULL_IMPLEMENTATION
6969 case TYPE_flt:
6970 nils = mul_hge_lng_flt(lft, incr1, rgt, incr2,
6971 dst, GDK_flt_max, cnt,
6972 ci, candoff,
6973 abort_on_error);
6974 break;
6975 case TYPE_dbl:
6976 nils = mul_hge_lng_dbl(lft, incr1, rgt, incr2,
6977 dst, GDK_dbl_max, cnt,
6978 ci, candoff,
6979 abort_on_error);
6980 break;
6981#endif
6982 default:
6983 goto unsupported;
6984 }
6985 break;
6986#ifdef HAVE_HGE
6987 case TYPE_hge:
6988 switch (tp) {
6989 case TYPE_hge:
6990 nils = mul_hge_hge_hge(lft, incr1, rgt, incr2,
6991 dst, GDK_hge_max, cnt,
6992 ci, candoff,
6993 abort_on_error);
6994 break;
6995#ifdef FULL_IMPLEMENTATION
6996 case TYPE_flt:
6997 nils = mul_hge_hge_flt(lft, incr1, rgt, incr2,
6998 dst, GDK_flt_max, cnt,
6999 ci, candoff,
7000 abort_on_error);
7001 break;
7002 case TYPE_dbl:
7003 nils = mul_hge_hge_dbl(lft, incr1, rgt, incr2,
7004 dst, GDK_dbl_max, cnt,
7005 ci, candoff,
7006 abort_on_error);
7007 break;
7008#endif
7009 default:
7010 goto unsupported;
7011 }
7012 break;
7013#endif
7014 case TYPE_flt:
7015 switch (tp) {
7016 case TYPE_flt:
7017 nils = mul_hge_flt_flt(lft, incr1, rgt, incr2,
7018 dst, GDK_flt_max, cnt,
7019 ci, candoff,
7020 abort_on_error);
7021 break;
7022 case TYPE_dbl:
7023 nils = mul_hge_flt_dbl(lft, incr1, rgt, incr2,
7024 dst, GDK_dbl_max, cnt,
7025 ci, candoff,
7026 abort_on_error);
7027 break;
7028 default:
7029 goto unsupported;
7030 }
7031 break;
7032 case TYPE_dbl:
7033 switch (tp) {
7034 case TYPE_dbl:
7035 nils = mul_hge_dbl_dbl(lft, incr1, rgt, incr2,
7036 dst, GDK_dbl_max, cnt,
7037 ci, candoff,
7038 abort_on_error);
7039 break;
7040 default:
7041 goto unsupported;
7042 }
7043 break;
7044 default:
7045 goto unsupported;
7046 }
7047 break;
7048#endif
7049 case TYPE_flt:
7050 switch (tp2) {
7051 case TYPE_bte:
7052 switch (tp) {
7053 case TYPE_flt:
7054 nils = mul_flt_bte_flt(lft, incr1, rgt, incr2,
7055 dst, GDK_flt_max, cnt,
7056 ci, candoff,
7057 abort_on_error);
7058 break;
7059 case TYPE_dbl:
7060 nils = mul_flt_bte_dbl(lft, incr1, rgt, incr2,
7061 dst, GDK_dbl_max, cnt,
7062 ci, candoff,
7063 abort_on_error);
7064 break;
7065 default:
7066 goto unsupported;
7067 }
7068 break;
7069 case TYPE_sht:
7070 switch (tp) {
7071 case TYPE_flt:
7072 nils = mul_flt_sht_flt(lft, incr1, rgt, incr2,
7073 dst, GDK_flt_max, cnt,
7074 ci, candoff,
7075 abort_on_error);
7076 break;
7077 case TYPE_dbl:
7078 nils = mul_flt_sht_dbl(lft, incr1, rgt, incr2,
7079 dst, GDK_dbl_max, cnt,
7080 ci, candoff,
7081 abort_on_error);
7082 break;
7083 default:
7084 goto unsupported;
7085 }
7086 break;
7087 case TYPE_int:
7088 switch (tp) {
7089 case TYPE_flt:
7090 nils = mul_flt_int_flt(lft, incr1, rgt, incr2,
7091 dst, GDK_flt_max, cnt,
7092 ci, candoff,
7093 abort_on_error);
7094 break;
7095 case TYPE_dbl:
7096 nils = mul_flt_int_dbl(lft, incr1, rgt, incr2,
7097 dst, GDK_dbl_max, cnt,
7098 ci, candoff,
7099 abort_on_error);
7100 break;
7101 default:
7102 goto unsupported;
7103 }
7104 break;
7105 case TYPE_lng:
7106 switch (tp) {
7107 case TYPE_flt:
7108 nils = mul_flt_lng_flt(lft, incr1, rgt, incr2,
7109 dst, GDK_flt_max, cnt,
7110 ci, candoff,
7111 abort_on_error);
7112 break;
7113 case TYPE_dbl:
7114 nils = mul_flt_lng_dbl(lft, incr1, rgt, incr2,
7115 dst, GDK_dbl_max, cnt,
7116 ci, candoff,
7117 abort_on_error);
7118 break;
7119 default:
7120 goto unsupported;
7121 }
7122 break;
7123#ifdef HAVE_HGE
7124 case TYPE_hge:
7125 switch (tp) {
7126 case TYPE_flt:
7127 nils = mul_flt_hge_flt(lft, incr1, rgt, incr2,
7128 dst, GDK_flt_max, cnt,
7129 ci, candoff,
7130 abort_on_error);
7131 break;
7132 case TYPE_dbl:
7133 nils = mul_flt_hge_dbl(lft, incr1, rgt, incr2,
7134 dst, GDK_dbl_max, cnt,
7135 ci, candoff,
7136 abort_on_error);
7137 break;
7138 default:
7139 goto unsupported;
7140 }
7141 break;
7142#endif
7143 case TYPE_flt:
7144 switch (tp) {
7145 case TYPE_flt:
7146 nils = mul_flt_flt_flt(lft, incr1, rgt, incr2,
7147 dst, GDK_flt_max, cnt,
7148 ci, candoff,
7149 abort_on_error);
7150 break;
7151 case TYPE_dbl:
7152 nils = mul_flt_flt_dbl(lft, incr1, rgt, incr2,
7153 dst, GDK_dbl_max, cnt,
7154 ci, candoff,
7155 abort_on_error);
7156 break;
7157 default:
7158 goto unsupported;
7159 }
7160 break;
7161 case TYPE_dbl:
7162 switch (tp) {
7163 case TYPE_dbl:
7164 nils = mul_flt_dbl_dbl(lft, incr1, rgt, incr2,
7165 dst, GDK_dbl_max, cnt,
7166 ci, candoff,
7167 abort_on_error);
7168 break;
7169 default:
7170 goto unsupported;
7171 }
7172 break;
7173 default:
7174 goto unsupported;
7175 }
7176 break;
7177 case TYPE_dbl:
7178 switch (tp2) {
7179 case TYPE_bte:
7180 switch (tp) {
7181 case TYPE_dbl:
7182 nils = mul_dbl_bte_dbl(lft, incr1, rgt, incr2,
7183 dst, GDK_dbl_max, cnt,
7184 ci, candoff,
7185 abort_on_error);
7186 break;
7187 default:
7188 goto unsupported;
7189 }
7190 break;
7191 case TYPE_sht:
7192 switch (tp) {
7193 case TYPE_dbl:
7194 nils = mul_dbl_sht_dbl(lft, incr1, rgt, incr2,
7195 dst, GDK_dbl_max, cnt,
7196 ci, candoff,
7197 abort_on_error);
7198 break;
7199 default:
7200 goto unsupported;
7201 }
7202 break;
7203 case TYPE_int:
7204 switch (tp) {
7205 case TYPE_dbl:
7206 nils = mul_dbl_int_dbl(lft, incr1, rgt, incr2,
7207 dst, GDK_dbl_max, cnt,
7208 ci, candoff,
7209 abort_on_error);
7210 break;
7211 default:
7212 goto unsupported;
7213 }
7214 break;
7215 case TYPE_lng:
7216 switch (tp) {
7217 case TYPE_dbl:
7218 nils = mul_dbl_lng_dbl(lft, incr1, rgt, incr2,
7219 dst, GDK_dbl_max, cnt,
7220 ci, candoff,
7221 abort_on_error);
7222 break;
7223 default:
7224 goto unsupported;
7225 }
7226 break;
7227#ifdef HAVE_HGE
7228 case TYPE_hge:
7229 switch (tp) {
7230 case TYPE_dbl:
7231 nils = mul_dbl_hge_dbl(lft, incr1, rgt, incr2,
7232 dst, GDK_dbl_max, cnt,
7233 ci, candoff,
7234 abort_on_error);
7235 break;
7236 default:
7237 goto unsupported;
7238 }
7239 break;
7240#endif
7241 case TYPE_flt:
7242 switch (tp) {
7243 case TYPE_dbl:
7244 nils = mul_dbl_flt_dbl(lft, incr1, rgt, incr2,
7245 dst, GDK_dbl_max, cnt,
7246 ci, candoff,
7247 abort_on_error);
7248 break;
7249 default:
7250 goto unsupported;
7251 }
7252 break;
7253 case TYPE_dbl:
7254 switch (tp) {
7255 case TYPE_dbl:
7256 nils = mul_dbl_dbl_dbl(lft, incr1, rgt, incr2,
7257 dst, GDK_dbl_max, cnt,
7258 ci, candoff,
7259 abort_on_error);
7260 break;
7261 default:
7262 goto unsupported;
7263 }
7264 break;
7265 default:
7266 goto unsupported;
7267 }
7268 break;
7269 default:
7270 goto unsupported;
7271 }
7272
7273 return nils;
7274
7275 unsupported:
7276 GDKerror("%s: type combination mul(%s,%s)->%s) not supported.\n",
7277 func, ATOMname(tp1), ATOMname(tp2), ATOMname(tp));
7278 return BUN_NONE;
7279}
7280
7281static BAT *
7282BATcalcmuldivmod(BAT *b1, BAT *b2, BAT *s, int tp, bool abort_on_error,
7283 BUN (*typeswitchloop)(const void *, int, int,
7284 const void *, int, int,
7285 void *restrict, int, BUN,
7286 struct canditer *restrict,
7287 oid, bool, const char *),
7288 const char *func)
7289{
7290 BAT *bn;
7291 BUN nils;
7292 BUN cnt, ncand;
7293 struct canditer ci;
7294
7295 BATcheck(b1, func, NULL);
7296 BATcheck(b2, func, NULL);
7297
7298 if (checkbats(b1, b2, func) != GDK_SUCCEED)
7299 return NULL;
7300
7301 cnt = BATcount(b1);
7302 ncand = canditer_init(&ci, b1, s);
7303 if (ncand == 0)
7304 return BATconstant(b1->hseqbase, tp, ATOMnilptr(tp),
7305 cnt, TRANSIENT);
7306
7307 bn = COLnew(b1->hseqbase, tp, cnt, TRANSIENT);
7308 if (bn == NULL)
7309 return NULL;
7310
7311 nils = (*typeswitchloop)(Tloc(b1, 0), b1->ttype, 1,
7312 Tloc(b2, 0), b2->ttype, 1,
7313 Tloc(bn, 0), tp,
7314 cnt, &ci, b1->hseqbase,
7315 abort_on_error, func);
7316
7317 if (nils >= BUN_NONE) {
7318 BBPunfix(bn->batCacheid);
7319 return NULL;
7320 }
7321
7322 BATsetcount(bn, cnt);
7323
7324 bn->tsorted = cnt <= 1 || nils == cnt;
7325 bn->trevsorted = cnt <= 1 || nils == cnt;
7326 bn->tkey = cnt <= 1;
7327 bn->tnil = nils != 0;
7328 bn->tnonil = nils == 0;
7329
7330 return bn;
7331}
7332
7333BAT *
7334BATcalcmul(BAT *b1, BAT *b2, BAT *s, int tp, bool abort_on_error)
7335{
7336 return BATcalcmuldivmod(b1, b2, s, tp, abort_on_error,
7337 mul_typeswitchloop, __func__);
7338}
7339
7340BAT *
7341BATcalcmulcst(BAT *b, const ValRecord *v, BAT *s, int tp, bool abort_on_error)
7342{
7343 BAT *bn;
7344 BUN nils;
7345 BUN cnt, ncand;
7346 struct canditer ci;
7347
7348 BATcheck(b, __func__, NULL);
7349
7350 cnt = BATcount(b);
7351 ncand = canditer_init(&ci, b, s);
7352 if (ncand == 0)
7353 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
7354 cnt, TRANSIENT);
7355
7356 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
7357 if (bn == NULL)
7358 return NULL;
7359
7360 nils = mul_typeswitchloop(Tloc(b, 0), b->ttype, 1,
7361 VALptr(v), v->vtype, 0,
7362 Tloc(bn, 0), tp,
7363 cnt, &ci, b->hseqbase,
7364 abort_on_error, __func__);
7365
7366 if (nils == BUN_NONE) {
7367 BBPunfix(bn->batCacheid);
7368 return NULL;
7369 }
7370
7371 BATsetcount(bn, cnt);
7372
7373 /* if the input is sorted, and no overflow occurred (we only
7374 * know for sure if abort_on_error is set), the result is also
7375 * sorted, or reverse sorted if the constant is negative */
7376 if (abort_on_error) {
7377 ValRecord sign;
7378
7379 VARcalcsign(&sign, v);
7380 bn->tsorted = (sign.val.btval >= 0 && b->tsorted && nils == 0) ||
7381 (sign.val.btval <= 0 && b->trevsorted && nils == 0) ||
7382 cnt <= 1 || nils == cnt;
7383 bn->trevsorted = (sign.val.btval >= 0 && b->trevsorted && nils == 0) ||
7384 (sign.val.btval <= 0 && b->tsorted && nils == 0) ||
7385 cnt <= 1 || nils == cnt;
7386 } else {
7387 bn->tsorted = cnt <= 1 || nils == cnt;
7388 bn->trevsorted = cnt <= 1 || nils == cnt;
7389 }
7390 bn->tkey = cnt <= 1;
7391 bn->tnil = nils != 0;
7392 bn->tnonil = nils == 0;
7393
7394 return bn;
7395}
7396
7397BAT *
7398BATcalccstmul(const ValRecord *v, BAT *b, BAT *s, int tp, bool abort_on_error)
7399{
7400 BAT *bn;
7401 BUN nils;
7402 BUN cnt, ncand;
7403 struct canditer ci;
7404
7405 BATcheck(b, __func__, NULL);
7406
7407 cnt = BATcount(b);
7408 ncand = canditer_init(&ci, b, s);
7409 if (ncand == 0)
7410 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
7411 cnt, TRANSIENT);
7412
7413 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
7414 if (bn == NULL)
7415 return NULL;
7416
7417 nils = mul_typeswitchloop(VALptr(v), v->vtype, 0,
7418 Tloc(b, 0), b->ttype, 1,
7419 Tloc(bn, 0), tp,
7420 cnt, &ci, b->hseqbase,
7421 abort_on_error, __func__);
7422
7423 if (nils == BUN_NONE) {
7424 BBPunfix(bn->batCacheid);
7425 return NULL;
7426 }
7427
7428 BATsetcount(bn, cnt);
7429
7430 /* if the input is sorted, and no overflow occurred (we only
7431 * know for sure if abort_on_error is set), the result is also
7432 * sorted, or reverse sorted if the constant is negative */
7433 if (abort_on_error) {
7434 ValRecord sign;
7435
7436 VARcalcsign(&sign, v);
7437 bn->tsorted = (sign.val.btval >= 0 && b->tsorted && nils == 0) ||
7438 (sign.val.btval <= 0 && b->trevsorted && nils == 0) ||
7439 cnt <= 1 || nils == cnt;
7440 bn->trevsorted = (sign.val.btval >= 0 && b->trevsorted && nils == 0) ||
7441 (sign.val.btval <= 0 && b->tsorted && nils == 0) ||
7442 cnt <= 1 || nils == cnt;
7443 } else {
7444 bn->tsorted = cnt <= 1 || nils == cnt;
7445 bn->trevsorted = cnt <= 1 || nils == cnt;
7446 }
7447 bn->tkey = cnt <= 1;
7448 bn->tnil = nils != 0;
7449 bn->tnonil = nils == 0;
7450
7451 return bn;
7452}
7453
7454gdk_return
7455VARcalcmul(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
7456 bool abort_on_error)
7457{
7458 if (mul_typeswitchloop(VALptr(lft), lft->vtype, 0,
7459 VALptr(rgt), rgt->vtype, 0,
7460 VALget(ret), ret->vtype, 1,
7461 &(struct canditer){.tpe=cand_dense, .ncand=1},
7462 0, abort_on_error, __func__) == BUN_NONE)
7463 return GDK_FAIL;
7464 return GDK_SUCCEED;
7465}
7466
7467/* ---------------------------------------------------------------------- */
7468/* division (any numeric type) */
7469
7470#define DIV_3TYPE(TYPE1, TYPE2, TYPE3) \
7471static BUN \
7472div_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
7473 const TYPE2 *rgt, int incr2, \
7474 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
7475 struct canditer *restrict ci, \
7476 oid candoff, bool abort_on_error) \
7477{ \
7478 oid x = canditer_next(ci) - candoff; \
7479 BUN i, j, k = 0; \
7480 BUN nils = 0; \
7481 \
7482 do { \
7483 while (k < x) { \
7484 dst[k++] = TYPE3##_nil; \
7485 nils++; \
7486 } \
7487 i = x * incr1; \
7488 j = x * incr2; \
7489 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
7490 dst[k] = TYPE3##_nil; \
7491 nils++; \
7492 } else if (rgt[j] == 0) { \
7493 if (abort_on_error) \
7494 return BUN_NONE + 1; \
7495 dst[k] = TYPE3##_nil; \
7496 nils++; \
7497 } else { \
7498 dst[k] = (TYPE3) (lft[i] / rgt[j]); \
7499 if (dst[k] < -max || dst[k] > max) { \
7500 if (abort_on_error) \
7501 return BUN_NONE + 2; \
7502 dst[k] = TYPE3##_nil; \
7503 nils++; \
7504 } \
7505 } \
7506 k++; \
7507 x = canditer_next(ci); \
7508 if (is_oid_nil(x)) \
7509 break; \
7510 x -= candoff; \
7511 } while (k < cnt); \
7512 while (k < cnt) { \
7513 dst[k++] = TYPE3##_nil; \
7514 nils++; \
7515 } \
7516 return nils; \
7517}
7518
7519#define DIV_3TYPE_float(TYPE1, TYPE2, TYPE3) \
7520static BUN \
7521div_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
7522 const TYPE2 *rgt, int incr2, \
7523 TYPE3 *restrict dst, TYPE3 max, BUN cnt, \
7524 struct canditer *restrict ci, \
7525 oid candoff, bool abort_on_error) \
7526{ \
7527 oid x = canditer_next(ci) - candoff; \
7528 BUN i, j, k = 0; \
7529 BUN nils = 0; \
7530 \
7531 do { \
7532 while (k < x) { \
7533 dst[k++] = TYPE3##_nil; \
7534 nils++; \
7535 } \
7536 i = x * incr1; \
7537 j = x * incr2; \
7538 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
7539 dst[k] = TYPE3##_nil; \
7540 nils++; \
7541 } else if (rgt[j] == 0 || \
7542 (ABSOLUTE(rgt[j]) < 1 && \
7543 GDK_##TYPE3##_max * ABSOLUTE(rgt[j]) < lft[i])) { \
7544 /* only check for overflow, not for underflow */ \
7545 if (abort_on_error) { \
7546 if (rgt[j] == 0) \
7547 return BUN_NONE + 1; \
7548 ON_OVERFLOW(TYPE1, TYPE2, "/"); \
7549 } \
7550 dst[k] = TYPE3##_nil; \
7551 nils++; \
7552 } else { \
7553 dst[k] = (TYPE3) lft[i] / rgt[j]; \
7554 if (dst[k] < -max || dst[k] > max) { \
7555 if (abort_on_error) \
7556 return BUN_NONE + 2; \
7557 dst[k] = TYPE3##_nil; \
7558 nils++; \
7559 } \
7560 } \
7561 k++; \
7562 x = canditer_next(ci); \
7563 if (is_oid_nil(x)) \
7564 break; \
7565 x -= candoff; \
7566 } while (k < cnt); \
7567 while (k < cnt) { \
7568 dst[k++] = TYPE3##_nil; \
7569 nils++; \
7570 } \
7571 return nils; \
7572}
7573
7574DIV_3TYPE(bte, bte, bte)
7575#ifdef FULL_IMPLEMENTATION
7576DIV_3TYPE(bte, bte, sht)
7577DIV_3TYPE(bte, bte, int)
7578DIV_3TYPE(bte, bte, lng)
7579#ifdef HAVE_HGE
7580DIV_3TYPE(bte, bte, hge)
7581#endif
7582#endif
7583DIV_3TYPE(bte, bte, flt)
7584DIV_3TYPE(bte, bte, dbl)
7585DIV_3TYPE(bte, sht, bte)
7586#ifdef FULL_IMPLEMENTATION
7587DIV_3TYPE(bte, sht, sht)
7588DIV_3TYPE(bte, sht, int)
7589DIV_3TYPE(bte, sht, lng)
7590#ifdef HAVE_HGE
7591DIV_3TYPE(bte, sht, hge)
7592#endif
7593#endif
7594DIV_3TYPE(bte, sht, flt)
7595DIV_3TYPE(bte, sht, dbl)
7596DIV_3TYPE(bte, int, bte)
7597#ifdef FULL_IMPLEMENTATION
7598DIV_3TYPE(bte, int, sht)
7599DIV_3TYPE(bte, int, int)
7600DIV_3TYPE(bte, int, lng)
7601#ifdef HAVE_HGE
7602DIV_3TYPE(bte, int, hge)
7603#endif
7604#endif
7605DIV_3TYPE(bte, int, flt)
7606DIV_3TYPE(bte, int, dbl)
7607DIV_3TYPE(bte, lng, bte)
7608#ifdef FULL_IMPLEMENTATION
7609DIV_3TYPE(bte, lng, sht)
7610DIV_3TYPE(bte, lng, int)
7611DIV_3TYPE(bte, lng, lng)
7612#ifdef HAVE_HGE
7613DIV_3TYPE(bte, lng, hge)
7614#endif
7615#endif
7616DIV_3TYPE(bte, lng, flt)
7617DIV_3TYPE(bte, lng, dbl)
7618#ifdef HAVE_HGE
7619DIV_3TYPE(bte, hge, bte)
7620#ifdef FULL_IMPLEMENTATION
7621DIV_3TYPE(bte, hge, sht)
7622DIV_3TYPE(bte, hge, int)
7623DIV_3TYPE(bte, hge, lng)
7624DIV_3TYPE(bte, hge, hge)
7625#endif
7626DIV_3TYPE(bte, hge, flt)
7627DIV_3TYPE(bte, hge, dbl)
7628#endif
7629DIV_3TYPE_float(bte, flt, flt)
7630DIV_3TYPE_float(bte, flt, dbl)
7631DIV_3TYPE_float(bte, dbl, dbl)
7632DIV_3TYPE(sht, bte, sht)
7633#ifdef FULL_IMPLEMENTATION
7634DIV_3TYPE(sht, bte, int)
7635DIV_3TYPE(sht, bte, lng)
7636#ifdef HAVE_HGE
7637DIV_3TYPE(sht, bte, hge)
7638#endif
7639#endif
7640DIV_3TYPE(sht, bte, flt)
7641DIV_3TYPE(sht, bte, dbl)
7642DIV_3TYPE(sht, sht, sht)
7643#ifdef FULL_IMPLEMENTATION
7644DIV_3TYPE(sht, sht, int)
7645DIV_3TYPE(sht, sht, lng)
7646#ifdef HAVE_HGE
7647DIV_3TYPE(sht, sht, hge)
7648#endif
7649#endif
7650DIV_3TYPE(sht, sht, flt)
7651DIV_3TYPE(sht, sht, dbl)
7652DIV_3TYPE(sht, int, sht)
7653#ifdef FULL_IMPLEMENTATION
7654DIV_3TYPE(sht, int, int)
7655DIV_3TYPE(sht, int, lng)
7656#ifdef HAVE_HGE
7657DIV_3TYPE(sht, int, hge)
7658#endif
7659#endif
7660DIV_3TYPE(sht, int, flt)
7661DIV_3TYPE(sht, int, dbl)
7662DIV_3TYPE(sht, lng, sht)
7663#ifdef FULL_IMPLEMENTATION
7664DIV_3TYPE(sht, lng, int)
7665DIV_3TYPE(sht, lng, lng)
7666#ifdef HAVE_HGE
7667DIV_3TYPE(sht, lng, hge)
7668#endif
7669#endif
7670DIV_3TYPE(sht, lng, flt)
7671DIV_3TYPE(sht, lng, dbl)
7672#ifdef HAVE_HGE
7673DIV_3TYPE(sht, hge, sht)
7674#ifdef FULL_IMPLEMENTATION
7675DIV_3TYPE(sht, hge, int)
7676DIV_3TYPE(sht, hge, lng)
7677DIV_3TYPE(sht, hge, hge)
7678#endif
7679DIV_3TYPE(sht, hge, flt)
7680DIV_3TYPE(sht, hge, dbl)
7681#endif
7682DIV_3TYPE_float(sht, flt, flt)
7683DIV_3TYPE_float(sht, flt, dbl)
7684DIV_3TYPE_float(sht, dbl, dbl)
7685DIV_3TYPE(int, bte, int)
7686#ifdef FULL_IMPLEMENTATION
7687DIV_3TYPE(int, bte, lng)
7688#ifdef HAVE_HGE
7689DIV_3TYPE(int, bte, hge)
7690#endif
7691#endif
7692DIV_3TYPE(int, bte, flt)
7693DIV_3TYPE(int, bte, dbl)
7694DIV_3TYPE(int, sht, int)
7695#ifdef FULL_IMPLEMENTATION
7696DIV_3TYPE(int, sht, lng)
7697#ifdef HAVE_HGE
7698DIV_3TYPE(int, sht, hge)
7699#endif
7700#endif
7701DIV_3TYPE(int, sht, flt)
7702DIV_3TYPE(int, sht, dbl)
7703DIV_3TYPE(int, int, int)
7704#ifdef FULL_IMPLEMENTATION
7705DIV_3TYPE(int, int, lng)
7706#ifdef HAVE_HGE
7707DIV_3TYPE(int, int, hge)
7708#endif
7709#endif
7710DIV_3TYPE(int, int, flt)
7711DIV_3TYPE(int, int, dbl)
7712DIV_3TYPE(int, lng, int)
7713#ifdef FULL_IMPLEMENTATION
7714DIV_3TYPE(int, lng, lng)
7715#ifdef HAVE_HGE
7716DIV_3TYPE(int, lng, hge)
7717#endif
7718#endif
7719DIV_3TYPE(int, lng, flt)
7720DIV_3TYPE(int, lng, dbl)
7721#ifdef HAVE_HGE
7722DIV_3TYPE(int, hge, int)
7723#ifdef FULL_IMPLEMENTATION
7724DIV_3TYPE(int, hge, lng)
7725DIV_3TYPE(int, hge, hge)
7726#endif
7727DIV_3TYPE(int, hge, flt)
7728DIV_3TYPE(int, hge, dbl)
7729#endif
7730DIV_3TYPE_float(int, flt, flt)
7731DIV_3TYPE_float(int, flt, dbl)
7732DIV_3TYPE_float(int, dbl, dbl)
7733DIV_3TYPE(lng, bte, lng)
7734#ifdef HAVE_HGE
7735#ifdef FULL_IMPLEMENTATION
7736DIV_3TYPE(lng, bte, hge)
7737#endif
7738#endif
7739DIV_3TYPE(lng, bte, flt)
7740DIV_3TYPE(lng, bte, dbl)
7741DIV_3TYPE(lng, sht, lng)
7742#ifdef FULL_IMPLEMENTATION
7743#ifdef HAVE_HGE
7744DIV_3TYPE(lng, sht, hge)
7745#endif
7746#endif
7747DIV_3TYPE(lng, sht, flt)
7748DIV_3TYPE(lng, sht, dbl)
7749DIV_3TYPE(lng, int, lng)
7750#ifdef FULL_IMPLEMENTATION
7751#ifdef HAVE_HGE
7752DIV_3TYPE(lng, int, hge)
7753#endif
7754#endif
7755DIV_3TYPE(lng, int, flt)
7756DIV_3TYPE(lng, int, dbl)
7757DIV_3TYPE(lng, lng, lng)
7758#ifdef FULL_IMPLEMENTATION
7759#ifdef HAVE_HGE
7760DIV_3TYPE(lng, lng, hge)
7761#endif
7762#endif
7763DIV_3TYPE(lng, lng, flt)
7764DIV_3TYPE(lng, lng, dbl)
7765#ifdef HAVE_HGE
7766DIV_3TYPE(lng, hge, lng)
7767#ifdef FULL_IMPLEMENTATION
7768DIV_3TYPE(lng, hge, hge)
7769#endif
7770DIV_3TYPE(lng, hge, flt)
7771DIV_3TYPE(lng, hge, dbl)
7772#endif
7773DIV_3TYPE_float(lng, flt, flt)
7774DIV_3TYPE_float(lng, flt, dbl)
7775DIV_3TYPE_float(lng, dbl, dbl)
7776#ifdef HAVE_HGE
7777DIV_3TYPE(hge, bte, hge)
7778DIV_3TYPE(hge, bte, flt)
7779DIV_3TYPE(hge, bte, dbl)
7780DIV_3TYPE(hge, sht, hge)
7781DIV_3TYPE(hge, sht, flt)
7782DIV_3TYPE(hge, sht, dbl)
7783DIV_3TYPE(hge, int, hge)
7784DIV_3TYPE(hge, int, flt)
7785DIV_3TYPE(hge, int, dbl)
7786DIV_3TYPE(hge, lng, hge)
7787DIV_3TYPE(hge, lng, flt)
7788DIV_3TYPE(hge, lng, dbl)
7789DIV_3TYPE(hge, hge, hge)
7790DIV_3TYPE(hge, hge, flt)
7791DIV_3TYPE(hge, hge, dbl)
7792DIV_3TYPE_float(hge, flt, flt)
7793DIV_3TYPE_float(hge, flt, dbl)
7794DIV_3TYPE_float(hge, dbl, dbl)
7795#endif
7796DIV_3TYPE(flt, bte, flt)
7797DIV_3TYPE(flt, bte, dbl)
7798DIV_3TYPE(flt, sht, flt)
7799DIV_3TYPE(flt, sht, dbl)
7800DIV_3TYPE(flt, int, flt)
7801DIV_3TYPE(flt, int, dbl)
7802DIV_3TYPE(flt, lng, flt)
7803DIV_3TYPE(flt, lng, dbl)
7804#ifdef HAVE_HGE
7805DIV_3TYPE(flt, hge, flt)
7806DIV_3TYPE(flt, hge, dbl)
7807#endif
7808DIV_3TYPE_float(flt, flt, flt)
7809DIV_3TYPE_float(flt, flt, dbl)
7810DIV_3TYPE_float(flt, dbl, dbl)
7811DIV_3TYPE(dbl, bte, dbl)
7812DIV_3TYPE(dbl, sht, dbl)
7813DIV_3TYPE(dbl, int, dbl)
7814DIV_3TYPE(dbl, lng, dbl)
7815#ifdef HAVE_HGE
7816DIV_3TYPE(dbl, hge, dbl)
7817#endif
7818DIV_3TYPE_float(dbl, flt, dbl)
7819DIV_3TYPE_float(dbl, dbl, dbl)
7820
7821static BUN
7822div_typeswitchloop(const void *lft, int tp1, int incr1,
7823 const void *rgt, int tp2, int incr2,
7824 void *restrict dst, int tp, BUN cnt,
7825 struct canditer *restrict ci, oid candoff,
7826 bool abort_on_error, const char *func)
7827{
7828 BUN nils;
7829
7830 tp1 = ATOMbasetype(tp1);
7831 tp2 = ATOMbasetype(tp2);
7832 tp = ATOMbasetype(tp);
7833 switch (tp1) {
7834 case TYPE_bte:
7835 switch (tp2) {
7836 case TYPE_bte:
7837 switch (tp) {
7838 case TYPE_bte:
7839 nils = div_bte_bte_bte(lft, incr1, rgt, incr2,
7840 dst, GDK_bte_max, cnt,
7841 ci, candoff,
7842 abort_on_error);
7843 break;
7844#ifdef FULL_IMPLEMENTATION
7845 case TYPE_sht:
7846 nils = div_bte_bte_sht(lft, incr1, rgt, incr2,
7847 dst, GDK_sht_max, cnt,
7848 ci, candoff,
7849 abort_on_error);
7850 break;
7851 case TYPE_int:
7852 nils = div_bte_bte_int(lft, incr1, rgt, incr2,
7853 dst, GDK_int_max, cnt,
7854 ci, candoff,
7855 abort_on_error);
7856 break;
7857 case TYPE_lng:
7858 nils = div_bte_bte_lng(lft, incr1, rgt, incr2,
7859 dst, GDK_lng_max, cnt,
7860 ci, candoff,
7861 abort_on_error);
7862 break;
7863#ifdef HAVE_HGE
7864 case TYPE_hge:
7865 nils = div_bte_bte_hge(lft, incr1, rgt, incr2,
7866 dst, GDK_hge_max, cnt,
7867 ci, candoff,
7868 abort_on_error);
7869 break;
7870#endif
7871#endif
7872 case TYPE_flt:
7873 nils = div_bte_bte_flt(lft, incr1, rgt, incr2,
7874 dst, GDK_flt_max, cnt,
7875 ci, candoff,
7876 abort_on_error);
7877 break;
7878 case TYPE_dbl:
7879 nils = div_bte_bte_dbl(lft, incr1, rgt, incr2,
7880 dst, GDK_dbl_max, cnt,
7881 ci, candoff,
7882 abort_on_error);
7883 break;
7884 default:
7885 goto unsupported;
7886 }
7887 break;
7888 case TYPE_sht:
7889 switch (tp) {
7890 case TYPE_bte:
7891 nils = div_bte_sht_bte(lft, incr1, rgt, incr2,
7892 dst, GDK_bte_max, cnt,
7893 ci, candoff,
7894 abort_on_error);
7895 break;
7896#ifdef FULL_IMPLEMENTATION
7897 case TYPE_sht:
7898 nils = div_bte_sht_sht(lft, incr1, rgt, incr2,
7899 dst, GDK_sht_max, cnt,
7900 ci, candoff,
7901 abort_on_error);
7902 break;
7903 case TYPE_int:
7904 nils = div_bte_sht_int(lft, incr1, rgt, incr2,
7905 dst, GDK_int_max, cnt,
7906 ci, candoff,
7907 abort_on_error);
7908 break;
7909 case TYPE_lng:
7910 nils = div_bte_sht_lng(lft, incr1, rgt, incr2,
7911 dst, GDK_lng_max, cnt,
7912 ci, candoff,
7913 abort_on_error);
7914 break;
7915#ifdef HAVE_HGE
7916 case TYPE_hge:
7917 nils = div_bte_sht_hge(lft, incr1, rgt, incr2,
7918 dst, GDK_hge_max, cnt,
7919 ci, candoff,
7920 abort_on_error);
7921 break;
7922#endif
7923#endif
7924 case TYPE_flt:
7925 nils = div_bte_sht_flt(lft, incr1, rgt, incr2,
7926 dst, GDK_flt_max, cnt,
7927 ci, candoff,
7928 abort_on_error);
7929 break;
7930 case TYPE_dbl:
7931 nils = div_bte_sht_dbl(lft, incr1, rgt, incr2,
7932 dst, GDK_dbl_max, cnt,
7933 ci, candoff,
7934 abort_on_error);
7935 break;
7936 default:
7937 goto unsupported;
7938 }
7939 break;
7940 case TYPE_int:
7941 switch (tp) {
7942 case TYPE_bte:
7943 nils = div_bte_int_bte(lft, incr1, rgt, incr2,
7944 dst, GDK_bte_max, cnt,
7945 ci, candoff,
7946 abort_on_error);
7947 break;
7948#ifdef FULL_IMPLEMENTATION
7949 case TYPE_sht:
7950 nils = div_bte_int_sht(lft, incr1, rgt, incr2,
7951 dst, GDK_sht_max, cnt,
7952 ci, candoff,
7953 abort_on_error);
7954 break;
7955 case TYPE_int:
7956 nils = div_bte_int_int(lft, incr1, rgt, incr2,
7957 dst, GDK_int_max, cnt,
7958 ci, candoff,
7959 abort_on_error);
7960 break;
7961 case TYPE_lng:
7962 nils = div_bte_int_lng(lft, incr1, rgt, incr2,
7963 dst, GDK_lng_max, cnt,
7964 ci, candoff,
7965 abort_on_error);
7966 break;
7967#ifdef HAVE_HGE
7968 case TYPE_hge:
7969 nils = div_bte_int_hge(lft, incr1, rgt, incr2,
7970 dst, GDK_hge_max, cnt,
7971 ci, candoff,
7972 abort_on_error);
7973 break;
7974#endif
7975#endif
7976 case TYPE_flt:
7977 nils = div_bte_int_flt(lft, incr1, rgt, incr2,
7978 dst, GDK_flt_max, cnt,
7979 ci, candoff,
7980 abort_on_error);
7981 break;
7982 case TYPE_dbl:
7983 nils = div_bte_int_dbl(lft, incr1, rgt, incr2,
7984 dst, GDK_dbl_max, cnt,
7985 ci, candoff,
7986 abort_on_error);
7987 break;
7988 default:
7989 goto unsupported;
7990 }
7991 break;
7992 case TYPE_lng:
7993 switch (tp) {
7994 case TYPE_bte:
7995 nils = div_bte_lng_bte(lft, incr1, rgt, incr2,
7996 dst, GDK_bte_max, cnt,
7997 ci, candoff,
7998 abort_on_error);
7999 break;
8000#ifdef FULL_IMPLEMENTATION
8001 case TYPE_sht:
8002 nils = div_bte_lng_sht(lft, incr1, rgt, incr2,
8003 dst, GDK_sht_max, cnt,
8004 ci, candoff,
8005 abort_on_error);
8006 break;
8007 case TYPE_int:
8008 nils = div_bte_lng_int(lft, incr1, rgt, incr2,
8009 dst, GDK_int_max, cnt,
8010 ci, candoff,
8011 abort_on_error);
8012 break;
8013 case TYPE_lng:
8014 nils = div_bte_lng_lng(lft, incr1, rgt, incr2,
8015 dst, GDK_lng_max, cnt,
8016 ci, candoff,
8017 abort_on_error);
8018 break;
8019#ifdef HAVE_HGE
8020 case TYPE_hge:
8021 nils = div_bte_lng_hge(lft, incr1, rgt, incr2,
8022 dst, GDK_hge_max, cnt,
8023 ci, candoff,
8024 abort_on_error);
8025 break;
8026#endif
8027#endif
8028 case TYPE_flt:
8029 nils = div_bte_lng_flt(lft, incr1, rgt, incr2,
8030 dst, GDK_flt_max, cnt,
8031 ci, candoff,
8032 abort_on_error);
8033 break;
8034 case TYPE_dbl:
8035 nils = div_bte_lng_dbl(lft, incr1, rgt, incr2,
8036 dst, GDK_dbl_max, cnt,
8037 ci, candoff,
8038 abort_on_error);
8039 break;
8040 default:
8041 goto unsupported;
8042 }
8043 break;
8044#ifdef HAVE_HGE
8045 case TYPE_hge:
8046 switch (tp) {
8047 case TYPE_bte:
8048 nils = div_bte_hge_bte(lft, incr1, rgt, incr2,
8049 dst, GDK_bte_max, cnt,
8050 ci, candoff,
8051 abort_on_error);
8052 break;
8053#ifdef FULL_IMPLEMENTATION
8054 case TYPE_sht:
8055 nils = div_bte_hge_sht(lft, incr1, rgt, incr2,
8056 dst, GDK_sht_max, cnt,
8057 ci, candoff,
8058 abort_on_error);
8059 break;
8060 case TYPE_int:
8061 nils = div_bte_hge_int(lft, incr1, rgt, incr2,
8062 dst, GDK_int_max, cnt,
8063 ci, candoff,
8064 abort_on_error);
8065 break;
8066 case TYPE_lng:
8067 nils = div_bte_hge_lng(lft, incr1, rgt, incr2,
8068 dst, GDK_lng_max, cnt,
8069 ci, candoff,
8070 abort_on_error);
8071 break;
8072 case TYPE_hge:
8073 nils = div_bte_hge_hge(lft, incr1, rgt, incr2,
8074 dst, GDK_hge_max, cnt,
8075 ci, candoff,
8076 abort_on_error);
8077 break;
8078#endif
8079 case TYPE_flt:
8080 nils = div_bte_hge_flt(lft, incr1, rgt, incr2,
8081 dst, GDK_flt_max, cnt,
8082 ci, candoff,
8083 abort_on_error);
8084 break;
8085 case TYPE_dbl:
8086 nils = div_bte_hge_dbl(lft, incr1, rgt, incr2,
8087 dst, GDK_dbl_max, cnt,
8088 ci, candoff,
8089 abort_on_error);
8090 break;
8091 default:
8092 goto unsupported;
8093 }
8094 break;
8095#endif
8096 case TYPE_flt:
8097 switch (tp) {
8098 case TYPE_flt:
8099 nils = div_bte_flt_flt(lft, incr1, rgt, incr2,
8100 dst, GDK_flt_max, cnt,
8101 ci, candoff,
8102 abort_on_error);
8103 break;
8104 case TYPE_dbl:
8105 nils = div_bte_flt_dbl(lft, incr1, rgt, incr2,
8106 dst, GDK_dbl_max, cnt,
8107 ci, candoff,
8108 abort_on_error);
8109 break;
8110 default:
8111 goto unsupported;
8112 }
8113 break;
8114 case TYPE_dbl:
8115 switch (tp) {
8116 case TYPE_dbl:
8117 nils = div_bte_dbl_dbl(lft, incr1, rgt, incr2,
8118 dst, GDK_dbl_max, cnt,
8119 ci, candoff,
8120 abort_on_error);
8121 break;
8122 default:
8123 goto unsupported;
8124 }
8125 break;
8126 default:
8127 goto unsupported;
8128 }
8129 break;
8130 case TYPE_sht:
8131 switch (tp2) {
8132 case TYPE_bte:
8133 switch (tp) {
8134 case TYPE_sht:
8135 nils = div_sht_bte_sht(lft, incr1, rgt, incr2,
8136 dst, GDK_sht_max, cnt,
8137 ci, candoff,
8138 abort_on_error);
8139 break;
8140#ifdef FULL_IMPLEMENTATION
8141 case TYPE_int:
8142 nils = div_sht_bte_int(lft, incr1, rgt, incr2,
8143 dst, GDK_int_max, cnt,
8144 ci, candoff,
8145 abort_on_error);
8146 break;
8147 case TYPE_lng:
8148 nils = div_sht_bte_lng(lft, incr1, rgt, incr2,
8149 dst, GDK_lng_max, cnt,
8150 ci, candoff,
8151 abort_on_error);
8152 break;
8153#ifdef HAVE_HGE
8154 case TYPE_hge:
8155 nils = div_sht_bte_hge(lft, incr1, rgt, incr2,
8156 dst, GDK_hge_max, cnt,
8157 ci, candoff,
8158 abort_on_error);
8159 break;
8160#endif
8161#endif
8162 case TYPE_flt:
8163 nils = div_sht_bte_flt(lft, incr1, rgt, incr2,
8164 dst, GDK_flt_max, cnt,
8165 ci, candoff,
8166 abort_on_error);
8167 break;
8168 case TYPE_dbl:
8169 nils = div_sht_bte_dbl(lft, incr1, rgt, incr2,
8170 dst, GDK_dbl_max, cnt,
8171 ci, candoff,
8172 abort_on_error);
8173 break;
8174 default:
8175 goto unsupported;
8176 }
8177 break;
8178 case TYPE_sht:
8179 switch (tp) {
8180 case TYPE_sht:
8181 nils = div_sht_sht_sht(lft, incr1, rgt, incr2,
8182 dst, GDK_sht_max, cnt,
8183 ci, candoff,
8184 abort_on_error);
8185 break;
8186#ifdef FULL_IMPLEMENTATION
8187 case TYPE_int:
8188 nils = div_sht_sht_int(lft, incr1, rgt, incr2,
8189 dst, GDK_int_max, cnt,
8190 ci, candoff,
8191 abort_on_error);
8192 break;
8193 case TYPE_lng:
8194 nils = div_sht_sht_lng(lft, incr1, rgt, incr2,
8195 dst, GDK_lng_max, cnt,
8196 ci, candoff,
8197 abort_on_error);
8198 break;
8199#ifdef HAVE_HGE
8200 case TYPE_hge:
8201 nils = div_sht_sht_hge(lft, incr1, rgt, incr2,
8202 dst, GDK_hge_max, cnt,
8203 ci, candoff,
8204 abort_on_error);
8205 break;
8206#endif
8207#endif
8208 case TYPE_flt:
8209 nils = div_sht_sht_flt(lft, incr1, rgt, incr2,
8210 dst, GDK_flt_max, cnt,
8211 ci, candoff,
8212 abort_on_error);
8213 break;
8214 case TYPE_dbl:
8215 nils = div_sht_sht_dbl(lft, incr1, rgt, incr2,
8216 dst, GDK_dbl_max, cnt,
8217 ci, candoff,
8218 abort_on_error);
8219 break;
8220 default:
8221 goto unsupported;
8222 }
8223 break;
8224 case TYPE_int:
8225 switch (tp) {
8226 case TYPE_sht:
8227 nils = div_sht_int_sht(lft, incr1, rgt, incr2,
8228 dst, GDK_sht_max, cnt,
8229 ci, candoff,
8230 abort_on_error);
8231 break;
8232#ifdef FULL_IMPLEMENTATION
8233 case TYPE_int:
8234 nils = div_sht_int_int(lft, incr1, rgt, incr2,
8235 dst, GDK_int_max, cnt,
8236 ci, candoff,
8237 abort_on_error);
8238 break;
8239 case TYPE_lng:
8240 nils = div_sht_int_lng(lft, incr1, rgt, incr2,
8241 dst, GDK_lng_max, cnt,
8242 ci, candoff,
8243 abort_on_error);
8244 break;
8245#ifdef HAVE_HGE
8246 case TYPE_hge:
8247 nils = div_sht_int_hge(lft, incr1, rgt, incr2,
8248 dst, GDK_hge_max, cnt,
8249 ci, candoff,
8250 abort_on_error);
8251 break;
8252#endif
8253#endif
8254 case TYPE_flt:
8255 nils = div_sht_int_flt(lft, incr1, rgt, incr2,
8256 dst, GDK_flt_max, cnt,
8257 ci, candoff,
8258 abort_on_error);
8259 break;
8260 case TYPE_dbl:
8261 nils = div_sht_int_dbl(lft, incr1, rgt, incr2,
8262 dst, GDK_dbl_max, cnt,
8263 ci, candoff,
8264 abort_on_error);
8265 break;
8266 default:
8267 goto unsupported;
8268 }
8269 break;
8270 case TYPE_lng:
8271 switch (tp) {
8272 case TYPE_sht:
8273 nils = div_sht_lng_sht(lft, incr1, rgt, incr2,
8274 dst, GDK_sht_max, cnt,
8275 ci, candoff,
8276 abort_on_error);
8277 break;
8278#ifdef FULL_IMPLEMENTATION
8279 case TYPE_int:
8280 nils = div_sht_lng_int(lft, incr1, rgt, incr2,
8281 dst, GDK_int_max, cnt,
8282 ci, candoff,
8283 abort_on_error);
8284 break;
8285 case TYPE_lng:
8286 nils = div_sht_lng_lng(lft, incr1, rgt, incr2,
8287 dst, GDK_lng_max, cnt,
8288 ci, candoff,
8289 abort_on_error);
8290 break;
8291#ifdef HAVE_HGE
8292 case TYPE_hge:
8293 nils = div_sht_lng_hge(lft, incr1, rgt, incr2,
8294 dst, GDK_hge_max, cnt,
8295 ci, candoff,
8296 abort_on_error);
8297 break;
8298#endif
8299#endif
8300 case TYPE_flt:
8301 nils = div_sht_lng_flt(lft, incr1, rgt, incr2,
8302 dst, GDK_flt_max, cnt,
8303 ci, candoff,
8304 abort_on_error);
8305 break;
8306 case TYPE_dbl:
8307 nils = div_sht_lng_dbl(lft, incr1, rgt, incr2,
8308 dst, GDK_dbl_max, cnt,
8309 ci, candoff,
8310 abort_on_error);
8311 break;
8312 default:
8313 goto unsupported;
8314 }
8315 break;
8316#ifdef HAVE_HGE
8317 case TYPE_hge:
8318 switch (tp) {
8319 case TYPE_sht:
8320 nils = div_sht_hge_sht(lft, incr1, rgt, incr2,
8321 dst, GDK_sht_max, cnt,
8322 ci, candoff,
8323 abort_on_error);
8324 break;
8325#ifdef FULL_IMPLEMENTATION
8326 case TYPE_int:
8327 nils = div_sht_hge_int(lft, incr1, rgt, incr2,
8328 dst, GDK_int_max, cnt,
8329 ci, candoff,
8330 abort_on_error);
8331 break;
8332 case TYPE_lng:
8333 nils = div_sht_hge_lng(lft, incr1, rgt, incr2,
8334 dst, GDK_lng_max, cnt,
8335 ci, candoff,
8336 abort_on_error);
8337 break;
8338 case TYPE_hge:
8339 nils = div_sht_hge_hge(lft, incr1, rgt, incr2,
8340 dst, GDK_hge_max, cnt,
8341 ci, candoff,
8342 abort_on_error);
8343 break;
8344#endif
8345 case TYPE_flt:
8346 nils = div_sht_hge_flt(lft, incr1, rgt, incr2,
8347 dst, GDK_flt_max, cnt,
8348 ci, candoff,
8349 abort_on_error);
8350 break;
8351 case TYPE_dbl:
8352 nils = div_sht_hge_dbl(lft, incr1, rgt, incr2,
8353 dst, GDK_dbl_max, cnt,
8354 ci, candoff,
8355 abort_on_error);
8356 break;
8357 default:
8358 goto unsupported;
8359 }
8360 break;
8361#endif
8362 case TYPE_flt:
8363 switch (tp) {
8364 case TYPE_flt:
8365 nils = div_sht_flt_flt(lft, incr1, rgt, incr2,
8366 dst, GDK_flt_max, cnt,
8367 ci, candoff,
8368 abort_on_error);
8369 break;
8370 case TYPE_dbl:
8371 nils = div_sht_flt_dbl(lft, incr1, rgt, incr2,
8372 dst, GDK_dbl_max, cnt,
8373 ci, candoff,
8374 abort_on_error);
8375 break;
8376 default:
8377 goto unsupported;
8378 }
8379 break;
8380 case TYPE_dbl:
8381 switch (tp) {
8382 case TYPE_dbl:
8383 nils = div_sht_dbl_dbl(lft, incr1, rgt, incr2,
8384 dst, GDK_dbl_max, cnt,
8385 ci, candoff,
8386 abort_on_error);
8387 break;
8388 default:
8389 goto unsupported;
8390 }
8391 break;
8392 default:
8393 goto unsupported;
8394 }
8395 break;
8396 case TYPE_int:
8397 switch (tp2) {
8398 case TYPE_bte:
8399 switch (tp) {
8400 case TYPE_int:
8401 nils = div_int_bte_int(lft, incr1, rgt, incr2,
8402 dst, GDK_int_max, cnt,
8403 ci, candoff,
8404 abort_on_error);
8405 break;
8406#ifdef FULL_IMPLEMENTATION
8407 case TYPE_lng:
8408 nils = div_int_bte_lng(lft, incr1, rgt, incr2,
8409 dst, GDK_lng_max, cnt,
8410 ci, candoff,
8411 abort_on_error);
8412 break;
8413#ifdef HAVE_HGE
8414 case TYPE_hge:
8415 nils = div_int_bte_hge(lft, incr1, rgt, incr2,
8416 dst, GDK_hge_max, cnt,
8417 ci, candoff,
8418 abort_on_error);
8419 break;
8420#endif
8421#endif
8422 case TYPE_flt:
8423 nils = div_int_bte_flt(lft, incr1, rgt, incr2,
8424 dst, GDK_flt_max, cnt,
8425 ci, candoff,
8426 abort_on_error);
8427 break;
8428 case TYPE_dbl:
8429 nils = div_int_bte_dbl(lft, incr1, rgt, incr2,
8430 dst, GDK_dbl_max, cnt,
8431 ci, candoff,
8432 abort_on_error);
8433 break;
8434 default:
8435 goto unsupported;
8436 }
8437 break;
8438 case TYPE_sht:
8439 switch (tp) {
8440 case TYPE_int:
8441 nils = div_int_sht_int(lft, incr1, rgt, incr2,
8442 dst, GDK_int_max, cnt,
8443 ci, candoff,
8444 abort_on_error);
8445 break;
8446#ifdef FULL_IMPLEMENTATION
8447 case TYPE_lng:
8448 nils = div_int_sht_lng(lft, incr1, rgt, incr2,
8449 dst, GDK_lng_max, cnt,
8450 ci, candoff,
8451 abort_on_error);
8452 break;
8453#ifdef HAVE_HGE
8454 case TYPE_hge:
8455 nils = div_int_sht_hge(lft, incr1, rgt, incr2,
8456 dst, GDK_hge_max, cnt,
8457 ci, candoff,
8458 abort_on_error);
8459 break;
8460#endif
8461#endif
8462 case TYPE_flt:
8463 nils = div_int_sht_flt(lft, incr1, rgt, incr2,
8464 dst, GDK_flt_max, cnt,
8465 ci, candoff,
8466 abort_on_error);
8467 break;
8468 case TYPE_dbl:
8469 nils = div_int_sht_dbl(lft, incr1, rgt, incr2,
8470 dst, GDK_dbl_max, cnt,
8471 ci, candoff,
8472 abort_on_error);
8473 break;
8474 default:
8475 goto unsupported;
8476 }
8477 break;
8478 case TYPE_int:
8479 switch (tp) {
8480 case TYPE_int:
8481 nils = div_int_int_int(lft, incr1, rgt, incr2,
8482 dst, GDK_int_max, cnt,
8483 ci, candoff,
8484 abort_on_error);
8485 break;
8486#ifdef FULL_IMPLEMENTATION
8487 case TYPE_lng:
8488 nils = div_int_int_lng(lft, incr1, rgt, incr2,
8489 dst, GDK_lng_max, cnt,
8490 ci, candoff,
8491 abort_on_error);
8492 break;
8493#ifdef HAVE_HGE
8494 case TYPE_hge:
8495 nils = div_int_int_hge(lft, incr1, rgt, incr2,
8496 dst, GDK_hge_max, cnt,
8497 ci, candoff,
8498 abort_on_error);
8499 break;
8500#endif
8501#endif
8502 case TYPE_flt:
8503 nils = div_int_int_flt(lft, incr1, rgt, incr2,
8504 dst, GDK_flt_max, cnt,
8505 ci, candoff,
8506 abort_on_error);
8507 break;
8508 case TYPE_dbl:
8509 nils = div_int_int_dbl(lft, incr1, rgt, incr2,
8510 dst, GDK_dbl_max, cnt,
8511 ci, candoff,
8512 abort_on_error);
8513 break;
8514 default:
8515 goto unsupported;
8516 }
8517 break;
8518 case TYPE_lng:
8519 switch (tp) {
8520 case TYPE_int:
8521 nils = div_int_lng_int(lft, incr1, rgt, incr2,
8522 dst, GDK_int_max, cnt,
8523 ci, candoff,
8524 abort_on_error);
8525 break;
8526#ifdef FULL_IMPLEMENTATION
8527 case TYPE_lng:
8528 nils = div_int_lng_lng(lft, incr1, rgt, incr2,
8529 dst, GDK_lng_max, cnt,
8530 ci, candoff,
8531 abort_on_error);
8532 break;
8533#ifdef HAVE_HGE
8534 case TYPE_hge:
8535 nils = div_int_lng_hge(lft, incr1, rgt, incr2,
8536 dst, GDK_hge_max, cnt,
8537 ci, candoff,
8538 abort_on_error);
8539 break;
8540#endif
8541#endif
8542 case TYPE_flt:
8543 nils = div_int_lng_flt(lft, incr1, rgt, incr2,
8544 dst, GDK_flt_max, cnt,
8545 ci, candoff,
8546 abort_on_error);
8547 break;
8548 case TYPE_dbl:
8549 nils = div_int_lng_dbl(lft, incr1, rgt, incr2,
8550 dst, GDK_dbl_max, cnt,
8551 ci, candoff,
8552 abort_on_error);
8553 break;
8554 default:
8555 goto unsupported;
8556 }
8557 break;
8558#ifdef HAVE_HGE
8559 case TYPE_hge:
8560 switch (tp) {
8561 case TYPE_int:
8562 nils = div_int_hge_int(lft, incr1, rgt, incr2,
8563 dst, GDK_int_max, cnt,
8564 ci, candoff,
8565 abort_on_error);
8566 break;
8567#ifdef FULL_IMPLEMENTATION
8568 case TYPE_lng:
8569 nils = div_int_hge_lng(lft, incr1, rgt, incr2,
8570 dst, GDK_lng_max, cnt,
8571 ci, candoff,
8572 abort_on_error);
8573 break;
8574 case TYPE_hge:
8575 nils = div_int_hge_hge(lft, incr1, rgt, incr2,
8576 dst, GDK_hge_max, cnt,
8577 ci, candoff,
8578 abort_on_error);
8579 break;
8580#endif
8581 case TYPE_flt:
8582 nils = div_int_hge_flt(lft, incr1, rgt, incr2,
8583 dst, GDK_flt_max, cnt,
8584 ci, candoff,
8585 abort_on_error);
8586 break;
8587 case TYPE_dbl:
8588 nils = div_int_hge_dbl(lft, incr1, rgt, incr2,
8589 dst, GDK_dbl_max, cnt,
8590 ci, candoff,
8591 abort_on_error);
8592 break;
8593 default:
8594 goto unsupported;
8595 }
8596 break;
8597#endif
8598 case TYPE_flt:
8599 switch (tp) {
8600 case TYPE_flt:
8601 nils = div_int_flt_flt(lft, incr1, rgt, incr2,
8602 dst, GDK_flt_max, cnt,
8603 ci, candoff,
8604 abort_on_error);
8605 break;
8606 case TYPE_dbl:
8607 nils = div_int_flt_dbl(lft, incr1, rgt, incr2,
8608 dst, GDK_dbl_max, cnt,
8609 ci, candoff,
8610 abort_on_error);
8611 break;
8612 default:
8613 goto unsupported;
8614 }
8615 break;
8616 case TYPE_dbl:
8617 switch (tp) {
8618 case TYPE_dbl:
8619 nils = div_int_dbl_dbl(lft, incr1, rgt, incr2,
8620 dst, GDK_dbl_max, cnt,
8621 ci, candoff,
8622 abort_on_error);
8623 break;
8624 default:
8625 goto unsupported;
8626 }
8627 break;
8628 default:
8629 goto unsupported;
8630 }
8631 break;
8632 case TYPE_lng:
8633 switch (tp2) {
8634 case TYPE_bte:
8635 switch (tp) {
8636 case TYPE_lng:
8637 nils = div_lng_bte_lng(lft, incr1, rgt, incr2,
8638 dst, GDK_lng_max, cnt,
8639 ci, candoff,
8640 abort_on_error);
8641 break;
8642#ifdef FULL_IMPLEMENTATION
8643#ifdef HAVE_HGE
8644 case TYPE_hge:
8645 nils = div_lng_bte_hge(lft, incr1, rgt, incr2,
8646 dst, GDK_hge_max, cnt,
8647 ci, candoff,
8648 abort_on_error);
8649 break;
8650#endif
8651#endif
8652 case TYPE_flt:
8653 nils = div_lng_bte_flt(lft, incr1, rgt, incr2,
8654 dst, GDK_flt_max, cnt,
8655 ci, candoff,
8656 abort_on_error);
8657 break;
8658 case TYPE_dbl:
8659 nils = div_lng_bte_dbl(lft, incr1, rgt, incr2,
8660 dst, GDK_dbl_max, cnt,
8661 ci, candoff,
8662 abort_on_error);
8663 break;
8664 default:
8665 goto unsupported;
8666 }
8667 break;
8668 case TYPE_sht:
8669 switch (tp) {
8670 case TYPE_lng:
8671 nils = div_lng_sht_lng(lft, incr1, rgt, incr2,
8672 dst, GDK_lng_max, cnt,
8673 ci, candoff,
8674 abort_on_error);
8675 break;
8676#ifdef FULL_IMPLEMENTATION
8677#ifdef HAVE_HGE
8678 case TYPE_hge:
8679 nils = div_lng_sht_hge(lft, incr1, rgt, incr2,
8680 dst, GDK_hge_max, cnt,
8681 ci, candoff,
8682 abort_on_error);
8683 break;
8684#endif
8685#endif
8686 case TYPE_flt:
8687 nils = div_lng_sht_flt(lft, incr1, rgt, incr2,
8688 dst, GDK_flt_max, cnt,
8689 ci, candoff,
8690 abort_on_error);
8691 break;
8692 case TYPE_dbl:
8693 nils = div_lng_sht_dbl(lft, incr1, rgt, incr2,
8694 dst, GDK_dbl_max, cnt,
8695 ci, candoff,
8696 abort_on_error);
8697 break;
8698 default:
8699 goto unsupported;
8700 }
8701 break;
8702 case TYPE_int:
8703 switch (tp) {
8704 case TYPE_lng:
8705 nils = div_lng_int_lng(lft, incr1, rgt, incr2,
8706 dst, GDK_lng_max, cnt,
8707 ci, candoff,
8708 abort_on_error);
8709 break;
8710#ifdef FULL_IMPLEMENTATION
8711#ifdef HAVE_HGE
8712 case TYPE_hge:
8713 nils = div_lng_int_hge(lft, incr1, rgt, incr2,
8714 dst, GDK_hge_max, cnt,
8715 ci, candoff,
8716 abort_on_error);
8717 break;
8718#endif
8719#endif
8720 case TYPE_flt:
8721 nils = div_lng_int_flt(lft, incr1, rgt, incr2,
8722 dst, GDK_flt_max, cnt,
8723 ci, candoff,
8724 abort_on_error);
8725 break;
8726 case TYPE_dbl:
8727 nils = div_lng_int_dbl(lft, incr1, rgt, incr2,
8728 dst, GDK_dbl_max, cnt,
8729 ci, candoff,
8730 abort_on_error);
8731 break;
8732 default:
8733 goto unsupported;
8734 }
8735 break;
8736 case TYPE_lng:
8737 switch (tp) {
8738 case TYPE_lng:
8739 nils = div_lng_lng_lng(lft, incr1, rgt, incr2,
8740 dst, GDK_lng_max, cnt,
8741 ci, candoff,
8742 abort_on_error);
8743 break;
8744#ifdef FULL_IMPLEMENTATION
8745#ifdef HAVE_HGE
8746 case TYPE_hge:
8747 nils = div_lng_lng_hge(lft, incr1, rgt, incr2,
8748 dst, GDK_hge_max, cnt,
8749 ci, candoff,
8750 abort_on_error);
8751 break;
8752#endif
8753#endif
8754 case TYPE_flt:
8755 nils = div_lng_lng_flt(lft, incr1, rgt, incr2,
8756 dst, GDK_flt_max, cnt,
8757 ci, candoff,
8758 abort_on_error);
8759 break;
8760 case TYPE_dbl:
8761 nils = div_lng_lng_dbl(lft, incr1, rgt, incr2,
8762 dst, GDK_dbl_max, cnt,
8763 ci, candoff,
8764 abort_on_error);
8765 break;
8766 default:
8767 goto unsupported;
8768 }
8769 break;
8770#ifdef HAVE_HGE
8771 case TYPE_hge:
8772 switch (tp) {
8773 case TYPE_lng:
8774 nils = div_lng_hge_lng(lft, incr1, rgt, incr2,
8775 dst, GDK_lng_max, cnt,
8776 ci, candoff,
8777 abort_on_error);
8778 break;
8779#ifdef FULL_IMPLEMENTATION
8780 case TYPE_hge:
8781 nils = div_lng_hge_hge(lft, incr1, rgt, incr2,
8782 dst, GDK_hge_max, cnt,
8783 ci, candoff,
8784 abort_on_error);
8785 break;
8786#endif
8787 case TYPE_flt:
8788 nils = div_lng_hge_flt(lft, incr1, rgt, incr2,
8789 dst, GDK_flt_max, cnt,
8790 ci, candoff,
8791 abort_on_error);
8792 break;
8793 case TYPE_dbl:
8794 nils = div_lng_hge_dbl(lft, incr1, rgt, incr2,
8795 dst, GDK_dbl_max, cnt,
8796 ci, candoff,
8797 abort_on_error);
8798 break;
8799 default:
8800 goto unsupported;
8801 }
8802 break;
8803#endif
8804 case TYPE_flt:
8805 switch (tp) {
8806 case TYPE_flt:
8807 nils = div_lng_flt_flt(lft, incr1, rgt, incr2,
8808 dst, GDK_flt_max, cnt,
8809 ci, candoff,
8810 abort_on_error);
8811 break;
8812 case TYPE_dbl:
8813 nils = div_lng_flt_dbl(lft, incr1, rgt, incr2,
8814 dst, GDK_dbl_max, cnt,
8815 ci, candoff,
8816 abort_on_error);
8817 break;
8818 default:
8819 goto unsupported;
8820 }
8821 break;
8822 case TYPE_dbl:
8823 switch (tp) {
8824 case TYPE_dbl:
8825 nils = div_lng_dbl_dbl(lft, incr1, rgt, incr2,
8826 dst, GDK_dbl_max, cnt,
8827 ci, candoff,
8828 abort_on_error);
8829 break;
8830 default:
8831 goto unsupported;
8832 }
8833 break;
8834 default:
8835 goto unsupported;
8836 }
8837 break;
8838#ifdef HAVE_HGE
8839 case TYPE_hge:
8840 switch (tp2) {
8841 case TYPE_bte:
8842 switch (tp) {
8843 case TYPE_hge:
8844 nils = div_hge_bte_hge(lft, incr1, rgt, incr2,
8845 dst, GDK_hge_max, cnt,
8846 ci, candoff,
8847 abort_on_error);
8848 break;
8849 case TYPE_flt:
8850 nils = div_hge_bte_flt(lft, incr1, rgt, incr2,
8851 dst, GDK_flt_max, cnt,
8852 ci, candoff,
8853 abort_on_error);
8854 break;
8855 case TYPE_dbl:
8856 nils = div_hge_bte_dbl(lft, incr1, rgt, incr2,
8857 dst, GDK_dbl_max, cnt,
8858 ci, candoff,
8859 abort_on_error);
8860 break;
8861 default:
8862 goto unsupported;
8863 }
8864 break;
8865 case TYPE_sht:
8866 switch (tp) {
8867 case TYPE_hge:
8868 nils = div_hge_sht_hge(lft, incr1, rgt, incr2,
8869 dst, GDK_hge_max, cnt,
8870 ci, candoff,
8871 abort_on_error);
8872 break;
8873 case TYPE_flt:
8874 nils = div_hge_sht_flt(lft, incr1, rgt, incr2,
8875 dst, GDK_flt_max, cnt,
8876 ci, candoff,
8877 abort_on_error);
8878 break;
8879 case TYPE_dbl:
8880 nils = div_hge_sht_dbl(lft, incr1, rgt, incr2,
8881 dst, GDK_dbl_max, cnt,
8882 ci, candoff,
8883 abort_on_error);
8884 break;
8885 default:
8886 goto unsupported;
8887 }
8888 break;
8889 case TYPE_int:
8890 switch (tp) {
8891 case TYPE_hge:
8892 nils = div_hge_int_hge(lft, incr1, rgt, incr2,
8893 dst, GDK_hge_max, cnt,
8894 ci, candoff,
8895 abort_on_error);
8896 break;
8897 case TYPE_flt:
8898 nils = div_hge_int_flt(lft, incr1, rgt, incr2,
8899 dst, GDK_flt_max, cnt,
8900 ci, candoff,
8901 abort_on_error);
8902 break;
8903 case TYPE_dbl:
8904 nils = div_hge_int_dbl(lft, incr1, rgt, incr2,
8905 dst, GDK_dbl_max, cnt,
8906 ci, candoff,
8907 abort_on_error);
8908 break;
8909 default:
8910 goto unsupported;
8911 }
8912 break;
8913 case TYPE_lng:
8914 switch (tp) {
8915 case TYPE_hge:
8916 nils = div_hge_lng_hge(lft, incr1, rgt, incr2,
8917 dst, GDK_hge_max, cnt,
8918 ci, candoff,
8919 abort_on_error);
8920 break;
8921 case TYPE_flt:
8922 nils = div_hge_lng_flt(lft, incr1, rgt, incr2,
8923 dst, GDK_flt_max, cnt,
8924 ci, candoff,
8925 abort_on_error);
8926 break;
8927 case TYPE_dbl:
8928 nils = div_hge_lng_dbl(lft, incr1, rgt, incr2,
8929 dst, GDK_dbl_max, cnt,
8930 ci, candoff,
8931 abort_on_error);
8932 break;
8933 default:
8934 goto unsupported;
8935 }
8936 break;
8937 case TYPE_hge:
8938 switch (tp) {
8939 case TYPE_hge:
8940 nils = div_hge_hge_hge(lft, incr1, rgt, incr2,
8941 dst, GDK_hge_max, cnt,
8942 ci, candoff,
8943 abort_on_error);
8944 break;
8945 case TYPE_flt:
8946 nils = div_hge_hge_flt(lft, incr1, rgt, incr2,
8947 dst, GDK_flt_max, cnt,
8948 ci, candoff,
8949 abort_on_error);
8950 break;
8951 case TYPE_dbl:
8952 nils = div_hge_hge_dbl(lft, incr1, rgt, incr2,
8953 dst, GDK_dbl_max, cnt,
8954 ci, candoff,
8955 abort_on_error);
8956 break;
8957 default:
8958 goto unsupported;
8959 }
8960 break;
8961 case TYPE_flt:
8962 switch (tp) {
8963 case TYPE_flt:
8964 nils = div_hge_flt_flt(lft, incr1, rgt, incr2,
8965 dst, GDK_flt_max, cnt,
8966 ci, candoff,
8967 abort_on_error);
8968 break;
8969 case TYPE_dbl:
8970 nils = div_hge_flt_dbl(lft, incr1, rgt, incr2,
8971 dst, GDK_dbl_max, cnt,
8972 ci, candoff,
8973 abort_on_error);
8974 break;
8975 default:
8976 goto unsupported;
8977 }
8978 break;
8979 case TYPE_dbl:
8980 switch (tp) {
8981 case TYPE_dbl:
8982 nils = div_hge_dbl_dbl(lft, incr1, rgt, incr2,
8983 dst, GDK_dbl_max, cnt,
8984 ci, candoff,
8985 abort_on_error);
8986 break;
8987 default:
8988 goto unsupported;
8989 }
8990 break;
8991 default:
8992 goto unsupported;
8993 }
8994 break;
8995#endif
8996 case TYPE_flt:
8997 switch (tp2) {
8998 case TYPE_bte:
8999 switch (tp) {
9000 case TYPE_flt:
9001 nils = div_flt_bte_flt(lft, incr1, rgt, incr2,
9002 dst, GDK_flt_max, cnt,
9003 ci, candoff,
9004 abort_on_error);
9005 break;
9006 case TYPE_dbl:
9007 nils = div_flt_bte_dbl(lft, incr1, rgt, incr2,
9008 dst, GDK_dbl_max, cnt,
9009 ci, candoff,
9010 abort_on_error);
9011 break;
9012 default:
9013 goto unsupported;
9014 }
9015 break;
9016 case TYPE_sht:
9017 switch (tp) {
9018 case TYPE_flt:
9019 nils = div_flt_sht_flt(lft, incr1, rgt, incr2,
9020 dst, GDK_flt_max, cnt,
9021 ci, candoff,
9022 abort_on_error);
9023 break;
9024 case TYPE_dbl:
9025 nils = div_flt_sht_dbl(lft, incr1, rgt, incr2,
9026 dst, GDK_dbl_max, cnt,
9027 ci, candoff,
9028 abort_on_error);
9029 break;
9030 default:
9031 goto unsupported;
9032 }
9033 break;
9034 case TYPE_int:
9035 switch (tp) {
9036 case TYPE_flt:
9037 nils = div_flt_int_flt(lft, incr1, rgt, incr2,
9038 dst, GDK_flt_max, cnt,
9039 ci, candoff,
9040 abort_on_error);
9041 break;
9042 case TYPE_dbl:
9043 nils = div_flt_int_dbl(lft, incr1, rgt, incr2,
9044 dst, GDK_dbl_max, cnt,
9045 ci, candoff,
9046 abort_on_error);
9047 break;
9048 default:
9049 goto unsupported;
9050 }
9051 break;
9052 case TYPE_lng:
9053 switch (tp) {
9054 case TYPE_flt:
9055 nils = div_flt_lng_flt(lft, incr1, rgt, incr2,
9056 dst, GDK_flt_max, cnt,
9057 ci, candoff,
9058 abort_on_error);
9059 break;
9060 case TYPE_dbl:
9061 nils = div_flt_lng_dbl(lft, incr1, rgt, incr2,
9062 dst, GDK_dbl_max, cnt,
9063 ci, candoff,
9064 abort_on_error);
9065 break;
9066 default:
9067 goto unsupported;
9068 }
9069 break;
9070#ifdef HAVE_HGE
9071 case TYPE_hge:
9072 switch (tp) {
9073 case TYPE_flt:
9074 nils = div_flt_hge_flt(lft, incr1, rgt, incr2,
9075 dst, GDK_flt_max, cnt,
9076 ci, candoff,
9077 abort_on_error);
9078 break;
9079 case TYPE_dbl:
9080 nils = div_flt_hge_dbl(lft, incr1, rgt, incr2,
9081 dst, GDK_dbl_max, cnt,
9082 ci, candoff,
9083 abort_on_error);
9084 break;
9085 default:
9086 goto unsupported;
9087 }
9088 break;
9089#endif
9090 case TYPE_flt:
9091 switch (tp) {
9092 case TYPE_flt:
9093 nils = div_flt_flt_flt(lft, incr1, rgt, incr2,
9094 dst, GDK_flt_max, cnt,
9095 ci, candoff,
9096 abort_on_error);
9097 break;
9098 case TYPE_dbl:
9099 nils = div_flt_flt_dbl(lft, incr1, rgt, incr2,
9100 dst, GDK_dbl_max, cnt,
9101 ci, candoff,
9102 abort_on_error);
9103 break;
9104 default:
9105 goto unsupported;
9106 }
9107 break;
9108 case TYPE_dbl:
9109 switch (tp) {
9110 case TYPE_dbl:
9111 nils = div_flt_dbl_dbl(lft, incr1, rgt, incr2,
9112 dst, GDK_dbl_max, cnt,
9113 ci, candoff,
9114 abort_on_error);
9115 break;
9116 default:
9117 goto unsupported;
9118 }
9119 break;
9120 default:
9121 goto unsupported;
9122 }
9123 break;
9124 case TYPE_dbl:
9125 switch (tp2) {
9126 case TYPE_bte:
9127 switch (tp) {
9128 case TYPE_dbl:
9129 nils = div_dbl_bte_dbl(lft, incr1, rgt, incr2,
9130 dst, GDK_dbl_max, cnt,
9131 ci, candoff,
9132 abort_on_error);
9133 break;
9134 default:
9135 goto unsupported;
9136 }
9137 break;
9138 case TYPE_sht:
9139 switch (tp) {
9140 case TYPE_dbl:
9141 nils = div_dbl_sht_dbl(lft, incr1, rgt, incr2,
9142 dst, GDK_dbl_max, cnt,
9143 ci, candoff,
9144 abort_on_error);
9145 break;
9146 default:
9147 goto unsupported;
9148 }
9149 break;
9150 case TYPE_int:
9151 switch (tp) {
9152 case TYPE_dbl:
9153 nils = div_dbl_int_dbl(lft, incr1, rgt, incr2,
9154 dst, GDK_dbl_max, cnt,
9155 ci, candoff,
9156 abort_on_error);
9157 break;
9158 default:
9159 goto unsupported;
9160 }
9161 break;
9162 case TYPE_lng:
9163 switch (tp) {
9164 case TYPE_dbl:
9165 nils = div_dbl_lng_dbl(lft, incr1, rgt, incr2,
9166 dst, GDK_dbl_max, cnt,
9167 ci, candoff,
9168 abort_on_error);
9169 break;
9170 default:
9171 goto unsupported;
9172 }
9173 break;
9174#ifdef HAVE_HGE
9175 case TYPE_hge:
9176 switch (tp) {
9177 case TYPE_dbl:
9178 nils = div_dbl_hge_dbl(lft, incr1, rgt, incr2,
9179 dst, GDK_dbl_max, cnt,
9180 ci, candoff,
9181 abort_on_error);
9182 break;
9183 default:
9184 goto unsupported;
9185 }
9186 break;
9187#endif
9188 case TYPE_flt:
9189 switch (tp) {
9190 case TYPE_dbl:
9191 nils = div_dbl_flt_dbl(lft, incr1, rgt, incr2,
9192 dst, GDK_dbl_max, cnt,
9193 ci, candoff,
9194 abort_on_error);
9195 break;
9196 default:
9197 goto unsupported;
9198 }
9199 break;
9200 case TYPE_dbl:
9201 switch (tp) {
9202 case TYPE_dbl:
9203 nils = div_dbl_dbl_dbl(lft, incr1, rgt, incr2,
9204 dst, GDK_dbl_max, cnt,
9205 ci, candoff,
9206 abort_on_error);
9207 break;
9208 default:
9209 goto unsupported;
9210 }
9211 break;
9212 default:
9213 goto unsupported;
9214 }
9215 break;
9216 default:
9217 goto unsupported;
9218 }
9219
9220 if (nils == BUN_NONE + 1)
9221 GDKerror("22012!division by zero.\n");
9222
9223 return nils;
9224
9225 unsupported:
9226 GDKerror("%s: type combination (div(%s,%s)->%s) not supported.\n",
9227 func, ATOMname(tp1), ATOMname(tp2), ATOMname(tp));
9228 return BUN_NONE;
9229}
9230
9231BAT *
9232BATcalcdiv(BAT *b1, BAT *b2, BAT *s, int tp, bool abort_on_error)
9233{
9234 return BATcalcmuldivmod(b1, b2, s, tp, abort_on_error,
9235 div_typeswitchloop, __func__);
9236}
9237
9238BAT *
9239BATcalcdivcst(BAT *b, const ValRecord *v, BAT *s, int tp, bool abort_on_error)
9240{
9241 BAT *bn;
9242 BUN nils;
9243 BUN cnt, ncand;
9244 struct canditer ci;
9245
9246 BATcheck(b, __func__, NULL);
9247
9248 cnt = BATcount(b);
9249 ncand = canditer_init(&ci, b, s);
9250 if (ncand == 0)
9251 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
9252 cnt, TRANSIENT);
9253
9254 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
9255 if (bn == NULL)
9256 return NULL;
9257
9258 nils = div_typeswitchloop(Tloc(b, 0), b->ttype, 1,
9259 VALptr(v), v->vtype, 0,
9260 Tloc(bn, 0), tp,
9261 cnt, &ci, b->hseqbase,
9262 abort_on_error, __func__);
9263
9264 if (nils >= BUN_NONE) {
9265 BBPunfix(bn->batCacheid);
9266 return NULL;
9267 }
9268
9269 BATsetcount(bn, cnt);
9270
9271 /* if the input is sorted, and no zero division occurred (we
9272 * only know for sure if abort_on_error is set), the result is
9273 * also sorted, or reverse sorted if the constant is
9274 * negative */
9275 if (abort_on_error) {
9276 ValRecord sign;
9277
9278 VARcalcsign(&sign, v);
9279 bn->tsorted = (sign.val.btval > 0 && b->tsorted && nils == 0) ||
9280 (sign.val.btval < 0 && b->trevsorted && nils == 0) ||
9281 cnt <= 1 || nils == cnt;
9282 bn->trevsorted = (sign.val.btval > 0 && b->trevsorted && nils == 0) ||
9283 (sign.val.btval < 0 && b->tsorted && nils == 0) ||
9284 cnt <= 1 || nils == cnt;
9285 } else {
9286 bn->tsorted = cnt <= 1 || nils == cnt;
9287 bn->trevsorted = cnt <= 1 || nils == cnt;
9288 }
9289 bn->tsorted = cnt <= 1 || nils == cnt;
9290 bn->trevsorted = cnt <= 1 || nils == cnt;
9291 bn->tkey = cnt <= 1;
9292 bn->tnil = nils != 0;
9293 bn->tnonil = nils == 0;
9294
9295 return bn;
9296}
9297
9298BAT *
9299BATcalccstdiv(const ValRecord *v, BAT *b, BAT *s, int tp, bool abort_on_error)
9300{
9301 BAT *bn;
9302 BUN nils;
9303 BUN cnt, ncand;
9304 struct canditer ci;
9305
9306 BATcheck(b, __func__, NULL);
9307
9308 cnt = BATcount(b);
9309 ncand = canditer_init(&ci, b, s);
9310 if (ncand == 0)
9311 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
9312 cnt, TRANSIENT);
9313
9314 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
9315 if (bn == NULL)
9316 return NULL;
9317
9318 nils = div_typeswitchloop(VALptr(v), v->vtype, 0,
9319 Tloc(b, 0), b->ttype, 1,
9320 Tloc(bn, 0), tp,
9321 cnt, &ci, b->hseqbase,
9322 abort_on_error, __func__);
9323
9324 if (nils >= BUN_NONE) {
9325 BBPunfix(bn->batCacheid);
9326 return NULL;
9327 }
9328
9329 BATsetcount(bn, cnt);
9330
9331 bn->tsorted = cnt <= 1 || nils == cnt;
9332 bn->trevsorted = cnt <= 1 || nils == cnt;
9333 bn->tkey = cnt <= 1;
9334 bn->tnil = nils != 0;
9335 bn->tnonil = nils == 0;
9336
9337 return bn;
9338}
9339
9340gdk_return
9341VARcalcdiv(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
9342 bool abort_on_error)
9343{
9344 if (div_typeswitchloop(VALptr(lft), lft->vtype, 0,
9345 VALptr(rgt), rgt->vtype, 0,
9346 VALget(ret), ret->vtype, 1,
9347 &(struct canditer){.tpe=cand_dense, .ncand=1},
9348 0, abort_on_error, __func__) >= BUN_NONE)
9349 return GDK_FAIL;
9350 return GDK_SUCCEED;
9351}
9352
9353/* ---------------------------------------------------------------------- */
9354/* modulo (any numeric type) */
9355
9356#define MOD_3TYPE(TYPE1, TYPE2, TYPE3) \
9357static BUN \
9358mod_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
9359 const TYPE2 *rgt, int incr2, \
9360 TYPE3 *restrict dst, BUN cnt, \
9361 struct canditer *restrict ci, \
9362 oid candoff, bool abort_on_error) \
9363{ \
9364 oid x = canditer_next(ci) - candoff; \
9365 BUN i, j, k = 0; \
9366 BUN nils = 0; \
9367 \
9368 do { \
9369 while (k < x) { \
9370 dst[k++] = TYPE3##_nil; \
9371 nils++; \
9372 } \
9373 i = x * incr1; \
9374 j = x * incr2; \
9375 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
9376 dst[k] = TYPE3##_nil; \
9377 nils++; \
9378 } else if (rgt[j] == 0) { \
9379 if (abort_on_error) \
9380 return BUN_NONE + 1; \
9381 dst[k] = TYPE3##_nil; \
9382 nils++; \
9383 } else { \
9384 dst[k] = (TYPE3) lft[i] % rgt[j]; \
9385 } \
9386 k++; \
9387 x = canditer_next(ci); \
9388 if (is_oid_nil(x)) \
9389 break; \
9390 x -= candoff; \
9391 } while (k < cnt); \
9392 while (k < cnt) { \
9393 dst[k++] = TYPE3##_nil; \
9394 nils++; \
9395 } \
9396 return nils; \
9397}
9398
9399#define FMOD_3TYPE(TYPE1, TYPE2, TYPE3, FUNC) \
9400static BUN \
9401mod_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
9402 const TYPE2 *rgt, int incr2, \
9403 TYPE3 *restrict dst, BUN cnt, \
9404 struct canditer *restrict ci, \
9405 oid candoff, bool abort_on_error) \
9406{ \
9407 oid x = canditer_next(ci) - candoff; \
9408 BUN i, j, k = 0; \
9409 BUN nils = 0; \
9410 \
9411 do { \
9412 while (k < x) { \
9413 dst[k++] = TYPE3##_nil; \
9414 nils++; \
9415 } \
9416 i = x * incr1; \
9417 j = x * incr2; \
9418 if (is_##TYPE1##_nil(lft[i]) || is_##TYPE2##_nil(rgt[j])) { \
9419 dst[k] = TYPE3##_nil; \
9420 nils++; \
9421 } else if (rgt[j] == 0) { \
9422 if (abort_on_error) \
9423 return BUN_NONE + 1; \
9424 dst[k] = TYPE3##_nil; \
9425 nils++; \
9426 } else { \
9427 dst[k] = (TYPE3) FUNC((TYPE3) lft[i], \
9428 (TYPE3) rgt[j]); \
9429 } \
9430 k++; \
9431 x = canditer_next(ci); \
9432 if (is_oid_nil(x)) \
9433 break; \
9434 x -= candoff; \
9435 } while (k < cnt); \
9436 while (k < cnt) { \
9437 dst[k++] = TYPE3##_nil; \
9438 nils++; \
9439 } \
9440 return nils; \
9441}
9442
9443MOD_3TYPE(bte, bte, bte)
9444#ifdef FULL_IMPLEMENTATION
9445MOD_3TYPE(bte, bte, sht)
9446MOD_3TYPE(bte, bte, int)
9447MOD_3TYPE(bte, bte, lng)
9448#ifdef HAVE_HGE
9449MOD_3TYPE(bte, bte, hge)
9450#endif
9451#endif
9452MOD_3TYPE(bte, sht, bte)
9453#ifdef FULL_IMPLEMENTATION
9454MOD_3TYPE(bte, sht, sht)
9455MOD_3TYPE(bte, sht, int)
9456MOD_3TYPE(bte, sht, lng)
9457#ifdef HAVE_HGE
9458MOD_3TYPE(bte, sht, hge)
9459#endif
9460#endif
9461MOD_3TYPE(bte, int, bte)
9462#ifdef FULL_IMPLEMENTATION
9463MOD_3TYPE(bte, int, sht)
9464MOD_3TYPE(bte, int, int)
9465MOD_3TYPE(bte, int, lng)
9466#ifdef HAVE_HGE
9467MOD_3TYPE(bte, int, hge)
9468#endif
9469#endif
9470MOD_3TYPE(bte, lng, bte)
9471#ifdef FULL_IMPLEMENTATION
9472MOD_3TYPE(bte, lng, sht)
9473MOD_3TYPE(bte, lng, int)
9474MOD_3TYPE(bte, lng, lng)
9475#ifdef HAVE_HGE
9476MOD_3TYPE(bte, lng, hge)
9477#endif
9478#endif
9479#ifdef HAVE_HGE
9480MOD_3TYPE(bte, hge, bte)
9481#ifdef FULL_IMPLEMENTATION
9482MOD_3TYPE(bte, hge, sht)
9483MOD_3TYPE(bte, hge, int)
9484MOD_3TYPE(bte, hge, lng)
9485MOD_3TYPE(bte, hge, hge)
9486#endif
9487#endif
9488MOD_3TYPE(sht, bte, bte)
9489#ifdef FULL_IMPLEMENTATION
9490MOD_3TYPE(sht, bte, sht)
9491MOD_3TYPE(sht, bte, int)
9492MOD_3TYPE(sht, bte, lng)
9493#ifdef HAVE_HGE
9494MOD_3TYPE(sht, bte, hge)
9495#endif
9496#endif
9497MOD_3TYPE(sht, sht, sht)
9498#ifdef FULL_IMPLEMENTATION
9499MOD_3TYPE(sht, sht, int)
9500MOD_3TYPE(sht, sht, lng)
9501#ifdef HAVE_HGE
9502MOD_3TYPE(sht, sht, hge)
9503#endif
9504#endif
9505MOD_3TYPE(sht, int, sht)
9506#ifdef FULL_IMPLEMENTATION
9507MOD_3TYPE(sht, int, int)
9508MOD_3TYPE(sht, int, lng)
9509#ifdef HAVE_HGE
9510MOD_3TYPE(sht, int, hge)
9511#endif
9512#endif
9513MOD_3TYPE(sht, lng, sht)
9514#ifdef FULL_IMPLEMENTATION
9515MOD_3TYPE(sht, lng, int)
9516MOD_3TYPE(sht, lng, lng)
9517#ifdef HAVE_HGE
9518MOD_3TYPE(sht, lng, hge)
9519#endif
9520#endif
9521#ifdef HAVE_HGE
9522MOD_3TYPE(sht, hge, sht)
9523#ifdef FULL_IMPLEMENTATION
9524MOD_3TYPE(sht, hge, int)
9525MOD_3TYPE(sht, hge, lng)
9526MOD_3TYPE(sht, hge, hge)
9527#endif
9528#endif
9529MOD_3TYPE(int, bte, bte)
9530#ifdef FULL_IMPLEMENTATION
9531MOD_3TYPE(int, bte, sht)
9532MOD_3TYPE(int, bte, int)
9533MOD_3TYPE(int, bte, lng)
9534#ifdef HAVE_HGE
9535MOD_3TYPE(int, bte, hge)
9536#endif
9537#endif
9538MOD_3TYPE(int, sht, sht)
9539#ifdef FULL_IMPLEMENTATION
9540MOD_3TYPE(int, sht, int)
9541MOD_3TYPE(int, sht, lng)
9542#ifdef HAVE_HGE
9543MOD_3TYPE(int, sht, hge)
9544#endif
9545#endif
9546MOD_3TYPE(int, int, int)
9547#ifdef FULL_IMPLEMENTATION
9548MOD_3TYPE(int, int, lng)
9549#ifdef HAVE_HGE
9550MOD_3TYPE(int, int, hge)
9551#endif
9552#endif
9553MOD_3TYPE(int, lng, int)
9554#ifdef FULL_IMPLEMENTATION
9555MOD_3TYPE(int, lng, lng)
9556#ifdef HAVE_HGE
9557MOD_3TYPE(int, lng, hge)
9558#endif
9559#endif
9560#ifdef HAVE_HGE
9561MOD_3TYPE(int, hge, int)
9562#ifdef FULL_IMPLEMENTATION
9563MOD_3TYPE(int, hge, lng)
9564MOD_3TYPE(int, hge, hge)
9565#endif
9566#endif
9567MOD_3TYPE(lng, bte, bte)
9568#ifdef FULL_IMPLEMENTATION
9569MOD_3TYPE(lng, bte, sht)
9570MOD_3TYPE(lng, bte, int)
9571MOD_3TYPE(lng, bte, lng)
9572#ifdef HAVE_HGE
9573MOD_3TYPE(lng, bte, hge)
9574#endif
9575#endif
9576MOD_3TYPE(lng, sht, sht)
9577#ifdef FULL_IMPLEMENTATION
9578MOD_3TYPE(lng, sht, int)
9579MOD_3TYPE(lng, sht, lng)
9580#ifdef HAVE_HGE
9581MOD_3TYPE(lng, sht, hge)
9582#endif
9583#endif
9584MOD_3TYPE(lng, int, int)
9585#ifdef FULL_IMPLEMENTATION
9586MOD_3TYPE(lng, int, lng)
9587#ifdef HAVE_HGE
9588MOD_3TYPE(lng, int, hge)
9589#endif
9590#endif
9591MOD_3TYPE(lng, lng, lng)
9592#ifdef FULL_IMPLEMENTATION
9593#ifdef HAVE_HGE
9594MOD_3TYPE(lng, lng, hge)
9595#endif
9596#endif
9597#ifdef HAVE_HGE
9598MOD_3TYPE(lng, hge, lng)
9599#ifdef FULL_IMPLEMENTATION
9600MOD_3TYPE(lng, hge, hge)
9601#endif
9602#endif
9603#ifdef HAVE_HGE
9604MOD_3TYPE(hge, bte, bte)
9605#ifdef FULL_IMPLEMENTATION
9606MOD_3TYPE(hge, bte, sht)
9607MOD_3TYPE(hge, bte, int)
9608MOD_3TYPE(hge, bte, lng)
9609MOD_3TYPE(hge, bte, hge)
9610#endif
9611MOD_3TYPE(hge, sht, sht)
9612#ifdef FULL_IMPLEMENTATION
9613MOD_3TYPE(hge, sht, int)
9614MOD_3TYPE(hge, sht, lng)
9615MOD_3TYPE(hge, sht, hge)
9616#endif
9617MOD_3TYPE(hge, int, int)
9618#ifdef FULL_IMPLEMENTATION
9619MOD_3TYPE(hge, int, lng)
9620MOD_3TYPE(hge, int, hge)
9621#endif
9622MOD_3TYPE(hge, lng, lng)
9623#ifdef FULL_IMPLEMENTATION
9624MOD_3TYPE(hge, lng, hge)
9625#endif
9626MOD_3TYPE(hge, hge, hge)
9627#endif
9628
9629FMOD_3TYPE(bte, flt, flt, fmodf)
9630FMOD_3TYPE(sht, flt, flt, fmodf)
9631FMOD_3TYPE(int, flt, flt, fmodf)
9632FMOD_3TYPE(lng, flt, flt, fmodf)
9633#ifdef HAVE_HGE
9634FMOD_3TYPE(hge, flt, flt, fmodf)
9635#endif
9636FMOD_3TYPE(flt, bte, flt, fmodf)
9637FMOD_3TYPE(flt, sht, flt, fmodf)
9638FMOD_3TYPE(flt, int, flt, fmodf)
9639FMOD_3TYPE(flt, lng, flt, fmodf)
9640#ifdef HAVE_HGE
9641FMOD_3TYPE(flt, hge, flt, fmodf)
9642#endif
9643FMOD_3TYPE(flt, flt, flt, fmodf)
9644FMOD_3TYPE(bte, dbl, dbl, fmod)
9645FMOD_3TYPE(sht, dbl, dbl, fmod)
9646FMOD_3TYPE(int, dbl, dbl, fmod)
9647FMOD_3TYPE(lng, dbl, dbl, fmod)
9648#ifdef HAVE_HGE
9649FMOD_3TYPE(hge, dbl, dbl, fmod)
9650#endif
9651FMOD_3TYPE(flt, dbl, dbl, fmod)
9652FMOD_3TYPE(dbl, bte, dbl, fmod)
9653FMOD_3TYPE(dbl, sht, dbl, fmod)
9654FMOD_3TYPE(dbl, int, dbl, fmod)
9655FMOD_3TYPE(dbl, lng, dbl, fmod)
9656#ifdef HAVE_HGE
9657FMOD_3TYPE(dbl, hge, dbl, fmod)
9658#endif
9659FMOD_3TYPE(dbl, flt, dbl, fmod)
9660FMOD_3TYPE(dbl, dbl, dbl, fmod)
9661
9662static BUN
9663mod_typeswitchloop(const void *lft, int tp1, int incr1,
9664 const void *rgt, int tp2, int incr2,
9665 void *restrict dst, int tp, BUN cnt,
9666 struct canditer *restrict ci, oid candoff,
9667 bool abort_on_error, const char *func)
9668{
9669 BUN nils;
9670
9671 tp1 = ATOMbasetype(tp1);
9672 tp2 = ATOMbasetype(tp2);
9673 tp = ATOMbasetype(tp);
9674 switch (tp1) {
9675 case TYPE_bte:
9676 switch (tp2) {
9677 case TYPE_bte:
9678 switch (tp) {
9679 case TYPE_bte:
9680 nils = mod_bte_bte_bte(lft, incr1, rgt, incr2,
9681 dst, cnt, ci, candoff,
9682 abort_on_error);
9683 break;
9684#ifdef FULL_IMPLEMENTATION
9685 case TYPE_sht:
9686 nils = mod_bte_bte_sht(lft, incr1, rgt, incr2,
9687 dst, cnt, ci, candoff,
9688 abort_on_error);
9689 break;
9690 case TYPE_int:
9691 nils = mod_bte_bte_int(lft, incr1, rgt, incr2,
9692 dst, cnt, ci, candoff,
9693 abort_on_error);
9694 break;
9695 case TYPE_lng:
9696 nils = mod_bte_bte_lng(lft, incr1, rgt, incr2,
9697 dst, cnt, ci, candoff,
9698 abort_on_error);
9699 break;
9700#ifdef HAVE_HGE
9701 case TYPE_hge:
9702 nils = mod_bte_bte_hge(lft, incr1, rgt, incr2,
9703 dst, cnt, ci, candoff,
9704 abort_on_error);
9705 break;
9706#endif
9707#endif
9708 default:
9709 goto unsupported;
9710 }
9711 break;
9712 case TYPE_sht:
9713 switch (tp) {
9714 case TYPE_bte:
9715 nils = mod_bte_sht_bte(lft, incr1, rgt, incr2,
9716 dst, cnt, ci, candoff,
9717 abort_on_error);
9718 break;
9719#ifdef FULL_IMPLEMENTATION
9720 case TYPE_sht:
9721 nils = mod_bte_sht_sht(lft, incr1, rgt, incr2,
9722 dst, cnt, ci, candoff,
9723 abort_on_error);
9724 break;
9725 case TYPE_int:
9726 nils = mod_bte_sht_int(lft, incr1, rgt, incr2,
9727 dst, cnt, ci, candoff,
9728 abort_on_error);
9729 break;
9730 case TYPE_lng:
9731 nils = mod_bte_sht_lng(lft, incr1, rgt, incr2,
9732 dst, cnt, ci, candoff,
9733 abort_on_error);
9734 break;
9735#ifdef HAVE_HGE
9736 case TYPE_hge:
9737 nils = mod_bte_sht_hge(lft, incr1, rgt, incr2,
9738 dst, cnt, ci, candoff,
9739 abort_on_error);
9740 break;
9741#endif
9742#endif
9743 default:
9744 goto unsupported;
9745 }
9746 break;
9747 case TYPE_int:
9748 switch (tp) {
9749 case TYPE_bte:
9750 nils = mod_bte_int_bte(lft, incr1, rgt, incr2,
9751 dst, cnt, ci, candoff,
9752 abort_on_error);
9753 break;
9754#ifdef FULL_IMPLEMENTATION
9755 case TYPE_sht:
9756 nils = mod_bte_int_sht(lft, incr1, rgt, incr2,
9757 dst, cnt, ci, candoff,
9758 abort_on_error);
9759 break;
9760 case TYPE_int:
9761 nils = mod_bte_int_int(lft, incr1, rgt, incr2,
9762 dst, cnt, ci, candoff,
9763 abort_on_error);
9764 break;
9765 case TYPE_lng:
9766 nils = mod_bte_int_lng(lft, incr1, rgt, incr2,
9767 dst, cnt, ci, candoff,
9768 abort_on_error);
9769 break;
9770#ifdef HAVE_HGE
9771 case TYPE_hge:
9772 nils = mod_bte_int_hge(lft, incr1, rgt, incr2,
9773 dst, cnt, ci, candoff,
9774 abort_on_error);
9775 break;
9776#endif
9777#endif
9778 default:
9779 goto unsupported;
9780 }
9781 break;
9782 case TYPE_lng:
9783 switch (tp) {
9784 case TYPE_bte:
9785 nils = mod_bte_lng_bte(lft, incr1, rgt, incr2,
9786 dst, cnt, ci, candoff,
9787 abort_on_error);
9788 break;
9789#ifdef FULL_IMPLEMENTATION
9790 case TYPE_sht:
9791 nils = mod_bte_lng_sht(lft, incr1, rgt, incr2,
9792 dst, cnt, ci, candoff,
9793 abort_on_error);
9794 break;
9795 case TYPE_int:
9796 nils = mod_bte_lng_int(lft, incr1, rgt, incr2,
9797 dst, cnt, ci, candoff,
9798 abort_on_error);
9799 break;
9800 case TYPE_lng:
9801 nils = mod_bte_lng_lng(lft, incr1, rgt, incr2,
9802 dst, cnt, ci, candoff,
9803 abort_on_error);
9804 break;
9805#ifdef HAVE_HGE
9806 case TYPE_hge:
9807 nils = mod_bte_lng_hge(lft, incr1, rgt, incr2,
9808 dst, cnt, ci, candoff,
9809 abort_on_error);
9810 break;
9811#endif
9812#endif
9813 default:
9814 goto unsupported;
9815 }
9816 break;
9817#ifdef HAVE_HGE
9818 case TYPE_hge:
9819 switch (tp) {
9820 case TYPE_bte:
9821 nils = mod_bte_hge_bte(lft, incr1, rgt, incr2,
9822 dst, cnt, ci, candoff,
9823 abort_on_error);
9824 break;
9825#ifdef FULL_IMPLEMENTATION
9826 case TYPE_sht:
9827 nils = mod_bte_hge_sht(lft, incr1, rgt, incr2,
9828 dst, cnt, ci, candoff,
9829 abort_on_error);
9830 break;
9831 case TYPE_int:
9832 nils = mod_bte_hge_int(lft, incr1, rgt, incr2,
9833 dst, cnt, ci, candoff,
9834 abort_on_error);
9835 break;
9836 case TYPE_lng:
9837 nils = mod_bte_hge_lng(lft, incr1, rgt, incr2,
9838 dst, cnt, ci, candoff,
9839 abort_on_error);
9840 break;
9841 case TYPE_hge:
9842 nils = mod_bte_hge_hge(lft, incr1, rgt, incr2,
9843 dst, cnt, ci, candoff,
9844 abort_on_error);
9845 break;
9846#endif
9847 default:
9848 goto unsupported;
9849 }
9850 break;
9851#endif
9852 case TYPE_flt:
9853 switch (tp) {
9854 case TYPE_flt:
9855 nils = mod_bte_flt_flt(lft, incr1, rgt, incr2,
9856 dst, cnt, ci, candoff,
9857 abort_on_error);
9858 break;
9859 default:
9860 goto unsupported;
9861 }
9862 break;
9863 case TYPE_dbl:
9864 switch (tp) {
9865 case TYPE_dbl:
9866 nils = mod_bte_dbl_dbl(lft, incr1, rgt, incr2,
9867 dst, cnt, ci, candoff,
9868 abort_on_error);
9869 break;
9870 default:
9871 goto unsupported;
9872 }
9873 break;
9874 default:
9875 goto unsupported;
9876 }
9877 break;
9878 case TYPE_sht:
9879 switch (tp2) {
9880 case TYPE_bte:
9881 switch (tp) {
9882 case TYPE_bte:
9883 nils = mod_sht_bte_bte(lft, incr1, rgt, incr2,
9884 dst, cnt, ci, candoff,
9885 abort_on_error);
9886 break;
9887#ifdef FULL_IMPLEMENTATION
9888 case TYPE_sht:
9889 nils = mod_sht_bte_sht(lft, incr1, rgt, incr2,
9890 dst, cnt, ci, candoff,
9891 abort_on_error);
9892 break;
9893 case TYPE_int:
9894 nils = mod_sht_bte_int(lft, incr1, rgt, incr2,
9895 dst, cnt, ci, candoff,
9896 abort_on_error);
9897 break;
9898 case TYPE_lng:
9899 nils = mod_sht_bte_lng(lft, incr1, rgt, incr2,
9900 dst, cnt, ci, candoff,
9901 abort_on_error);
9902 break;
9903#ifdef HAVE_HGE
9904 case TYPE_hge:
9905 nils = mod_sht_bte_hge(lft, incr1, rgt, incr2,
9906 dst, cnt, ci, candoff,
9907 abort_on_error);
9908 break;
9909#endif
9910#endif
9911 default:
9912 goto unsupported;
9913 }
9914 break;
9915 case TYPE_sht:
9916 switch (tp) {
9917 case TYPE_sht:
9918 nils = mod_sht_sht_sht(lft, incr1, rgt, incr2,
9919 dst, cnt, ci, candoff,
9920 abort_on_error);
9921 break;
9922#ifdef FULL_IMPLEMENTATION
9923 case TYPE_int:
9924 nils = mod_sht_sht_int(lft, incr1, rgt, incr2,
9925 dst, cnt, ci, candoff,
9926 abort_on_error);
9927 break;
9928 case TYPE_lng:
9929 nils = mod_sht_sht_lng(lft, incr1, rgt, incr2,
9930 dst, cnt, ci, candoff,
9931 abort_on_error);
9932 break;
9933#ifdef HAVE_HGE
9934 case TYPE_hge:
9935 nils = mod_sht_sht_hge(lft, incr1, rgt, incr2,
9936 dst, cnt, ci, candoff,
9937 abort_on_error);
9938 break;
9939#endif
9940#endif
9941 default:
9942 goto unsupported;
9943 }
9944 break;
9945 case TYPE_int:
9946 switch (tp) {
9947 case TYPE_sht:
9948 nils = mod_sht_int_sht(lft, incr1, rgt, incr2,
9949 dst, cnt, ci, candoff,
9950 abort_on_error);
9951 break;
9952#ifdef FULL_IMPLEMENTATION
9953 case TYPE_int:
9954 nils = mod_sht_int_int(lft, incr1, rgt, incr2,
9955 dst, cnt, ci, candoff,
9956 abort_on_error);
9957 break;
9958 case TYPE_lng:
9959 nils = mod_sht_int_lng(lft, incr1, rgt, incr2,
9960 dst, cnt, ci, candoff,
9961 abort_on_error);
9962 break;
9963#ifdef HAVE_HGE
9964 case TYPE_hge:
9965 nils = mod_sht_int_hge(lft, incr1, rgt, incr2,
9966 dst, cnt, ci, candoff,
9967 abort_on_error);
9968 break;
9969#endif
9970#endif
9971 default:
9972 goto unsupported;
9973 }
9974 break;
9975 case TYPE_lng:
9976 switch (tp) {
9977 case TYPE_sht:
9978 nils = mod_sht_lng_sht(lft, incr1, rgt, incr2,
9979 dst, cnt, ci, candoff,
9980 abort_on_error);
9981 break;
9982#ifdef FULL_IMPLEMENTATION
9983 case TYPE_int:
9984 nils = mod_sht_lng_int(lft, incr1, rgt, incr2,
9985 dst, cnt, ci, candoff,
9986 abort_on_error);
9987 break;
9988 case TYPE_lng:
9989 nils = mod_sht_lng_lng(lft, incr1, rgt, incr2,
9990 dst, cnt, ci, candoff,
9991 abort_on_error);
9992 break;
9993#ifdef HAVE_HGE
9994 case TYPE_hge:
9995 nils = mod_sht_lng_hge(lft, incr1, rgt, incr2,
9996 dst, cnt, ci, candoff,
9997 abort_on_error);
9998 break;
9999#endif
10000#endif
10001 default:
10002 goto unsupported;
10003 }
10004 break;
10005#ifdef HAVE_HGE
10006 case TYPE_hge:
10007 switch (tp) {
10008 case TYPE_sht:
10009 nils = mod_sht_hge_sht(lft, incr1, rgt, incr2,
10010 dst, cnt, ci, candoff,
10011 abort_on_error);
10012 break;
10013#ifdef FULL_IMPLEMENTATION
10014 case TYPE_int:
10015 nils = mod_sht_hge_int(lft, incr1, rgt, incr2,
10016 dst, cnt, ci, candoff,
10017 abort_on_error);
10018 break;
10019 case TYPE_lng:
10020 nils = mod_sht_hge_lng(lft, incr1, rgt, incr2,
10021 dst, cnt, ci, candoff,
10022 abort_on_error);
10023 break;
10024 case TYPE_hge:
10025 nils = mod_sht_hge_hge(lft, incr1, rgt, incr2,
10026 dst, cnt, ci, candoff,
10027 abort_on_error);
10028 break;
10029#endif
10030 default:
10031 goto unsupported;
10032 }
10033 break;
10034#endif
10035 case TYPE_flt:
10036 switch (tp) {
10037 case TYPE_flt:
10038 nils = mod_sht_flt_flt(lft, incr1, rgt, incr2,
10039 dst, cnt, ci, candoff,
10040 abort_on_error);
10041 break;
10042 default:
10043 goto unsupported;
10044 }
10045 break;
10046 case TYPE_dbl:
10047 switch (tp) {
10048 case TYPE_dbl:
10049 nils = mod_sht_dbl_dbl(lft, incr1, rgt, incr2,
10050 dst, cnt, ci, candoff,
10051 abort_on_error);
10052 break;
10053 default:
10054 goto unsupported;
10055 }
10056 break;
10057 default:
10058 goto unsupported;
10059 }
10060 break;
10061 case TYPE_int:
10062 switch (tp2) {
10063 case TYPE_bte:
10064 switch (tp) {
10065 case TYPE_bte:
10066 nils = mod_int_bte_bte(lft, incr1, rgt, incr2,
10067 dst, cnt, ci, candoff,
10068 abort_on_error);
10069 break;
10070#ifdef FULL_IMPLEMENTATION
10071 case TYPE_sht:
10072 nils = mod_int_bte_sht(lft, incr1, rgt, incr2,
10073 dst, cnt, ci, candoff,
10074 abort_on_error);
10075 break;
10076 case TYPE_int:
10077 nils = mod_int_bte_int(lft, incr1, rgt, incr2,
10078 dst, cnt, ci, candoff,
10079 abort_on_error);
10080 break;
10081 case TYPE_lng:
10082 nils = mod_int_bte_lng(lft, incr1, rgt, incr2,
10083 dst, cnt, ci, candoff,
10084 abort_on_error);
10085 break;
10086#ifdef HAVE_HGE
10087 case TYPE_hge:
10088 nils = mod_int_bte_hge(lft, incr1, rgt, incr2,
10089 dst, cnt, ci, candoff,
10090 abort_on_error);
10091 break;
10092#endif
10093#endif
10094 default:
10095 goto unsupported;
10096 }
10097 break;
10098 case TYPE_sht:
10099 switch (tp) {
10100 case TYPE_sht:
10101 nils = mod_int_sht_sht(lft, incr1, rgt, incr2,
10102 dst, cnt, ci, candoff,
10103 abort_on_error);
10104 break;
10105#ifdef FULL_IMPLEMENTATION
10106 case TYPE_int:
10107 nils = mod_int_sht_int(lft, incr1, rgt, incr2,
10108 dst, cnt, ci, candoff,
10109 abort_on_error);
10110 break;
10111 case TYPE_lng:
10112 nils = mod_int_sht_lng(lft, incr1, rgt, incr2,
10113 dst, cnt, ci, candoff,
10114 abort_on_error);
10115 break;
10116#ifdef HAVE_HGE
10117 case TYPE_hge:
10118 nils = mod_int_sht_hge(lft, incr1, rgt, incr2,
10119 dst, cnt, ci, candoff,
10120 abort_on_error);
10121 break;
10122#endif
10123#endif
10124 default:
10125 goto unsupported;
10126 }
10127 break;
10128 case TYPE_int:
10129 switch (tp) {
10130 case TYPE_int:
10131 nils = mod_int_int_int(lft, incr1, rgt, incr2,
10132 dst, cnt, ci, candoff,
10133 abort_on_error);
10134 break;
10135#ifdef FULL_IMPLEMENTATION
10136 case TYPE_lng:
10137 nils = mod_int_int_lng(lft, incr1, rgt, incr2,
10138 dst, cnt, ci, candoff,
10139 abort_on_error);
10140 break;
10141#ifdef HAVE_HGE
10142 case TYPE_hge:
10143 nils = mod_int_int_hge(lft, incr1, rgt, incr2,
10144 dst, cnt, ci, candoff,
10145 abort_on_error);
10146 break;
10147#endif
10148#endif
10149 default:
10150 goto unsupported;
10151 }
10152 break;
10153 case TYPE_lng:
10154 switch (tp) {
10155 case TYPE_int:
10156 nils = mod_int_lng_int(lft, incr1, rgt, incr2,
10157 dst, cnt, ci, candoff,
10158 abort_on_error);
10159 break;
10160#ifdef FULL_IMPLEMENTATION
10161 case TYPE_lng:
10162 nils = mod_int_lng_lng(lft, incr1, rgt, incr2,
10163 dst, cnt, ci, candoff,
10164 abort_on_error);
10165 break;
10166#ifdef HAVE_HGE
10167 case TYPE_hge:
10168 nils = mod_int_lng_hge(lft, incr1, rgt, incr2,
10169 dst, cnt, ci, candoff,
10170 abort_on_error);
10171 break;
10172#endif
10173#endif
10174 default:
10175 goto unsupported;
10176 }
10177 break;
10178#ifdef HAVE_HGE
10179 case TYPE_hge:
10180 switch (tp) {
10181 case TYPE_int:
10182 nils = mod_int_hge_int(lft, incr1, rgt, incr2,
10183 dst, cnt, ci, candoff,
10184 abort_on_error);
10185 break;
10186#ifdef FULL_IMPLEMENTATION
10187 case TYPE_lng:
10188 nils = mod_int_hge_lng(lft, incr1, rgt, incr2,
10189 dst, cnt, ci, candoff,
10190 abort_on_error);
10191 break;
10192 case TYPE_hge:
10193 nils = mod_int_hge_hge(lft, incr1, rgt, incr2,
10194 dst, cnt, ci, candoff,
10195 abort_on_error);
10196 break;
10197#endif
10198 default:
10199 goto unsupported;
10200 }
10201 break;
10202#endif
10203 case TYPE_flt:
10204 switch (tp) {
10205 case TYPE_flt:
10206 nils = mod_int_flt_flt(lft, incr1, rgt, incr2,
10207 dst, cnt, ci, candoff,
10208 abort_on_error);
10209 break;
10210 default:
10211 goto unsupported;
10212 }
10213 break;
10214 case TYPE_dbl:
10215 switch (tp) {
10216 case TYPE_dbl:
10217 nils = mod_int_dbl_dbl(lft, incr1, rgt, incr2,
10218 dst, cnt, ci, candoff,
10219 abort_on_error);
10220 break;
10221 default:
10222 goto unsupported;
10223 }
10224 break;
10225 default:
10226 goto unsupported;
10227 }
10228 break;
10229 case TYPE_lng:
10230 switch (tp2) {
10231 case TYPE_bte:
10232 switch (tp) {
10233 case TYPE_bte:
10234 nils = mod_lng_bte_bte(lft, incr1, rgt, incr2,
10235 dst, cnt, ci, candoff,
10236 abort_on_error);
10237 break;
10238#ifdef FULL_IMPLEMENTATION
10239 case TYPE_sht:
10240 nils = mod_lng_bte_sht(lft, incr1, rgt, incr2,
10241 dst, cnt, ci, candoff,
10242 abort_on_error);
10243 break;
10244 case TYPE_int:
10245 nils = mod_lng_bte_int(lft, incr1, rgt, incr2,
10246 dst, cnt, ci, candoff,
10247 abort_on_error);
10248 break;
10249 case TYPE_lng:
10250 nils = mod_lng_bte_lng(lft, incr1, rgt, incr2,
10251 dst, cnt, ci, candoff,
10252 abort_on_error);
10253 break;
10254#ifdef HAVE_HGE
10255 case TYPE_hge:
10256 nils = mod_lng_bte_hge(lft, incr1, rgt, incr2,
10257 dst, cnt, ci, candoff,
10258 abort_on_error);
10259 break;
10260#endif
10261#endif
10262 default:
10263 goto unsupported;
10264 }
10265 break;
10266 case TYPE_sht:
10267 switch (tp) {
10268 case TYPE_sht:
10269 nils = mod_lng_sht_sht(lft, incr1, rgt, incr2,
10270 dst, cnt, ci, candoff,
10271 abort_on_error);
10272 break;
10273#ifdef FULL_IMPLEMENTATION
10274 case TYPE_int:
10275 nils = mod_lng_sht_int(lft, incr1, rgt, incr2,
10276 dst, cnt, ci, candoff,
10277 abort_on_error);
10278 break;
10279 case TYPE_lng:
10280 nils = mod_lng_sht_lng(lft, incr1, rgt, incr2,
10281 dst, cnt, ci, candoff,
10282 abort_on_error);
10283 break;
10284#ifdef HAVE_HGE
10285 case TYPE_hge:
10286 nils = mod_lng_sht_hge(lft, incr1, rgt, incr2,
10287 dst, cnt, ci, candoff,
10288 abort_on_error);
10289 break;
10290#endif
10291#endif
10292 default:
10293 goto unsupported;
10294 }
10295 break;
10296 case TYPE_int:
10297 switch (tp) {
10298 case TYPE_int:
10299 nils = mod_lng_int_int(lft, incr1, rgt, incr2,
10300 dst, cnt, ci, candoff,
10301 abort_on_error);
10302 break;
10303#ifdef FULL_IMPLEMENTATION
10304 case TYPE_lng:
10305 nils = mod_lng_int_lng(lft, incr1, rgt, incr2,
10306 dst, cnt, ci, candoff,
10307 abort_on_error);
10308 break;
10309#ifdef HAVE_HGE
10310 case TYPE_hge:
10311 nils = mod_lng_int_hge(lft, incr1, rgt, incr2,
10312 dst, cnt, ci, candoff,
10313 abort_on_error);
10314 break;
10315#endif
10316#endif
10317 default:
10318 goto unsupported;
10319 }
10320 break;
10321 case TYPE_lng:
10322 switch (tp) {
10323 case TYPE_lng:
10324 nils = mod_lng_lng_lng(lft, incr1, rgt, incr2,
10325 dst, cnt, ci, candoff,
10326 abort_on_error);
10327 break;
10328#ifdef FULL_IMPLEMENTATION
10329#ifdef HAVE_HGE
10330 case TYPE_hge:
10331 nils = mod_lng_lng_hge(lft, incr1, rgt, incr2,
10332 dst, cnt, ci, candoff,
10333 abort_on_error);
10334 break;
10335#endif
10336#endif
10337 default:
10338 goto unsupported;
10339 }
10340 break;
10341#ifdef HAVE_HGE
10342 case TYPE_hge:
10343 switch (tp) {
10344 case TYPE_lng:
10345 nils = mod_lng_hge_lng(lft, incr1, rgt, incr2,
10346 dst, cnt, ci, candoff,
10347 abort_on_error);
10348 break;
10349#ifdef FULL_IMPLEMENTATION
10350 case TYPE_hge:
10351 nils = mod_lng_hge_hge(lft, incr1, rgt, incr2,
10352 dst, cnt, ci, candoff,
10353 abort_on_error);
10354 break;
10355#endif
10356 default:
10357 goto unsupported;
10358 }
10359 break;
10360#endif
10361 case TYPE_flt:
10362 switch (tp) {
10363 case TYPE_flt:
10364 nils = mod_lng_flt_flt(lft, incr1, rgt, incr2,
10365 dst, cnt, ci, candoff,
10366 abort_on_error);
10367 break;
10368 default:
10369 goto unsupported;
10370 }
10371 break;
10372 case TYPE_dbl:
10373 switch (tp) {
10374 case TYPE_dbl:
10375 nils = mod_lng_dbl_dbl(lft, incr1, rgt, incr2,
10376 dst, cnt, ci, candoff,
10377 abort_on_error);
10378 break;
10379 default:
10380 goto unsupported;
10381 }
10382 break;
10383 default:
10384 goto unsupported;
10385 }
10386 break;
10387#ifdef HAVE_HGE
10388 case TYPE_hge:
10389 switch (tp2) {
10390 case TYPE_bte:
10391 switch (tp) {
10392 case TYPE_bte:
10393 nils = mod_hge_bte_bte(lft, incr1, rgt, incr2,
10394 dst, cnt, ci, candoff,
10395 abort_on_error);
10396 break;
10397#ifdef FULL_IMPLEMENTATION
10398 case TYPE_sht:
10399 nils = mod_hge_bte_sht(lft, incr1, rgt, incr2,
10400 dst, cnt, ci, candoff,
10401 abort_on_error);
10402 break;
10403 case TYPE_int:
10404 nils = mod_hge_bte_int(lft, incr1, rgt, incr2,
10405 dst, cnt, ci, candoff,
10406 abort_on_error);
10407 break;
10408 case TYPE_lng:
10409 nils = mod_hge_bte_lng(lft, incr1, rgt, incr2,
10410 dst, cnt, ci, candoff,
10411 abort_on_error);
10412 break;
10413 case TYPE_hge:
10414 nils = mod_hge_bte_hge(lft, incr1, rgt, incr2,
10415 dst, cnt, ci, candoff,
10416 abort_on_error);
10417 break;
10418#endif
10419 default:
10420 goto unsupported;
10421 }
10422 break;
10423 case TYPE_sht:
10424 switch (tp) {
10425 case TYPE_sht:
10426 nils = mod_hge_sht_sht(lft, incr1, rgt, incr2,
10427 dst, cnt, ci, candoff,
10428 abort_on_error);
10429 break;
10430#ifdef FULL_IMPLEMENTATION
10431 case TYPE_int:
10432 nils = mod_hge_sht_int(lft, incr1, rgt, incr2,
10433 dst, cnt, ci, candoff,
10434 abort_on_error);
10435 break;
10436 case TYPE_lng:
10437 nils = mod_hge_sht_lng(lft, incr1, rgt, incr2,
10438 dst, cnt, ci, candoff,
10439 abort_on_error);
10440 break;
10441 case TYPE_hge:
10442 nils = mod_hge_sht_hge(lft, incr1, rgt, incr2,
10443 dst, cnt, ci, candoff,
10444 abort_on_error);
10445 break;
10446#endif
10447 default:
10448 goto unsupported;
10449 }
10450 break;
10451 case TYPE_int:
10452 switch (tp) {
10453 case TYPE_int:
10454 nils = mod_hge_int_int(lft, incr1, rgt, incr2,
10455 dst, cnt, ci, candoff,
10456 abort_on_error);
10457 break;
10458#ifdef FULL_IMPLEMENTATION
10459 case TYPE_lng:
10460 nils = mod_hge_int_lng(lft, incr1, rgt, incr2,
10461 dst, cnt, ci, candoff,
10462 abort_on_error);
10463 break;
10464 case TYPE_hge:
10465 nils = mod_hge_int_hge(lft, incr1, rgt, incr2,
10466 dst, cnt, ci, candoff,
10467 abort_on_error);
10468 break;
10469#endif
10470 default:
10471 goto unsupported;
10472 }
10473 break;
10474 case TYPE_lng:
10475 switch (tp) {
10476 case TYPE_lng:
10477 nils = mod_hge_lng_lng(lft, incr1, rgt, incr2,
10478 dst, cnt, ci, candoff,
10479 abort_on_error);
10480 break;
10481#ifdef FULL_IMPLEMENTATION
10482 case TYPE_hge:
10483 nils = mod_hge_lng_hge(lft, incr1, rgt, incr2,
10484 dst, cnt, ci, candoff,
10485 abort_on_error);
10486 break;
10487#endif
10488 default:
10489 goto unsupported;
10490 }
10491 break;
10492 case TYPE_hge:
10493 switch (tp) {
10494 case TYPE_hge:
10495 nils = mod_hge_hge_hge(lft, incr1, rgt, incr2,
10496 dst, cnt, ci, candoff,
10497 abort_on_error);
10498 break;
10499 default:
10500 goto unsupported;
10501 }
10502 break;
10503 case TYPE_flt:
10504 switch (tp) {
10505 case TYPE_flt:
10506 nils = mod_hge_flt_flt(lft, incr1, rgt, incr2,
10507 dst, cnt, ci, candoff,
10508 abort_on_error);
10509 break;
10510 default:
10511 goto unsupported;
10512 }
10513 break;
10514 case TYPE_dbl:
10515 switch (tp) {
10516 case TYPE_dbl:
10517 nils = mod_hge_dbl_dbl(lft, incr1, rgt, incr2,
10518 dst, cnt, ci, candoff,
10519 abort_on_error);
10520 break;
10521 default:
10522 goto unsupported;
10523 }
10524 break;
10525 default:
10526 goto unsupported;
10527 }
10528 break;
10529#endif
10530 case TYPE_flt:
10531 switch (tp2) {
10532 case TYPE_bte:
10533 switch (tp) {
10534 case TYPE_flt:
10535 nils = mod_flt_bte_flt(lft, incr1, rgt, incr2,
10536 dst, cnt, ci, candoff,
10537 abort_on_error);
10538 break;
10539 default:
10540 goto unsupported;
10541 }
10542 break;
10543 case TYPE_sht:
10544 switch (tp) {
10545 case TYPE_flt:
10546 nils = mod_flt_sht_flt(lft, incr1, rgt, incr2,
10547 dst, cnt, ci, candoff,
10548 abort_on_error);
10549 break;
10550 default:
10551 goto unsupported;
10552 }
10553 break;
10554 case TYPE_int:
10555 switch (tp) {
10556 case TYPE_flt:
10557 nils = mod_flt_int_flt(lft, incr1, rgt, incr2,
10558 dst, cnt, ci, candoff,
10559 abort_on_error);
10560 break;
10561 default:
10562 goto unsupported;
10563 }
10564 break;
10565 case TYPE_lng:
10566 switch (tp) {
10567 case TYPE_flt:
10568 nils = mod_flt_lng_flt(lft, incr1, rgt, incr2,
10569 dst, cnt, ci, candoff,
10570 abort_on_error);
10571 break;
10572 default:
10573 goto unsupported;
10574 }
10575 break;
10576#ifdef HAVE_HGE
10577 case TYPE_hge:
10578 switch (tp) {
10579 case TYPE_flt:
10580 nils = mod_flt_hge_flt(lft, incr1, rgt, incr2,
10581 dst, cnt, ci, candoff,
10582 abort_on_error);
10583 break;
10584 default:
10585 goto unsupported;
10586 }
10587 break;
10588#endif
10589 case TYPE_flt:
10590 switch (tp) {
10591 case TYPE_flt:
10592 nils = mod_flt_flt_flt(lft, incr1, rgt, incr2,
10593 dst, cnt, ci, candoff,
10594 abort_on_error);
10595 break;
10596 default:
10597 goto unsupported;
10598 }
10599 break;
10600 case TYPE_dbl:
10601 switch (tp) {
10602 case TYPE_dbl:
10603 nils = mod_flt_dbl_dbl(lft, incr1, rgt, incr2,
10604 dst, cnt, ci, candoff,
10605 abort_on_error);
10606 break;
10607 default:
10608 goto unsupported;
10609 }
10610 break;
10611 default:
10612 goto unsupported;
10613 }
10614 break;
10615 case TYPE_dbl:
10616 switch (tp2) {
10617 case TYPE_bte:
10618 switch (tp) {
10619 case TYPE_dbl:
10620 nils = mod_dbl_bte_dbl(lft, incr1, rgt, incr2,
10621 dst, cnt, ci, candoff,
10622 abort_on_error);
10623 break;
10624 default:
10625 goto unsupported;
10626 }
10627 break;
10628 case TYPE_sht:
10629 switch (tp) {
10630 case TYPE_dbl:
10631 nils = mod_dbl_sht_dbl(lft, incr1, rgt, incr2,
10632 dst, cnt, ci, candoff,
10633 abort_on_error);
10634 break;
10635 default:
10636 goto unsupported;
10637 }
10638 break;
10639 case TYPE_int:
10640 switch (tp) {
10641 case TYPE_dbl:
10642 nils = mod_dbl_int_dbl(lft, incr1, rgt, incr2,
10643 dst, cnt, ci, candoff,
10644 abort_on_error);
10645 break;
10646 default:
10647 goto unsupported;
10648 }
10649 break;
10650 case TYPE_lng:
10651 switch (tp) {
10652 case TYPE_dbl:
10653 nils = mod_dbl_lng_dbl(lft, incr1, rgt, incr2,
10654 dst, cnt, ci, candoff,
10655 abort_on_error);
10656 break;
10657 default:
10658 goto unsupported;
10659 }
10660 break;
10661#ifdef HAVE_HGE
10662 case TYPE_hge:
10663 switch (tp) {
10664 case TYPE_dbl:
10665 nils = mod_dbl_hge_dbl(lft, incr1, rgt, incr2,
10666 dst, cnt, ci, candoff,
10667 abort_on_error);
10668 break;
10669 default:
10670 goto unsupported;
10671 }
10672 break;
10673#endif
10674 case TYPE_flt:
10675 switch (tp) {
10676 case TYPE_dbl:
10677 nils = mod_dbl_flt_dbl(lft, incr1, rgt, incr2,
10678 dst, cnt, ci, candoff,
10679 abort_on_error);
10680 break;
10681 default:
10682 goto unsupported;
10683 }
10684 break;
10685 case TYPE_dbl:
10686 switch (tp) {
10687 case TYPE_dbl:
10688 nils = mod_dbl_dbl_dbl(lft, incr1, rgt, incr2,
10689 dst, cnt, ci, candoff,
10690 abort_on_error);
10691 break;
10692 default:
10693 goto unsupported;
10694 }
10695 break;
10696 default:
10697 goto unsupported;
10698 }
10699 break;
10700 default:
10701 goto unsupported;
10702 }
10703
10704 if (nils == BUN_NONE + 1)
10705 GDKerror("22012!division by zero.\n");
10706
10707 return nils;
10708
10709 unsupported:
10710 GDKerror("%s: type combination (mod(%s,%s)->%s) not supported.\n",
10711 func, ATOMname(tp1), ATOMname(tp2), ATOMname(tp));
10712 return BUN_NONE;
10713}
10714
10715BAT *
10716BATcalcmod(BAT *b1, BAT *b2, BAT *s, int tp, bool abort_on_error)
10717{
10718 return BATcalcmuldivmod(b1, b2, s, tp, abort_on_error,
10719 mod_typeswitchloop, __func__);
10720}
10721
10722BAT *
10723BATcalcmodcst(BAT *b, const ValRecord *v, BAT *s, int tp, bool abort_on_error)
10724{
10725 BAT *bn;
10726 BUN nils;
10727 BUN cnt, ncand;
10728 struct canditer ci;
10729
10730 BATcheck(b, __func__, NULL);
10731
10732 cnt = BATcount(b);
10733 ncand = canditer_init(&ci, b, s);
10734 if (ncand == 0)
10735 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
10736 cnt, TRANSIENT);
10737
10738 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
10739 if (bn == NULL)
10740 return NULL;
10741
10742 nils = mod_typeswitchloop(Tloc(b, 0), b->ttype, 1,
10743 VALptr(v), v->vtype, 0,
10744 Tloc(bn, 0), tp,
10745 cnt, &ci, b->hseqbase,
10746 abort_on_error, __func__);
10747
10748 if (nils >= BUN_NONE) {
10749 BBPunfix(bn->batCacheid);
10750 return NULL;
10751 }
10752
10753 BATsetcount(bn, cnt);
10754
10755 bn->tsorted = cnt <= 1 || nils == cnt;
10756 bn->trevsorted = cnt <= 1 || nils == cnt;
10757 bn->tkey = cnt <= 1;
10758 bn->tnil = nils != 0;
10759 bn->tnonil = nils == 0;
10760
10761 return bn;
10762}
10763
10764BAT *
10765BATcalccstmod(const ValRecord *v, BAT *b, BAT *s, int tp, bool abort_on_error)
10766{
10767 BAT *bn;
10768 BUN nils;
10769 BUN cnt, ncand;
10770 struct canditer ci;
10771
10772 BATcheck(b, __func__, NULL);
10773
10774 cnt = BATcount(b);
10775 ncand = canditer_init(&ci, b, s);
10776 if (ncand == 0)
10777 return BATconstant(b->hseqbase, tp, ATOMnilptr(tp),
10778 cnt, TRANSIENT);
10779
10780 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
10781 if (bn == NULL)
10782 return NULL;
10783
10784 nils = mod_typeswitchloop(VALptr(v), v->vtype, 0,
10785 Tloc(b, 0), b->ttype, 1,
10786 Tloc(bn, 0), tp,
10787 cnt, &ci, b->hseqbase,
10788 abort_on_error, __func__);
10789
10790 if (nils >= BUN_NONE) {
10791 BBPunfix(bn->batCacheid);
10792 return NULL;
10793 }
10794
10795 BATsetcount(bn, cnt);
10796
10797 bn->tsorted = cnt <= 1 || nils == cnt;
10798 bn->trevsorted = cnt <= 1 || nils == cnt;
10799 bn->tkey = cnt <= 1;
10800 bn->tnil = nils != 0;
10801 bn->tnonil = nils == 0;
10802
10803 return bn;
10804}
10805
10806gdk_return
10807VARcalcmod(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
10808 bool abort_on_error)
10809{
10810 if (mod_typeswitchloop(VALptr(lft), lft->vtype, 0,
10811 VALptr(rgt), rgt->vtype, 0,
10812 VALget(ret), ret->vtype, 1,
10813 &(struct canditer){.tpe=cand_dense, .ncand=1},
10814 0, abort_on_error, __func__) >= BUN_NONE)
10815 return GDK_FAIL;
10816 return GDK_SUCCEED;
10817}
10818
10819/* ---------------------------------------------------------------------- */
10820/* logical (for type bit) or bitwise (for integral types) exclusive OR */
10821
10822#define XOR(a, b) ((a) ^ (b))
10823#define XORBIT(a, b) (((a) == 0) != ((b) == 0))
10824
10825static BUN
10826xor_typeswitchloop(const void *lft, int incr1,
10827 const void *rgt, int incr2,
10828 void *restrict dst, int tp, BUN cnt,
10829 struct canditer *restrict ci, oid candoff,
10830 int nonil, const char *func)
10831{
10832 oid x = canditer_next(ci) - candoff;
10833 BUN i, j, k = 0;
10834 BUN nils = 0;
10835
10836 switch (ATOMbasetype(tp)) {
10837 case TYPE_bte:
10838 if (tp == TYPE_bit) {
10839 if (nonil)
10840 BINARY_3TYPE_FUNC_nonil(bit, bit, bit, XORBIT);
10841 else
10842 BINARY_3TYPE_FUNC(bit, bit, bit, XORBIT);
10843 } else {
10844 if (nonil)
10845 BINARY_3TYPE_FUNC_nonil(bte, bte, bte, XOR);
10846 else
10847 BINARY_3TYPE_FUNC(bte, bte, bte, XOR);
10848 }
10849 break;
10850 case TYPE_sht:
10851 if (nonil)
10852 BINARY_3TYPE_FUNC_nonil(sht, sht, sht, XOR);
10853 else
10854 BINARY_3TYPE_FUNC(sht, sht, sht, XOR);
10855 break;
10856 case TYPE_int:
10857 if (nonil)
10858 BINARY_3TYPE_FUNC_nonil(int, int, int, XOR);
10859 else
10860 BINARY_3TYPE_FUNC(int, int, int, XOR);
10861 break;
10862 case TYPE_lng:
10863 if (nonil)
10864 BINARY_3TYPE_FUNC_nonil(lng, lng, lng, XOR);
10865 else
10866 BINARY_3TYPE_FUNC(lng, lng, lng, XOR);
10867 break;
10868#ifdef HAVE_HGE
10869 case TYPE_hge:
10870 if (nonil)
10871 BINARY_3TYPE_FUNC_nonil(hge, hge, hge, XOR);
10872 else
10873 BINARY_3TYPE_FUNC(hge, hge, hge, XOR);
10874 break;
10875#endif
10876 default:
10877 GDKerror("%s: bad input type %s.\n", func, ATOMname(tp));
10878 return BUN_NONE;
10879 }
10880
10881 return nils;
10882}
10883
10884BAT *
10885BATcalcxor(BAT *b1, BAT *b2, BAT *s)
10886{
10887 BAT *bn;
10888 BUN nils;
10889 BUN cnt, ncand;
10890 struct canditer ci;
10891
10892 BATcheck(b1, __func__, NULL);
10893 BATcheck(b2, __func__, NULL);
10894
10895 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
10896 return NULL;
10897
10898 if (ATOMbasetype(b1->ttype) != ATOMbasetype(b2->ttype)) {
10899 GDKerror("%s: incompatible input types.\n", __func__);
10900 return NULL;
10901 }
10902
10903 cnt = BATcount(b1);
10904 ncand = canditer_init(&ci, b1, s);
10905 if (ncand == 0)
10906 return BATconstant(b1->hseqbase, b1->ttype,
10907 ATOMnilptr(b1->ttype), cnt, TRANSIENT);
10908
10909 bn = COLnew(b1->hseqbase, b1->ttype, cnt, TRANSIENT);
10910 if (bn == NULL)
10911 return NULL;
10912
10913 nils = xor_typeswitchloop(Tloc(b1, 0), 1,
10914 Tloc(b2, 0), 1,
10915 Tloc(bn, 0),
10916 b1->ttype, cnt,
10917 &ci, b1->hseqbase,
10918 cnt == ncand && b1->tnonil && b2->tnonil,
10919 __func__);
10920
10921 if (nils == BUN_NONE) {
10922 BBPunfix(bn->batCacheid);
10923 return NULL;
10924 }
10925
10926 BATsetcount(bn, cnt);
10927
10928 bn->tsorted = cnt <= 1 || nils == cnt;
10929 bn->trevsorted = cnt <= 1 || nils == cnt;
10930 bn->tkey = cnt <= 1;
10931 bn->tnil = nils != 0;
10932 bn->tnonil = nils == 0;
10933
10934 return bn;
10935}
10936
10937BAT *
10938BATcalcxorcst(BAT *b, const ValRecord *v, BAT *s)
10939{
10940 BAT *bn;
10941 BUN nils;
10942 BUN cnt, ncand;
10943 struct canditer ci;
10944
10945 BATcheck(b, __func__, NULL);
10946
10947 if (ATOMbasetype(b->ttype) != ATOMbasetype(v->vtype)) {
10948 GDKerror("%s: incompatible input types.\n", __func__);
10949 return NULL;
10950 }
10951
10952 cnt = BATcount(b);
10953 ncand = canditer_init(&ci, b, s);
10954 if (ncand == 0)
10955 return BATconstant(b->hseqbase, b->ttype, ATOMnilptr(b->ttype),
10956 cnt, TRANSIENT);
10957
10958 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
10959 if (bn == NULL)
10960 return NULL;
10961
10962 nils = xor_typeswitchloop(Tloc(b, 0), 1,
10963 VALptr(v), 0,
10964 Tloc(bn, 0), b->ttype,
10965 cnt,
10966 &ci, b->hseqbase,
10967 cnt == ncand && b->tnonil && ATOMcmp(v->vtype, VALptr(v), ATOMnilptr(v->vtype)) != 0,
10968 __func__);
10969
10970 if (nils == BUN_NONE) {
10971 BBPunfix(bn->batCacheid);
10972 return NULL;
10973 }
10974
10975 BATsetcount(bn, cnt);
10976
10977 bn->tsorted = cnt <= 1 || nils == cnt;
10978 bn->trevsorted = cnt <= 1 || nils == cnt;
10979 bn->tkey = cnt <= 1;
10980 bn->tnil = nils != 0;
10981 bn->tnonil = nils == 0;
10982
10983 return bn;
10984}
10985
10986BAT *
10987BATcalccstxor(const ValRecord *v, BAT *b, BAT *s)
10988{
10989 return BATcalcxorcst(b, v, s);
10990}
10991
10992gdk_return
10993VARcalcxor(ValPtr ret, const ValRecord *lft, const ValRecord *rgt)
10994{
10995 if (ATOMbasetype(lft->vtype) != ATOMbasetype(rgt->vtype)) {
10996 GDKerror("VARcalccstxor: incompatible input types.\n");
10997 return GDK_FAIL;
10998 }
10999
11000 if (xor_typeswitchloop(VALptr(lft), 0,
11001 VALptr(rgt), 0,
11002 VALget(ret), lft->vtype, 1,
11003 &(struct canditer){.tpe=cand_dense, .ncand=1},
11004 0, 0, __func__) == BUN_NONE)
11005 return GDK_FAIL;
11006 return GDK_SUCCEED;
11007}
11008
11009/* ---------------------------------------------------------------------- */
11010/* logical (for type bit) or bitwise (for integral types) OR */
11011
11012#define or3(a,b) ((a) == 1 || (b) == 1 ? 1 : is_bit_nil(a) || is_bit_nil(b) ? bit_nil : 0)
11013
11014#define OR(a, b) ((a) | (b))
11015
11016static BUN
11017or_typeswitchloop(const void *lft, int incr1,
11018 const void *rgt, int incr2,
11019 void *restrict dst, int tp, BUN cnt,
11020 struct canditer *restrict ci, oid candoff,
11021 int nonil, const char *func)
11022{
11023 oid x = canditer_next(ci) - candoff;
11024 BUN i, j, k = 0;
11025 BUN nils = 0;
11026
11027 switch (ATOMbasetype(tp)) {
11028 case TYPE_bte:
11029 if (tp == TYPE_bit) {
11030 /* implement tri-Boolean algebra */
11031 do {
11032 while (k < x) {
11033 ((bit *) dst)[k++] = bit_nil;
11034 nils++;
11035 }
11036 i = x * incr1;
11037 j = x * incr2;
11038 bit v1 = ((const bit *) lft)[i];
11039 bit v2 = ((const bit *) rgt)[j];
11040 ((bit *) dst)[k] = or3(v1, v2);
11041 nils += is_bit_nil(((bit *) dst)[k]);
11042 k++;
11043 x = canditer_next(ci);
11044 if (is_oid_nil(x))
11045 break;
11046 x -= candoff;
11047 } while (k < cnt);
11048 while (k < cnt) {
11049 ((bit *) dst)[k++] = bit_nil;
11050 nils++;
11051 }
11052 } else {
11053 if (nonil)
11054 BINARY_3TYPE_FUNC_nonil(bte, bte, bte, OR);
11055 else
11056 BINARY_3TYPE_FUNC(bte, bte, bte, OR);
11057 }
11058 break;
11059 case TYPE_sht:
11060 if (nonil)
11061 BINARY_3TYPE_FUNC_nonil(sht, sht, sht, OR);
11062 else
11063 BINARY_3TYPE_FUNC(sht, sht, sht, OR);
11064 break;
11065 case TYPE_int:
11066 if (nonil)
11067 BINARY_3TYPE_FUNC_nonil(int, int, int, OR);
11068 else
11069 BINARY_3TYPE_FUNC(int, int, int, OR);
11070 break;
11071 case TYPE_lng:
11072 if (nonil)
11073 BINARY_3TYPE_FUNC_nonil(lng, lng, lng, OR);
11074 else
11075 BINARY_3TYPE_FUNC(lng, lng, lng, OR);
11076 break;
11077#ifdef HAVE_HGE
11078 case TYPE_hge:
11079 if (nonil)
11080 BINARY_3TYPE_FUNC_nonil(hge, hge, hge, OR);
11081 else
11082 BINARY_3TYPE_FUNC(hge, hge, hge, OR);
11083 break;
11084#endif
11085 default:
11086 GDKerror("%s: bad input type %s.\n", func, ATOMname(tp));
11087 return BUN_NONE;
11088 }
11089
11090 return nils;
11091}
11092
11093BAT *
11094BATcalcor(BAT *b1, BAT *b2, BAT *s)
11095{
11096 BAT *bn;
11097 BUN nils;
11098 BUN cnt, ncand;
11099 struct canditer ci;
11100
11101 BATcheck(b1, __func__, NULL);
11102 BATcheck(b2, __func__, NULL);
11103
11104 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
11105 return NULL;
11106
11107 if (ATOMbasetype(b1->ttype) != ATOMbasetype(b2->ttype)) {
11108 GDKerror("%s: incompatible input types.\n", __func__);
11109 return NULL;
11110 }
11111
11112 cnt = BATcount(b1);
11113 ncand = canditer_init(&ci, b1, s);
11114 if (ncand == 0)
11115 return BATconstant(b1->hseqbase, b1->ttype,
11116 ATOMnilptr(b1->ttype), cnt, TRANSIENT);
11117
11118 bn = COLnew(b1->hseqbase, b1->ttype, cnt, TRANSIENT);
11119 if (bn == NULL)
11120 return NULL;
11121
11122 nils = or_typeswitchloop(Tloc(b1, 0), 1,
11123 Tloc(b2, 0), 1,
11124 Tloc(bn, 0),
11125 b1->ttype, cnt,
11126 &ci, b1->hseqbase,
11127 b1->tnonil && b2->tnonil,
11128 __func__);
11129
11130 if (nils == BUN_NONE) {
11131 BBPunfix(bn->batCacheid);
11132 return NULL;
11133 }
11134
11135 BATsetcount(bn, cnt);
11136
11137 bn->tsorted = cnt <= 1 || nils == cnt;
11138 bn->trevsorted = cnt <= 1 || nils == cnt;
11139 bn->tkey = cnt <= 1;
11140 bn->tnil = nils != 0;
11141 bn->tnonil = nils == 0;
11142
11143 return bn;
11144}
11145
11146BAT *
11147BATcalcorcst(BAT *b, const ValRecord *v, BAT *s)
11148{
11149 BAT *bn;
11150 BUN nils;
11151 BUN cnt, ncand;
11152 struct canditer ci;
11153
11154 BATcheck(b, __func__, NULL);
11155
11156 if (ATOMbasetype(b->ttype) != ATOMbasetype(v->vtype)) {
11157 GDKerror("%s: incompatible input types.\n", __func__);
11158 return NULL;
11159 }
11160
11161 cnt = BATcount(b);
11162 ncand = canditer_init(&ci, b, s);
11163 if (ncand == 0)
11164 return BATconstant(b->hseqbase, b->ttype, ATOMnilptr(b->ttype),
11165 cnt, TRANSIENT);
11166
11167 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
11168 if (bn == NULL)
11169 return NULL;
11170
11171 nils = or_typeswitchloop(Tloc(b, 0), 1,
11172 VALptr(v), 0,
11173 Tloc(bn, 0), b->ttype,
11174 cnt,
11175 &ci, b->hseqbase,
11176 cnt == ncand && b->tnonil && ATOMcmp(v->vtype, VALptr(v), ATOMnilptr(v->vtype)) != 0,
11177 __func__);
11178
11179 if (nils == BUN_NONE) {
11180 BBPunfix(bn->batCacheid);
11181 return NULL;
11182 }
11183
11184 BATsetcount(bn, cnt);
11185
11186 bn->tsorted = cnt <= 1 || nils == cnt;
11187 bn->trevsorted = cnt <= 1 || nils == cnt;
11188 bn->tkey = cnt <= 1;
11189 bn->tnil = nils != 0;
11190 bn->tnonil = nils == 0;
11191
11192 return bn;
11193}
11194
11195BAT *
11196BATcalccstor(const ValRecord *v, BAT *b, BAT *s)
11197{
11198 return BATcalcorcst(b, v, s);
11199}
11200
11201gdk_return
11202VARcalcor(ValPtr ret, const ValRecord *lft, const ValRecord *rgt)
11203{
11204 if (ATOMbasetype(lft->vtype) != ATOMbasetype(rgt->vtype)) {
11205 GDKerror("VARcalccstor: incompatible input types.\n");
11206 return GDK_FAIL;
11207 }
11208
11209 if (or_typeswitchloop(VALptr(lft), 0,
11210 VALptr(rgt), 0,
11211 VALget(ret), lft->vtype, 1,
11212 &(struct canditer){.tpe=cand_dense, .ncand=1},
11213 0, 0, __func__) == BUN_NONE)
11214 return GDK_FAIL;
11215 return GDK_SUCCEED;
11216}
11217
11218/* ---------------------------------------------------------------------- */
11219/* logical (for type bit) or bitwise (for integral types) exclusive AND */
11220
11221#define and3(a,b) ((a) == 0 || (b) == 0 ? 0 : is_bit_nil(a) || is_bit_nil(b) ? bit_nil : 1)
11222
11223#define AND(a, b) ((a) & (b))
11224
11225static BUN
11226and_typeswitchloop(const void *lft, int incr1,
11227 const void *rgt, int incr2,
11228 void *restrict dst, int tp, BUN cnt,
11229 struct canditer *restrict ci, oid candoff,
11230 int nonil, const char *func)
11231{
11232 oid x = canditer_next(ci) - candoff;
11233 BUN i, j, k = 0;
11234 BUN nils = 0;
11235
11236 switch (ATOMbasetype(tp)) {
11237 case TYPE_bte:
11238 if (tp == TYPE_bit) {
11239 /* implement tri-Boolean algebra */
11240 do {
11241 while (k < x) {
11242 ((bit *) dst)[k++] = bit_nil;
11243 nils++;
11244 }
11245 i = x * incr1;
11246 j = x * incr2;
11247 bit v1 = ((const bit *) lft)[i];
11248 bit v2 = ((const bit *) rgt)[j];
11249 ((bit *) dst)[k] = and3(v1, v2);
11250 nils += is_bit_nil(((bit *) dst)[k]);
11251 k++;
11252 x = canditer_next(ci);
11253 if (is_oid_nil(x))
11254 break;
11255 x -= candoff;
11256 } while (k < cnt);
11257 while (k < cnt) {
11258 ((bit *) dst)[k++] = bit_nil;
11259 nils++;
11260 }
11261 } else {
11262 if (nonil)
11263 BINARY_3TYPE_FUNC_nonil(bte, bte, bte, AND);
11264 else
11265 BINARY_3TYPE_FUNC(bte, bte, bte, AND);
11266 }
11267 break;
11268 case TYPE_sht:
11269 if (nonil)
11270 BINARY_3TYPE_FUNC_nonil(sht, sht, sht, AND);
11271 else
11272 BINARY_3TYPE_FUNC(sht, sht, sht, AND);
11273 break;
11274 case TYPE_int:
11275 if (nonil)
11276 BINARY_3TYPE_FUNC_nonil(int, int, int, AND);
11277 else
11278 BINARY_3TYPE_FUNC(int, int, int, AND);
11279 break;
11280 case TYPE_lng:
11281 if (nonil)
11282 BINARY_3TYPE_FUNC_nonil(lng, lng, lng, AND);
11283 else
11284 BINARY_3TYPE_FUNC(lng, lng, lng, AND);
11285 break;
11286#ifdef HAVE_HGE
11287 case TYPE_hge:
11288 if (nonil)
11289 BINARY_3TYPE_FUNC_nonil(hge, hge, hge, AND);
11290 else
11291 BINARY_3TYPE_FUNC(hge, hge, hge, AND);
11292 break;
11293#endif
11294 default:
11295 GDKerror("%s: bad input type %s.\n", func, ATOMname(tp));
11296 return BUN_NONE;
11297 }
11298
11299 return nils;
11300}
11301
11302BAT *
11303BATcalcand(BAT *b1, BAT *b2, BAT *s)
11304{
11305 BAT *bn;
11306 BUN nils;
11307 BUN cnt, ncand;
11308 struct canditer ci;
11309
11310 BATcheck(b1, __func__, NULL);
11311 BATcheck(b2, __func__, NULL);
11312
11313 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
11314 return NULL;
11315
11316 if (ATOMbasetype(b1->ttype) != ATOMbasetype(b2->ttype)) {
11317 GDKerror("%s: incompatible input types.\n", __func__);
11318 return NULL;
11319 }
11320
11321 cnt = BATcount(b1);
11322 ncand = canditer_init(&ci, b1, s);
11323 if (ncand == 0)
11324 return BATconstant(b1->hseqbase, b1->ttype,
11325 ATOMnilptr(b1->ttype), cnt, TRANSIENT);
11326
11327 bn = COLnew(b1->hseqbase, b1->ttype, cnt, TRANSIENT);
11328 if (bn == NULL)
11329 return NULL;
11330
11331 nils = and_typeswitchloop(Tloc(b1, 0), 1,
11332 Tloc(b2, 0), 1,
11333 Tloc(bn, 0),
11334 b1->ttype, cnt,
11335 &ci, b1->hseqbase,
11336 b1->tnonil && b2->tnonil,
11337 __func__);
11338
11339 if (nils == BUN_NONE) {
11340 BBPunfix(bn->batCacheid);
11341 return NULL;
11342 }
11343
11344 BATsetcount(bn, cnt);
11345
11346 bn->tsorted = cnt <= 1 || nils == cnt;
11347 bn->trevsorted = cnt <= 1 || nils == cnt;
11348 bn->tkey = cnt <= 1;
11349 bn->tnil = nils != 0;
11350 bn->tnonil = nils == 0;
11351
11352 return bn;
11353}
11354
11355BAT *
11356BATcalcandcst(BAT *b, const ValRecord *v, BAT *s)
11357{
11358 BAT *bn;
11359 BUN nils;
11360 BUN cnt, ncand;
11361 struct canditer ci;
11362
11363 BATcheck(b, __func__, NULL);
11364
11365 if (ATOMbasetype(b->ttype) != ATOMbasetype(v->vtype)) {
11366 GDKerror("%s: incompatible input types.\n", __func__);
11367 return NULL;
11368 }
11369
11370 cnt = BATcount(b);
11371 ncand = canditer_init(&ci, b, s);
11372 if (ncand == 0)
11373 return BATconstant(b->hseqbase, b->ttype, ATOMnilptr(b->ttype),
11374 cnt, TRANSIENT);
11375
11376 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
11377 if (bn == NULL)
11378 return NULL;
11379
11380 nils = and_typeswitchloop(Tloc(b, 0), 1,
11381 VALptr(v), 0,
11382 Tloc(bn, 0), b->ttype,
11383 cnt, &ci, b->hseqbase,
11384 b->tnonil && ATOMcmp(v->vtype, VALptr(v), ATOMnilptr(v->vtype)) != 0,
11385 __func__);
11386
11387 if (nils == BUN_NONE) {
11388 BBPunfix(bn->batCacheid);
11389 return NULL;
11390 }
11391
11392 BATsetcount(bn, cnt);
11393
11394 bn->tsorted = cnt <= 1 || nils == cnt;
11395 bn->trevsorted = cnt <= 1 || nils == cnt;
11396 bn->tkey = cnt <= 1;
11397 bn->tnil = nils != 0;
11398 bn->tnonil = nils == 0;
11399
11400 return bn;
11401}
11402
11403BAT *
11404BATcalccstand(const ValRecord *v, BAT *b, BAT *s)
11405{
11406 return BATcalcandcst(b, v, s);
11407}
11408
11409gdk_return
11410VARcalcand(ValPtr ret, const ValRecord *lft, const ValRecord *rgt)
11411{
11412 if (ATOMbasetype(lft->vtype) != ATOMbasetype(rgt->vtype)) {
11413 GDKerror("VARcalccstand: incompatible input types.\n");
11414 return GDK_FAIL;
11415 }
11416
11417 if (and_typeswitchloop(VALptr(lft), 0,
11418 VALptr(rgt), 0,
11419 VALget(ret), lft->vtype, 1,
11420 &(struct canditer){.tpe=cand_dense, .ncand=1},
11421 0, 0, __func__) == BUN_NONE)
11422 return GDK_FAIL;
11423 return GDK_SUCCEED;
11424}
11425
11426/* ---------------------------------------------------------------------- */
11427/* left shift (any integral type) */
11428
11429#define LSH(a, b) ((a) << (b))
11430
11431#define SHIFT_CHECK(a, b) ((b) < 0 || (b) >= 8 * (int) sizeof(a))
11432#define NO_SHIFT_CHECK(a, b) 0
11433
11434/* In standard C, left shift is undefined if any of the following
11435 * conditions hold:
11436 * - right operand is negative or larger or equal to the width of the
11437 * left operand;
11438 * - left operand is negative;
11439 * - left operand times two-to-the-power of the right operand is not
11440 * representable in the (promoted) type of the left operand. */
11441#define LSH_CHECK(a, b, TYPE) (SHIFT_CHECK(a, b) || (a) < 0 || (a) > (GDK_##TYPE##_max >> (b)))
11442#define LSH_CHECK_bte(a, b) LSH_CHECK(a, b, bte)
11443#define LSH_CHECK_sht(a, b) LSH_CHECK(a, b, sht)
11444#define LSH_CHECK_int(a, b) LSH_CHECK(a, b, int)
11445#define LSH_CHECK_lng(a, b) LSH_CHECK(a, b, lng)
11446
11447static BUN
11448lsh_typeswitchloop(const void *lft, int tp1, int incr1,
11449 const void *rgt, int tp2, int incr2,
11450 void *restrict dst, BUN cnt,
11451 struct canditer *restrict ci, oid candoff,
11452 bool abort_on_error, const char *func)
11453{
11454 oid x = canditer_next(ci) - candoff;
11455 BUN i, j, k = 0;
11456 BUN nils = 0;
11457
11458 tp1 = ATOMbasetype(tp1);
11459 tp2 = ATOMbasetype(tp2);
11460 switch (tp1) {
11461 case TYPE_bte:
11462 switch (tp2) {
11463 case TYPE_bte:
11464 BINARY_3TYPE_FUNC_CHECK(bte, bte, bte, LSH,
11465 LSH_CHECK_bte);
11466 break;
11467 case TYPE_sht:
11468 BINARY_3TYPE_FUNC_CHECK(bte, sht, bte, LSH,
11469 LSH_CHECK_bte);
11470 break;
11471 case TYPE_int:
11472 BINARY_3TYPE_FUNC_CHECK(bte, int, bte, LSH,
11473 LSH_CHECK_bte);
11474 break;
11475 case TYPE_lng:
11476 BINARY_3TYPE_FUNC_CHECK(bte, lng, bte, LSH,
11477 LSH_CHECK_bte);
11478 break;
11479#ifdef HAVE_HGE
11480 case TYPE_hge:
11481 BINARY_3TYPE_FUNC_CHECK(bte, hge, bte, LSH,
11482 SHIFT_CHECK);
11483 break;
11484#endif
11485 default:
11486 goto unsupported;
11487 }
11488 break;
11489 case TYPE_sht:
11490 switch (tp2) {
11491 case TYPE_bte:
11492 BINARY_3TYPE_FUNC_CHECK(sht, bte, sht, LSH,
11493 LSH_CHECK_sht);
11494 break;
11495 case TYPE_sht:
11496 BINARY_3TYPE_FUNC_CHECK(sht, sht, sht, LSH,
11497 LSH_CHECK_sht);
11498 break;
11499 case TYPE_int:
11500 BINARY_3TYPE_FUNC_CHECK(sht, int, sht, LSH,
11501 LSH_CHECK_sht);
11502 break;
11503 case TYPE_lng:
11504 BINARY_3TYPE_FUNC_CHECK(sht, lng, sht, LSH,
11505 LSH_CHECK_sht);
11506 break;
11507#ifdef HAVE_HGE
11508 case TYPE_hge:
11509 BINARY_3TYPE_FUNC_CHECK(sht, hge, sht, LSH,
11510 SHIFT_CHECK);
11511 break;
11512#endif
11513 default:
11514 goto unsupported;
11515 }
11516 break;
11517 case TYPE_int:
11518 switch (tp2) {
11519 case TYPE_bte:
11520 BINARY_3TYPE_FUNC_CHECK(int, bte, int, LSH,
11521 LSH_CHECK_int);
11522 break;
11523 case TYPE_sht:
11524 BINARY_3TYPE_FUNC_CHECK(int, sht, int, LSH,
11525 LSH_CHECK_int);
11526 break;
11527 case TYPE_int:
11528 BINARY_3TYPE_FUNC_CHECK(int, int, int, LSH,
11529 LSH_CHECK_int);
11530 break;
11531 case TYPE_lng:
11532 BINARY_3TYPE_FUNC_CHECK(int, lng, int, LSH,
11533 LSH_CHECK_int);
11534 break;
11535#ifdef HAVE_HGE
11536 case TYPE_hge:
11537 BINARY_3TYPE_FUNC_CHECK(int, hge, int, LSH,
11538 SHIFT_CHECK);
11539 break;
11540#endif
11541 default:
11542 goto unsupported;
11543 }
11544 break;
11545 case TYPE_lng:
11546 switch (tp2) {
11547 case TYPE_bte:
11548 BINARY_3TYPE_FUNC_CHECK(lng, bte, lng, LSH,
11549 LSH_CHECK_lng);
11550 break;
11551 case TYPE_sht:
11552 BINARY_3TYPE_FUNC_CHECK(lng, sht, lng, LSH,
11553 LSH_CHECK_lng);
11554 break;
11555 case TYPE_int:
11556 BINARY_3TYPE_FUNC_CHECK(lng, int, lng, LSH,
11557 LSH_CHECK_lng);
11558 break;
11559 case TYPE_lng:
11560 BINARY_3TYPE_FUNC_CHECK(lng, lng, lng, LSH,
11561 LSH_CHECK_lng);
11562 break;
11563#ifdef HAVE_HGE
11564 case TYPE_hge:
11565 BINARY_3TYPE_FUNC_CHECK(lng, hge, lng, LSH,
11566 SHIFT_CHECK);
11567 break;
11568#endif
11569 default:
11570 goto unsupported;
11571 }
11572 break;
11573#ifdef HAVE_HGE
11574 case TYPE_hge:
11575 switch (tp2) {
11576 case TYPE_bte:
11577 BINARY_3TYPE_FUNC_CHECK(hge, bte, hge, LSH,
11578 NO_SHIFT_CHECK);
11579 break;
11580 case TYPE_sht:
11581 BINARY_3TYPE_FUNC_CHECK(hge, sht, hge, LSH,
11582 SHIFT_CHECK);
11583 break;
11584 case TYPE_int:
11585 BINARY_3TYPE_FUNC_CHECK(hge, int, hge, LSH,
11586 SHIFT_CHECK);
11587 break;
11588 case TYPE_lng:
11589 BINARY_3TYPE_FUNC_CHECK(hge, lng, hge, LSH,
11590 SHIFT_CHECK);
11591 break;
11592 case TYPE_hge:
11593 BINARY_3TYPE_FUNC_CHECK(hge, hge, hge, LSH,
11594 SHIFT_CHECK);
11595 break;
11596 default:
11597 goto unsupported;
11598 }
11599 break;
11600#endif
11601 default:
11602 goto unsupported;
11603 }
11604
11605 return nils;
11606
11607 unsupported:
11608 GDKerror("%s: bad input types %s,%s.\n", func,
11609 ATOMname(tp1), ATOMname(tp2));
11610 checkfail:
11611 return BUN_NONE;
11612}
11613
11614BAT *
11615BATcalclsh(BAT *b1, BAT *b2, BAT *s, bool abort_on_error)
11616{
11617 BAT *bn;
11618 BUN nils;
11619 BUN cnt, ncand;
11620 struct canditer ci;
11621
11622 BATcheck(b1, __func__, NULL);
11623 BATcheck(b2, __func__, NULL);
11624
11625 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
11626 return NULL;
11627
11628 cnt = BATcount(b1);
11629 ncand = canditer_init(&ci, b1, s);
11630 if (ncand == 0)
11631 return BATconstant(b1->hseqbase, b1->ttype,
11632 ATOMnilptr(b1->ttype), cnt, TRANSIENT);
11633
11634 bn = COLnew(b1->hseqbase, b1->ttype, cnt, TRANSIENT);
11635 if (bn == NULL)
11636 return NULL;
11637
11638 nils = lsh_typeswitchloop(Tloc(b1, 0), b1->ttype, 1,
11639 Tloc(b2, 0), b2->ttype, 1,
11640 Tloc(bn, 0),
11641 cnt, &ci, b1->hseqbase,
11642 abort_on_error, __func__);
11643
11644 if (nils == BUN_NONE) {
11645 BBPunfix(bn->batCacheid);
11646 return NULL;
11647 }
11648
11649 BATsetcount(bn, cnt);
11650
11651 bn->tsorted = cnt <= 1 || nils == cnt;
11652 bn->trevsorted = cnt <= 1 || nils == cnt;
11653 bn->tkey = cnt <= 1;
11654 bn->tnil = nils != 0;
11655 bn->tnonil = nils == 0;
11656
11657 return bn;
11658}
11659
11660BAT *
11661BATcalclshcst(BAT *b, const ValRecord *v, BAT *s, bool abort_on_error)
11662{
11663 BAT *bn;
11664 BUN nils;
11665 BUN cnt, ncand;
11666 struct canditer ci;
11667
11668 BATcheck(b, __func__, NULL);
11669
11670 cnt = BATcount(b);
11671 ncand = canditer_init(&ci, b, s);
11672 if (ncand == 0)
11673 return BATconstant(b->hseqbase, b->ttype, ATOMnilptr(b->ttype),
11674 cnt, TRANSIENT);
11675
11676 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
11677 if (bn == NULL)
11678 return NULL;
11679
11680 nils = lsh_typeswitchloop(Tloc(b, 0), b->ttype, 1,
11681 VALptr(v), v->vtype, 0,
11682 Tloc(bn, 0),
11683 cnt, &ci, b->hseqbase,
11684 abort_on_error, __func__);
11685
11686 if (nils == BUN_NONE) {
11687 BBPunfix(bn->batCacheid);
11688 return NULL;
11689 }
11690
11691 BATsetcount(bn, cnt);
11692
11693 bn->tsorted = cnt <= 1 || nils == cnt;
11694 bn->trevsorted = cnt <= 1 || nils == cnt;
11695 bn->tkey = cnt <= 1;
11696 bn->tnil = nils != 0;
11697 bn->tnonil = nils == 0;
11698
11699 return bn;
11700}
11701
11702BAT *
11703BATcalccstlsh(const ValRecord *v, BAT *b, BAT *s, bool abort_on_error)
11704{
11705 BAT *bn;
11706 BUN nils;
11707 BUN cnt, ncand;
11708 struct canditer ci;
11709
11710 BATcheck(b, __func__, NULL);
11711
11712 cnt = BATcount(b);
11713 ncand = canditer_init(&ci, b, s);
11714 if (ncand == 0)
11715 return BATconstant(b->hseqbase, v->vtype, ATOMnilptr(v->vtype),
11716 cnt, TRANSIENT);
11717
11718 bn = COLnew(b->hseqbase, v->vtype, cnt, TRANSIENT);
11719 if (bn == NULL)
11720 return NULL;
11721
11722 nils = lsh_typeswitchloop(VALptr(v), v->vtype, 0,
11723 Tloc(b, 0), b->ttype, 1,
11724 Tloc(bn, 0),
11725 cnt, &ci, b->hseqbase,
11726 abort_on_error, __func__);
11727
11728 if (nils == BUN_NONE) {
11729 BBPunfix(bn->batCacheid);
11730 return NULL;
11731 }
11732
11733 BATsetcount(bn, cnt);
11734
11735 bn->tsorted = cnt <= 1 || nils == cnt;
11736 bn->trevsorted = cnt <= 1 || nils == cnt;
11737 bn->tkey = cnt <= 1;
11738 bn->tnil = nils != 0;
11739 bn->tnonil = nils == 0;
11740
11741 return bn;
11742}
11743
11744gdk_return
11745VARcalclsh(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
11746 bool abort_on_error)
11747{
11748 ret->vtype = lft->vtype;
11749 if (lsh_typeswitchloop(VALptr(lft), lft->vtype, 0,
11750 VALptr(rgt), rgt->vtype, 0,
11751 VALget(ret), 1,
11752 &(struct canditer){.tpe=cand_dense, .ncand=1},
11753 0, abort_on_error, __func__) == BUN_NONE)
11754 return GDK_FAIL;
11755 return GDK_SUCCEED;
11756}
11757
11758/* ---------------------------------------------------------------------- */
11759/* right shift (any integral type) */
11760
11761#define RSH(a, b) ((a) >> (b))
11762
11763static BUN
11764rsh_typeswitchloop(const void *lft, int tp1, int incr1,
11765 const void *rgt, int tp2, int incr2,
11766 void *restrict dst, BUN cnt,
11767 struct canditer *restrict ci, oid candoff,
11768 bool abort_on_error, const char *func)
11769{
11770 oid x = canditer_next(ci) - candoff;
11771 BUN i, j, k = 0;
11772 BUN nils = 0;
11773
11774 tp1 = ATOMbasetype(tp1);
11775 tp2 = ATOMbasetype(tp2);
11776 switch (tp1) {
11777 case TYPE_bte:
11778 switch (tp2) {
11779 case TYPE_bte:
11780 BINARY_3TYPE_FUNC_CHECK(bte, bte, bte, RSH,
11781 SHIFT_CHECK);
11782 break;
11783 case TYPE_sht:
11784 BINARY_3TYPE_FUNC_CHECK(bte, sht, bte, RSH,
11785 SHIFT_CHECK);
11786 break;
11787 case TYPE_int:
11788 BINARY_3TYPE_FUNC_CHECK(bte, int, bte, RSH,
11789 SHIFT_CHECK);
11790 break;
11791 case TYPE_lng:
11792 BINARY_3TYPE_FUNC_CHECK(bte, lng, bte, RSH,
11793 SHIFT_CHECK);
11794 break;
11795#ifdef HAVE_HGE
11796 case TYPE_hge:
11797 BINARY_3TYPE_FUNC_CHECK(bte, hge, bte, RSH,
11798 SHIFT_CHECK);
11799 break;
11800#endif
11801 default:
11802 goto unsupported;
11803 }
11804 break;
11805 case TYPE_sht:
11806 switch (tp2) {
11807 case TYPE_bte:
11808 BINARY_3TYPE_FUNC_CHECK(sht, bte, sht, RSH,
11809 SHIFT_CHECK);
11810 break;
11811 case TYPE_sht:
11812 BINARY_3TYPE_FUNC_CHECK(sht, sht, sht, RSH,
11813 SHIFT_CHECK);
11814 break;
11815 case TYPE_int:
11816 BINARY_3TYPE_FUNC_CHECK(sht, int, sht, RSH,
11817 SHIFT_CHECK);
11818 break;
11819 case TYPE_lng:
11820 BINARY_3TYPE_FUNC_CHECK(sht, lng, sht, RSH,
11821 SHIFT_CHECK);
11822 break;
11823#ifdef HAVE_HGE
11824 case TYPE_hge:
11825 BINARY_3TYPE_FUNC_CHECK(sht, hge, sht, RSH,
11826 SHIFT_CHECK);
11827 break;
11828#endif
11829 default:
11830 goto unsupported;
11831 }
11832 break;
11833 case TYPE_int:
11834 switch (tp2) {
11835 case TYPE_bte:
11836 BINARY_3TYPE_FUNC_CHECK(int, bte, int, RSH,
11837 SHIFT_CHECK);
11838 break;
11839 case TYPE_sht:
11840 BINARY_3TYPE_FUNC_CHECK(int, sht, int, RSH,
11841 SHIFT_CHECK);
11842 break;
11843 case TYPE_int:
11844 BINARY_3TYPE_FUNC_CHECK(int, int, int, RSH,
11845 SHIFT_CHECK);
11846 break;
11847 case TYPE_lng:
11848 BINARY_3TYPE_FUNC_CHECK(int, lng, int, RSH,
11849 SHIFT_CHECK);
11850 break;
11851#ifdef HAVE_HGE
11852 case TYPE_hge:
11853 BINARY_3TYPE_FUNC_CHECK(int, hge, int, RSH,
11854 SHIFT_CHECK);
11855 break;
11856#endif
11857 default:
11858 goto unsupported;
11859 }
11860 break;
11861 case TYPE_lng:
11862 switch (tp2) {
11863 case TYPE_bte:
11864 BINARY_3TYPE_FUNC_CHECK(lng, bte, lng, RSH,
11865 SHIFT_CHECK);
11866 break;
11867 case TYPE_sht:
11868 BINARY_3TYPE_FUNC_CHECK(lng, sht, lng, RSH,
11869 SHIFT_CHECK);
11870 break;
11871 case TYPE_int:
11872 BINARY_3TYPE_FUNC_CHECK(lng, int, lng, RSH,
11873 SHIFT_CHECK);
11874 break;
11875 case TYPE_lng:
11876 BINARY_3TYPE_FUNC_CHECK(lng, lng, lng, RSH,
11877 SHIFT_CHECK);
11878 break;
11879#ifdef HAVE_HGE
11880 case TYPE_hge:
11881 BINARY_3TYPE_FUNC_CHECK(lng, hge, lng, RSH,
11882 SHIFT_CHECK);
11883 break;
11884#endif
11885 default:
11886 goto unsupported;
11887 }
11888 break;
11889#ifdef HAVE_HGE
11890 case TYPE_hge:
11891 switch (tp2) {
11892 case TYPE_bte:
11893 BINARY_3TYPE_FUNC_CHECK(hge, bte, hge, RSH,
11894 NO_SHIFT_CHECK);
11895 break;
11896 case TYPE_sht:
11897 BINARY_3TYPE_FUNC_CHECK(hge, sht, hge, RSH,
11898 SHIFT_CHECK);
11899 break;
11900 case TYPE_int:
11901 BINARY_3TYPE_FUNC_CHECK(hge, int, hge, RSH,
11902 SHIFT_CHECK);
11903 break;
11904 case TYPE_lng:
11905 BINARY_3TYPE_FUNC_CHECK(hge, lng, hge, RSH,
11906 SHIFT_CHECK);
11907 break;
11908 case TYPE_hge:
11909 BINARY_3TYPE_FUNC_CHECK(hge, hge, hge, RSH,
11910 SHIFT_CHECK);
11911 break;
11912 default:
11913 goto unsupported;
11914 }
11915 break;
11916#endif
11917 default:
11918 goto unsupported;
11919 }
11920
11921 return nils;
11922
11923 unsupported:
11924 GDKerror("%s: bad input types %s,%s.\n", func,
11925 ATOMname(tp1), ATOMname(tp2));
11926 checkfail:
11927 return BUN_NONE;
11928}
11929
11930BAT *
11931BATcalcrsh(BAT *b1, BAT *b2, BAT *s, bool abort_on_error)
11932{
11933 BAT *bn;
11934 BUN nils;
11935 BUN cnt, ncand;
11936 struct canditer ci;
11937
11938 BATcheck(b1, __func__, NULL);
11939 BATcheck(b2, __func__, NULL);
11940
11941 if (checkbats(b1, b2, __func__) != GDK_SUCCEED)
11942 return NULL;
11943
11944 cnt = BATcount(b1);
11945 ncand = canditer_init(&ci, b1, s);
11946 if (ncand == 0)
11947 return BATconstant(b1->hseqbase, b1->ttype,
11948 ATOMnilptr(b1->ttype), cnt, TRANSIENT);
11949
11950 bn = COLnew(b1->hseqbase, b1->ttype, cnt, TRANSIENT);
11951 if (bn == NULL)
11952 return NULL;
11953
11954 nils = rsh_typeswitchloop(Tloc(b1, 0), b1->ttype, 1,
11955 Tloc(b2, 0), b2->ttype, 1,
11956 Tloc(bn, 0),
11957 cnt, &ci, b1->hseqbase,
11958 abort_on_error, __func__);
11959
11960 if (nils == BUN_NONE) {
11961 BBPunfix(bn->batCacheid);
11962 return NULL;
11963 }
11964
11965 BATsetcount(bn, cnt);
11966
11967 bn->tsorted = cnt <= 1 || nils == cnt;
11968 bn->trevsorted = cnt <= 1 || nils == cnt;
11969 bn->tkey = cnt <= 1;
11970 bn->tnil = nils != 0;
11971 bn->tnonil = nils == 0;
11972
11973 return bn;
11974}
11975
11976BAT *
11977BATcalcrshcst(BAT *b, const ValRecord *v, BAT *s, bool abort_on_error)
11978{
11979 BAT *bn;
11980 BUN nils;
11981 BUN cnt, ncand;
11982 struct canditer ci;
11983
11984 BATcheck(b, __func__, NULL);
11985
11986 cnt = BATcount(b);
11987 ncand = canditer_init(&ci, b, s);
11988 if (ncand == 0)
11989 return BATconstant(b->hseqbase, b->ttype, ATOMnilptr(b->ttype),
11990 cnt, TRANSIENT);
11991
11992 bn = COLnew(b->hseqbase, b->ttype, cnt, TRANSIENT);
11993 if (bn == NULL)
11994 return NULL;
11995
11996 nils = rsh_typeswitchloop(Tloc(b, 0), b->ttype, 1,
11997 VALptr(v), v->vtype, 0,
11998 Tloc(bn, 0),
11999 cnt, &ci, b->hseqbase,
12000 abort_on_error, __func__);
12001
12002 if (nils == BUN_NONE) {
12003 BBPunfix(bn->batCacheid);
12004 return NULL;
12005 }
12006
12007 BATsetcount(bn, cnt);
12008
12009 bn->tsorted = cnt <= 1 || nils == cnt;
12010 bn->trevsorted = cnt <= 1 || nils == cnt;
12011 bn->tkey = cnt <= 1;
12012 bn->tnil = nils != 0;
12013 bn->tnonil = nils == 0;
12014
12015 return bn;
12016}
12017
12018BAT *
12019BATcalccstrsh(const ValRecord *v, BAT *b, BAT *s, bool abort_on_error)
12020{
12021 BAT *bn;
12022 BUN nils;
12023 BUN cnt, ncand;
12024 struct canditer ci;
12025
12026 BATcheck(b, __func__, NULL);
12027
12028 cnt = BATcount(b);
12029 ncand = canditer_init(&ci, b, s);
12030 if (ncand == 0)
12031 return BATconstant(b->hseqbase, v->vtype, ATOMnilptr(v->vtype),
12032 cnt, TRANSIENT);
12033
12034 bn = COLnew(b->hseqbase, v->vtype, cnt, TRANSIENT);
12035 if (bn == NULL)
12036 return NULL;
12037
12038 nils = rsh_typeswitchloop(VALptr(v), v->vtype, 0,
12039 Tloc(b, 0), b->ttype, 1,
12040 Tloc(bn, 0),
12041 cnt, &ci, b->hseqbase,
12042 abort_on_error, __func__);
12043
12044 if (nils == BUN_NONE) {
12045 BBPunfix(bn->batCacheid);
12046 return NULL;
12047 }
12048
12049 BATsetcount(bn, cnt);
12050
12051 bn->tsorted = cnt <= 1 || nils == cnt;
12052 bn->trevsorted = cnt <= 1 || nils == cnt;
12053 bn->tkey = cnt <= 1;
12054 bn->tnil = nils != 0;
12055 bn->tnonil = nils == 0;
12056
12057 return bn;
12058}
12059
12060gdk_return
12061VARcalcrsh(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
12062 bool abort_on_error)
12063{
12064 ret->vtype = lft->vtype;
12065 if (rsh_typeswitchloop(VALptr(lft), lft->vtype, 0,
12066 VALptr(rgt), rgt->vtype, 0,
12067 VALget(ret), 1,
12068 &(struct canditer){.tpe=cand_dense, .ncand=1},
12069 0, abort_on_error, __func__) == BUN_NONE)
12070 return GDK_FAIL;
12071 return GDK_SUCCEED;
12072}
12073
12074/* ---------------------------------------------------------------------- */
12075/* less than (any "linear" type) */
12076
12077/* these three are for all simple comparisons (6 in all) */
12078#define TYPE_TPE TYPE_bit
12079#define TPE bit
12080#define TPE_nil bit_nil
12081#define is_TPE_nil is_bit_nil
12082
12083#define OP LT
12084#define op_typeswitchloop lt_typeswitchloop
12085#define BATcalcop_intern BATcalclt_intern
12086#define BATcalcop BATcalclt
12087#define BATcalcopcst BATcalcltcst
12088#define BATcalccstop BATcalccstlt
12089#define VARcalcop VARcalclt
12090
12091#include "gdk_calc_compare.h"
12092
12093#undef OP
12094#undef op_typeswitchloop
12095#undef BATcalcop_intern
12096#undef BATcalcop
12097#undef BATcalcopcst
12098#undef BATcalccstop
12099#undef VARcalcop
12100
12101/* ---------------------------------------------------------------------- */
12102/* greater than (any "linear" type) */
12103
12104#define OP GT
12105#define op_typeswitchloop gt_typeswitchloop
12106#define BATcalcop_intern BATcalcgt_intern
12107#define BATcalcop BATcalcgt
12108#define BATcalcopcst BATcalcgtcst
12109#define BATcalccstop BATcalccstgt
12110#define VARcalcop VARcalcgt
12111
12112#include "gdk_calc_compare.h"
12113
12114#undef OP
12115#undef op_typeswitchloop
12116#undef BATcalcop_intern
12117#undef BATcalcop
12118#undef BATcalcopcst
12119#undef BATcalccstop
12120#undef VARcalcop
12121
12122/* ---------------------------------------------------------------------- */
12123/* less than or equal (any "linear" type) */
12124
12125#define LE(a, b) ((bit) ((a) <= (b)))
12126
12127#define OP LE
12128#define op_typeswitchloop le_typeswitchloop
12129#define BATcalcop_intern BATcalcle_intern
12130#define BATcalcop BATcalcle
12131#define BATcalcopcst BATcalclecst
12132#define BATcalccstop BATcalccstle
12133#define VARcalcop VARcalcle
12134
12135#include "gdk_calc_compare.h"
12136
12137#undef OP
12138#undef op_typeswitchloop
12139#undef BATcalcop_intern
12140#undef BATcalcop
12141#undef BATcalcopcst
12142#undef BATcalccstop
12143#undef VARcalcop
12144
12145/* ---------------------------------------------------------------------- */
12146/* greater than or equal (any "linear" type) */
12147
12148#define GE(a, b) ((bit) ((a) >= (b)))
12149
12150#define OP GE
12151#define op_typeswitchloop ge_typeswitchloop
12152#define BATcalcop_intern BATcalcge_intern
12153#define BATcalcop BATcalcge
12154#define BATcalcopcst BATcalcgecst
12155#define BATcalccstop BATcalccstge
12156#define VARcalcop VARcalcge
12157
12158#include "gdk_calc_compare.h"
12159
12160#undef OP
12161#undef op_typeswitchloop
12162#undef BATcalcop_intern
12163#undef BATcalcop
12164#undef BATcalcopcst
12165#undef BATcalccstop
12166#undef VARcalcop
12167
12168/* ---------------------------------------------------------------------- */
12169/* equal (any type) */
12170
12171#define EQ(a, b) ((bit) ((a) == (b)))
12172
12173#define OP EQ
12174#define op_typeswitchloop eq_typeswitchloop
12175#define BATcalcop_intern BATcalceq_intern
12176#define BATcalcop BATcalceq
12177#define BATcalcopcst BATcalceqcst
12178#define BATcalccstop BATcalccsteq
12179#define VARcalcop VARcalceq
12180
12181#define NIL_MATCHES_FLAG 1
12182
12183#include "gdk_calc_compare.h"
12184
12185#undef OP
12186#undef op_typeswitchloop
12187#undef BATcalcop_intern
12188#undef BATcalcop
12189#undef BATcalcopcst
12190#undef BATcalccstop
12191#undef VARcalcop
12192
12193/* ---------------------------------------------------------------------- */
12194/* not equal (any type) */
12195
12196#define NE(a, b) ((bit) ((a) != (b)))
12197
12198#define OP NE
12199#define op_typeswitchloop ne_typeswitchloop
12200#define BATcalcop_intern BATcalcne_intern
12201#define BATcalcop BATcalcne
12202#define BATcalcopcst BATcalcnecst
12203#define BATcalccstop BATcalccstne
12204#define VARcalcop VARcalcne
12205
12206#include "gdk_calc_compare.h"
12207
12208#undef NIL_MATCHES_FLAG
12209
12210#undef OP
12211#undef op_typeswitchloop
12212#undef BATcalcop_intern
12213#undef BATcalcop
12214#undef BATcalcopcst
12215#undef BATcalccstop
12216#undef VARcalcop
12217
12218#undef TYPE_TPE
12219#undef TPE
12220#undef TPE_nil
12221#undef is_TPE_nil
12222
12223/* ---------------------------------------------------------------------- */
12224/* generic comparison (any "linear" type) */
12225
12226/* #define CMP(a, b) ((bte) ((a) < (b) ? -1 : (a) > (b))) */
12227#define CMP(a, b) ((bte) (((a) > (b)) - ((a) < (b))))
12228
12229#define TYPE_TPE TYPE_bte
12230#define TPE bte
12231#define TPE_nil bte_nil
12232#define is_TPE_nil is_bte_nil
12233
12234#define OP CMP
12235#define op_typeswitchloop cmp_typeswitchloop
12236#define BATcalcop_intern BATcalccmp_intern
12237#define BATcalcop BATcalccmp
12238#define BATcalcopcst BATcalccmpcst
12239#define BATcalccstop BATcalccstcmp
12240#define VARcalcop VARcalccmp
12241
12242#include "gdk_calc_compare.h"
12243
12244#undef OP
12245#undef op_typeswitchloop
12246#undef BATcalcop_intern
12247#undef BATcalcop
12248#undef BATcalcopcst
12249#undef BATcalccstop
12250#undef VARcalcop
12251
12252#undef TYPE_TPE
12253#undef TPE
12254#undef TPE_nil
12255#undef is_TPE_nil
12256
12257/* ---------------------------------------------------------------------- */
12258/* between (any "linear" type) */
12259
12260#define LTbte(a,b) ((a) < (b))
12261#define LTsht(a,b) ((a) < (b))
12262#define LTint(a,b) ((a) < (b))
12263#define LTlng(a,b) ((a) < (b))
12264#define LThge(a,b) ((a) < (b))
12265#define LToid(a,b) ((a) < (b))
12266#define LTflt(a,b) ((a) < (b))
12267#define LTdbl(a,b) ((a) < (b))
12268#define LTany(a,b) ((*atomcmp)(a, b) < 0)
12269#define EQbte(a,b) ((a) == (b))
12270#define EQsht(a,b) ((a) == (b))
12271#define EQint(a,b) ((a) == (b))
12272#define EQlng(a,b) ((a) == (b))
12273#define EQhge(a,b) ((a) == (b))
12274#define EQoid(a,b) ((a) == (b))
12275#define EQflt(a,b) ((a) == (b))
12276#define EQdbl(a,b) ((a) == (b))
12277#define EQany(a,b) ((*atomcmp)(a, b) == 0)
12278
12279#define is_any_nil(v) ((v) == NULL || (*atomcmp)((v), nil) == 0)
12280
12281#define less3(a,b,i,t) (is_##t##_nil(a) || is_##t##_nil(b) ? bit_nil : LT##t(a, b) || (i && EQ##t(a, b)))
12282#define grtr3(a,b,i,t) (is_##t##_nil(a) || is_##t##_nil(b) ? bit_nil : LT##t(b, a) || (i && EQ##t(a, b)))
12283#define not3(a) (is_bit_nil(a) ? bit_nil : !(a))
12284
12285#define between3(v, lo, linc, hi, hinc, TYPE) \
12286 and3(grtr3(v, lo, linc, TYPE), less3(v, hi, hinc, TYPE))
12287
12288#define BETWEEN(v, lo, hi, TYPE) \
12289 (is_##TYPE##_nil(v) \
12290 ? nils_false ? 0 : bit_nil \
12291 : (bit) (anti \
12292 ? (symmetric \
12293 ? not3(or3(between3(v, lo, linc, hi, hinc, TYPE), \
12294 between3(v, hi, hinc, lo, linc, TYPE))) \
12295 : not3(between3(v, lo, linc, hi, hinc, TYPE))) \
12296 : (symmetric \
12297 ? or3(between3(v, lo, linc, hi, hinc, TYPE), \
12298 between3(v, hi, hinc, lo, linc, TYPE)) \
12299 : between3(v, lo, linc, hi, hinc, TYPE))))
12300
12301#define BETWEEN_LOOP_TYPE(TYPE) \
12302 do { \
12303 do { \
12304 while (l < x) { \
12305 dst[l++] = bit_nil; \
12306 nils++; \
12307 } \
12308 i = x * incr1; \
12309 j = x * incr2; \
12310 k = x * incr3; \
12311 dst[l] = BETWEEN(((const TYPE *) src)[i], \
12312 ((const TYPE *) lo)[j], \
12313 ((const TYPE *) hi)[k], \
12314 TYPE); \
12315 nils += is_bit_nil(dst[l]); \
12316 l++; \
12317 x = canditer_next(ci); \
12318 if (is_oid_nil(x)) \
12319 break; \
12320 x -= seqbase; \
12321 } while (l < cnt); \
12322 while (l < cnt) { \
12323 dst[l++] = bit_nil; \
12324 nils++; \
12325 } \
12326 } while (0)
12327
12328static BAT *
12329BATcalcbetween_intern(const void *src, int incr1, const char *hp1, int wd1,
12330 const void *lo, int incr2, const char *hp2, int wd2,
12331 const void *hi, int incr3, const char *hp3, int wd3,
12332 int tp, BUN cnt, struct canditer *restrict ci,
12333 oid seqbase, bool symmetric, bool anti,
12334 bool linc, bool hinc, bool nils_false, const char *func)
12335{
12336 BAT *bn;
12337 BUN nils = 0;
12338 BUN i, j, k, l = 0;
12339 bit *restrict dst;
12340 const void *nil;
12341 int (*atomcmp)(const void *, const void *);
12342 oid x = canditer_next(ci) - seqbase;
12343
12344 bn = COLnew(seqbase, TYPE_bit, cnt, TRANSIENT);
12345 if (bn == NULL)
12346 return NULL;
12347
12348 dst = (bit *) Tloc(bn, 0);
12349
12350 tp = ATOMbasetype(tp);
12351
12352 switch (tp) {
12353 case TYPE_bte:
12354 BETWEEN_LOOP_TYPE(bte);
12355 break;
12356 case TYPE_sht:
12357 BETWEEN_LOOP_TYPE(sht);
12358 break;
12359 case TYPE_int:
12360 BETWEEN_LOOP_TYPE(int);
12361 break;
12362 case TYPE_lng:
12363 BETWEEN_LOOP_TYPE(lng);
12364 break;
12365#ifdef HAVE_HGE
12366 case TYPE_hge:
12367 BETWEEN_LOOP_TYPE(hge);
12368 break;
12369#endif
12370 case TYPE_flt:
12371 BETWEEN_LOOP_TYPE(flt);
12372 break;
12373 case TYPE_dbl:
12374 BETWEEN_LOOP_TYPE(dbl);
12375 break;
12376 default:
12377 assert(tp != TYPE_oid);
12378 if (!ATOMlinear(tp) ||
12379 (atomcmp = ATOMcompare(tp)) == NULL) {
12380 BBPunfix(bn->batCacheid);
12381 GDKerror("%s: bad input type %s.\n",
12382 func, ATOMname(tp));
12383 return NULL;
12384 }
12385 nil = ATOMnilptr(tp);
12386 do {
12387 while (l < x) {
12388 dst[l++] = bit_nil;
12389 nils++;
12390 }
12391 i = x * incr1;
12392 j = x * incr2;
12393 k = x * incr3;
12394 const void *p1, *p2, *p3;
12395 p1 = hp1
12396 ? (const void *) (hp1 + VarHeapVal(src, i, wd1))
12397 : (const void *) ((const char *) src + i * wd1);
12398 p2 = hp2
12399 ? (const void *) (hp2 + VarHeapVal(lo, j, wd2))
12400 : (const void *) ((const char *) lo + j * wd2);
12401 p3 = hp3
12402 ? (const void *) (hp3 + VarHeapVal(hi, k, wd3))
12403 : (const void *) ((const char *) hi + k * wd3);
12404 dst[l] = BETWEEN(p1, p2, p3, any);
12405 nils += is_bit_nil(dst[l]);
12406 l++;
12407 x = canditer_next(ci);
12408 if (is_oid_nil(x))
12409 break;
12410 x -= seqbase;
12411 } while (l < cnt);
12412 while (l < cnt) {
12413 dst[l++] = bit_nil;
12414 nils++;
12415 }
12416 break;
12417 }
12418
12419 BATsetcount(bn, cnt);
12420
12421 bn->tsorted = cnt <= 1 || nils == cnt;
12422 bn->trevsorted = cnt <= 1 || nils == cnt;
12423 bn->tkey = cnt <= 1;
12424 bn->tnil = nils != 0;
12425 bn->tnonil = nils == 0;
12426
12427 return bn;
12428}
12429
12430BAT *
12431BATcalcbetween(BAT *b, BAT *lo, BAT *hi, BAT *s, bool symmetric,
12432 bool linc, bool hinc, bool nils_false, bool anti)
12433{
12434 BAT *bn;
12435 BUN cnt, ncand;
12436 struct canditer ci;
12437
12438 BATcheck(b, __func__, NULL);
12439 BATcheck(lo, __func__, NULL);
12440 BATcheck(hi, __func__, NULL);
12441
12442 if (checkbats(b, lo, __func__) != GDK_SUCCEED)
12443 return NULL;
12444 if (checkbats(b, hi, __func__) != GDK_SUCCEED)
12445 return NULL;
12446
12447 cnt = BATcount(b);
12448 ncand = canditer_init(&ci, b, s);
12449 if (ncand == 0)
12450 return BATconstant(b->hseqbase, TYPE_bit,
12451 ATOMnilptr(TYPE_bit), cnt, TRANSIENT);
12452
12453 if (BATtvoid(b) &&
12454 BATtvoid(lo) &&
12455 BATtvoid(hi) &&
12456 cnt == ncand) {
12457 bit res;
12458
12459 res = BETWEEN(b->tseqbase, lo->tseqbase, hi->tseqbase, oid);
12460 return BATconstant(b->hseqbase, TYPE_bit, &res, BATcount(b),
12461 TRANSIENT);
12462 }
12463
12464 bn = BATcalcbetween_intern(Tloc(b, 0), 1,
12465 b->tvheap ? b->tvheap->base : NULL,
12466 b->twidth,
12467 Tloc(lo, 0), 1,
12468 lo->tvheap ? lo->tvheap->base : NULL,
12469 lo->twidth,
12470 Tloc(hi, 0), 1,
12471 hi->tvheap ? hi->tvheap->base : NULL,
12472 hi->twidth,
12473 b->ttype, cnt,
12474 &ci,
12475 b->hseqbase, symmetric, anti, linc, hinc,
12476 nils_false, __func__);
12477
12478 return bn;
12479}
12480
12481BAT *
12482BATcalcbetweencstcst(BAT *b, const ValRecord *lo, const ValRecord *hi, BAT *s,
12483 bool symmetric, bool linc, bool hinc, bool nils_false,
12484 bool anti)
12485{
12486 BAT *bn;
12487 BUN cnt, ncand;
12488 struct canditer ci;
12489
12490 BATcheck(b, __func__, NULL);
12491
12492 if (ATOMbasetype(b->ttype) != ATOMbasetype(lo->vtype) ||
12493 ATOMbasetype(b->ttype) != ATOMbasetype(hi->vtype)) {
12494 GDKerror("%s: incompatible input types.\n", __func__);
12495 return NULL;
12496 }
12497
12498 cnt = BATcount(b);
12499 ncand = canditer_init(&ci, b, s);
12500 if (ncand == 0)
12501 return BATconstant(b->hseqbase, TYPE_bit,
12502 ATOMnilptr(TYPE_bit), cnt, TRANSIENT);
12503
12504 bn = BATcalcbetween_intern(Tloc(b, 0), 1,
12505 b->tvheap ? b->tvheap->base : NULL,
12506 b->twidth,
12507 VALptr(lo), 0, NULL, 0,
12508 VALptr(hi), 0, NULL, 0,
12509 b->ttype, cnt,
12510 &ci,
12511 b->hseqbase, symmetric, anti,
12512 linc, hinc, nils_false,
12513 __func__);
12514
12515 return bn;
12516}
12517
12518BAT *
12519BATcalcbetweenbatcst(BAT *b, BAT *lo, const ValRecord *hi, BAT *s,
12520 bool symmetric, bool linc, bool hinc, bool nils_false,
12521 bool anti)
12522{
12523 BAT *bn;
12524 BUN cnt, ncand;
12525 struct canditer ci;
12526
12527 BATcheck(b, __func__, NULL);
12528 BATcheck(lo, __func__, NULL);
12529
12530 if (checkbats(b, lo, __func__) != GDK_SUCCEED)
12531 return NULL;
12532
12533 if (ATOMbasetype(b->ttype) != ATOMbasetype(hi->vtype)) {
12534 GDKerror("%s: incompatible input types.\n", __func__);
12535 return NULL;
12536 }
12537
12538 cnt = BATcount(b);
12539 ncand = canditer_init(&ci, b, s);
12540 if (ncand == 0)
12541 return BATconstant(b->hseqbase, TYPE_bit,
12542 ATOMnilptr(TYPE_bit), cnt, TRANSIENT);
12543
12544 bn = BATcalcbetween_intern(Tloc(b, 0), 1,
12545 b->tvheap ? b->tvheap->base : NULL,
12546 b->twidth,
12547 Tloc(lo, 0), 1,
12548 lo->tvheap ? lo->tvheap->base : NULL,
12549 lo->twidth,
12550 VALptr(hi), 0, NULL, 0,
12551 b->ttype, cnt,
12552 &ci,
12553 b->hseqbase, symmetric, anti,
12554 linc, hinc, nils_false,
12555 __func__);
12556
12557 return bn;
12558}
12559
12560BAT *
12561BATcalcbetweencstbat(BAT *b, const ValRecord *lo, BAT *hi, BAT *s,
12562 bool symmetric, bool linc, bool hinc, bool nils_false,
12563 bool anti)
12564{
12565 BAT *bn;
12566 BUN cnt, ncand;
12567 struct canditer ci;
12568
12569 BATcheck(b, __func__, NULL);
12570 BATcheck(hi, __func__, NULL);
12571
12572 if (checkbats(b, hi, __func__) != GDK_SUCCEED)
12573 return NULL;
12574
12575 if (ATOMbasetype(b->ttype) != ATOMbasetype(lo->vtype)) {
12576 GDKerror("%s: incompatible input types.\n", __func__);
12577 return NULL;
12578 }
12579
12580 cnt = BATcount(b);
12581 ncand = canditer_init(&ci, b, s);
12582 if (ncand == 0)
12583 return BATconstant(b->hseqbase, TYPE_bit,
12584 ATOMnilptr(TYPE_bit), cnt, TRANSIENT);
12585
12586 bn = BATcalcbetween_intern(Tloc(b, 0), 1,
12587 b->tvheap ? b->tvheap->base : NULL,
12588 b->twidth,
12589 VALptr(lo), 0, NULL, 0,
12590 Tloc(hi, 0), 1,
12591 hi->tvheap ? hi->tvheap->base : NULL,
12592 hi->twidth,
12593 b->ttype, cnt,
12594 &ci,
12595 b->hseqbase, symmetric, anti,
12596 linc, hinc, nils_false,
12597 __func__);
12598
12599 return bn;
12600}
12601
12602gdk_return
12603VARcalcbetween(ValPtr ret, const ValRecord *v, const ValRecord *lo,
12604 const ValRecord *hi, bool symmetric, bool linc, bool hinc,
12605 bool nils_false, bool anti)
12606{
12607 int t;
12608 int (*atomcmp)(const void *, const void *);
12609 const void *nil;
12610
12611 t = v->vtype;
12612 if (t != lo->vtype || t != hi->vtype) {
12613 GDKerror("VARcalcbetween: incompatible input types.\n");
12614 return GDK_FAIL;
12615 }
12616 if (!ATOMlinear(t)) {
12617 GDKerror("VARcalcbetween: non-linear input type.\n");
12618 return GDK_FAIL;
12619 }
12620
12621 t = ATOMbasetype(t);
12622
12623 ret->vtype = TYPE_bit;
12624 switch (t) {
12625 case TYPE_bte:
12626 ret->val.btval = BETWEEN(v->val.btval, lo->val.btval, hi->val.btval, bte);
12627 break;
12628 case TYPE_sht:
12629 ret->val.btval = BETWEEN(v->val.shval, lo->val.shval, hi->val.shval, sht);
12630 break;
12631 case TYPE_int:
12632 ret->val.btval = BETWEEN(v->val.ival, lo->val.ival, hi->val.ival, int);
12633 break;
12634 case TYPE_lng:
12635 ret->val.btval = BETWEEN(v->val.lval, lo->val.lval, hi->val.lval, lng);
12636 break;
12637#ifdef HAVE_HGE
12638 case TYPE_hge:
12639 ret->val.btval = BETWEEN(v->val.hval, lo->val.hval, hi->val.hval, hge);
12640 break;
12641#endif
12642 case TYPE_flt:
12643 ret->val.btval = BETWEEN(v->val.fval, lo->val.fval, hi->val.fval, flt);
12644 break;
12645 case TYPE_dbl:
12646 ret->val.btval = BETWEEN(v->val.dval, lo->val.dval, hi->val.dval, dbl);
12647 break;
12648 default:
12649 nil = ATOMnilptr(t);
12650 atomcmp = ATOMcompare(t);
12651 ret->val.btval = BETWEEN(VALptr(v), VALptr(lo), VALptr(hi), any);
12652 break;
12653 }
12654 return GDK_SUCCEED;
12655}
12656
12657/* ---------------------------------------------------------------------- */
12658/* if-then-else (any type) */
12659
12660#define IFTHENELSELOOP(TYPE) \
12661 do { \
12662 for (i = 0; i < cnt; i++) { \
12663 if (is_bit_nil(src[i])) { \
12664 ((TYPE *) dst)[i] = * (TYPE *) nil; \
12665 nils++; \
12666 } else if (src[i]) { \
12667 ((TYPE *) dst)[i] = ((TYPE *) col1)[k]; \
12668 } else { \
12669 ((TYPE *) dst)[i] = ((TYPE *) col2)[l]; \
12670 } \
12671 k += incr1; \
12672 l += incr2; \
12673 } \
12674 } while (0)
12675#define IFTHENELSELOOP_oid() \
12676 do { \
12677 for (i = 0; i < cnt; i++) { \
12678 if (is_bit_nil(src[i])) { \
12679 ((oid *) dst)[i] = oid_nil; \
12680 nils++; \
12681 } else if (src[i]) { \
12682 ((oid *) dst)[i] = col1 ? ((oid *) col1)[k] : seq1; \
12683 } else { \
12684 ((oid *) dst)[i] = col2 ? ((oid *) col2)[k] : seq2; \
12685 } \
12686 k += incr1; \
12687 l += incr2; \
12688 seq1 += incr1; \
12689 seq2 += incr2; \
12690 } \
12691 } while (0)
12692
12693static BAT *
12694BATcalcifthenelse_intern(BAT *b,
12695 const void *col1, int incr1, const char *heap1,
12696 int width1, int nonil1, oid seq1,
12697 const void *col2, int incr2, const char *heap2,
12698 int width2, int nonil2, oid seq2,
12699 int tpe)
12700{
12701 BAT *bn;
12702 void *restrict dst;
12703 BUN i, k, l;
12704 BUN nils = 0;
12705 const void *nil;
12706 const void *p;
12707 const bit *src;
12708 BUN cnt = b->batCount;
12709
12710 /* col1 and col2 can only be NULL for void columns */
12711 assert(col1 != NULL || ATOMtype(tpe) == TYPE_oid);
12712 assert(col2 != NULL || ATOMtype(tpe) == TYPE_oid);
12713 assert(col1 != NULL || heap1 == NULL);
12714 assert(col2 != NULL || heap2 == NULL);
12715 assert(col1 != NULL || incr1 == 1);
12716 assert(col2 != NULL || incr2 == 1);
12717
12718 bn = COLnew(b->hseqbase, ATOMtype(tpe), cnt, TRANSIENT);
12719 if (bn == NULL)
12720 return NULL;
12721
12722 src = (const bit *) Tloc(b, 0);
12723
12724 nil = ATOMnilptr(tpe);
12725 dst = (void *) Tloc(bn, 0);
12726 k = l = 0;
12727 if (bn->tvarsized) {
12728 assert((heap1 != NULL && width1 > 0) || (width1 == 0 && incr1 == 0));
12729 assert((heap2 != NULL && width2 > 0) || (width2 == 0 && incr2 == 0));
12730 for (i = 0; i < cnt; i++) {
12731 if (is_bit_nil(src[i])) {
12732 p = nil;
12733 nils++;
12734 } else if (src[i]) {
12735 if (heap1)
12736 p = heap1 + VarHeapVal(col1, k, width1);
12737 else
12738 p = col1;
12739 } else {
12740 if (heap2)
12741 p = heap2 + VarHeapVal(col2, l, width2);
12742 else
12743 p = col2;
12744 }
12745 tfastins_nocheckVAR(bn, i, p, Tsize(bn));
12746 k += incr1;
12747 l += incr2;
12748 }
12749 } else {
12750 assert(heap1 == NULL);
12751 assert(heap2 == NULL);
12752 if (ATOMtype(tpe) == TYPE_oid) {
12753 IFTHENELSELOOP_oid();
12754 } else {
12755 switch (bn->twidth) {
12756 case 1:
12757 IFTHENELSELOOP(bte);
12758 break;
12759 case 2:
12760 IFTHENELSELOOP(sht);
12761 break;
12762 case 4:
12763 IFTHENELSELOOP(int);
12764 break;
12765 case 8:
12766 IFTHENELSELOOP(lng);
12767 break;
12768#ifdef HAVE_HGE
12769 case 16:
12770 IFTHENELSELOOP(hge);
12771 break;
12772#endif
12773 default:
12774 for (i = 0; i < cnt; i++) {
12775 if (is_bit_nil(src[i])) {
12776 p = nil;
12777 nils++;
12778 } else if (src[i]) {
12779 p = ((const char *) col1) + k * width1;
12780 } else {
12781 p = ((const char *) col2) + l * width2;
12782 }
12783 memcpy(dst, p, bn->twidth);
12784 dst = (void *) ((char *) dst + bn->twidth);
12785 k += incr1;
12786 l += incr2;
12787 }
12788 }
12789 }
12790 }
12791
12792 BATsetcount(bn, cnt);
12793 bn->theap.dirty = true;
12794
12795 bn->tsorted = cnt <= 1 || nils == cnt;
12796 bn->trevsorted = cnt <= 1 || nils == cnt;
12797 bn->tkey = cnt <= 1;
12798 bn->tnil = nils != 0;
12799 bn->tnonil = nils == 0 && nonil1 && nonil2;
12800
12801 return bn;
12802 bunins_failed:
12803 BBPreclaim(bn);
12804 return NULL;
12805}
12806
12807BAT *
12808BATcalcifthenelse(BAT *b, BAT *b1, BAT *b2)
12809{
12810 BATcheck(b, __func__, NULL);
12811 BATcheck(b1, __func__, NULL);
12812 BATcheck(b2, __func__, NULL);
12813
12814 if (checkbats(b, b1, __func__) != GDK_SUCCEED)
12815 return NULL;
12816 if (checkbats(b, b2, __func__) != GDK_SUCCEED)
12817 return NULL;
12818 if (b->ttype != TYPE_bit || ATOMtype(b1->ttype) != ATOMtype(b2->ttype)) {
12819 GDKerror("%s: \"then\" and \"else\" BATs have different types.\n", __func__);
12820 return NULL;
12821 }
12822 return BATcalcifthenelse_intern(b,
12823 Tloc(b1, 0), 1, b1->tvheap ? b1->tvheap->base : NULL, b1->twidth, b1->tnonil, b1->tseqbase,
12824 Tloc(b2, 0), 1, b2->tvheap ? b2->tvheap->base : NULL, b2->twidth, b2->tnonil, b2->tseqbase,
12825 b1->ttype);
12826}
12827
12828BAT *
12829BATcalcifthenelsecst(BAT *b, BAT *b1, const ValRecord *c2)
12830{
12831 BATcheck(b, __func__, NULL);
12832 BATcheck(b1, __func__, NULL);
12833 BATcheck(c2, __func__, NULL);
12834
12835 if (checkbats(b, b1, __func__) != GDK_SUCCEED)
12836 return NULL;
12837 if (b->ttype != TYPE_bit || ATOMtype(b1->ttype) != ATOMtype(c2->vtype)) {
12838 GDKerror("%s: \"then\" and \"else\" BATs have different types.\n", __func__);
12839 return NULL;
12840 }
12841 return BATcalcifthenelse_intern(b,
12842 Tloc(b1, 0), 1, b1->tvheap ? b1->tvheap->base : NULL, b1->twidth, b1->tnonil, b1->tseqbase,
12843 VALptr(c2), 0, NULL, 0, !VALisnil(c2), 0,
12844 b1->ttype);
12845}
12846
12847BAT *
12848BATcalcifthencstelse(BAT *b, const ValRecord *c1, BAT *b2)
12849{
12850 BATcheck(b, __func__, NULL);
12851 BATcheck(c1, __func__, NULL);
12852 BATcheck(b2, __func__, NULL);
12853
12854 if (checkbats(b, b2, __func__) != GDK_SUCCEED)
12855 return NULL;
12856 if (b->ttype != TYPE_bit || ATOMtype(b2->ttype) != ATOMtype(c1->vtype)) {
12857 GDKerror("%s: \"then\" and \"else\" BATs have different types.\n", __func__);
12858 return NULL;
12859 }
12860 return BATcalcifthenelse_intern(b,
12861 VALptr(c1), 0, NULL, 0, !VALisnil(c1), 0,
12862 Tloc(b2, 0), 1, b2->tvheap ? b2->tvheap->base : NULL, b2->twidth, b2->tnonil, b2->tseqbase,
12863 c1->vtype);
12864}
12865
12866BAT *
12867BATcalcifthencstelsecst(BAT *b, const ValRecord *c1, const ValRecord *c2)
12868{
12869 BATcheck(b, __func__, NULL);
12870 BATcheck(c1, __func__, NULL);
12871 BATcheck(c2, __func__, NULL);
12872
12873 if (b->ttype != TYPE_bit || ATOMtype(c1->vtype) != ATOMtype(c2->vtype)) {
12874 GDKerror("%s: \"then\" and \"else\" BATs have different types.\n", __func__);
12875 return NULL;
12876 }
12877 return BATcalcifthenelse_intern(b,
12878 VALptr(c1), 0, NULL, 0, !VALisnil(c1), 0,
12879 VALptr(c2), 0, NULL, 0, !VALisnil(c2), 0,
12880 c1->vtype);
12881}
12882
12883/* ---------------------------------------------------------------------- */
12884/* type conversion (cast) */
12885
12886/* a note on the return values from the internal conversion functions:
12887 *
12888 * the functions return the number of NIL values produced (or at
12889 * least, 0 if no NIL, and != 0 if there were any);
12890 * the return value is BUN_NONE if there was overflow and a message
12891 * was generated;
12892 * the return value is BUN_NONE + 1 if the types were not compatible;
12893 * the return value is BUN_NONE + 2 if inserting a value into a BAT
12894 * failed (only happens for conversion to str).
12895 */
12896
12897#define convertimpl_copy(TYPE) \
12898static BUN \
12899convert_##TYPE##_##TYPE(const TYPE *src, TYPE *restrict dst, BUN cnt, \
12900 struct canditer *restrict ci, \
12901 oid candoff, bool *reduce) \
12902{ \
12903 BUN i = 0, nils = 0; \
12904 oid x = canditer_next(ci) - candoff; \
12905 \
12906 *reduce = false; \
12907 if (ci->tpe == cand_dense) { \
12908 do { \
12909 while (i < x) { \
12910 dst[i++] = TYPE##_nil; \
12911 nils++; \
12912 } \
12913 nils += is_##TYPE##_nil(src[i]); \
12914 dst[i] = src[i]; \
12915 i++; \
12916 x = canditer_next_dense(ci); \
12917 if (is_oid_nil(x)) \
12918 break; \
12919 x -= candoff; \
12920 } while (i < cnt); \
12921 } else { \
12922 do { \
12923 while (i < x) { \
12924 dst[i++] = TYPE##_nil; \
12925 nils++; \
12926 } \
12927 nils += is_##TYPE##_nil(src[i]); \
12928 dst[i] = src[i]; \
12929 i++; \
12930 x = canditer_next(ci); \
12931 if (is_oid_nil(x)) \
12932 break; \
12933 x -= candoff; \
12934 } while (i < cnt); \
12935 } \
12936 while (i < cnt) { \
12937 dst[i++] = TYPE##_nil; \
12938 nils++; \
12939 } \
12940 return nils; \
12941}
12942
12943#define convertimpl_enlarge(TYPE1, TYPE2) \
12944static BUN \
12945convert_##TYPE1##_##TYPE2(const TYPE1 *src, TYPE2 *restrict dst, BUN cnt, \
12946 struct canditer *restrict ci, \
12947 oid candoff, bool *reduce) \
12948{ \
12949 BUN i = 0, nils = 0; \
12950 oid x = canditer_next(ci) - candoff; \
12951 \
12952 *reduce = false; \
12953 if (ci->tpe == cand_dense) { \
12954 do { \
12955 while (i < x) { \
12956 dst[i++] = TYPE2##_nil; \
12957 nils++; \
12958 } \
12959 if (is_##TYPE1##_nil(src[i])) { \
12960 dst[i] = TYPE2##_nil; \
12961 nils++; \
12962 } else \
12963 dst[i] = (TYPE2) src[i]; \
12964 i++; \
12965 x = canditer_next_dense(ci); \
12966 if (is_oid_nil(x)) \
12967 break; \
12968 x -= candoff; \
12969 } while (i < cnt); \
12970 } else { \
12971 do { \
12972 while (i < x) { \
12973 dst[i++] = TYPE2##_nil; \
12974 nils++; \
12975 } \
12976 if (is_##TYPE1##_nil(src[i])) { \
12977 dst[i] = TYPE2##_nil; \
12978 nils++; \
12979 } else \
12980 dst[i] = (TYPE2) src[i]; \
12981 i++; \
12982 x = canditer_next(ci); \
12983 if (is_oid_nil(x)) \
12984 break; \
12985 x -= candoff; \
12986 } while (i < cnt); \
12987 } \
12988 while (i < cnt) { \
12989 dst[i++] = TYPE2##_nil; \
12990 nils++; \
12991 } \
12992 return nils; \
12993}
12994
12995#define convertimpl_enlarge_float(TYPE1, TYPE2, MANT_DIG) \
12996static BUN \
12997convert_##TYPE1##_##TYPE2(const TYPE1 *src, TYPE2 *restrict dst, BUN cnt, \
12998 struct canditer *restrict ci, \
12999 oid candoff, bool *reduce) \
13000{ \
13001 BUN i = 0, nils = 0; \
13002 oid x = canditer_next(ci) - candoff; \
13003 \
13004 *reduce = 8 * sizeof(TYPE1) > MANT_DIG; \
13005 if (ci->tpe == cand_dense) { \
13006 do { \
13007 while (i < x) { \
13008 dst[i++] = TYPE2##_nil; \
13009 nils++; \
13010 } \
13011 if (is_##TYPE1##_nil(src[i])) { \
13012 dst[i] = TYPE2##_nil; \
13013 nils++; \
13014 } else \
13015 dst[i] = (TYPE2) src[i]; \
13016 i++; \
13017 x = canditer_next_dense(ci); \
13018 if (is_oid_nil(x)) \
13019 break; \
13020 x -= candoff; \
13021 } while (i < cnt); \
13022 } else { \
13023 do { \
13024 while (i < x) { \
13025 dst[i++] = TYPE2##_nil; \
13026 nils++; \
13027 } \
13028 if (is_##TYPE1##_nil(src[i])) { \
13029 dst[i] = TYPE2##_nil; \
13030 nils++; \
13031 } else \
13032 dst[i] = (TYPE2) src[i]; \
13033 i++; \
13034 x = canditer_next(ci); \
13035 if (is_oid_nil(x)) \
13036 break; \
13037 x -= candoff; \
13038 } while (i < cnt); \
13039 } \
13040 while (i < cnt) { \
13041 dst[i++] = TYPE2##_nil; \
13042 nils++; \
13043 } \
13044 return nils; \
13045}
13046
13047#define CONV_OVERFLOW(TYPE1, TYPE2, value) \
13048 do { \
13049 GDKerror("22003!overflow in conversion of " \
13050 FMT##TYPE1 " to %s.\n", CST##TYPE1 (value), TYPE2); \
13051 return BUN_NONE; \
13052 } while (0)
13053
13054#define convertimpl_oid_enlarge(TYPE1) \
13055static BUN \
13056convert_##TYPE1##_oid(const TYPE1 *src, oid *restrict dst, BUN cnt, \
13057 struct canditer *restrict ci, \
13058 oid candoff, bool abort_on_error, bool *reduce) \
13059{ \
13060 BUN i = 0, nils = 0; \
13061 oid x = canditer_next(ci) - candoff; \
13062 \
13063 *reduce = false; \
13064 if (ci->tpe == cand_dense) { \
13065 do { \
13066 while (i < x) { \
13067 dst[i++] = oid_nil; \
13068 nils++; \
13069 } \
13070 if (is_##TYPE1##_nil(src[i])) { \
13071 dst[i] = oid_nil; \
13072 nils++; \
13073 } else if (src[i] < 0) { \
13074 if (abort_on_error) \
13075 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13076 *reduce = true; \
13077 dst[i] = oid_nil; \
13078 nils++; \
13079 } else if (is_oid_nil((dst[i] = (oid) src[i])) && \
13080 abort_on_error) \
13081 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13082 i++; \
13083 x = canditer_next_dense(ci); \
13084 if (is_oid_nil(x)) \
13085 break; \
13086 x -= candoff; \
13087 } while (i < cnt); \
13088 } else { \
13089 do { \
13090 while (i < x) { \
13091 dst[i++] = oid_nil; \
13092 nils++; \
13093 } \
13094 if (is_##TYPE1##_nil(src[i])) { \
13095 dst[i] = oid_nil; \
13096 nils++; \
13097 } else if (src[i] < 0) { \
13098 if (abort_on_error) \
13099 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13100 *reduce = true; \
13101 dst[i] = oid_nil; \
13102 nils++; \
13103 } else if (is_oid_nil((dst[i] = (oid) src[i])) && \
13104 abort_on_error) \
13105 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13106 i++; \
13107 x = canditer_next(ci); \
13108 if (is_oid_nil(x)) \
13109 break; \
13110 x -= candoff; \
13111 } while (i < cnt); \
13112 } \
13113 while (i < cnt) { \
13114 dst[i++] = oid_nil; \
13115 nils++; \
13116 } \
13117 return nils; \
13118}
13119
13120#define convertimpl_oid_reduce(TYPE1) \
13121static BUN \
13122convert_##TYPE1##_oid(const TYPE1 *src, oid *restrict dst, BUN cnt, \
13123 struct canditer *restrict ci, \
13124 oid candoff, bool abort_on_error, bool *reduce) \
13125{ \
13126 BUN i = 0, nils = 0; \
13127 oid x = canditer_next(ci) - candoff; \
13128 \
13129 *reduce = false; \
13130 if (ci->tpe == cand_dense) { \
13131 do { \
13132 while (i < x) { \
13133 dst[i++] = oid_nil; \
13134 nils++; \
13135 } \
13136 if (is_##TYPE1##_nil(src[i])) { \
13137 dst[i] = oid_nil; \
13138 nils++; \
13139 } else if (src[i] < 0 || \
13140 src[i] > (TYPE1) GDK_oid_max) { \
13141 if (abort_on_error) \
13142 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13143 *reduce = true; \
13144 dst[i] = oid_nil; \
13145 nils++; \
13146 } else if (is_oid_nil((dst[i] = (oid) src[i])) && \
13147 abort_on_error) \
13148 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13149 i++; \
13150 x = canditer_next_dense(ci); \
13151 if (is_oid_nil(x)) \
13152 break; \
13153 x -= candoff; \
13154 } while (i < cnt); \
13155 } else { \
13156 do { \
13157 while (i < x) { \
13158 dst[i++] = oid_nil; \
13159 nils++; \
13160 } \
13161 if (is_##TYPE1##_nil(src[i])) { \
13162 dst[i] = oid_nil; \
13163 nils++; \
13164 } else if (src[i] < 0 || \
13165 src[i] > (TYPE1) GDK_oid_max) { \
13166 if (abort_on_error) \
13167 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13168 *reduce = true; \
13169 dst[i] = oid_nil; \
13170 nils++; \
13171 } else if (is_oid_nil((dst[i] = (oid) src[i])) && \
13172 abort_on_error) \
13173 CONV_OVERFLOW(TYPE1, "oid", src[i]); \
13174 i++; \
13175 x = canditer_next(ci); \
13176 if (is_oid_nil(x)) \
13177 break; \
13178 x -= candoff; \
13179 } while (i < cnt); \
13180 } \
13181 while (i < cnt) { \
13182 dst[i++] = oid_nil; \
13183 nils++; \
13184 } \
13185 return nils; \
13186}
13187
13188#define convertimpl_reduce(TYPE1, TYPE2) \
13189static BUN \
13190convert_##TYPE1##_##TYPE2(const TYPE1 *src, TYPE2 *restrict dst, BUN cnt, \
13191 struct canditer *restrict ci, \
13192 oid candoff, bool abort_on_error, bool *reduce) \
13193{ \
13194 BUN i = 0, nils = 0; \
13195 oid x = canditer_next(ci) - candoff; \
13196 \
13197 *reduce = false; \
13198 if (ci->tpe == cand_dense) { \
13199 do { \
13200 while (i < x) { \
13201 dst[i++] = TYPE2##_nil; \
13202 nils++; \
13203 } \
13204 if (is_##TYPE1##_nil(src[i])) { \
13205 dst[i] = TYPE2##_nil; \
13206 nils++; \
13207 } else if (src[i] < (TYPE1) GDK_##TYPE2##_min || \
13208 src[i] > (TYPE1) GDK_##TYPE2##_max) { \
13209 if (abort_on_error) \
13210 CONV_OVERFLOW(TYPE1, #TYPE2, src[i]); \
13211 *reduce = true; \
13212 dst[i] = TYPE2##_nil; \
13213 nils++; \
13214 } else \
13215 dst[i] = (TYPE2) src[i]; \
13216 i++; \
13217 x = canditer_next_dense(ci); \
13218 if (is_oid_nil(x)) \
13219 break; \
13220 x -= candoff; \
13221 } while (i < cnt); \
13222 } else { \
13223 do { \
13224 while (i < x) { \
13225 dst[i++] = TYPE2##_nil; \
13226 nils++; \
13227 } \
13228 if (is_##TYPE1##_nil(src[i])) { \
13229 dst[i] = TYPE2##_nil; \
13230 nils++; \
13231 } else if (src[i] < (TYPE1) GDK_##TYPE2##_min || \
13232 src[i] > (TYPE1) GDK_##TYPE2##_max) { \
13233 if (abort_on_error) \
13234 CONV_OVERFLOW(TYPE1, #TYPE2, src[i]); \
13235 *reduce = true; \
13236 dst[i] = TYPE2##_nil; \
13237 nils++; \
13238 } else \
13239 dst[i] = (TYPE2) src[i]; \
13240 i++; \
13241 x = canditer_next(ci); \
13242 if (is_oid_nil(x)) \
13243 break; \
13244 x -= candoff; \
13245 } while (i < cnt); \
13246 } \
13247 while (i < cnt) { \
13248 dst[i++] = TYPE2##_nil; \
13249 nils++; \
13250 } \
13251 return nils; \
13252}
13253
13254/* Special version of the above for converting from floating point.
13255 * The final assignment rounds the value which can still come out to
13256 * the NIL representation, so we need to check for that. */
13257#ifdef TRUNCATE_NUMBERS
13258#define roundflt(x) (x)
13259#define rounddbl(x) (x)
13260#else
13261#define roundflt(x) roundf(x)
13262#define rounddbl(x) round(x)
13263#endif
13264
13265#define convertimpl_reduce_float(TYPE1, TYPE2) \
13266static BUN \
13267convert_##TYPE1##_##TYPE2(const TYPE1 *src, TYPE2 *restrict dst, BUN cnt, \
13268 struct canditer *restrict ci, \
13269 oid candoff, bool abort_on_error, bool *reduce) \
13270{ \
13271 BUN i = 0, nils = 0; \
13272 oid x = canditer_next(ci) - candoff; \
13273 \
13274 *reduce = true; \
13275 if (ci->tpe == cand_dense) { \
13276 do { \
13277 while (i < x) { \
13278 dst[i++] = TYPE2##_nil; \
13279 nils++; \
13280 } \
13281 if (is_##TYPE1##_nil(src[i])) { \
13282 dst[i] = TYPE2##_nil; \
13283 nils++; \
13284 } else if (src[i] < (TYPE1) GDK_##TYPE2##_min || \
13285 src[i] > (TYPE1) GDK_##TYPE2##_max) { \
13286 if (abort_on_error) \
13287 CONV_OVERFLOW(TYPE1, #TYPE2, src[i]); \
13288 dst[i] = TYPE2##_nil; \
13289 nils++; \
13290 } else { \
13291 dst[i] = (TYPE2) round##TYPE1(src[i]); \
13292 if (is_##TYPE2##_nil(dst[i]) && \
13293 abort_on_error) \
13294 CONV_OVERFLOW(TYPE1, #TYPE2, src[i]); \
13295 } \
13296 i++; \
13297 x = canditer_next_dense(ci); \
13298 if (is_oid_nil(x)) \
13299 break; \
13300 x -= candoff; \
13301 } while (i < cnt); \
13302 } else { \
13303 do { \
13304 while (i < x) { \
13305 dst[i++] = TYPE2##_nil; \
13306 nils++; \
13307 } \
13308 if (is_##TYPE1##_nil(src[i])) { \
13309 dst[i] = TYPE2##_nil; \
13310 nils++; \
13311 } else if (src[i] < (TYPE1) GDK_##TYPE2##_min || \
13312 src[i] > (TYPE1) GDK_##TYPE2##_max) { \
13313 if (abort_on_error) \
13314 CONV_OVERFLOW(TYPE1, #TYPE2, src[i]); \
13315 dst[i] = TYPE2##_nil; \
13316 nils++; \
13317 } else { \
13318 dst[i] = (TYPE2) round##TYPE1(src[i]); \
13319 if (is_##TYPE2##_nil(dst[i]) && \
13320 abort_on_error) \
13321 CONV_OVERFLOW(TYPE1, #TYPE2, src[i]); \
13322 } \
13323 i++; \
13324 x = canditer_next(ci); \
13325 if (is_oid_nil(x)) \
13326 break; \
13327 x -= candoff; \
13328 } while (i < cnt); \
13329 } \
13330 while (i < cnt) { \
13331 dst[i++] = TYPE2##_nil; \
13332 nils++; \
13333 } \
13334 return nils; \
13335}
13336
13337#define convert2bit_impl(TYPE) \
13338static BUN \
13339convert_##TYPE##_bit(const TYPE *src, bit *restrict dst, BUN cnt, \
13340 struct canditer *restrict ci, \
13341 oid candoff, bool *reduce) \
13342{ \
13343 BUN i = 0, nils = 0; \
13344 oid x = canditer_next(ci) - candoff; \
13345 \
13346 *reduce = true; \
13347 if (ci->tpe == cand_dense) { \
13348 do { \
13349 while (i < x) { \
13350 dst[i++] = bit_nil; \
13351 nils++; \
13352 } \
13353 if (is_##TYPE##_nil(src[i])) { \
13354 dst[i] = bit_nil; \
13355 nils++; \
13356 } else \
13357 dst[i] = (bit) (src[i] != 0); \
13358 i++; \
13359 x = canditer_next_dense(ci); \
13360 if (is_oid_nil(x)) \
13361 break; \
13362 x -= candoff; \
13363 } while (i < cnt); \
13364 } else { \
13365 do { \
13366 while (i < x) { \
13367 dst[i++] = bit_nil; \
13368 nils++; \
13369 } \
13370 if (is_##TYPE##_nil(src[i])) { \
13371 dst[i] = bit_nil; \
13372 nils++; \
13373 } else \
13374 dst[i] = (bit) (src[i] != 0); \
13375 i++; \
13376 x = canditer_next(ci); \
13377 if (is_oid_nil(x)) \
13378 break; \
13379 x -= candoff; \
13380 } while (i < cnt); \
13381 } \
13382 while (i < cnt) { \
13383 dst[i++] = bit_nil; \
13384 nils++; \
13385 } \
13386 return nils; \
13387}
13388
13389convertimpl_copy(bte)
13390convertimpl_enlarge(bte, sht)
13391convertimpl_enlarge(bte, int)
13392convertimpl_oid_enlarge(bte)
13393convertimpl_enlarge(bte, lng)
13394#ifdef HAVE_HGE
13395convertimpl_enlarge(bte, hge)
13396#endif
13397convertimpl_enlarge_float(bte, flt, FLT_MANT_DIG)
13398convertimpl_enlarge_float(bte, dbl, DBL_MANT_DIG)
13399
13400convertimpl_reduce(sht, bte)
13401convertimpl_copy(sht)
13402convertimpl_enlarge(sht, int)
13403convertimpl_oid_enlarge(sht)
13404convertimpl_enlarge(sht, lng)
13405#ifdef HAVE_HGE
13406convertimpl_enlarge(sht, hge)
13407#endif
13408convertimpl_enlarge_float(sht, flt, FLT_MANT_DIG)
13409convertimpl_enlarge_float(sht, dbl, DBL_MANT_DIG)
13410
13411convertimpl_reduce(int, bte)
13412convertimpl_reduce(int, sht)
13413convertimpl_copy(int)
13414convertimpl_oid_enlarge(int)
13415convertimpl_enlarge(int, lng)
13416#ifdef HAVE_HGE
13417convertimpl_enlarge(int, hge)
13418#endif
13419convertimpl_enlarge_float(int, flt, FLT_MANT_DIG)
13420convertimpl_enlarge_float(int, dbl, DBL_MANT_DIG)
13421
13422convertimpl_reduce(lng, bte)
13423convertimpl_reduce(lng, sht)
13424convertimpl_reduce(lng, int)
13425#if SIZEOF_OID == SIZEOF_LNG
13426convertimpl_oid_enlarge(lng)
13427#else
13428convertimpl_oid_reduce(lng)
13429#endif
13430convertimpl_copy(lng)
13431#ifdef HAVE_HGE
13432convertimpl_enlarge(lng, hge)
13433#endif
13434convertimpl_enlarge_float(lng, flt, FLT_MANT_DIG)
13435convertimpl_enlarge_float(lng, dbl, DBL_MANT_DIG)
13436
13437#ifdef HAVE_HGE
13438convertimpl_reduce(hge, bte)
13439convertimpl_reduce(hge, sht)
13440convertimpl_reduce(hge, int)
13441convertimpl_oid_reduce(hge)
13442convertimpl_reduce(hge, lng)
13443convertimpl_copy(hge)
13444convertimpl_enlarge_float(hge, flt, FLT_MANT_DIG)
13445convertimpl_enlarge_float(hge, dbl, DBL_MANT_DIG)
13446#endif
13447
13448convertimpl_reduce_float(flt, bte)
13449convertimpl_reduce_float(flt, sht)
13450convertimpl_reduce_float(flt, int)
13451convertimpl_oid_reduce(flt)
13452convertimpl_reduce_float(flt, lng)
13453#ifdef HAVE_HGE
13454convertimpl_reduce_float(flt, hge)
13455#endif
13456convertimpl_copy(flt)
13457convertimpl_enlarge_float(flt, dbl, DBL_MANT_DIG)
13458
13459convertimpl_reduce_float(dbl, bte)
13460convertimpl_reduce_float(dbl, sht)
13461convertimpl_reduce_float(dbl, int)
13462convertimpl_oid_reduce(dbl)
13463convertimpl_reduce_float(dbl, lng)
13464#ifdef HAVE_HGE
13465convertimpl_reduce_float(dbl, hge)
13466#endif
13467#undef rounddbl
13468/* no rounding here */
13469#define rounddbl(x) (x)
13470convertimpl_reduce_float(dbl, flt)
13471convertimpl_copy(dbl)
13472
13473convert2bit_impl(bte)
13474convert2bit_impl(sht)
13475convert2bit_impl(int)
13476convert2bit_impl(lng)
13477#ifdef HAVE_HGE
13478convert2bit_impl(hge)
13479#endif
13480convert2bit_impl(flt)
13481convert2bit_impl(dbl)
13482
13483static BUN
13484convert_any_str(BAT *b, BAT *bn, BUN cnt, struct canditer *restrict ci)
13485{
13486 int tp = b->ttype;
13487 oid candoff = b->hseqbase;
13488 str dst = 0;
13489 size_t len = 0;
13490 BUN nils = 0;
13491 BUN i = 0;
13492 const void *nil = ATOMnilptr(tp);
13493 const void *restrict src;
13494 ssize_t (*atomtostr)(str *, size_t *, const void *, bool) = BATatoms[tp].atomToStr;
13495 int (*atomcmp)(const void *, const void *) = ATOMcompare(tp);
13496 oid x = canditer_next(ci) - candoff;
13497
13498 if (atomtostr == BATatoms[TYPE_str].atomToStr) {
13499 /* compatible with str, we just copy the value */
13500 BATiter bi = bat_iterator(b);
13501
13502 assert(b->ttype != TYPE_void);
13503 do {
13504 while (i < x) {
13505 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13506 i++;
13507 nils++;
13508 }
13509 src = BUNtvar(bi, i);
13510 if ((*atomcmp)(src, str_nil) == 0)
13511 nils++;
13512 tfastins_nocheckVAR(bn, i, src, bn->twidth);
13513 i++;
13514 x = canditer_next(ci);
13515 if (is_oid_nil(x))
13516 break;
13517 x -= candoff;
13518 } while (i < cnt);
13519 } else if (b->tvarsized) {
13520 BATiter bi = bat_iterator(b);
13521
13522 assert(b->ttype != TYPE_void);
13523 do {
13524 while (i < x) {
13525 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13526 i++;
13527 nils++;
13528 }
13529 src = BUNtvar(bi, i);
13530 if ((*atomcmp)(src, nil) == 0) {
13531 nils++;
13532 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13533 } else {
13534 if ((*atomtostr)(&dst, &len, src, false) < 0)
13535 goto bunins_failed;
13536 tfastins_nocheckVAR(bn, i, dst, bn->twidth);
13537 }
13538 i++;
13539 x = canditer_next(ci);
13540 if (is_oid_nil(x))
13541 break;
13542 x -= candoff;
13543 } while (i < cnt);
13544 } else {
13545 do {
13546 while (i < x) {
13547 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13548 i++;
13549 nils++;
13550 }
13551 src = Tloc(b, i);
13552 if ((*atomcmp)(src, nil) == 0) {
13553 nils++;
13554 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13555 } else {
13556 if ((*atomtostr)(&dst, &len, src, false) < 0)
13557 goto bunins_failed;
13558 tfastins_nocheckVAR(bn, i, dst, bn->twidth);
13559 }
13560 i++;
13561 x = canditer_next(ci);
13562 if (is_oid_nil(x))
13563 break;
13564 x -= candoff;
13565 } while (i < cnt);
13566 }
13567 while (i < cnt) {
13568 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13569 i++;
13570 nils++;
13571 }
13572 bn->theap.dirty = true;
13573 BATsetcount(bn, cnt);
13574 GDKfree(dst);
13575 return nils;
13576 bunins_failed:
13577 GDKfree(dst);
13578 return BUN_NONE + 2;
13579}
13580
13581static BUN
13582convert_str_any(BAT *b, int tp, void *restrict dst,
13583 struct canditer *restrict ci,
13584 oid candoff, bool abort_on_error)
13585{
13586 BUN i = 0, cnt = BATcount(b);
13587 BUN nils = 0;
13588 const void *nil = ATOMnilptr(tp);
13589 char *s;
13590 void *d;
13591 size_t len = ATOMsize(tp);
13592 ssize_t l;
13593 ssize_t (*atomfromstr)(const char *, size_t *, ptr *, bool) = BATatoms[tp].atomFromStr;
13594 BATiter bi = bat_iterator(b);
13595 oid x = canditer_next(ci) - candoff;
13596
13597 do {
13598 while (i < x) {
13599 memcpy(dst, nil, len);
13600 dst = (void *) ((char *) dst + len);
13601 i++;
13602 nils++;
13603 }
13604 s = BUNtvar(bi, i);
13605 if (strcmp(s, str_nil) == 0) {
13606 memcpy(dst, nil, len);
13607 nils++;
13608 } else {
13609 d = dst;
13610 if ((l = (*atomfromstr)(s, &len, &d, false)) < 0 ||
13611 l < (ssize_t) strlen(s)) {
13612 if (abort_on_error) {
13613 GDKclrerr();
13614 GDKerror("22018!conversion of string "
13615 "'%s' to type %s failed.\n",
13616 s, ATOMname(tp));
13617 return BUN_NONE;
13618 }
13619 memcpy(dst, nil, len);
13620 }
13621 assert(len == ATOMsize(tp));
13622 if (ATOMcmp(tp, dst, nil) == 0)
13623 nils++;
13624 }
13625 i++;
13626 dst = (void *) ((char *) dst + len);
13627 x = canditer_next(ci);
13628 if (is_oid_nil(x))
13629 break;
13630 x -= candoff;
13631 } while (i < cnt);
13632 while (i < cnt) {
13633 memcpy(dst, nil, len);
13634 dst = (void *) ((char *) dst + len);
13635 i++;
13636 nils++;
13637 }
13638 return nils;
13639}
13640
13641static BUN
13642convert_void_any(oid seq, BUN cnt, BAT *bn,
13643 struct canditer *restrict ci, oid candoff,
13644 bool abort_on_error, bool *reduce)
13645{
13646 BUN nils = 0;
13647 BUN i = 0;
13648 int tp = bn->ttype;
13649 void *restrict dst = Tloc(bn, 0);
13650 ssize_t (*atomtostr)(str *, size_t *, const void *, bool) = BATatoms[TYPE_oid].atomToStr;
13651 char *s = NULL;
13652 size_t len = 0;
13653 oid x = canditer_next(ci) - candoff;
13654
13655 *reduce = false;
13656 assert(!is_oid_nil(seq));
13657
13658 switch (ATOMbasetype(tp)) {
13659 case TYPE_bte:
13660 if (tp == TYPE_bit) {
13661 if (x == 0 && seq == 0) {
13662 ((bte *) dst)[i++] = 0;
13663 x = canditer_next(ci);
13664 }
13665 while (i < cnt) {
13666 while (i < x) {
13667 ((bit *) dst)[i++] = bit_nil;
13668 nils++;
13669 }
13670 ((bit *) dst)[i] = 1;
13671 i++;
13672 x = canditer_next(ci);
13673 if (is_oid_nil(x))
13674 break;
13675 x -= candoff;
13676 }
13677 } else {
13678 do {
13679 while (i < x) {
13680 ((bte *) dst)[i++] = bte_nil;
13681 nils++;
13682 }
13683 if (seq + i > GDK_bte_max) {
13684 if (abort_on_error)
13685 CONV_OVERFLOW(oid, "bte", seq + i);
13686 ((bte *) dst)[i] = bte_nil;
13687 nils++;
13688 } else
13689 ((bte *) dst)[i] = (bte) (seq + i);
13690 i++;
13691 x = canditer_next(ci);
13692 if (is_oid_nil(x))
13693 break;
13694 x -= candoff;
13695 } while (i < cnt);
13696 }
13697 while (i < cnt) {
13698 ((bte *) dst)[i++] = bte_nil;
13699 nils++;
13700 }
13701 break;
13702 case TYPE_sht:
13703 do {
13704 while (i < x) {
13705 ((sht *) dst)[i++] = sht_nil;
13706 nils++;
13707 }
13708 if (seq + i > GDK_sht_max) {
13709 if (abort_on_error)
13710 CONV_OVERFLOW(oid, "sht", seq + i);
13711 ((sht *) dst)[i] = sht_nil;
13712 nils++;
13713 } else
13714 ((sht *) dst)[i] = (sht) (seq + i);
13715 i++;
13716 x = canditer_next(ci);
13717 if (is_oid_nil(x))
13718 break;
13719 x -= candoff;
13720 } while (i < cnt);
13721 while (i < cnt) {
13722 ((sht *) dst)[i++] = sht_nil;
13723 nils++;
13724 }
13725 break;
13726 case TYPE_int:
13727 do {
13728 while (i < x) {
13729 ((int *) dst)[i++] = int_nil;
13730 nils++;
13731 }
13732#if SIZEOF_OID > SIZEOF_INT
13733 if (seq + i > GDK_int_max) {
13734 if (abort_on_error)
13735 CONV_OVERFLOW(oid, "int", seq + i);
13736 ((int *) dst)[i] = int_nil;
13737 nils++;
13738 } else
13739#endif
13740 ((int *) dst)[i] = (int) (seq + i);
13741 i++;
13742 x = canditer_next(ci);
13743 if (is_oid_nil(x))
13744 break;
13745 x -= candoff;
13746 } while (i < cnt);
13747 while (i < cnt) {
13748 ((int *) dst)[i++] = int_nil;
13749 nils++;
13750 }
13751 break;
13752 case TYPE_lng:
13753 do {
13754 while (i < x) {
13755 ((lng *) dst)[i++] = lng_nil;
13756 nils++;
13757 }
13758 ((lng *) dst)[i] = (lng) (seq + i);
13759 i++;
13760 x = canditer_next(ci);
13761 if (is_oid_nil(x))
13762 break;
13763 x -= candoff;
13764 } while (i < cnt);
13765 while (i < cnt) {
13766 ((lng *) dst)[i++] = lng_nil;
13767 nils++;
13768 }
13769 break;
13770#ifdef HAVE_HGE
13771 case TYPE_hge:
13772 do {
13773 while (i < x) {
13774 ((hge *) dst)[i++] = hge_nil;
13775 nils++;
13776 }
13777 ((hge *) dst)[i] = (hge) (seq + i);
13778 i++;
13779 x = canditer_next(ci);
13780 if (is_oid_nil(x))
13781 break;
13782 x -= candoff;
13783 } while (i < cnt);
13784 while (i < cnt) {
13785 ((hge *) dst)[i++] = hge_nil;
13786 nils++;
13787 }
13788 break;
13789#endif
13790 case TYPE_flt:
13791 do {
13792 while (i < x) {
13793 ((flt *) dst)[i++] = flt_nil;
13794 nils++;
13795 }
13796 ((flt *) dst)[i] = (flt) (seq + i);
13797 i++;
13798 x = canditer_next(ci);
13799 if (is_oid_nil(x))
13800 break;
13801 x -= candoff;
13802 } while (i < cnt);
13803 while (i < cnt) {
13804 ((flt *) dst)[i++] = flt_nil;
13805 nils++;
13806 }
13807 break;
13808 case TYPE_dbl:
13809 do {
13810 while (i < x) {
13811 ((dbl *) dst)[i++] = dbl_nil;
13812 nils++;
13813 }
13814 ((dbl *) dst)[i] = (dbl) (seq + i);
13815 i++;
13816 x = canditer_next(ci);
13817 if (is_oid_nil(x))
13818 break;
13819 x -= candoff;
13820 } while (i < cnt);
13821 while (i < cnt) {
13822 ((dbl *) dst)[i++] = dbl_nil;
13823 nils++;
13824 }
13825 break;
13826 case TYPE_str:
13827 do {
13828 while (i < x) {
13829 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13830 i++;
13831 nils++;
13832 }
13833 if ((*atomtostr)(&s, &len, &(oid){seq + i}, false) < 0)
13834 goto bunins_failed;
13835 tfastins_nocheckVAR(bn, i, s, bn->twidth);
13836 i++;
13837 x = canditer_next(ci);
13838 if (is_oid_nil(x))
13839 break;
13840 x -= candoff;
13841 } while (i < cnt);
13842 GDKfree(s);
13843 s = NULL;
13844 while (i < cnt) {
13845 tfastins_nocheckVAR(bn, i, str_nil, bn->twidth);
13846 i++;
13847 }
13848 break;
13849 default:
13850 return BUN_NONE + 1;
13851 }
13852
13853 bn->theap.dirty = true;
13854 return nils;
13855
13856 bunins_failed:
13857 GDKfree(s);
13858 return BUN_NONE + 2;
13859}
13860
13861static BUN
13862convert_typeswitchloop(const void *src, int stp, void *restrict dst, int dtp,
13863 BUN cnt, struct canditer *restrict ci,
13864 oid candoff, bool abort_on_error, bool *reduce)
13865{
13866 switch (ATOMbasetype(stp)) {
13867 case TYPE_bte:
13868 switch (ATOMbasetype(dtp)) {
13869 case TYPE_bte:
13870 if (dtp == TYPE_bit)
13871 return convert_bte_bit(src, dst, cnt,
13872 ci, candoff,
13873 reduce);
13874 return convert_bte_bte(src, dst, cnt,
13875 ci, candoff, reduce);
13876 case TYPE_sht:
13877 return convert_bte_sht(src, dst, cnt,
13878 ci, candoff, reduce);
13879 case TYPE_int:
13880#if SIZEOF_OID == SIZEOF_INT
13881 if (dtp == TYPE_oid)
13882 return convert_bte_oid(src, dst, cnt,
13883 ci, candoff,
13884 abort_on_error, reduce);
13885#endif
13886 return convert_bte_int(src, dst, cnt,
13887 ci, candoff, reduce);
13888 case TYPE_lng:
13889#if SIZEOF_OID == SIZEOF_LNG
13890 if (dtp == TYPE_oid)
13891 return convert_bte_oid(src, dst, cnt,
13892 ci, candoff,
13893 abort_on_error, reduce);
13894#endif
13895 return convert_bte_lng(src, dst, cnt,
13896 ci, candoff, reduce);
13897#ifdef HAVE_HGE
13898 case TYPE_hge:
13899 return convert_bte_hge(src, dst, cnt,
13900 ci, candoff, reduce);
13901#endif
13902 case TYPE_flt:
13903 return convert_bte_flt(src, dst, cnt,
13904 ci, candoff, reduce);
13905 case TYPE_dbl:
13906 return convert_bte_dbl(src, dst, cnt,
13907 ci, candoff, reduce);
13908 default:
13909 return BUN_NONE + 1;
13910 }
13911 case TYPE_sht:
13912 switch (ATOMbasetype(dtp)) {
13913 case TYPE_bte:
13914 if (dtp == TYPE_bit)
13915 return convert_sht_bit(src, dst, cnt,
13916 ci, candoff,
13917 reduce);
13918 return convert_sht_bte(src, dst, cnt,
13919 ci, candoff,
13920 abort_on_error, reduce);
13921 case TYPE_sht:
13922 return convert_sht_sht(src, dst, cnt,
13923 ci, candoff, reduce);
13924 case TYPE_int:
13925#if SIZEOF_OID == SIZEOF_INT
13926 if (dtp == TYPE_oid)
13927 return convert_sht_oid(src, dst, cnt,
13928 ci, candoff,
13929 abort_on_error, reduce);
13930#endif
13931 return convert_sht_int(src, dst, cnt,
13932 ci, candoff, reduce);
13933 case TYPE_lng:
13934#if SIZEOF_OID == SIZEOF_LNG
13935 if (dtp == TYPE_oid)
13936 return convert_sht_oid(src, dst, cnt,
13937 ci, candoff,
13938 abort_on_error, reduce);
13939#endif
13940 return convert_sht_lng(src, dst, cnt,
13941 ci, candoff, reduce);
13942#ifdef HAVE_HGE
13943 case TYPE_hge:
13944 return convert_sht_hge(src, dst, cnt,
13945 ci, candoff, reduce);
13946#endif
13947 case TYPE_flt:
13948 return convert_sht_flt(src, dst, cnt,
13949 ci, candoff, reduce);
13950 case TYPE_dbl:
13951 return convert_sht_dbl(src, dst, cnt,
13952 ci, candoff, reduce);
13953 default:
13954 return BUN_NONE + 1;
13955 }
13956 case TYPE_int:
13957 switch (ATOMbasetype(dtp)) {
13958 case TYPE_bte:
13959 if (dtp == TYPE_bit) {
13960 return convert_int_bit(src, dst, cnt,
13961 ci, candoff,
13962 reduce);
13963 }
13964 return convert_int_bte(src, dst, cnt,
13965 ci, candoff,
13966 abort_on_error, reduce);
13967 case TYPE_sht:
13968 return convert_int_sht(src, dst, cnt,
13969 ci, candoff,
13970 abort_on_error, reduce);
13971 case TYPE_int:
13972#if SIZEOF_OID == SIZEOF_INT
13973 if (dtp == TYPE_oid)
13974 return convert_int_oid(src, dst, cnt,
13975 ci, candoff,
13976 abort_on_error, reduce);
13977#endif
13978 return convert_int_int(src, dst, cnt,
13979 ci, candoff, reduce);
13980 case TYPE_lng:
13981#if SIZEOF_OID == SIZEOF_LNG
13982 if (dtp == TYPE_oid)
13983 return convert_int_oid(src, dst, cnt,
13984 ci, candoff,
13985 abort_on_error, reduce);
13986#endif
13987 return convert_int_lng(src, dst, cnt,
13988 ci, candoff, reduce);
13989#ifdef HAVE_HGE
13990 case TYPE_hge:
13991 return convert_int_hge(src, dst, cnt,
13992 ci, candoff, reduce);
13993#endif
13994 case TYPE_flt:
13995 return convert_int_flt(src, dst, cnt,
13996 ci, candoff, reduce);
13997 case TYPE_dbl:
13998 return convert_int_dbl(src, dst, cnt,
13999 ci, candoff, reduce);
14000 default:
14001 return BUN_NONE + 1;
14002 }
14003 case TYPE_lng:
14004 switch (ATOMbasetype(dtp)) {
14005 case TYPE_bte:
14006 if (dtp == TYPE_bit) {
14007 return convert_lng_bit(src, dst, cnt,
14008 ci, candoff,
14009 reduce);
14010 }
14011 return convert_lng_bte(src, dst, cnt,
14012 ci, candoff,
14013 abort_on_error, reduce);
14014 case TYPE_sht:
14015 return convert_lng_sht(src, dst, cnt,
14016 ci, candoff,
14017 abort_on_error, reduce);
14018 case TYPE_int:
14019#if SIZEOF_OID == SIZEOF_INT
14020 if (dtp == TYPE_oid)
14021 return convert_lng_oid(src, dst, cnt,
14022 ci, candoff,
14023 abort_on_error, reduce);
14024#endif
14025 return convert_lng_int(src, dst, cnt,
14026 ci, candoff,
14027 abort_on_error, reduce);
14028 case TYPE_lng:
14029#if SIZEOF_OID == SIZEOF_LNG
14030 if (dtp == TYPE_oid)
14031 return convert_lng_oid(src, dst, cnt,
14032 ci, candoff,
14033 abort_on_error, reduce);
14034#endif
14035 return convert_lng_lng(src, dst, cnt,
14036 ci, candoff, reduce);
14037#ifdef HAVE_HGE
14038 case TYPE_hge:
14039 return convert_lng_hge(src, dst, cnt,
14040 ci, candoff, reduce);
14041#endif
14042 case TYPE_flt:
14043 return convert_lng_flt(src, dst, cnt,
14044 ci, candoff, reduce);
14045 case TYPE_dbl:
14046 return convert_lng_dbl(src, dst, cnt,
14047 ci, candoff, reduce);
14048 default:
14049 return BUN_NONE + 1;
14050 }
14051#ifdef HAVE_HGE
14052 case TYPE_hge:
14053 switch (ATOMbasetype(dtp)) {
14054 case TYPE_bte:
14055 if (dtp == TYPE_bit) {
14056 return convert_hge_bit(src, dst, cnt,
14057 ci, candoff,
14058 reduce);
14059 }
14060 return convert_hge_bte(src, dst, cnt,
14061 ci, candoff,
14062 abort_on_error, reduce);
14063 case TYPE_sht:
14064 return convert_hge_sht(src, dst, cnt,
14065 ci, candoff,
14066 abort_on_error, reduce);
14067 case TYPE_int:
14068 return convert_hge_int(src, dst, cnt,
14069 ci, candoff,
14070 abort_on_error, reduce);
14071 case TYPE_lng:
14072 return convert_hge_lng(src, dst, cnt,
14073 ci, candoff,
14074 abort_on_error, reduce);
14075 case TYPE_hge:
14076 return convert_hge_hge(src, dst, cnt,
14077 ci, candoff, reduce);
14078 case TYPE_oid:
14079 return convert_hge_oid(src, dst, cnt,
14080 ci, candoff,
14081 abort_on_error, reduce);
14082 case TYPE_flt:
14083 return convert_hge_flt(src, dst, cnt,
14084 ci, candoff, reduce);
14085 case TYPE_dbl:
14086 return convert_hge_dbl(src, dst, cnt,
14087 ci, candoff, reduce);
14088 default:
14089 return BUN_NONE + 1;
14090 }
14091#endif
14092 case TYPE_flt:
14093 switch (ATOMbasetype(dtp)) {
14094 case TYPE_bte:
14095 if (dtp == TYPE_bit) {
14096 return convert_flt_bit(src, dst, cnt,
14097 ci, candoff,
14098 reduce);
14099 }
14100 return convert_flt_bte(src, dst, cnt,
14101 ci, candoff,
14102 abort_on_error, reduce);
14103 case TYPE_sht:
14104 return convert_flt_sht(src, dst, cnt,
14105 ci, candoff,
14106 abort_on_error, reduce);
14107 case TYPE_int:
14108#if SIZEOF_OID == SIZEOF_INT
14109 if (dtp == TYPE_oid)
14110 return convert_flt_oid(src, dst, cnt,
14111 ci, candoff,
14112 abort_on_error, reduce);
14113#endif
14114 return convert_flt_int(src, dst, cnt,
14115 ci, candoff,
14116 abort_on_error, reduce);
14117 case TYPE_lng:
14118#if SIZEOF_OID == SIZEOF_LNG
14119 if (dtp == TYPE_oid)
14120 return convert_flt_oid(src, dst, cnt,
14121 ci, candoff,
14122 abort_on_error, reduce);
14123#endif
14124 return convert_flt_lng(src, dst, cnt,
14125 ci, candoff,
14126 abort_on_error, reduce);
14127#ifdef HAVE_HGE
14128 case TYPE_hge:
14129 return convert_flt_hge(src, dst, cnt,
14130 ci, candoff,
14131 abort_on_error, reduce);
14132#endif
14133 case TYPE_flt:
14134 return convert_flt_flt(src, dst, cnt,
14135 ci, candoff, reduce);
14136 case TYPE_dbl:
14137 return convert_flt_dbl(src, dst, cnt,
14138 ci, candoff, reduce);
14139 default:
14140 return BUN_NONE + 1;
14141 }
14142 case TYPE_dbl:
14143 switch (ATOMbasetype(dtp)) {
14144 case TYPE_bte:
14145 if (dtp == TYPE_bit) {
14146 return convert_dbl_bit(src, dst, cnt,
14147 ci, candoff,
14148 reduce);
14149 }
14150 return convert_dbl_bte(src, dst, cnt,
14151 ci, candoff,
14152 abort_on_error, reduce);
14153 case TYPE_sht:
14154 return convert_dbl_sht(src, dst, cnt,
14155 ci, candoff,
14156 abort_on_error, reduce);
14157 case TYPE_int:
14158#if SIZEOF_OID == SIZEOF_INT
14159 if (dtp == TYPE_oid)
14160 return convert_dbl_oid(src, dst, cnt,
14161 ci, candoff,
14162 abort_on_error, reduce);
14163#endif
14164 return convert_dbl_int(src, dst, cnt,
14165 ci, candoff,
14166 abort_on_error, reduce);
14167 case TYPE_lng:
14168#if SIZEOF_OID == SIZEOF_LNG
14169 if (dtp == TYPE_oid)
14170 return convert_dbl_oid(src, dst, cnt,
14171 ci, candoff,
14172 abort_on_error, reduce);
14173#endif
14174 return convert_dbl_lng(src, dst, cnt,
14175 ci, candoff,
14176 abort_on_error, reduce);
14177#ifdef HAVE_HGE
14178 case TYPE_hge:
14179 return convert_dbl_hge(src, dst, cnt,
14180 ci, candoff,
14181 abort_on_error, reduce);
14182#endif
14183 case TYPE_flt:
14184 return convert_dbl_flt(src, dst, cnt,
14185 ci, candoff,
14186 abort_on_error, reduce);
14187 case TYPE_dbl:
14188 return convert_dbl_dbl(src, dst, cnt,
14189 ci, candoff, reduce);
14190 default:
14191 return BUN_NONE + 1;
14192 }
14193 default:
14194 return BUN_NONE + 1;
14195 }
14196}
14197
14198BAT *
14199BATconvert(BAT *b, BAT *s, int tp, bool abort_on_error)
14200{
14201 BAT *bn;
14202 BUN nils = 0; /* in case no conversion defined */
14203 struct canditer ci;
14204 BUN cnt, ncand;
14205 /* set reduce to true if there are (potentially) multiple
14206 * (different) source values that map to the same destination
14207 * value */
14208 bool reduce = false;
14209
14210 BATcheck(b, __func__, NULL);
14211 if (tp == TYPE_void)
14212 tp = TYPE_oid;
14213
14214 cnt = BATcount(b);
14215 ncand = canditer_init(&ci, b, s);
14216 if (ncand == 0 || (b->ttype == TYPE_void && is_oid_nil(b->tseqbase)))
14217 return BATconstant(b->hseqbase, tp,
14218 ATOMnilptr(tp), cnt, TRANSIENT);
14219
14220 if (cnt == ncand && tp != TYPE_bit &&
14221 ATOMbasetype(b->ttype) == ATOMbasetype(tp) &&
14222 (tp != TYPE_oid || b->ttype == TYPE_oid) &&
14223 (tp != TYPE_str ||
14224 BATatoms[b->ttype].atomToStr == BATatoms[TYPE_str].atomToStr)) {
14225 return COLcopy(b, tp, false, TRANSIENT);
14226 }
14227
14228 bn = COLnew(b->hseqbase, tp, cnt, TRANSIENT);
14229 if (bn == NULL)
14230 return NULL;
14231
14232 if (b->ttype == TYPE_void)
14233 nils = convert_void_any(b->tseqbase, cnt, bn,
14234 &ci, b->hseqbase,
14235 abort_on_error, &reduce);
14236 else if (tp == TYPE_str)
14237 nils = convert_any_str(b, bn, cnt, &ci);
14238 else if (b->ttype == TYPE_str) {
14239 reduce = true;
14240 nils = convert_str_any(b, tp, Tloc(bn, 0),
14241 &ci, b->hseqbase,
14242 abort_on_error);
14243 } else
14244 nils = convert_typeswitchloop(Tloc(b, 0), b->ttype,
14245 Tloc(bn, 0), tp,
14246 cnt, &ci, b->hseqbase,
14247 abort_on_error, &reduce);
14248
14249 if (nils >= BUN_NONE) {
14250 BBPunfix(bn->batCacheid);
14251 if (nils == BUN_NONE + 1) {
14252 GDKerror("%s: type combination (convert(%s)->%s) "
14253 "not supported.\n", __func__,
14254 ATOMname(b->ttype), ATOMname(tp));
14255 } else if (nils == BUN_NONE + 2) {
14256 GDKerror("%s: could not insert value into BAT.\n", __func__);
14257 }
14258 return NULL;
14259 }
14260
14261 BATsetcount(bn, cnt);
14262
14263 bn->tnil = nils != 0;
14264 bn->tnonil = nils == 0;
14265 if ((bn->ttype != TYPE_bit && b->ttype != TYPE_str) ||
14266 BATcount(bn) < 2) {
14267 bn->tsorted = nils == 0 && b->tsorted;
14268 bn->trevsorted = nils == 0 && b->trevsorted;
14269 } else {
14270 bn->tsorted = false;
14271 bn->trevsorted = false;
14272 }
14273 if (!reduce || BATcount(bn) < 2)
14274 bn->tkey = b->tkey && nils <= 1;
14275 else
14276 bn->tkey = false;
14277
14278 return bn;
14279}
14280
14281gdk_return
14282VARconvert(ValPtr ret, const ValRecord *v, bool abort_on_error)
14283{
14284 ptr p;
14285 BUN nils = 0;
14286 bool reduce;
14287
14288 if (ret->vtype == TYPE_str) {
14289 if (v->vtype == TYPE_void ||
14290 (*ATOMcompare(v->vtype))(VALptr(v),
14291 ATOMnilptr(v->vtype)) == 0) {
14292 ret->val.sval = GDKstrdup(str_nil);
14293 } else if (BATatoms[v->vtype].atomToStr == BATatoms[TYPE_str].atomToStr) {
14294 ret->val.sval = GDKstrdup(v->val.sval);
14295 } else {
14296 ret->len = 0;
14297 ret->val.sval = NULL;
14298 if ((*BATatoms[v->vtype].atomToStr)(&ret->val.sval,
14299 &ret->len,
14300 VALptr(v),
14301 false) < 0) {
14302 GDKfree(ret->val.sval);
14303 ret->val.sval = NULL;
14304 ret->len = 0;
14305 nils = BUN_NONE;
14306 }
14307 }
14308 if (ret->val.sval == NULL)
14309 nils = BUN_NONE;
14310 } else if (ret->vtype == TYPE_void) {
14311 if (abort_on_error &&
14312 ATOMcmp(v->vtype, VALptr(v), ATOMnilptr(v->vtype)) != 0) {
14313 GDKerror("22003!cannot convert non-nil to void.\n");
14314 nils = BUN_NONE;
14315 }
14316 ret->val.oval = oid_nil;
14317 } else if (v->vtype == TYPE_void) {
14318 if (VALinit(ret, ret->vtype, ATOMnilptr(ret->vtype)) == NULL)
14319 nils = BUN_NONE;
14320 } else if (v->vtype == TYPE_str) {
14321 if (v->val.sval == NULL || strcmp(v->val.sval, str_nil) == 0) {
14322 if (VALinit(ret, ret->vtype, ATOMnilptr(ret->vtype)) == NULL)
14323 nils = BUN_NONE;
14324 } else {
14325 ssize_t l;
14326 size_t len;
14327
14328 if (ATOMextern(ret->vtype)) {
14329 /* let atomFromStr allocate memory
14330 * which we later give away to ret */
14331 p = NULL;
14332 len = 0;
14333 } else {
14334 /* use the space provided by ret */
14335 p = VALget(ret);
14336 len = ATOMsize(ret->vtype);
14337 }
14338 if ((l = (*BATatoms[ret->vtype].atomFromStr)(
14339 v->val.sval, &len, &p, false)) < 0 ||
14340 l < (ssize_t) strlen(v->val.sval)) {
14341 if (ATOMextern(ret->vtype))
14342 GDKfree(p);
14343 GDKclrerr();
14344 GDKerror("22018!conversion of string "
14345 "'%s' to type %s failed.\n",
14346 v->val.sval, ATOMname(ret->vtype));
14347 nils = BUN_NONE;
14348 } else {
14349 /* now give value obtained to ret */
14350 assert(ATOMextern(ret->vtype) ||
14351 p == VALget(ret));
14352 ret->len = (int) len;
14353 if (ATOMextern(ret->vtype))
14354 VALset(ret, ret->vtype, p);
14355 }
14356 }
14357 } else {
14358 nils = convert_typeswitchloop(VALptr(v), v->vtype,
14359 VALget(ret), ret->vtype, 1,
14360 &(struct canditer){.tpe=cand_dense, .ncand=1},
14361 0, abort_on_error, &reduce);
14362 }
14363 if (nils == BUN_NONE + 1) {
14364 GDKerror("VARconvert: conversion from type %s to type %s "
14365 "unsupported.\n",
14366 ATOMname(v->vtype), ATOMname(ret->vtype));
14367 return GDK_FAIL;
14368 }
14369 ret->len = ATOMlen(ret->vtype, VALptr(ret));
14370 return nils == BUN_NONE ? GDK_FAIL : GDK_SUCCEED;
14371}
14372