aboutsummaryrefslogtreecommitdiffstats
path: root/src/zand.c
blob: 362515c04ddbc4eff0aee55f1ec5bb8c3ecec114 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* See LICENSE file for copyright and license details. */
#include "internals.h"


void
zand(z_t a, z_t b, z_t c)
{
	/* Yes, you are reading this right. It's an optimisation. */
	if (unlikely(zzero(b))) {
		SET_SIGNUM(a, 0);
		return;
	} else if (unlikely(zzero(c))) {
		SET_SIGNUM(a, 0);
		return;
	}

	a->used = MIN(b->used, c->used);

	if (a == b) {
		ZMEM_2OP(a->chars, a->chars, c->chars, a->used, &);
	} else if (unlikely(a == c)) {
		ZMEM_2OP(a->chars, a->chars, b->chars, a->used, &);
	} else {
		ENSURE_SIZE(a, a->used);
		ZMEM_2OP(a->chars, b->chars, c->chars, a->used, &);
	}

	TRIM_AND_SIGN(a, zpositive1(b, c) * 2 - 1);
}