Skip to content

Optimization: bitwise instead of logical #217

@Raimo33

Description

@Raimo33

I propose a whole refactoring by using bitwise | and & instead of logical || and && for all booleans related conditionals.

This drastically reduces the number of branches, but ultimately has to be benchmarked.

It is something that the compiler can do, but almost never does, because of short circuiting behavior.

In reality, in most real world HPC scenarios, sacrificing short circuiting for a branchless option is almost always better.

This solution works in every architecture.

Example:

if (var1 == true && var2 == false)
Becomes
if ((var1 == true) & (var2 == false))

I argue that it is not harder to read, it just needs an extra parenthesis.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions