summaryrefslogtreecommitdiff
path: root/src/fpu-ia32.cc
blob: 16e9aa1f907025031ab70d5f0a17ec0ad8a87003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* IA-32 floating point unit non-inline related functions.
   Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
   Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com)

This file is part of the Parma Polyhedra Library (PPL).

The PPL 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 of the License, or (at your
option) any later version.

The PPL 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.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.

For the most up-to-date information see the Parma Polyhedra Library
site: http://www.cs.unipr.it/ppl/ . */

#include <ppl-config.h>

#if PPL_CAN_CONTROL_FPU && defined(PPL_FPMATH_MAY_USE_SSE) \
  && defined(__i386__) \
  && (defined(__GNUC__) || defined(__INTEL_COMPILER))

#include "fpu.defs.hh"
#include <csetjmp>
#include <csignal>
// This inclusion is to work around a bug present in some versions
// of GCC under mingw-w64.
// See http://www.cs.unipr.it/pipermail/ppl-devel/2011-February/017342.html
#include <cstddef>

namespace {

jmp_buf env;

void
illegal_instruction_catcher(int) {
  longjmp(env, 1);
}

} // namespace

namespace Parma_Polyhedra_Library {

bool have_sse_unit = true;

void
detect_sse_unit() {
  void (*old)(int);
  if (setjmp(env)) {
    // We will end up here if sse_get_control() raises SIGILL.
    have_sse_unit = false;
    goto restore_sigill_handler;
  }

  // Install our own signal handler for SIGILL.
  old = signal(SIGILL, illegal_instruction_catcher);
  (void) sse_get_control();
  // sse_get_control() did not raise SIGILL: we have an SSE unit.
  have_sse_unit = true;

 restore_sigill_handler:
  // Restore the previous signal handler for SIGILL.
  signal(SIGILL, old);
}

} // namespace Parma_Polyhedra_Library

#endif // PPL_CAN_CONTROL_FPU && defined(PPL_FPMATH_MAY_USE_SSE) && defined(__i386__) && (defined(__GNUC__) || defined(__INTEL_COMPILER))