]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/CRT/Gcc.c
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..
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.
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.
17 #include <Library/DebugLib.h>
18 #include <sys/EfiCdefs.h>
20 #include <Library/BaseLib.h>
22 // Shift Datum left by Count bits.
23 // ===========================================================================
24 int __ashlsi3(int Datum
, int Count
)
26 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
27 return (int) LShiftU64 ((UINT64
)Datum
, (UINTN
)Count
);
30 long __ashldi3(long Datum
, int Count
)
32 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
33 return (long) LShiftU64 ((UINT64
)Datum
, (UINTN
)Count
);
36 long long __ashlti3(long long Datum
, int Count
)
38 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
39 return (long long) LShiftU64 ((UINT64
)Datum
, (UINTN
)Count
);
42 // Arithmetically shift Datum right by Count bits.
43 // ===========================================================================
44 int __ashrsi3(int Datum
, int Count
)
46 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
47 return (int) ARShiftU64 ((UINT64
) Datum
, (UINTN
)Count
);
50 long __ashrdi3(long Datum
, int Count
)
52 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
53 return (long) ARShiftU64 ((UINT64
) Datum
, (UINTN
)Count
);
56 long long __ashrti3(long long Datum
, int Count
)
58 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
59 return (long long) ARShiftU64 ((UINT64
) Datum
, (UINTN
)Count
);
62 // Return the quotient of the signed division of Dividend and Divisor
63 // ===========================================================================
64 int __divsi3(int Dividend
, int Divisor
)
66 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
67 return (int) DivS64x64Remainder ((INT64
) Dividend
, (INT64
) Divisor
, NULL
);
70 INT64
__divdi3(INT64 Dividend
, INT64 Divisor
)
74 Quotient
= DivS64x64Remainder ((INT64
) Dividend
, (INT64
) Divisor
, NULL
);
75 DEBUG((DEBUG_INFO
, "%a: %Ld / %Ld = %Ld\n", __func__
, Dividend
, Divisor
, Quotient
));
80 long long __divti3(long long Dividend
, long long Divisor
)
82 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
83 return (long long) DivS64x64Remainder ((INT64
) Dividend
, (INT64
) Divisor
, NULL
);
86 // Logically shift Datum right by Count bits
87 // ===========================================================================
88 int __lshrsi3(int Datum
, int Count
)
90 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
91 return (int) RShiftU64 ((UINT64
) Datum
, (UINTN
)Count
);
94 long __lshrdi3(int Datum
, int Count
)
96 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
97 return (long) RShiftU64 ((UINT64
) Datum
, (UINTN
)Count
);
100 long long __lshrti3(int Datum
, int Count
)
102 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
103 return (long long) RShiftU64 ((UINT64
) Datum
, (UINTN
)Count
);
106 // Return the remainder of the signed division of Dividend and Divisor
107 // ===========================================================================
108 int __modsi3(int Dividend
, int Divisor
)
112 (void) DivS64x64Remainder ((INT64
) Dividend
, (INT64
) Divisor
, &Remainder
);
113 DEBUG((DEBUG_INFO
, "modsi3: %d %% %d = %d\n", Dividend
, Divisor
, (int)Remainder
));
115 return (int) Remainder
;
118 INT64
__moddi3(INT64 Dividend
, INT64 Divisor
)
122 (void) DivS64x64Remainder ((INT64
) Dividend
, (INT64
) Divisor
, &Remainder
);
123 DEBUG((DEBUG_INFO
, "moddi3: %Ld %% %Ld = %Ld\n", (INT64
)Dividend
, (INT64
)Divisor
, Remainder
));
128 long long __modti3(long long Dividend
, long long Divisor
)
132 (void) DivS64x64Remainder ((INT64
) Dividend
, (INT64
) Divisor
, &Remainder
);
133 DEBUG((DEBUG_INFO
, "modti3: %Ld %% %Ld = %Ld\n", (INT64
)Dividend
, (INT64
)Divisor
, Remainder
));
135 return (long long) Remainder
;
138 // These functions return the product of the Multiplicand and Multiplier.
139 // ===========================================================================
140 long long __multi3(long long Multiplicand
, long long Multiplier
)
142 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
143 return (long long) MultS64x64 ((INT64
)Multiplicand
, (INT64
)Multiplier
);
146 // Return the quotient of the unsigned division of a and b.
147 // ===========================================================================
148 unsigned int __udivsi3(unsigned int Dividend
, unsigned int Divisor
)
150 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
151 return (int) DivU64x64Remainder ((UINT64
) Dividend
, (UINT64
) Divisor
, NULL
);
154 unsigned long __udivdi3(unsigned long Dividend
, unsigned long Divisor
)
156 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
157 return (long) DivU64x64Remainder ((UINT64
) Dividend
, (UINT64
) Divisor
, NULL
);
160 unsigned long long __udivti3(unsigned long long Dividend
, unsigned long long Divisor
)
162 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
163 return (long long) DivU64x64Remainder ((UINT64
) Dividend
, (UINT64
) Divisor
, NULL
);
166 // ===========================================================================
167 unsigned int __umodsi3(unsigned int Dividend
, unsigned int Divisor
)
171 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
172 (void) DivU64x64Remainder ((UINT64
) Dividend
, (UINT64
) Divisor
, &Remainder
);
174 return (unsigned int) Remainder
;
177 unsigned long __umoddi3(unsigned long Dividend
, unsigned long Divisor
)
181 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
182 (void) DivU64x64Remainder ((UINT64
) Dividend
, (UINT64
) Divisor
, &Remainder
);
184 return (unsigned long) Remainder
;
187 unsigned long long __umodti3(unsigned long long Dividend
, unsigned long long Divisor
)
191 DEBUG((DEBUG_INFO
, "%a:\n", __func__
));
192 (void) DivU64x64Remainder ((UINT64
) Dividend
, (UINT64
) Divisor
, &Remainder
);
194 return (unsigned long long) Remainder
;