mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
enable nontrapping fptoint feature in c and zig example
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
clang -O2 -Wno-incompatible-library-redeclaration --no-standard-libraries -ffast-math -Wl,--no-entry -Wl,--export-all -Wl,--import-memory -Wl,--initial-memory=262144 -Wl,-zstack-size=90000 -o cart.wasm cart.c --target=wasm32 && \
|
clang -O2 -Wno-incompatible-library-redeclaration --no-standard-libraries -ffast-math -Xclang -target-feature -Xclang +nontrapping-fptoint -Wl,--no-entry -Wl,--export-all -Wl,--import-memory -Wl,--initial-memory=262144 -Wl,-zstack-size=90000 -o cart.wasm cart.c --target=wasm32 && \
|
||||||
uw8 filter-exports cart.wasm cart.wasm && \
|
uw8 filter-exports cart.wasm cart.wasm && \
|
||||||
wasm-opt -Oz --fast-math --strip-producers -o cart.wasm cart.wasm && \
|
wasm-opt -Oz --fast-math --strip-producers -o cart.wasm cart.wasm && \
|
||||||
uw8 pack -l 9 cart.wasm cart.uw8
|
uw8 pack -l 9 cart.wasm cart.uw8
|
||||||
@@ -3,10 +3,6 @@
|
|||||||
IMPORT("env", "atan2") extern float atan2(float, float);
|
IMPORT("env", "atan2") extern float atan2(float, float);
|
||||||
IMPORT("env", "time") extern float time();
|
IMPORT("env", "time") extern float time();
|
||||||
|
|
||||||
int ftoi(float v) {
|
|
||||||
return __builtin_wasm_trunc_s_i32_f32(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
float sqrt(float v) {
|
float sqrt(float v) {
|
||||||
return __builtin_sqrt(v);
|
return __builtin_sqrt(v);
|
||||||
}
|
}
|
||||||
@@ -22,7 +18,7 @@ void upd() {
|
|||||||
float y = (float)(i / 320 - 120);
|
float y = (float)(i / 320 - 120);
|
||||||
float d = 40000.0f / sqrt(x * x + y * y + 1.0f);
|
float d = 40000.0f / sqrt(x * x + y * y + 1.0f);
|
||||||
float u = atan2(x, y) * 512.0f / 3.141f;
|
float u = atan2(x, y) * 512.0f / 3.141f;
|
||||||
unsigned char c = (unsigned char)(ftoi(d + t * 2.0f) ^ ftoi(u + t)) >> 4;
|
unsigned char c = (unsigned char)((int)(d + t * 2.0f) ^ (int)(u + t)) >> 4;
|
||||||
FRAMEBUFFER[i] = c;
|
FRAMEBUFFER[i] = c;
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ pub fn build(b: *std.build.Builder) void {
|
|||||||
|
|
||||||
const lib = b.addSharedLibrary("cart", "main.zig", .unversioned);
|
const lib = b.addSharedLibrary("cart", "main.zig", .unversioned);
|
||||||
lib.setBuildMode(mode);
|
lib.setBuildMode(mode);
|
||||||
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
lib.setTarget(.{
|
||||||
|
.cpu_arch = .wasm32,
|
||||||
|
.os_tag = .freestanding,
|
||||||
|
.cpu_features_add = std.Target.wasm.featureSet(&.{ .nontrapping_fptoint })
|
||||||
|
});
|
||||||
lib.import_memory = true;
|
lib.import_memory = true;
|
||||||
lib.initial_memory = 262144;
|
lib.initial_memory = 262144;
|
||||||
lib.max_memory = 262144;
|
lib.max_memory = 262144;
|
||||||
|
|||||||
Reference in New Issue
Block a user