2024-10-18 00:53:56 -05:00
|
|
|
// 32-bit x86 returns float types differently to avoid the x87 stack.
|
2024-10-12 11:17:34 -05:00
|
|
|
// 32-bit systems will return 128bit values using a return area pointer.
|
|
|
|
//@ revisions: x86 bit32 bit64
|
2024-07-03 07:41:36 -05:00
|
|
|
//@[x86] only-x86
|
2024-10-12 11:17:34 -05:00
|
|
|
//@[bit32] ignore-x86
|
|
|
|
//@[bit32] only-32bit
|
|
|
|
//@[bit64] ignore-x86
|
|
|
|
//@[bit64] only-64bit
|
2024-07-03 07:41:36 -05:00
|
|
|
|
2024-03-06 05:40:29 -06:00
|
|
|
// Verify that our intrinsics generate the correct LLVM calls for f16
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
2024-05-16 04:05:34 -05:00
|
|
|
#![feature(f128)]
|
2024-03-06 05:40:29 -06:00
|
|
|
#![feature(f16)]
|
|
|
|
#![feature(core_intrinsics)]
|
|
|
|
|
2024-05-16 04:05:34 -05:00
|
|
|
/* arithmetic */
|
|
|
|
|
2024-03-06 05:40:29 -06:00
|
|
|
// CHECK-LABEL: i1 @f16_eq(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_eq(a: f16, b: f16) -> bool {
|
|
|
|
// CHECK: fcmp oeq half %{{.+}}, %{{.+}}
|
|
|
|
a == b
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i1 @f16_ne(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_ne(a: f16, b: f16) -> bool {
|
|
|
|
// CHECK: fcmp une half %{{.+}}, %{{.+}}
|
|
|
|
a != b
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i1 @f16_gt(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_gt(a: f16, b: f16) -> bool {
|
|
|
|
// CHECK: fcmp ogt half %{{.+}}, %{{.+}}
|
|
|
|
a > b
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i1 @f16_ge(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_ge(a: f16, b: f16) -> bool {
|
|
|
|
// CHECK: fcmp oge half %{{.+}}, %{{.+}}
|
|
|
|
a >= b
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i1 @f16_lt(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_lt(a: f16, b: f16) -> bool {
|
|
|
|
// CHECK: fcmp olt half %{{.+}}, %{{.+}}
|
|
|
|
a < b
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i1 @f16_le(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_le(a: f16, b: f16) -> bool {
|
|
|
|
// CHECK: fcmp ole half %{{.+}}, %{{.+}}
|
|
|
|
a <= b
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// This is where we check the argument and return ABI for f16.
|
|
|
|
// other-LABEL: half @f16_neg(half
|
|
|
|
// x86-LABEL: i16 @f16_neg(half
|
2024-03-06 05:40:29 -06:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_neg(a: f16) -> f16 {
|
|
|
|
// CHECK: fneg half %{{.+}}
|
|
|
|
-a
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f16_add
|
2024-03-06 05:40:29 -06:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_add(a: f16, b: f16) -> f16 {
|
|
|
|
// CHECK: fadd half %{{.+}}, %{{.+}}
|
|
|
|
a + b
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f16_sub
|
2024-03-06 05:40:29 -06:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_sub(a: f16, b: f16) -> f16 {
|
|
|
|
// CHECK: fsub half %{{.+}}, %{{.+}}
|
|
|
|
a - b
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f16_mul
|
2024-03-06 05:40:29 -06:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_mul(a: f16, b: f16) -> f16 {
|
|
|
|
// CHECK: fmul half %{{.+}}, %{{.+}}
|
|
|
|
a * b
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f16_div
|
2024-03-06 05:40:29 -06:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_div(a: f16, b: f16) -> f16 {
|
|
|
|
// CHECK: fdiv half %{{.+}}, %{{.+}}
|
|
|
|
a / b
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f16_rem
|
2024-03-06 05:40:29 -06:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_rem(a: f16, b: f16) -> f16 {
|
|
|
|
// CHECK: frem half %{{.+}}, %{{.+}}
|
|
|
|
a % b
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void @f16_add_assign(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_add_assign(a: &mut f16, b: f16) {
|
|
|
|
// CHECK: fadd half %{{.+}}, %{{.+}}
|
|
|
|
// CHECK-NEXT: store half %{{.+}}, ptr %{{.+}}
|
|
|
|
*a += b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void @f16_sub_assign(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_sub_assign(a: &mut f16, b: f16) {
|
|
|
|
// CHECK: fsub half %{{.+}}, %{{.+}}
|
|
|
|
// CHECK-NEXT: store half %{{.+}}, ptr %{{.+}}
|
|
|
|
*a -= b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void @f16_mul_assign(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_mul_assign(a: &mut f16, b: f16) {
|
|
|
|
// CHECK: fmul half %{{.+}}, %{{.+}}
|
|
|
|
// CHECK-NEXT: store half %{{.+}}, ptr %{{.+}}
|
2024-05-16 04:05:34 -05:00
|
|
|
*a *= b;
|
2024-03-06 05:40:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void @f16_div_assign(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_div_assign(a: &mut f16, b: f16) {
|
|
|
|
// CHECK: fdiv half %{{.+}}, %{{.+}}
|
|
|
|
// CHECK-NEXT: store half %{{.+}}, ptr %{{.+}}
|
2024-05-16 04:05:34 -05:00
|
|
|
*a /= b;
|
2024-03-06 05:40:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: void @f16_rem_assign(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_rem_assign(a: &mut f16, b: f16) {
|
|
|
|
// CHECK: frem half %{{.+}}, %{{.+}}
|
|
|
|
// CHECK-NEXT: store half %{{.+}}, ptr %{{.+}}
|
2024-05-16 04:05:34 -05:00
|
|
|
*a %= b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* float to float conversions */
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// other-LABEL: half @f16_as_self(
|
|
|
|
// x86-LABEL: i16 @f16_as_self(
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_self(a: f16) -> f16 {
|
2024-10-18 00:53:56 -05:00
|
|
|
// other-CHECK: ret half %{{.+}}
|
|
|
|
// x86-CHECK: bitcast half
|
|
|
|
// x86-CHECK: ret i16
|
2024-05-16 04:05:34 -05:00
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-07-03 07:41:36 -05:00
|
|
|
// x86-LABEL: i32 @f16_as_f32(
|
2024-10-12 11:17:34 -05:00
|
|
|
// bit32-LABEL: float @f16_as_f32(
|
|
|
|
// bit64-LABEL: float @f16_as_f32(
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_f32(a: f16) -> f32 {
|
|
|
|
// CHECK: fpext half %{{.+}} to float
|
|
|
|
a as f32
|
|
|
|
}
|
|
|
|
|
2024-07-03 07:41:36 -05:00
|
|
|
// x86-LABEL: void @f16_as_f64(
|
2024-10-12 11:17:34 -05:00
|
|
|
// bit32-LABEL: double @f16_as_f64(
|
|
|
|
// bit64-LABEL: double @f16_as_f64(
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_f64(a: f16) -> f64 {
|
|
|
|
// CHECK: fpext half %{{.+}} to double
|
|
|
|
a as f64
|
|
|
|
}
|
|
|
|
|
2024-10-12 11:17:34 -05:00
|
|
|
// x86-LABEL: void @f16_as_f128({{.*}}sret([16 x i8])
|
|
|
|
// bit32-LABEL: void @f16_as_f128({{.*}}sret([16 x i8])
|
|
|
|
// bit64-LABEL: fp128 @f16_as_f128(
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_f128(a: f16) -> f128 {
|
|
|
|
// CHECK: fpext half %{{.+}} to fp128
|
|
|
|
a as f128
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f32_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f32_as_f16(a: f32) -> f16 {
|
|
|
|
// CHECK: fptrunc float %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f64_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f64_as_f16(a: f64) -> f16 {
|
|
|
|
// CHECK: fptrunc double %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @f128_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f128_as_f16(a: f128) -> f16 {
|
|
|
|
// CHECK: fptrunc fp128 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
|
|
|
/* float to int conversions */
|
|
|
|
|
|
|
|
// CHECK-LABEL: i8 @f16_as_u8(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_u8(a: f16) -> u8 {
|
|
|
|
// CHECK: call i8 @llvm.fptoui.sat.i8.f16(half %{{.+}})
|
|
|
|
a as u8
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_u16(a: f16) -> u16 {
|
|
|
|
// CHECK: call i16 @llvm.fptoui.sat.i16.f16(half %{{.+}})
|
|
|
|
a as u16
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i32 @f16_as_u32(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_u32(a: f16) -> u32 {
|
|
|
|
// CHECK: call i32 @llvm.fptoui.sat.i32.f16(half %{{.+}})
|
|
|
|
a as u32
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i64 @f16_as_u64(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_u64(a: f16) -> u64 {
|
|
|
|
// CHECK: call i64 @llvm.fptoui.sat.i64.f16(half %{{.+}})
|
|
|
|
a as u64
|
|
|
|
}
|
|
|
|
|
2024-10-12 11:17:34 -05:00
|
|
|
// x86-LABEL: void @f16_as_u128({{.*}}sret([16 x i8])
|
|
|
|
// bit32-LABEL: void @f16_as_u128({{.*}}sret([16 x i8])
|
|
|
|
// bit64-LABEL: i128 @f16_as_u128(
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_u128(a: f16) -> u128 {
|
|
|
|
// CHECK: call i128 @llvm.fptoui.sat.i128.f16(half %{{.+}})
|
|
|
|
a as u128
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i8 @f16_as_i8(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_i8(a: f16) -> i8 {
|
|
|
|
// CHECK: call i8 @llvm.fptosi.sat.i8.f16(half %{{.+}})
|
|
|
|
a as i8
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i16 @f16_as_i16(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_i16(a: f16) -> i16 {
|
|
|
|
// CHECK: call i16 @llvm.fptosi.sat.i16.f16(half %{{.+}})
|
|
|
|
a as i16
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: i32 @f16_as_i32(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_i32(a: f16) -> i32 {
|
|
|
|
// CHECK: call i32 @llvm.fptosi.sat.i32.f16(half %{{.+}})
|
|
|
|
a as i32
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: i64 @f16_as_i64(
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_i64(a: f16) -> i64 {
|
|
|
|
// CHECK: call i64 @llvm.fptosi.sat.i64.f16(half %{{.+}})
|
|
|
|
a as i64
|
|
|
|
}
|
|
|
|
|
2024-10-12 11:17:34 -05:00
|
|
|
// x86-LABEL: void @f16_as_i128({{.*}}sret([16 x i8])
|
|
|
|
// bit32-LABEL: void @f16_as_i128({{.*}}sret([16 x i8])
|
|
|
|
// bit64-LABEL: i128 @f16_as_i128(
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn f16_as_i128(a: f16) -> i128 {
|
|
|
|
// CHECK: call i128 @llvm.fptosi.sat.i128.f16(half %{{.+}})
|
|
|
|
a as i128
|
|
|
|
}
|
|
|
|
|
|
|
|
/* int to float conversions */
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @u8_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn u8_as_f16(a: u8) -> f16 {
|
|
|
|
// CHECK: uitofp i8 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @u16_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn u16_as_f16(a: u16) -> f16 {
|
|
|
|
// CHECK: uitofp i16 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @u32_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn u32_as_f16(a: u32) -> f16 {
|
|
|
|
// CHECK: uitofp i32 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @u64_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn u64_as_f16(a: u64) -> f16 {
|
|
|
|
// CHECK: uitofp i64 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @u128_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn u128_as_f16(a: u128) -> f16 {
|
|
|
|
// CHECK: uitofp i128 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @i8_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn i8_as_f16(a: i8) -> f16 {
|
|
|
|
// CHECK: sitofp i8 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @i16_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn i16_as_f16(a: i16) -> f16 {
|
|
|
|
// CHECK: sitofp i16 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @i32_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn i32_as_f16(a: i32) -> f16 {
|
|
|
|
// CHECK: sitofp i32 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @i64_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn i64_as_f16(a: i64) -> f16 {
|
|
|
|
// CHECK: sitofp i64 %{{.+}} to half
|
|
|
|
a as f16
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:53:56 -05:00
|
|
|
// CHECK-LABEL: @i128_as_f16
|
2024-05-16 04:05:34 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn i128_as_f16(a: i128) -> f16 {
|
|
|
|
// CHECK: sitofp i128 %{{.+}} to half
|
|
|
|
a as f16
|
2024-03-06 05:40:29 -06:00
|
|
|
}
|