poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED] pkl: use the right offset type in offset casts


From: Jose E. Marchesi
Subject: [COMMITTED] pkl: use the right offset type in offset casts
Date: Sun, 12 Feb 2023 17:37:29 +0100
User-agent: Gnus/5.13 (Gnus v5.13)


2023-02-12  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pkl-insn.def: Remove instruction PKL_INSN_OTO.
        * libpoke/pkl-asm.c (pkl_asm_insn_oto): Remove.
        (pkl_asm_insn): Do not handle PKL_INSN_OTO.
        * libpoke/pkl-asm.pks: Move RAS_MACRO_OFFSET_CAST from here..
        * libpoke/pkl-gen.pks: ... to here.
        * libpoke/pkl-gen.c (pkl_gen_pr_cast): Use RAS_MACRO_OFFSET_CAST.
---
 ChangeLog            |  9 +++++++++
 libpoke/pkl-asm.c    | 20 -------------------
 libpoke/pkl-asm.pks  | 44 -----------------------------------------
 libpoke/pkl-gen.c    |  2 +-
 libpoke/pkl-gen.pks  | 47 ++++++++++++++++++++++++++++++++++++++++++++
 libpoke/pkl-insn.def |  1 -
 6 files changed, 57 insertions(+), 66 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bb382f12..d82acf3b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-02-12  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * libpoke/pkl-insn.def: Remove instruction PKL_INSN_OTO.
+       * libpoke/pkl-asm.c (pkl_asm_insn_oto): Remove.
+       (pkl_asm_insn): Do not handle PKL_INSN_OTO.
+       * libpoke/pkl-asm.pks: Move RAS_MACRO_OFFSET_CAST from here..
+       * libpoke/pkl-gen.pks: ... to here.
+       * libpoke/pkl-gen.c (pkl_gen_pr_cast): Use RAS_MACRO_OFFSET_CAST.
+
 2023-02-12  Jose E. Marchesi  <jemarch@gnu.org>
 
        * libpoke/pkl-gen-attrs.pks (attr_size): Use mkoq.
diff --git a/libpoke/pkl-asm.c b/libpoke/pkl-asm.c
index 27ba46f7..84b20c40 100644
--- a/libpoke/pkl-asm.c
+++ b/libpoke/pkl-asm.c
@@ -166,25 +166,6 @@ pkl_asm_poplevel (pkl_asm pasm)
   pasm->level = level->parent;
 }
 
-/* Macro-instruction: OTO from_type, to_type
-   ( OFF(from_type) TOUNIT -- OFF(to_type) )
-
-   Generate code to convert an offset value from FROM_TYPE to
-   TO_TYPE.  */
-
-static void
-pkl_asm_insn_oto (pkl_asm pasm,
-                  pkl_ast_node from_type,
-                  pkl_ast_node to_type)
-{
-  pkl_ast_node from_base_type = PKL_AST_TYPE_O_BASE_TYPE (from_type);
-  pkl_ast_node from_base_unit = PKL_AST_TYPE_O_UNIT (from_type);
-  pkl_ast_node to_base_type = PKL_AST_TYPE_O_BASE_TYPE (to_type);
-  pkl_ast_node unit_type = PKL_AST_TYPE (from_base_unit);
-
-  RAS_MACRO_OFFSET_CAST (from_base_type, to_base_type, unit_type);
-}
-
 /* Macro-instruction: ATOA from_type to_type
   ( ARR(from_type) -- ARR(to_type) )
 
@@ -1562,7 +1543,6 @@ pkl_asm_insn (pkl_asm pasm, enum pkl_asm_insn insn, ...)
             break;
           }
         case PKL_INSN_NTON:
-        case PKL_INSN_OTO:
         case PKL_INSN_ATOA:
           {
             pkl_ast_node from_type;
diff --git a/libpoke/pkl-asm.pks b/libpoke/pkl-asm.pks
index 150e0936..3666834e 100644
--- a/libpoke/pkl-asm.pks
+++ b/libpoke/pkl-asm.pks
@@ -110,50 +110,6 @@
         drop                    ; VAL
         .end
 
-;;; RAS_MACRO_OFFSET_CAST
-;;; ( OFF TOUNIT -- OFF )
-;;;
-;;; This macro generates code that converts an offset of a given type
-;;; into an offset of another given type.  This is the implementation of
-;;; the PKL_INSN_OTO macro-instruction.
-;;;
-;;; Macro arguments:
-;;; @from_base_type
-;;;    pkl_ast_node reflecting the type of the source offset magnitude.
-;;; @to_base_type
-;;;    pkl_ast_node reflecting the type of the result offset magnitude.
-;;; @unit_type
-;;;    pkl_ast_node reflecting the type of an unit, i.e. uint<64>.
-
-        .macro offset_cast @from_base_type @to_base_type @unit_type
-        ;; Note that we have to do the arithmetic in unit_types, then
-        ;; convert to to_base_type, to assure that to_base_type can hold
-        ;; the to_base_unit.  Otherwise weird division by zero occurs.
-        pushf 2
-        regvar $tounit                          ; OFF
-        ogetu                                   ; OFF FROMUNIT
-        regvar $fromunit                        ; OFF
-        ;; Get the magnitude of the offset and convert it to the
-        ;; unit type, which is uint<64>.
-        ogetm                                   ; OFF OFFM
-        nton @from_base_type, @unit_type        ; OFF OFFM OFFMC
-        nip                                     ; OFF OFFMC
-        ;; Now do the same for the unit.
-        pushvar $fromunit                       ; OFF OFFMC OFFU
-        mul @unit_type                          ; OFF OFFMC OFFU (OFFMC*OFFUC)
-        nip2                                    ; OFF (OFFMC*OFFUC)
-        ;; Convert the new unit.
-        pushvar $tounit                         ; OFF (OFFMC*OFFUC) TOUNIT
-        div @unit_type
-        nip2                                    ; OFF (OFFMC*OFFUC/TOUNIT)
-        ;; Convert to the new unit
-        nton @unit_type, @to_base_type          ; OFF (OFFMC*OFFUC/TOUNIT) OFFC
-        nip2                                    ; OFFC
-        pushvar $tounit                         ; OFFC TOUNIT
-        mkoq                                    ; OFFC XXX this should really 
use mko but that requires subpassing
-        popf 1
-        .end
-
 ;;; GCD type
 ;;; ( VAL VAL -- VAL VAL VAL )
 ;;;
diff --git a/libpoke/pkl-gen.c b/libpoke/pkl-gen.c
index af75dd10..46a63ea6 100644
--- a/libpoke/pkl-gen.c
+++ b/libpoke/pkl-gen.c
@@ -2373,7 +2373,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_cast)
 
       pkl_asm_insn (pasm, PKL_INSN_PUSH,
                     pvm_make_ulong (PKL_AST_INTEGER_VALUE (to_unit), 64));
-      pkl_asm_insn (pasm, PKL_INSN_OTO, from_type, to_type);
+      RAS_MACRO_OFFSET_CAST (from_type, to_type);
     }
   else if (PKL_AST_TYPE_CODE (to_type) == PKL_TYPE_STRING)
     {
diff --git a/libpoke/pkl-gen.pks b/libpoke/pkl-gen.pks
index 5ac111ad..4c337e6d 100644
--- a/libpoke/pkl-gen.pks
+++ b/libpoke/pkl-gen.pks
@@ -3454,3 +3454,50 @@
         .macro stroref @index_type
         .call _pkl_stroref
         .end
+
+;;; RAS_MACRO_OFFSET_CAST
+;;; ( OFF TOUNIT -- OFF )
+;;;
+;;; This macro generates code that converts an offset of a given type
+;;; into an offset of another given type.
+;;;
+;;; Macro arguments:
+;;; @from_type
+;;;    pkl_ast_node reflecting the offset type of OFF.
+;;; @to_type
+;;;    pkl_ast_node reflecting the offset type we are casting to.
+
+        .macro offset_cast @from_type @to_type
+        ;; Note that we have to do the arithmetic in unit_types, then
+        ;; convert to to_base_type, to assure that to_base_type can hold
+        ;; the to_base_unit.  Otherwise weird division by zero occurs.
+        pushf 2
+        regvar $tounit                          ; OFF
+        ogetu                                   ; OFF FROMUNIT
+        regvar $fromunit                        ; OFF
+        ;; Get the magnitude of the offset and convert it to the
+        ;; unit type, which is uint<64>.
+        ogetm                                   ; OFF OFFM
+        .let @unit_type = PKL_AST_TYPE (PKL_AST_TYPE_O_UNIT (@from_type))
+        .let @from_base_type = PKL_AST_TYPE_O_BASE_TYPE (@from_type)
+        nton @from_base_type, @unit_type        ; OFF OFFM OFFMC
+        nip                                     ; OFF OFFMC
+        ;; Now do the same for the unit.
+        pushvar $fromunit                       ; OFF OFFMC OFFU
+        mul @unit_type                          ; OFF OFFMC OFFU (OFFMC*OFFUC)
+        nip2                                    ; OFF (OFFMC*OFFUC)
+        ;; Convert the new unit.
+        pushvar $tounit                         ; OFF (OFFMC*OFFUC) TOUNIT
+        div @unit_type
+        nip2                                    ; OFF (OFFMC*OFFUC/TOUNIT)
+        ;; Convert to the new unit
+        .let @to_base_type = PKL_AST_TYPE_O_BASE_TYPE (@to_type)
+        nton @unit_type, @to_base_type          ; OFF (OFFMC*OFFUC/TOUNIT) OFFC
+        nip2                                    ; OFFC
+     .c PKL_GEN_PUSH_SET_CONTEXT (PKL_GEN_CTX_IN_TYPE);
+     .c PKL_PASS_SUBPASS (@to_type);
+     .c PKL_GEN_POP_CONTEXT;
+                                                ; OFFC TYPE
+        mko                                     ; OFFC
+        popf 1
+        .end
diff --git a/libpoke/pkl-insn.def b/libpoke/pkl-insn.def
index 74cd90d1..c086bdf1 100644
--- a/libpoke/pkl-insn.def
+++ b/libpoke/pkl-insn.def
@@ -534,7 +534,6 @@ PKL_DEF_INSN(PKL_INSN_POPAREM,"","poparem")
 PKL_DEF_INSN(PKL_INSN_MACRO,"","")
 
 PKL_DEF_INSN(PKL_INSN_NTON,"aa","nton")
-PKL_DEF_INSN(PKL_INSN_OTO,"aa","oto")
 PKL_DEF_INSN(PKL_INSN_ATOA,"aa","atoa")
 
 PKL_DEF_INSN(PKL_INSN_NEG,"a","neg")
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]