// Benchmark host compiled to f64 Wasm. rayKernel is generated from the same // KidLisp numeric plan as the scalar Wasm and WGSL kernels. No libc/imports. #include "ray-kernel.h" typedef struct { double x, y, z; } Vec; typedef struct { int found; Vec position, normal, color; double mirror; } Hit; static unsigned char pixels[512 * 512 * 4]; static int rays, intersections; static double greenX; static Vec v(double x, double y, double z) { return (Vec){x, y, z}; } static Vec add(Vec a, Vec b) { return v(a.x+b.x,a.y+b.y,a.z+b.z); } static Vec sub(Vec a, Vec b) { return v(a.x-b.x,a.y-b.y,a.z-b.z); } static Vec mul(Vec a, double b) { return v(a.x*b,a.y*b,a.z*b); } static Vec divv(Vec a, double b) { return v(a.x/b,a.y/b,a.z/b); } static double dot(Vec a, Vec b) { return a.x*b.x+a.y*b.y+a.z*b.z; } static Vec norm(Vec a) { return divv(a,__builtin_sqrt(dot(a,a))); } static double max(double a, double b) { return a>b?a:b; } static double min(double a, double b) { return a0.0001 && t1e-9) { double t=(-1-origin.y)/direction.y; if (t>0.0001 && t=0;i--) color=add(mul(locals[i],1-mirrors[i]),mul(color,mirrors[i])); return color; } static unsigned char channel(double x) { return (unsigned char)__builtin_floor(__builtin_sqrt(max(0,min(1,x)))*255+0.5); } __attribute__((export_name("render"))) int render(int width,int height,int bounces,double x) { if (width<1||width>512||height<1||height>512||bounces<0||bounces>3||!__builtin_isfinite(x)||x<-0.23||x>0.33) return 0; rays=intersections=0;greenX=x; for (int y=0;y