Patchwork Add VIS intrinsics header for sparc.

login
register
mail settings
Submitter David Miller
Date Sept. 16, 2011, 7:02 p.m.
Message ID <20110916.150207.668420722149363976.davem@davemloft.net>
Download mbox | patch
Permalink /patch/115023/
State New
Headers show

Comments

David Miller - Sept. 16, 2011, 7:02 p.m.
I've been meaning to toss something like this together for a while.

If we were going to do this, I wanted to get it out of the way before
adding VIS2 and VIS3 support.

I considered trying to make a set of VIS headers compatible with the
vis_*.h headers Sun provides in medialib and Sun Studio, but that's
not possible since we use fundamentally different types in the
builtins provided by GCC.

Sun uses "double" and "float" in the declarations whereas we use our
vector types.

I even checked various users of Sun's VIS intrinsics and they all just
declare their vector variables as "float" and "double" so it would be
impossible to provide headers that would work out of the box.

Eric, any objections?

2011-09-16  David S. Miller  <davem@davemloft.net>

	* config/sparc/visintrin.h: New file.
	* config.gcc: Add it to extra_headers on sparc.
Jakub Jelinek - Sept. 16, 2011, 7:07 p.m.
On Fri, Sep 16, 2011 at 03:02:07PM -0400, David Miller wrote:
> +extern __inline void *
> +__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
> +__vis_alignaddr (void *__A, long __B)
> +{
> +	return __builtin_vis_alignaddr(__A, __B);

Just formatting nits, two spaces instead of tab to indent and
space in between function name and (.

	Jakub
David Miller - Sept. 16, 2011, 7:09 p.m.
From: Jakub Jelinek <jakub@redhat.com>
Date: Fri, 16 Sep 2011 21:07:09 +0200

> On Fri, Sep 16, 2011 at 03:02:07PM -0400, David Miller wrote:
>> +extern __inline void *
>> +__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
>> +__vis_alignaddr (void *__A, long __B)
>> +{
>> +	return __builtin_vis_alignaddr(__A, __B);
> 
> Just formatting nits, two spaces instead of tab to indent and
> space in between function name and (.

Thanks Jakub, I'll fix those up.
Eric Botcazou - Sept. 16, 2011, 9:01 p.m.
> I considered trying to make a set of VIS headers compatible with the
> vis_*.h headers Sun provides in medialib and Sun Studio, but that's
> not possible since we use fundamentally different types in the
> builtins provided by GCC.
>
> Sun uses "double" and "float" in the declarations whereas we use our
> vector types.
>
> I even checked various users of Sun's VIS intrinsics and they all just
> declare their vector variables as "float" and "double" so it would be
> impossible to provide headers that would work out of the box.

Yes, I have some recollections of that.

> Eric, any objections?

None, this looks OK to me.
David Miller - Sept. 16, 2011, 9:08 p.m.
From: Eric Botcazou <ebotcazou@adacore.com>
Date: Fri, 16 Sep 2011 23:01:56 +0200

>> Eric, any objections?
> 
> None, this looks OK to me.

Thanks Eric, I'll check this in.
Hans-Peter Nilsson - Sept. 22, 2011, 1:27 a.m.
On Fri, 16 Sep 2011, David Miller wrote:
>
> I've been meaning to toss something like this together for a while.
>
> If we were going to do this, I wanted to get it out of the way before
> adding VIS2 and VIS3 support.

While revisiting VIS, *please* consider fixing a big usability
problem: the pack and aligndata builtins don't take GSR in
account; it has unknown state and might be changed as a
side-effect of a previous VIS insn (well, alignaddr).  The
affected builtins don't have dependencies to GSR or a means to
set it besides in an asm; hardly usable at all.  See PR48974.

brgds, H-P
David Miller - Sept. 22, 2011, 2:20 a.m.
From: Hans-Peter Nilsson <hp@bitrange.com>
Date: Wed, 21 Sep 2011 21:27:08 -0400 (EDT)

> While revisiting VIS, *please* consider fixing a big usability
> problem: the pack and aligndata builtins don't take GSR in
> account; it has unknown state and might be changed as a
> side-effect of a previous VIS insn (well, alignaddr).  The
> affected builtins don't have dependencies to GSR or a means to
> set it besides in an asm; hardly usable at all.  See PR48974.

I know, see my posting from yesterday:

--------------------
Subject: [PATCH] Use TREE_READONLY on some sparc VIS builtins

While fiddling around with the VIS intrinsic builtins I noticed that
none of them have TREE_READONLY set, so the resulting code can be
terrible.

We can't currently do this for alignaddr and faligndata because we
don't model the way those instructions use the %gsr register.
--------------------
Hans-Peter Nilsson - Sept. 22, 2011, 3:27 a.m.
On Wed, 21 Sep 2011, David Miller wrote:
> From: Hans-Peter Nilsson <hp@bitrange.com>
> Date: Wed, 21 Sep 2011 21:27:08 -0400 (EDT)
>
> > While revisiting VIS, *please* consider fixing a big usability
> > problem: the pack and aligndata builtins don't take GSR in
> > account; it has unknown state and might be changed as a
> > side-effect of a previous VIS insn (well, alignaddr).  The
> > affected builtins don't have dependencies to GSR or a means to
> > set it besides in an asm; hardly usable at all.  See PR48974.
>
> I know, see my posting from yesterday:
>
> --------------------
> Subject: [PATCH] Use TREE_READONLY on some sparc VIS builtins
>
> While fiddling around with the VIS intrinsic builtins I noticed that
> none of them have TREE_READONLY set, so the resulting code can be
> terrible.
>
> We can't currently do this for alignaddr and faligndata because we
> don't model the way those instructions use the %gsr register.

Minor inconsistency spotted there: the same goes for the fpack
insns but you now set TREE_READONLY for them.  (Not claiming I
caught all of them.)

brgds, H-P
David Miller - Sept. 22, 2011, 6:15 a.m.
From: Hans-Peter Nilsson <hp@bitrange.com>
Date: Wed, 21 Sep 2011 23:27:38 -0400 (EDT)

> Minor inconsistency spotted there: the same goes for the fpack
> insns but you now set TREE_READONLY for them.  (Not claiming I
> caught all of them.)

Thanks a lot for pointing this out, I'll remove the TREE_READONLY flag
for these operations.

Positive feedback for the fact that someone is at least working on
this stuff at all would be appreciated as well.
Hans-Peter Nilsson - Sept. 22, 2011, 8:50 a.m.
On Thu, 22 Sep 2011, David Miller wrote:
> Positive feedback for the fact that someone is at least working on
> this stuff at all would be appreciated as well.

Using it or working on it?  Not that much of either, sorry, but
what I found when using it, I put in PR48974 (well, besides the
ICE's, which got separate PR's, of which Eric's been fixing some).

(For VIS, why not make use of fone / fones!)

brgds, H-P

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index e442fa7..7183f26 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -422,6 +422,7 @@  score*-*-*)
 	;;
 sparc*-*-*)
 	cpu_type=sparc
+	extra_headers="visintrin.h"
 	need_64bit_hwint=yes
 	;;
 spu*-*-*)
--- /dev/null	2011-09-11 10:37:28.169997151 -0700
+++ b/gcc/config/sparc/visintrin.h	2011-09-14 21:20:35.000000000 -0700
@@ -0,0 +1,160 @@ 
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GCC is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _VISINTRIN_H_INCLUDED
+#define _VISINTRIN_H_INCLUDED
+
+typedef int __v2si __attribute__ ((__vector_size__ (8)));
+typedef short __v4hi __attribute__ ((__vector_size__ (8)));
+typedef short __v2hi __attribute__ ((__vector_size__ (4)));
+typedef char __v8qi __attribute__ ((__vector_size__ (8)));
+typedef char __v4qi __attribute__ ((__vector_size__ (4)));
+typedef int __i64 __attribute__ ((__mode__ (DI)));
+
+extern __inline void *
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_alignaddr (void *__A, long __B)
+{
+	return __builtin_vis_alignaddr(__A, __B);
+}
+
+extern __inline __i64
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_faligndatadi (__i64 __A)
+{
+	return __builtin_vis_faligndatadi (__A);
+}
+
+extern __inline __v2si
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_faligndatav2si (__v2si __A)
+{
+	return __builtin_vis_faligndatav2si (__A);
+}
+
+extern __inline __v4hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_faligndatav4hi (__v4hi __A)
+{
+	return __builtin_vis_faligndatav4hi (__A);
+}
+
+extern __inline __v8qi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_faligndatav8qi (__v8qi __A)
+{
+	return __builtin_vis_faligndatav8qi (__A);
+}
+
+extern __inline __v4hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fexpand (__v4qi __A)
+{
+	return __builtin_vis_fexpand (__A);
+}
+
+extern __inline __v4hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fmul8x16 (__v4qi __A, __v4hi __B)
+{
+	return __builtin_vis_fmul8x16 (__A, __B);
+}
+
+extern __inline __v4hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fmul8x16au (__v4qi __A, __v4hi __B)
+{
+	return __builtin_vis_fmul8x16au (__A, __B);
+}
+
+extern __inline __v4hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fmul8x16al (__v4qi __A, __v4hi __B)
+{
+	return __builtin_vis_fmul8x16al (__A, __B);
+}
+
+extern __inline __v4hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fmul8sux16 (__v8qi __A, __v4hi __B)
+{
+	return __builtin_vis_fmul8sux16 (__A, __B);
+}
+
+extern __inline __v4hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fmul8ulx16 (__v8qi __A, __v4hi __B)
+{
+	return __builtin_vis_fmul8ulx16 (__A, __B);
+}
+
+extern __inline __v2si
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fmuld8sux16 (__v4qi __A, __v2hi __B)
+{
+	return __builtin_vis_fmuld8sux16 (__A, __B);
+}
+
+extern __inline __v2si
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fmuld8ulx16 (__v4qi __A, __v2hi __B)
+{
+	return __builtin_vis_fmuld8ulx16 (__A, __B);
+}
+
+extern __inline __v4qi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fpack16 (__v4hi __A)
+{
+	return __builtin_vis_fpack16 (__A);
+}
+
+extern __inline __v8qi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fpack32 (__v2si __A, __v2si __B)
+{
+	return __builtin_vis_fpack32 (__A, __B);
+}
+
+extern __inline __v2hi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fpackfix (__v2si __A)
+{
+	return __builtin_vis_fpackfix (__A);
+}
+
+extern __inline __v8qi
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_fpmerge (__v4qi __A, __v4qi __B)
+{
+	return __builtin_vis_fpmerge (__A, __B);
+}
+
+extern __inline __i64
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+__vis_pdist (__v8qi __A, __v8qi __B, __i64 __C)
+{
+	return __builtin_vis_pdist (__A, __B, __C);
+}
+
+#endif  /* _VISINTRIN_H_INCLUDED */