Skip to content

Commit

Permalink
Merge pull request #789 from pao/topic/zebras
Browse files Browse the repository at this point in the history
RFC: Optionally set FZ/DAZ on SSE(2) processors
  • Loading branch information
JeffBezanson committed May 3, 2012
2 parents 75529ab + 4158d61 commit 887d701
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/julia.expmap
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
jl_buf_mutex_lock;
jl_buf_mutex_unlock;
jl_start_io_thread;
jl_zero_denormals;
jl_save_system_image;
jl_restore_system_image;
jl_compress_ast;
Expand Down
27 changes: 27 additions & 0 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <pthread.h>
#include "julia.h"

#ifdef __SSE__
#include <xmmintrin.h>
#endif

// --- io and select ---

void jl__not__used__(void)
Expand Down Expand Up @@ -378,3 +382,26 @@ DLLEXPORT void jl_start_io_thread(void)
pthread_cond_init(&wake_cond, NULL);
pthread_create(&io_thread, NULL, run_io_thr, NULL);
}

DLLEXPORT uint8_t jl_zero_denormals(uint8_t isZero)
{
#ifdef __SSE2__
// SSE2 supports both FZ and DAZ
uint32_t flags = 0x8040;
#elif __SSE__
// SSE supports only the FZ flag
uint32_t flags = 0x8000;
#endif

#ifdef __SSE__
if (isZero) {
_mm_setcsr(_mm_getcsr() | flags);
}
else {
_mm_setcsr(_mm_getcsr() & ~flags);
}
return 1;
#else
return 0;
#endif
}

0 comments on commit 887d701

Please sign in to comment.