Commit 8e12142e authored by Radford Neal's avatar Radford Neal

put some variables in high-frequency variable structure

parent 60d1b86a
......@@ -4,3 +4,19 @@ Changed how eval relates to evalv (with tuning #if).
Got rid of saving of R_EvalDepth in eval, in favour of increment/decrement.
It's saved and restored in/from contexts anyway.
Put the following global variables that are frequently used into a
structure to ensure reference locality (and possibly allow the
compiler to address faster):
R_variant_result
R_Visible
R_EvalDepth
R_Expressions
evalcount (was local to eval.c)
R_PPStackSize
R_PPStack
R_PPStackTop
R_CStackDir
R_CStackLimit
R_CStackThreshold
......@@ -83,7 +83,6 @@
R_BCNodeStackTop
R_BrowseLevel
R_BrowseLines
R_CStackDir
R_ChooseFile
R_ClearerrConsole
R_CollectWarnings
......@@ -99,7 +98,6 @@
R_EditFiles
R_ErrorCon
R_ExactSymbol
R_Expressions
R_Expressions_keep
R_ExternalPtrAddrFn
R_FileExists
......@@ -141,9 +139,6 @@
R_OpenSiteFile
R_OpenSysInitFile
R_OutputCon
R_PPStack
R_PPStackSize
R_PPStackTop
R_Parse1Stream
R_ParseContext
R_ParseContextLast
......@@ -188,7 +183,6 @@
R_UseNamesSymbol
R_VSize
R_Verbose
R_Visible
R_WarnEscapes
R_WarnLength
R_Warnings
......
......@@ -874,7 +874,8 @@ LibExtern SEXP R_binding_cell; /* NULL, or the binding cell for the variable
just found or created (if the binding uses
a CONS cell that is suitable for update */
LibExtern unsigned R_variant_result; /* 0 or kind of variant result */
#define R_variant_result R_high_frequency_globals.variant_result
LibExtern Rboolean R_interrupts_suspended INI_as(FALSE);
LibExtern int R_interrupts_pending INI_as(0);
......@@ -895,9 +896,9 @@ extern0 R_size_t R_Collected; /* Number of free cons cells (after gc) */
LibExtern int R_Is_Running; /* for Windows memory manager */
/* The Pointer Protection Stack */
extern0 int R_PPStackSize INI_as(R_PPSSIZE); /* The stack size (elements) */
extern0 int R_PPStackTop; /* The top of the stack */
extern0 SEXP* R_PPStack; /* The pointer protection stack */
#define R_PPStackSize R_high_frequency_globals.PPStackSize
#define R_PPStackTop R_high_frequency_globals.PPStackTop
#define R_PPStack R_high_frequency_globals.PPStack
/* Evaluation Environment */
LibExtern SEXP R_CurrentExpr; /* Currently evaluating expression */
......@@ -908,21 +909,21 @@ LibExtern RCNTXT R_Toplevel; /* Storage for the toplevel environment */
LibExtern RCNTXT* R_ToplevelContext; /* The toplevel environment */
LibExtern RCNTXT* R_GlobalContext; /* The global environment */
#endif
extern0 Rboolean R_Visible; /* Value visibility flag */
LibExtern int R_EvalDepth INI_as(0); /* Evaluation recursion depth */
#define R_Visible R_high_frequency_globals.Visible
#define R_EvalDepth R_high_frequency_globals.EvalDepth
extern0 int R_BrowseLines INI_as(0); /* lines/per call in browser */
extern0 SEXP R_VStack INI_as(NULL); /* R_alloc stack pointer */
extern0 int R_Expressions INI_as(5000); /* options(expressions) */
#define R_Expressions R_high_frequency_globals.Expressions
extern0 int R_Expressions_keep INI_as(5000); /* options(expressions) */
extern0 Rboolean R_KeepSource INI_as(FALSE); /* options(keep.source) */
extern0 int R_WarnLength INI_as(1000); /* Error/warning max length */
extern0 int R_nwarnings INI_as(50);
extern uintptr_t R_CStackLimit INI_as((uintptr_t)-1); /* C stack limit */
extern uintptr_t R_CStackStart INI_as((uintptr_t)-1); /* Initial stack address */
extern0 int R_CStackDir INI_as(1); /* C stack direction */
extern0 uintptr_t R_CStackThreshold; /* Threshold for overflow detection */
#define R_CStackDir R_high_frequency_globals.CStackDir
#define R_CStackLimit R_high_frequency_globals.CStackLimit
#define R_CStackThreshold R_high_frequency_globals.CStackThreshold
#ifdef R_USE_SIGNALS
extern0 struct RPRSTACK *R_PendingPromises INI_as(NULL); /* Pending promise stack */
......
......@@ -1596,6 +1596,37 @@ const char *Rf_reEnc(const char *x, cetype_t ce_in, cetype_t ce_out, int subst);
#define error_return(msg) { Rf_error(msg); return R_NilValue; }
#define errorcall_return(cl,msg){ Rf_errorcall(cl, msg); return R_NilValue; }
/* Structure containing frequently-used globals, to ensure locality of
reference, and perhaps allow the compiler to generate faster code
for addressing these variables (from knowing they are adjacent). */
LibExtern struct {
unsigned variant_result; /* 0 or kind of variant result */
Rboolean Visible; /* Value visibility flag */
int EvalDepth; /* Evaluation recursion depth */
int Expressions; /* options(expressions) */
int evalcount; /* counts down to check user interrupt */
int PPStackSize; /* Size of pointer protect stack (elements) */
SEXP *PPStack; /* Pointer to area for pointer protect stack*/
int PPStackTop; /* Top of the pointer protection stack */
int CStackDir; /* C stack direction */
uintptr_t CStackLimit; /* C stack limit */
uintptr_t CStackThreshold; /* Threshold for overflow detection */
} R_high_frequency_globals;
#define InitHighFrequencyGlobals() \
do \
{ \
R_high_frequency_globals.EvalDepth = 0; \
R_high_frequency_globals.Expressions = 5000; \
R_high_frequency_globals.evalcount = 0; \
R_high_frequency_globals.PPStackSize = R_PPSSIZE; \
R_high_frequency_globals.CStackDir = 1; \
R_high_frequency_globals.CStackLimit = (uintptr_t)-1; \
} while (0)
#ifdef __MAIN__
#undef extern
#undef LibExtern
......@@ -2144,5 +2175,5 @@ void Rf_R_from_C99_complex(Rcomplex *, double complex);
#ifdef __cplusplus
}
#endif
#endif /* R_INTERNALS_H_ */
......@@ -437,10 +437,11 @@ SEXP attribute_hidden forcePromisePendingOK(SEXP e)/* e protected here if rqd */
Rf_builtin_op. These functions are global even though un-used elsewhere
in order to discourage inlining by the compiler. */
static int evalcount = 0; /* counts down to when to check for user interrupt */
SEXP Rf_evalv2(SEXP,SEXP,int);
SEXP Rf_builtin_op (SEXP op, SEXP e, SEXP rho, int variant);
#define evalcount R_high_frequency_globals.evalcount
#define EVAL_PRELUDE do { \
\
R_variant_result = 0; \
......@@ -4617,9 +4618,9 @@ static int opcode_counts[OPCOUNT];
#define BC_COUNT_DELTA 1000
#define BC_CHECK_SIGINT() do { \
if (++evalcount > BC_COUNT_DELTA) { \
if (++eval_count > BC_COUNT_DELTA) { \
R_CheckUserInterrupt(); \
evalcount = 0; \
eval_count = 0; \
} \
} while (0)
......@@ -4946,7 +4947,7 @@ static SEXP bcEval(SEXP body, SEXP rho, Rboolean useCache)
BCODE *pc, *codebase;
int ftype = 0;
R_bcstack_t *oldntop = R_BCNodeStackTop;
static int evalcount = 0;
static int eval_count = 0;
#ifdef BC_INT_STACK
IStackval *olditop = R_BCIntStackTop;
#endif
......
......@@ -771,6 +771,8 @@ void setup_Rmainloop(void)
char deferred_warnings[11][250]; /* INCREASE AS NECESSARY! */
volatile int ndeferred_warnings = 0;
InitHighFrequencyGlobals();
InitConnections(); /* needed to get any output at all */
/* Initialize the interpreter's internal structures. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment