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
rust 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
mrustc (master)
rustc 1.0.0
rustc 1.1.0
rustc 1.10.0
rustc 1.11.0
rustc 1.12.0
rustc 1.13.0
rustc 1.14.0
rustc 1.15.1
rustc 1.16.0
rustc 1.17.0
rustc 1.18.0
rustc 1.19.0
rustc 1.2.0
rustc 1.20.0
rustc 1.21.0
rustc 1.22.0
rustc 1.23.0
rustc 1.24.0
rustc 1.25.0
rustc 1.26.0
rustc 1.27.0
rustc 1.27.1
rustc 1.28.0
rustc 1.29.0
rustc 1.3.0
rustc 1.30.0
rustc 1.31.0
rustc 1.32.0
rustc 1.33.0
rustc 1.34.0
rustc 1.35.0
rustc 1.36.0
rustc 1.37.0
rustc 1.38.0
rustc 1.39.0
rustc 1.4.0
rustc 1.40.0
rustc 1.41.0
rustc 1.42.0
rustc 1.43.0
rustc 1.44.0
rustc 1.45.0
rustc 1.45.2
rustc 1.46.0
rustc 1.47.0
rustc 1.48.0
rustc 1.49.0
rustc 1.5.0
rustc 1.50.0
rustc 1.51.0
rustc 1.52.0
rustc 1.53.0
rustc 1.54.0
rustc 1.55.0
rustc 1.56.0
rustc 1.57.0
rustc 1.58.0
rustc 1.59.0
rustc 1.6.0
rustc 1.60.0
rustc 1.61.0
rustc 1.62.0
rustc 1.63.0
rustc 1.64.0
rustc 1.65.0
rustc 1.66.0
rustc 1.67.0
rustc 1.68.0
rustc 1.69.0
rustc 1.7.0
rustc 1.70.0
rustc 1.71.0
rustc 1.72.0
rustc 1.73.0
rustc 1.74.0
rustc 1.75.0
rustc 1.76.0
rustc 1.77.0
rustc 1.78.0
rustc 1.79.0
rustc 1.8.0
rustc 1.80.0
rustc 1.81.0
rustc 1.82.0
rustc 1.83.0
rustc 1.84.0
rustc 1.85.0
rustc 1.86.0
rustc 1.87.0
rustc 1.88.0
rustc 1.89.0
rustc 1.9.0
rustc 1.90.0
rustc beta
rustc nightly
rustc-cg-gcc (master)
x86-64 GCCRS (GCC master)
x86-64 GCCRS (GCCRS master)
x86-64 GCCRS 14.1 (GCC assertions)
x86-64 GCCRS 14.1 (GCC)
x86-64 GCCRS 14.2 (GCC assertions)
x86-64 GCCRS 14.2 (GCC)
x86-64 GCCRS 14.3 (GCC assertions)
x86-64 GCCRS 14.3 (GCC)
x86-64 GCCRS 15.1 (GCC assertions)
x86-64 GCCRS 15.1 (GCC)
x86-64 GCCRS 15.2 (GCC assertions)
x86-64 GCCRS 15.2 (GCC)
Options
Source code
#![feature(abi_vectorcall, portable_simd)] use std::simd::cmp::SimdOrd; use std::simd::u8x32; use std::arch::x86_64::_mm256_shuffle_epi8; fn avx2_swizzle_lo(a: u8x32, b: u8x32) -> u8x32 { unsafe { _mm256_shuffle_epi8(a.into(), b.into()).into() } } pub struct Cube3(u8x32); const ORI_MASK: u8x32 = u8x32::splat(0b0011_0000); const ORI_CARRY: u8x32 = u8x32::from_array([ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, ]); const PERM_MASK: u8x32 = u8x32::splat(0b0000_1111); const ORI_CARRY_INVERSE: u8x32 = u8x32::from_array([ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, ]); impl Cube3 { /// Compose two Rubik's cube states (apply `b` to `a`) /// /// In practice the three vmovqda instructions and the vzeroupper /// instruction would be optimized away by the "vectorcall" ABI. /// See https://learn.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-170 pub extern "vectorcall" fn replace_compose(&mut self, a: &Self, b: &Self) { let mut composed = avx2_swizzle_lo(a.0, b.0); composed += b.0 & ORI_MASK; composed = composed.simd_min(composed - ORI_CARRY); self.0 = composed; } /// Inverse a Rubik's cube state /// /// In practice the two vmovqda instructions and the vzeroupper /// instruction would be optimized away by the "vectorcall" ABI. /// See https://learn.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-170 pub extern "vectorcall" fn replace_inverse(&mut self, a: &Self) { let perm = a.0 & PERM_MASK; let pow_3 = avx2_swizzle_lo(avx2_swizzle_lo(perm, perm), perm); let mut inverse = avx2_swizzle_lo(pow_3, pow_3); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(avx2_swizzle_lo(inverse, inverse), pow_3); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(avx2_swizzle_lo(inverse, inverse), perm); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(inverse, inverse); inverse = avx2_swizzle_lo(avx2_swizzle_lo(inverse, inverse), pow_3); inverse = avx2_swizzle_lo(avx2_swizzle_lo(inverse, inverse), perm); let mut added_ori = a.0 & ORI_MASK; added_ori += added_ori; added_ori = added_ori.simd_min(added_ori - ORI_CARRY_INVERSE); added_ori = avx2_swizzle_lo(added_ori, inverse); *self = Cube3(inverse | added_ori); } }
rust source #2
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
mrustc (master)
rustc 1.0.0
rustc 1.1.0
rustc 1.10.0
rustc 1.11.0
rustc 1.12.0
rustc 1.13.0
rustc 1.14.0
rustc 1.15.1
rustc 1.16.0
rustc 1.17.0
rustc 1.18.0
rustc 1.19.0
rustc 1.2.0
rustc 1.20.0
rustc 1.21.0
rustc 1.22.0
rustc 1.23.0
rustc 1.24.0
rustc 1.25.0
rustc 1.26.0
rustc 1.27.0
rustc 1.27.1
rustc 1.28.0
rustc 1.29.0
rustc 1.3.0
rustc 1.30.0
rustc 1.31.0
rustc 1.32.0
rustc 1.33.0
rustc 1.34.0
rustc 1.35.0
rustc 1.36.0
rustc 1.37.0
rustc 1.38.0
rustc 1.39.0
rustc 1.4.0
rustc 1.40.0
rustc 1.41.0
rustc 1.42.0
rustc 1.43.0
rustc 1.44.0
rustc 1.45.0
rustc 1.45.2
rustc 1.46.0
rustc 1.47.0
rustc 1.48.0
rustc 1.49.0
rustc 1.5.0
rustc 1.50.0
rustc 1.51.0
rustc 1.52.0
rustc 1.53.0
rustc 1.54.0
rustc 1.55.0
rustc 1.56.0
rustc 1.57.0
rustc 1.58.0
rustc 1.59.0
rustc 1.6.0
rustc 1.60.0
rustc 1.61.0
rustc 1.62.0
rustc 1.63.0
rustc 1.64.0
rustc 1.65.0
rustc 1.66.0
rustc 1.67.0
rustc 1.68.0
rustc 1.69.0
rustc 1.7.0
rustc 1.70.0
rustc 1.71.0
rustc 1.72.0
rustc 1.73.0
rustc 1.74.0
rustc 1.75.0
rustc 1.76.0
rustc 1.77.0
rustc 1.78.0
rustc 1.79.0
rustc 1.8.0
rustc 1.80.0
rustc 1.81.0
rustc 1.82.0
rustc 1.83.0
rustc 1.84.0
rustc 1.85.0
rustc 1.86.0
rustc 1.87.0
rustc 1.88.0
rustc 1.89.0
rustc 1.9.0
rustc 1.90.0
rustc beta
rustc nightly
rustc-cg-gcc (master)
x86-64 GCCRS (GCC master)
x86-64 GCCRS (GCCRS master)
x86-64 GCCRS 14.1 (GCC assertions)
x86-64 GCCRS 14.1 (GCC)
x86-64 GCCRS 14.2 (GCC assertions)
x86-64 GCCRS 14.2 (GCC)
x86-64 GCCRS 14.3 (GCC assertions)
x86-64 GCCRS 14.3 (GCC)
x86-64 GCCRS 15.1 (GCC assertions)
x86-64 GCCRS 15.1 (GCC)
x86-64 GCCRS 15.2 (GCC assertions)
x86-64 GCCRS 15.2 (GCC)
Options
Source code
#![feature(portable_simd)] use std::simd::cmp::SimdOrd; use std::simd::u8x8; use std::simd::u8x16; pub struct Cube3 { edges: u8x16, corners: u8x8, } const EDGE_ORI_MASK: u8x16 = u8x16::splat(0b0001_0000); const EDGE_PERM_MASK: u8x16 = u8x16::splat(0b0000_1111); const CORNER_ORI_MASK: u8x8 = u8x8::splat(0b0011_0000); const CORNER_PERM_MASK: u8x8 = u8x8::splat(0b0000_0111); const CO_INV_SWIZZLE: u8x8 = u8x8::from_array([0, 2, 1, 0, 0, 0, 0, 0]); impl Cube3 { /// Compose two Rubik's cube states (apply `b` to `a`) pub fn replace_compose(&mut self, a: &Self, b: &Self) { let mut edges_composed = a.edges.swizzle_dyn(b.edges & EDGE_PERM_MASK); edges_composed ^= b.edges & EDGE_ORI_MASK; let mut corners_composed = a.corners.swizzle_dyn(b.corners & CORNER_PERM_MASK); corners_composed += b.corners & CORNER_ORI_MASK; corners_composed = corners_composed.simd_min(corners_composed - CORNER_ORI_MASK); self.edges = edges_composed; self.corners = corners_composed; } /// Inverse a Rubik's cube state pub fn replace_inverse(&mut self, a: &Self) { let ep = a.edges & EDGE_PERM_MASK; let pow_3_ep = ep.swizzle_dyn(ep).swizzle_dyn(ep); let mut inverse_ep = pow_3_ep.swizzle_dyn(pow_3_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep).swizzle_dyn(pow_3_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep).swizzle_dyn(ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep).swizzle_dyn(pow_3_ep); inverse_ep = inverse_ep.swizzle_dyn(inverse_ep).swizzle_dyn(ep); let mut inverse_eo = a.edges & EDGE_ORI_MASK; inverse_eo = inverse_eo.swizzle_dyn(inverse_ep); self.edges = inverse_eo | inverse_ep; let cp = a.corners & CORNER_PERM_MASK; let pow_3_cp = cp.swizzle_dyn(cp).swizzle_dyn(cp); let pow_6_cp = pow_3_cp.swizzle_dyn(pow_3_cp); let pow_7_cp = pow_6_cp.swizzle_dyn(cp); let mut inverse_cp = pow_7_cp.swizzle_dyn(pow_6_cp); inverse_cp = inverse_cp.swizzle_dyn(inverse_cp); inverse_cp = inverse_cp.swizzle_dyn(inverse_cp); inverse_cp = inverse_cp.swizzle_dyn(inverse_cp); inverse_cp = inverse_cp.swizzle_dyn(inverse_cp); inverse_cp = inverse_cp.swizzle_dyn(inverse_cp); inverse_cp = inverse_cp.swizzle_dyn(inverse_cp).swizzle_dyn(pow_7_cp); let mut inverse_co = a.corners >> 3; inverse_co = CO_INV_SWIZZLE .swizzle_dyn(inverse_co) .swizzle_dyn(inverse_cp); inverse_co <<= 3; self.corners = inverse_co | inverse_cp; } }
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