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
Helion
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 1.91.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
pub fn dequantize_and_idct_block_8x8(coefficients: &[i16], quantization_table: &[u16; 64], output_linestride: usize, output: &mut [u8]) { debug_assert_eq!(coefficients.len(), 64); let mut temp = [0i32; 64]; // columns for i in 0 .. 8 { // if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing if coefficients[i + 8] == 0 && coefficients[i + 16] == 0 && coefficients[i + 24] == 0 && coefficients[i + 32] == 0 && coefficients[i + 40] == 0 && coefficients[i + 48] == 0 && coefficients[i + 56] == 0 { let dcterm = (coefficients[i] as i32 * quantization_table[i] as i32).wrapping_shl(2); temp[i] = dcterm; temp[i + 8] = dcterm; temp[i + 16] = dcterm; temp[i + 24] = dcterm; temp[i + 32] = dcterm; temp[i + 40] = dcterm; temp[i + 48] = dcterm; temp[i + 56] = dcterm; } else { let s0 = coefficients[i] as i32 * quantization_table[i] as i32; let s1 = coefficients[i + 8] as i32 * quantization_table[i + 8] as i32; let s2 = coefficients[i + 16] as i32 * quantization_table[i + 16] as i32; let s3 = coefficients[i + 24] as i32 * quantization_table[i + 24] as i32; let s4 = coefficients[i + 32] as i32 * quantization_table[i + 32] as i32; let s5 = coefficients[i + 40] as i32 * quantization_table[i + 40] as i32; let s6 = coefficients[i + 48] as i32 * quantization_table[i + 48] as i32; let s7 = coefficients[i + 56] as i32 * quantization_table[i + 56] as i32; let p2 = s2; let p3 = s6; let p1 = p2.wrapping_add(p3).wrapping_mul(stbi_f2f(0.5411961)); let t2 = p1.wrapping_add(p3.wrapping_mul(stbi_f2f(-1.847759065))); let t3 = p1.wrapping_add(p2.wrapping_mul(stbi_f2f(0.765366865))); let p2 = s0; let p3 = s4; let t0 = stbi_fsh(p2.wrapping_add(p3)); let t1 = stbi_fsh(p2.wrapping_sub(p3)); let x0 = t0.wrapping_add(t3); let x3 = t0.wrapping_sub(t3); let x1 = t1.wrapping_add(t2); let x2 = t1.wrapping_sub(t2); let t0 = s7; let t1 = s5; let t2 = s3; let t3 = s1; let p3 = t0.wrapping_add(t2); let p4 = t1.wrapping_add(t3); let p1 = t0.wrapping_add(t3); let p2 = t1.wrapping_add(t2); let p5 = p3.wrapping_add(p4).wrapping_mul(stbi_f2f(1.175875602)); let t0 = t0.wrapping_mul(stbi_f2f(0.298631336)); let t1 = t1.wrapping_mul(stbi_f2f(2.053119869)); let t2 = t2.wrapping_mul(stbi_f2f(3.072711026)); let t3 = t3.wrapping_mul(stbi_f2f(1.501321110)); let p1 = p5.wrapping_add(p1.wrapping_mul(stbi_f2f(-0.899976223))); let p2 = p5.wrapping_add(p2.wrapping_mul(stbi_f2f(-2.562915447))); let p3 = p3.wrapping_mul(stbi_f2f(-1.961570560)); let p4 = p4.wrapping_mul(stbi_f2f(-0.390180644)); let t3 = t3.wrapping_add(p1.wrapping_add(p4)); let t2 = t2.wrapping_add(p2.wrapping_add(p3)); let t1 = t1.wrapping_add(p2.wrapping_add(p4)); let t0 = t0.wrapping_add(p1.wrapping_add(p3)); // constants scaled things up by 1<<12; let's bring them back // down, but keep 2 extra bits of precision let x0 = x0.wrapping_add(512); let x1 = x1.wrapping_add(512); let x2 = x2.wrapping_add(512); let x3 = x3.wrapping_add(512); temp[i] = x0.wrapping_add(t3).wrapping_shr(10); temp[i + 56] = x0.wrapping_sub(t3).wrapping_shr(10); temp[i + 8] = x1.wrapping_add(t2).wrapping_shr(10); temp[i + 48] = x1.wrapping_sub(t2).wrapping_shr(10); temp[i + 16] = x2.wrapping_add(t1).wrapping_shr(10); temp[i + 40] = x2.wrapping_sub(t1).wrapping_shr(10); temp[i + 24] = x3.wrapping_add(t0).wrapping_shr(10); temp[i + 32] = x3.wrapping_sub(t0).wrapping_shr(10); } } for i in 0 .. 8 { // no fast case since the first 1D IDCT spread components out let s0 = temp[i * 8]; let s1 = temp[i * 8 + 1]; let s2 = temp[i * 8 + 2]; let s3 = temp[i * 8 + 3]; let s4 = temp[i * 8 + 4]; let s5 = temp[i * 8 + 5]; let s6 = temp[i * 8 + 6]; let s7 = temp[i * 8 + 7]; let p2 = s2; let p3 = s6; let p1 = p2.wrapping_add(p3).wrapping_mul(stbi_f2f(0.5411961)); let t2 = p1.wrapping_add(p3.wrapping_mul(stbi_f2f(-1.847759065))); let t3 = p1.wrapping_add(p2.wrapping_mul(stbi_f2f(0.765366865))); let p2 = s0; let p3 = s4; let t0 = stbi_fsh(p2.wrapping_add(p3)); let t1 = stbi_fsh(p2.wrapping_sub(p3)); let x0 = t0.wrapping_add(t3); let x3 = t0.wrapping_sub(t3); let x1 = t1.wrapping_add(t2); let x2 = t1.wrapping_sub(t2); let t0 = s7; let t1 = s5; let t2 = s3; let t3 = s1; let p3 = t0.wrapping_add(t2); let p4 = t1.wrapping_add(t3); let p1 = t0.wrapping_add(t3); let p2 = t1.wrapping_add(t2); let p5 = p3.wrapping_add(p4).wrapping_mul(stbi_f2f(1.175875602)); let t0 = t0.wrapping_mul(stbi_f2f(0.298631336)); let t1 = t1.wrapping_mul(stbi_f2f(2.053119869)); let t2 = t2.wrapping_mul(stbi_f2f(3.072711026)); let t3 = t3.wrapping_mul(stbi_f2f(1.501321110)); let p1 = p5.wrapping_add(p1.wrapping_mul(stbi_f2f(-0.899976223))); let p2 = p5.wrapping_add(p2.wrapping_mul(stbi_f2f(-2.562915447))); let p3 = p3.wrapping_mul(stbi_f2f(-1.961570560)); let p4 = p4.wrapping_mul(stbi_f2f(-0.390180644)); let t3 = t3.wrapping_add(p1.wrapping_add(p4)); let t2 = t2.wrapping_add(p2.wrapping_add(p3)); let t1 = t1.wrapping_add(p2.wrapping_add(p4)); let t0 = t0.wrapping_add(p1.wrapping_add(p3)); // constants scaled things up by 1<<12, plus we had 1<<2 from first // loop, plus horizontal and vertical each scale by sqrt(8) so together // we've got an extra 1<<3, so 1<<17 total we need to remove. // so we want to round that, which means adding 0.5 * 1<<17, // aka 65536. Also, we'll end up with -128 to 127 that we want // to encode as 0..255 by adding 128, so we'll add that before the shift let x0 = x0.wrapping_add(65536 + (128 << 17)); let x1 = x1.wrapping_add(65536 + (128 << 17)); let x2 = x2.wrapping_add(65536 + (128 << 17)); let x3 = x3.wrapping_add(65536 + (128 << 17)); output[i * output_linestride] = stbi_clamp(x0.wrapping_add(t3).wrapping_shr(17)); output[i * output_linestride + 7] = stbi_clamp(x0.wrapping_sub(t3).wrapping_shr(17)); output[i * output_linestride + 1] = stbi_clamp(x1.wrapping_add(t2).wrapping_shr(17)); output[i * output_linestride + 6] = stbi_clamp(x1.wrapping_sub(t2).wrapping_shr(17)); output[i * output_linestride + 2] = stbi_clamp(x2.wrapping_add(t1).wrapping_shr(17)); output[i * output_linestride + 5] = stbi_clamp(x2.wrapping_sub(t1).wrapping_shr(17)); output[i * output_linestride + 3] = stbi_clamp(x3.wrapping_add(t0).wrapping_shr(17)); output[i * output_linestride + 4] = stbi_clamp(x3.wrapping_sub(t0).wrapping_shr(17)); } } // take a -128..127 value and stbi__clamp it and convert to 0..255 fn stbi_clamp(x: i32) -> u8 { x.max(0).min(255) as u8 } fn stbi_f2f(x: f32) -> i32 { (x * 4096.0 + 0.5) as i32 } fn stbi_fsh(x: i32) -> i32 { x << 12 }
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