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$");
30245548Sandrew
31245548Sandrew#include <libkern/quad.h>
32245548Sandrew
33245548Sandrew/*
34245548Sandrew * Helper for __aeabi_ldivmod.
35245548Sandrew * TODO: __divdi3 calls __qdivrem. We should do the same and use the
36245548Sandrew * remainder value rather than re-calculating it.
37245548Sandrew */
38245548Sandrewlong long __kern_ldivmod(long long, long long, long long *);
39245548Sandrew
40245548Sandrewlong long
41245548Sandrew__kern_ldivmod(long long n, long long m, long long *rem)
42245548Sandrew{
43245548Sandrew	long long q;
44245548Sandrew
45245548Sandrew	q = __divdi3(n, m);	/* q = n / m */
46245548Sandrew	*rem = n - m * q;
47245548Sandrew
48245548Sandrew	return q;
49245548Sandrew}
50