1
0
Fork 0
forked from AbleOS/ableos

fiddling and move some stuff to stn.math

This commit is contained in:
koniifer 2024-12-16 01:06:55 +00:00 committed by peony
parent 31b3d5e5ba
commit 0db997b435
5 changed files with 132 additions and 126 deletions

View file

@ -96,18 +96,19 @@ pub fn memory_msg_handler(
log::debug!(" {} pages", page_count); log::debug!(" {} pages", page_count);
} }
4 => unsafe { 4 => unsafe {
let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize; let count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap_unchecked()) as usize;
let src = u64::from_le_bytes(msg_vec[5..13].try_into().unwrap_unchecked()) as *const u8; let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8;
let dest = u64::from_le_bytes(msg_vec[13..21].try_into().unwrap_unchecked()) as *mut u8; let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8;
debug_assert!(src.addr() & 0xFFFF000000000000 != 0); debug_assert!(src.addr() & 0xFFFF000000000000 != 0);
debug_assert!(dest.addr() & 0xFFFF000000000000 != 0); debug_assert!(dest.addr() & 0xFFFF000000000000 != 0);
src.copy_to_nonoverlapping(dest, count); src.copy_to_nonoverlapping(dest, count);
}, },
5 => unsafe { 5 => unsafe {
let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize; let count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap_unchecked()) as usize;
let size = u32::from_le_bytes(msg_vec[5..9].try_into().unwrap_unchecked()) as usize; let size = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as usize;
let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8; let src =
let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8; u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *const u8;
let dest = u64::from_le_bytes(msg_vec[25..33].try_into().unwrap_unchecked()) as *mut u8;
debug_assert!(src.addr() & 0xFFFF000000000000 != 0); debug_assert!(src.addr() & 0xFFFF000000000000 != 0);
debug_assert!(dest.addr() & 0xFFFF000000000000 != 0); debug_assert!(dest.addr() & 0xFFFF000000000000 != 0);
memset(dest, src, count, size); memset(dest, src, count, size);

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,11 @@ $PAGE_SIZE := 4096
$MAX_ALLOC := 0xFF $MAX_ALLOC := 0xFF
$MAX_FREE := 0xFF $MAX_FREE := 0xFF
$uninit := fn($Expr: type): ?Expr { $uninit := fn($Expr: type): Expr {
return idk
}
$nulled := fn($Expr: type): ?Expr {
return null return null
} }
@ -65,12 +69,12 @@ $inl := fn(addr: u16): u32 {
return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg)) return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
} }
CopyMsg := packed struct {a: u8, count: u32, src: ^u8, dest: ^u8} CopyMsg := packed struct {a: u8, count: uint, src: ^u8, dest: ^u8}
$copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { $copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
return @eca(3, 2, &CopyMsg.(4, @intcast(count * @sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg)) return @eca(3, 2, &CopyMsg.(4, count * @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg))
} }
SetMsg := packed struct {a: u8, count: u32, size: u32, src: ^u8, dest: ^u8} SetMsg := packed struct {a: u8, count: uint, size: uint, src: ^u8, dest: ^u8}
$set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { $set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
return @eca(3, 2, &SetMsg.(5, @intcast(count), @intcast(@sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg)) return @eca(3, 2, &SetMsg.(5, count, @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg))
} }

View file

@ -1,97 +1,24 @@
ln_f64 := fn(x: f64): f64 {
if x <= 0.0 return -100000000000000000000000.0
if x == 1.0 return 0.0
if x == E return 1.0
scale := @as(f64, 0.0)
scaled_x := x
if scaled_x > 2.0 {
loop if scaled_x <= 2.0 break else {
scaled_x = scaled_x / E
scale += 1.0
}
} else if scaled_x < 1.0 {
loop if scaled_x >= 1.0 {
scaled_x = scaled_x * E
scale -= 1.0
}
}
guess := (scaled_x - 1.0) / (scaled_x + 1.0)
max_iter := 30
i := 0
loop if i == max_iter break else {
exp_g := exp_f64(guess)
f := exp_g - scaled_x
f_prime := exp_g
delta := f / (f_prime * (1.0 - 0.5 * f * f_prime / (f_prime * f_prime)))
guess = guess - delta
if abs_f64(delta) < 0.0000000001 break
i += 1
}
return guess + scale
}
exp_f64 := fn(x: f64): f64 {
result := @as(f64, 1.0)
term := @as(f64, 1.0)
n := @as(int, 1)
loop if n == 20 break else {
term = term * x / @itf(n)
result += term
if abs_f64(term) < 0.0000000001 break
n += 1
}
return result
}
abs_f64 := fn(x: f64): f64 {
if x < 0 return -x else return x
}
lerp_f64 := fn(v0: f64, v1: f64, t: f64): f64 {
return v0 + t * (v1 - v0)
}
render := @use("lib:render") render := @use("lib:render")
sunset := @use("lib:sunset_proto"); sunset := @use("lib:sunset_proto");
.{log} := @use("stn") .{math, log} := @use("stn")
// full mandelbrot // full mandelbrot
// $X_MIN := -2.0 $X_MIN := -2.0
// $X_MAX := 0.47 $X_MAX := 0.47
// $Y_MIN := -1.12 $Y_MIN := -1.12
// $Y_MAX := 1.12 $Y_MAX := 1.12
// a minibrot // a minibrot
$X_MIN := -0.94 // $X_MIN := -0.94
$X_MAX := -0.93 // $X_MAX := -0.93
$Y_MIN := 0.31 // $Y_MIN := 0.31
$Y_MAX := 0.306 // $Y_MAX := 0.306
$MAX_ITERATION := 300 $MAX_ITERATION := 300
$USE_SUNSET := false $USE_SUNSET := false
$COLOUR_R := 200 palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_GREEN, render.LIGHT_CYAN, render.LIGHT_BLUE, render.LIGHT_MAGENTA)
$COLOUR_G := 100
$COLOUR_B := 255
$LOG_2 := 0.693147180559945309417232121458176568
$E := 2.71828182845904523536028747135266250
$INTERIOR_COLOUR := render.BLACK
palette := [render.Color].(render.RED, render.YELLOW, render.GREEN, render.CYAN, render.BLUE, render.MAGENTA)
$LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color) $LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color)
example := fn(): void { example := fn(): void {
@ -108,7 +35,6 @@ example := fn(): void {
} else { } else {
screen = render.init(false) screen = render.init(false)
} }
screen.clear(INTERIOR_COLOUR)
x_scale := @as(f64, X_MAX - X_MIN) / @itf(@bitcast(screen.width)) x_scale := @as(f64, X_MAX - X_MIN) / @itf(@bitcast(screen.width))
y_scale := @as(f64, Y_MAX - Y_MIN) / @itf(@bitcast(screen.height)) y_scale := @as(f64, Y_MAX - Y_MIN) / @itf(@bitcast(screen.height))
@ -121,12 +47,7 @@ example := fn(): void {
y0 := @as(f64, Y_MIN) + @itf(@bitcast(py)) * y_scale y0 := @as(f64, Y_MIN) + @itf(@bitcast(py)) * y_scale
q := (x0 - 0.25) * (x0 - 0.25) + y0 * y0 q := (x0 - 0.25) * (x0 - 0.25) + y0 * y0
if q * (q + x0 - 0.25) <= 0.25 * y0 * y0 { if q * (q + x0 - 0.25) <= 0.25 * y0 * y0 | (x0 + 1.0) * (x0 + 1.0) + y0 * y0 <= 0.0625 {
px += 1
continue
}
if (x0 + 1.0) * (x0 + 1.0) + y0 * y0 <= 0.0625 {
px += 1 px += 1
continue continue
} }
@ -134,31 +55,26 @@ example := fn(): void {
x := @as(f64, 0.0) x := @as(f64, 0.0)
y := @as(f64, 0.0) y := @as(f64, 0.0)
iteration := 0 iteration := 0
// arbitrary, i cant tell the difference between 32 and 1 << 16
loop if x * x + y * y > @itf(1 << 16) | iteration == MAX_ITERATION break else { loop if x * x + y * y > 32.0 | iteration == MAX_ITERATION break else {
x_temp := x * x - y * y + x0 x_temp := x * x - y * y + x0
y = 2 * x * y + y0 y = 2 * x * y + y0
x = x_temp x = x_temp
iteration += 1 iteration += 1
} }
c := *screen.indexptr(px, py)
if c.r != INTERIOR_COLOUR.r | c.b != INTERIOR_COLOUR.b | c.g != INTERIOR_COLOUR.g {
px += 1
continue
}
if iteration < MAX_ITERATION { if iteration < MAX_ITERATION {
log_zn := ln_f64(x * x + y * y) / 2.0 log_zn := math.ln(f64, x * x + y * y) / 2
nu := ln_f64(log_zn / LOG_2) / LOG_2 nu := math.ln(f64, log_zn / math.LN_2) / math.LN_2
smoothed := @itf(@bitcast(iteration + 1)) - nu smoothed := @itf(@bitcast(iteration + 1)) - nu
smoothed_int := @fti(smoothed) smoothed_int := @fti(smoothed)
normalised := smoothed - @itf(smoothed_int) normalised := smoothed - @itf(smoothed_int)
colour0 := palette[@bitcast(smoothed_int) % LEN_PALETTE] colour0 := palette[@bitcast(smoothed_int) % LEN_PALETTE]
colour1 := palette[@bitcast(smoothed_int + 1) % LEN_PALETTE] colour1 := palette[@bitcast(smoothed_int + 1) % LEN_PALETTE]
colour := render.Color.{ colour := render.Color.{
r: @intcast(@fti(lerp_f64(@itf(@intcast(colour0.r)), @itf(@intcast(colour1.r)), normalised))), r: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.r)), @itf(@intcast(colour1.r)), normalised))),
g: @intcast(@fti(lerp_f64(@itf(@intcast(colour0.g)), @itf(@intcast(colour1.g)), normalised))), g: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.g)), @itf(@intcast(colour1.g)), normalised))),
b: @intcast(@fti(lerp_f64(@itf(@intcast(colour0.b)), @itf(@intcast(colour1.b)), normalised))), b: @intcast(@fti(math.lerp(f64, @itf(@intcast(colour0.b)), @itf(@intcast(colour1.b)), normalised))),
a: 0, a: 0,
} }
screen.put_pixel(.(px, py), colour) screen.put_pixel(.(px, py), colour)

View file

@ -16,6 +16,7 @@ comment = "Default AbleOS boot entry."
protocol = "limine" protocol = "limine"
kernel_path = "boot:///kernel_${ARCH}" kernel_path = "boot:///kernel_${ARCH}"
kernel_cmdline = "" kernel_cmdline = ""
# resolution = "2560x1440x24"
# resolution = "1920x1080x24" # resolution = "1920x1080x24"
resolution = "1024x768x24" resolution = "1024x768x24"
# resolution = "640x480x24" # resolution = "640x480x24"