diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 920702173..80a0251c5 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -471,6 +471,10 @@ playerdata_t g_player[MAXPLAYERS]; ]] -- functions +ffi.cdef[[ +int32_t ksqrt(int32_t num); +]] + ffi.cdef "double gethitickms(void);" local ffiC = ffi.C diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index eb9288162..bf39748b5 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -26,6 +26,7 @@ nextspritestat; headsectbunch; nextsectbunch; +ksqrt; hitscan; actor; diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index 68f007480..78dcfe579 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -127,6 +127,7 @@ gameevent(gv.EVENT_JUMP, gameevent(gv.EVENT_ENTERLEVEL, function() + -- NOTE: times are for helixhorned (Core2Duo 3GHz) local i local N = 1e6 local t = gv.gethitickms() @@ -137,9 +138,28 @@ gameevent(gv.EVENT_ENTERLEVEL, t = gv.gethitickms()-t - -- NOTE: for me (helixhorned), about 40 ns per call + -- x86: 40ns/call, x86_64: 290 ns/call printf("%d gethitickms() calls took %.03f ms (%.03f us/call)", N, t, (t*1000)/N) + + local sum=0 + t = gv.gethitickms() + for i=1,N do sum = sum+gv.ksqrt(i) end + t = gv.gethitickms()-t + -- x86_64: 14ns/call + printf("%d ksqrt() calls took %.03f ms (%.03f us/call) [sum=%f]", + N, t, (t*1000)/N, sum) + + sum=0 + t = gv.gethitickms() + for i=1,N do sum = sum+math.sqrt(i) end + t = gv.gethitickms()-t + -- x86_64: 7ns/call + printf("%d math.sqrt() calls took %.03f ms (%.03f us/call) [sum=%f]", + N, t, (t*1000)/N, sum) + + printf("sqrt(0xffffffff) = %f(ksqrt) %f(math.sqrt)", + gv.ksqrt(-1), math.sqrt(0xffffffff)) end )