#WIP: C port of Omeganum

1 messages · Page 1 of 1 (latest)

hushed ether
#

This thread simply serves as my hub for publishing progress on my C port of omeganum (I previously did this in the talisman thread, but it's not entirely related and it clogged that up a bit). The idea is to be backwards compatible with the existing Lua version of omeganum (such that all the methods still exist, they're just fronts for corresponding C functions).

As for existing progress, I've got a working build system and functional linking between Lua and C. It's designed for dynamic linkage with Lua (no need to recompile Lua, we have ffi). Garbage collection is working, C resources are properly freed when their associated object in Lua is collected. Basic functions like creation and comparison of bigs are completed.

Anyways, rants and progress will ensue! Maybe when I get this done it can be implemented in Talisman... Maybe if it's fast enough. Technically since the resources are mostly stored in C it's efficient? Who knows!

#

p.s. im working off of the Lua port. i don't feel like reading JS (or rust, yes there is a rust omeganum port out there)

#
local bigmt = {
    __gc = function(self)
        omeganum.freeOmega(rawget(getmetatable(self), "data"))
    end,
    __call = function(self, ...)
        return rawget(getmetatable(self), "data")
    end
}

local function makeSafe(big)
    local toRet = newproxy(true)
    local mt = getmetatable(toRet)
    mt.__gc = bigmt.__gc
    mt.__call = bigmt.__call
    mt.data = big
    return toRet
end

anyways i posted this code in the talisman thread but thoughts on this abomination? pre 5.2 lua truly is a language

#

how it feels putting a cdata inside a table inside a userdata

#

cdata is a luajit thing but still egg

quick mica
#

very cool! have you seen lmapm by any chance?

#

I'm curious to see how much overhead is introduced by the ffi layer

hushed ether
# quick mica very cool! have you seen lmapm by any chance?

i have not! it looks like it uses the lua C library, not ffi, but still worth looking at if i need a reference, thanks
as for the ffi overhead, it probably exists and is measurable (so slower than normal manual lua-c) but according to https://luajit.org/ext_ffi.html its still 20x faster than typical lua in extreme cases
and for omeganum i believe that its one of those extreme cases, the reason its so slow when you get massive numbers is the need for operations on massive tables (accesses to large tables in lua are very slow, see for i = 1, 10000 do _G[i] = true end and watch your frames die). so C omeganum will help quite a bit with operations on bignumber data structures that are above ##10000 or so

hushed ether
#

tbh im not sure if using exclusively integers in a table allows for accessing to be faster, idk if lua implements that

#

if it is that statement is void

harsh hare
weary prawn
#

Does your build system support C++ in addition to C? I’ve actually been looking into working on a similar style of mod, to optimize the calculation event list processing.

hushed ether
#

yeah, im not ever gonna be using cpp though

#

ive lightly touched it and im not a fan

hushed ether
#

to be honest i could just, not write this at all, and instead just bind talisman to the rust port instead

#

but im not doing that because thats no fun 🔥

#

oh wait

#

ffi would not want to work with rust would it

#

im not sure

harsh hare
#

I doubt it would work with rust

hushed ether
#

okay nvm looks like it does

harsh hare
#

how

hushed ether
#

extern "C" in the rust declarations

#

which is kinda cheating but bleh

forest kernel
weary prawn
pseudo sage
#

yeah Rust FFI is pretty easy, you just have to explicitly define the interfaces in a way that's compatible with whatever you're calling

quick mica
#

rust is ffi compatible with C

#

you don't even need to make it safe

#

just use rust

#

I'm bully you into it

hushed ether
#

nuh uh

#

barely functional btw

#

im unsure if this lua file works with the dll i just posted but bleh

#

youll also need to change line 9 to wherever you put the dll

#

not that theres any reason for you to want to run this yourself, but its whatever

#

and obviously most stuff isnt implemented rn

#

wait why are those enums defined i removed those lol

#

that makes the omeganumber definition just wrong

#

lemme fix that rq

#

why is xmalloc defined too

#

that is a shitshow

#

much less embarrassing

#

yeah apparently setting my thingamajigs did not work

hushed ether
#

i should probably git this stuff

#

bleh

quick mica
#

feels good to see raw C for once

#

nice work, this is all looking pretty good

#

and yeah you probably should

hushed ether
hushed ether
hushed ether
#

switching back to cpp compiler because i finally got vs2022 to work

#

who doesnt love writing raw C in cpp

#

this also means the github is gonna be out of date until i decide to put in the 10 minutes of work itd take to make it not out of date

#

and god knows im not capable of doing 10 minutes of work

quick mica
#

replace the mult impl with a Schönhage–Strassen FFT

#

really squeeze out that performance

#

why are you using malloc + memset instead of calloc?

#

I cloned the code and have been playing around with it

harsh hare
#

I need experience with C so I also started coding something by the way: https://github.com/EIG520/omeganum.c (though I’m not sure how well it works and I don’t do the DLL stuff right now so it’s not really useful anyway)

quick mica
#

my turn to implement it in rust 😎

harsh hare
#

Well I would have done that but someone else did already and I felt I should have some diversity in my GitHub projects

quick mica
#

~~my turn to implement it in rust 😎 ~~ my turn to implement it in nim 😎

harsh hare
#

Fair enough

#

Zig when???

quick mica
#

I haven't looked at it until now

harsh hare
#

Yeah there are tons of ports of omeganum

#

Probably because it is kind of fun (uncommented code with no variable naming = more critical thinking)

harsh hare
hushed ether
hushed ether
#

Big:parse is kicking my ass

#

oh wait

#

no wonder i recognized the omeganum rust port developer

#

they're like Here

#

@flat sky egg

flat sky
#

hii :3

flat sky
#

oh shit f128 has log10 now i should add that

#

uhh later

#

working on a webfishing mod rn

quick mica
#

:-)

#

good work should be congratulated haha

hushed ether
#

THERES NO FUCKING WAY

#

this has been here the whole time

#

i feel like an idiot omg

#

of course i dont need to wrap it in a goddamn userdata and then put a finalizer in that

#

okay nevermind apparently i cant because that crashes for some odd reason

#

its fine my method is probably honestly relatively the same

#

does the same thing except is very slightly slower and very slightly more memory intensive

hushed ether
#

ah thats funny that comment is still there

#

thanks visual studio

#

i wonder if i can rename that without it crying to me about not having it

#

oh hey i can

#

sick

hushed ether
#

im probably not even writing anything functional right now its just a walking talking buffer overflow

harsh hare
#

valgrind?