ldivmod_helper.c revision 245548
1245548Sandrew/* 2245548Sandrew * Copyright (C) 2012 Andrew Turner 3245548Sandrew * All rights reserved. 4245548Sandrew * 5245548Sandrew * Redistribution and use in source and binary forms, with or without 6245548Sandrew * modification, are permitted provided that the following conditions 7245548Sandrew * are met: 8245548Sandrew * 1. Redistributions of source code must retain the above copyright 9245548Sandrew * notice, this list of conditions and the following disclaimer. 10245548Sandrew * 2. Redistributions in binary form must reproduce the above copyright 11245548Sandrew * notice, this list of conditions and the following disclaimer in the 12245548Sandrew * documentation and/or other materials provided with the distribution. 13245548Sandrew * 14245548Sandrew * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15245548Sandrew * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16245548Sandrew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17245548Sandrew * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18245548Sandrew * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19245548Sandrew * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20245548Sandrew * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21245548Sandrew * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22245548Sandrew * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23245548Sandrew * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24245548Sandrew * SUCH DAMAGE. 25245548Sandrew * 26245548Sandrew */ 27245548Sandrew 28245548Sandrew#include <sys/cdefs.h> 29245548Sandrew__FBSDID("$FreeBSD: head/sys/libkern/arm/ldivmod_helper.c 245548 2013-01-17 09:37:42Z andrew $"); 30245548Sandrew 31245548Sandrew#ifdef __ARM_EABI__ 32245548Sandrew#include <libkern/quad.h> 33245548Sandrew 34245548Sandrew/* 35245548Sandrew * Helper for __aeabi_ldivmod. 36245548Sandrew * TODO: __divdi3 calls __qdivrem. We should do the same and use the 37245548Sandrew * remainder value rather than re-calculating it. 38245548Sandrew */ 39245548Sandrewlong long __kern_ldivmod(long long, long long, long long *); 40245548Sandrew 41245548Sandrewlong long 42245548Sandrew__kern_ldivmod(long long n, long long m, long long *rem) 43245548Sandrew{ 44245548Sandrew long long q; 45245548Sandrew 46245548Sandrew q = __divdi3(n, m); /* q = n / m */ 47245548Sandrew *rem = n - m * q; 48245548Sandrew 49245548Sandrew return q; 50245548Sandrew} 51245548Sandrew 52245548Sandrew#endif 53245548Sandrew 54