Skip to content

Commit

Permalink
enable floating point exceptions when debugging (glibc only)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorvde committed Jun 23, 2015
1 parent 25739ae commit 6aec1eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NO_WARN_FLAGS+=-w
CC?=$(HOST)gcc
WINDRES?=$(HOST)windres
LIBS+=-ljpeg -lpng -lm -lz
OBJS+=jpeg2png.o utils.o jpeg.o png.o box.o compute.o logger.o progressbar.o gopt/gopt.o ooura/dct.o
OBJS+=jpeg2png.o utils.o jpeg.o png.o box.o compute.o logger.o progressbar.o fp_exceptions.o gopt/gopt.o ooura/dct.o

ifeq ($(BUILTINS),1)
CFLAGS+=-DBUILTIN_UNREACHABLE -DBUILTIN_ASSUME_ALIGNED -DATTRIBUTE_UNUSED
Expand All @@ -32,7 +32,6 @@ else # not supported by gcc
CFLAGS+=-ffp-contract=off
endif

CFLAGS+=
ifeq ($(SIMD),1)
CFLAGS+=-DUSE_SIMD
endif
Expand All @@ -42,7 +41,7 @@ BFLAGS+=-fopenmp
endif

ifeq ($(DEBUG),1)
CFLAGS+=-Og -DNDEBUG
CFLAGS+=-Og -DDEBUG
BFLAGS+=-pg -g
else
CFLAGS+=-O3 -DNDEBUG
Expand Down
13 changes: 13 additions & 0 deletions fp_exceptions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifdef DEBUG
#ifdef _WIN32
#error "enabling floating point exceptions for debugging is not supported on windows"
#endif
#define _GNU_SOURCE
#include <fenv.h>
#endif

void enable_fp_exceptions() {
#ifdef DEBUG
feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
#endif
}
6 changes: 6 additions & 0 deletions fp_exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef JPEG2PNG_FP_EXCEPTIONS_H
#define JPEG2PNG_FP_EXCEPTIONS_H

void enable_fp_exceptions(void);

#endif
3 changes: 3 additions & 0 deletions jpeg2png.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "compute.h"
#include "logger.h"
#include "progressbar.h"
#include "fp_exceptions.h"

#define JPEG2PNG_VERSION "0.4"
static const float default_weight = 0.3;
Expand Down Expand Up @@ -161,6 +162,8 @@ void decode_file(FILE* in, FILE *out, unsigned iterations[3], float weights[3],


int main(int argc, const char **argv) {
enable_fp_exceptions();

void *options = gopt_sort(&argc, argv, gopt_start(
gopt_option('h', GOPT_NOARG, gopt_shorts('h','?'), gopt_longs("help")),
gopt_option('V', GOPT_NOARG, gopt_shorts('V'), gopt_longs("version")),
Expand Down

0 comments on commit 6aec1eb

Please sign in to comment.