Skip to content
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

fix issue 14767 - Support CTFE of BigInt under x86 #6029

Merged
merged 5 commits into from Jan 24, 2018
Merged

fix issue 14767 - Support CTFE of BigInt under x86 #6029

merged 5 commits into from Jan 24, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jan 14, 2018

This allows to declare very big BigInt constants but has the same limitation as x86_64 BigInt CTFE.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @bbasile! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Auto-close Bugzilla Description
14767 Support CTFE of BigInt under x86

Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Nice trick! Remove pure from the templates and we should be good to go.

@@ -52,6 +52,130 @@ import std.range.primitives;
import std.traits;

private:

// compile-time & run-time dipatchers to allows BigInt CTFE for 32 bit OS.
Copy link
Member

Choose a reason for hiding this comment

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

/for 32bit OS/d - it should work for all OS at CTFE?

Copy link
Author

Choose a reason for hiding this comment

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

No but now it will likely be the case. Even if CTFE isn't a requirement i think that it's a problem when it works for an arch and not the other

}
static import std.internal.math.biguintnoasm;
Copy link
Member

Choose a reason for hiding this comment

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

This now will lead to a bigger object size on x86 as this file will always be imported, but dmd isn't smart enough to lazy load local imports anyways. Besides if (__ctfe) isn't even static if, so imports within will always be loaded.

Copy link
Author

@ghost ghost Jan 15, 2018

Choose a reason for hiding this comment

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

Yeah i guess this is the counterpart of the trick used to avoid symbol conflicts.

Copy link
Member

Choose a reason for hiding this comment

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

I was trying to think of various ways to work around this, but could not.

I wonder if there's a way to introduce a CTFE-only template, basically one that is not instantiated even if it's referred to, until the CTFE engine tries to execute it.

pragma(inline, true)
uint multibyteAddSub(char op)(uint[] dest, const(uint)[] src1, const (uint)[] src2, uint carry) pure
{
if (__ctfe)
Copy link
Member

Choose a reason for hiding this comment

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

Does are the times where CTFE + static if would be really cool:

static if(__ctfe || isNotX86)

Copy link
Author

Choose a reason for hiding this comment

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

Yes. I remember that Stefan said that it could be possible, so it may be true in the future.

// compile-time & run-time dipatchers to allows BigInt CTFE for 32 bit OS.

pragma(inline, true)
uint multibyteAddSub(char op)(uint[] dest, const(uint)[] src1, const (uint)[] src2, uint carry) pure
Copy link
Member

Choose a reason for hiding this comment

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

Why did you specify the attributes manually? It's a template and DMD should infer the attributes automatically.
The best practice is to avoid specifying the attributes manually, because then future improvements will propagate.

@ghost ghost closed this Jan 15, 2018
@ghost ghost reopened this Jan 15, 2018
@ghost ghost closed this Jan 15, 2018
@ghost ghost reopened this Jan 15, 2018
@ghost
Copy link
Author

ghost commented Jan 15, 2018

I authorized CircleCi for my own stuff again (revoked last week because i didn't use them) and after reopening the status is reported. They have a bug at CircleCi, it seems that they don't make the difference between people own stuff and their PRs in foreign repo.

@wilzbach
Copy link
Member

It seems that the autotester, for some reason, stops after FreeBSD32 test.

Not for some reason. There are a couple of PRs with "auto-merge" in the queue. They receive a higher priority:
https://auto-tester.puremagic.com/pulls.ghtml?projectid=1

Windows + MacOS build hosts are typically quite busy:
https://auto-tester.puremagic.com/hosts/

In addition this PR has never been reported to CircleCI (same problem with other PRs of mine last week)

I still don't know why that's just happening with your account, but it seems like it works now.

@ghost
Copy link
Author

ghost commented Jan 15, 2018

It works now because see my other comment., we've posted more or less at the same time.

@ghost
Copy link
Author

ghost commented Jan 15, 2018

@wilzbach, can you accept as you stated before that if i

Remove pure from the templates and we should be good to go.

The pragma for inline guarantee that there's no performance regressions and they don't fail locally.

@@ -52,6 +52,130 @@ import std.range.primitives;
import std.traits;

private:

// compile-time & run-time dipatchers to allows BigInt CTFE for 32 bit systems.
Copy link
Member

Choose a reason for hiding this comment

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

typo: "to allow:

Also as I mentioned earlier, the dispatchers are more general than 32 bit, so either X86 or remove the last part of the sentence.

Copy link
Author

Choose a reason for hiding this comment

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

Should be much better now, in no way someone will ever be confused about the role of the new functions.

@ghost
Copy link
Author

ghost commented Jan 17, 2018

Good news, i can make a direct path for X86_64, saving the time took to inline.

@ghost
Copy link
Author

ghost commented Jan 17, 2018

And bad news, i have to remove the pragma for inlining. Actually not all the primitives can be inlined, meaning that the X86 version can be slightly slower with dmd-produced code (but not always): prologue + CALL + epilogue, maybe a few stack copies for the arrays passed as param (2*4 or 2*2*4 bytes, depending on the number of array used by the primitive).

@quickfur
Copy link
Member

For performance-related issues, I'm tempted to say check with ldc/gdc where possible. Dmd's optimizer leaves much to be desired.

@ghost
Copy link
Author

ghost commented Jan 17, 2018

Okay so this is still accepted.

@ghost
Copy link
Author

ghost commented Jan 17, 2018

The latest version is better. It doesn't affect X86_64, which is widely used, it only slightly affects X86, less and less used.

@wilzbach
Copy link
Member

DAutoTest fails due to dlang/dub#1336

@ghost
Copy link
Author

ghost commented Jan 18, 2018

Thanks for the information buddy.

@dlang-bot dlang-bot merged commit 3784831 into dlang:master Jan 24, 2018
@ghost ghost deleted the issue-14767 branch April 23, 2018 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants