{"id":20052,"date":"2022-11-08T14:36:29","date_gmt":"2022-11-08T09:06:29","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/"},"modified":"2022-11-08T14:36:29","modified_gmt":"2022-11-08T09:06:29","slug":"solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/","title":{"rendered":"[Solved] What is the most efficient way to zero all bits below the most significant set bit?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-54759854\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"54759854\" data-parentid=\"54756500\" data-score=\"6\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"js-endorsements\" data-for-answer=\"54759854\">\n<\/div>\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>There&#8217;s no single instruction that can do this.  <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.felixcloutier.com\/x86\/BLSI.html\">BMI1 <code>blsi dst,src<\/code><\/a> can isolate the <em>lowest<\/em> set bit, not the highest.  i.e. <code>x &amp; -x<\/code>.  If x86 had a bit-reversed version of <code>blsi<\/code>, we could use that, but it doesn&#8217;t.<\/p>\n<hr>\n<p><strong>But you can do much better than what you were suggesting<\/strong>.  An all-zero input is always going to be a special case for bit-scan and shift. Otherwise our output has exactly 1 bit set.  It&#8217;s <code>1 &lt;&lt; bsr(input)<\/code>.<\/p>\n<pre><code>;; input: x in RDI\n;; output: result in RAX\nisolate_msb:\n    xor   eax, eax           ; tmp = 0\n    bsr   rdi, rdi           ; edi = bit index of MSB in input\n    jz    .input_was_zero\n    bts   rax, rdi           ; rax |= 1&lt;&lt;edi\n\n.input_was_zero:             ; return 0 for input=0\n    ret\n<\/code><\/pre>\n<p>Obviously for 32-bit inputs, use only 32-bit registers.  And if zero is not possible, omit the JZ.  Using BSR instead of LZCNT gives us a bit-index, not 31-bitidx, so we can use it directly.  But LZCNT is significantly faster on AMD.<\/p>\n<p>The xor-zeroing is off the critical path, to prepare an input for BTS.  xor-zero + BTS is the most efficient way to implement <code>1&lt;&lt;n<\/code> on Intel CPUs.  It&#8217;s 2 uops with 2c latency on AMD, so <code>mov rax,1<\/code> \/ <code>shl rax,cl<\/code> would be better there.  But worse on Intel because variable-count shifts are 3 uops, unless you use BMI2 <code>shlx<\/code>.<\/p>\n<p>Anyway, the real work here is BSR + BTS, so that&#8217;s 3 cycle + 1 cycle latency on Intel SnB-family.  (<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/agner.org\/optimize\/\">https:\/\/agner.org\/optimize\/<\/a>)<\/p>\n<hr>\n<h1>In C \/ C++, you&#8217;d write this as<\/h1>\n<pre><code>unsigned isolate_msb32(unsigned x) {\n    unsigned bitidx = BSR32(x);\n    \/\/return 1ULL &lt;&lt; bitidx;           \/\/ if x is definitely non-zero\n    return x ? 1U &lt;&lt; bitidx : x;\n}\n\nunsigned isolate_msb64(uint64_t x) {\n    unsigned bitidx = BSR64(x);\n    return x ? 1ULL &lt;&lt; bitidx : x;\n}\n<\/code><\/pre>\n<p>Where <code>BSR32<\/code> is defined in terms of an intrinsic your compiler supports.  This is where things get tricky, especially if you want a 64-bit version.  There&#8217;s no single portable intrinsic.  GNU C provides count-leading-zeros intrinsics, but GCC and ICC suck at optimizing <code>63-__builtin_clzll(x)<\/code> back into just BSR.  Instead they negate twice.  There <em>are<\/em> builtins for BSR specifically, but those are even more compiler-specific than just MSVC vs. compilers that support GNU extensions (gcc\/clang\/ICC).<\/p>\n<pre><code>#include &lt;stdint.h&gt;\n\n\/\/ define BSR32() and BSR64()\n#if defined(_MSC_VER) || defined(__INTEL_COMPILER)\n    #ifdef __INTEL_COMPILER\n        typedef unsigned int bsr_idx_t;\n    #else\n        #include &lt;intrin.h&gt;   \/\/ MSVC\n        typedef unsigned long bsr_idx_t;\n    #endif\n\n    static inline\n    unsigned BSR32(unsigned long x){\n        bsr_idx_t idx;\n        _BitScanReverse(&amp;idx, x); \/\/ ignore bool retval\n        return idx;\n    }\n    static inline\n    unsigned BSR64(uint64_t x) {\n        bsr_idx_t idx;\n        _BitScanReverse64(&amp;idx, x); \/\/ ignore bool retval\n        return idx;\n    }\n#elif defined(__GNUC__)\n\n  #ifdef __clang__\n    static inline unsigned BSR64(uint64_t x) {\n        return 63-__builtin_clzll(x);\n      \/\/ gcc\/ICC can't optimize this back to just BSR, but clang can and doesn't provide alternate intrinsics\n    }\n  #else\n    #define BSR64 __builtin_ia32_bsrdi\n  #endif\n\n    #include &lt;x86intrin.h&gt;\n    #define BSR32(x) _bit_scan_reverse(x)\n\n#endif\n<\/code><\/pre>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/godbolt.org\/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAM1QDsCBlZAQwBtMQBGAOgCYAOAJyCALAFYADPwDswucNIArLqVbNaoZAFJeAIR27SAZ1QBXYsg4ByHQGY8tZK1NYA1FtsBhIwXz1uCB7YWhIAgiGhAPSRrlhUDpiuugwASra8EACUruroSakAbCJZEXZ4VLGY8bSY6BAA%2BgCyDJ71AGrYKdla0p49npXVtQ31AJIAcgAq2AAy9Z4A8o0ACqMznZkRrtvuvPZUca71Y1Oz80ur6ylbO7cEAJ4ADrVVrqa0RnjANXkOBK4AIyMxHqeHQAA96gQPPowrc7JhWEZMDdbtsyo5nG4PJ4\/sQHAEgjtoq5mm0%2BnC0dsHs9Du9Pt9aq5WHRgIDgaCIVCYajdrZMLR8FRSpTtj5mAQ8MhXA5WAlefSvj98mkMorGXkWRpXODNtJ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er<\/a>, clang and ICC compile this branchlessly, even when they don&#8217;t know that <code>x<\/code> is non-zero.<\/p>\n<p>All 4 compilers fail to use <code>bts<\/code> to implement <code>1&lt;&lt;bit<\/code>. \ud83d\ude41  It&#8217;s very cheap on Intel.<\/p>\n<pre><code># clang7.0 -O3 -march=ivybridge   (for x86-64 System V)\n# with -march=haswell and later it uses lzcnt and has to negate.  \/sigh.\nisolate_msb32(unsigned int):\n        bsr     ecx, edi\n        mov     eax, 1\n        shl     rax, cl\n        test    edi, edi\n        cmove   eax, edi       # return 1&lt;&lt;bsr(x)  or  x (0) if x was zero\n        ret\n<\/code><\/pre>\n<p>GCC and MSVC make branchy code.  e.g.<\/p>\n<pre><code># gcc8.2 -O3 -march=haswell\n    mov     eax, edi\n    test    edi, edi\n    je      .L6\n    bsr     eax, edi\n    mov     edi, 1\n    shlx    rax, rdi, rax    # BMI2:  1 uop instead of 3 for shl rax,cl\n.L6:\n    ret\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved What is the most efficient way to zero all bits below the most significant set bit? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] There&#8217;s no single instruction that can do this. BMI1 blsi dst,src can isolate the lowest set bit, not the highest. i.e. x &amp; -x. If x86 had a bit-reversed version of blsi, we could use that, but it doesn&#8217;t. But you can do much better than what you were suggesting. An all-zero input is &#8230; <a title=\"[Solved] What is the most efficient way to zero all bits below the most significant set bit?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\" aria-label=\"More on [Solved] What is the most efficient way to zero all bits below the most significant set bit?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[465,1013,324,325,523],"class_list":["post-20052","post","type-post","status-publish","format-standard","hentry","category-solved","tag-assembly","tag-bit-manipulation","tag-c","tag-performance","tag-x86"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] What is the most efficient way to zero all bits below the most significant set bit? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] What is the most efficient way to zero all bits below the most significant set bit? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] There&#8217;s no single instruction that can do this. BMI1 blsi dst,src can isolate the lowest set bit, not the highest. i.e. x &amp; -x. If x86 had a bit-reversed version of blsi, we could use that, but it doesn&#8217;t. But you can do much better than what you were suggesting. An all-zero input is ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-08T09:06:29+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] What is the most efficient way to zero all bits below the most significant set bit?\",\"datePublished\":\"2022-11-08T09:06:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\"},\"wordCount\":343,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"assembly\",\"bit-manipulation\",\"c++\",\"performance\",\"x86\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\",\"name\":\"[Solved] What is the most efficient way to zero all bits below the most significant set bit? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-11-08T09:06:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] What is the most efficient way to zero all bits below the most significant set bit?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] What is the most efficient way to zero all bits below the most significant set bit? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] What is the most efficient way to zero all bits below the most significant set bit? - JassWeb","og_description":"[ad_1] There&#8217;s no single instruction that can do this. BMI1 blsi dst,src can isolate the lowest set bit, not the highest. i.e. x &amp; -x. If x86 had a bit-reversed version of blsi, we could use that, but it doesn&#8217;t. But you can do much better than what you were suggesting. An all-zero input is ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/","og_site_name":"JassWeb","article_published_time":"2022-11-08T09:06:29+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] What is the most efficient way to zero all bits below the most significant set bit?","datePublished":"2022-11-08T09:06:29+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/"},"wordCount":343,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["assembly","bit-manipulation","c++","performance","x86"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/","url":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/","name":"[Solved] What is the most efficient way to zero all bits below the most significant set bit? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-11-08T09:06:29+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-most-efficient-way-to-zero-all-bits-below-the-most-significant-set-bit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] What is the most efficient way to zero all bits below the most significant set bit?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/20052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=20052"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/20052\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=20052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=20052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=20052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}