Skip to content

Commit

Permalink
Modularize special-math code HT @adri326
Browse files Browse the repository at this point in the history
  • Loading branch information
dcnorris committed Jan 11, 2025
1 parent ff252d6 commit 7b2159e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
19 changes: 1 addition & 18 deletions src/machine/system_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
use crrl::{ed25519, secp256k1, x25519};

#[cfg(feature = "special-math")]

This comment has been minimized.

Copy link
@triska

triska Jan 11, 2025

Is there any reason to make this contingent on a flag? The reason we did this in some cases is that compilation with certain features is not supported on all targets, notably WASM. For pure Rust crates, compilation should work on all targets.

This comment has been minimized.

Copy link
@dcnorris

dcnorris Jan 11, 2025

Author Owner

I had supposed it might be desirable to de-select this feature, but perhaps I misunderstood mthom#2765 (comment). I would be very glad to remove this feature flag!

This comment has been minimized.

Copy link
@triska

triska Jan 11, 2025

Since this feature is now only available if a library is loaded, Scryer remains in its strictly conforming mode already when it starts! Only when the library is loaded is the feature made available. That's an important difference to building this function into standard arithmetic expressions.

use puruspe::error::erf;
pub(crate) mod special_math;

#[cfg(feature = "tls")]
use native_tls::{Identity, TlsAcceptor, TlsConnector};
Expand Down Expand Up @@ -7751,23 +7751,6 @@ impl Machine {
);
}

#[cfg(feature = "special-math")]
#[inline(always)]
pub(crate) fn erf(&mut self) {
let x = self.deref_register(1);
let x = match Number::try_from(x) {
Ok(Number::Float(n)) => n.into_inner(),
Ok(Number::Fixnum(n)) => n.get_num() as f64,
Ok(Number::Integer(n)) => n.to_f64().value(),
_ => {
unreachable!()
}
};
let erf_x = float_alloc!(erf(x), self.machine_st.arena);
let return_value = self.deref_register(2);
self.machine_st.unify_f64(erf_x, return_value);
}

#[inline(always)]
pub(crate) fn crypto_curve_scalar_mult(&mut self) {
let stub_gen = || functor_stub(atom!("crypto_curve_scalar_mult"), 4);
Expand Down
23 changes: 23 additions & 0 deletions src/machine/system_calls/special_math.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::machine::Number;
use crate::Machine;
use puruspe::error::*;

impl Machine {

#[inline(always)]
pub(crate) fn erf(&mut self) {
let x = self.deref_register(1);
let x = match Number::try_from(x) {
Ok(Number::Float(n)) => n.into_inner(),
Ok(Number::Fixnum(n)) => n.get_num() as f64,
Ok(Number::Integer(n)) => n.to_f64().value(),
_ => {
unreachable!()
}
};
let erf_x = float_alloc!(erf(x), self.machine_st.arena);
let return_value = self.deref_register(2);
self.machine_st.unify_f64(erf_x, return_value);
}

}

0 comments on commit 7b2159e

Please sign in to comment.