From 3823fc6c814d20f2b2a0a1e3be8782084440040f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 15 Mar 2024 11:01:34 -0300 Subject: Added "bulk operations" to arrays A few operations on arrays can be performed "in bulk", treating all tags of a cell as a simple (or a few) word(s). --- ltable.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'ltable.h') diff --git a/ltable.h b/ltable.h index 8b0340b5..8688264c 100644 --- a/ltable.h +++ b/ltable.h @@ -87,20 +87,32 @@ /* -** The array part of a table is represented by an array of cells. +** The array part of a table is represented by an array of *cells*. ** Each cell is composed of NM tags followed by NM values, so that ** no space is wasted in padding. */ #define NM cast_uint(sizeof(Value)) + +/* +** A few operations on arrays can be performed "in bulk", treating all +** tags of a cell as a simple (or a few) word(s). The next constant is +** the number of words to cover the tags of a cell. (In conventional +** architectures that will be 1 or 2.) +*/ +#define BKSZ cast_int((NM - 1) / sizeof(lua_Unsigned) + 1) + struct ArrayCell { - lu_byte tag[NM]; + union { + lua_Unsigned bulk[BKSZ]; /* for "bulk" operations */ + lu_byte tag[NM]; + } u; Value value[NM]; }; /* Computes the address of the tag for the abstract index 'k' */ -#define getArrTag(t,k) (&(t)->array[(k)/NM].tag[(k)%NM]) +#define getArrTag(t,k) (&(t)->array[(k)/NM].u.tag[(k)%NM]) /* Computes the address of the value for the abstract index 'k' */ #define getArrVal(t,k) (&(t)->array[(k)/NM].value[(k)%NM]) -- cgit v1.2.3-55-g6feb