moddi3.c revision 1.2
1112918Sjeff/*- 2112918Sjeff * Copyright (c) 1992, 1993 3112918Sjeff * The Regents of the University of California. All rights reserved. 4112918Sjeff * 5112918Sjeff * This software was developed by the Computer Systems Engineering group 6112918Sjeff * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7112918Sjeff * contributed to Berkeley. 8112918Sjeff * 9112918Sjeff * Redistribution and use in source and binary forms, with or without 10112918Sjeff * modification, are permitted provided that the following conditions 11112918Sjeff * are met: 12112918Sjeff * 1. Redistributions of source code must retain the above copyright 13165967Simp * notice, this list of conditions and the following disclaimer. 14112918Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15112918Sjeff * notice, this list of conditions and the following disclaimer in the 16112918Sjeff * documentation and/or other materials provided with the distribution. 17112918Sjeff * 3. All advertising materials mentioning features or use of this software 18112918Sjeff * must display the following acknowledgement: 19112918Sjeff * This product includes software developed by the University of 20112918Sjeff * California, Berkeley and its contributors. 21112918Sjeff * 4. Neither the name of the University nor the names of its contributors 22112918Sjeff * may be used to endorse or promote products derived from this software 23112918Sjeff * without specific prior written permission. 24112918Sjeff * 25112918Sjeff * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26112918Sjeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27112918Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28112918Sjeff * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29112918Sjeff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30112918Sjeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31144518Sdavidxu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32157457Sdavidxu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33112918Sjeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34112918Sjeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35157457Sdavidxu * SUCH DAMAGE. 36157457Sdavidxu */ 37144518Sdavidxu 38112918Sjeff#if defined(LIBC_SCCS) && !defined(lint) 39112918Sjeffstatic char rcsid[] = "$OpenBSD: moddi3.c,v 1.2 1996/08/19 08:30:37 tholo Exp $"; 40154055Sdavidxu#endif /* LIBC_SCCS and not lint */ 41154055Sdavidxu 42144518Sdavidxu#include "quad.h" 43112918Sjeff 44112918Sjeff/* 45112918Sjeff * Return remainder after dividing two signed quads. 46112918Sjeff * 47112918Sjeff * XXX 48112918Sjeff * If -1/2 should produce -1 on this machine, this code is wrong. 49112918Sjeff */ 50144518Sdavidxuquad_t 51144518Sdavidxu__moddi3(a, b) 52144518Sdavidxu quad_t a, b; 53144518Sdavidxu{ 54144518Sdavidxu u_quad_t ua, ub, ur; 55144518Sdavidxu int neg; 56144518Sdavidxu 57144518Sdavidxu if (a < 0) 58144518Sdavidxu ua = -(u_quad_t)a, neg = 1; 59144518Sdavidxu else 60144518Sdavidxu ua = a, neg = 0; 61144518Sdavidxu if (b < 0) 62154055Sdavidxu ub = -(u_quad_t)b, neg ^= 1; 63144518Sdavidxu else 64144518Sdavidxu ub = b; 65144518Sdavidxu (void)__qdivrem(ua, ub, &ur); 66144518Sdavidxu return (neg ? -ur : ur); 67144518Sdavidxu} 68144518Sdavidxu