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
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
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
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.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
const std = @import("std"); fn expand8xu8To16xu4AsByteVector(vec: @Vector(8, u8)) @Vector(16, u8) { return std.simd.interlace(.{ vec & @as(@Vector(8, u8), @splat(0xF)), vec >> @splat(4) }); } fn sel(vec: anytype) @Vector(@typeInfo(@TypeOf(vec)).vector.len, u8) { const false_vec: @Vector(16, u8) = @splat(0); const true_vec = ~false_vec; return @select(u8, vec, true_vec, false_vec); } fn bsl2(vec1: anytype, vec2: @TypeOf(vec1), vec3: @TypeOf(vec1)) @TypeOf(vec1) { return (vec1 & (vec2 ^ vec3)) ^ vec3; } fn bsl(vec1: anytype, vec2: @TypeOf(vec1), vec3: @TypeOf(vec1)) @TypeOf(vec1) { return (vec1 & vec2) | (~vec1 & vec3); } export fn bad_bsl(x: u64, buffer1_half1: @Vector(16, u8), buffer1_half2: @Vector(16, u8), buffer2_half1: @Vector(16, u8), buffer2_half2: @Vector(16, u8)) @Vector(32, u8) { const splatted = blk: { // try to avoid https://github.com/llvm/llvm-project/issues/92211 var y: u64 = x; // spread out each bit of `x` into a nibble of `y` // zig fmt: off // start positions: 0b0000000000000000000000000000000000000000000000001111111111111111; y = (y | (y << 24)); // & 0b0000000000000000000000001111111100000000000000000000000011111111 this AND is optimized out y = (y | (y << 12)) & 0b0000000000001111000000000000111100000000000011110000000000001111; y = (y | (y << 6)); // & 0b0000001100000011000000110000001100000011000000110000001100000011 this AND is optimized out y = (y | (y << 3)) & 0b0001000100010001000100010001000100010001000100010001000100010001; // zig fmt: on break :blk y; }; const selector_compressed = sel(expand8xu8To16xu4AsByteVector(@bitCast(splatted)) != @as(@Vector(16, u8), @splat(0))); const selectors: [2]@Vector(16, u8) = @bitCast(std.simd.interlace(.{ selector_compressed, selector_compressed })); return @bitCast([2]@Vector(16, u8){ bsl( selectors[0], buffer1_half1, buffer2_half1, ), bsl( selectors[1], buffer1_half2, buffer2_half2, ), }); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
About the author
Statistics
Changelog
Version tree