• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Integer Arithmetic Run-time support functions for GCC.
3   The integer arithmetic routines are used on platforms that don't provide
4   hardware support for arithmetic operations on some modes..
5 
6   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
7   This program and the accompanying materials are licensed and made available
8   under the terms and conditions of the BSD License which accompanies this
9   distribution.  The full text of the license may be found at
10   http://opensource.org/licenses/bsd-license.
11 
12   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 #include <Uefi.h>
17 #include <Library/DebugLib.h>
18 #include <sys/EfiCdefs.h>
19 
20 #include <Library/BaseLib.h>
21 
22 // Shift Datum left by Count bits.
23 // ===========================================================================
__ashlsi3(int Datum,int Count)24 int __ashlsi3(int Datum, int Count)
25 {
26   DEBUG((DEBUG_INFO, "%a:\n", __func__));
27   return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);
28 }
29 
__ashldi3(long Datum,int Count)30 long __ashldi3(long Datum, int Count)
31 {
32   DEBUG((DEBUG_INFO, "%a:\n", __func__));
33   return (long) LShiftU64 ((UINT64)Datum, (UINTN)Count);
34 }
35 
__ashlti3(long long Datum,int Count)36 long long __ashlti3(long long Datum, int Count)
37 {
38   DEBUG((DEBUG_INFO, "%a:\n", __func__));
39   return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);
40 }
41 
42 // Arithmetically shift Datum right by Count bits.
43 // ===========================================================================
__ashrsi3(int Datum,int Count)44 int __ashrsi3(int Datum, int Count)
45 {
46   DEBUG((DEBUG_INFO, "%a:\n", __func__));
47   return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
48 }
49 
__ashrdi3(long Datum,int Count)50 long __ashrdi3(long Datum, int Count)
51 {
52   DEBUG((DEBUG_INFO, "%a:\n", __func__));
53   return (long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
54 }
55 
__ashrti3(long long Datum,int Count)56 long long __ashrti3(long long Datum, int Count)
57 {
58   DEBUG((DEBUG_INFO, "%a:\n", __func__));
59   return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
60 }
61 
62 // Return the quotient of the signed division of Dividend and Divisor
63 // ===========================================================================
__divsi3(int Dividend,int Divisor)64 int __divsi3(int Dividend, int Divisor)
65 {
66   DEBUG((DEBUG_INFO, "%a:\n", __func__));
67   return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
68 }
69 
__divdi3(INT64 Dividend,INT64 Divisor)70 INT64 __divdi3(INT64 Dividend, INT64 Divisor)
71 {
72   INT64 Quotient;
73 
74   Quotient = DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
75   DEBUG((DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient));
76 
77   return Quotient;
78 }
79 
__divti3(long long Dividend,long long Divisor)80 long long __divti3(long long Dividend, long long Divisor)
81 {
82   DEBUG((DEBUG_INFO, "%a:\n", __func__));
83   return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
84 }
85 
86 // Logically shift Datum right by Count bits
87 // ===========================================================================
__lshrsi3(int Datum,int Count)88 int __lshrsi3(int Datum, int Count)
89 {
90   DEBUG((DEBUG_INFO, "%a:\n", __func__));
91   return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);
92 }
93 
__lshrdi3(int Datum,int Count)94 long __lshrdi3(int Datum, int Count)
95 {
96   DEBUG((DEBUG_INFO, "%a:\n", __func__));
97   return (long) RShiftU64 ((UINT64) Datum, (UINTN)Count);
98 }
99 
__lshrti3(int Datum,int Count)100 long long __lshrti3(int Datum, int Count)
101 {
102   DEBUG((DEBUG_INFO, "%a:\n", __func__));
103   return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);
104 }
105 
106 // Return the remainder of the signed division of Dividend and Divisor
107 // ===========================================================================
__modsi3(int Dividend,int Divisor)108 int __modsi3(int Dividend, int Divisor)
109 {
110   INT64 Remainder;
111 
112   (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
113   DEBUG((DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder));
114 
115   return (int) Remainder;
116 }
117 
__moddi3(INT64 Dividend,INT64 Divisor)118 INT64 __moddi3(INT64 Dividend, INT64 Divisor)
119 {
120   INT64 Remainder;
121 
122   (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
123   DEBUG((DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));
124 
125   return Remainder;
126 }
127 
__modti3(long long Dividend,long long Divisor)128 long long __modti3(long long Dividend, long long Divisor)
129 {
130   INT64 Remainder;
131 
132   (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
133   DEBUG((DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));
134 
135   return (long long) Remainder;
136 }
137 
138 // These functions return the product of the Multiplicand and Multiplier.
139 // ===========================================================================
__multi3(long long Multiplicand,long long Multiplier)140 long long __multi3(long long Multiplicand, long long Multiplier)
141 {
142   DEBUG((DEBUG_INFO, "%a:\n", __func__));
143   return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);
144 }
145 
146 // Return the quotient of the unsigned division of a and b.
147 // ===========================================================================
__udivsi3(unsigned int Dividend,unsigned int Divisor)148 unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)
149 {
150   DEBUG((DEBUG_INFO, "%a:\n", __func__));
151   return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
152 }
153 
__udivdi3(unsigned long Dividend,unsigned long Divisor)154 unsigned long __udivdi3(unsigned long Dividend, unsigned long Divisor)
155 {
156   DEBUG((DEBUG_INFO, "%a:\n", __func__));
157   return (long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
158 }
159 
__udivti3(unsigned long long Dividend,unsigned long long Divisor)160 unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)
161 {
162   DEBUG((DEBUG_INFO, "%a:\n", __func__));
163   return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
164 }
165 
166 // ===========================================================================
__umodsi3(unsigned int Dividend,unsigned int Divisor)167 unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)
168 {
169   UINT64 Remainder;
170 
171   DEBUG((DEBUG_INFO, "%a:\n", __func__));
172   (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
173 
174   return (unsigned int) Remainder;
175 }
176 
__umoddi3(unsigned long Dividend,unsigned long Divisor)177 unsigned long __umoddi3(unsigned long Dividend, unsigned long Divisor)
178 {
179   UINT64 Remainder;
180 
181   DEBUG((DEBUG_INFO, "%a:\n", __func__));
182   (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
183 
184   return (unsigned long) Remainder;
185 }
186 
__umodti3(unsigned long long Dividend,unsigned long long Divisor)187 unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)
188 {
189   UINT64 Remainder;
190 
191   DEBUG((DEBUG_INFO, "%a:\n", __func__));
192   (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
193 
194   return (unsigned long long) Remainder;
195 }
196