[{"data":1,"prerenderedAt":379},["ShallowReactive",2],{"project-29540416":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":28,"sentiment":29,"stance_mix":30,"scored_comments":35,"aspects":36,"strip":41,"post_text":43,"what":44,"said":83,"maker_in_thread":166,"shape":174,"grid":177,"attempts":342,"same_week":343,"maker_shows":42,"maker_hidden":371,"reader_version":372,"card":373},"29540416","LZMA decoder x86 CMOV patch","10-40% faster LZMA decoder using x86 CMOVcc","title","Show HN: 10-40% faster LZMA decoder using x86 CMOVcc","https:\u002F\u002Fgist.github.com\u002Filyakurdyukov\u002Ff514418f3affd677e1ac408ec0c09188","gist.github.com","jpegqs",1639409357,2021,205,68,220,2533,9,"notable","languages","compression library optimization","library",[24,25,26,27],"lzma decoder","x86 cmov","xz decompression","branchless code","curious",0.095,{"positive":31,"neutral":32,"mixed":33,"critical":34},3,6,0,1,10,{"performance":37,"execution":39,"idea":40},{"positive":38,"critical":33},2,{"positive":34,"critical":33},{"positive":33,"critical":34},[33,31,33,33,33,33,33,33,33,33,33,42,31,33,31,33,33,33,33,42,33,33,33,33,33,33,33,34,33,33,33,33,33,33,33,33,33,33,33,42],5,null,{"problem":45,"audience":43,"pricing":43,"motivation":52,"time_to_build":43,"stack":56,"openness":80,"stage":81,"team_size":82},{"value":46,"source":47,"evidence":48},"LZMA decompression is slow due to branching on every decoded bit","maker",[49],{"id":50,"by":11,"text":51},"29540453","LZMA compression (used in 7-zip, XZ, LZMA2) is known as one of the best, but it has a noticeable drawback - it's slow. I tried to improve the decompression speed by removing…",{"value":53,"source":47,"evidence":54},"Improve LZMA decompression speed by removing branching",[55],{"id":50,"by":11,"text":51},[57,65,72,76],{"value":58,"source":59,"evidence":60},"C","inferred",[61],{"id":62,"by":63,"text":64},"29542999","dragontamer","I'm trying to grok the performance improvement here. The diff points to: ``` + \u002F* tmp = rc.code \u003C rc_bound ? rc.range = rc_bound, ~0 : 0; *\u002F \\ + __asm__ ( \\ + \"cmpl %3, %2\\n\\t\" \\…",{"value":66,"source":47,"evidence":67},"x86 inline assembly",[68,69],{"id":50,"by":11,"text":51},{"id":70,"by":11,"text":71},"29551393","Cool, but it doesn't generate SBB in real code, but instead gives me something like this: ``` xorl %r11d, %r11d cmpl %r12d, %eax seta %r11b ``` And if I do both of these, side by…",{"value":73,"source":47,"evidence":74},"GCC",[75],{"id":50,"by":11,"text":51},{"value":77,"source":47,"evidence":78},"Clang",[79],{"id":50,"by":11,"text":51},"open_source","prototype","unknown",{"praise":84,"objections":99,"requests":119,"questions":132,"alternatives":147},[85,93],{"value":86,"source":87,"evidence":88},"Decent measured speedup on a Ryzen workstation with xz","commenter",[89],{"id":90,"by":91,"text":92},"29544844","injinj","Decent speedup on my 3970x. Including this patch reduced the number of instructions in lzma_decoder.s (using gcc 8.3.1) by about 8% (4417 lines of asm vs 4824). With perf stat,…",{"value":94,"source":87,"evidence":95},"Interesting low-level optimization result",[96],{"id":97,"by":63,"text":98},"29542801","But this seems like a patch given to the LZMA project, with an interesting low-level result to boot.",[100,108],{"value":101,"source":87,"evidence":102},"Compilers fail to reliably emit CMOV, so inline assembly is needed",[103,107],{"id":104,"by":105,"text":106},"29546297","mgaunard","I find it sad that you need to use inline asm for this. Why isn't GCC providing a built-in to reliably use cmov? Every time I use ?: it's a lottery whether I get it or not. I've…",{"id":70,"by":11,"text":71},{"value":109,"source":87,"evidence":110},"CMOV is not always faster than branching",[111,115],{"id":112,"by":113,"text":114},"29543624","10000truths","https:\u002F\u002Fwww.agner.org\u002Foptimize\u002Foptimizing_assembly.pdf#page=70 TL;DR rule of thumb is that conditional jump is better than CMOV if the code is part of a dependency chain and the…",{"id":116,"by":117,"text":118},"29543883","ncmncm","Correctly-predicted branching is better; but if the branch would have been mis-predicted, cmov is better. The compiler has no idea which will happen at runtime. Gcc will never…",[120,124],{"value":121,"source":47,"evidence":122},"Test results on different x86 CPUs",[123],{"id":50,"by":11,"text":51},{"value":125,"source":87,"evidence":126},"Compiler builtin for CMOV",[127,128],{"id":104,"by":105,"text":106},{"id":129,"by":130,"text":131},"29547791","mananaysiempre","I think I’ve observed reliably-emitted CMOVs when using equivalent (but contrived) arithmetic branchless idioms, e.g. instead of (a ? b : c) write (-!!a & b | -!a & c) (yes, this…",[133,140],{"value":134,"source":87,"evidence":135},"Would compiler intrinsics work across more architectures",[136],{"id":137,"by":138,"text":139},"29542602","CyberShadow","Would using compiler intrinsics instead of raw assembler have any benefits here, such as being applicable to more architectures?",{"value":141,"source":87,"evidence":142},"Could the same be done for aarch64",[143],{"id":144,"by":145,"text":146},"29549869","floatboth","Hm, should the same be done for aarch64? Generally compilers (well, clang) seem to use CSEL all the time anyway, would be interesting to investigate this.",[148,155,162],{"value":149,"source":87,"evidence":150},"Brotli",[151],{"id":152,"by":153,"text":154},"29541582","jeffbee","If you're going for decoding speed wouldn't you be using brotli anyway? At a given compression ratio brotli is ~4x faster on decode path, and they are similar on the encode path.…",{"value":156,"source":87,"evidence":157},"Zstandard",[158],{"id":159,"by":160,"text":161},"29542845","skyde","I think he mean is less popular (like zstandard and lz4) compared to zlib and LZMA and BZip2. this is unfortunate because Brotli and Zstandard compress much better than zLib and…",{"value":163,"source":87,"evidence":164},"LZ4 decoder with cmov",[165],{"id":116,"by":117,"text":118},{"comments":167,"answered":31,"key":168},7,[169,170,173],{"id":50,"text":51},{"id":171,"text":172},"29549252","It would be great to have builtin for CMOV. But I also want GCC to utilize the hack with the SBB instruction when I write something like: (unsigned)a \u003C (unsigned)b ? ~0 : 0…",{"id":70,"text":71},{"commenters":175,"max_depth":167,"maker_replies":167,"first_comment_mins":31,"lifespan_hours":176},41,27,[178,180,184,187,191,194,195,196,199,201,202,205,207,211,212,215,218,221,223,227,228,230,232,234,236,237,239,241,244,246,248,251,254,255,257,259,261,262,265,268,270,273,275,277,280,282,285,288,291,294,296,299,302,305,308,310,312,314,317,318,320,323,326,328,331,334,336,338],[50,33,33,179,11,34],"project\u002Fpositive\u002Fperformance",[181,34,31,182,183,33],"29541730","maker\u002Fneutral\u002Fnone","jack_pp",[185,34,31,182,186,33],"29546037","Tiberium",[188,34,33,189,190,33],"29546859","other\u002Fneutral\u002Fnone","sitkack",[192,34,33,189,193,33],"29547049","mhh__",[104,38,33,189,105,33],[129,38,33,189,130,33],[197,38,33,198,105,33],"29551988","commenter\u002Fneutral\u002Fnone",[200,38,33,198,130,33],"29555665",[171,38,33,189,11,34],[203,38,33,198,204,33],"29551171","account42",[70,38,33,206,11,34],"project\u002Fneutral\u002Fexecution",[208,31,33,209,210,33],"29543217","other\u002Fneutral\u002Fperformance","hasmanean",[112,31,33,209,113,33],[213,31,33,209,214,33],"29552251","mirker",[216,31,33,209,217,33],"29543629","wolf550e",[219,31,33,189,220,33],"29548403","speed_spread",[222,31,33,209,117,33],"29543720",[224,225,33,189,226,33],"29545345",4,"viraptor",[90,42,42,179,91,33],[144,32,31,229,145,33],"project\u002Fneutral\u002Fperformance",[231,32,33,229,11,34],"29549950",[233,32,33,229,11,34],"29551114",[235,32,33,179,11,34],"29551550",[137,167,31,206,138,33],[238,167,33,209,63,33],"29542753",[240,167,33,189,138,33],"29542825",[242,167,33,198,243,33],"29543192","danachow",[245,167,33,198,138,33],"29544841",[247,167,33,198,243,33],"29547947",[249,167,33,209,250,33],"29548877","adgjlsfhk1",[252,167,33,189,253,33],"29542859","brigade",[62,167,42,179,63,33],[256,167,31,229,253,33],"29543160",[258,167,33,189,63,33],"29544313",[260,167,33,209,253,33],"29544536",[116,167,33,209,117,33],[263,167,33,189,264,33],"29544273","mmozeiko",[266,167,33,198,267,33],"29545209","tssva",[269,167,33,198,63,33],"29545268",[271,167,33,198,272,33],"29548863","comex",[274,167,33,209,117,33],"29545428",[276,167,33,198,264,33],"29545736",[278,167,33,198,279,33],"29545866","ycombobreaker",[281,167,33,206,11,34],"29554049",[152,283,34,284,153,33],8,"project\u002Fcritical\u002Fidea",[286,283,33,189,287,33],"29541735","pletnes",[289,283,33,189,290,33],"29541796","peter-m80",[292,283,33,189,293,33],"29541830","stillicidious",[295,283,33,189,287,33],"29542221",[297,283,33,189,298,33],"29543855","ByTheBook",[300,283,33,189,301,33],"29542111","throwaway1777",[303,283,33,189,304,33],"29542673","GordonS",[306,283,33,189,307,33],"29542155","orev",[309,283,33,189,160,33],"29542290",[311,283,33,189,307,33],"29542333",[313,283,33,189,153,33],"29542632",[315,283,33,189,316,33],"29542817","masklinn",[159,283,33,189,160,33],[319,283,33,198,307,33],"29554784",[321,283,33,198,322,33],"29542736","duskwuff",[324,283,33,198,325,33],"29543490","sebazzz",[327,283,33,198,250,33],"29543831",[329,283,33,198,330,33],"29546753","throwthere",[332,283,33,198,333,33],"29544126","1vuio0pswjnm7",[335,283,33,189,153,33],"29544172",[97,283,42,337,63,33],"project\u002Fpositive\u002Fexecution",[339,283,31,340,341,33],"29543871","project\u002Fneutral\u002Fidea","rwmj",[],[344,349,354,358,363,367],{"id":345,"name":346,"points":347,"category":348},"29513547","federalist",433,"infrastructure",{"id":350,"name":351,"points":352,"category":353},"29540808","Deployment from Scratch",326,"learning_science",{"id":355,"name":356,"points":357,"category":353},"29551947","NLP for Semantic Search",239,{"id":359,"name":360,"points":361,"category":362},"29551465","DoodleCSS",188,"dev_tools",{"id":364,"name":365,"points":366,"category":362},"29538264","glibc-abi-tool",171,{"id":368,"name":369,"points":370,"category":362},"29535432","setup-new-computer-script",169,false,"v2",{"id":374,"name":5,"line":6,"ai":371,"cat":20,"year":13,"points":14,"comments":15,"rec":28,"s":375,"top":18,"kw":376,"maker":11,"domain":10,"tier":19,"attempts":33,"strip":377,"url":9,"mix":378,"praise":86,"objection":101,"sub":21},29540416,0.1,[24,25,26,27],"0300000000053030000500000001000000000005",[31,32,33,34],1794036614180]