Skip to main content

slatec_src/
lib.rs

1#![no_std]
2#![deny(missing_docs)]
3
4//! Native implementation-provider selection for `slatec`.
5//!
6//! This crate intentionally exposes no numerical API. Its Cargo features
7//! select one native provider and keep that provider in the dependency graph.
8//! The runtime library is `no_std`; acquisition, compilation, and linker
9//! configuration are confined to its hosted Cargo build script.
10
11/// Keeps the selected implementation provider in the final dependency graph.
12///
13/// Safe wrapper crates call this zero-cost marker internally. It performs no
14/// runtime initialization and is not a numerical interface.
15#[doc(hidden)]
16#[inline(never)]
17pub fn ensure_linked() {}
18
19#[cfg(feature = "optimization-linear-programming-in-memory")]
20mod lp_forbidden_io {
21    use core::sync::atomic::{AtomicUsize, Ordering};
22
23    static PAGE_ENTRIES: AtomicUsize = AtomicUsize::new(0);
24    static OPEN_ENTRIES: AtomicUsize = AtomicUsize::new(0);
25    static CLOSE_ENTRIES: AtomicUsize = AtomicUsize::new(0);
26
27    pub(crate) fn reset() {
28        PAGE_ENTRIES.store(0, Ordering::SeqCst);
29        OPEN_ENTRIES.store(0, Ordering::SeqCst);
30        CLOSE_ENTRIES.store(0, Ordering::SeqCst);
31    }
32
33    pub(crate) fn counts() -> (usize, usize, usize) {
34        (
35            PAGE_ENTRIES.load(Ordering::SeqCst),
36            OPEN_ENTRIES.load(Ordering::SeqCst),
37            CLOSE_ENTRIES.load(Ordering::SeqCst),
38        )
39    }
40
41    #[unsafe(no_mangle)]
42    unsafe extern "C" fn dprwpg_(
43        _key: *mut i32,
44        _page: *mut i32,
45        _page_len: *mut i32,
46        _real: *mut f64,
47        _integer: *mut i32,
48    ) {
49        PAGE_ENTRIES.fetch_add(1, Ordering::SeqCst);
50    }
51
52    #[unsafe(no_mangle)]
53    unsafe extern "C" fn prwpge_(
54        _key: *mut i32,
55        _page: *mut i32,
56        _page_len: *mut i32,
57        _real: *mut f32,
58        _integer: *mut i32,
59    ) {
60        PAGE_ENTRIES.fetch_add(1, Ordering::SeqCst);
61    }
62
63    #[unsafe(no_mangle)]
64    unsafe extern "C" fn dprwvr_(
65        _key: *mut i32,
66        _page: *mut i32,
67        _page_len: *mut i32,
68        _real: *mut f64,
69        _integer: *mut i32,
70    ) {
71        PAGE_ENTRIES.fetch_add(1, Ordering::SeqCst);
72    }
73
74    #[unsafe(no_mangle)]
75    unsafe extern "C" fn prwvir_(
76        _key: *mut i32,
77        _page: *mut i32,
78        _page_len: *mut i32,
79        _real: *mut f32,
80        _integer: *mut i32,
81    ) {
82        PAGE_ENTRIES.fetch_add(1, Ordering::SeqCst);
83    }
84
85    #[unsafe(no_mangle)]
86    unsafe extern "C" fn sopenm_(_unit: *mut i32, _record_len: *mut i32) {
87        OPEN_ENTRIES.fetch_add(1, Ordering::SeqCst);
88    }
89
90    #[unsafe(no_mangle)]
91    unsafe extern "C" fn sclosm_(_unit: *mut i32) {
92        CLOSE_ENTRIES.fetch_add(1, Ordering::SeqCst);
93    }
94}
95
96/// Clears the forbidden paging/I/O entry counters for one serialized LP call.
97///
98/// This is an internal provider contract hook, not a paging interface.
99#[cfg(feature = "optimization-linear-programming-in-memory")]
100#[doc(hidden)]
101pub fn reset_lp_forbidden_io_entries() {
102    lp_forbidden_io::reset();
103}
104
105/// Returns `(paging, open, close)` forbidden-entry counts.
106///
107/// A supported in-memory LP call requires all three values to remain zero.
108#[cfg(feature = "optimization-linear-programming-in-memory")]
109#[doc(hidden)]
110#[must_use]
111pub fn lp_forbidden_io_entries() -> (usize, usize, usize) {
112    lp_forbidden_io::counts()
113}