Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
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
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
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.9.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)
x86-64 GCCRS 14.2 (GCC)
Options
Source code
#![no_std] pub(crate) const COSSIN_DEPTH: usize = 7; pub(crate) const COSSIN: [u32; 1 << COSSIN_DEPTH] = [ 13238269, 39583736, 65929199, 92274656, 118620108, 144965555, 171310998, 197656435, 223936332, 250281759, 276561646, 302907064, 329186941, 355401277, 381681144, 407895470, 434175327, 460389643, 486538418, 512752725, 538901490, 564984715, 591133471, 617216686, 643299896, 669317565, 695335229, 721352888, 747305007, 773257121, 799143693, 825030261, 850851288, 876672311, 902493328, 928248805, 953938741, 979628672, 1005253062, 1030877447, 1056436292, 1081929595, 1107422895, 1132850653, 1158278406, 1183640619, 1208937291, 1234168422, 1259399549, 1284565135, 1309730716, 1334765220, 1359799720, 1384768679, 1409672097, 1434575511, 1459347848, 1484120181, 1508826972, 1533468224, 1558043934, 1582554104, 1607064269, 1631443358, 1655822442, 1680070450, 1704318453, 1728500916, 1752552302, 1776603684, 1800523989, 1824444289, 1848233513, 1872022733, 1895680876, 1919339015, 1942866078, 1966327600, 1989723581, 2013054022, 2036253387, 2059452748, 2082521032, 2105523776, 2128460980, 2151332643, 2174073230, 2196748277, 2219357783, 2241901750, 2264314640, 2286661990, 2308943799, 2331094533, 2353179726, 2375199380, 2397087957, 2418910994, 2440668491, 2462294912, 2483855793, 2505285598, 2526649863, 2547883051, 2569050700, 2590152809, 2611123842, 2632029335, 2652803753, 2673447094, 2694024895, 2714471621, 2734852807, 2755102917, 2775287487, 2795340982, 2815328936, 2835185815, 2854911618, 2874506346, 2894035534, 2913499182, 2932766219, 2951967716, 2971038137, 2990043019, 3008916826, 3027659556, ]; // #[inline(never)] pub fn cossin(mut phase: i32) -> (i32, i32) { let mut octant = phase as u32; if octant & (1 << 29) != 0 { // phase = pi/4 - phase phase = !phase; } // 16 + 1 bits for cos/sin and 15 for dphi to saturate the i32 range. const ALIGN_MSB: usize = 32 - 16 - 1; // Mask off octant bits. This leaves the angle in the range [0, pi/4). phase = (((phase as u32) << 3) >> (32 - COSSIN_DEPTH - ALIGN_MSB)) as _; let lookup = COSSIN[(phase >> ALIGN_MSB) as usize]; phase &= (1 << ALIGN_MSB) - 1; // The phase values used for the LUT are at midpoint for the truncated phase. // Interpolate relative to the LUT entry midpoint. phase -= 1 << (ALIGN_MSB - 1); // Cancel the -1 bias that was conditionally introduced above. // This lowers the DC spur from 2e-8 to 2e-10 magnitude. // phase += ((octant >> 29) & 1) as i32; // Fixed point pi/4. const PI4: i32 = (core::f64::consts::FRAC_PI_4 * (1 << 16) as f64) as _; // No rounding bias necessary here since we keep enough low bits. let dphi = (phase * PI4) >> 16; // 1/2 < cos(0 <= x <= pi/4) <= 1: Shift the cos // values and scale the sine values as encoded in the LUT. let mut cos = (lookup & 0xffff) as i32 + (1 << 16); let mut sin = (lookup >> 16) as i32; //let mut cos = (lookup.0) as i32 + (1 << 16); //let mut sin = (lookup.1) as i32; let dcos = (sin * dphi) >> COSSIN_DEPTH; let dsin = (cos * dphi) >> (COSSIN_DEPTH + 1); cos = (cos << (ALIGN_MSB - 1)) - dcos; sin = (sin << ALIGN_MSB) + dsin; // Unmap using octant bits. octant ^= octant >> 1; if octant & (1 << 29) != 0 { (cos, sin) = (sin, cos); } if octant & (1 << 30) != 0 { cos = -cos; } if octant & (1 << 31) != 0 { sin = -sin; } (cos, sin) }
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
About the author
Statistics
Changelog
Version tree