{"id":20068,"date":"2018-01-04T14:05:54","date_gmt":"2018-01-04T19:05:54","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=20068"},"modified":"2018-01-04T14:05:54","modified_gmt":"2018-01-04T19:05:54","slug":"a-branchless-utf-8-decoder","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/01\/04\/a-branchless-utf-8-decoder\/","title":{"rendered":"A Branchless UTF-8 Decoder"},"content":{"rendered":"<p><a href=\"http:\/\/nullprogram.com\/blog\/2017\/10\/06\/\">Chris Wellons<\/a> (via <a href=\"https:\/\/twitter.com\/matiasgoldberg\/status\/948745881695682560\">Mat&iacute;as N. Goldberg<\/a>):<\/p>\n<blockquote cite=\"http:\/\/nullprogram.com\/blog\/2017\/10\/06\/\">\n<p>The CPU must correctly predict the length of the code point or else it will suffer a hazard. An incorrect guess will stall the pipeline and slow down decoding.<\/p>\n<p>[&#8230;]<\/p>\n<p>This reads four bytes regardless of the actual length. Avoiding doing something is branching, so this can&rsquo;t be helped. The unneeded bits are shifted out based on the length. That&rsquo;s all it takes to decode UTF-8 without branching.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Chris Wellons (via Mat&iacute;as N. Goldberg): The CPU must correctly predict the length of the code point or else it will suffer a hazard. An incorrect guess will stall the pipeline and slow down decoding. [&#8230;] This reads four bytes regardless of the actual length. Avoiding doing something is branching, so this can&rsquo;t be helped. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[],"tags":[45,138,71,258],"class_list":["post-20068","post","type-post","status-publish","format-standard","hentry","tag-c","tag-optimization","tag-programming","tag-unicode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/20068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=20068"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/20068\/revisions"}],"predecessor-version":[{"id":20069,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/20068\/revisions\/20069"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=20068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=20068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=20068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}