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


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 最近2022中文字幕免费视频| 国产免费观看黄AV片| 最近免费中文字幕大全免费| 国产亚洲免费的视频看| 中文日韩亚洲欧美制服| 成人免费乱码大片A毛片| 国产大片91精品免费观看不卡| 四虎国产精品免费久久影院| 日韩精品亚洲专区在线影视| 无码国产精品一区二区免费16| 日韩免费高清一级毛片在线| 亚洲视频在线一区| 一级做α爱过程免费视频| 永久免费av无码网站韩国毛片| 伊伊人成亚洲综合人网7777| 亚洲乱色伦图片区小说| 久久黄色免费网站| 亚洲人成电影在线播放| 亚洲AV无码XXX麻豆艾秋| 91视频国产免费| 亚洲最大天堂无码精品区| 久草视频在线免费看| 99久久亚洲综合精品成人网| 大地资源在线资源免费观看| 亚洲精品国产精品乱码不卡| 久久久精品国产亚洲成人满18免费网站| 免费无码不卡视频在线观看| 亚洲第一页在线视频| 久久国产精品免费网站| 亚洲第一永久在线观看| 成人免费无码大片A毛片抽搐色欲| 亚洲视频在线观看地址| 日本在线免费播放| 亚洲国产日韩在线一区| 99爱免费观看视频在线| 亚洲日本va午夜中文字幕一区| 免费无码A片一区二三区| 亚洲在成人网在线看| 日本免费人成视频在线观看| 亚洲午夜无码久久| 亚洲精品午夜无码电影网|