[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] pk_equal_val_p function and tests.
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] pk_equal_val_p function and tests. |
Date: |
Thu, 13 Aug 2020 06:58:20 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Kostas.
> diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
> index 2042cfa8..826e44db 100644
> --- a/libpoke/pvm-val.c
> +++ b/libpoke/pvm-val.c
> @@ -348,6 +348,260 @@ pvm_make_offset (pvm_val magnitude, pvm_val unit)
> return PVM_BOX (box);
> }
>
> +static int
> +pvm_val_equal_int (pvm_val pvm_int1, pvm_val pvm_int2)
> +{
> + /* size is checked on pvm_type_equal. */
> + int64_t pvm_int1_value, pvm_int2_value;
> +
> + pvm_int1_value = PVM_VAL_INTEGRAL (pvm_int1);
> + pvm_int2_value = PVM_VAL_INTEGRAL (pvm_int2);
> +
> + return pvm_int1_value == pvm_int2_value;
> +}
> +
> +static int
> +pvm_val_equal_uint (pvm_val pvm_uint1, pvm_val pvm_uint2)
> +{
> + /* size is checked on pvm_type_equal. */
> + uint64_t pvm_uint1_value, pvm_uint2_value;
> +
> + pvm_uint1_value = PVM_VAL_INTEGRAL (pvm_uint1);
> + pvm_uint2_value = PVM_VAL_INTEGRAL (pvm_uint2);
> +
> + return pvm_uint1_value == pvm_uint2_value;
> +}
> +
> +static int
> +pvm_val_equal_str (pvm_val pvm_str1, pvm_val pvm_str2)
> +{
> + char *pvm_str1_value, *pvm_str2_value;
> +
> + pvm_str1_value = PVM_VAL_STR (pvm_str1);
> + pvm_str2_value = PVM_VAL_STR (pvm_str2);
> +
> + return strncmp (pvm_str1_value, pvm_str2_value, strlen (pvm_str1_value))
> == 0;
> +}
> +
> +static int
> +pvm_val_equal_off (pvm_val pvm_off1, pvm_val pvm_off2)
> +{
> + pvm_val pvm_off1_magnitude, pvm_off2_magnitude;
> + pvm_val pvm_off1_unit, pvm_off2_unit;
> + pvm_val pvm_off1_base_type, pvm_off2_base_type;
> + int pvm_off_mag_equal, pvm_off_unit_equal, pvm_off_base_type_equal;
> +
> + pvm_off1_magnitude = PVM_VAL_OFF_MAGNITUDE (pvm_off1);
> + pvm_off2_magnitude = PVM_VAL_OFF_MAGNITUDE (pvm_off2);
> +
> + pvm_off1_unit = PVM_VAL_OFF_UNIT (pvm_off1);
> + pvm_off2_unit = PVM_VAL_OFF_UNIT (pvm_off2);
> +
> + pvm_off1_base_type = PVM_VAL_OFF_BASE_TYPE (pvm_off1);
> + pvm_off2_base_type = PVM_VAL_OFF_BASE_TYPE (pvm_off2);
> +
> + pvm_off_mag_equal = pvm_val_equal_p (pvm_off1_magnitude,
> pvm_off2_magnitude);
> + pvm_off_unit_equal = pvm_val_equal_p (pvm_off1_unit, pvm_off2_unit);
> + pvm_off_base_type_equal = pvm_val_equal_p (pvm_off1_base_type,
> + pvm_off2_base_type);
> +
> + return pvm_off_mag_equal && pvm_off_unit_equal && pvm_off_base_type_equal;
> +}
>
> +static int
> +pvm_val_equal_sct (pvm_val pvm_sct1, pvm_val pvm_sct2)
> +{
> + pvm_val pvm_sct1_field_boffset, pvm_sct2_field_boffset;
> + pvm_val pvm_sct1_field_value, pvm_sct2_field_value;
> + pvm_val pvm_sct1_field_name, pvm_sct2_field_name;
> + pvm_val pvm_sct1_method_name, pvm_sct2_method_name;
> + pvm_val pvm_sct1_ios, pvm_sct2_ios;
> + pvm_val pvm_sct1_type, pvm_sct2_type;
> + pvm_val pvm_sct1_off, pvm_sct2_off;
> + uint64_t pvm_sct1_nfields, pvm_sct2_nfields;
> + uint64_t pvm_sct1_nmethods, pvm_sct2_nmethods;
> +
> + pvm_sct1_nfields = PVM_VAL_INTEGRAL (PVM_VAL_SCT_NFIELDS (pvm_sct1));
> + pvm_sct2_nfields = PVM_VAL_INTEGRAL (PVM_VAL_SCT_NFIELDS (pvm_sct2));
> +
> + pvm_sct1_nmethods = PVM_VAL_INTEGRAL (PVM_VAL_SCT_NMETHODS (pvm_sct1));
> + pvm_sct2_nmethods = PVM_VAL_INTEGRAL (PVM_VAL_SCT_NMETHODS (pvm_sct2));
> +
> + if (pvm_sct1_nfields != pvm_sct2_nfields
> + || pvm_sct1_nmethods != pvm_sct2_nmethods)
> + return 0;
> +
> + pvm_sct1_ios = PVM_VAL_SCT_IOS (pvm_sct1);
> + pvm_sct2_ios = PVM_VAL_SCT_IOS (pvm_sct2);
> +
> + if (!(pvm_val_equal_p (pvm_sct1_ios, pvm_sct2_ios)))
> + return 0;
> +
> + pvm_sct1_type = PVM_VAL_SCT_TYPE (pvm_sct1);
> + pvm_sct2_type = PVM_VAL_SCT_TYPE (pvm_sct2);
> +
> + if (!(pvm_type_equal (pvm_sct1_type, pvm_sct2_type)))
> + return 0;
> +
> + pvm_sct1_off = PVM_VAL_SCT_OFFSET (pvm_sct1);
> + pvm_sct2_off = PVM_VAL_SCT_OFFSET (pvm_sct2);
> +
> + if (!(pvm_val_equal_p (pvm_sct1_off, pvm_sct2_off)))
> + return 0;
> +
> + for (size_t i = 0 ; i < pvm_sct1_nfields ; i++)
> + {
> + if (PVM_VAL_SCT_FIELD_ABSENT_P (pvm_sct1, i)
> + != PVM_VAL_SCT_FIELD_ABSENT_P (pvm_sct2, i))
> + return 0;
> +
> + if (!PVM_VAL_SCT_FIELD_ABSENT_P (pvm_sct1, i))
> + {
> + pvm_sct1_field_name = PVM_VAL_SCT_FIELD_NAME (pvm_sct1, i);
> + pvm_sct2_field_name = PVM_VAL_SCT_FIELD_NAME (pvm_sct2, i);
> +
> + pvm_sct1_field_value = PVM_VAL_SCT_FIELD_VALUE (pvm_sct1, i);
> + pvm_sct2_field_value = PVM_VAL_SCT_FIELD_VALUE (pvm_sct2, i);
> +
> + pvm_sct1_field_boffset = PVM_VAL_SCT_FIELD_OFFSET (pvm_sct1, i);
> + pvm_sct2_field_boffset = PVM_VAL_SCT_FIELD_OFFSET (pvm_sct2, i);
> +
> + if (!pvm_val_equal_p (pvm_sct1_field_name, pvm_sct2_field_name)
> + || !pvm_val_equal_p (pvm_sct1_field_value,
> pvm_sct2_field_value)
> + || !pvm_val_equal_p (pvm_sct1_field_boffset,
> + pvm_sct2_field_boffset))
> + return 0;
> + }
> + }
> +
> + for (size_t i = 0 ; i < pvm_sct1_nmethods ; i++)
> + {
> + pvm_sct1_method_name = PVM_VAL_SCT_METHOD_NAME (pvm_sct1, i);
> + pvm_sct2_method_name = PVM_VAL_SCT_METHOD_NAME (pvm_sct2, i);
> +
> + if (!pvm_val_equal_p (pvm_sct1_method_name, pvm_sct2_method_name))
> + return 0;
> + }
> +
> + return 1;
> +}
> +
> +static int
> +pvm_val_equal_arr (pvm_val pvm_arr1, pvm_val pvm_arr2)
> +{
> + pvm_val pvm_arr1_ios, pvm_arr2_ios;
> + pvm_val pvm_arr1_off, pvm_arr2_off;
> + pvm_val pvm_arr1_elems_bound, pvm_arr2_elems_bound;
> + pvm_val pvm_arr1_size_bound, pvm_arr2_size_bound;
> + pvm_val pvm_arr1_mapper, pvm_arr2_mapper;
> + pvm_val pvm_arr1_writer, pvm_arr2_writer;
> + pvm_val pvm_arr1_type, pvm_arr2_type;
> + pvm_val pvm_arr1_elem_value, pvm_arr2_elem_value;
> + pvm_val pvm_arr1_elem_offset, pvm_arr2_elem_offset;
> + uint64_t pvm_arr1_nelems, pvm_arr2_nelems;
> +
> + pvm_arr1_ios = PVM_VAL_ARR_IOS (pvm_arr1);
> + pvm_arr2_ios = PVM_VAL_ARR_IOS (pvm_arr2);
> +
> + if (!pvm_val_equal_p (pvm_arr1_ios, pvm_arr2_ios))
> + return 0;
> +
> + pvm_arr1_off = PVM_VAL_ARR_OFFSET (pvm_arr1);
> + pvm_arr2_off = PVM_VAL_ARR_OFFSET (pvm_arr2);
> +
> + if (!pvm_val_equal_p (pvm_arr1_off, pvm_arr2_off))
> + return 0;
> +
> + pvm_arr1_elems_bound = PVM_VAL_ARR_ELEMS_BOUND (pvm_arr1);
> + pvm_arr2_elems_bound = PVM_VAL_ARR_ELEMS_BOUND (pvm_arr2);
> +
> + if (!pvm_val_equal_p (pvm_arr1_elems_bound, pvm_arr2_elems_bound))
> + return 0;
> +
> + pvm_arr1_size_bound = PVM_VAL_ARR_SIZE_BOUND (pvm_arr1);
> + pvm_arr2_size_bound = PVM_VAL_ARR_SIZE_BOUND (pvm_arr2);
> +
> + if (!pvm_val_equal_p (pvm_arr1_size_bound, pvm_arr2_size_bound))
> + return 0;
> +
> + pvm_arr1_mapper = PVM_VAL_ARR_MAPPER (pvm_arr1);
> + pvm_arr2_mapper = PVM_VAL_ARR_MAPPER (pvm_arr2);
> +
> + if (!pvm_val_equal_p (pvm_arr1_mapper, pvm_arr2_mapper))
> + return 0;
> +
> + pvm_arr1_writer = PVM_VAL_ARR_WRITER (pvm_arr1);
> + pvm_arr2_writer = PVM_VAL_ARR_WRITER (pvm_arr2);
> +
> + if (!pvm_val_equal_p (pvm_arr1_writer, pvm_arr2_writer))
> + return 0;
> +
> + pvm_arr1_type = PVM_VAL_ARR_TYPE (pvm_arr1);
> + pvm_arr2_type = PVM_VAL_ARR_TYPE (pvm_arr2);
> +
> + if (!pvm_type_equal (pvm_arr1_type, pvm_arr2_type))
> + return 0;
> +
> + pvm_arr1_nelems = PVM_VAL_INTEGRAL (PVM_VAL_ARR_NELEM (pvm_arr1));
> + pvm_arr2_nelems = PVM_VAL_INTEGRAL (PVM_VAL_ARR_NELEM (pvm_arr2));
> +
> + if (pvm_arr1_nelems != pvm_arr2_nelems)
> + return 0;
> +
> + for (size_t i = 0 ; i < pvm_arr1_nelems ; i++)
> + {
> + pvm_arr1_elem_value = PVM_VAL_ARR_ELEM_VALUE (pvm_arr1, i);
> + pvm_arr2_elem_value = PVM_VAL_ARR_ELEM_VALUE (pvm_arr2, i);
> +
> + pvm_arr1_elem_offset = PVM_VAL_ARR_ELEM_OFFSET (pvm_arr1, i);
> + pvm_arr2_elem_offset = PVM_VAL_ARR_ELEM_OFFSET (pvm_arr2, i);
> +
> + if (!pvm_val_equal_p (pvm_arr1_elem_value, pvm_arr2_elem_value)
> + || !pvm_val_equal_p (pvm_arr1_elem_offset, pvm_arr2_elem_offset))
> + return 0;
> + }
> +
> + return 1;
> +}
I would really inline the functions above in pvm_val_equal_p below, like
in:
if (PVM_IS_INT (val1))
return PVM_VAL_INT (val1) == PVM_VAL_INT (val2);
else if (PVM_IS_UINT (val1))
return PVM_VAL_UINT (val1) == PVM_VAL_UINT (val2);
else if (PVM_IS_STR (val1))
return STR_EQ (PVM_VAL_STR (val1), PVM_VAL_STR (val2));
else if ...
- [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/04
- Re: [PATCH] pk_equal_val_p function and tests., Jose E. Marchesi, 2020/08/07
- Re: [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/07
- Re: [PATCH] pk_equal_val_p function and tests., Jose E. Marchesi, 2020/08/07
- Re: [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/08
- Re: [PATCH] pk_equal_val_p function and tests.,
Jose E. Marchesi <=
- Re: [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/17
- Re: [PATCH] pk_equal_val_p function and tests., Jose E. Marchesi, 2020/08/18
- Re: [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/19
- Re: [PATCH] pk_equal_val_p function and tests., Jose E. Marchesi, 2020/08/19
- Re: [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/19
- Re: [PATCH] pk_equal_val_p function and tests., Jose E. Marchesi, 2020/08/19
- Re: [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/21
- Re: [PATCH] pk_equal_val_p function and tests., Konstantinos Chasialis, 2020/08/28
- Re: [PATCH] pk_equal_val_p function and tests., Jose E. Marchesi, 2020/08/30