Commit Graph
2284 Commits
Author SHA1 Message Date
Sergio Pedri bf18a2c1b0 Fixed T4 linked files in .csproj file 2021-02-03 22:47:12 +01:00
Sergio Pedri 92131a4cbf Added missing references to test projects 2021-02-03 12:05:29 +01:00
Sergio Pedri 80dd1f927f Fixed .csproj files for base and Diagnostics packages 2021-02-03 02:17:31 +01:00
Sergio Pedri 9ae8782847 Split Microsoft.Toolkit.Diagnostics package 2021-02-02 23:00:41 +01:00
Kyaa Dost 641292b74f Merge pull request #2 from windows-toolkit/master
UPDATE
2021-02-02 10:58:25 -08:00
Ratish Philip 60ae79b4bc Merge branch 'master' into feature/win2dparser 2021-01-28 11:01:28 -08:00
msftbot[bot] cafb0a5054 Guard overloads for nint/nuint, codegen improvements (#3573)
## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->

<!-- - Bugfix -->
- Feature
- Optimization
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
There are no `nint`/`nuint` overloads for the any `Guard` APIs. These types have been introduced with C# 9, so it makes sense to add proper support for them given that #3356 added full support for C# 9 and .NET 5 to these packages.
Also there were some codegen bits in `Guard.IsCloseTo` that were not ideal.
Additionally, the codegen for the `Guard` APIs didn't leverage compiler support properly.

## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
✅ Added new `nint`/`nuint` overloads to `Guard` APIs
🚀 Improved codegen in a number of `Guard.IsCloseTo` overloads
🚀 Improved codegen for faulting blocks

## PR Checklist

Please check if your PR fulfills the following requirements:

- [X] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [ ] Sample in sample app has been added / updated (for bug fixes / features)
    - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [X] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [X] Contains **NO** breaking changes
2021-01-28 18:17:57 +00:00
Michael Hawker MSFT (XAML Llama) f0e5805112 Merge branch 'master' into feature/nint-guard-apis 2021-01-28 08:39:59 -08:00
Ratish Philip 2b36530c10 Merge branch 'master' into feature/win2dparser 2021-01-21 18:27:23 -08:00
msftbot[bot] d210795043 Add lazy loading threshold for ImageEx control (#3483)
## Fixes
<!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. -->
Add lazy loading threshold for ```ImageEx``` control and change the lazy loading implement that will be also fixed #3258 .

<!-- Add a brief overview here of the feature/bug & fix. -->

## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->

 - Bugfix 
 - Feature 
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
If enable lazy loading, only the ImageEx entered the viewport, the source will start to load.

## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
Give a threshold for triggering the lazy loading behavior, the default value is 300 px.

## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [x] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: https://github.com/MicrosoftDocs/WindowsCommunityToolkitDocs/pull/387<!-- docs PR link -->
- [x] Sample in sample app has been added / updated (for bug fixes / features)
    - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [x] Contains **NO** breaking changes

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. 
     Please note that breaking changes are likely to be rejected. -->


## Other information
2021-01-21 22:57:59 +00:00
Ratish Philip 5686b3a37f Removed ThrowHelper.ThrowNullReferenceException which I had added.
Using ThrowHelper.ThrowArgumentNullException instead.
2021-01-17 17:35:51 -08:00
Ratish Philip 503f22b579 Merge branch 'master' into feature/win2dparser 2021-01-17 11:14:55 -08:00
Ratish Philip bdf52bdfd2 Implemented changes based on Sergio's review comments. 2021-01-17 11:13:51 -08:00
Michael Hawker MSFT (XAML Llama) 4d68cf8f1e Merge branch 'master' into lazyLoadingThreshold 2021-01-14 13:51:44 -08:00
msftbot[bot] eeaddbbf8d Loop codegen improvements (#3632)
## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->

- Optimization
<!-- - Bugfix -->
<!-- - Feature -->
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
Some `for` loops have unoptimal codegen involving the indexing at each iteration.

For instance, as a very simple test, this method simply sets all items in an input `Span<int>` to `0`:

```csharp
public static void M1(Span<int> span)
{
    ref int r0 = ref MemoryMarshal.GetReference(span);
    int length = span.Length;

    for (int i = 0; i < length; i++)
    {
        Unsafe.Add(ref r0, i) = 0;
    }
}
```
```asm
C.M1(System.Span`1<Int32>)
    L0000: mov rax, [rcx]
    L0003: mov edx, [rcx+8]
    L0006: xor ecx, ecx
    L0008: test edx, edx
    L000a: jle short L001c
    L000c: movsxd r8, ecx
    L000f: xor r9d, r9d
    L0012: mov [rax+r8*4], r9d
    L0016: inc ecx
    L0018: cmp ecx, edx
    L001a: jl short L000c
    L001c: ret
```

Here the loop starts at `L000c`, and at every iteration it takes the loop counter, extends it to native int, then uses it to index from the initial reference (that `[rax+r8*4]` offset calculation), and then writes to it. This is unnecessary logic, in cases such as this.

## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
Refactored some loops to operate within a target address range, with all indexing out of the loop body.

```csharp
public static void M2(Span<int> span)
{
    ref int r0 = ref MemoryMarshal.GetReference(span);
    ref int r1 = ref Unsafe.Add(ref r0, span.Length);

    while (Unsafe.IsAddressLessThan(ref r0, ref r1))
    {
        r0 = 0;

        r0 = ref Unsafe.Add(ref r0, 1);
    }
}
```
```asm
C.M2(System.Span`1<Int32>)
    L0000: mov rax, [rcx]
    L0003: mov edx, [rcx+8]
    L0006: movsxd rdx, edx
    L0009: lea rdx, [rax+rdx*4]
    L000d: cmp rax, rdx
    L0010: jae short L001f
    L0012: xor ecx, ecx
    L0014: mov [rax], ecx
    L0016: add rax, 4
    L001a: cmp rax, rdx
    L001d: jb short L0012
    L001f: ret
```

Here instead we pre-calculate the target address just once, outside the loop, and then just iterate until the initial, moving reference reaches that point. This allows the actual loop to be more compact and with no indexing logic needed. We just read directly from the moving reference, and then increment it by a fixed amount at the end of each iteration. Not groundbreaking, but better 🚀

## PR Checklist

Please check if your PR fulfills the following requirements:

- [X] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] ~~Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->~~
- [ ] ~~Sample in sample app has been added / updated (for bug fixes / features)~~
    - [ ] ~~Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)~~
- [X] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [X] Contains **NO** breaking changes
2021-01-13 22:50:25 +00:00
Ratish Philip 7495dba54d Merge branch 'master' into feature/win2dparser 2020-12-16 11:22:25 -08:00
Ratish Philip 49eaecde7b Merge branch 'feature/win2dparser' of https://github.com/ratishphilip/WindowsCommunityToolkit into feature/win2dparser 2020-12-16 11:00:50 -08:00
Ratish Philip f09557dd17 Added unit test cases for Geometry Helpers. 2020-12-16 11:00:18 -08:00
Sergio Pedri ab99ffc93f Codegen tweaks in [ReadOnly]Span2D<T> types 2020-12-16 00:31:45 +01:00
Sergio Pedri 8607971c47 Codegen tweaks to ParallelHelper 2020-12-16 00:31:30 +01:00
Sergio Pedri 87d0b45f51 Revert "Minor code tweaks" to fix .NET Native error
This reverts commit f286447fe3 to work around a .NET Native compiler bug causing a crash. See more details in https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3573#issuecomment-742131056.
2020-12-10 01:24:07 +01:00
Sergio Pedri 2665e8e9d3 Decoupled Guard helpers from ThrowHelper class 2020-12-09 23:54:42 +01:00
Sergio Pedri 9bec8362bb Minor code refactoring for new class structure 2020-12-09 23:54:41 +01:00
Sergio Pedri 39e338632e Renamed files to match new class structure 2020-12-09 23:54:41 +01:00
Sergio Pedri 1b52768de7 Improved Guard APIs codegen 2020-12-09 23:54:41 +01:00
Sergio Pedri df28b20038 Added Guard.IsCloseTo overloads for nint type 2020-12-09 23:54:41 +01:00
Sergio Pedri b84e9b7d97 Codegen improvements to Guard.IsCloseTo 2020-12-09 23:54:41 +01:00
Sergio Pedri e88a7f5c0b Improved IsCloseTo unit tests 2020-12-09 23:54:41 +01:00
Sergio Pedri 22f842faed Refactored Guard.IsCloseTo unit tests 2020-12-09 23:54:41 +01:00
Sergio Pedri d43b63c95e Added nint/nuint comparable Guard overloads 2020-12-09 23:54:41 +01:00
Sergio Pedri f286447fe3 Minor code tweaks 2020-12-09 23:54:41 +01:00
msftbot[bot] 0bb94f5a7f Improved RuntimeHelpers.ConvertLength codegen (#3608)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 -->

<!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork.  This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 -->


## Follow up from #3520 
<!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. -->

<!-- Add a brief overview here of the feature/bug & fix. -->

## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->

- Optimization
<!-- - Bugfix -->
<!-- - Feature -->
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
The codegen for the second branch in `RuntimeHelpers.ConvertLength` does a signed division:

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/9b75c9f910f999834c64bd00e522d7ae464c121b/Microsoft.Toolkit.HighPerformance/Helpers/Internals/RuntimeHelpers.cs#L43-L46

This is not the best for the codegen, as the JIT has to handle the sign in that division, resulting in the following:

```asm
; [System.Byte, System.Private.CoreLib],[System.Numerics.Vector4, System.Numerics.Vectors]
ConvertLength[TFrom, TTo](Int32)
    L0000: mov eax, ecx
    L0002: sar eax, 0x1f
    L0005: and eax, 0xf
    L0008: add eax, ecx
    L000a: sar eax, 4
    L000d: ret
```

## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
Avoided that with a cast to `uint`, since the length is guaranteed to be a positive value in `[0, int.MaxValue]` anyway:

```asm
; [System.Byte, System.Private.CoreLib],[System.Numerics.Vector4, System.Numerics.Vectors]
    L0000: mov eax, ecx
    L0002: shr eax, 4
    L0005: ret
```

Perfect! 😄🎉

## PR Checklist

Please check if your PR fulfills the following requirements:

- [X] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] ~~Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->~~
- [ ] ~~Sample in sample app has been added / updated (for bug fixes / features)~~
    - [ ] ~~Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)~~
- [X] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [X] Contains **NO** breaking changes
2020-12-08 16:28:04 +00:00
Sergio Pedri 210fababa4 Improved RuntimeHelpers.ConvertLength codegen 2020-12-06 01:20:59 +01:00
msftbot[bot] 91157c65cd .NET 5 target for Toolkit and HighPerformance packages (#3356)
## Adds the .NET 5 target to `Microsoft.Toolkit.HighPerformance`

## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->

<!-- - Bugfix -->
 - Feature
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
The `Microsoft.Toolkit.HighPerformance` package maxes out at .NET Core 3.1.
The `Microsoft.Toolkit` package maxes out at .NET Standard 2.1.

Additionally, `Microsoft.Toolkit` doesn't have proper nullability annotations, and it reports installing additional dependencies if installed in a .NET 5 apps. The extra dependency is `System.Runtime.CompilerServices.Unsafe` which is actually built-in on .NET 5, but consumers not aware of this would still see the installation prompt from NuGet as reporting an extra indirect dependency.

## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
✅ Added .NET 5 target to `Microsoft.Toolkit.HighPerformance`
✅ Added .NET 5 target to `Microsoft.Toolkit`
✅ Enabled global nullability annotations to `Microsoft.Toolkit` and improved the codebase.
✅ Enabled C# 9 in both projects, with some extra code tweaks.

## PR Checklist

Please check if your PR fulfills the following requirements:

- [X] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [ ] Sample in sample app has been added / updated (for bug fixes / features)
    - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [X] Contains **NO** breaking changes

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. 
     Please note that breaking changes are likely to be rejected. -->
2020-11-24 22:34:04 +00:00
Sergio Pedri ec071adbf0 Fixed a small bug, minor code tweaks 2020-11-23 12:32:13 +01:00
Sergio Pedri 01aa6f0dfe Removed nullability warning suppressions 2020-11-23 00:30:15 +01:00
Sergio Pedri 88ae057bae Code refactoring, improved nullability annotations 2020-11-23 00:28:39 +01:00
Sergio Pedri b8c73457a2 Minor code style tweaks 2020-11-23 00:17:46 +01:00
Sergio Pedri 31f5906a76 Removed unnecessary nullability attribute 2020-11-23 00:16:02 +01:00
Sergio Pedri d27bb82af1 Removed unused attribute 2020-11-23 00:10:45 +01:00
Sergio Pedri 574dfb4dfb Fixed nullability annotations in Microsoft.Toolkit 2020-11-23 00:08:31 +01:00
Sergio Pedri e7012b9ce4 Minor code style tweaks 2020-11-22 18:15:26 +01:00
Sergio Pedri ae783a1df9 Minor code tweak to ToHexString 2020-11-22 18:13:11 +01:00
Sergio Pedri 31a63b53fc Added .NET 5 target to Microsoft.Toolkit package 2020-11-22 18:00:22 +01:00
Sergio Pedri 3990071643 Aligned ThrowHelper nullability annotations to .NET 5 2020-11-22 17:13:39 +01:00
Sergio Pedri 2d961728e1 Enabled missing fast code paths on .NET 5 2020-11-21 02:33:13 +01:00
Sergio Pedri 3635ed2899 Minor code quality improvements 2020-11-21 02:13:01 +01:00
Sergio Pedri 9e495214bb Minor code style tweaks 2020-11-21 02:02:45 +01:00
Sergio Pedri fd2ed709fb Suppressed compiler warnings 2020-11-21 02:00:22 +01:00
h82258652 886a0278b3 Merge branch 'master' into lazyLoadingThreshold 2020-11-21 08:50:28 +08:00