"shift operates on bits individually" 是什么意思?
What's the meaning of "shift operates on bits individually"?
我在书上看过这句话:
Logical and Shift Instructions Operate on bits individually Unlike
arithmetic, which operate on entire word
Use to isolate fields. Either by masking or by shifting back and forth.
这两句话我完全看不懂。
移位和算术指令都会改变所有的位(在某些情况下),而在算术中,一位一位地相加计算答案。
那么这部分是什么意思"Instructions Operate on bits individually Unlike arithmetic, which operate on entire word"?
我的第二个问题:
我不知道这部分有什么想法你能给我解释一下吗:
Use to isolate fields. Either by masking or by shifting back and forth.
我的第三个问题:什么是逻辑指令。例如,他的意思是 AND、OR 吗?你能解释更多吗?
逻辑指令是and,or,xor,但是第一句我都看不懂。
关于第二个,假设您对单词的一部分感兴趣,例如位 6..4,并且您希望提取此信息。有两种方法可以做到这一点。
使用掩码和移位。你在你感兴趣的字段上设置了一个掩码,在其他地方设置了零,然后用这个掩码应用一个 AND。
unsigned original ; // initial data is yyy...yyyxxxyyyy
// where the interesting part is coded by xxx
unsigned field ; // we want to have field=00..0xxx
unsigned mask = 0x70 ; // 0...01110000 ones on the interesting part
field = original & mask ; // field=0...00xxx0000
field >>= 4 ; // field=00...00xxx
仅使用班次
unsigned original, field ; // initial data and interesting field
field = original << 25 ; // put interesting bits in the msb of field
// field=xxxyyyy00..00
field >>= 29 ; // get rid of the 4 LSB -> field=00...00xxx
如果您想修改这些位而不是提取它们,可以使用类似的方法。
逻辑和移位运算通常称为按位运算。它们 单独对位进行操作 这意味着每个输出位仅取决于输入中单个固定位位置的位,您可以立即计算该位而无需依赖任何其他位或先前的计算结果
例如,在 AND、OR、XOR 中...output[n]
(即输出中的位 n)是根据 input1[n]
和 input2[n]
计算得出的。类似地左移 N 仅从 input[i - N]
产生 output[i]
,并且补码 (NOT) 从 input[n]
转换为 output[n]
。我正在从 here 中获取示例图像,以便更容易理解
并且:
左移:
OTOH 加法结果中的每一位取决于进位 必须等待前面的加法操作完成,如Sn = An + Bn + Cn
可以通过像 carry-lookahead adder 中的某些逻辑预先计算进位来进行更快的加法运算,但它仍然较慢并且需要比没有依赖项的按位运算更多的芯片面积。类似地,其他算术运算也无法通过单独获取每个输出位来完成。
这是你的第一个和第三个问题。关于第二个
Use to isolate fields Either by masking or by shifting back and forth.
表示它们用于通过使用 AND 进行掩码来获得 bit fields(即只让该字段中的位通过,通过过滤掉掩码为零的位置的位),或者通过移出将位归零并移回其原始位置
进一步阅读:
- What are bitwise shift (bit-shift) operators and how do they work?
- How do you set, clear, and toggle a single bit?
- What is Bit Masking?
- What are bitwise operators?
- https://en.wikipedia.org/wiki/Bit_manipulation
- https://en.wikipedia.org/wiki/Bitwise_operation
- https://en.wikipedia.org/wiki/Adder_(electronics)
- bitwise-operators
- bit-manipulation
我在书上看过这句话:
Logical and Shift Instructions Operate on bits individually Unlike arithmetic, which operate on entire word
Use to isolate fields. Either by masking or by shifting back and forth.
这两句话我完全看不懂。
移位和算术指令都会改变所有的位(在某些情况下),而在算术中,一位一位地相加计算答案。
那么这部分是什么意思"Instructions Operate on bits individually Unlike arithmetic, which operate on entire word"?
我的第二个问题:
我不知道这部分有什么想法你能给我解释一下吗:
Use to isolate fields. Either by masking or by shifting back and forth.
我的第三个问题:什么是逻辑指令。例如,他的意思是 AND、OR 吗?你能解释更多吗?
逻辑指令是and,or,xor,但是第一句我都看不懂。
关于第二个,假设您对单词的一部分感兴趣,例如位 6..4,并且您希望提取此信息。有两种方法可以做到这一点。
使用掩码和移位。你在你感兴趣的字段上设置了一个掩码,在其他地方设置了零,然后用这个掩码应用一个 AND。
unsigned original ; // initial data is yyy...yyyxxxyyyy // where the interesting part is coded by xxx unsigned field ; // we want to have field=00..0xxx unsigned mask = 0x70 ; // 0...01110000 ones on the interesting part field = original & mask ; // field=0...00xxx0000 field >>= 4 ; // field=00...00xxx
仅使用班次
unsigned original, field ; // initial data and interesting field field = original << 25 ; // put interesting bits in the msb of field // field=xxxyyyy00..00 field >>= 29 ; // get rid of the 4 LSB -> field=00...00xxx
如果您想修改这些位而不是提取它们,可以使用类似的方法。
逻辑和移位运算通常称为按位运算。它们 单独对位进行操作 这意味着每个输出位仅取决于输入中单个固定位位置的位,您可以立即计算该位而无需依赖任何其他位或先前的计算结果
例如,在 AND、OR、XOR 中...output[n]
(即输出中的位 n)是根据 input1[n]
和 input2[n]
计算得出的。类似地左移 N 仅从 input[i - N]
产生 output[i]
,并且补码 (NOT) 从 input[n]
转换为 output[n]
。我正在从 here 中获取示例图像,以便更容易理解
并且:
左移:
OTOH 加法结果中的每一位取决于进位 必须等待前面的加法操作完成,如Sn = An + Bn + Cn
可以通过像 carry-lookahead adder 中的某些逻辑预先计算进位来进行更快的加法运算,但它仍然较慢并且需要比没有依赖项的按位运算更多的芯片面积。类似地,其他算术运算也无法通过单独获取每个输出位来完成。
这是你的第一个和第三个问题。关于第二个
Use to isolate fields Either by masking or by shifting back and forth.
表示它们用于通过使用 AND 进行掩码来获得 bit fields(即只让该字段中的位通过,通过过滤掉掩码为零的位置的位),或者通过移出将位归零并移回其原始位置
进一步阅读:
- What are bitwise shift (bit-shift) operators and how do they work?
- How do you set, clear, and toggle a single bit?
- What is Bit Masking?
- What are bitwise operators?
- https://en.wikipedia.org/wiki/Bit_manipulation
- https://en.wikipedia.org/wiki/Bitwise_operation
- https://en.wikipedia.org/wiki/Adder_(electronics)
- bitwise-operators
- bit-manipulation