Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mulsi3.c « h8500 « machine « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a923e8db5ec9f7e6834f882c38ffaa5a9fb8b4ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

typedef union {
  struct {
  unsigned int msw;
  unsigned int lsw;
} s;
  long v;
} u;

long __mulsi3(u a, u b)
{
  int s;
  long pp1;
  long pp2;
  long r;

  if (a.s.msw == 0 &&
      b.s.msw == 0)
    {
      return (long)a.s.lsw * b.s.lsw;
    }

  s = 0;
  if (a.v < 0)
    {
      s = 1;
      a.v = - a.v;
    }
  if (b.v < 0)
    { 
      s = 1-s;
      b.v = - b.v;
    }

  pp1 = (long)a.s.lsw * b.s.lsw ;
  pp2 = (long)a.s.lsw * b.s.msw + (long)a.s.msw * b.s.lsw;

  pp1 += pp2 << 16;

  if (s)
    {
      pp1 = -pp1;
    }
  return pp1;
}
long __mulpsi3(long a, long b)
{
 return a*b;
}


short 
__mulhi3(short a, short b)
{
  int r;

  r = 0;
  while (a) 
    {
      if (a & 1) 
	{
	  r += b;

	}
      b<<=1;
      a>>=1;

    }
  return r;
}