<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 閱讀(213) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 天天操夜夜操免费视频| 精品国产污污免费网站aⅴ| 亚洲精品456在线播放| 亚洲人成影院在线观看| 成人免费大片免费观看网站| 男女一边摸一边做爽的免费视频 | jizz免费一区二区三区| 亚洲乱码中文字幕小综合| 亚洲精品无码Av人在线观看国产| 成人免费无码大片a毛片| 免费视频成人片在线观看| 一级女性全黄生活片免费看| 亚洲熟妇无码一区二区三区| 亚洲高清在线mv| 久久精品国产亚洲av成人| 国产亚洲精品AA片在线观看不加载| 日本无吗免费一二区| 黄页免费的网站勿入免费直接进入| 日本免费污片中国特一级| 国产精品免费久久| 免费人成视频在线播放| 成a人片亚洲日本久久| 亚洲中文字幕无码mv| 色婷五月综激情亚洲综合| 亚洲成av人片在线看片| 亚洲欧洲日产国产最新| 91久久亚洲国产成人精品性色| 亚洲精品午夜无码专区| 亚洲乱码精品久久久久..| 亚洲日韩国产精品第一页一区| 在线亚洲人成电影网站色www| 亚洲国产成人爱av在线播放| 免费国产一级特黄久久| 亚洲va中文字幕无码| 亚洲综合久久夜AV | 亚洲色偷偷狠狠综合网| 久久亚洲av无码精品浪潮| 国产偷窥女洗浴在线观看亚洲| 国产L精品国产亚洲区久久 | 成人片黄网站色大片免费观看cn| 国产成人1024精品免费|