LSL, но обновляет правильные биты с 1, а не с 0 - PullRequest
0 голосов
/ 16 февраля 2020

Мне нужна инструкция, похожая на LSL, но биты справа должны быть заполнены 1, а не 0. Что-то вроде:

mov x0, 1
XXX x0, 3 -> here I should have 1111 in x0.

1 Ответ

3 голосов
/ 16 февраля 2020

К сожалению, нет, нет ни одной инструкции, которая будет делать это. Из вашего примера трудно сказать, хотите ли вы что-то наподобие арифметического c смещения вправо, которое будет заполняться на основе младшего значащего бита (либо один, либо ноль в зависимости от значения LSb), либо просто всегда заполнять единицами вместо нулей. В любом случае, вы можете достичь аналогичного результата в 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
...