Hi Jeevitha,

On 02/07/25 11:50 am, jeevitha wrote:
> diff --git a/gcc/testsuite/gcc.target/powerpc/amo3.c 
> b/gcc/testsuite/gcc.target/powerpc/amo3.c
> new file mode 100644
> index 00000000000..ac27543e2dc
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/amo3.c
> @@ -0,0 +1,134 @@
> +/* { dg-do compile { target { lp64 } } } */
> +/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
> +
> +/* This test uses uint64_t types. lp64 is added to avoid running it on 32-bit
> +    target. The test is skipped on 32-bit systems. */
> +
> +/* Test whether the ISA 3.0 amo (atomic memory operations) functions perform 
> as
> +   expected.  */
> +
> +#include <amo.h>
> +#include <stdint.h>
> +
> +uint32_t
> +do_lw_cs_ne (uint32_t *mem, uint32_t cond, uint32_t value)
> +{
> +  return amo_lwat_cas_neq (mem, cond, value);
> +}
> +
> +int32_t
> +do_lw_scs_ne (int32_t *mem, int32_t cond, int32_t value)
> +{
> +  return amo_lwat_scas_neq (mem, cond, value);
> +}
> +
> +uint32_t
> +do_lw_inc_equal (uint32_t *mem)
> +{
> +  return amo_lwat_inc_eq (mem);
> +}
> +
> +int32_t
> +do_lw_sinc_equal (int32_t *mem)
> +{
> +  return amo_lwat_sinc_eq (mem);
> +}
> +
> +uint32_t
> +do_lw_inc_bounded (uint32_t *mem)
> +{
> +  return amo_lwat_inc_bounded (mem);
> +}
> +
> +int32_t
> +do_lw_sinc_bounded (int32_t *mem)
> +{
> +  return amo_lwat_sinc_bounded (mem);
> +}
> +uint32_t
> +do_lw_dec_bounded (uint32_t *mem)
> +{
> +  return amo_lwat_dec_bounded (mem);
> +}
> +
> +int32_t
> +do_lw_sdec_bounded (int32_t *mem)
> +{
> +  return amo_lwat_sdec_bounded (mem);
> +}
> +
> +uint64_t
> +do_ld_cs_ne (uint64_t *mem, uint64_t cond, uint64_t value)
> +{
> +  return amo_ldat_cas_neq (mem, cond, value);
> +}
> +
> +int64_t
> +do_ld_scs_ne (int64_t *mem, int64_t cond, int64_t value)
> +{
> +  return amo_ldat_scas_neq (mem, cond, value);
> +}
> +
> +uint64_t
> +do_ld_inc_equal (uint64_t *mem)
> +{
> +  return amo_ldat_inc_eq (mem);
> +}
> +
> +int64_t
> +do_ld_sinc_equal (int64_t *mem)
> +{
> +  return amo_ldat_sinc_eq (mem);
> +}
> +
> +uint64_t
> +do_ld_inc_bounded (uint64_t *mem)
> +{
> +  return amo_ldat_inc_bounded (mem);
> +}
> +
> +int64_t
> +do_ld_sinc_bounded (int64_t *mem)
> +{
> +  return amo_ldat_sinc_bounded (mem);
> +}
> +uint64_t
> +do_ld_dec_bounded (uint64_t *mem)
> +{
> +  return amo_ldat_dec_bounded (mem);
> +}
> +
> +int64_t
> +do_ld_sdec_bounded (int64_t *mem)
> +{
> +  return amo_ldat_sdec_bounded (mem);
> +}
> +
> +void
> +do_sw_twin (uint32_t *mem, uint32_t value)
> +{
> +  amo_stwat_twin (mem, value);
> +}
> +
> +void
> +do_sw_stwin (int32_t *mem, int32_t value)
> +{
> +  amo_stwat_stwin (mem, value);
> +}
> +
> +void
> +do_sd_twin (uint64_t *mem, uint64_t value)
> +{
> +  amo_stdat_twin (mem, value);
> +}
> +
> +void
> +do_sd_stwin (int64_t *mem, int64_t value)
> +{
> +  amo_stdat_stwin (mem, value);
> +}
> +
> +/* { dg-final { scan-assembler-times {\mldat\M}  8 } } */
> +/* { dg-final { scan-assembler-times {\mlwat\M}  8 } } */
> +/* { dg-final { scan-assembler-times {\mstdat\M}  2 } } */
> +/* { dg-final { scan-assembler-times {\mstwat\M}  2 } } */
> diff --git a/gcc/testsuite/gcc.target/powerpc/amo4.c 
> b/gcc/testsuite/gcc.target/powerpc/amo4.c
> new file mode 100644
> index 00000000000..4138f63a9f0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/amo4.c
> @@ -0,0 +1,94 @@
> +/* { dg-do run { target { lp64 && p9vector_hw } } } */
> +/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
> +
> +/* This test uses uint64_t types. lp64 is added to avoid running it on 32-bit
> +    target. The test is skipped on 32-bit systems. */
> +
> +#include <amo.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +#include <limits.h>
> +
> +/* Test whether the ISA 3.0 amo (atomic memory operations) functions perform 
> as
> +   expected.  */
> +
> +/* 32-bit tests.  */
> +static uint32_t u32_ld[4][2] = {
> +  { 10, 15 },                        /* Increment Bounded */
> +  { 10, 10 },                        /* Increment Bounded */
> +  { 10, 10 },                        /* Increment Equal */
> +  { 10, 15 }                 /* Increment Equal */
> +};
> +
> +static uint32_t u32_result[4];
> +
> +static uint32_t u32_update[4] = {
> +  10 + 1,                    /* Increment Bounded */
> +  10,                                /* Increment Bounded */
> +  10 + 1,                    /* Increment Equal */
> +  10                         /* Increment Equal */
> +};
> +
> +static uint32_t u32_prev[4] = {
> +  10,                                /* Increment Bounded */
> +  INT_MIN,                   /* Increment Bounded */
> +  10,                                /* Increment Equal */
> +  INT_MIN                    /* Increment Equal */
> +};
> +

The name 'u32_prev' doesn't reflect what it actually means.
Better name would be u32_expected_result. And u32_result can be named
as u32_actual_result.
Ditto for u64_prev and u64_result.

> +/* 64-bit tests.  */
> +static uint64_t u64_ld[4][2] = {
> +  { 10, 15 },                        /* Increment Bounded */
> +  { 10, 10 },                        /* Increment Bounded */
> +  { 10, 10 },                        /* Increment Equal */
> +  { 10, 15 }                 /* Increment Equal */
> +};
> +
> +static uint64_t u64_result[4];
> +
> +static uint64_t u64_update[4] = {
> +  10 + 1,                    /* Increment Bounded */
> +  10,                                /* Increment Bounded */
> +  10 + 1,                    /* Increment Equal */
> +  10                         /* Increment Equal */
> +};
> +
> +static uint64_t u64_prev[4] = {
> +  10,                                /* Increment Bounded */
> +  INT64_MIN,                 /* Increment Bounded */
> +  10,                                /* Increment Equal */
> +  INT64_MIN                  /* Increment Equal */
> +};
> +
> +int
> +main (void)
> +{
> +  size_t i;
> +
> +  u32_result[0] = amo_lwat_inc_bounded (&u32_ld[0][0]);
> +  u32_result[1] = amo_lwat_inc_bounded (&u32_ld[1][0]);
> +  u32_result[2] = amo_lwat_inc_eq (&u32_ld[2][0]);
> +  u32_result[3] = amo_lwat_inc_eq (&u32_ld[3][0]);
> +
> +  u64_result[0] = amo_ldat_inc_bounded (&u64_ld[0][0]);
> +  u64_result[1] = amo_ldat_inc_bounded (&u64_ld[1][0]);
> +  u64_result[2] = amo_ldat_inc_eq (&u64_ld[2][0]);
> +  u64_result[3] = amo_ldat_inc_eq (&u64_ld[3][0]);
> +
> +  for (i = 0; i < 4; i++)
> +    {
> +      if (u32_result[i] != u32_prev[i])
> +     abort ();
> +
> +      if (u32_ld[i][0] != u32_update[i])
> +     abort ();
> +
> +      if (u64_result[i] != u64_prev[i])
> +     abort ();
> +
> +      if (u64_ld[i][0] != u64_update[i])
> +     abort ();
> +    }
> +
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.target/powerpc/amo5.c 
> b/gcc/testsuite/gcc.target/powerpc/amo5.c
> new file mode 100644
> index 00000000000..dae55fc755d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/amo5.c
> @@ -0,0 +1,46 @@
> +/* { dg-do run { target { lp64 && p9vector_hw } } } */
> +/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
> +
> +/* This test uses uint64_t types. lp64 is added to avoid running it on 32-bit
> +    target. The test is skipped on 32-bit systems. */
> +
> +#include <amo.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +#include <limits.h>
> +
> +/* Test whether the ISA 3.0 amo (atomic memory operations) functions perform 
> as
> +   expected.  */
> +
> +int
> +main (void)
> +{
> +  static uint32_t u32_mem = 100;
> +  static uint32_t u32_cond = 200;
> +  static uint32_t u32_value = 250;
> +  static uint32_t u32_prev = 100;
> +  static uint32_t u32_result;
> +
> +  static uint64_t u64_mem = 200;
> +  static uint64_t u64_cond = 300;
> +  static uint64_t u64_value = 250;
> +  static uint64_t u64_prev = 200;
> +  static uint64_t u64_result;

This test is testing the case where "mem(EA,s) != (RT+1)". Please add
tests to check for the case where the != condition fails.

> +
> +  u32_result = amo_lwat_cas_neq (&u32_mem, u32_cond, u32_value);
> +  u64_result = amo_ldat_cas_neq (&u64_mem, u64_cond, u64_value);
> +
> +  if (u32_mem != u32_value)
> +    abort();
> +
> +  if (u32_result != u32_prev)
> +    abort();
> +
> +  if (u64_mem != u64_value)
> +    abort();
> +
> +  if (u64_result != u64_prev)
> +    abort();
> +
> +    return 0;
> + }
> diff --git a/gcc/testsuite/gcc.target/powerpc/amo6.c 
> b/gcc/testsuite/gcc.target/powerpc/amo6.c
> new file mode 100644
> index 00000000000..ae68ebaa280
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/amo6.c
> @@ -0,0 +1,42 @@
> +/* { dg-do run { target { lp64 && p9vector_hw } } } */
> +/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
> +
> +/* This test uses uint64_t types. lp64 is added to avoid running it on 32-bit
> +    target. The test is skipped on 32-bit systems. */
> +
> +#include <amo.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +#include <limits.h>
> +
> +/* Test whether the ISA 3.0 amo (atomic memory operations) functions perform 
> as
> +   expected.  */
> +
> +int
> +main (void)
> +{
> +  size_t i;
> +  static uint32_t u32_mem[2] = { 3, 3 };
> +  static uint32_t u32_value = 5;
> +  static uint32_t u32_prev[2] = { 3, 3 };
> +  static uint32_t u32_result;
> +
> +  static uint64_t u64_mem[2] = { 7, 7 };
> +  static uint64_t u64_value = 9;
> +  static uint64_t u64_prev[2] = { 7, 7 };
> +  static uint64_t u64_result;

The variables u32_prev, u32_result, u64_prev and u64_result are not used. They 
can
be removed.
Please add test to check for the case where mem(EA,s) != mem(EA+s,s).

> +
> +  amo_stwat_twin (u32_mem, u32_value);
> +  amo_stdat_twin (u64_mem, u64_value);
> +
> +  for ( i = 0; i < 2; i++)
> +    {
> +      if (u32_mem[i] != u32_value)
> +     abort();
> +
> +      if (u64_mem[i] != u64_value)
> +     abort();
> +     }
> +
> +    return 0;
> + }
> diff --git a/gcc/testsuite/gcc.target/powerpc/amo7.c 
> b/gcc/testsuite/gcc.target/powerpc/amo7.c
> new file mode 100644
> index 00000000000..183125f6f97
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/amo7.c
> @@ -0,0 +1,78 @@
> +/* { dg-do run { target { lp64 && p9vector_hw } } } */
> +/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
> +
> +/* This test uses uint64_t types. lp64 is added to avoid running it on 32-bit
> +    target. The test is skipped on 32-bit systems. */
> +
> +#include <amo.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +#include <limits.h>
> +
> +/* Test whether the ISA 3.0 amo (atomic memory operations) functions perform 
> as
> +   expected.  */
> +
> +/* 32-bit tests.  */
> +static uint32_t u32_ld[2][2] = {
> +  { 10, 15 },                        /* Decrement Bounded */
> +  { 10, 10 },                        /* Decrement Bounded */
> +};
> +
> +static uint32_t u32_result[2];
> +
> +static uint32_t u32_update[2] = {
> +  15 - 1,                    /* Decrement Bounded */
> +  10,                                /* Decrement Bounded */
> +};
> +
> +static uint32_t u32_prev[2] = {
> +  15,                                /* Decrement Bounded */
> +  INT_MIN,                   /* Decrement Bounded */
> +};

Here too, please rename 'u32_prev' and 'u64_prev' to what they actually mean.

Regards,
Surya

> +
> +/* 64-bit tests.  */
> +static uint64_t u64_ld[2][2] = {
> +  { 10, 15 },                   /* Decrement Bounded */
> +  { 10, 10 },                   /* Decrement Bounded */
> +};
> +
> +static uint64_t u64_result[2];
> +
> +static uint64_t u64_update[2] = {
> +  15 - 1,                       /* Decrement Bounded */
> +  10,                           /* Decrement Bounded */
> +};
> +
> +static uint64_t u64_prev[2] = {
> +  15,                           /* Decrement Bounded */
> +  INT64_MIN,                    /* Decrement Bounded */
> +};
> +
> +int
> +main (void)
> +{
> +  size_t i;
> +
> +  u32_result[0] = amo_lwat_dec_bounded (&u32_ld[0][0]);
> +  u32_result[1] = amo_lwat_dec_bounded (&u32_ld[1][0]);
> +
> +  u64_result[0] = amo_ldat_dec_bounded (&u64_ld[0][0]);
> +  u64_result[1] = amo_ldat_dec_bounded (&u64_ld[1][0]);
> +  
> +  for (i = 0; i < 2; i++)
> +    {
> +      if (u32_result[i] != u32_prev[i])
> +     abort ();
> +
> +      if (u32_ld[i][1] != u32_update[i])
> +     abort ();
> +
> +      if (u64_result[i] != u64_prev[i])
> +     abort ();
> +
> +      if (u64_ld[i][1] != u64_update[i])
> +     abort ();
> +    }
> +
> +  return 0;
> +}
> 

Reply via email to