Expand description
Runtime support for the Word8/Word16/Word32/Word64 ring types in COMPILED LOGOS.
Generated Rust constructs words with word32(x), rotates with rotl(x, n), and shows them.
Arithmetic and bit operators (+, ^, &, …) already live as trait impls on the Word
newtypes in [logicaffeine_base] — each delegating to the wrapping primitive — so the
emitted a + b is ring-correct with no per-site wrapping_*. This module supplies the
remaining glue the codegen names: the word* constructors, the width-generic rotl/rotr,
and the Showable impls so Show renders a word as its decimal value (matching the
tree-walker and VM byte-for-byte).
Structs§
- Lanes4
Word32 - Four lanes of
Word32= one 128-bit register (__m128i) — the SHA-1 state/message carrier. Unlike the arithmetic lane types, its vocabulary is the four Intel SHA operations (sha1rnds4/sha1msg1/sha1msg2/sha1nexte), so SHA-1 WRITTEN in Logos over these compiles to thesha1rnds4hardware sequence (AOT) and runs the byte-identical software spec [crate::sha_ops] on the interpreter. Laneiis bits[32i+31 : 32i]— index 0 low, index 3 high — matching_mm_loadu_si128. - Lanes4
Word64 - Four lanes of
Word64(one 256-bit SIMD register) — the Poly1305 accumulator lane vector. Carries[u64; 4]; ops have an AVX2 fast path proven byte-identical to the scalar lanes. - Lanes8
Word32 - Eight lanes of
Word32(one 256-bit SIMD register). Operations are lane-wise over the ℤ/2³² ring. - Lanes16
Word8 - Sixteen
Word8lanes = one 128-bit register (__m128i) — the BYTE-SHUFFLE carrier for SIMD text codecs (hex encode/decode). Its vocabulary isshuffle(pshufb, a 16-entry byte LUT), byte AND, per-byte shift, and the two byte interleaves — so a hex codec WRITTEN in Logos over it compiles to thepshufbsequence (AOT, when SSSE3 is statically enabled) and runs the byte-identical scalar spec on the interpreter. Laneiis bytei(index 0 low), matching_mm_loadu_si128. - Lanes16
Word16 - Sixteen lanes of
Word16(one 256-bit SIMD register) — the NTT coefficient lane vector. Carries[u16; 16]; the multiply-high is the SIGNED_mm256_mulhi_epi16(the Montgomery butterfly’smulhi). Ops have an AVX2 fast path proven byte-identical to the scalar lanes. - Word8
- A 8-bit wrapping integer: the ring ℤ/2^8ℤ, where every operation is total and wraps modulo 2^8.
- Word16
- A 16-bit wrapping integer: the ring ℤ/2^16ℤ, where every operation is total and wraps modulo 2^16.
- Word32
- A 32-bit wrapping integer: the ring ℤ/2^32ℤ, where every operation is total and wraps modulo 2^32.
- Word64
- A 64-bit wrapping integer: the ring ℤ/2^64ℤ, where every operation is total and wraps modulo 2^64.
Traits§
- Word
Rotate - Width-defined bit rotation, available on every word width so
rotl(x, n)is one name.
Functions§
- and_
not4 andNot4(a, b)— Keccak χ’s(¬a) ∧ bin one lane op (vpandn). The compiled form of the builtin.- byte_
add16 - Per-byte wrapping add — compiled
byteAdd16(a, b)(the ASCII→nibble decode). - hsum_
lanes4 - The horizontal sum of a
Lanes4Word64’s lanes as anInt— the compiled form ofhsumLanes4(v). - int_
of_ word16 - The unsigned value of a
Word16as anInt(0..2¹⁶−1) — the compiled form ofintOfWord16(w), the ML-KEM NTT’s Word16-coefficient → Int boundary. - int_
of_ word32 - The unsigned value of a
Word32as anInt— the compiled form ofintOfWord32(w), used to serialize a keystream word into bytes (Intmod/div) for the XOR against aSeq of Intpayload. - int_
of_ word64 - The value of a
Word64as anInt—intOfWord64(w). For values ≥ 2⁶³ this is a negativei64(two’s-complement bits); used on byte-masked lanes (< 256) in Keccak’s squeeze. - interleave_
hi16 - High-eight byte interleave (
_mm_unpackhi_epi8) — compiledinterleaveHi16(a, b). - interleave_
lo16 - Low-eight byte interleave (
_mm_unpacklo_epi8) — compiledinterleaveLo16(a, b). - lanes4_
of - Pack four
Word32s straight into a SHA-1 lane register — compiledlanes4Of(a, b, c, d). The alloc-free constructor (noSeq, no heap): the Logos SHA-1 packs a lane this way every round. - lanes4_
word32 - Pack the first 4
Word32s of a Seq into a SHA-1 lane register — compiledlanes4Word32(s). - lanes4_
word64 - Pack the first 4
Ints of a Seq into aLanes4Word64— the compiled form oflanes4Word64(s). - lanes8_
word32 - Pack the first 8
Word32s of a Seq into a lane vector — the compiled form oflanes8Word32(s). - lanes16_
word8 - Pack the first 16 bytes of a
Seq of Intinto a byte-shuffle register — compiledlanes16Word8(s). - lanes16_
word16 - Pack the first 16
Ints of a Seq into aLanes16Word16— the compiled form oflanes16Word16(s). - maddubs16
- Multiply-add adjacent byte pairs (
pmaddubsw) — compiledmaddubs16(a, w)(nibble-pair → byte). - montmul32
- The signed i32 Montgomery multiply (
vpmuldq) — the compiled form ofmontmul32(a, b, q, qinv), the ML-DSA NTT butterfly multiply. - mul32x32to64
- Lane-wise widening low-32 multiply (
vpmuludq) — the compiled form ofmul32x32to64(a, b). - mulhi16
- Lane-wise SIGNED high-16 multiply (
vpmulhw) — the compiled form ofmulhi16(a, b). - packus16
- Pack two
8×i16vectors to16×u8with unsigned saturation (packuswb) — compiledpackus16(a, b). - rotl
- Left rotation — the compiled form of
rotl(x, n). The amount is taken asi64(the type of a LOGOSInt) and reduced to the rotation width. - rotr
- Right rotation — the compiled form of
rotr(x, n). - seq_
of_ lanes4 - Unpack a
Lanes4Word64into a Seq of 4Intlanes — the compiled form ofseqOfLanes4(v). - seq_
of_ lanes8 - Unpack a lane vector into a Seq of 8
Word32— the compiled form ofseqOfLanes8(v). - seq_
of_ lanes4w32 - The 4 lanes back as a
Seq of Word32— compiledseqOfLanes4W32(v). - seq_
of_ lanes16 - Unpack a
Lanes16Word16into a Seq of 16Intlanes (u16 bits) —seqOfLanes16(v). - seq_
of_ lanes16w8 - The 16 bytes back as a
Seq of Int— compiledseqOfLanes16W8(v). - sha1msg1
sha1msg1(a, b)— message-schedule step 1. Lowers tosha1msg1.- sha1msg2
sha1msg2(a, b)— message-schedule step 2. Lowers tosha1msg2.- sha1nexte
sha1nexte(a, b)— fold the next round E. Lowers tosha1nexte.- sha1rnds4
sha1rnds4(abcd, msg, func)— four SHA-1 rounds. Lowers to thesha1rnds4instruction.- shr_
bytes16 - Per-byte logical shift right — compiled
shrBytes16(v, n). - shuffle16
- Byte shuffle (
pshufb) — compiledshuffle16(table, idx). - splat4_
word64 splat4Word64(x)— broadcast oneWord64into all four Keccak lanes (the ι round-constant XOR, and the all-ones vector for χ’s complement). The compiled form of the Logos builtin.- splat8_
word32 - Broadcast one
Word32into all 8 lanes — the compiled form ofsplat8Word32(x)(a crypto kernel loads a shared constant/key word into every block’s lane this way). - splat16_
word8 - Broadcast one byte into all 16 lanes — compiled
splat16Word8(x). - splat16_
word16 - Broadcast a
Word16/Intinto all 16 lanes — the compiled form ofsplat16Word16(x). - word8
- Construct a word from the low bits of an integer — the compiled form of
word32(x)etc. - word16
- word32
- word64
- word32_
shr word32Shr(w, n)— logical shift-right of aWord32bynbits (SHA-256’sσ0/σ1message schedule, where the shift is NOT a rotate — the vacated high bits are zero).- word64_
and word64And(a, b)— bitwise AND of twoWord64s (Keccak χ’s¬b ∧ c, and byte masking).- word64_
shl word64Shl(w, n)— logical shift-left of aWord64bynbits (Keccak lane byte-packing).- word64_
shr word64Shr(w, n)— logical shift-right of aWord64bynbits (Keccak squeeze byte-extract).- word_
and - Bitwise AND/OR/NOT — the compiled form of
word_and/word_or/word_not. Distinct from theand/orkeywords (logical short-circuit) so word crypto written in LOGOS (the MD5/SHA-1 round functions) is bit-exact on every tier. Word8/16/32/64 impl these operators, so they lower to a single machineand/or/not; a lane vector lowers to the AVX2 vector form. - word_
not - word_or