<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 53, 文章 - 0, 評論 - 3, 引用 - 0
    數(shù)據(jù)加載中……

    A piece of beautiful and trick bitwise operation code.

    A detailed reading process of a piece of beautiful and trick bitwise operation code.
     
    The following code is from MMIXWare, it is used to implement the Wyde difference between two octabyte.
     
         in file: "mmix-arith.w"
         423 tetra wyde_diff(y,z)
         424   tetra y,z;
         425 {
         426   register tetra a=((y>>16)-(z>>16))&0x10000;
         427   register tetra b=((y&0xffff)-(z&0xffff))&0x10000;
         428   return y-(z^((y^z)&(b-a-(b>>16))));
         429 }
     
    It is hard to understand it without any thinking or verification, here is the process I used
    to check the correctness of this algorithm.

    let y = 0xuuuuvvvv;
         z = 0xccccdddd; (please note the [c]s may be different hex number.)
        
    then y>>16 = 0x0000uuuu;
         z>>16 = 0x0000cccc;
         
    then ((y>>16)-(z>>16)) = 0x1111gggg if #uuuu < #cccc or
         ((y>>16)-(z>>16)) = 0x0000gggg if #uuuu >= #cccc   

    so variable a = 0x00010000 if #uuuu < #cccc or
       variable a = 0x00000000 if #uuuu >= #cccc
      
    similarly, we can get
       variable b = 0x00010000 if #vvvv < #dddd or
       variable b = 0x00000000 if #vvvv >= #dddd

    for (b-a-(b>>16)))), there are four different result depending on the relation between a and b.
    when #uuuu >= #cccc and #vvvv >= #dddd, (b-a-(b>>16)))) = 0x00000000;
    when #uuuu >= #cccc and #vvvv < #dddd, (b-a-(b>>16)))) = 0x00001111;
    when #uuuu < #cccc and #vvvv >= #dddd, (b-a-(b>>16)))) = 0x11110000;
    when #uuuu < #cccc and #vvvv < #dddd, (b-a-(b>>16)))) = 0x11111111;
    You can see that >= map to #0000 and < map to #1111

    for y-(z^((y^z)&(b-a-(b>>16)))), when (b-a-(b>>16)))) is 0x00000000, z^((y^z)&(b-a-(b>>16))) is
    z^((y^z)& 0) = z^0=z, so y-(z^((y^z)&(b-a-(b>>16))))=y-z.
    similarily, when (b-a-(b>>16)))) is 0x11111111, z^((y^z)&(b-a-(b>>16))) is
    z^((y^z)& 1) = z^(y^z)=y, so y-(z^((y^z)&(b-a-(b>>16))))=0.

    when (b-a-(b>>16)))) is 0x11110000 or 0x11110000, we can treat the y and z as two separate wydes.
    each wyde in the result is correct.

    You may think it is a little stupid to verify such kind of details. but for my point of view,
    without such detailed analysis, I can not understand the algorithm in the code. with the hard
    work like this, I successfully understand it. The pleasure deserve the effort.
     
    I am wondering how can the author discover such a genius algorithm.


    posted on 2009-01-06 16:04 InPractice 閱讀(210) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 一区二区三区无码视频免费福利| 亚洲人成色4444在线观看| 永久免费观看的毛片的网站| 亚洲视频在线免费看| 免费无码又爽又刺激高潮视频 | 色屁屁www影院免费观看视频| 日韩激情无码免费毛片| 亚洲gay片在线gv网站| 又色又污又黄无遮挡的免费视| 精品韩国亚洲av无码不卡区| 国产无遮挡又黄又爽免费视频| 特级毛片全部免费播放a一级| 亚洲国产午夜福利在线播放| 久久精品国产亚洲AV嫖农村妇女| 久久久久久影院久久久久免费精品国产小说 | 亚洲精品无码不卡在线播放HE | 免免费国产AAAAA片| 亚洲日日做天天做日日谢| 免费无码成人AV片在线在线播放| 国产精品亚洲AV三区| 国产亚洲精aa成人网站| 亚洲视频免费在线观看| 亚洲校园春色另类激情| 免费一级毛片正在播放| 两个人日本WWW免费版| 亚洲精品在线播放| 国产精品成人四虎免费视频| 国产精品一区二区三区免费| 青青青国产免费一夜七次郎| 男女啪啪免费体验区| 亚洲av日韩av天堂影片精品| 在线观看H网址免费入口| 亚洲短视频男人的影院| 久久午夜免费视频| 日韩大片免费观看视频播放| 亚洲国产精品人久久| 免费观看的毛片手机视频| a毛片免费在线观看| 国产精品亚洲精品青青青| 亚洲精品国产电影| 国产一卡二卡四卡免费|