/src/test/codegen/float_math.rs

https://gitlab.com/jianglu/rust · Rust · 60 lines · 31 code · 8 blank · 21 comment · 0 complexity · 0d83f8aba7805fa821ef2196b602175c MD5 · raw file

  1. // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. // compile-flags: -C no-prepopulate-passes
  11. #![crate_type = "lib"]
  12. #![feature(core_intrinsics)]
  13. use std::intrinsics::{fadd_fast, fsub_fast, fmul_fast, fdiv_fast, frem_fast};
  14. // CHECK-LABEL: @add
  15. #[no_mangle]
  16. pub fn add(x: f32, y: f32) -> f32 {
  17. // CHECK: fadd float
  18. // CHECK-NOT: fast
  19. x + y
  20. }
  21. // CHECK-LABEL: @addition
  22. #[no_mangle]
  23. pub fn addition(x: f32, y: f32) -> f32 {
  24. // CHECK: fadd fast float
  25. unsafe {
  26. fadd_fast(x, y)
  27. }
  28. }
  29. // CHECK-LABEL: @subtraction
  30. #[no_mangle]
  31. pub fn subtraction(x: f32, y: f32) -> f32 {
  32. // CHECK: fsub fast float
  33. unsafe {
  34. fsub_fast(x, y)
  35. }
  36. }
  37. // CHECK-LABEL: @multiplication
  38. #[no_mangle]
  39. pub fn multiplication(x: f32, y: f32) -> f32 {
  40. // CHECK: fmul fast float
  41. unsafe {
  42. fmul_fast(x, y)
  43. }
  44. }
  45. // CHECK-LABEL: @division
  46. #[no_mangle]
  47. pub fn division(x: f32, y: f32) -> f32 {
  48. // CHECK: fdiv fast float
  49. unsafe {
  50. fdiv_fast(x, y)
  51. }
  52. }