aboutsummaryrefslogtreecommitdiff
path: root/ltable.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-03-15 11:01:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-03-15 11:01:34 -0300
commit3823fc6c814d20f2b2a0a1e3be8782084440040f (patch)
treecb9b5ef3919dea45cb917ad79cc23c74a3c87681 /ltable.h
parent52aa2b5d24c560fb4d7a642971571ff9cbeabfcd (diff)
downloadlua-3823fc6c814d20f2b2a0a1e3be8782084440040f.tar.gz
lua-3823fc6c814d20f2b2a0a1e3be8782084440040f.tar.bz2
lua-3823fc6c814d20f2b2a0a1e3be8782084440040f.zip
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).
Diffstat (limited to 'ltable.h')
-rw-r--r--ltable.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/ltable.h b/ltable.h
index 8b0340b5..8688264c 100644
--- a/ltable.h
+++ b/ltable.h
@@ -87,20 +87,32 @@
87 87
88 88
89/* 89/*
90** The array part of a table is represented by an array of cells. 90** The array part of a table is represented by an array of *cells*.
91** Each cell is composed of NM tags followed by NM values, so that 91** Each cell is composed of NM tags followed by NM values, so that
92** no space is wasted in padding. 92** no space is wasted in padding.
93*/ 93*/
94#define NM cast_uint(sizeof(Value)) 94#define NM cast_uint(sizeof(Value))
95 95
96
97/*
98** A few operations on arrays can be performed "in bulk", treating all
99** tags of a cell as a simple (or a few) word(s). The next constant is
100** the number of words to cover the tags of a cell. (In conventional
101** architectures that will be 1 or 2.)
102*/
103#define BKSZ cast_int((NM - 1) / sizeof(lua_Unsigned) + 1)
104
96struct ArrayCell { 105struct ArrayCell {
97 lu_byte tag[NM]; 106 union {
107 lua_Unsigned bulk[BKSZ]; /* for "bulk" operations */
108 lu_byte tag[NM];
109 } u;
98 Value value[NM]; 110 Value value[NM];
99}; 111};
100 112
101 113
102/* Computes the address of the tag for the abstract index 'k' */ 114/* Computes the address of the tag for the abstract index 'k' */
103#define getArrTag(t,k) (&(t)->array[(k)/NM].tag[(k)%NM]) 115#define getArrTag(t,k) (&(t)->array[(k)/NM].u.tag[(k)%NM])
104 116
105/* Computes the address of the value for the abstract index 'k' */ 117/* Computes the address of the value for the abstract index 'k' */
106#define getArrVal(t,k) (&(t)->array[(k)/NM].value[(k)%NM]) 118#define getArrVal(t,k) (&(t)->array[(k)/NM].value[(k)%NM])