[otbn] Better specify "result" when setting flags The L, M and Z flags operate on the "result" of an operation. Clarify that this means only the "lower" 256 bits as they are written back to the destination register, not the overflow bit (which is present in the carry flag). Fixes #3336 (See also this issue for a long reason by Felix Miller why this is the correct behavior.) Signed-off-by: Philipp Wagner <phw@lowrisc.org>
diff --git a/hw/ip/otbn/doc/_index.md b/hw/ip/otbn/doc/_index.md index 274e3c9..47232ec 100644 --- a/hw/ip/otbn/doc/_index.md +++ b/hw/ip/otbn/doc/_index.md
@@ -307,6 +307,8 @@ - `Z` (Zero Flag) Set to 1 if the result of the last operation was zero; otherwise 0. +The `L`, `M`, and `Z` flags are determined based on the result of the operation as it is written back into the result register, without considering the overflow bit. + ### Loop Stack The LOOP instruction allows for nested loops; the active loops are stored on the loop stack. @@ -436,7 +438,7 @@ flags_out.C = result[WLEN] flags_out.L = result[0] flags_out.M = result[WLEN-1] - flags_out.Z = (result == 0) + flags_out.Z = (result[WLEN-1:0] == 0) return (result[WLEN-1:0], flags_out)