mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
make use of nontrapping-fptoint, add tunnel.cwa as reference
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
rustc --target=wasm32-unknown-unknown --crate-type cdylib -C opt-level="z" -C "link-args=--import-memory --initial-memory=262144 -zstack-size=90000" -o tunnel.wasm tunnel.rs && \
|
||||
rustc --target=wasm32-unknown-unknown -C target-feature=+nontrapping-fptoint --crate-type cdylib -C opt-level="z" -C "link-args=--import-memory --initial-memory=262144 -zstack-size=90000" -o tunnel.wasm tunnel.rs && \
|
||||
uw8 filter-exports tunnel.wasm tunnel.wasm && \
|
||||
wasm-opt -Oz --strip-producers -o tunnel.wasm tunnel.wasm && \
|
||||
uw8 pack -l 9 tunnel.wasm tunnel.uw8
|
||||
|
||||
@@ -27,15 +27,6 @@ fn sqrt(v: f32) -> f32 {
|
||||
unsafe { core::intrinsics::sqrtf32(v) }
|
||||
}
|
||||
|
||||
fn ftoi(v: f32) -> i32 {
|
||||
// The compiler is allowed to do bad things to our code if this
|
||||
// ever results in a value that doesn't fit in an i32.
|
||||
// (the joy of undefined behavior)
|
||||
// But that would trap in wasm anyway, so we don't really
|
||||
// care.
|
||||
unsafe { v.to_int_unchecked() }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn upd() {
|
||||
let mut i: i32 = 0;
|
||||
@@ -43,9 +34,9 @@ pub fn upd() {
|
||||
let t = time() * 63.;
|
||||
let x = (i % 320 - 160) as f32;
|
||||
let y = (i / 320 - 120) as f32;
|
||||
let d = 40000 as f32 / sqrt(x * x + y * y + 1.);
|
||||
let d = 40000 as f32 / sqrt(x * x + y * y);
|
||||
let u = atan2(x, y) * 512. / 3.141;
|
||||
let c = (ftoi(d + t * 2.) ^ ftoi(u + t)) as u8 >> 4;
|
||||
let c = ((d + t * 2.) as i32 ^ (u + t) as i32) as u8 >> 4;
|
||||
unsafe {
|
||||
*((120 + i) as *mut u8) = c;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user