File: f128-wasm32-callconv.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 934,168 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (49 lines) | stat: -rw-r--r-- 1,255 bytes parent folder | download | duplicates (11)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Verify that Rust implements the expected calling convention for `f128`

//@ add-core-stubs
//@ compile-flags: -Copt-level=3 --target wasm32-wasip1
//@ needs-llvm-components: webassembly

#![crate_type = "lib"]
#![no_std]
#![no_core]
#![feature(no_core, lang_items, f128)]

extern crate minicore;

extern "C" {
    fn extern_call(arg0: f128);
    fn extern_ret() -> f128;
}

#[no_mangle]
pub extern "C" fn pass(_arg0: u32, arg1: f128) {
    // CHECK-LABEL: @pass(
    // an f128 is passed via registers
    // CHECK-SAME: fp128 noundef %arg1
    // CHECK: call void @extern_call
    unsafe { extern_call(arg1) };
}

// Check that we produce the correct return ABI
#[no_mangle]
pub extern "C" fn ret(_arg0: u32, arg1: f128) -> f128 {
    // CHECK-LABEL: @ret(
    // but an f128 is returned via the stack
    // CHECK-SAME: sret
    // CHECK: store fp128 %arg1
    // CHECK-NEXT: ret void
    arg1
}

// Check that we consume the correct return ABI
#[no_mangle]
pub extern "C" fn forward(dst: *mut f128) {
    // CHECK-LABEL: @forward
    // CHECK-SAME: ptr{{.*}} %dst)
    // without optimizatons, an intermediate alloca is used
    // CHECK: call void @extern_ret
    // CHECK: store fp128
    // CHECK: ret void
    unsafe { *dst = extern_ret() };
}