summaryrefslogtreecommitdiffstats
path: root/StdLib/LibC/CRT/Gcc.c
blob: cbf4ec273f8cb5b208dc17a2063478aac9d6d8e2 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/** @file
  Integer Arithmetic Run-time support functions for GCC.
  The integer arithmetic routines are used on platforms that don't provide
  hardware support for arithmetic operations on some modes..

  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
  This program and the accompanying materials are licensed and made available
  under the terms and conditions of the BSD License which accompanies this
  distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <sys/EfiCdefs.h>

#include <Library/BaseLib.h>

// Shift Datum left by Count bits.
// ===========================================================================
int __ashlsi3(int Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);
}

long __ashldi3(long Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long) LShiftU64 ((UINT64)Datum, (UINTN)Count);
}

long long __ashlti3(long long Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);
}

// Arithmetically shift Datum right by Count bits.
// ===========================================================================
int __ashrsi3(int Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
}

long __ashrdi3(long Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
}

long long __ashrti3(long long Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
}

// Return the quotient of the signed division of Dividend and Divisor
// ===========================================================================
int __divsi3(int Dividend, int Divisor)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
}

INT64 __divdi3(INT64 Dividend, INT64 Divisor)
{
  INT64 Quotient;

  Quotient = DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
  DEBUG((DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient));

  return Quotient;
}

long long __divti3(long long Dividend, long long Divisor)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
}

// Logically shift Datum right by Count bits
// ===========================================================================
int __lshrsi3(int Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);
}

long __lshrdi3(int Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long) RShiftU64 ((UINT64) Datum, (UINTN)Count);
}

long long __lshrti3(int Datum, int Count)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);
}

// Return the remainder of the signed division of Dividend and Divisor
// ===========================================================================
int __modsi3(int Dividend, int Divisor)
{
  INT64 Remainder;

  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
  DEBUG((DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder));

  return (int) Remainder;
}

INT64 __moddi3(INT64 Dividend, INT64 Divisor)
{
  INT64 Remainder;

  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
  DEBUG((DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));

  return Remainder;
}

long long __modti3(long long Dividend, long long Divisor)
{
  INT64 Remainder;

  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
  DEBUG((DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));

  return (long long) Remainder;
}

// These functions return the product of the Multiplicand and Multiplier.
// ===========================================================================
long long __multi3(long long Multiplicand, long long Multiplier)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);
}

// Return the quotient of the unsigned division of a and b.
// ===========================================================================
unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
}

unsigned long __udivdi3(unsigned long Dividend, unsigned long Divisor)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
}

unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)
{
  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
}

// ===========================================================================
unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)
{
  UINT64 Remainder;

  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);

  return (unsigned int) Remainder;
}

unsigned long __umoddi3(unsigned long Dividend, unsigned long Divisor)
{
  UINT64 Remainder;

  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);

  return (unsigned long) Remainder;
}

unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)
{
  UINT64 Remainder;

  DEBUG((DEBUG_INFO, "%a:\n", __func__));
  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);

  return (unsigned long long) Remainder;
}