Skip to content

Commit 7adb3e9

Browse files
Vincent ChenGreentime Hu
authored andcommitted
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>
1 parent 44e92e0 commit 7adb3e9

1 file changed

Lines changed: 47 additions & 52 deletions

File tree

‎include/math-emu/op-2.h‎

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,61 +31,56 @@
3131
#define _FP_FRAC_HIGH_2(X) (X##_f1)
3232
#define _FP_FRAC_LOW_2(X) (X##_f0)
3333
#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+
})))
3464

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)
7065

7166
/* Right shift with sticky-lsb. */
72-
#define _FP_FRAC_SRS_2(X,N,sz) \
73-
do { \
74-
if ((N) < _FP_W_TYPE_SIZE) \
75-
{ \
76-
X##_f0 = (X##_f1 << (_FP_W_TYPE_SIZE - (N)) | X##_f0 >> (N) | \
77-
(__builtin_constant_p(N) && (N) == 1 \
78-
? X##_f0 & 1 \
79-
: (X##_f0 << (_FP_W_TYPE_SIZE - (N))) != 0)); \
80-
X##_f1 >>= (N); \
81-
} \
82-
else \
83-
{ \
84-
X##_f0 = (X##_f1 >> ((N) - _FP_W_TYPE_SIZE) | \
85-
(((X##_f1 << (2*_FP_W_TYPE_SIZE - (N))) | X##_f0) != 0)); \
86-
X##_f1 = 0; \
87-
} \
88-
} while (0)
67+
#define _FP_FRAC_SRS_2(X, N, sz) ( \
68+
(void) (((N) < _FP_W_TYPE_SIZE) \
69+
? ({ \
70+
X##_f0 = (X##_f1 << (_FP_W_TYPE_SIZE - (N)) | X##_f0 >> (N) \
71+
| (__builtin_constant_p(N) && (N) == 1 \
72+
? X##_f0 & 1 \
73+
: (X##_f0 << (_FP_W_TYPE_SIZE - (N))) != 0)); \
74+
X##_f1 >>= (N); \
75+
}) \
76+
: ({ \
77+
X##_f0 = (X##_f1 >> ((N) - _FP_W_TYPE_SIZE) \
78+
| ((((N) == _FP_W_TYPE_SIZE \
79+
? 0 \
80+
: (X##_f1 << (2*_FP_W_TYPE_SIZE - (N)))) \
81+
| X##_f0) != 0)); \
82+
X##_f1 = 0; \
83+
})))
8984

9085
#define _FP_FRAC_ADDI_2(X,I) \
9186
__FP_FRAC_ADDI_2(X##_f1, X##_f0, I)

0 commit comments

Comments
 (0)