From c44871bfa852a4ec4c85cde2e390d7650ec64845 Mon Sep 17 00:00:00 2001 From: Don Ward Date: Tue, 30 Jul 2024 16:21:08 +0100 Subject: [PATCH] Accomodate differences betwe 32-bit and 64-bit builds of rngRbt --- plugins/rngLibraries/rngConfidence.icn | 55 +++++++++++++-------- plugins/rngLibraries/rngRbt/ecrypt-config.h | 3 ++ plugins/rngLibraries/rngRbt/rngRbt.c | 14 +++++- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/plugins/rngLibraries/rngConfidence.icn b/plugins/rngLibraries/rngConfidence.icn index 4cdc8c094..f53facad4 100644 --- a/plugins/rngLibraries/rngConfidence.icn +++ b/plugins/rngLibraries/rngConfidence.icn @@ -306,7 +306,11 @@ $else if not("rngRbt" == loadrng("rngRbt")) then { write(**** "loadrng(\"rngRbt\") failed (Error) ****") } else { - if not (&random := a := array(192/intBits(),42)) then { + a := array(192/intBits(),42) + if intBits() = 32 then { + a[2] := a[4] := a[6] := 0 + } + if not (&random := a) then { Failure("**** Initialization with an array failed (Error) ****") } else { printRandomState() @@ -422,7 +426,7 @@ $else # One round of ClosePool(); MakePool() is usually enough to cause the # invocatiotion of the garbage collector ClosePool() - MakePool() + MakePool(18) printGC("After recreating thread pool") printLibChain("After recreating thread pool: ") @@ -442,19 +446,21 @@ $else printLibChain("After 5th sequence test: ") write("The current rng library is <", loadrng(), ">") + # reload the library to guarantee a clean start + alterRng(loadrng()) &random := 42 every 1 to 1000000 do Rbt1000000 := ?0 write("The value of the millionth number after 42 is ", Rbt1000000) - banner("Run Iconx in parallel") + banner("Run Rbt in parallel") every n := 1 to 16 do { - every 1 to n do Dispatch(check1000000,5, "rngIconEx", Icon1000000) + every 1 to n do Dispatch(check1000000,5, "rngRbt", Rbt1000000) write("main waiting ...") every 1 to n do <<@ } - banner("Run Rbt in parallel") + banner("Run Iconx in parallel") every n := 1 to 16 do { - every 1 to n do Dispatch(check1000000,5, "rngRbt", Rbt1000000) + every 1 to n do Dispatch(check1000000,5, "rngIconEx", Icon1000000) write("main waiting ...") every 1 to n do <<@ } @@ -499,16 +505,21 @@ procedure check1000000(limit, rnglib, theLastOne) local x, differences differences := 0 every 1 to limit do { - loadrng(rnglib) + # Force a new copy of the library by loading something else + loadrng(if rnglib == "rngIcon" then "rngRbt" else "rngIcon") + loadrng(rnglib) &random := 42 every 1 to 1000000 do x := ?0 - if x ~= theLastOne then differences +:= 1 + if x ~= theLastOne then { + differences +:= 1 + write("Thread ", serial(¤t), " ", x, " ~= ", theLastOne) + } } if differences = 0 then { - write("Thread ", serial(¤t), " no differences") + write("Thread ", serial(¤t), " (", rnglib, ") no differences") } else { - Failure("Thread ", serial(¤t), + Failure("Thread ", serial(¤t), " (", rnglib, ") ", " **** ", differences, " differences (Error) ****") } @>&main @@ -551,10 +562,12 @@ end # Print out garbage collector stats. procedure printGC(s) - writes(s, ": GC heap: ", &collections) - writes(" static: ", &collections) - writes(" string: ", &collections) - write(" block: ", &collections) + local Heap, Static, String, Block + Heap := &collections + every Static := &collections \ 2 + every String := &collections \ 3 + every Block := &collections \4 + write(s, ": GC heap: ", Heap, " static: ", Static, " string: ", String, " block: ", Block) end # Print out value of &random (or a copy) @@ -601,13 +614,15 @@ $endif end # Note failures as we go along and produce a summary at the end -procedure Failure(msg) +procedure Failure(msg[]) + local m static FT, total initial { FT := mutex(table(0)) ; total := 0} - if \msg then { - write(&errout, msg) + if *msg > 0 then { + m := ""; every m ||:= !msg + write(&errout, m) critical FT: { - FT[msg] +:= 1 + FT[m] +:= 1 total +:= 1 } } else { # Produce a Final summary @@ -615,8 +630,8 @@ procedure Failure(msg) write(&errout, "All tests passed") } else { write(&errout, total, " test", if total = 1 then " failed" else "s failed") - every msg := key(FT) do { - write(&errout, left(FT[msg],6), msg) + every m := key(FT) do { + write(&errout, left(FT[m],6), m) } write(&errout, "Verbose output is on stdout") } diff --git a/plugins/rngLibraries/rngRbt/ecrypt-config.h b/plugins/rngLibraries/rngRbt/ecrypt-config.h index 4ea47970e..8c259be97 100644 --- a/plugins/rngLibraries/rngRbt/ecrypt-config.h +++ b/plugins/rngLibraries/rngRbt/ecrypt-config.h @@ -37,6 +37,9 @@ #define ECRYPT_LITTLE_ENDIAN #elif defined(__ARMEL__) /* Raspberry Pi (gcc) */ #define ECRYPT_LITTLE_ENDIAN +#elif defined(__AARCH64EL__) /* Raspberry Pi 64 bit (gcc) */ +#define ECRYPT_LITTLE_ENDIAN + /* * The BIG endian machines: diff --git a/plugins/rngLibraries/rngRbt/rngRbt.c b/plugins/rngLibraries/rngRbt/rngRbt.c index 0810c065e..e94839eee 100644 --- a/plugins/rngLibraries/rngRbt/rngRbt.c +++ b/plugins/rngLibraries/rngRbt/rngRbt.c @@ -205,11 +205,21 @@ int putSeed(word type, word size, void *param) /* Not initialized */ u64 keyIv[3]; /* "stretch" the data to 192 bits. There are probably better ways to do this. */ - keyIv[0] = keyIv[1] = keyIv[2] = *(u64 *)param; + if (size == 4) { /* 32-bit system */ + keyIv[0] = keyIv[1] = keyIv[2] = *(u32 *)param; + } else { + keyIv[0] = keyIv[1] = keyIv[2] = *(u64 *)param; + } return putSeed(T_Intarray, sizeof(keyIv), keyIv); } else { /* This is a reinitilization with an integer: just change the IV */ - ECRYPT_ivsetup(state, param); + u64 keyIv; + if (size == 4) { /* 32-bit system */ + keyIv = *(u32 *)param; + } else { + keyIv = *(u64 *)param; + } + ECRYPT_ivsetup(state, (const u8 *) &keyIv); state->cached = 1.0; /* Clear any stored value */ } }