adddi3.c revision 296373
138494Sobrien/*-
2174313Sobrien * Copyright (c) 1992, 1993
338494Sobrien *	The Regents of the University of California.  All rights reserved.
438494Sobrien *
538494Sobrien * This software was developed by the Computer Systems Engineering group
638494Sobrien * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
738494Sobrien * contributed to Berkeley.
838494Sobrien *
938494Sobrien * Redistribution and use in source and binary forms, with or without
1038494Sobrien * modification, are permitted provided that the following conditions
1138494Sobrien * are met:
1238494Sobrien * 1. Redistributions of source code must retain the above copyright
1338494Sobrien *    notice, this list of conditions and the following disclaimer.
1438494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1538494Sobrien *    notice, this list of conditions and the following disclaimer in the
1638494Sobrien *    documentation and/or other materials provided with the distribution.
1738494Sobrien * 4. Neither the name of the University nor the names of its contributors
1838494Sobrien *    may be used to endorse or promote products derived from this software
1938494Sobrien *    without specific prior written permission.
2042633Sobrien *
2138494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2238494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2338494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2438494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2538494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2638494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2738494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2838494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2938494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3038494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3138494Sobrien * SUCH DAMAGE.
3238494Sobrien */
3338494Sobrien
3438494Sobrien#if defined(LIBC_SCCS) && !defined(lint)
3538494Sobrienstatic char sccsid[] = "@(#)adddi3.c	8.1 (Berkeley) 6/4/93";
3638494Sobrien#endif /* LIBC_SCCS and not lint */
3738494Sobrien#include <sys/cdefs.h>
3838494Sobrien__FBSDID("$FreeBSD: releng/10.3/lib/libc/quad/adddi3.c 165903 2007-01-09 00:28:16Z imp $");
3938494Sobrien
40174313Sobrien#include "quad.h"
4138494Sobrien
4238494Sobrien/*
4338494Sobrien * Add two quads.  This is trivial since a one-bit carry from a single
4438494Sobrien * u_long addition x+y occurs if and only if the sum x+y is less than
4538494Sobrien * either x or y (the choice to compare with x or y is arbitrary).
4638494Sobrien */
4738494Sobrienquad_t
4838494Sobrien__adddi3(a, b)
4938494Sobrien	quad_t a, b;
5038494Sobrien{
5138494Sobrien	union uu aa, bb, sum;
5238494Sobrien
5338494Sobrien	aa.q = a;
5438494Sobrien	bb.q = b;
5538494Sobrien	sum.ul[L] = aa.ul[L] + bb.ul[L];
5638494Sobrien	sum.ul[H] = aa.ul[H] + bb.ul[H] + (sum.ul[L] < bb.ul[L]);
57174313Sobrien	return (sum.q);
5838494Sobrien}
5938494Sobrien