about summary refs log tree commit diff
path: root/library/stdarch/crates/intrinsic-test/src/common/intrinsic.rs
blob: 95276d19b72f9a3083a1b92c5860dfb60cc60778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use super::argument::ArgumentList;
use super::intrinsic_helpers::{IntrinsicTypeDefinition, TypeKind};

/// An intrinsic
#[derive(Debug, PartialEq, Clone)]
pub struct Intrinsic<T: IntrinsicTypeDefinition> {
    /// The function name of this intrinsic.
    pub name: String,

    /// Any arguments for this intrinsic.
    pub arguments: ArgumentList<T>,

    /// The return type of this intrinsic.
    pub results: T,

    /// Any architecture-specific tags.
    pub arch_tags: Vec<String>,
}

pub fn format_f16_return_value<T: IntrinsicTypeDefinition>(intrinsic: &Intrinsic<T>) -> String {
    // the `intrinsic-test` crate compares the output of C and Rust intrinsics. Currently, It uses
    // a string representation of the output value to compare. In C, f16 values are currently printed
    // as hexadecimal integers. Since https://github.com/rust-lang/rust/pull/127013, rust does print
    // them as decimal floating point values. To keep the intrinsics tests working, for now, format
    // vectors containing f16 values like C prints them.
    let return_value = match intrinsic.results.kind() {
        TypeKind::Float if intrinsic.results.inner_size() == 16 => "debug_f16(__return_value)",
        _ => "format_args!(\"{__return_value:.150?}\")",
    };

    String::from(return_value)
}