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

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

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

    隨筆 - 53, 文章 - 0, 評論 - 3, 引用 - 0
    數據加載中……

    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)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 亚洲色丰满少妇高潮18p| 亚洲第一网站免费视频| 日韩亚洲人成网站| 在线观看的免费网站| 亚洲精品无码久久久久久久| 日韩插啊免费视频在线观看| 亚洲AV乱码久久精品蜜桃| a级毛片免费高清毛片视频| 亚洲精品乱码久久久久66| a级大片免费观看| 亚洲AV无码成人精品区天堂 | 怡红院免费的全部视频| 亚洲伊人久久大香线蕉综合图片| 国产精品免费αv视频| 亚洲人色婷婷成人网站在线观看| 国产在线一区二区综合免费视频| 99久久精品国产亚洲| 性短视频在线观看免费不卡流畅| 亚洲日韩精品无码专区加勒比☆| 国产在线观看www鲁啊鲁免费| 特级av毛片免费观看| 亚洲国产一成人久久精品| 91福利视频免费观看| 亚洲sss综合天堂久久久| 波多野结衣免费视频观看 | 亚洲欧美日本韩国| 亚洲AV无码一区二区三区在线观看| 一级做受视频免费是看美女| 无码久久精品国产亚洲Av影片| 亚洲免费黄色网址| 国产亚洲综合视频| 亚洲激情中文字幕| 成全影视免费观看大全二| 免费一区二区三区在线视频| 亚洲欧洲国产精品香蕉网| 在线看免费观看AV深夜影院| 黄色免费网址在线观看| 亚洲美女视频一区| 午夜亚洲av永久无码精品| 日本免费一区二区三区| 色偷偷亚洲第一综合|