| 1 |
include (CheckCSourceRuns) |
| 2 |
include (CMakePushCheckState) |
| 3 |
|
| 4 |
macro (CLIP_MODE) |
| 5 |
if ((NOT DEFINED CPU_CLIPS_NEGATIVE) AND (NOT DEFINED CPU_CLIPS_POSITIVE)) |
| 6 |
set (CLIP_MODE_POSITIVE_MESSAGE "Target processor clips on positive float to int conversion") |
| 7 |
set (CLIP_MODE_NEGATIVE_MESSAGE "Target processor clips on negative float to int conversion") |
| 8 |
|
| 9 |
message (STATUS "Checking processor clipping capabilities...") |
| 10 |
|
| 11 |
if (CMAKE_CROSSCOMPILING) |
| 12 |
|
| 13 |
set (CLIP_MSG "disabled") |
| 14 |
set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE}) |
| 15 |
set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE}) |
| 16 |
|
| 17 |
else (NOT CMAKE_CROSSCOMPILING) |
| 18 |
|
| 19 |
cmake_push_check_state () |
| 20 |
|
| 21 |
set (CMAKE_REQUIRED_QUIET TRUE) |
| 22 |
if (LIBM_REQUIRED) |
| 23 |
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${M_LIBRARY}) |
| 24 |
endif () |
| 25 |
|
| 26 |
check_c_source_runs ( |
| 27 |
" |
| 28 |
#define _ISOC9X_SOURCE 1 |
| 29 |
#define _ISOC99_SOURCE 1 |
| 30 |
#define __USE_ISOC99 1 |
| 31 |
#define __USE_ISOC9X 1 |
| 32 |
#include <math.h> |
| 33 |
int main (void) |
| 34 |
{ double fval ; |
| 35 |
int k, ival ; |
| 36 |
|
| 37 |
fval = 1.0 * 0x7FFFFFFF ; |
| 38 |
for (k = 0 ; k < 100 ; k++) |
| 39 |
{ ival = (lrint (fval)) >> 24 ; |
| 40 |
if (ival != 127) |
| 41 |
return 1 ; |
| 42 |
|
| 43 |
fval *= 1.2499999 ; |
| 44 |
} ; |
| 45 |
|
| 46 |
return 0 ; |
| 47 |
} |
| 48 |
" |
| 49 |
CPU_CLIPS_POSITIVE) |
| 50 |
|
| 51 |
check_c_source_runs ( |
| 52 |
" |
| 53 |
#define _ISOC9X_SOURCE 1 |
| 54 |
#define _ISOC99_SOURCE 1 |
| 55 |
#define __USE_ISOC99 1 |
| 56 |
#define __USE_ISOC9X 1 |
| 57 |
#include <math.h> |
| 58 |
int main (void) |
| 59 |
{ double fval ; |
| 60 |
int k, ival ; |
| 61 |
|
| 62 |
fval = -8.0 * 0x10000000 ; |
| 63 |
for (k = 0 ; k < 100 ; k++) |
| 64 |
{ ival = (lrint (fval)) >> 24 ; |
| 65 |
if (ival != -128) |
| 66 |
return 1 ; |
| 67 |
|
| 68 |
fval *= 1.2499999 ; |
| 69 |
} ; |
| 70 |
|
| 71 |
return 0 ; |
| 72 |
} |
| 73 |
" |
| 74 |
CPU_CLIPS_NEGATIVE) |
| 75 |
|
| 76 |
cmake_pop_check_state () |
| 77 |
|
| 78 |
if (CPU_CLIPS_POSITIVE AND (NOT CPU_CLIPS_NEGATIVE)) |
| 79 |
set (CLIP_MSG "positive") |
| 80 |
elseif (CPU_CLIPS_NEGATIVE AND (NOT CPU_CLIPS_POSITIVE)) |
| 81 |
set (CLIP_MSG "negative") |
| 82 |
elseif (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE) |
| 83 |
set (CLIP_MSG "both") |
| 84 |
else () |
| 85 |
set (CLIP_MSG "none") |
| 86 |
endif () |
| 87 |
|
| 88 |
endif (CMAKE_CROSSCOMPILING) |
| 89 |
|
| 90 |
message (STATUS "Checking processor clipping capabilities... ${CLIP_MSG}") |
| 91 |
endif () |
| 92 |
endmacro (CLIP_MODE) |