Does anyone irl actually use bitwise operators unironically? for what purpose?

does anyone irl actually use bitwise operators unironically? for what purpose?

Attached: Screenshot 2018-12-16 at 23.17.10.png (1240x988, 972K)

masking

(x ^ y) >= 0

memory-mapped registers

To set specific bits and masking, obviously.

some_value | SOME_FLAG

Attached: 1482689417590.png (538x664, 311K)

I do. It's sometimes necessary when working with embedded and C. E.g., when you read data from some bus.

Precision.

low level languages that front end web devs need not worry about

error |= dostuff();

Flag enums, checking if something is evenly divisible by a power of two, cryptographic algorithms, etc.

why? are you writing a virtualization-based packer, ivan?

Attached: smug bear.png (500x500, 9K)

In what language doesn't this evaluate dostuff()?

In a language where |= is a logical or and the compiler makes gross assumptions about the (lack of) side-effects of functions

so a shitty one. Probably Rust or D or whatever garbage languages people on Jow Forums love.

fpbp

had to implement a binary digital radio protocol in which broadcast information would come encapsulated in rtp packets, a lot of info would come in 1 or 2 bits, so I needed to use masks to get that information, learned a lot of bitwise ops

This

Yep. Use them all the fucking time.

Attached: bitlevelops.png (640x640, 32K)

runs at about 200-300 fps if I redraw the entire background and upload it to the gpu every frame

I prefer to use bitfields and unions. It's damn comfy is what it is.

I actually wanted to use bitfield, seeing as C doesn't have a uint24_t, and I really only needed 18 bits too (but made some changes so u could have one additional color and choose up to 256 colors). I actually hoped bitfield arrays would work but unfortunately you can't address anything smaller than a byte, and it seems too painful to set 18 bits manually as membes of a struct.

All the time, for various purposes. These are just a few examples.

Attached: bw.png (1594x1172, 15K)

i can't tell what's wrong with that, in theory. like, wouldn't the long form of that be
error = error | dostuff();
so if error is already true, then it doesn't dostuff() and error stays as it was.
but if error is false, then it calls dostuff() and error is set to the result of dostuff().

that doesn't seem abhorrent, so what's the actual problem you have with this?

>for what purpose?
Well sometimes my bits will come out and they will have a really fucking good INT stat, but just no common sense. I use the wise operator to give their WIS a kick.

I can't help but feel that a NES emulator should be able to run at a lot, lot more than 200-300 FPS.

What?
you faggots are making way too many assumptions about what that line of code does. Its a basic bitwise OR.

What's masking?

>use C++ for years
>love bit twiddling
>all super straightforward. Got my bytes in memory and I just manipulate them to do what I want
>using python for a project now
>tfw it's pig disgusting high level dynamic bullshit I just can't wrap my head around because of how simplified it is

He's redrawing for every single frame, so there are no optimizations whatsoever.

I have an ancient laptop though. In any case, I guess you are right. I can get much higher fps on GBC emulators, but on the NES, SNES and GBA i usually cap out at around 3-400 NES on this computer. And those emulators are optimized in addition to emulating the CPU.

If you have tips for optimizing that would be really helpful. I am currently drawing every single pixel with the cpu before uploading to gpu.

In most languages, | is regular OR and || is short-circuiting OR. If | is short-circuiting in whatever language user is using then disregard the rest of this post.

I assume that the purpose of "error |= dostuff()" is to only invoke dostuff if error is false, but because | doesn't short-circuit, dostuff will always be invoked.
If the language had a ||= construct it would have been the correct thing to use.

I don't get it.

>but because | doesn't short-circuit, dostuff will always be invoked.
aaahhh ok got it. i did not realize that | does not short circuit. thanks for clearing that up user.

>I am currently drawing every single pixel with the cpu before uploading to gpu.
Have you profiled your emulator and concluded that most of your time is even spent drawing pixels?

Also, I have to ask, but it looks like you're drawing tiles at a time rather than scanlines at a time. Does that really work with games that do scanline counting?

Well aware, but the output resolution is just 256x224, so even at 300 FPS and a 2 GHz CPU, that's over 100 clocks per pixel, which sounds very unnecessarily high.

> error |= dostuff();
RIP anyone maintaining this shithouse attempt at error handling.

Why?

Literally fucking everything. OP has never compiled a program and has a penis that could be mistaken for Krill.

Yeah im going to change the render code to do scanlines. It was just to test that I actually got the correct output. How do I profile the code parts? I just have gcc and sublime

> sublime
Bloat

I also should maybe drop using raylibs rendering system and get closer to the opengl maybe that will be faster.

>How do I profile the code parts?
Alternatives I've used include gprof (built into gcc), callgrind and perf record/perf report.

Do you think it would be faster to send it raw to the gpu and let it handle drawing ? Im not sure if its possible with scanlines

I don't really think you should have much to gain from doing the drawing on the GPU (CPU-based rendering should be more than well fast enough for NES rendering anyway, and does allow greater control). Parallelism sounds like a reasonable goal, but if so, just do the CPU and PPU emulation on separate threads.

It's when I cover my face so the police doesn't know who I am while nailing degenerates like you to the cross.

That’s because it’s supposed to evaluate dostuff and then update the error flag without resetting it.

JSniggers out

>bitflags
>fast division/modulo for powers of 2 (ringbuffers and such)

Can't think of anything else. Still useful though

start.asm from my os:
_start:
; Make sure protected mode is on
mov dword eax, cr0
or eax,1
mov dword cr0, eax

I used it once for obfuscation.
Other than that, just for setting microcontroller bits.

underrated

Attached: bap.png (303x262, 161K)

Bit shifting.

is this from a gameboy emulator?

How do I learn this?

I don't get it.

try evaluating the expression with any 2 inputs

Attached: 1485790032937.png (1200x1314, 46K)

It always returns true. I thought it'd be some goofy way of checking equality.