Blame sysdeps/mips/tst-mode-switch-3.c

Packit 6c4009
/* Copyright (C) 2014-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <setjmp.h>
Packit 6c4009
#include <sys/prctl.h>
Packit 6c4009
Packit 6c4009
#if __mips_fpr != 0 || _MIPS_SPFPSET != 16
Packit 6c4009
# error This test requires -mfpxx -mno-odd-spreg
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* This test verifies that mode changes between a setjmp and longjmp do
Packit 6c4009
   not corrupt the state of callee-saved registers.  */
Packit 6c4009
Packit 6c4009
static int mode[6] =
Packit 6c4009
  {
Packit 6c4009
    0,
Packit 6c4009
    PR_FP_MODE_FR,
Packit 6c4009
    PR_FP_MODE_FR | PR_FP_MODE_FRE,
Packit 6c4009
    PR_FP_MODE_FR,
Packit 6c4009
    0,
Packit 6c4009
    PR_FP_MODE_FR | PR_FP_MODE_FRE
Packit 6c4009
  };
Packit 6c4009
static jmp_buf env;
Packit 6c4009
float check1 = 2.0;
Packit 6c4009
double check2 = 3.0;
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
  int result = 0;
Packit 6c4009
Packit 6c4009
  for (i = 0 ; i < 7 ; i++)
Packit 6c4009
    {
Packit 6c4009
      int retval;
Packit 6c4009
      register float test1 __asm ("$f20");
Packit 6c4009
      register double test2 __asm ("$f22");
Packit 6c4009
Packit 6c4009
      /* Hide what we are doing to $f20 and $f22 from the compiler.  */
Packit 6c4009
      __asm __volatile ("l.s %0,%2\n"
Packit 6c4009
			"l.d %1,%3\n"
Packit 6c4009
			: "=f" (test1), "=f" (test2)
Packit 6c4009
			: "m" (check1), "m" (check2));
Packit 6c4009
Packit 6c4009
      retval = setjmp (env);
Packit 6c4009
Packit 6c4009
      /* Make sure the compiler knows we want to access the variables
Packit 6c4009
         via the named registers again.  */
Packit 6c4009
      __asm __volatile ("" : : "f" (test1), "f" (test2));
Packit 6c4009
Packit 6c4009
      if (test1 != check1 || test2 != check2)
Packit 6c4009
	{
Packit 6c4009
	  printf ("Corrupt register detected: $20 %f = %f, $22 %f = %f\n",
Packit 6c4009
		  test1, check1, test2, check2);
Packit 6c4009
	  result = 1;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      if (retval == 0)
Packit 6c4009
	{
Packit 6c4009
	  if (prctl (PR_SET_FP_MODE, mode[i % 6]) != 0
Packit 6c4009
	      && errno != ENOTSUP)
Packit 6c4009
	    {
Packit 6c4009
	      printf ("prctl PR_SET_FP_MODE failed: %m");
Packit 6c4009
	      exit (1);
Packit 6c4009
	    }
Packit 6c4009
	  longjmp (env, 0);
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../../test-skeleton.c"