raz / commit 06ec7fde

commit
06ec7fde32d48cef86e37feddf9b20a54917218c
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
c3a65c4c
raz.md: MIN, MAX, CLZ, CTZ and POPCOUNT

patch · log

3 files changed, +40 -3

doc/raz.7 (history) modified +13 -0

@@ -472,6 +472,19 @@
472472 of an unsigned integer type, rotated left or right by
473473 .Ar n
474474 bits modulo its width.
475+.It Fn CLZ x , Fn CTZ x
476+The zero bits above the highest one, or below the lowest one, in
477+.Ar x ,
478+of an unsigned integer type; its width if
479+.Ar x
480+is 0.
481+.It Fn POPCOUNT x
482+The one bits in
483+.Ar x ,
484+of an unsigned integer type, or the members of a set.
485+.It Fn MIN T , Fn MAX T
486+The smallest, or the largest, value of the integer type
487+.Ar T .
475488 .It Cm FENCE
476489 A full memory barrier.
477490 .It Fn SYSCALL n x1 ...

doc/raz.md (history) modified +20 -2

@@ -49,7 +49,10 @@
4949 with `ADR`. 2026-10.34 is a tenth: `PTR(s)`, the address a slice
5050 starts at, even an empty one (section 6.8); it breaks no program.
5151 2026-10.35 is an eleventh: `ROL(x, n)` and `ROR(x, n)`, a word
52-rotated (sections 6.1 and 6.8); it breaks no program.
52+rotated (sections 6.1 and 6.8); it breaks no program. 2026-10.36 is a
53+twelfth: `MIN(T)` and `MAX(T)`, the limits of an integer type, and
54+`CLZ`, `CTZ` and `POPCOUNT`, which count bits (sections 6.1 and 6.8);
55+it breaks no program.
5356
5457 The language is frozen, softly, from this version on: it changes only
5558 to mend a defect, and its library grows only by what breaks no program
@@ -377,7 +380,8 @@
377380
378381 **Constants** are evaluated by the compiler. Their expressions use only
379382 literals, other constants, operators, conversions, `SIZE`, the `LEN`
380-of arrays and strings, `ROL` and `ROR`, and a variant's cases. A constant is an integer,
383+of arrays and strings, `MIN`, `MAX`, `ROL`, `ROR`, `CLZ`, `CTZ`,
384+`POPCOUNT`, and a variant's cases. A constant is an integer,
381385 a real, a `BOOL`, a name of an enumeration, a set, a string, an array,
382386 a record, a variant or an `ERROR`. A constant of an integer type wraps as the
383387 program would: `U8(250) + 10` is 4. Dividing by zero in a constant is
@@ -816,6 +820,17 @@
816820 and an `or` say only at more length: `ROR(x, 7)` is `x shr 7 | x shl
817821 25` for a `U32` `x`.
818822
823+`CLZ(x)` and `CTZ(x)` (section 6.8) count the zero bits above the
824+highest one in `x` and below the lowest one, and `POPCOUNT(x)` counts
825+its one bits. `x` is of an unsigned integer type, and the result is an
826+`INT`; for `x: U8`, `CLZ(x)` is 7 when `x` is 1, and `CLZ(x)` and
827+`CTZ(x)` are 8 when `x` is 0. The width is the type's, as for `ROL`; an
828+untyped constant has none, so `CLZ(1)` is an error, and `CLZ(U64(1))`
829+is 63. `POPCOUNT(x)` may also take a set, and counts its members.
830+`MIN(T)` and `MAX(T)` are the smallest and the largest value of the
831+integer type `T`, untyped constants: `MAX(U8)` is 255 and `MIN(I16)` is
832+-32768. Each of the five, given constants, is a constant (section 4).
833+
819834 Relations compare as signed or unsigned according to the type.
820835
821836 ### 6.2 Booleans
@@ -956,6 +971,9 @@
956971 | `XCHG(p, x)` | sets `p^ := x` and returns the value before, atomically |
957972 | `XADD(p, x)` | adds `x` to `p^` and returns the value before, atomically |
958973 | `ROL(x, n)`, `ROR(x, n)` | `x` rotated left, or right, by `n` bits modulo its width; `x` of an unsigned integer type (section 6.1) |
974+| `CLZ(x)`, `CTZ(x)` | the number of zero bits above the highest one in `x`, or below the lowest one, an `INT`; the width of `x`'s type if `x` is 0; `x` of an unsigned integer type |
975+| `POPCOUNT(x)` | the number of one bits in `x`, or of members of the set `x`, an `INT`; `x` of an unsigned integer type or a set |
976+| `MIN(T)`, `MAX(T)` | the smallest, or the largest, value of the integer type `T`, an untyped constant; any other type is an error |
959977 | `ARGC()` | the number of command line arguments, an `INT` |
960978 | `ARGV()` | the arguments, a `^^U8` (C strings) |
961979

doc/report-history.md (history) modified +7 -1

@@ -233,4 +233,10 @@
233233 - **2026-10.36.** Three modules join the standard library: `Rand`, a
234234 seeded random number generator; `Check`, checks for a test; and
235235 `Prop`, property tests and fuzzing with shrinking (volume 2). They are
236- not core. The language is unchanged, and no program breaks.
236+ not core. And a twelfth thaw, by the owner's word: `MIN(T)` and
237+ `MAX(T)`, the smallest and largest value of an integer type, untyped
238+ constants; and `CLZ(x)`, `CTZ(x)` and `POPCOUNT(x)`, which count the
239+ zero bits above the highest one, below the lowest one, and the one
240+ bits (or members of a set) of a word of an unsigned integer type, an
241+ `INT`, and of constants are a constant (sections 4, 6.1 and 6.8). A
242+ predeclared name may be hidden (section 2), so it breaks no program.