-
-
Notifications
You must be signed in to change notification settings - Fork 416
bt() is no longer a builtin #388
Conversation
Why not? As far as I can see, it did nothing memory-unsafe or non-portable? I mean, sure, it involves reinterpreting a pointer as an integer, but since we assume everywhere in the language that |
int bt(in size_t* p, size_t bitnum) pure; | ||
@system | ||
{ | ||
int bt(in size_t* p, size_t bitnum) pure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unusual lack of indentation
Interesting. I'd say forging pointers is unsafe, but peeking at their bits - knock yourself out. @WalterBright, let's make it back |
So, *(pointer + random_integer_value) is @safe? I don't agree. I might add that array[random_integer_value] is range checked. |
BTW, this was caught because the compiler no longer allows *(p + random_integer_value) in @safe code. |
@alexrp bt() does not reinterpret a pointer as an integer. Look at its implementation. |
You're right, I misinterpreted the semantics without reading the code. |
To be fair, that documentation is pretty bad... can we improve it so that it actually describes what happens? |
BTW, the reason I'm doing this is to simplify user code (I've run into various codes that don't call bt(), but do the equivalent), simplify the interface to the code generator (no need for the code generator to deal with bt() or for the front end to recognize b() as builtin), and enable bt() to work in CTFE. It's the same reason rol() and ror() are no longer builtins. |
I need this so dmd pull #1510 will work. |
Cool. One question would be how much of a deviation from the standard pattern is accepted... |
In the diffs for 1510 of dmd, you can see the patterns that are accepted. It's a superset of the bt() prototype. |
bt() is no longer a builtin
@WalterBright: @alexrp left two notes which you haven't responded to. Generally I think we need an "OK" before a pull can be merged, and we have a rule that the person who makes a pull request should never be the one to merge the request. It seems you're only using pull requests for the autotester and not for reviews. |
This causes a performance regression for me because the function call is not inlined. I suggest we turn this back into an intrinsic but keep the pattern recognition in the compiler so both generate optimal code. Also the negated pattern is not detected. bool bt(in uint[] ary, size_t bitnum)
{
return !!(ary[bitnum >> 5] & 1 << (bitnum & 31)); // uses bt
}
bool neg_bt(in uint[] ary, size_t bitnum)
{
return !(ary[bitnum >> 5] & 1 << (bitnum & 31)); // does not use bt
} |
Please file a new bug report, if you haven't already, referencing this pull request. |
Added function body for backwards compatibility.
It should never have been @safe.