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
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Functions for linking and calling the square root function in JIT-compiled code.
//!
//! This module provides functionality to:
//! - Link the external square root function (sqrt) into JIT-compiled code
//! - Generate Cranelift IR instructions to call sqrt within compiled functions
//!
//! The square root function operates on 64-bit floating point numbers (f64).
use FunctionBuilder;
use F64; // since sqrt works with doubles
use ;
use ;
/// Links the square root function to make it available for JIT compilation.
///
/// This function declares the external sqrt function to the Cranelift module,
/// making it available for use in JIT-compiled code. It creates a function
/// signature matching the standard sqrt function: f64 -> f64.
///
/// # Arguments
/// * `module` - The Cranelift module to declare the function in
///
/// # Returns
/// * `Ok(FuncId)` - The function ID that can be used to call sqrt
/// * `Err(String)` - Error message if declaration fails
/// Generates Cranelift IR instructions to call the square root function.
///
/// This helper function adds instructions to call the previously linked sqrt
/// function within a function being built with Cranelift.
///
/// # Arguments
/// * `builder` - The Cranelift function builder being used to construct the function
/// * `module` - The Cranelift module containing the function declaration
/// * `func_id` - The function ID returned by link_sqrt()
/// * `arg` - The Cranelift IR value to pass as the argument to sqrt
///
/// # Returns
/// The Cranelift IR value containing the result of calling sqrt