Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Optimize Decimal.Remainder - #5926

Merged
jkotas merged 1 commit into
dotnet:masterfrom
pentp:VarDecMod
Jun 11, 2018
Merged

jkotas merged 1 commit into
dotnet:masterfrom
pentp:VarDecMod

Conversation

@pentp

@pentp pentp commented Jun 10, 2018

Copy link
Copy Markdown
Contributor

In addition to better performance this contributes to making decimal a readonly struct.
I'll add new tests to CoreFX also.
Contributes to https://github.com/dotnet/coreclr/issues/18249.

x64

Method Mean Error StdDev Scaled
Native 169.42 ns 0.3258 ns 0.1162 ns 1.00
CoreRT2 78.66 ns 0.0869 ns 0.0310 ns 0.46

x86

Method Mean Error StdDev Scaled
Native 128.0 ns 0.1594 ns 0.0568 ns 1.00
CoreRT2 120.4 ns 0.2057 ns 0.0734 ns 0.94

@jkotas I have a WIP readonly decimal branch, it doesn't compile yet because of VarDecMod and NumberBufferToDecimal, but can you check if I'm on the right track?

@jkotas

jkotas commented Jun 11, 2018

Copy link
Copy Markdown
Member

can you check if I'm on the right track?

It think so. In may be useful for clarify to use explicit in, like VarDecCmp(in this, in value)

d1.uflags = (d1.uflags & ~SignMask) | (d2.uflags & SignMask);
}
Decimal tmp = d2;
DecAddSub(ref d1, ref tmp, true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: DecAddSub trashing the second argument is non-intuitive ... it may be useful to add comment about it in front of DecAddSub at least.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in the readonly decimal, use ref for arguments that can be trashed; and in for arguments that stay intact?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add comments for parameter trashing and use in where possible (can't use in for mutable structs because property calls would require implicit local copies).

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas
jkotas merged commit dda21a9 into dotnet:master Jun 11, 2018
@pentp
pentp deleted the VarDecMod branch June 11, 2018 21:11
@pentp

pentp commented Jun 11, 2018

Copy link
Copy Markdown
Contributor Author

I added new tests that cover all Decimal.Remainder code paths now, but I might have been a bit too eager with fixing the NearNegativeZero/NearPositiveZero scale issue (https://github.com/dotnet/coreclr/issues/12605) because now CoreRT and CoreFX return different values, but the tests are shared.
Should I add back the scale bug for CoreRT or fix it in CoreCLR?

@jkotas

jkotas commented Jun 11, 2018

Copy link
Copy Markdown
Member

Is fixing it just about changing the scale from 27 to 28? I think it would be easier to fix it.

@pentp

pentp commented Jun 11, 2018

Copy link
Copy Markdown
Contributor Author

The fix is in dotnet/coreclr#18424 and I updated tests also (tests will fail until until CoreCLR update, NETFX is excluded).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants