This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Function specific patch against the mainline, Intro


I submitted the initial version of the function specific patches for inclusion
in the mainline on June 11th here:
http://gcc.gnu.org/ml/gcc-patches/2008-06/msg00717.html

Since then, I have added support to specify the optimization options on a per
function basis, and #pragma support to specify either target options or
optimization options.  In the next 3 postings, I will add the machine
independent, ix86 dependent, and new tests for the testsuite.  I have done a
full bootstrap build and check on x86_64 with no regressions.

Here is the twiki that describes the work:
http://gcc.gnu.org/wiki/FunctionSpecificOpt

Here is an example using the attribute form that would allow you to compile a
32-bit program using one function that is compiled with -msse2, and the other
function compiled with default options (no sse2 by default on 32-bit):

#ifndef SIZE
#define SIZE 1024
#endif

static float a[SIZE] __attribute__((__aligned__(16)));
static float b[SIZE] __attribute__((__aligned__(16)));
static float c[SIZE] __attribute__((__aligned__(16)));

void sse_addnums (void) __attribute__ ((__option__ ("sse2")));

void
sse_addnums (void)
{
  int i = 0;
  for (; i < SIZE; ++i)
    a[i] = b[i] + c[i];
}

void
i387_subnums (void)
{
  int i = 0;
  for (; i < SIZE; ++i)
    a[i] = b[i] - c[i];
}

Here is the same thing using the #pragma support:

#ifndef SIZE
#define SIZE 1024
#endif

static float a[SIZE] __attribute__((__aligned__(16)));
static float b[SIZE] __attribute__((__aligned__(16)));
static float c[SIZE] __attribute__((__aligned__(16)));

#pragma GCC option ("sse2")

void
sse_addnums (void)
{
  int i = 0;
  for (; i < SIZE; ++i)
    a[i] = b[i] + c[i];
}

#pragma GCC option ("reset")

void
i387_subnums (void)
{
  int i = 0;
  for (; i < SIZE; ++i)
    a[i] = b[i] - c[i];
}

Here is an example changing the optimization options using attributes:

#define SIZE 10240
float a[SIZE] __attribute__((__aligned__(32)));
float b[SIZE] __attribute__((__aligned__(32)));
float c[SIZE] __attribute__((__aligned__(32)));

/* This should vectorize.  */
void opt3 (void) __attribute__((__optimize__(3,"unroll-all-loops,-fprefetch-loop-arrays")));

void
opt3 (void)
{
  int i;

  for (i = 0; i < SIZE; i++)
    a[i] = b[i] + c[i];
}

/* This should not vectorize.  */
void
not_opt3 (void)
{
  int i;

  for (i = 0; i < SIZE; i++)
    a[i] = b[i] - c[i];
}

Here is the #pragma version of the optimization example:

#define SIZE 10240
float a[SIZE] __attribute__((__aligned__(32)));
float b[SIZE] __attribute__((__aligned__(32)));
float c[SIZE] __attribute__((__aligned__(32)));

/* This should vectorize.  */
#pragma GCC optimize push
#pragma GCC optimize (3, "unroll-all-loops", "-fprefetch-loop-arrays")

void
opt3 (void)
{
  int i;

  for (i = 0; i < SIZE; i++)
    a[i] = b[i] + c[i];
}

#pragma GCC optimize pop

/* This should not vectorize.  */
void
not_opt3 (void)
{
  int i;

  for (i = 0; i < SIZE; i++)
    a[i] = b[i] - c[i];
}


-- 
Michael Meissner
email: gnu@the-meissners.org
http://www.the-meissners.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]