x86: Cast stride to __PTRDIFF_TYPE__ in AMX intrinsics

Message ID 20220822170244.670691-1-hjl.tools@gmail.com
State New, archived
Headers
Series x86: Cast stride to __PTRDIFF_TYPE__ in AMX intrinsics |

Commit Message

H.J. Lu Aug. 22, 2022, 5:02 p.m. UTC
  On 64-bit Windows, long is 32 bits and can't be used as stride in memory
operand when base is a pointer which is 64 bits.  Cast stride to
__PTRDIFF_TYPE__, instead of long.

	PR target/106714
	* config/i386/amxtileintrin.h (_tile_loadd_internal): Cast to
	__PTRDIFF_TYPE__.
	(_tile_stream_loadd_internal): Likewise.
	(_tile_stored_internal): Likewise.
---
 gcc/config/i386/amxtileintrin.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Hongtao Liu Aug. 23, 2022, 2:05 a.m. UTC | #1
On Tue, Aug 23, 2022 at 1:02 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On 64-bit Windows, long is 32 bits and can't be used as stride in memory
> operand when base is a pointer which is 64 bits.  Cast stride to
> __PTRDIFF_TYPE__, instead of long.
Ok.
>
>         PR target/106714
>         * config/i386/amxtileintrin.h (_tile_loadd_internal): Cast to
>         __PTRDIFF_TYPE__.
>         (_tile_stream_loadd_internal): Likewise.
>         (_tile_stored_internal): Likewise.
> ---
>  gcc/config/i386/amxtileintrin.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/config/i386/amxtileintrin.h b/gcc/config/i386/amxtileintrin.h
> index 7b5a39eba72..06f18aa9bfb 100644
> --- a/gcc/config/i386/amxtileintrin.h
> +++ b/gcc/config/i386/amxtileintrin.h
> @@ -62,7 +62,7 @@ _tile_release (void)
>  #define _tile_loadd_internal(dst,base,stride)                          \
>    __asm__ volatile                                                     \
>    ("{tileloadd\t(%0,%1,1), %%tmm"#dst"|tileloadd\t%%tmm"#dst", [%0+%1*1]}" \
> -   :: "r" ((const void*) (base)), "r" ((long) (stride)))
> +   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
>
>  #define _tile_stream_loadd(dst,base,stride)            \
>    _tile_stream_loadd_internal (dst, base, stride)
> @@ -70,7 +70,7 @@ _tile_release (void)
>  #define _tile_stream_loadd_internal(dst,base,stride)                   \
>    __asm__ volatile                                                     \
>    ("{tileloaddt1\t(%0,%1,1), %%tmm"#dst"|tileloaddt1\t%%tmm"#dst", [%0+%1*1]}" \
> -   :: "r" ((const void*) (base)), "r" ((long) (stride)))
> +   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
>
>  #define _tile_stored(dst,base,stride)          \
>    _tile_stored_internal (dst, base, stride)
> @@ -78,7 +78,7 @@ _tile_release (void)
>  #define _tile_stored_internal(src,base,stride)                         \
>    __asm__ volatile                                                     \
>    ("{tilestored\t%%tmm"#src", (%0,%1,1)|tilestored\t[%0+%1*1], %%tmm"#src"}" \
> -   :: "r" ((void*) (base)), "r" ((long) (stride)) \
> +   :: "r" ((void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)) \
>     : "memory")
>
>  #define _tile_zero(dst)                                \
> --
> 2.37.2
>


--
BR,
Hongtao
  
H.J. Lu Aug. 26, 2022, 4:51 p.m. UTC | #2
On Mon, Aug 22, 2022 at 7:05 PM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Tue, Aug 23, 2022 at 1:02 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On 64-bit Windows, long is 32 bits and can't be used as stride in memory
> > operand when base is a pointer which is 64 bits.  Cast stride to
> > __PTRDIFF_TYPE__, instead of long.
> Ok.
> >
> >         PR target/106714
> >         * config/i386/amxtileintrin.h (_tile_loadd_internal): Cast to
> >         __PTRDIFF_TYPE__.
> >         (_tile_stream_loadd_internal): Likewise.
> >         (_tile_stored_internal): Likewise.
> > ---
> >  gcc/config/i386/amxtileintrin.h | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/gcc/config/i386/amxtileintrin.h b/gcc/config/i386/amxtileintrin.h
> > index 7b5a39eba72..06f18aa9bfb 100644
> > --- a/gcc/config/i386/amxtileintrin.h
> > +++ b/gcc/config/i386/amxtileintrin.h
> > @@ -62,7 +62,7 @@ _tile_release (void)
> >  #define _tile_loadd_internal(dst,base,stride)                          \
> >    __asm__ volatile                                                     \
> >    ("{tileloadd\t(%0,%1,1), %%tmm"#dst"|tileloadd\t%%tmm"#dst", [%0+%1*1]}" \
> > -   :: "r" ((const void*) (base)), "r" ((long) (stride)))
> > +   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
> >
> >  #define _tile_stream_loadd(dst,base,stride)            \
> >    _tile_stream_loadd_internal (dst, base, stride)
> > @@ -70,7 +70,7 @@ _tile_release (void)
> >  #define _tile_stream_loadd_internal(dst,base,stride)                   \
> >    __asm__ volatile                                                     \
> >    ("{tileloaddt1\t(%0,%1,1), %%tmm"#dst"|tileloaddt1\t%%tmm"#dst", [%0+%1*1]}" \
> > -   :: "r" ((const void*) (base)), "r" ((long) (stride)))
> > +   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
> >
> >  #define _tile_stored(dst,base,stride)          \
> >    _tile_stored_internal (dst, base, stride)
> > @@ -78,7 +78,7 @@ _tile_release (void)
> >  #define _tile_stored_internal(src,base,stride)                         \
> >    __asm__ volatile                                                     \
> >    ("{tilestored\t%%tmm"#src", (%0,%1,1)|tilestored\t[%0+%1*1], %%tmm"#src"}" \
> > -   :: "r" ((void*) (base)), "r" ((long) (stride)) \
> > +   :: "r" ((void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)) \
> >     : "memory")
> >
> >  #define _tile_zero(dst)                                \
> > --
> > 2.37.2
> >
>
>
> --
> BR,
> Hongtao

OK to backport it to GCC 12 branch?
  
Hongtao Liu Aug. 29, 2022, 12:24 a.m. UTC | #3
On Sat, Aug 27, 2022 at 12:51 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Mon, Aug 22, 2022 at 7:05 PM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Tue, Aug 23, 2022 at 1:02 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On 64-bit Windows, long is 32 bits and can't be used as stride in memory
> > > operand when base is a pointer which is 64 bits.  Cast stride to
> > > __PTRDIFF_TYPE__, instead of long.
> > Ok.
> > >
> > >         PR target/106714
> > >         * config/i386/amxtileintrin.h (_tile_loadd_internal): Cast to
> > >         __PTRDIFF_TYPE__.
> > >         (_tile_stream_loadd_internal): Likewise.
> > >         (_tile_stored_internal): Likewise.
> > > ---
> > >  gcc/config/i386/amxtileintrin.h | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/gcc/config/i386/amxtileintrin.h b/gcc/config/i386/amxtileintrin.h
> > > index 7b5a39eba72..06f18aa9bfb 100644
> > > --- a/gcc/config/i386/amxtileintrin.h
> > > +++ b/gcc/config/i386/amxtileintrin.h
> > > @@ -62,7 +62,7 @@ _tile_release (void)
> > >  #define _tile_loadd_internal(dst,base,stride)                          \
> > >    __asm__ volatile                                                     \
> > >    ("{tileloadd\t(%0,%1,1), %%tmm"#dst"|tileloadd\t%%tmm"#dst", [%0+%1*1]}" \
> > > -   :: "r" ((const void*) (base)), "r" ((long) (stride)))
> > > +   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
> > >
> > >  #define _tile_stream_loadd(dst,base,stride)            \
> > >    _tile_stream_loadd_internal (dst, base, stride)
> > > @@ -70,7 +70,7 @@ _tile_release (void)
> > >  #define _tile_stream_loadd_internal(dst,base,stride)                   \
> > >    __asm__ volatile                                                     \
> > >    ("{tileloaddt1\t(%0,%1,1), %%tmm"#dst"|tileloaddt1\t%%tmm"#dst", [%0+%1*1]}" \
> > > -   :: "r" ((const void*) (base)), "r" ((long) (stride)))
> > > +   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
> > >
> > >  #define _tile_stored(dst,base,stride)          \
> > >    _tile_stored_internal (dst, base, stride)
> > > @@ -78,7 +78,7 @@ _tile_release (void)
> > >  #define _tile_stored_internal(src,base,stride)                         \
> > >    __asm__ volatile                                                     \
> > >    ("{tilestored\t%%tmm"#src", (%0,%1,1)|tilestored\t[%0+%1*1], %%tmm"#src"}" \
> > > -   :: "r" ((void*) (base)), "r" ((long) (stride)) \
> > > +   :: "r" ((void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)) \
> > >     : "memory")
> > >
> > >  #define _tile_zero(dst)                                \
> > > --
> > > 2.37.2
> > >
> >
> >
> > --
> > BR,
> > Hongtao
>
> OK to backport it to GCC 12 branch?
Ok.
>
>
> --
> H.J.
  

Patch

diff --git a/gcc/config/i386/amxtileintrin.h b/gcc/config/i386/amxtileintrin.h
index 7b5a39eba72..06f18aa9bfb 100644
--- a/gcc/config/i386/amxtileintrin.h
+++ b/gcc/config/i386/amxtileintrin.h
@@ -62,7 +62,7 @@  _tile_release (void)
 #define _tile_loadd_internal(dst,base,stride)				\
   __asm__ volatile							\
   ("{tileloadd\t(%0,%1,1), %%tmm"#dst"|tileloadd\t%%tmm"#dst", [%0+%1*1]}" \
-   :: "r" ((const void*) (base)), "r" ((long) (stride)))
+   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
 
 #define _tile_stream_loadd(dst,base,stride)		\
   _tile_stream_loadd_internal (dst, base, stride)
@@ -70,7 +70,7 @@  _tile_release (void)
 #define _tile_stream_loadd_internal(dst,base,stride)			\
   __asm__ volatile							\
   ("{tileloaddt1\t(%0,%1,1), %%tmm"#dst"|tileloaddt1\t%%tmm"#dst", [%0+%1*1]}" \
-   :: "r" ((const void*) (base)), "r" ((long) (stride)))
+   :: "r" ((const void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)))
 
 #define _tile_stored(dst,base,stride)		\
   _tile_stored_internal (dst, base, stride)
@@ -78,7 +78,7 @@  _tile_release (void)
 #define _tile_stored_internal(src,base,stride)				\
   __asm__ volatile							\
   ("{tilestored\t%%tmm"#src", (%0,%1,1)|tilestored\t[%0+%1*1], %%tmm"#src"}" \
-   :: "r" ((void*) (base)), "r" ((long) (stride)) \
+   :: "r" ((void*) (base)), "r" ((__PTRDIFF_TYPE__) (stride)) \
    : "memory")
 
 #define _tile_zero(dst)				\