[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


Janitor application acceptance emails are being sent out. Please remember to check your spam box!


[Advertise on 4chan]


What are you OLs working on?

Previous TPS report: >>107088464
>>
File: sombrita walking.gif (152 KB, 349x430)
152 KB
152 KB GIF
>>107113418
i'm not working at all
>>
Erlang is KING
>>
Are there any ways to simplify this? (searching for blocks of set/unset bits in a bitmap)
  template <bool BIT>
static constexpr u32 find_sequence(u64 *buckets, u32 num_buckets, u32 num_bits) {
u32 run = 0;
for (u32 bk = 0; bk < num_buckets; ++bk) {
u64 bucket = buckets[bk];
if (!BIT) bucket = ~bucket;
u32 bit = 0;
do {
if (bucket & 1) {
const u32 ones = tzcnt(~bucket);
run += ones;
bucket = ones == 64 ? 0 : bucket >> ones;
bit += ones;
if (run >= num_bits) return (bk * 64 + bit) - run;
if (bit < 64) run = 0;
} else {
const u32 zeroes = tzcnt(bucket);
run = 0;
bucket = zeroes == 64 ? 0 : bucket >> zeroes;
bit += zeroes;
}
if (!bucket) break;
} while (true);
}
return U32_MAX;
}
>>
>>107113418
how to get OL GF?
>>
File: carbon.png (247 KB, 1988x1020)
247 KB
247 KB PNG
I pressed F5 after writing all this shit down fml

>>107113513
>>107113160
This is how I would write it in Rust if I wanted to keep it simple.
However simple =/= fast

I have some idea for optimized, C-like solution, but I don't have time to write it down right now.
The basic idea is to split this into 3 cases: (1)len < 64, (2)64 <= len < 128, (3) 128 <= len
(1) you can do preliminary filtering using POPCNT+TZCNT as a bucket has to have at least len bits(set/unset) or ends up with some bits to be any interest for you.
(2) you can just use TZCNT+LZCNT because the sequence is guaranteed to span at least 2 buckets.
(3) you can do preliminary filtering by checking bucket = 0/~0 because the sequence is guaranteed to span at least one homogeneous bucket in it. Then just check proceeding and following buckets in using TZCNT/LZCNT
Only in (1) you need explicit looping over each bit. It might turn out to be more performant if you split them in u32s or u16s.
If this is performance critical code, I strongly suggest you set up some benchmark and observe emitted assembly to find best solution.
>>
>>107113592
btw I made it return the position of last bit of matching sequence, but one can just (pos + 1 - len) to find the start of it.
>>
>>107113592
Also (2) and (3) can probably be combined if checking for bucket == 0 is not much faster than TZCNT
>>
>>107113513
>>107113592
what is it that youre trying to do?
you look for the first 0 or the first 1, and what next?
you emit its position?
whats the actual mission bc finding the first 0 or the first 1 isnt that complicated
but you still return u32_max
i dont get it
>>
>>107113513
>>107113633
cont
>if (run >= num_bits) return (bk * 64 + bit) - run;

aaaah
so you return the position of the first 0 or 1 found in an array
ok
gimme a sec
>>
>>107113633
He is looking for first span of continuous bits(either 1s or 0s based on template argument) of given length inside some arbitrary long bitfield stored as an array of u64s
>>
>>107113592
Naive is 4.3x slower, trying your optimized approach now.
>>
>>107113687
aaaaah
much more interesting
ok
>>
>>107113571
They seem attracted to photocopiers, so wear clothing reminiscent of a photocopier
>>
File: Gu9sZNwWUAABsbu.jpg (40 KB, 735x640)
40 KB
40 KB JPG
>>107113486
That would be Clojure
>>
>>107113418
I need a shy pervert office lady GF like this.
>>
>>107113820
>Tensei Shitara Fukushaki Datta Ken
>>
I just learned that cniles don't have booleans in their language
>>
File: enlightenment.png (38 KB, 1024x1024)
38 KB
38 KB PNG
>>107115077
That's a funny way of spelling Common Lisp
>>
File: 1759701366685367.gif (53 KB, 300x300)
53 KB
53 KB GIF
>>107115761
Not true since c23, we even have static_assert and nullptr now
>>
>>107113513
Yes, there is a neat bit trick. I even posted it here this year or the last. I'm trying to find it in the archive.
>>
>>107115165
I wish this was real. Another strategy is leaving a trail of stationary, coffee vouchers, and various luxury products leading to the cafeteria to lure OLs to lunch
>>
File: uni-mc-wagie.jpg (7 KB, 217x232)
7 KB
7 KB JPG
>>107115761
>needs a dedicated boolean type
the absolute state
also
>>107115951
how does that stack up with branchless?
does it throw an error? lmao
>>
>>107115761
I present to you the octolean, a vastly superior boolean.
>>
>>107115761
stdbool is c99 i think?
>>
>>107116141
hexafoureans are so much better
>>
>>107116325
I'm a catastrophe.
>>107113513
>>107115972
This finds sequences where there are 3 or more consecutive 1 bits.
It's very simple. There is a bit sequence of 1s of length >= 3 starting at bit n if bit(n) == 1 && bit(n + 1) == 1 && bit(n + 2) == 1.
From there, if locations is not 0 you can easily find n by counting the number of leading 0s.
uint32_t bitmap = 0b011110111011010;
uint32_t x = bitmap;
uint32_t locations = x & x >> 1 & x >> 2;

if (locations == 0) {
// no sequence of bits is long enough
}
else {
printf("bitmap 0b%032b\n", bitmap);
printf("locations 0b%032b\n", locations);
}

bitmap    0b00000000000000000011110111011010
locations 0b00000000000000000000110001000000
>>
>>107115761
>cniles == nazis
>>
>>107113418
Why is she watching pornography at work?
>>
>>107116521
looks more like online lingerie shopping

>>107116126
>>needs a dedicated boolean type
better than having any type also act as a boolean as long as it's "zero"
>>
>>107116714
>better than having any type also act as a boolean as long as it's "zero"
i really dont see how
0 as false and anything but zero being true is comfy
>>
>>107116714
if (timer)
{
timer--;
}
>>
>>107116751
>0 as false and anything but zero being true is comfy
It's comfy but wrong, the compiler should be smart to see
enun state { stop, go }
and not permit
enum state s = 3
, as it raises the question of which of these are exhaustive:
switch (s) {
case stop:
....
case go:
....
case default:
....
}

switch (s) {
case stop:
....
case go:
....
}
>>
>>107116950
nono
it is correct
whats incorrect is your mental model of the language
how can a language be incorrect?
>>
>>107116782
timer = -1;

oops, timer broke
>>
>>107116950
>and not permit
its useful though
>>
>>107117003
>non exhaustive switch statements should not be permitted
what if one doesnt want anything to happen?
hes an autist
he cant wrap his head around any amount of fuzziness
>>
File: 1758373800279140.jpg (42 KB, 350x490)
42 KB
42 KB JPG
>>107117029
There's enough undefined behavior already without adding to it
>>
File: w11-devs.png (413 KB, 546x502)
413 KB
413 KB PNG
>>107117042
ub only means implementation defined
youre amgery at this because turns out not everything is contained within the standard

yes you have to learn more shit including learning empirically
no, the underlying mechanisms dont all neatly align its actually a big fucking mess of various, sometimes overlapping responsibilities
nor will the universe cater to your irrational need for order
>>
>>107117042
static casting something to and from the underlying type is well defined
>>
>>107117120
yea it all dissolves into syntactic sugar
an enum is an int iirc
>>
>>107117079
Hopefully the outcome of evaluating an expression like `true && false' isn't a matter of empirical observation but logical deduction, or we can at least arrange the machinery so we can imagine it is so
>>
>>107116126
>how does that stack up with branchless?
all a boolean type is doing is expressing that there's only one bit of meaningful information in that variable
it doesn't say at all whether operations require branches or not because that depends on so many other factors (including whether you bother to enable the optimizer lol)
>>
>>107117079
>ub only means implementation defined
sometimes not even that; blowing off the end of an array on the stack can easily get into total "fuck the rules" land
>>
>>107116950
If you want that level of guarantee, write Java or Rust.
>>
>>107117191
NTA but what is the "correct" way to tell the compiler I want strictness and not lazy/short circuiting &&
Is it just to use & even for logical ops?
>>
>>107117183
the observable, measurable effect on reality is how the machine performs.
the language is perfectly abstract.

empirical observation intervenes when one compares the language input to the asm output and then how the latter performs on an actual machine
theres two degrees of abstraction before we get to the observable effect
which is the goal of the exercice here-
what matters is not the purity of code, but how the machine performs
regardless of the lang, ub or not
again, your ubs are perfectly deterministic, even implementation defined in some cases
>>
>>107116950
correct
>>107117003
idiot
>>
>>107117213
thats on the compiler
if the cpu gets the directive to go to address x
then short of tripping some hardware protection its what its gonna do
its deterministic.
which makes it implementation if we stretch the definition a little bit

>>107117191
no, i meant something like this:
mask = TRUE * 1 + TRUE * 2 + FALSE * 4 + TRUE * 8;

liek int the conetxt of branchless maths and truth tables
>>
>>107117182
depends on the lang. c++ you can specify it, by default it's an int, but there's also some wacky rule (I think only applying to enum class) about the underlying type being "the minimum bitfield size to hold all enum values" which makes any swich case on a 2^n enum without default defined but any other type of enum UB (though most compilers lie and tell you it's fine...)
>>
>>107117303
>something like this
its contrived asf in my actual code you'd see something like this:
jump_table[(is_alpha) + (is_wspace * 2)];

if its enforced as type different from ints then that doesnt work
>>
>>107117336
>(though most compilers lie and tell you it's fine...)
they dont really lie i think theres a flag you can activate to find ub
i vaguely remember something like that for c
and heres the thing: a construct may be supported by the compiler while also being ub in the standard
type punning through union is apparently ub in sepples.
but its supported by most compilers from what i read (btw, wtf? why would you want to ub type punning through an union?)
>>
>>107117346
>if its enforced as type different from ints then that doesnt work
that's why type should have an abstract algebraic data type definition for type safety and generiticty, and optionally have a concrete implementation that allows you to write efficient code

this is a continuation of the idea of functions making operations on an abstract data structure (it calls methods on an abstract class) and then you can use different class implementations without changing the functions that use it
>>
>>107117395
I think I had it backwards, if you enable all the error checking flags it will complain to you about something like the following despite this case being explicitly defined for 2^n non-fixed enums

enum class Alpha {
A,
B
};

int printer(Alpha alpha) {
switch(alpha) {
case Alpha::A: return 1;
case Alpha::B: return 2;
}
}
>>
>>107113486
Based.
>>
>>107117526
yeah thats for higher level languages than c
the usecase for c is hacky shit, safety and genericity are the least of ones concerns
whats most important is consistent internal representations and kinda the opposite of safety, type flexibility
>>
>>107117567
maybe its a standard thing
as in your compiler compiles with a default standard but it becomes defined in a later one, still available, but as opt in
idk, i dont program in sepples
its an entirely different beast from c
but yeah, there is indeed a class of constructs that are ub in the standard but supported by the compilers, individually
>>
You CANNOT escape us.
You WILL be functional.
https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3694.htm
>>
>>107117677
>https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3694.htm
wow
so were gonna get this mental retardation and force inlines are not yet standard?
>>
>>107117677
>>107117698
cont
its still only a proposal hopefully it gets rejected



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.