Skip to content

fix: take uint_least8_t in fxp_rescale for CHAR_BIT == 16 targets - #3

Merged
aajll merged 2 commits into
masterfrom
2-fix-uint-least8
Oct 14, 2026
Merged

aajll merged 2 commits into
masterfrom
2-fix-uint-least8

Conversation

@aajll

@aajll aajll commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Refs #2

What and why

fxp_rescale() declared its fractional-bit counts as uint8_t. C11 provides uint8_t only where an exact 8-bit type exists, so fxp.h did not compile on targets with CHAR_BIT == 16, such as TI C2000. That blocks fixedpoint-control's move onto fxp (aajll/fixedpoint-control#6 to #9) on its main target.

  • Fix — fxp_rescale takes uint_least8_t. Where uint8_t exists the two are the same type, so this is source- and ABI-compatible for existing callers. README, guide and CHANGELOG ([Unreleased]) follow.
  • CI gate — a c2000 job builds the library with -Dwerror=true on CGT 22.6.2 and 25.11.1, under --abi=coffabi and --abi=eabi (C2000 double is 32-bit under COFF and 64-bit under EABI, which matters for fxp_convert.c). Installers come from TI's public download server, are checked against pinned SHA-256 sums, and the installed toolchain is cached per version.
  • Guides — CONTRIBUTING and AGENTS forbid uint8_t/int8_t in favour of the least types.

Audit for 16-bit int

Besides the exact-width type, I audited src/ for 16-bit-int hazards: unsuffixed literals at or above 2^15, 1 << n on int, and narrow-type arithmetic that promotes to int. Every shift operates on a fxp_wide_t or fxp_calc_t cast, and the only plain unsigned int values hold shift counts below FXP_WORD_BITS. cl2000 --issue_remarks reports nothing on fxp.c or fxp_convert.c; a probe confirmed that it does flag an oversized 1 << 20 on this target.

Evidence

Check Result
Library, -Dwerror=true, CGT 22.6.2 and 25.11.1, with_convert true and false 0 diagnostics
CI step run locally, both CGTs, COFF and EABI pass
Same step with uint8_t restored fails: identifier "uint8_t" is undefined
All four test programs compiled and linked (-z, lnk.cmd, libc.a), both CGTs, both ABIs 0 diagnostics
Host: ASan+UBSan, coverage, release, core-only (with_convert=false) all tests pass; coverage 97.7% lines, 89.7% branches (gates 80/70)
clang-format (pinned, via uvx) clean

Limitations

The C2000 evidence is from compiling and linking. No C28x hardware or simulator is available, so the test programs were not executed on target. Running them on target remains a separate step.

aajll added 2 commits October 14, 2026 17:48
C11 provides uint8_t only where an exact 8-bit type exists, so fxp.h failed to compile on targets with CHAR_BIT == 16, such as TI C2000. uint_least8_t exists everywhere and is the same type as uint8_t where that type exists, so callers need no change.

Refs #2
Builds the library with -Dwerror=true on CGT 22.6.2 and 25.11.1, under both COFF and EABI, so code that assumes CHAR_BIT == 8 or a 32-bit int fails CI instead of reaching consumers. The installers are checksum-pinned and the installed toolchains cached; the guides now state the rule against exact 8-bit types.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant