Skip to content

Commit

Permalink
selftests/powerpc: Fix generation of vector instructions/types in con…
Browse files Browse the repository at this point in the history
…text_switch

Currently it doesn't appear the resulting binary actually uses any
Altivec or VSX instructions the solution is to explicitly tell GCC to
use vector instructions and use vector types in the code.

Part of this this issue can be GCC version specific:

GCC 4.9.x is happy to use Altivec and VSX instructions if altivec.h is
includedi (and possibly if vector types are used), this also means that
4.9.x will use VSX instructions even if only -maltivec is passed. It is
also possible that Altivec instructions will be used even without
-maltivec or -mabi=altivec.

GCC 5.2.x complains about the lack of -maltivec parameter if altivec.h
is included and will not use VSX unless -mvsx is present on commandline.

GCC 5.3.0 has a regression that means __attribute__((__target__("no-vsx"))
fails to build. A fix is targeted for 5.4.

Furthermore LTO (Link Time Optimisation) doesn't play well with
__attribute__((__target__("no-vsx")), LTO can cause GCC to forget about
the attribute and compile with VSX instructions regardless. Be wary when
enabling -flfo for this test.

Signed-off-by: Cyril Bur <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
cyrilbur-ibm authored and mpe committed Jul 5, 2016
1 parent 94fa56a commit f2418ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/powerpc/benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ all: $(TEST_PROGS)
$(TEST_PROGS): ../harness.c

context_switch: ../utils.c
context_switch: CFLAGS += -maltivec -mvsx -mabi=altivec
context_switch: LDLIBS += -lpthread

include ../../lib.mk
Expand Down
11 changes: 8 additions & 3 deletions tools/testing/selftests/powerpc/benchmarks/context_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include <sys/types.h>
#include <sys/shm.h>
#include <linux/futex.h>

#ifdef __powerpc__
#include <altivec.h>
#endif
#include "../utils.h"

static unsigned int timeout = 30;
Expand All @@ -37,12 +39,15 @@ static int touch_fp = 1;
double fp;

static int touch_vector = 1;
typedef int v4si __attribute__ ((vector_size (16)));
v4si a, b, c;
vector int a, b, c;

#ifdef __powerpc__
static int touch_altivec = 1;

/*
* Note: LTO (Link Time Optimisation) doesn't play well with this function
* attribute. Be very careful enabling LTO for this test.
*/
static void __attribute__((__target__("no-vsx"))) altivec_touch_fn(void)
{
c = a + b;
Expand Down

0 comments on commit f2418ae

Please sign in to comment.