Expose algebraic floating point intrinsics

This commit is contained in:
Calder Coalson 2025-02-19 12:08:31 -08:00
parent 5cc60728e7
commit 8ff70529f2
15 changed files with 544 additions and 24 deletions

View file

@ -0,0 +1,149 @@
// Verify that algebraic intrinsics generate the correct LLVM calls
// Ensure operations get inlined
//@ compile-flags: -Copt-level=1
#![crate_type = "lib"]
#![feature(f16)]
#![feature(f128)]
#![feature(float_algebraic)]
// CHECK-LABEL: @f16_algebraic_add
#[no_mangle]
pub fn f16_algebraic_add(a: f16, b: f16) -> f16 {
// CHECK: fadd reassoc nsz arcp contract half %{{.+}}, %{{.+}}
a.algebraic_add(b)
}
// CHECK-LABEL: @f16_algebraic_sub
#[no_mangle]
pub fn f16_algebraic_sub(a: f16, b: f16) -> f16 {
// CHECK: fsub reassoc nsz arcp contract half %{{.+}}, %{{.+}}
a.algebraic_sub(b)
}
// CHECK-LABEL: @f16_algebraic_mul
#[no_mangle]
pub fn f16_algebraic_mul(a: f16, b: f16) -> f16 {
// CHECK: fmul reassoc nsz arcp contract half %{{.+}}, %{{.+}}
a.algebraic_mul(b)
}
// CHECK-LABEL: @f16_algebraic_div
#[no_mangle]
pub fn f16_algebraic_div(a: f16, b: f16) -> f16 {
// CHECK: fdiv reassoc nsz arcp contract half %{{.+}}, %{{.+}}
a.algebraic_div(b)
}
// CHECK-LABEL: @f16_algebraic_rem
#[no_mangle]
pub fn f16_algebraic_rem(a: f16, b: f16) -> f16 {
// CHECK: frem reassoc nsz arcp contract half %{{.+}}, %{{.+}}
a.algebraic_rem(b)
}
// CHECK-LABEL: @f32_algebraic_add
#[no_mangle]
pub fn f32_algebraic_add(a: f32, b: f32) -> f32 {
// CHECK: fadd reassoc nsz arcp contract float %{{.+}}, %{{.+}}
a.algebraic_add(b)
}
// CHECK-LABEL: @f32_algebraic_sub
#[no_mangle]
pub fn f32_algebraic_sub(a: f32, b: f32) -> f32 {
// CHECK: fsub reassoc nsz arcp contract float %{{.+}}, %{{.+}}
a.algebraic_sub(b)
}
// CHECK-LABEL: @f32_algebraic_mul
#[no_mangle]
pub fn f32_algebraic_mul(a: f32, b: f32) -> f32 {
// CHECK: fmul reassoc nsz arcp contract float %{{.+}}, %{{.+}}
a.algebraic_mul(b)
}
// CHECK-LABEL: @f32_algebraic_div
#[no_mangle]
pub fn f32_algebraic_div(a: f32, b: f32) -> f32 {
// CHECK: fdiv reassoc nsz arcp contract float %{{.+}}, %{{.+}}
a.algebraic_div(b)
}
// CHECK-LABEL: @f32_algebraic_rem
#[no_mangle]
pub fn f32_algebraic_rem(a: f32, b: f32) -> f32 {
// CHECK: frem reassoc nsz arcp contract float %{{.+}}, %{{.+}}
a.algebraic_rem(b)
}
// CHECK-LABEL: @f64_algebraic_add
#[no_mangle]
pub fn f64_algebraic_add(a: f64, b: f64) -> f64 {
// CHECK: fadd reassoc nsz arcp contract double %{{.+}}, %{{.+}}
a.algebraic_add(b)
}
// CHECK-LABEL: @f64_algebraic_sub
#[no_mangle]
pub fn f64_algebraic_sub(a: f64, b: f64) -> f64 {
// CHECK: fsub reassoc nsz arcp contract double %{{.+}}, %{{.+}}
a.algebraic_sub(b)
}
// CHECK-LABEL: @f64_algebraic_mul
#[no_mangle]
pub fn f64_algebraic_mul(a: f64, b: f64) -> f64 {
// CHECK: fmul reassoc nsz arcp contract double %{{.+}}, %{{.+}}
a.algebraic_mul(b)
}
// CHECK-LABEL: @f64_algebraic_div
#[no_mangle]
pub fn f64_algebraic_div(a: f64, b: f64) -> f64 {
// CHECK: fdiv reassoc nsz arcp contract double %{{.+}}, %{{.+}}
a.algebraic_div(b)
}
// CHECK-LABEL: @f64_algebraic_rem
#[no_mangle]
pub fn f64_algebraic_rem(a: f64, b: f64) -> f64 {
// CHECK: frem reassoc nsz arcp contract double %{{.+}}, %{{.+}}
a.algebraic_rem(b)
}
// CHECK-LABEL: @f128_algebraic_add
#[no_mangle]
pub fn f128_algebraic_add(a: f128, b: f128) -> f128 {
// CHECK: fadd reassoc nsz arcp contract fp128 %{{.+}}, %{{.+}}
a.algebraic_add(b)
}
// CHECK-LABEL: @f128_algebraic_sub
#[no_mangle]
pub fn f128_algebraic_sub(a: f128, b: f128) -> f128 {
// CHECK: fsub reassoc nsz arcp contract fp128 %{{.+}}, %{{.+}}
a.algebraic_sub(b)
}
// CHECK-LABEL: @f128_algebraic_mul
#[no_mangle]
pub fn f128_algebraic_mul(a: f128, b: f128) -> f128 {
// CHECK: fmul reassoc nsz arcp contract fp128 %{{.+}}, %{{.+}}
a.algebraic_mul(b)
}
// CHECK-LABEL: @f128_algebraic_div
#[no_mangle]
pub fn f128_algebraic_div(a: f128, b: f128) -> f128 {
// CHECK: fdiv reassoc nsz arcp contract fp128 %{{.+}}, %{{.+}}
a.algebraic_div(b)
}
// CHECK-LABEL: @f128_algebraic_rem
#[no_mangle]
pub fn f128_algebraic_rem(a: f128, b: f128) -> f128 {
// CHECK: frem reassoc nsz arcp contract fp128 %{{.+}}, %{{.+}}
a.algebraic_rem(b)
}

View file

@ -3,7 +3,10 @@
#![crate_type = "lib"]
#![feature(core_intrinsics)]
use std::intrinsics::{fadd_fast, fdiv_fast, fmul_fast, frem_fast, fsub_fast};
use std::intrinsics::{
fadd_algebraic, fadd_fast, fdiv_algebraic, fdiv_fast, fmul_algebraic, fmul_fast,
frem_algebraic, frem_fast, fsub_algebraic, fsub_fast,
};
// CHECK-LABEL: @add
#[no_mangle]
@ -13,30 +16,72 @@ pub fn add(x: f32, y: f32) -> f32 {
x + y
}
// CHECK-LABEL: @addition
// CHECK-LABEL: @test_fadd_algebraic
#[no_mangle]
pub fn addition(x: f32, y: f32) -> f32 {
// CHECK: fadd fast float
pub fn test_fadd_algebraic(x: f32, y: f32) -> f32 {
// CHECK: fadd reassoc nsz arcp contract float %x, %y
fadd_algebraic(x, y)
}
// CHECK-LABEL: @test_fsub_algebraic
#[no_mangle]
pub fn test_fsub_algebraic(x: f32, y: f32) -> f32 {
// CHECK: fsub reassoc nsz arcp contract float %x, %y
fsub_algebraic(x, y)
}
// CHECK-LABEL: @test_fmul_algebraic
#[no_mangle]
pub fn test_fmul_algebraic(x: f32, y: f32) -> f32 {
// CHECK: fmul reassoc nsz arcp contract float %x, %y
fmul_algebraic(x, y)
}
// CHECK-LABEL: @test_fdiv_algebraic
#[no_mangle]
pub fn test_fdiv_algebraic(x: f32, y: f32) -> f32 {
// CHECK: fdiv reassoc nsz arcp contract float %x, %y
fdiv_algebraic(x, y)
}
// CHECK-LABEL: @test_frem_algebraic
#[no_mangle]
pub fn test_frem_algebraic(x: f32, y: f32) -> f32 {
// CHECK: frem reassoc nsz arcp contract float %x, %y
frem_algebraic(x, y)
}
// CHECK-LABEL: @test_fadd_fast
#[no_mangle]
pub fn test_fadd_fast(x: f32, y: f32) -> f32 {
// CHECK: fadd fast float %x, %y
unsafe { fadd_fast(x, y) }
}
// CHECK-LABEL: @subtraction
// CHECK-LABEL: @test_fsub_fast
#[no_mangle]
pub fn subtraction(x: f32, y: f32) -> f32 {
// CHECK: fsub fast float
pub fn test_fsub_fast(x: f32, y: f32) -> f32 {
// CHECK: fsub fast float %x, %y
unsafe { fsub_fast(x, y) }
}
// CHECK-LABEL: @multiplication
// CHECK-LABEL: @test_fmul_fast
#[no_mangle]
pub fn multiplication(x: f32, y: f32) -> f32 {
// CHECK: fmul fast float
pub fn test_fmul_fast(x: f32, y: f32) -> f32 {
// CHECK: fmul fast float %x, %y
unsafe { fmul_fast(x, y) }
}
// CHECK-LABEL: @division
// CHECK-LABEL: @test_fdiv_fast
#[no_mangle]
pub fn division(x: f32, y: f32) -> f32 {
// CHECK: fdiv fast float
pub fn test_fdiv_fast(x: f32, y: f32) -> f32 {
// CHECK: fdiv fast float %x, %y
unsafe { fdiv_fast(x, y) }
}
// CHECK-LABEL: @test_frem_fast
#[no_mangle]
pub fn test_frem_fast(x: f32, y: f32) -> f32 {
// CHECK: frem fast float %x, %y
unsafe { frem_fast(x, y) }
}