Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83a611a

Browse files
committed
Remove newly added asserts from pg_bitutils.h
These were valuable during development, but are unlikely to tell usanything going forward. This reverts204b0cb and adjusts the contentof6773197 to more closely match the more-readable original style.Per review from Tom LaneDiscussion:https://www.postgresql.org/message-id/3567481.1676906261%40sss.pgh.pa.us
1 parente00bc6c commit83a611a

File tree

1 file changed

+51
-99
lines changed

1 file changed

+51
-99
lines changed

‎src/include/port/pg_bitutils.h

Lines changed: 51 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,26 @@ static inline int
4141
pg_leftmost_one_pos32(uint32word)
4242
{
4343
#ifdefHAVE__BUILTIN_CLZ
44-
intbitscan_result;
44+
Assert(word!=0);
45+
46+
return31-__builtin_clz(word);
4547
#elif defined(_MSC_VER)
46-
unsigned longbitscan_result;
48+
unsigned longresult;
4749
boolnon_zero;
48-
#endif
4950

50-
#if !defined(HAVE_BITSCAN_REVERSE)|| defined(USE_ASSERT_CHECKING)
51-
intresult;
51+
non_zero=_BitScanReverse(&result,word);
52+
Assert(non_zero);
53+
return (int)result;
54+
#else
5255
intshift=32-8;
5356

5457
Assert(word!=0);
5558

5659
while ((word >>shift)==0)
5760
shift-=8;
5861

59-
result=shift+pg_leftmost_one_pos[(word >>shift)&255];
60-
#endif
61-
62-
#ifdefHAVE_BITSCAN_REVERSE
63-
64-
#if defined(HAVE__BUILTIN_CLZ)
65-
bitscan_result=31-__builtin_clz(word);
66-
#elif defined(_MSC_VER)
67-
non_zero=_BitScanReverse(&bitscan_result,word);
68-
Assert(non_zero);
69-
#endif
70-
Assert(bitscan_result==result);
71-
returnbitscan_result;
72-
73-
#else
74-
returnresult;
75-
#endif/* HAVE_BITSCAN_REVERSE */
62+
returnshift+pg_leftmost_one_pos[(word >>shift)&255];
63+
#endif/* HAVE__BUILTIN_CLZ */
7664
}
7765

7866
/*
@@ -83,45 +71,33 @@ static inline int
8371
pg_leftmost_one_pos64(uint64word)
8472
{
8573
#ifdefHAVE__BUILTIN_CLZ
86-
intbitscan_result;
87-
#elif defined(_MSC_VER)
88-
unsigned longbitscan_result;
89-
boolnon_zero;
90-
#endif
91-
92-
#if !defined(HAVE_BITSCAN_REVERSE)|| defined(USE_ASSERT_CHECKING)
93-
intresult;
94-
intshift=64-8;
95-
9674
Assert(word!=0);
9775

98-
while ((word >>shift)==0)
99-
shift-=8;
100-
101-
result=shift+pg_leftmost_one_pos[(word >>shift)&255];
102-
#endif
103-
104-
#ifdefHAVE_BITSCAN_REVERSE
105-
106-
#if defined(HAVE__BUILTIN_CLZ)
10776
#if defined(HAVE_LONG_INT_64)
108-
bitscan_result=63-__builtin_clzl(word);
77+
return63-__builtin_clzl(word);
10978
#elif defined(HAVE_LONG_LONG_INT_64)
110-
bitscan_result=63-__builtin_clzll(word);
79+
return63-__builtin_clzll(word);
11180
#else
11281
#error must have a working 64-bit integer datatype
11382
#endif/* HAVE_LONG_INT_64 */
11483

11584
#elif defined(_MSC_VER)
116-
non_zero=_BitScanReverse64(&bitscan_result,word);
117-
Assert(non_zero);
118-
#endif/* HAVE__BUILTIN_CLZ */
119-
Assert(bitscan_result==result);
120-
returnbitscan_result;
85+
unsigned longresult;
86+
boolnon_zero;
12187

88+
non_zero=_BitScanReverse64(&result,word);
89+
Assert(non_zero);
90+
return (int)result;
12291
#else
123-
returnresult;
124-
#endif/* HAVE_BITSCAN_REVERSE */
92+
intshift=64-8;
93+
94+
Assert(word!=0);
95+
96+
while ((word >>shift)==0)
97+
shift-=8;
98+
99+
returnshift+pg_leftmost_one_pos[(word >>shift)&255];
100+
#endif/* HAVE__BUILTIN_CLZ */
125101
}
126102

127103
/*
@@ -133,15 +109,17 @@ static inline int
133109
pg_rightmost_one_pos32(uint32word)
134110
{
135111
#ifdefHAVE__BUILTIN_CTZ
136-
constuint32orig_word=word;
137-
intbitscan_result;
112+
Assert(word!=0);
113+
114+
return__builtin_ctz(word);
138115
#elif defined(_MSC_VER)
139-
constunsigned longorig_word=word;
140-
unsigned longbitscan_result;
116+
unsigned longresult;
141117
boolnon_zero;
142-
#endif
143118

144-
#if !defined(HAVE_BITSCAN_FORWARD)|| defined(USE_ASSERT_CHECKING)
119+
non_zero=_BitScanForward(&result,word);
120+
Assert(non_zero);
121+
return (int)result;
122+
#else
145123
intresult=0;
146124

147125
Assert(word!=0);
@@ -152,22 +130,8 @@ pg_rightmost_one_pos32(uint32 word)
152130
result+=8;
153131
}
154132
result+=pg_rightmost_one_pos[word&255];
155-
#endif
156-
157-
#ifdefHAVE_BITSCAN_FORWARD
158-
159-
#if defined(HAVE__BUILTIN_CTZ)
160-
bitscan_result=__builtin_ctz(orig_word);
161-
#elif defined(_MSC_VER)
162-
non_zero=_BitScanForward(&bitscan_result,orig_word);
163-
Assert(non_zero);
164-
#endif
165-
Assert(bitscan_result==result);
166-
returnbitscan_result;
167-
168-
#else
169133
returnresult;
170-
#endif/*HAVE_BITSCAN_FORWARD */
134+
#endif/*HAVE__BUILTIN_CTZ */
171135
}
172136

173137
/*
@@ -178,15 +142,24 @@ static inline int
178142
pg_rightmost_one_pos64(uint64word)
179143
{
180144
#ifdefHAVE__BUILTIN_CTZ
181-
constuint64orig_word=word;
182-
intbitscan_result;
145+
Assert(word!=0);
146+
147+
#if defined(HAVE_LONG_INT_64)
148+
return__builtin_ctzl(word);
149+
#elif defined(HAVE_LONG_LONG_INT_64)
150+
return__builtin_ctzll(word);
151+
#else
152+
#error must have a working 64-bit integer datatype
153+
#endif/* HAVE_LONG_INT_64 */
154+
183155
#elif defined(_MSC_VER)
184-
constunsigned__int64orig_word=word;
185-
unsigned longbitscan_result;
156+
unsigned longresult;
186157
boolnon_zero;
187-
#endif
188158

189-
#if !defined(HAVE_BITSCAN_FORWARD)|| defined(USE_ASSERT_CHECKING)
159+
non_zero=_BitScanForward64(&result,word);
160+
Assert(non_zero);
161+
return (int)result;
162+
#else
190163
intresult=0;
191164

192165
Assert(word!=0);
@@ -197,29 +170,8 @@ pg_rightmost_one_pos64(uint64 word)
197170
result+=8;
198171
}
199172
result+=pg_rightmost_one_pos[word&255];
200-
#endif
201-
202-
#ifdefHAVE_BITSCAN_FORWARD
203-
204-
#if defined(HAVE__BUILTIN_CTZ)
205-
#if defined(HAVE_LONG_INT_64)
206-
bitscan_result=__builtin_ctzl(orig_word);
207-
#elif defined(HAVE_LONG_LONG_INT_64)
208-
bitscan_result=__builtin_ctzll(orig_word);
209-
#else
210-
#error must have a working 64-bit integer datatype
211-
#endif/* HAVE_LONG_INT_64 */
212-
213-
#elif defined(_MSC_VER)
214-
non_zero=_BitScanForward64(&bitscan_result,orig_word);
215-
Assert(non_zero);
216-
#endif/* HAVE__BUILTIN_CTZ */
217-
Assert(bitscan_result==result);
218-
returnbitscan_result;
219-
220-
#else
221173
returnresult;
222-
#endif/*HAVE_BITSCAN_FORWARD */
174+
#endif/*HAVE__BUILTIN_CTZ */
223175
}
224176

225177
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp