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