From 64aa1de7df2f03e1f9e2c6135644c8fb97e0e98d Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Tue, 12 Sep 2023 22:12:46 -0700 Subject: [PATCH] add fenv cache to task struct Fixes #51277 --- src/julia.h | 4 ++++ src/task.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/julia.h b/src/julia.h index 92c383ccc5525..b8e392fa8a9bb 100644 --- a/src/julia.h +++ b/src/julia.h @@ -19,6 +19,7 @@ #include "libsupport.h" #include #include +#include #include "htable.h" #include "arraylist.h" @@ -2050,6 +2051,9 @@ typedef struct _jl_task_t { uint16_t priority; // hidden state: + // cached floating point environment + // only updated at task switch + fenv_t fenv; #ifdef USE_TRACY const char *name; diff --git a/src/task.c b/src/task.c index 73d9033f0cb50..7d1c1c82840b3 100644 --- a/src/task.c +++ b/src/task.c @@ -503,6 +503,8 @@ JL_NO_ASAN static void ctx_switch(jl_task_t *lastt) jl_set_pgcstack(&t->gcstack); jl_signal_fence(); lastt->ptls = NULL; + fegetenv(&lastt->fenv); + fesetenv(&t->fenv); #ifdef MIGRATE_TASKS ptls->previous_task = lastt; #endif @@ -1079,6 +1081,7 @@ JL_DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, jl_value_t *completion t->excstack = NULL; t->started = 0; t->priority = 0; + fegetenv(&t->fenv); jl_atomic_store_relaxed(&t->tid, t->copy_stack ? jl_atomic_load_relaxed(&ct->tid) : -1); // copy_stacks are always pinned since they can't be moved t->threadpoolid = ct->threadpoolid; t->ptls = NULL;