D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5703 - std.intrinsic. and core.bitop.bsf, bsr and bswap should be CTFE-able
Summary: std.intrinsic. and core.bitop.bsf, bsr and bswap should be CTFE-able
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: Other All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-05 06:20 UTC by kennytm
Modified: 2011-10-08 17:54 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-03-05 06:20:20 UTC
import core.bitop;
enum x = bsf(0b111100);
enum y = bsr(0b111100);
enum z = bswap(0b111100);
static assert(x == 2);
static assert(y == 5);
static assert(z == 0x3C000000);

The three functions bsr, bsf and bswap are pure nothrow, but cannot be used in CTFE because there is no source code.

These functions should be rewritten in D like bitswap and popcnt.
Comment 1 bearophile_hugs 2011-03-05 10:34:00 UTC
(In reply to comment #0)

> These functions should be rewritten in D like bitswap and popcnt.

I think they aren't functions.
Comment 2 kennytm 2011-03-05 13:34:17 UTC
(In reply to comment #1)
> (In reply to comment #0)
> 
> > These functions should be rewritten in D like bitswap and popcnt.
> 
> I think they aren't functions.

They appear to be functions, and can easily implemented as functions too. If they are special-cased in the compiler, I see no reason they can't be recognized in CTFE as well.