libzahl

big integer library
git clone git://git.suckless.org/libzahl
Log | Files | Refs | README | LICENSE

zxor.c (984B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "internals.h"
      3 
      4 
      5 void
      6 zxor(z_t a, z_t b, z_t c)
      7 {
      8 	size_t n, m, bn, cn;
      9 	const zahl_char_t *restrict bc;
     10 	const zahl_char_t *restrict cc;
     11 
     12 	if (unlikely(zzero(b))) {
     13 		SET(a, c);
     14 		return;
     15 	} else if (unlikely(zzero(c))) {
     16 		SET(a, b);
     17 		return;
     18 	}
     19 
     20 	bn = b->used;
     21 	bc = b->chars;
     22 	cn = c->used;
     23 	cc = c->chars;
     24 
     25 	MIN_MAX_1(n, m, bn, cn);
     26 	ENSURE_SIZE(a, m);
     27 
     28 	if (a == b) {
     29 		ZMEM_2OP_PRECISE(a->chars, a->chars, cc, n, ^);
     30 		if (a->used < cn)
     31 			zmemcpy_range(a->chars, cc, n, m);
     32 	} else if (unlikely(a == c)) {
     33 		ZMEM_2OP_PRECISE(a->chars, a->chars, bc, n, ^);
     34 		if (a->used < bn)
     35 			zmemcpy_range(a->chars, bc, n, m);
     36 	} else if (m == bn) {
     37 		ZMEM_2OP(a->chars, c->chars, b->chars, n, ^);
     38 		zmemcpy_range(a->chars, b->chars, n, m);
     39 	} else {
     40 		ZMEM_2OP(a->chars, b->chars, c->chars, n, ^);
     41 		zmemcpy_range(a->chars, c->chars, n, m);
     42 	}
     43 
     44 	a->used = m;
     45 	TRIM_AND_SIGN(a, 1 - 2 * ((zsignum(b) ^ zsignum(c)) < 0));
     46 }