LSL 但用 1 而不是 0 更新右位
LSL but updating right bits with 1 rather than 0
我需要一个类似于LSL的指令,但是右边的位必须用1而不是0来填充。
类似于:
mov x0, 1
XXX x0, 3 -> here I should have 1111 in x0.
很遗憾,没有一条指令可以做到这一点。从你的例子中,很难说你是否想要像算术右移这样的东西,它会根据最低有效位(根据 LSb 的值是 1 还是 0)来填充,或者只是总是用 1 而不是 0 来填充。无论哪种方式,您都可以在 2/3 指令中获得类似的结果:
MOV x0, #1
/* For the fill with LSb case */
RBIT x0, x0 /* reverse the bit order of the register */
ASR x0, x0, #3 /* use arithmetic right shift to do the shift, it will fill with the old LSb, now MSb */
RBIT x0, x0 /* fill bits back */
/* For the fill with 1s case */
MVN x0, x0 /* bitwise not the value of the register */
MVN x0, x0, LSL #3 /* shift the register value, filling with 0s, then invert the register again, restoring the original bits and flipping the filled 0s to 1s */
/* From the comments, it looks like OP wants the shift to come from another register and not a constant like in their post so the above needs an extra instruction */
MOV x1, #3 /* load the shift amount into a register */
MVN x0, x0
LSL x0, x0, x1 /* need a separate instruction to use a register instead of a constant as the shift amount */
MVN x0, x0
我需要一个类似于LSL的指令,但是右边的位必须用1而不是0来填充。 类似于:
mov x0, 1
XXX x0, 3 -> here I should have 1111 in x0.
很遗憾,没有一条指令可以做到这一点。从你的例子中,很难说你是否想要像算术右移这样的东西,它会根据最低有效位(根据 LSb 的值是 1 还是 0)来填充,或者只是总是用 1 而不是 0 来填充。无论哪种方式,您都可以在 2/3 指令中获得类似的结果:
MOV x0, #1
/* For the fill with LSb case */
RBIT x0, x0 /* reverse the bit order of the register */
ASR x0, x0, #3 /* use arithmetic right shift to do the shift, it will fill with the old LSb, now MSb */
RBIT x0, x0 /* fill bits back */
/* For the fill with 1s case */
MVN x0, x0 /* bitwise not the value of the register */
MVN x0, x0, LSL #3 /* shift the register value, filling with 0s, then invert the register again, restoring the original bits and flipping the filled 0s to 1s */
/* From the comments, it looks like OP wants the shift to come from another register and not a constant like in their post so the above needs an extra instruction */
MOV x1, #3 /* load the shift amount into a register */
MVN x0, x0
LSL x0, x0, x1 /* need a separate instruction to use a register instead of a constant as the shift amount */
MVN x0, x0