b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) // SPDX-License-Identifier: GPL-2.0
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 2) #include "libgcc.h"
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 3)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 4) #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 5) #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 6) #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 7)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 8) #define umul_ppmm(w1, w0, u, v) \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 9) do { \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 10) UWtype __x0, __x1, __x2, __x3; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 11) UHWtype __ul, __vl, __uh, __vh; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 12) __ul = __ll_lowpart(u); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 13) __uh = __ll_highpart(u); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 14) __vl = __ll_lowpart(v); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 15) __vh = __ll_highpart(v); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 16) __x0 = (UWtype) __ul * __vl; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 17) __x1 = (UWtype) __ul * __vh; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 18) __x2 = (UWtype) __uh * __vl; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 19) __x3 = (UWtype) __uh * __vh; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 20) __x1 += __ll_highpart(__x0); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 21) __x1 += __x2; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 22) if (__x1 < __x2) \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 23) __x3 += __ll_B; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 24) (w1) = __x3 + __ll_highpart(__x1); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 25) (w0) = __ll_lowpart(__x1) * __ll_B + __ll_lowpart(__x0); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 26) } while (0)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 27)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 28) #define __umulsidi3(u, v) ( \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 29) { \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 30) DWunion __w; \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 31) umul_ppmm(__w.s.high, __w.s.low, u, v); \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 32) __w.ll; } \
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 33) )
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 34)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 35) DWtype __muldi3(DWtype u, DWtype v)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 36) {
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 37) const DWunion uu = {.ll = u};
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 38) const DWunion vv = {.ll = v};
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 39) DWunion w = {.ll = __umulsidi3(uu.s.low, vv.s.low)};
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 40)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 41) w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 42) + (UWtype) uu.s.high * (UWtype) vv.s.low);
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 43)
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 44) return w.ll;
a71a29de4c2f9 (Yoshinori Sato 2015-01-28 02:48:15 +0900 45) }