Skip to content

Tests: bit methods coverage (§4) #483

Closed

Description

@ehartford

Tests: bit methods coverage (§4)

Summary

Runtime codegen implements the §4.2.4 integer bit methods, but coverage is incomplete. Add behavior tests for rotate, byte swap, population/count-zero methods, bit reverse, return types, width behavior, and signed receiver bit patterns.

Spec

docs/with-specification.md:1031-1145 defines rotate_left, rotate_right, swap_bytes, popcount, clz, ctz, and bitreverse. It specifies width-aware behavior, i32 return type for count methods, zero handling for clz/ctz, 8-bit identity for swap_bytes, and comptime evaluation.

Current state

  • src/MirLower.w:5852-5894 classifies the bit methods as integer intrinsics.
  • src/CodegenDispatch.w:7070-7190 lowers runtime operations using LLVM intrinsics or shift/or code.
  • test/behavior/behav_rotate.w and test/behavior/behav_int_swap_bytes.w provide partial runtime coverage.
  • There is no single spec-mapped test file covering all bit methods, return types, zero cases, width wrapping of rotate counts, signed receivers, and bitreverse.
  • Comptime evaluation is a separate implementation gap tracked by Comptime evaluation of bit-manipulation methods (§4.2.4) #422.

Implementation plan

  1. Add/extend runtime behavior tests for every method listed in §4.2.4.
  2. Keep comptime-specific expectations in Comptime evaluation of bit-manipulation methods (§4.2.4) #422 unless implementing that issue at the same time. This issue can still include runtime tests that will pass before comptime support lands.
  3. Add type assertions for popcount, clz, and ctz returning i32.
  4. Include signed integer receivers where the expected result is defined by the fixed-width bit pattern.
  5. Include edge cases: zero input, all-ones input, 8-bit swap identity, rotate by 0, rotate by width, and rotate by greater than width.

Test plan

  • test/behavior/behav_int_bit_methods.w or extensions to existing files:
    • u8, u16, u32, and u64 examples.
    • popcount(0) == 0, popcount(all_ones) == width.
    • clz(0) == width, ctz(0) == width.
    • swap_bytes identity on u8, byte reversal on u16/u32.
    • bitreverse on an obvious bit pattern.
    • rotate count normalization.
  • Add compile-time type checks if the test harness has a convention for static assertions; otherwise use assignments to i32 for count method results.
  • Run with build, with build :fixpoint, and with build :test.

Acceptance criteria

Dependencies

Overlaps #422 for comptime evaluation. Do not block runtime coverage on #422 unless the chosen tests use const/comptime.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 4.2.4.17, 4.2.4.19, 4.2.4.20, 4.2.4.21, 4.2.4.22, 4.2.4.24, 4.2.4.25, 4.2.4.26.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing — runtime bit methods pinned by behav_int_bit_methods_runtime (ec03406): popcount/clz/ctz/swap_bytes/bitreverse across u8/u16/u32/u64, signed receiver, i32-return. (Comptime bit methods remain #422's scope.) §4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions