Skip to content

Narrow 8- and 16-bit signed division and shift results - #30

Merged
maleadt merged 1 commit into
mainfrom
tb/narrow-signed-binops
Nov 10, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/narrow-signed-binops

Conversation

@maleadt

@maleadt maleadt commented Nov 10, 2026

Copy link
Copy Markdown
Member

Narrow 8- and 16-bit signed division and shift results

OpSDiv, OpSRem and OpShiftRightArithmetic on char/short were emitted as

ushort v = as_ushort(as_short(a) / as_short(b));

C promotes the operands to int, so as_ushort gets an int and clang rejects the size mismatch. This now casts the result back to the signed operand type first (as_ushort((short)(...))). Vectors don't promote and are unchanged.

Recent GPUArrays kernels do 16-bit signed division, which made the OpenCL.jl job fail in findall, logical indexing, accumulate and a few others (e.g. on #29). Every one of those failures was this compile error. The compare_exact ones show up as "Test Failed" because that helper catches the exception and compares its type.

OpSDiv, OpSRem and OpShiftRightArithmetic were emitted as
as_ushort(as_short(a) / as_short(b)). C promotes the char and short
operands to int, so as_ushort got an int and clang rejected the size
mismatch. Cast the result back to the signed operand type first; vectors
don't promote and are left alone.

Recent GPUArrays kernels do 16-bit signed division, which broke findall,
logical indexing and accumulate in the OpenCL.jl job.
@maleadt
maleadt merged commit 4c45134 into main Nov 10, 2026
4 of 5 checks passed
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