Title: All examples are compiled with -O3 for x86-64.<p>https:&#x2F;&#x2F;godbolt.org&#x2F;z&#x2F;PYxz55
(GCC 9, 10, 11)<p><pre><code>    xorl    %eax, %eax
    movl    $0, -24(%rsp)
    movw    %ax, -20(%rsp)
    movabsq $72057594037927935, %rax
    movb    $0, -18(%rsp)
    andq    -24(%rsp), %rax
    salq    $8, %rax
    movb    %dil, %al
    ret

</code></pre>
https:&#x2F;&#x2F;godbolt.org&#x2F;z&#x2F;8njqn1 (GCC 9, 10)<p><pre><code>    xorl    %edx, %edx
    movl    $1, %eax
    movb    $2, %dl
    movq    %rax, -24(%rsp)
    xorl    %eax, %eax
    movq    %rdx, -16(%rsp)
    movdqa  -24(%rsp), %xmm0
    pinsrd  $3, %eax, %xmm0
    movaps  %xmm0, -24(%rsp)
    movq    -24(%rsp), %rax
    movq    -16(%rsp), %rdx
    ret

</code></pre>
https:&#x2F;&#x2F;godbolt.org&#x2F;z&#x2F;sronaG (GCC 7, 8, 9, 10, 11)<p><pre><code>    movq    %rdi, -24(%rsp)
    movq    -24(%rsp), %rax
    movq    %rsi, -16(%rsp)
    movq    -16(%rsp), %rdx

</code></pre>
For each example, two movs and a ret (and no stack access) would suffice.
Upvote: