poke-devel
[Top][All Lists]
Advanced

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

Re: [RFC] Array Integrators


From: Jose E. Marchesi
Subject: Re: [RFC] Array Integrators
Date: Sat, 01 Jan 2022 21:51:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi MOhammad.

> Hi, Jose and people!
>
> Happy New Year!

Ditto :)

> I think email is a better medium for this discussion than IRC, so I'm writing
> this email.
>
> I will write my understanding of array integrator as a bunch of
> assertions, so, please tell me your comments on them.
>
> One thing to consider is that I think integration should be endian-dependent.
> Endians matters because we're dealing with "bytes" which will become an
> integer. We're dealing with the "representation" of integers, not integers.
> This is different from integral structs which are also integrals, which
> endianness doesn't matter for them.

I very strongly disagree :-)

IMO endianness should only come into play when reading and writing data
from/to an IO space.  Integer values have constituent bits which are
ordered from most significative to least significative.  That is easy to
understand and pretty much predictable.

Otherwise, consider this:

(poke) .set endian little
(poke) int<16> @ 0#B = [0xabUB,0xcdUB] as int<16>
                                      swap
                    swap!

You just wrote the bytes 0xab, 0xcd...

> What about this syntax?
>
> ```poke
> set_endian (ENDIAN_BIG);
> assert ([0xabUB, 0x12UB] as uint16        == 0xab12);
> assert ([0xabUB, 0x12UB] as big uint16    == 0xab12);
> assert ([0xabUB, 0x12UB] as little uint16 == 0x12ab);
>
> set_endian (ENDIAN_LITTLE);
> assert ([0xabUB, 0x12UB] as uint16        == 0x12ab);
> assert ([0xabUB, 0x12UB] as big uint16    == 0xab12);
> assert ([0xabUB, 0x12UB] as little uint16 == 0x12ab);
> ```
>
> One more thing, I'm using this predicate to see if a thing is integratable
> or not (WDYT?):
>
> ```c
> int
> pkl_ast_type_integratable_p (pkl_ast_node type)
> {
>   if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_ARRAY)
>     {
>       pkl_ast_node etype = PKL_AST_TYPE_A_ETYPE (type);
>
>       switch (PKL_AST_TYPE_CODE (etype))
>         {
>         case PKL_TYPE_INTEGRAL:
>         case PKL_TYPE_OFFSET:
>           return 1;
>         case PKL_TYPE_ARRAY:
>         case PKL_TYPE_STRUCT:
>           return pkl_ast_type_integratable_p (etype);
>         default:
>           return 0;
>         }
>     }
>
>   /* Integral structs are integratable.  */
>   if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_STRUCT
>       && PKL_AST_TYPE_S_ITYPE (type) != NULL)
>     return 1;
>
>   return 0;
> }
> ```

LGTM.  But why not `integrable'?

> Test cases:
>
> ```poke
> set_endian (ENDIAN_BIG);
>
> assert ([1UB] as byte = 1UB);
> assert ([1UB, 2UB] as uint16 == 0x0102UH);
> assert ([1UB, 2UB, 3UB, 4UB] as int32 == 0x01020304);
>
> assert ([[1UB], [2UB]] as uint32 == 0x0000_0102U);
> assert ([[1UB, 2UB], [3UB, 4UB]] as int32 == 0x01020304);
> assert ([[[1UB], [2UB]], [[3UB], [4UB]]] as int32 == 0x01020304);
>
> assert ([0xaabbccdd, 0xeeff0011] as uint64 == 0xaabbccddeeff0011UL);
> assert ([0xaabbUH, 0xeeffUH] as uint64 == 0xaabbeeffUL);
>
> /* Compilation error */
> /* assert ([1, 2, 3] as uint64); */ /* 3 32-bit number is wider than 64 bits 
> */
>
> var a1 = [1, 2, 3];
>
> assert (!(a1 as int64 ?! E_conv));
> ```
>
> We can have similar tests for offsets and integral structs.
>
>
> Regards,
> Mohammad-Reza



reply via email to

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