diff options
author | Vincent Chen <vincentc@andestech.com> | 2018-11-21 22:14:37 -0500 |
---|---|---|
committer | Greentime Hu <greentime@andestech.com> | 2018-11-22 05:13:33 -0500 |
commit | 7adb3e998f5bea3e1fd2f76c1cf80d76b8af6626 (patch) | |
tree | e1e56e8d2a7b2fdc9edd12f6a29b7eb8a07e4d9b | |
parent | 44e92e0364adfd7b6759084e02a550d06336d896 (diff) |
math-emu/op-2.h: Use statement expressions to prevent negative constant shift
This modification is quoted from glibc 'commit <
sysdeps/unix/sysv/linux/sparc/sparc64/dl-procinfo.c: Moved to>
(fe0b1e854ad32a69b260)'
Signed-off-by: Vincent Chen <vincentc@andestech.com>
Acked-by: Greentime Hu <greentime@andestech.com>
Signed-off-by: Greentime Hu <greentime@andestech.com>
-rw-r--r-- | include/math-emu/op-2.h | 99 |
1 files changed, 47 insertions, 52 deletions
diff --git a/include/math-emu/op-2.h b/include/math-emu/op-2.h index 4f26ecc1411b..13a374f51a22 100644 --- a/include/math-emu/op-2.h +++ b/include/math-emu/op-2.h | |||
@@ -31,61 +31,56 @@ | |||
31 | #define _FP_FRAC_HIGH_2(X) (X##_f1) | 31 | #define _FP_FRAC_HIGH_2(X) (X##_f1) |
32 | #define _FP_FRAC_LOW_2(X) (X##_f0) | 32 | #define _FP_FRAC_LOW_2(X) (X##_f0) |
33 | #define _FP_FRAC_WORD_2(X,w) (X##_f##w) | 33 | #define _FP_FRAC_WORD_2(X,w) (X##_f##w) |
34 | #define _FP_FRAC_SLL_2(X, N) ( \ | ||
35 | (void) (((N) < _FP_W_TYPE_SIZE) \ | ||
36 | ? ({ \ | ||
37 | if (__builtin_constant_p(N) && (N) == 1) { \ | ||
38 | X##_f1 = X##_f1 + X##_f1 + \ | ||
39 | (((_FP_WS_TYPE) (X##_f0)) < 0); \ | ||
40 | X##_f0 += X##_f0; \ | ||
41 | } else { \ | ||
42 | X##_f1 = X##_f1 << (N) | X##_f0 >> \ | ||
43 | (_FP_W_TYPE_SIZE - (N)); \ | ||
44 | X##_f0 <<= (N); \ | ||
45 | } \ | ||
46 | 0; \ | ||
47 | }) \ | ||
48 | : ({ \ | ||
49 | X##_f1 = X##_f0 << ((N) - _FP_W_TYPE_SIZE); \ | ||
50 | X##_f0 = 0; \ | ||
51 | }))) | ||
52 | |||
53 | |||
54 | #define _FP_FRAC_SRL_2(X, N) ( \ | ||
55 | (void) (((N) < _FP_W_TYPE_SIZE) \ | ||
56 | ? ({ \ | ||
57 | X##_f0 = X##_f0 >> (N) | X##_f1 << (_FP_W_TYPE_SIZE - (N)); \ | ||
58 | X##_f1 >>= (N); \ | ||
59 | }) \ | ||
60 | : ({ \ | ||
61 | X##_f0 = X##_f1 >> ((N) - _FP_W_TYPE_SIZE); \ | ||
62 | X##_f1 = 0; \ | ||
63 | }))) | ||
34 | 64 | ||
35 | #define _FP_FRAC_SLL_2(X,N) \ | ||
36 | do { \ | ||
37 | if ((N) < _FP_W_TYPE_SIZE) \ | ||
38 | { \ | ||
39 | if (__builtin_constant_p(N) && (N) == 1) \ | ||
40 | { \ | ||
41 | X##_f1 = X##_f1 + X##_f1 + (((_FP_WS_TYPE)(X##_f0)) < 0); \ | ||
42 | X##_f0 += X##_f0; \ | ||
43 | } \ | ||
44 | else \ | ||
45 | { \ | ||
46 | X##_f1 = X##_f1 << (N) | X##_f0 >> (_FP_W_TYPE_SIZE - (N)); \ | ||
47 | X##_f0 <<= (N); \ | ||
48 | } \ | ||
49 | } \ | ||
50 | else \ | ||
51 | { \ | ||
52 | X##_f1 = X##_f0 << ((N) - _FP_W_TYPE_SIZE); \ | ||
53 | X##_f0 = 0; \ | ||
54 | } \ | ||
55 | } while (0) | ||
56 | |||
57 | #define _FP_FRAC_SRL_2(X,N) \ | ||
58 | do { \ | ||
59 | if ((N) < _FP_W_TYPE_SIZE) \ | ||
60 | { \ | ||
61 | X##_f0 = X##_f0 >> (N) | X##_f1 << (_FP_W_TYPE_SIZE - (N)); \ | ||
62 | X##_f1 >>= (N); \ | ||
63 | } \ | ||
64 | else \ | ||
65 | { \ | ||
66 | X##_f0 = X##_f1 >> ((N) - _FP_W_TYPE_SIZE); \ | ||
67 | X##_f1 = 0; \ | ||
68 | } \ | ||
69 | } while (0) | ||
70 | 65 | ||
71 | /* Right shift with sticky-lsb. */ | 66 | /* Right shift with sticky-lsb. */ |
72 | #define _FP_FRAC_SRS_2(X,N,sz) \ | 67 | #define _FP_FRAC_SRS_2(X, N, sz) ( \ |
73 | do { \ | 68 | (void) (((N) < _FP_W_TYPE_SIZE) \ |
74 | if ((N) < _FP_W_TYPE_SIZE) \ | 69 | ? ({ \ |
75 | { \ | 70 | X##_f0 = (X##_f1 << (_FP_W_TYPE_SIZE - (N)) | X##_f0 >> (N) \ |
76 | X##_f0 = (X##_f1 << (_FP_W_TYPE_SIZE - (N)) | X##_f0 >> (N) | \ | 71 | | (__builtin_constant_p(N) && (N) == 1 \ |
77 | (__builtin_constant_p(N) && (N) == 1 \ | 72 | ? X##_f0 & 1 \ |
78 | ? X##_f0 & 1 \ | 73 | : (X##_f0 << (_FP_W_TYPE_SIZE - (N))) != 0)); \ |
79 | : (X##_f0 << (_FP_W_TYPE_SIZE - (N))) != 0)); \ | 74 | X##_f1 >>= (N); \ |
80 | X##_f1 >>= (N); \ | 75 | }) \ |
81 | } \ | 76 | : ({ \ |
82 | else \ | 77 | X##_f0 = (X##_f1 >> ((N) - _FP_W_TYPE_SIZE) \ |
83 | { \ | 78 | | ((((N) == _FP_W_TYPE_SIZE \ |
84 | X##_f0 = (X##_f1 >> ((N) - _FP_W_TYPE_SIZE) | \ | 79 | ? 0 \ |
85 | (((X##_f1 << (2*_FP_W_TYPE_SIZE - (N))) | X##_f0) != 0)); \ | 80 | : (X##_f1 << (2*_FP_W_TYPE_SIZE - (N)))) \ |
86 | X##_f1 = 0; \ | 81 | | X##_f0) != 0)); \ |
87 | } \ | 82 | X##_f1 = 0; \ |
88 | } while (0) | 83 | }))) |
89 | 84 | ||
90 | #define _FP_FRAC_ADDI_2(X,I) \ | 85 | #define _FP_FRAC_ADDI_2(X,I) \ |
91 | __FP_FRAC_ADDI_2(X##_f1, X##_f0, I) | 86 | __FP_FRAC_ADDI_2(X##_f1, X##_f0, I) |