Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bflat/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ public override int Handle(ParseResult result)
}

string libc = result.GetValueForOption(TargetLibcOption);
if (targetOS == TargetOS.Windows && targetArchitecture == TargetArchitecture.X86)
libc ??= "none"; // don't have shcrt for Windows x86 because that one's hacked up

string homePath = CommonOptions.HomePath;
string libPath = Environment.GetEnvironmentVariable("BFLAT_LIB");
Expand Down Expand Up @@ -896,7 +894,7 @@ public override int Handle(ParseResult result)
ldArgs.Append("api-ms-win-crt-string-l1-1-0.lib api-ms-win-crt-time-l1-1-0.lib api-ms-win-crt-utility-l1-1-0.lib ");
}
}
ldArgs.Append("/opt:ref,icf /nodefaultlib:libcpmt.lib /nodefaultlib:libcmt.lib /nodefaultlib:oldnames.lib ");
ldArgs.Append("/opt:ref,icf /nodefaultlib:libcpmt.lib /nodefaultlib:libcmt.lib /nodefaultlib:oldnames.lib /nodefaultlib:uuid.lib ");
}
else if (targetOS == TargetOS.Linux)
{
Expand Down
4 changes: 2 additions & 2 deletions src/bflat/bflat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
</PropertyGroup>

<PropertyGroup>
<RuntimeVersion>10.0.0-rc.1.25451.2</RuntimeVersion>
<RuntimeVersion>10.0.0-rc.1.25527.1</RuntimeVersion>
<RuntimeUri>https://github.com/bflattened/runtime/releases/download/</RuntimeUri>

<BlobsVersion>1.3</BlobsVersion>
<BlobsUri>https://github.com/bflattened/blobs/releases/download/</BlobsUri>

<MicrosoftCodeAnalysisCSharpVersion>4.8.0-3.final</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisCSharpVersion>5.0.0-2.final</MicrosoftCodeAnalysisCSharpVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
197 changes: 197 additions & 0 deletions src/zerolib/System/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System.Runtime;
using System.Runtime.CompilerServices;

namespace System
Expand Down Expand Up @@ -43,5 +44,201 @@ internal static ulong ConvertToUInt64Checked(double value)
Environment.FailFast(null);
return 0;
}

internal static int DivInt32(int dividend, int divisor)
{
if ((uint)(divisor + 1) <= 1)
{
if (divisor == 0)
{
Environment.FailFast(null);
return 0;
}
else if (divisor == -1)
{
if (dividend == int.MinValue)
{
Environment.FailFast(null);
return 0;
}
return -dividend;
}
}

return DivInt32Internal(dividend, divisor);
}

internal static uint DivUInt32(uint dividend, uint divisor)
{
if (divisor == 0)
{
Environment.FailFast(null);
return 0;
}

return DivUInt32Internal(dividend, divisor);
}

internal static long DivInt64(long dividend, long divisor)
{
if ((int)((ulong)divisor >> 32) == (int)(((ulong)(int)divisor) >> 32))
{
if ((int)divisor == 0)
{
Environment.FailFast(null);
return 0;
}

if ((int)divisor == -1)
{
if (dividend == long.MinValue)
{
Environment.FailFast(null);
return 0;
}
return -dividend;
}

if ((int)((ulong)dividend >> 32) == (int)(((ulong)(int)dividend) >> 32))
{
return DivInt32Internal((int)dividend, (int)divisor);
}
}

return DivInt64Internal(dividend, divisor);
}

internal static ulong DivUInt64(ulong dividend, ulong divisor)
{
if ((int)(divisor >> 32) == 0)
{
if ((uint)divisor == 0)
{
Environment.FailFast(null);
return 0;
}

if ((int)(dividend >> 32) == 0)
{
return DivUInt32Internal((uint)dividend, (uint)divisor);
}
}

return DivUInt64Internal(dividend, divisor);
}

internal static int ModInt32(int dividend, int divisor)
{
if ((uint)(divisor + 1) <= 1)
{
if (divisor == 0)
{
Environment.FailFast(null);
return 0;
}
else if (divisor == -1)
{
if (dividend == int.MinValue)
{
Environment.FailFast(null);
return 0;
}
return 0;
}
}

return ModInt32Internal(dividend, divisor);
}

internal static uint ModUInt32(uint dividend, uint divisor)
{
if (divisor == 0)
{
Environment.FailFast(null);
return 0;
}

return ModUInt32Internal(dividend, divisor);
}

internal static long ModInt64(long dividend, long divisor)
{
if ((int)((ulong)divisor >> 32) == (int)(((ulong)(int)divisor) >> 32))
{
if ((int)divisor == 0)
{
Environment.FailFast(null);
return 0;
}

if ((int)divisor == -1)
{
if (dividend == long.MinValue)
{
Environment.FailFast(null);
return 0;
}
return 0;
}

if ((int)((ulong)dividend >> 32) == (int)(((ulong)(int)dividend) >> 32))
{
return ModInt32Internal((int)dividend, (int)divisor);
}
}

return ModInt64Internal(dividend, divisor);
}

internal static ulong ModUInt64(ulong dividend, ulong divisor)
{
if ((int)(divisor >> 32) == 0)
{
if ((uint)divisor == 0)
{
Environment.FailFast(null);
return 0;
}

if ((int)(dividend >> 32) == 0)
{
return ModUInt32Internal((uint)dividend, (uint)divisor);
}
}

return ModUInt64Internal(dividend, divisor);
}

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "DivInt32Internal")]
private static extern int DivInt32Internal(int dividend, int divisor);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "DivUInt32Internal")]
private static extern uint DivUInt32Internal(uint dividend, uint divisor);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "DivInt64Internal")]
private static extern long DivInt64Internal(long dividend, long divisor);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "DivUInt64Internal")]
private static extern ulong DivUInt64Internal(ulong dividend, ulong divisor);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "ModInt32Internal")]
private static extern int ModInt32Internal(int dividend, int divisor);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "ModUInt32Internal")]
private static extern uint ModUInt32Internal(uint dividend, uint divisor);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "ModInt64Internal")]
private static extern long ModInt64Internal(long dividend, long divisor);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport("*", "ModUInt64Internal")]
private static extern ulong ModUInt64Internal(ulong dividend, ulong divisor);
}
}
12 changes: 10 additions & 2 deletions src/zerolib/System/Primitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ public struct SByte { }
public struct Byte { }
public struct Int16 { }
public struct UInt16 { }
public struct Int32 { }
public struct Int32
{
public const int MaxValue = 0x7fffffff;
public const int MinValue = unchecked((int)0x80000000);
}
public struct UInt32 { }
public struct Int64 { }
public struct Int64
{
public const long MaxValue = 0x7fffffffffffffffL;
public const long MinValue = unchecked((long)0x8000000000000000L);
}
public struct UInt64 { }
public struct IntPtr { }
public struct UIntPtr { }
Expand Down