mirror of
https://github.com/golang/go
synced 2024-10-05 18:21:21 -06:00
[dev.power64] runtime: replace getproccount with simpler code
This runs once. There is no need for inscrutable algorithms. Also it doesn't compile correctly with 9c. LGTM=minux R=minux CC=golang-codereviews https://golang.org/cl/130000043
This commit is contained in:
parent
25bde37af4
commit
ecbe6b9f7f
@ -78,19 +78,22 @@ static int32
|
|||||||
getproccount(void)
|
getproccount(void)
|
||||||
{
|
{
|
||||||
uintptr buf[16], t;
|
uintptr buf[16], t;
|
||||||
int32 r, cnt, i;
|
int32 r, n, i;
|
||||||
|
|
||||||
cnt = 0;
|
|
||||||
r = runtime·sched_getaffinity(0, sizeof(buf), buf);
|
r = runtime·sched_getaffinity(0, sizeof(buf), buf);
|
||||||
if(r > 0)
|
if(r <= 0)
|
||||||
|
return 1;
|
||||||
|
n = 0;
|
||||||
for(i = 0; i < r/sizeof(buf[0]); i++) {
|
for(i = 0; i < r/sizeof(buf[0]); i++) {
|
||||||
t = buf[i];
|
t = buf[i];
|
||||||
t = t - ((t >> 1) & 0x5555555555555555ULL);
|
while(t != 0) {
|
||||||
t = (t & 0x3333333333333333ULL) + ((t >> 2) & 0x3333333333333333ULL);
|
n += t&1;
|
||||||
cnt += (int32)((((t + (t >> 4)) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56);
|
t >>= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if(n < 1)
|
||||||
return cnt ? cnt : 1;
|
n = 1;
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone, the Linux rfork.
|
// Clone, the Linux rfork.
|
||||||
|
Loading…
Reference in New Issue
Block a user