-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Adding Int128 and UInt128 with a base software implementation #69204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
897fdb9
2fe1618
6559609
2c820b5
e7970fb
828440f
6904e73
bcbc375
09e8bfc
5f9d22f
b6b85e6
9de4e76
a1dc14f
7666952
f0a30cb
cb5a82e
384e572
ab85c7b
163cfda
cd3c9e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1072,4 +1072,30 @@ Copyright (c) Microsoft Corporation. | |
| Licensed under the MIT License. | ||
|
|
||
| Available at | ||
| https://github.com/microsoft/msquic/blob/main/LICENSE | ||
| https://github.com/microsoft/msquic/blob/main/LICENSE | ||
|
|
||
| License notice for m-ou-se/floatconv | ||
| ------------------------------- | ||
|
|
||
| Copyright (c) 2020 Mara Bos <[email protected]> | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
|
|
||
| 1. Redistributions of source code must retain the above copyright notice, this | ||
| list of conditions and the following disclaimer. | ||
| 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| this list of conditions and the following disclaimer in the documentation | ||
| and/or other materials provided with the distribution. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Internal.TypeSystem; | ||
|
|
||
| using Debug = System.Diagnostics.Debug; | ||
|
|
||
| namespace ILCompiler | ||
| { | ||
| /// <summary> | ||
| /// Represents an algorithm that computes field layout for intrinsic integer types (Int128/UInt128). | ||
| /// </summary> | ||
| public class Int128FieldLayoutAlgorithm : FieldLayoutAlgorithm | ||
| { | ||
| private readonly FieldLayoutAlgorithm _fallbackAlgorithm; | ||
|
|
||
| public Int128FieldLayoutAlgorithm(FieldLayoutAlgorithm fallbackAlgorithm) | ||
| { | ||
| _fallbackAlgorithm = fallbackAlgorithm; | ||
| } | ||
|
|
||
| public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defType, InstanceLayoutKind layoutKind) | ||
| { | ||
| Debug.Assert(IsIntegerType(defType)); | ||
|
|
||
| string name = defType.Name; | ||
| Debug.Assert((name == "Int128") || (name == "UInt128")); | ||
|
|
||
| ComputedInstanceFieldLayout layoutFromMetadata = _fallbackAlgorithm.ComputeInstanceLayout(defType, layoutKind); | ||
|
|
||
| if (defType.Context.Target.IsWindows || (defType.Context.Target.PointerSize == 4)) | ||
| { | ||
| return layoutFromMetadata; | ||
| } | ||
|
|
||
| // 64-bit Unix systems follow the System V ABI and have a 16-byte packing requirement for Int128/UInt128 | ||
|
|
||
| return new ComputedInstanceFieldLayout | ||
| { | ||
| ByteCountUnaligned = layoutFromMetadata.ByteCountUnaligned, | ||
| ByteCountAlignment = layoutFromMetadata.ByteCountAlignment, | ||
| FieldAlignment = new LayoutInt(16), | ||
| FieldSize = layoutFromMetadata.FieldSize, | ||
| Offsets = layoutFromMetadata.Offsets, | ||
| LayoutAbiStable = true | ||
| }; | ||
| } | ||
|
|
||
| public override ComputedStaticFieldLayout ComputeStaticFieldLayout(DefType defType, StaticLayoutKind layoutKind) | ||
| { | ||
| return _fallbackAlgorithm.ComputeStaticFieldLayout(defType, layoutKind); | ||
| } | ||
|
|
||
| public override bool ComputeContainsGCPointers(DefType type) | ||
| { | ||
| Debug.Assert(!_fallbackAlgorithm.ComputeContainsGCPointers(type)); | ||
| return false; | ||
| } | ||
|
|
||
| public override bool ComputeIsUnsafeValueType(DefType type) | ||
| { | ||
| Debug.Assert(!_fallbackAlgorithm.ComputeIsUnsafeValueType(type)); | ||
| return false; | ||
| } | ||
|
|
||
| public override ValueTypeShapeCharacteristics ComputeValueTypeShapeCharacteristics(DefType type) | ||
| { | ||
| Debug.Assert(_fallbackAlgorithm.ComputeValueTypeShapeCharacteristics(type) == ValueTypeShapeCharacteristics.None); | ||
| return ValueTypeShapeCharacteristics.None; | ||
| } | ||
|
|
||
| public static bool IsIntegerType(DefType type) | ||
| { | ||
| return type.IsIntrinsic | ||
| && type.Namespace == "System." | ||
| && ((type.Name == "Int128") || (type.Name == "UInt128")); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,6 +282,9 @@ DEFINE_FIELD(DELEGATE, METHOD_PTR_AUX, _methodPtrAux) | |
| DEFINE_METHOD(DELEGATE, CONSTRUCT_DELEGATE, DelegateConstruct, IM_Obj_IntPtr_RetVoid) | ||
| DEFINE_METHOD(DELEGATE, GET_INVOKE_METHOD, GetInvokeMethod, IM_RetIntPtr) | ||
|
|
||
| DEFINE_CLASS(INT128, System, Int128) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anywhere?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what defines
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right, I was getting two two things mixed up. Looks like this is missing handling in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be fixed. The only other usage of |
||
| DEFINE_CLASS(UINT128, System, UInt128) | ||
|
|
||
| DEFINE_CLASS(DYNAMICMETHOD, ReflectionEmit, DynamicMethod) | ||
|
|
||
| DEFINE_CLASS(DYNAMICRESOLVER, ReflectionEmit, DynamicResolver) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9844,7 +9844,7 @@ void MethodTableBuilder::CheckForSystemTypes() | |
|
|
||
| if (strcmp(nameSpace, g_IntrinsicsNS) == 0) | ||
| { | ||
| EEClassLayoutInfo * pLayout = pClass->GetLayoutInfo(); | ||
| EEClassLayoutInfo* pLayout = pClass->GetLayoutInfo(); | ||
|
|
||
| // The SIMD Hardware Intrinsic types correspond to fundamental data types in the underlying ABIs: | ||
| // * Vector64<T>: __m64 | ||
|
|
@@ -9854,7 +9854,6 @@ void MethodTableBuilder::CheckForSystemTypes() | |
| // These __m128 and __m256 types, among other requirements, are special in that they must always | ||
| // be aligned properly. | ||
|
|
||
|
|
||
| if (strcmp(name, g_Vector64Name) == 0) | ||
| { | ||
| // The System V ABI for i386 defaults to 8-byte alignment for __m64, except for parameter passing, | ||
|
|
@@ -9898,6 +9897,21 @@ void MethodTableBuilder::CheckForSystemTypes() | |
|
|
||
| return; | ||
| } | ||
| #if defined(UNIX_AMD64_ABI) || defined(TARGET_ARM64) | ||
| else if (strcmp(nameSpace, g_SystemNS) == 0) | ||
| { | ||
| EEClassLayoutInfo* pLayout = pClass->GetLayoutInfo(); | ||
|
|
||
| // These types correspond to fundamental data types in the underlying ABIs: | ||
| // * Int128: __int128 | ||
| // * UInt128: unsigned __int128 | ||
|
|
||
| if ((strcmp(name, g_Int128Name) == 0) || (strcmp(name, g_UInt128Name) == 0)) | ||
| { | ||
| pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 16; // sizeof(__int128) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs equivalent fix in crossgen/NativeAOT and in Mono
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanyang-mono could you point me to where I tried checking for where that's handled for the vector types, but couldn't find it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -- I fixed this up for crossgen/NativeAOT already and added corresponding P/Invoke tests to ensure the data is passed correctly to/from Native.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's handled in mono_class_layout_fields () in metadata/class-init.c.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't impact 32-bit platforms, only 64-bit platforms (and only 64-bit Unix at that).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vargaz, looks like its just blocked everywhere not just 32-bit platforms: https://github.com/dotnet/runtime/blob/main/src/mono/mono/metadata/class-init.c#L2058-L2065 It looks like Mono also isn't differentiating "alignment" from "packing" and so the layout of types that include the new This would explain why I couldn't find any logic touching
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it looks like this is not implemented right now in mono.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll log an issue to ensure this is tracked (I don't see an existing issue).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logged #69399 |
||
| } | ||
| } | ||
| #endif // UNIX_AMD64_ABI || TARGET_ARM64 | ||
| } | ||
|
|
||
| if (g_pNullableClass != NULL) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.