summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/rsp/vadd.h
blob: 16009e53287a4195d8193eaa16e0e5719d1506f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// license:BSD-3-Clause
// copyright-holders:Tyler J. Stachecki,Ryan Holtz

inline rsp_vec_t vec_vadd(rsp_vec_t vs, rsp_vec_t vt, rsp_vec_t carry, rsp_vec_t *acc_lo)
{
	// VCC uses unsaturated arithmetic.
	rsp_vec_t vd = _mm_add_epi16(vs, vt);
	*acc_lo = _mm_sub_epi16(vd, carry);

	// VD is the signed sum of the two sources and the carry. Since we
	// have to saturate the sum of all three, we have to be clever.
	rsp_vec_t minimum = _mm_min_epi16(vs, vt);
	rsp_vec_t maximum = _mm_max_epi16(vs, vt);
	minimum = _mm_subs_epi16(minimum, carry);
	return _mm_adds_epi16(minimum, maximum);
}