This image is from the "Computer Organization and Design" book:
As you can see, the left-hand column is labeled as "logical operations", but the operations shown are all bitwise. Conventionally, &&
and ||
are known as logical operators while &
and |
are known as bitwise operators.
They are introducing the table with the following sentences:
It follows that operations were added to programming languages and instruction set architectures to simplify, among other things, the packing and unpacking of bits into words. These instructions are called logical operations. Figure 2.8 shows logical operations in C, Java, and RISC-V.
Why do you think they write logical operators for &
and |
?
In computer-architecture terminology, operations on numbers are "arithmetic" (e.g. add/sub/mul/div).
Operations on bits are often called "logical" or "logic instructions" as in "boolean logic". (Arithmetic right shift, shifting in copies of the sign bit, is usually grouped with other shifts as a logic aka bitwise operation.)
For example, in the Wikipedia ALU (Arithmetic logic unit) article, the editor who wrote it says the opcode "specifies the desired arithmetic or logic operation to be performed by the ALU".
Agner Fog's instruction tables of his per-instruction performance-testing results categorizes integer instructions into Move / Arithmetic / Logic (bitwise, shifts, bit-test, setcc
) / Control transfer / String (yes, x86 is funky like that) / Other (like leave
and cpuid
). And similarly, FP arithmetic vs. logic (yes, SIMD instruction sets provide bitwise boolean instructions for FP/SIMD registers).
CPUs don't have "logical" operations in the sense of C and Java's &&
or ||
(not even for integer inputs without considering the short-circuit eval), so in the context of computer architecture, "logical" has a different meaning than in software where they needed to distinguish bitwise from the more complicated operation of logical operators.
The computer architecture usage is older, I assume.
Your book isn't saying that &
in C or Java is a "logical operator", but it is saying that an and
instruction performs a "logical operation" in the computer-architecture sense of the word. The corresponding C and Java operator is the bitwise &
operator.
Machine code doesn't have operators, just instructions. (Assembly language has operations on assemble-time constants, like andi x1, x2, (1<<4)-1
as an alternate way of writing andi x1, x2, 0x0f
. But this is purely a feature of an assembler, and not something an ISA reference manual will discuss.)
Usage citations from random tutorials or guides that came up when I googled computer architecture logical operations
https://www.tutorialspoint.com/what-are-logic-micro-operations-in-computer-architecture "Logic operations are binary micro-operations implemented on the bits saved in the registers. These operations treated each bit independently and create them as binary variables."
https://www.sciencedirect.com/topics/computer-science/logical-operation quotes some books, like Harris & Harris: Digital Design and Computer Architecture, 2016 - "ARM logical operations include AND, ORR (OR), EOR (XOR), and BIC (bit clear)". The same authors wrote the same thing about MIPS bitwise instructions.
https://www.techtarget.com/whatis/definition/arithmetic-logic-unit-ALU