Report no value for in-process native entries without a result
NativeInstanceRun copied the result register even for a void entry, so an embedder that compared the value saw whatever the entry's last call returned. The site's Printing kernel failed this way once allocation stopped leaving zero there. native_load runs a void entry whose last call returns 42 and expects no result and zero.
This commit is contained in:
1 parent
3c905a61c1
commit
fa65a3fbd9
5 files changed
+34
-2
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- An in-process native run of an entry without a result reports zero instead of whatever its last call left in the result register, as the portable engine does.
|
||||
- In-process native x86-64 code allocates and frees blocks of up to 256 bytes itself: 16-byte classes with free lists and chunks per instance, behind a 16-byte header that still rejects a block with the wrong count or element size. Larger blocks and growth go through the host as before. Binary-trees runs in under half the time of the C reference (46 ms against 98 ms on Alpha), down from 223 ms.
|
||||
- Native x86-64 division and remainder by any other positive constant use a high multiply instead of `idiv`, signed and unsigned at every integer width. FASTA, whose generator takes `%139968` and `%1000000007` per byte, runs in less than half the time.
|
||||
- Native x86-64 code starts every function on a 32-byte boundary and keeps each branch, compare-and-branch pair, call and return inside one 32-byte block, with NOPs where needed. Intel cores with the jump-erratum microcode fix keep such loops in their decoded-instruction cache, so a change elsewhere in a program no longer moves a hot loop's speed by up to a third.
|
||||
|
||||
@@ -1764,7 +1764,9 @@ NativeInstanceRun(NativeInstance *instance, long long *result, int *has_result)
|
||||
}
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
*result = value;
|
||||
/* An entry without a result leaves whatever its last call put in the
|
||||
* result register; it reports zero, as the engine does. */
|
||||
*result = instance->has_result ? value : 0;
|
||||
*has_result = instance->has_result;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Executable → Regular
+1
-1
@@ -15,7 +15,7 @@ trap 'rm -rf "$work"' EXIT HUP INT TERM
|
||||
unset DISPLAY WAYLAND_DISPLAY XAUTHORITY DBUS_SESSION_BUS_ADDRESS SESSION_MANAGER
|
||||
export HARMONY_DESKTOP_RECOVERY=0
|
||||
|
||||
for entry in Answer Spin Overflow Bump Long Trapper Retain Grow Fields; do
|
||||
for entry in Answer Quiet Spin Overflow Bump Long Trapper Retain Grow Fields; do
|
||||
"$zi2zx" --root "$repo/tests/spec" -I "$repo/std" --entry "native_bundle:$entry" \
|
||||
-o "$work/$entry.zx" "$repo/tests/spec/native_bundle.zi"
|
||||
done
|
||||
|
||||
@@ -36,6 +36,24 @@ instantiate(const Bundle *bundle, BundleBackendPolicy policy, int max_steps,
|
||||
return BundleInstantiateWithOptions(bundle, bindings, binding_count, &options);
|
||||
}
|
||||
|
||||
/* An entry without a result reports none, and zero, whatever its last call
|
||||
* left in the result register. */
|
||||
static void
|
||||
voids(void)
|
||||
{
|
||||
Bundle *bundle = open_entry("Quiet");
|
||||
BundleInstance *instance = instantiate(bundle, BUNDLE_BACKEND_NATIVE, 0, NULL, 0);
|
||||
long long result = -1;
|
||||
int present = 1;
|
||||
assert(instance != NULL && BundleInstanceBackend(instance) == BUNDLE_EXECUTION_NATIVE_X86_64);
|
||||
for(int round = 0; round < 3; round++) {
|
||||
assert(BundleInstanceRun(instance, &result, &present));
|
||||
assert(!present && result == 0);
|
||||
}
|
||||
BundleInstanceClose(instance);
|
||||
BundleClose(bundle);
|
||||
}
|
||||
|
||||
static void
|
||||
run(BundleInstance *instance, BundleExecutionBackend backend, long long expected)
|
||||
{
|
||||
@@ -313,6 +331,7 @@ main(int argc, char **argv)
|
||||
strcpy(directory, argv[1]);
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
policies();
|
||||
voids();
|
||||
limits();
|
||||
state();
|
||||
checked();
|
||||
|
||||
@@ -52,6 +52,16 @@ Fields :: () -> s32 {
|
||||
#program_export
|
||||
Answer :: () -> s32 { return 42 }
|
||||
|
||||
// Calls itself, so it stays a call: its 42 is in the result register when
|
||||
// Quiet returns, and a run of Quiet still has no result.
|
||||
Countdown :: (n: s64) -> s64 {
|
||||
if n == 0 { return 42 }
|
||||
return Countdown(n - 1)
|
||||
}
|
||||
|
||||
#program_export
|
||||
Quiet :: () { unused Countdown(3) }
|
||||
|
||||
// Stops only when its fuel runs out.
|
||||
#program_export
|
||||
Spin :: () -> s32 {
|
||||
|
||||
Reference in new issue
Block a user