G*****h 发帖数: 33134 | |
c*****e 发帖数: 19 | |
A**u 发帖数: 2458 | |
G*****h 发帖数: 33134 | 4 的确是骂娘啊
【在 A**u 的大作中提到】 : 你老挖坑
|
r*********r 发帖数: 3195 | |
z****u 发帖数: 3461 | |
d********u 发帖数: 5383 | 7 埃,OPEN SOURCE这个圈子里的就喜欢嘴巴爽。有本事自己搞一个吧,又不行。自己翘
不起来,非要怪别人不性感?
【在 G*****h 的大作中提到】 : http://www.phoronix.com/image-viewer.php?id=0x2012&image=linus_
|
r****c 发帖数: 1494 | |
v*****r 发帖数: 1119 | 9 Linux 在 这个 video 里提到的 micro-optimization 应该是他三月初在 G+ 里贴的问
题,在征求大家的建议 on best code,G+的回复里不乏一些大腕,最后是澳洲的一个
college kid 贴的一行 code 被 Linux 采纳了,linux 的原贴如下:
Linus TorvaldsMar 3, 2012 - Public
More bitwise tricks..
So my quest to calculate the hash and the length of a pathname component
efficiently continues. I'm pretty happy with where I am now (some changes to
the code have happened, it you actually want to see the current situation
you need to check out the kernel mailing list post), but finding the number
of bytes in the final mask bothers me.
Using an explicit loop is out - the branch mispredicts kill it. And while at
least modern Intel CPU's do quite well with just using the bit scan
instructions ("bsf") to find where the first NUL or '/' was in the word,
that sucks on some older CPU's.
So I came up with the following trick to count the number of bytes set in
the byte mask:
/* Low bits set in each byte we used as a mask */
mask &= ONEBYTES;
/* Add up "mask + (mask<<8) + (mask<<16) +... ":
same as a multiply */
mask *= ONEBYTES;
/* High byte now contains count of bits set */
len += mask >> 8*(sizeof(unsigned long)-1);
and I'm wondering if anybody can come up with something that avoids the need
for that multiply (and again - conditionals don't work, the mispredict
costs kill you).
Because that multiply isn't free either.
【在 z****u 的大作中提到】 : http://www.youtube.com/watch?v=MShbP3OpASA&feature=player_embed
|
S*A 发帖数: 7142 | 10 And the result code is...
个
to
number
【在 v*****r 的大作中提到】 : Linux 在 这个 video 里提到的 micro-optimization 应该是他三月初在 G+ 里贴的问 : 题,在征求大家的建议 on best code,G+的回复里不乏一些大腕,最后是澳洲的一个 : college kid 贴的一行 code 被 Linux 采纳了,linux 的原贴如下: : Linus TorvaldsMar 3, 2012 - Public : More bitwise tricks.. : So my quest to calculate the hash and the length of a pathname component : efficiently continues. I'm pretty happy with where I am now (some changes to : the code have happened, it you actually want to see the current situation : you need to check out the kernel mailing list post), but finding the number : of bytes in the final mask bothers me.
|
v*****r 发帖数: 1119 | 11 I believe the following codes are what Linus added to kernel in the end (
Carl is the Aussie college kid).
/* Modified Carl Chatfield G+ version for 32-bit */
long a = (mask-256) >> 23;
long b = mask & 1;
return a + b + 1;
/* Jan Achrenius on G+ for 64-bit case */
return mask*0x0001020304050608 >> 56;
【在 S*A 的大作中提到】 : And the result code is... : : 个 : to : number
|
c*****m 发帖数: 1160 | 12 damn, magic numbers. the worst thing in the coding world. |