poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] libpoke,common: split suffix printing from `PK_PRINT_BINARY'


From: Jose E. Marchesi
Subject: Re: [PATCH] libpoke,common: split suffix printing from `PK_PRINT_BINARY'
Date: Sat, 18 Nov 2023 17:31:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Mohammad.
This is OK, thanks.  Please install.

I wonder though, why are these macros in common/pk-utils.h?  These are
only used by libpoke code as far as I can see.

> This commit makes `PK_PRINT_BINARY' macro more Jitter-friendly by
> removing the conditional call of `pk_integral_suffix' function and
> moving that logic to a different macro.
>
> At the moment, in pvm.jitter, the `pk_integral_suffix' invocation
> (through `PK_PRINT_BINARY' macro) is dead code (under `if (0)') so
> there's no need to put the function in the `wrapped-functions'
> sections (doing so will cause `make syntax-check' to fail on
> non-x86_64 platforms).
> So the fix is to remove `pk_integral_suffix' invocation from the macro.
>
> 2023-11-18  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>
>       * common/pk-utils.h (PK_INTEGRAL_SUFFIX): New macro.
>       (pk_integral_suffix): Remove function declaration.
>       (PK_PRINT_BINARY): Remove `use_suffix_p' parameter. And don't print
>       the suffix.
>       * common/pk-utils.c (PK_INTEGRAL_SUFFIX): Remove function definition.
>       * libpoke/pvm-val.c (pvm_print_val_1): Update use of `PK_PRINT_BINARY'
>       and use `PK_INTEGRAL_SUFFIX'.
>       * libpoke/pvm.jitter (wrapped-functions): Remove `pk_integral_suffix'.
>       (PVM_PRINTI): Update use of `PK_PRINT_BINARY'.
>       (PVM_PRINTL): Likewise.
> ---
>  ChangeLog          | 13 +++++++++++++
>  common/pk-utils.c  | 14 --------------
>  common/pk-utils.h  | 30 +++++++++++++-----------------
>  libpoke/pvm-val.c  | 13 ++++++++-----
>  libpoke/pvm.jitter |  5 ++---
>  5 files changed, 36 insertions(+), 39 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 74b628b6..cc2aad80 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,16 @@
> +2023-11-18  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> +
> +     * common/pk-utils.h (PK_INTEGRAL_SUFFIX): New macro.
> +     (pk_integral_suffix): Remove function declaration.
> +     (PK_PRINT_BINARY): Remove `use_suffix_p' parameter. And don't print
> +     the suffix.
> +     * common/pk-utils.c (PK_INTEGRAL_SUFFIX): Remove function definition.
> +     * libpoke/pvm-val.c (pvm_print_val_1): Update use of `PK_PRINT_BINARY'
> +     and use `PK_INTEGRAL_SUFFIX'.
> +     * libpoke/pvm.jitter (wrapped-functions): Remove `pk_integral_suffix'.
> +     (PVM_PRINTI): Update use of `PK_PRINT_BINARY'.
> +     (PVM_PRINTL): Likewise.
> +
>  2023-11-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>  
>       * common/pk-utils.h (pk_print_binary): Remove function decl.
> diff --git a/common/pk-utils.c b/common/pk-utils.c
> index d1c7cf90..eb4d28f5 100644
> --- a/common/pk-utils.c
> +++ b/common/pk-utils.c
> @@ -82,20 +82,6 @@ PK_POW (pk_upow, uint64_t)
>  
>  #undef PK_POW
>  
> -const char *
> -pk_integral_suffix (int size, int sign_p)
> -{
> -  if (size == 64)
> -    return sign_p ? "L" : "UL";
> -  if (size == 16)
> -    return sign_p ? "H" : "UH";
> -  if (size == 8)
> -    return sign_p ? "B" : "UB";
> -  if (size == 4)
> -    return sign_p ? "N" : "UN";
> -  return "";
> -}
> -
>  int
>  pk_format_binary (char* out, size_t outlen,
>                    uint64_t val, int size, int sign_p, int use_suffix_p)
> diff --git a/common/pk-utils.h b/common/pk-utils.h
> index 94b5c1f9..51898e73 100644
> --- a/common/pk-utils.h
> +++ b/common/pk-utils.h
> @@ -49,27 +49,26 @@ char *pk_file_readable (const char *filename);
>  int64_t pk_ipow (int64_t base, uint32_t exp);
>  uint64_t pk_upow (uint64_t base, uint32_t exp);
>  
> -/* Return one of the following strings based on the SIZE and SIGN_P:
> -     "N", "UN", "B", "UB", "H", "UH", "L", "UL"
> -   which are valid suffix for integral values in Poke.
> +/* Suffix for integral values.
>  
> -   PK_PRINT_BINARY macro uses this function to avoid using any string
> -   literals (because of Jitter's limitation).  */
> +   Please note that you cannot use this macro in pvm.jitter because
> +   of string literals.  */
>  
> -const char *pk_integral_suffix (int size, int sign_p);
> +#define PK_INTEGRAL_SUFFIX(SIZE, SIGNED_P)                                   
>  \
> +  ((SIZE) == 64   ? ((SIGNED_P) ? "L" : "UL")                                
>  \
> +   : (SIZE) == 16 ? ((SIGNED_P) ? "H" : "UH")                                
>  \
> +   : (SIZE) == 8  ? ((SIGNED_P) ? "B" : "UB")                                
>  \
> +   : (SIZE) == 4  ? ((SIGNED_P) ? "N" : "UN")                                
>  \
> +                  : "")
>  
> -/* Print the given unsigned 64-bit integer in binary.
> +/* Print the given unsigned 64-bit integer in base 2.  */
>  
> -   Please note that this macro is used in PVM_PRINT{I,L} macros in
> -   pvm.jitter; be careful to not call any non-wrapped functions
> -   or data (including string literals).  */
> -
> -#define PK_PRINT_BINARY(val, size, sign_p, use_suffix_p)                     
>  \
> +#define PK_PRINT_BINARY(VAL, SIZE)                                           
>  \
>    do                                                                         
>  \
>      {                                                                        
>  \
>        char _pkpb_buf[65];                                                    
>  \
> -      uint64_t _pkpb_val = (val);                                            
>  \
> -      int _pkpb_sz = (size);                                                 
>  \
> +      uint64_t _pkpb_val = (VAL);                                            
>  \
> +      int _pkpb_sz = (SIZE);                                                 
>  \
>                                                                               
>  \
>        for (int _pkpb_z = 0; _pkpb_z < _pkpb_sz; _pkpb_z++)                   
>  \
>          _pkpb_buf[_pkpb_sz - 1 - _pkpb_z]                                    
>  \
> @@ -77,9 +76,6 @@ const char *pk_integral_suffix (int size, int sign_p);
>        _pkpb_buf[_pkpb_sz] = '\0';                                            
>  \
>                                                                               
>  \
>        pk_puts (_pkpb_buf);                                                   
>  \
> -                                                                             
>  \
> -      if (use_suffix_p)                                                      
>  \
> -        pk_puts (pk_integral_suffix (_pkpb_sz, (sign_p)));                   
>  \
>      }                                                                        
>  \
>    while (0)
>  
> diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
> index e8091c50..aed63ae0 100644
> --- a/libpoke/pvm-val.c
> +++ b/libpoke/pvm-val.c
> @@ -1168,7 +1168,8 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base, 
> int indent,
>        if (base == 2)
>          {
>            pk_puts ("0b");
> -          PK_PRINT_BINARY (ulongval, size, /*signed_p*/ 1, /*use_suffix_p*/ 
> 1);
> +          PK_PRINT_BINARY (ulongval, size);
> +          pk_puts (PK_INTEGRAL_SUFFIX (size, /*signed_p*/ 1));
>          }
>        else
>          {
> @@ -1197,8 +1198,8 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base, 
> int indent,
>        if (base == 2)
>          {
>            pk_puts ("0b");
> -          PK_PRINT_BINARY ((uint64_t) uintval, size, /*signed*/ 1,
> -                           /*use_suffix_p*/ 1);
> +          PK_PRINT_BINARY ((uint64_t) uintval, size);
> +          pk_puts (PK_INTEGRAL_SUFFIX (size, /*signed_p*/ 1));
>          }
>        else
>          {
> @@ -1227,7 +1228,8 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base, 
> int indent,
>        if (base == 2)
>          {
>            pk_puts ("0b");
> -          PK_PRINT_BINARY (ulongval, size, /*signed_p*/ 0, /*use_suffix_p*/ 
> 1);
> +          PK_PRINT_BINARY (ulongval, size);
> +          pk_puts (PK_INTEGRAL_SUFFIX (size, /*signed_p*/ 0));
>          }
>        else
>          {
> @@ -1249,7 +1251,8 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base, 
> int indent,
>        if (base == 2)
>          {
>            pk_puts ("0b");
> -          PK_PRINT_BINARY (uintval, size, /*signed_p*/ 0, /*use_suffix_p*/ 
> 1);
> +          PK_PRINT_BINARY (uintval, size);
> +          pk_puts (PK_INTEGRAL_SUFFIX (size, /*signed_p*/ 0));
>          }
>        else
>          {
> diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
> index 3954345a..6c25f744 100644
> --- a/libpoke/pvm.jitter
> +++ b/libpoke/pvm.jitter
> @@ -90,7 +90,6 @@ wrapped-functions
>    pvm_make_offset_type
>    pvm_make_array_type
>    pk_upow
> -  pk_integral_suffix
>    pk_format_binary
>    pvm_alloc
>    pvm_allocate_struct_attrs
> @@ -517,7 +516,7 @@ late-header-c
>        }                                                                     \
>        else if ((BASE) == 2)                                                 \
>        {                                                                     \
> -        PK_PRINT_BINARY (val, JITTER_ARGN0, 1, 0);                          \
> +        PK_PRINT_BINARY (val, JITTER_ARGN0);                                \
>          JITTER_DROP_STACK ();                                               \
>          JITTER_DROP_STACK ();                                               \
>          break;                                                              \
> @@ -571,7 +570,7 @@ late-header-c
>        }                                                                     \
>        else if ((BASE) == 2)                                                 \
>        {                                                                     \
> -        PK_PRINT_BINARY (val, JITTER_ARGN0, 1, 0);                          \
> +        PK_PRINT_BINARY (val, JITTER_ARGN0);                                \
>          JITTER_DROP_STACK ();                                               \
>          JITTER_DROP_STACK ();                                               \
>          break;                                                              \



reply via email to

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