Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
hairtuq
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
6 ms
·
1.
▲
by
hairtuq
1y ago
The mapping after we have the leading 1's count can be done in 3 instructions (in 32-bit math) on either x86 or ARM: t = 0x2020c6 >> x return (t << (t & 31)) >> 27
2.
▲
by
hairtuq
1y ago
If you want to optimize it a little more, you can combine isLess(s, 0x20) and isChar('"') into isLess(s ^ (kOnes * 0x02), 0x21) (this works since '"' is 0x22).
3.
▲
by
hairtuq
1y ago
Thanks, fixed.
4.
▲
by
hairtuq
2y ago
The article leaves out optimizing is_leap_year. Here is an interesting version that is correct (in the Proleptic Gregorian calendar) for 0 <= year <= 102499 and takes only 3 instructions: ((year * 1073750999) & 3221352463) &
5.
▲
by
hairtuq
2y ago
Here is a cute variant that doesn't need lzcnt nor tables, but only works up to 99,999: (((x + 393206) & (x + 524188)) ^ ((x + 916504) & (x + 514288))) >> 17 This is for integer log 10, but could be adapted for n
6.
▲
by
hairtuq
2y ago
The author wonders: > In theory at least, the compiler can see that rule only has 256 values and create a reduced version of ca1d_rule_apply for each value. Whether it actually does is not of much practical concern when the rendering cod
7.
▲
by
hairtuq
2y ago
Similarly, the eexpect table can be done in 3 instructions with with t = 0x3c783023f + i; return ((t >> (t & 63)) & 0xf0808088.
8.
▲
by
hairtuq
4y ago
I wrote a solver for Atomix ( https://github.com/falk-hueffner/atomixer ), a similar game. Technically, the only difference is that in Atomix the solution location is not predefined, although probably based on level desi
9.
▲
by
hairtuq
4y ago
On a related note, almost any task around shuffling or shifting bits can be improved with xor. For example the straightforward way to remove bit i is mask = -1 << i; return (x & ~mask) | ((x >> 1) & mask); b
10.
▲
by
hairtuq
4y ago
It seems you're shifting the goal posts now. The fact that consensus criticisms are not as harsh as you'd like doesn't mean that Israel is "totally off limits". Discussions and criticisms are happening; and the fact
11.
▲
by
hairtuq
4y ago
I don't see that. For example, it has been the official position of the German government for at least 20 years to strongly criticize the Israeli settlements. There's regular critical reports in the press, endless TV discussions a
12.
▲
by
hairtuq
5y ago
I wrote an ingredient parser that is basically just one giant regular expression: https://github.com/falk-hueffner/metric-cooking/blob/master/... The use case is a bit different (the task includes findi
13.
▲
by
hairtuq
5y ago
For the quite similar puzzle Atomix, it also seems like the branching factor would be much higher for backward search because upper bounds are weaker, but you can show that on average the branching factor is actually the same [1]. I wonder
14.
▲
by
hairtuq
5y ago
You don't necessarily need a wider type (which might be slower to work with), you can just calculate (n|1) * ((n+1)/2). Clang does something much more complicated, probably because for it is just a special case of some much more g
15.
▲
by
hairtuq
5y ago
Slightly simpler: c = x ^ y; return popcount(((c >> 1) | 0x8080808080808080) - c) & 0x8080808080808080);
16.
▲
by
hairtuq
5y ago
Actually, e is the inverse of the xor, so (e & c1) is guaranteed to be c1, and you still need popcount(c1 & ((e & c2) + c3)).
17.
▲
by
hairtuq
6y ago
The name SWAR is sometimes used ( https://en.wikipedia.org/wiki/SWAR ). Indeed, even 8-bit fields can be added in parallel, using the fact that ^ is like a + that does not produce a carry: uint64_t signmask = 0x808
18.
▲
by
hairtuq
6y ago
There is some work on automatically generating data structure implementations from high-level specifications: https://cozy.uwplse.org/
19.
▲
by
hairtuq
6y ago
Since the shift count is implicitly modulo 32, you don't even need the subtraction: bool isvowel(char c) { return (1u << (c&31)) & 0x208222; }
20.
▲
by
hairtuq
6y ago
I wrote a browser extension that does this (although it will of course occasionally get something wrong): https://github.com/falk-hueffner/metric-cooking
21.
▲
by
hairtuq
7y ago
Here's a version that at least for 64 bit might be faster: bool isPerfect(uint64_t x) { int ctz = __builtin_ctzll(x); return ((0x40051056 >> ctz) & 1) && ((x >> ctz) + 1) == (uint64_t(1) <
22.
▲
by
hairtuq
7y ago
Red-black tree presentations are often more complicated than necessary, mostly because of (premature?) optimizations. A simple presentation can be found here: https://www.cs.tufts.edu/~nr/cs257/archive/chris-o
23.
▲
by
hairtuq
7y ago
But it's not only impossible to decide halting faster than the program would run, but impossible at all, a much stronger statement.
24.
▲
by
hairtuq
7y ago
That's very unlikely to happen, since finding a counterexample or proving there isn't one is much easier than finding a program candidate, so it'll usually time out in that phase.
25.
▲
by
hairtuq
7y ago
I wrote a superoptimizer using z3 here: https://github.com/falk-hueffner/sematrope . The idea is to have variables that encode the program and a giant if-then-else statement that represents program execution. Then for
26.
▲
by
hairtuq
7y ago
I tried using https://github.com/falk-hueffner/sematrope . Best I can get is x - ((x >> 4) ^ 0x33), should be slightly faster. EDIT: unfortunately that works only for upper case letters.
27.
▲
by
hairtuq
8y ago
The most fun part is when you get to use the Jordan curve theorem (using the parity of an intersecting ray).
28.
▲
by
hairtuq
8y ago
This will not yield a minimal set; in a cycle, it is only necessary to remove at least one word. The problem is thus to delete the minimum number of vertices to remove all cycles. This is the NP-hard Feedback Vertex Set problem. Here's
29.
▲
by
hairtuq
8y ago
If you're concerned about numerical inaccuracy of an expression, it might be worthwhile trying Herbie ( https://herbie.uwplse.org/ ), a system that will try to rearrange expressions to minimize numerical error even in co
30.
▲
by
hairtuq
8y ago
There is a tool that synthesize data structures based on the requirements similar as you describe: https://github.com/CozySynthesizer/cozy . It can handle even involved constraints that are not fulfilled by any off-the-
More ›