D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14767 - Support CTFE of BigInt under x86
Summary: Support CTFE of BigInt under x86
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
: 17003 17095 (view as issue list)
Depends on:
Blocks:
 
Reported: 2015-07-03 16:19 UTC by Paul D. Anderson
Modified: 2020-03-21 03:56 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul D. Anderson 2015-07-03 16:19:26 UTC
The following code fails to compile and responds with the given error message. Varying the "plusTwo" function doesn't work; as long as there is an arithmetic operation the error occurs.

It seems to mean that there is no way to modify a BigInt at compile time. This seriously limits the usability of the type.

enum BigInt test1 = BigInt(123);
enum BigInt test2 = plusTwo(test1);

public static BigInt plusTwo(in BigInt n)
{
	return n + 2;
}

void main()
{
}

Error message:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\internal\math\biguintx86.d(226): Error: asm statements cannot be interpreted at compile time

Error occurs with dmd 2.067.1 for 32-bit Windows. Does not occur with Windows 64-bit version
Comment 1 hsteoh 2015-07-03 20:20:17 UTC
Currently, BigInt is implemented as a runtime library type that uses asm optimizations, which cannot be interpreted in CTFE. Marking this as an enhancement request to add CTFE support to BigInt.
Comment 2 Paul D. Anderson 2015-07-07 22:23:05 UTC
Could we add a version or a compiler flag that would force use the .biguintnoasm version for the x86 also? That seems like an innocuous change that could be easily implemented.

Paul
Comment 3 Paul D. Anderson 2015-07-07 22:23:58 UTC
I changed the hardware setting from x86_64 to x86.

Paul
Comment 4 Ivan Kazmenko 2015-07-08 13:48:44 UTC
Perhaps on x86, the compiler could do something like the following when instantiating BigInt:

-----
if (__ctfe)
{
   // use biguintnoasm
}
else
{
   // use biguintx86
}
-----
Comment 5 basile-z 2018-01-14 18:20:21 UTC
*** Issue 17003 has been marked as a duplicate of this issue. ***
Comment 6 basile-z 2018-01-14 18:20:36 UTC
*** Issue 17095 has been marked as a duplicate of this issue. ***
Comment 7 basile-z 2018-01-14 20:48:04 UTC
pull https://github.com/dlang/phobos/pull/6029
Comment 8 github-bugzilla 2018-01-24 21:39:59 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/f2c5ee3bf17707ea16c2d7c269b3537a46d11032
fix issue 14767 - Support CTFE of BigInt under x86

https://github.com/dlang/phobos/commit/3784831e30f707d3c1411a639540e2bd2b3e241c
Merge pull request #6029 from BBasile/issue-14767

fix issue 14767 - Support CTFE of BigInt under x86
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>