# HG changeset patch
# User Petter .T <petter.vilhelm@gmail.com>
# Date 1701381755 -3600
#      Thu Nov 30 23:02:35 2023 +0100
# Node ID 60e9357d4a320acb310a630dd096ac7f8228f881
# Parent  f511a54000f79ab6f312466a564dd2950559e05c
Use 32-bit bytecode interpreter stack elements on 32-bit systems

Remove always 64-bit type fields in stack element union, to decrease
the memory footprint of the stack. Instead use octave_idx_type that
is 32-bits on 32-bit systems.

* pt-bytecode.h: (stack_element) Remove always 64-bit types.
                                 Add octave_idx_type idx field instead.
* pt-bytecode-vm.cc: Use idx field where appropiate.

diff -r f511a54000f7 -r 60e9357d4a32 libinterp/parse-tree/pt-bytecode-vm.cc
--- a/libinterp/parse-tree/pt-bytecode-vm.cc	Tue Nov 28 22:02:57 2023 -0800
+++ b/libinterp/parse-tree/pt-bytecode-vm.cc	Thu Nov 30 23:02:35 2023 +0100
@@ -843,8 +843,8 @@
   do {\
     for (unsigned i = 0; i < stack_pad; i++)\
       {\
-        CHECK (m_stack0[i].u == stack_magic_int);\
-        CHECK (m_stack0[i + stack_size].u == stack_magic_int);\
+        CHECK (m_stack0[i].idx == static_cast<octave_idx_type> (stack_magic_int));\
+        CHECK (m_stack0[i + stack_size].idx == static_cast<octave_idx_type> (stack_magic_int));\
       }\
     CHECK (sp <= m_stack + stack_size);\
     CHECK (sp + n <= m_stack + stack_size);\
@@ -3042,10 +3042,10 @@
 
 
     // Push n to the stack
-    (*sp++).i = n;
+    (*sp++).idx = n;
     // Push a counter to the stack, initialized so that it will
     // increment to 0.
-    (*sp++).i = -1;
+    (*sp++).idx = -1;
 
     // For empty rhs just assign it to lhs
     if (! n && ov_range.is_defined ())
@@ -3091,11 +3091,11 @@
     CATCH_EXIT_EXCEPTION
 
     // Increase counter
-    TOP ().i++; // Wraps to zero first iteration
+    TOP ().idx++; // Wraps to zero first iteration
 
     // Check if we done all iterations
     // n is second element on the stack
-    if (TOP ().i == SEC ().i)
+    if (TOP ().idx == SEC ().idx)
       {
         // The after address
         unsigned char b0 = *ip++;
@@ -3112,7 +3112,7 @@
         int slot = arg0;
         ip +=2; // Skip the after address
 
-        octave_idx_type counter = TOP ().i;
+        octave_idx_type counter = TOP ().idx;
 
         octave_value &ov_range = THIRD_OV ();
         octave_value &ov_it = bsp[slot].ov;
@@ -3938,21 +3938,21 @@
   octave_idx_type n = keys.numel ();
 
   // Push n to the stack
-  (*sp++).i = n;
+  (*sp++).idx = n;
   // Push a counter to the stack, initialized so that it will
   // increment to 0.
-  (*sp++).i = -1;
+  (*sp++).idx = -1;
 }
 DISPATCH ();
 
 for_complex_cond:
 {
   // Increase counter
-  TOP ().i++; // Wraps to zero first iteration
+  TOP ().idx++; // Wraps to zero first iteration
 
   // Check if we done all iterations
   // n is second element on the stack
-  if (TOP ().i == SEC ().i)
+  if (TOP ().idx == SEC ().idx)
     {
       // The after address
       unsigned char b0 = arg0;
@@ -3968,7 +3968,7 @@
       ip++; // Skip 2nd part of afteraddress
       int slot_key = POP_CODE_USHORT ();
       int slot_value = POP_CODE_USHORT ();
-      octave_idx_type counter = TOP ().i;
+      octave_idx_type counter = TOP ().idx;
 
       octave_value &ov_rhs = THIRD_OV (); // This is always a struct
       octave_value &ov_key = bsp[slot_key].ov;
@@ -7172,8 +7172,8 @@
 
   for (unsigned i = 0; i < stack_pad; i++)
     {
-      m_stack0[i].u = stack_magic_int;
-      m_stack0[i + stack_size].u = stack_magic_int;
+      m_stack0[i].idx = static_cast<octave_idx_type> (stack_magic_int);
+      m_stack0[i + stack_size].idx = static_cast<octave_idx_type> (stack_magic_int);
     }
 
   m_sp = m_stack = m_stack0 + stack_pad;
diff -r f511a54000f7 -r 60e9357d4a32 libinterp/parse-tree/pt-bytecode.h
--- a/libinterp/parse-tree/pt-bytecode.h	Tue Nov 28 22:02:57 2023 -0800
+++ b/libinterp/parse-tree/pt-bytecode.h	Thu Nov 30 23:02:35 2023 +0100
@@ -312,9 +312,10 @@
   octave_value ov;
   octave_value_vm ov_vm;
   octave_base_value *ovb;
-  uint64_t u;
-  int64_t i;
-  double d;
+  unsigned u;
+  int i;
+
+  octave_idx_type idx;
 
   void *pv;
   const char *pcc;
