Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
Clojure
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Yul (Solidity IR)
Zig
Javascript
GIMPLE
Ygen
sway
zig source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
zig 0.10.0
zig 0.11.0
zig 0.12.0
zig 0.12.1
zig 0.13.0
zig 0.14.0
zig 0.14.1
zig 0.15.1
zig 0.2.0
zig 0.3.0
zig 0.4.0
zig 0.5.0
zig 0.6.0
zig 0.7.0
zig 0.7.1
zig 0.8.0
zig 0.9.0
zig trunk
Options
Source code
// If the lowest bit of each byte is 1, set that byte to 255, else 0. // Should emit constant-load+and+orc.b export fn orc_b_opportunity1(x: u64) u64 { return (x & 0x0101010101010101) *% 0xFF; } // If the lowest bit of each byte is 1, set that byte to 255, else 0. // Should emit constant-load+and+orc.b export fn orc_b_opportunity1_fixed(x: u64) u64 { return orc_b(x & 0x0101010101010101); } // If the highest bit of each byte is 1, set that byte to 255, else 0. // Should emit constant-load+and+orc.b export fn orc_b_opportunity2(x: u64) u64 { return ((x & 0x8080808080808080) >> 7) *% 0xFF; } // If the highest bit of each byte is 1, set that byte to 255, else 0. // Should emit constant-load+and+orc.b export fn orc_b_opportunity3(x: u64) u64 { const y = x & 0x8080808080808080; return (y << 1) -% (y >> 7); } // If the highest bit of each byte is 1, set that byte to 255, else 0. // Should emit constant-load+and+orc.b export fn orc_b_opportunity4(x: u64) u64 { return ((x >> 7) & 0x0101010101010101) *% 0xFF; } // If the highest bit of each byte is 1, set that byte to 255, else 0. export fn orc_b_opportunity2_and_3_and_4_fixed(x: u64) u64 { return orc_b(x & 0x8080808080808080); } // If any byte is non-zero, set that byte to 255 (all ones), else 0. // This should just emit the `orc.b` instruction. export fn orc_b_opportunity5(x: u64) u64 { const c1: u64 = @bitCast([_]u8{0x7F} ** 8); return orc_b_opportunity2(((x & c1) +% c1) | x); } // If any byte is non-zero, set that byte to 255 (all ones), else 0. // This should just emit the `orc.b` instruction. export fn orc_b_opportunity6(x: u64) u64 { const c1: u64 = @bitCast([_]u8{0x7F} ** 8); return orc_b_opportunity3(((x & c1) +% c1) | x); } // If any byte is non-zero, set that byte to 255 (all ones), else 0. // This should just emit the `orc.b` instruction. export fn orc_b_opportunity7(x: u64) u64 { const c1: u64 = @bitCast([_]u8{0x7F} ** 8); return orc_b_opportunity4(((x & c1) +% c1) | x); } export fn orc_b_opportunity5_and_6_and_7_fixed(x: u64) u64 { return orc_b(x); } fn orc_b(x: u64) u64 { return struct { extern fn @"llvm.riscv.orc.b.i64"(u64) u64; }.@"llvm.riscv.orc.b.i64"(x); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree