From f38dc712990ae91fa0dfa9749df543bb175856bb Mon Sep 17 00:00:00 2001 From: Archaversine Date: Thu, 26 Feb 2026 11:05:14 -0500 Subject: [PATCH 1/2] Avoid calling getenv multiple times --- src/Instrumentation_cpu.cpp | 5 +++++ src/Runtime_cpu.h | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Instrumentation_cpu.cpp b/src/Instrumentation_cpu.cpp index af04b3f..a1a8aee 100644 --- a/src/Instrumentation_cpu.cpp +++ b/src/Instrumentation_cpu.cpp @@ -161,6 +161,11 @@ CPUFPInstrumentation::CPUFPInstrumentation(Module *M) assert(prog_args && "Invalid table!"); prog_args->setLinkage(GlobalValue::LinkageTypes::LinkOnceODRLinkage); + GlobalVariable *exponent_usage_flag = nullptr; + exponent_usage_flag = mod->getGlobalVariable("_FPC_EXPONENT_USAGE_FLAG", true); + assert(exponent_usage_flag && "Invalid table!"); + exponent_usage_flag->setLinkage(GlobalValue::LinkageTypes::LinkOnceODRLinkage); + GlobalVariable *fpc_lock = nullptr; fpc_lock = mod->getGlobalVariable("fpc_lock", true); if (fpc_lock) diff --git a/src/Runtime_cpu.h b/src/Runtime_cpu.h index 183f806..1a3510f 100644 --- a/src/Runtime_cpu.h +++ b/src/Runtime_cpu.h @@ -39,6 +39,9 @@ pthread_mutex_t fpc_lock; int _FPC_PROG_INPUTS; char **_FPC_PROG_ARGS; +/** Exponent usage flag **/ +int _FPC_EXPONENT_USAGE_FLAG; + /*----------------------------------------------------------------------------*/ /* Initialize */ /*----------------------------------------------------------------------------*/ @@ -62,6 +65,7 @@ void _FPC_INIT_HASH_TABLE_() void _FPC_INIT_FPCHECKER() { _FPC_PROG_INPUTS = 0; + _FPC_EXPONENT_USAGE_FLAG = 0; _FPC_INIT_HASH_TABLE_(); } @@ -69,6 +73,7 @@ void _FPC_INIT_ARGS_FPCHECKER(int argc, char **argv) { _FPC_PROG_INPUTS = argc; _FPC_PROG_ARGS = argv; + _FPC_EXPONENT_USAGE_FLAG = getenv("FPC_EXPONENT_USAGE") != NULL; _FPC_INIT_HASH_TABLE_(); } @@ -620,7 +625,7 @@ void _FPC_FP32_CHECK_( item.latent_infinity_neg = (uint64_t)_FPC_FP32_IS_LATENT_INFINITY_NEG(x); item.latent_underflow = (uint64_t)_FPC_FP32_IS_LATENT_SUBNORMAL(x); - if (getenv("FPC_EXPONENT_USAGE") != NULL) + if (_FPC_EXPONENT_USAGE_FLAG) { // Set exponent usage to zero for (int i = 0; i < FPC_HISTOGRAM_LEN; ++i) @@ -635,7 +640,7 @@ void _FPC_FP32_CHECK_( // If FPC_EXPONENT_USAGE is not defined (default), we only save items in the table // if an event ocurred. If FPC_EXPONENT_USAGE is defined, we save all items // (since we want to profile all instructions). - if (getenv("FPC_EXPONENT_USAGE") == NULL) + if (!_FPC_EXPONENT_USAGE_FLAG) { if (!_FPC_EVENT_OCURRED(&item)) return; @@ -686,7 +691,7 @@ void _FPC_FP64_CHECK_( item.latent_infinity_neg = (uint64_t)_FPC_FP64_IS_LATENT_INFINITY_NEG(x); item.latent_underflow = (uint64_t)_FPC_FP64_IS_LATENT_SUBNORMAL(x); - if (getenv("FPC_EXPONENT_USAGE") != NULL) + if (_FPC_EXPONENT_USAGE_FLAG) { // Set exponent usage to zero for (int i = 0; i < FPC_HISTOGRAM_LEN; ++i) @@ -701,7 +706,7 @@ void _FPC_FP64_CHECK_( // If FPC_EXPONENT_USAGE is not defined (default), we only save items in the table // if an event ocurred. If FPC_EXPONENT_USAGE is defined, we save all items // (since we want to profile all instructions). - if (getenv("FPC_EXPONENT_USAGE") == NULL) + if (_FPC_EXPONENT_USAGE_FLAG) { if (!_FPC_EVENT_OCURRED(&item)) return; From 6ab01201e551172bc226bcc25a52088ea64df7b5 Mon Sep 17 00:00:00 2001 From: Archaversine Date: Thu, 26 Feb 2026 11:21:04 -0500 Subject: [PATCH 2/2] Logical bug --- src/Runtime_cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runtime_cpu.h b/src/Runtime_cpu.h index 1a3510f..4ba65b7 100644 --- a/src/Runtime_cpu.h +++ b/src/Runtime_cpu.h @@ -706,7 +706,7 @@ void _FPC_FP64_CHECK_( // If FPC_EXPONENT_USAGE is not defined (default), we only save items in the table // if an event ocurred. If FPC_EXPONENT_USAGE is defined, we save all items // (since we want to profile all instructions). - if (_FPC_EXPONENT_USAGE_FLAG) + if (!_FPC_EXPONENT_USAGE_FLAG) { if (!_FPC_EVENT_OCURRED(&item)) return;