Skip to content

feat: std.intdiv - #2849

Open
iwoplaza wants to merge 1 commit into
mainfrom
feat/std-intdiv
Open

feat: std.intdiv#2849
iwoplaza wants to merge 1 commit into
mainfrom
feat/std-intdiv

Conversation

@iwoplaza

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI lite review requested due to automatic review settings August 14, 2026 09:37
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@f012224736fa3ac54991a3beab337edd02c207ea

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased (max 0.54%) ❔ Unknown
0 209 115 1

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Click to reveal the results table (62 entries).
Test tsdown
std_dot.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_length.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_distance.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_dot4U8Packed.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_fract.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_frexp.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_mix.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_modf.ts 69.67 kB ($${\color{red}+0.5\%}$$)
std_abs.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_acos.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_acosh.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_asin.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_asinh.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_atan.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_atan2.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_atanh.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_ceil.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_clamp.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_cos.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_cosh.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_countLeadingZeros.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_countOneBits.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_countTrailingZeros.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_cross.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_degrees.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_determinant.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_dot4I8Packed.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_exp.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_exp2.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_extractBits.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_faceForward.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_firstLeadingBit.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_firstTrailingBit.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_floor.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_fma.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_insertBits.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_inverseSqrt.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_ldexp.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_log.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_log2.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_max.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_min.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_normalize.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_pow.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_quantizeToF16.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_radians.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_reflect.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_refract.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_reverseBits.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_round.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_saturate.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_sign.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_sin.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_sinh.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_smoothstep.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_sqrt.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_step.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_tan.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_tanh.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_transpose.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_trunc.ts 69.68 kB ($${\color{red}+0.5\%}$$)
std_intdiv.ts 69.68 kB

import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):

Test tsdown
tgpu_init.ts 274.88 kB ($${\color{green}-3.4\%}$$)
tgpu_initFromDevice.ts 274.34 kB ($${\color{green}-3.5\%}$$)
tgpu_resolve.ts 175.17 kB ($${\color{green}-38.4\%}$$)
tgpu_resolveWithContext.ts 175.11 kB ($${\color{green}-38.4\%}$$)
tgpu_bindGroupLayout.ts 74.49 kB ($${\color{green}-73.8\%}$$)
tgpu_mutableAccessor.ts 69.21 kB ($${\color{green}-75.7\%}$$)
tgpu_accessor.ts 69.21 kB ($${\color{green}-75.7\%}$$)
tgpu_privateVar.ts 67.90 kB ($${\color{green}-76.1\%}$$)
tgpu_workgroupVar.ts 67.90 kB ($${\color{green}-76.1\%}$$)
tgpu_const.ts 67.32 kB ($${\color{green}-76.3\%}$$)
tgpu_lazy.ts 67.12 kB ($${\color{green}-76.4\%}$$)
tgpu_fragmentFn.ts 39.65 kB ($${\color{green}-86.1\%}$$)
tgpu_fn.ts 39.60 kB ($${\color{green}-86.1\%}$$)
tgpu_vertexFn.ts 39.47 kB ($${\color{green}-86.1\%}$$)
tgpu_computeFn.ts 39.17 kB ($${\color{green}-86.2\%}$$)
tgpu_vertexLayout.ts 28.30 kB ($${\color{green}-90.1\%}$$)
tgpu_comptime.ts 15.91 kB ($${\color{green}-94.4\%}$$)
tgpu_unroll.ts 1.75 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.70 kB ($${\color{green}-99.4\%}$$)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [1.06, 2.13, 4.60, 7.31, 8.50, 13.46, 27.05, 26.89]
  line [1.08, 2.10, 4.44, 7.65, 8.20, 13.66, 25.72, 25.10]
  line [1.00, 2.07, 4.94, 7.20, 8.62, 11.40, 26.11, 26.17]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.32, 0.60, 0.78, 0.87, 1.21, 1.25, 1.54, 1.68]
  line [0.30, 0.53, 0.69, 0.84, 1.16, 1.26, 1.43, 1.62]
  line [0.29, 0.56, 0.73, 0.86, 1.21, 1.24, 1.51, 1.68]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.96, 2.49, 4.71, 8.10, 13.81, 29.24, 62.74, 125.34]
  line [0.92, 2.35, 4.76, 8.70, 14.04, 28.51, 60.29, 118.85]
  line [0.87, 2.27, 4.06, 7.42, 12.93, 27.04, 58.62, 120.32]
Loading

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new std.intdiv helper to provide integer-division semantics (with proper type unification) in TypeGPU’s standard library, along with a dedicated test suite to validate CPU behavior, TGSL codegen, coercions, and unsupported-argument errors.

Changes:

  • Introduces std.intdiv as a dualImpl in packages/typegpu/src/std/numeric.ts.
  • Re-exports intdiv from packages/typegpu/src/std/index.ts for public consumption.
  • Adds packages/typegpu/tests/std/numeric/intdiv.test.ts to cover i32/u32, mixed integer types, float coercion, and vector-argument rejection.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/typegpu/src/std/numeric.ts Adds std.intdiv implementation (CPU + WGSL codegen) and signature validation.
packages/typegpu/src/std/index.ts Exposes intdiv via the public std entrypoint.
packages/typegpu/tests/std/numeric/intdiv.test.ts Adds tests for correctness, codegen snapshots, type capture, and error reporting.
Suppressed comments (1)

packages/typegpu/tests/std/numeric/intdiv.test.ts:106

  • Second inline error snapshot also hardcodes fn:div; update it to fn:intdiv to stay consistent with the function name shown by the resolver after renaming.
    - fn:div: Unsupported data types: abstractInt, vec3i. Supported types are: u32, i32.]

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/typegpu/src/std/numeric.ts
Comment thread packages/typegpu/src/std/numeric.ts
Comment thread packages/typegpu/src/std/numeric.ts
Comment thread packages/typegpu/tests/std/numeric/intdiv.test.ts Outdated

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Minor suggestions only - a couple of polish items, nothing blocking.

Reviewed changes

This PR adds std.intdiv, a dual-CPU/WGSL integer division operator restricted to scalar u32/i32 (vector/composite args reject with SignatureNotSupportedError), wired into the std barrel with a CPU reference implementation and a / codegen path.

  • packages/typegpu/src/std/numeric.ts — adds cpuIntdiv and the intdiv dualImpl (signature unify to [u32, i32], codegenImpl emitting /, ignoreImplicitCastWarning, sideEffects: false).
  • packages/typegpu/src/std/index.ts — exports intdiv from the std barrel.
  • packages/typegpu/tests/std/numeric/intdiv.test.ts — 5 tests covering i32, u32, mixed u32/i32, float coercion, and vector rejection via inline snapshots.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu/src/std/numeric.ts Outdated
Comment thread packages/typegpu/src/std/numeric.ts

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This incremental review covers the single new commit (0d4c02d69) since the prior Pullfrog review (9baee402). It resolves both previously raised items and adds a small declaration-style touch-up:

  • cpuIntdiv reuses divInteger — the CPU path now delegates to the shared divInteger helper in data/numberOps.ts, inheriting its rhs === 0 → lhs guard so CPU and WGSL division-by-zero semantics stay consistent. Also inverted to an early-throw on non-number args.
  • name: 'div'name: 'intdiv' — resolution/diagnostic errors for intdiv now report as fn:intdiv instead of colliding with std.div. Test snapshots updated accordingly.
  • data/numberOps.tsdivInteger converted from arrow to function declaration and annotated with the WGSL div-by-zero comment.

All 5 intdiv tests pass. No blocking or noteworthy issues in the delta.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one design observation worth a second look; everything tested and passing.

Reviewed changes

This incremental review covers the new commit f0122247 landed since the prior review (0d4c02d69).

  • Removed ignoreImplicitCastWarning: true from the intdiv dualImpl in packages/typegpu/src/std/numeric.ts:1325 — mixed u32/i32 and float-coercion calls now surface [implicit-conversion] warnings.
  • Added console-warning assertions to the mixed-int and float-coercion tests in packages/typegpu/tests/std/numeric/intdiv.test.ts, asserting the two implicit-conversion warnings (101u→i32, 5u→i32) and the float coercion warning.

All 5 intdiv tests pass. Prior feedback (reuse divInteger, name: 'intdiv') remains addressed.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +1325 to +1335
export const intdiv = dualImpl({
name: 'intdiv',
signature: (lhs: BaseData, rhs: BaseData) => {
const unified = unify([lhs, rhs], [u32, i32]);
if (!unified) {
throw new SignatureNotSupportedError([lhs, rhs], [u32, i32]);
}
return { argTypes: unified, returnType: unified[0] };
},
normalImpl: cpuIntdiv,
codegenImpl: (ctx, [lhs, rhs]) => ctx.gen.emitBinaryOp(lhs, '/', rhs),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing ignoreImplicitCastWarning: true means every mixed-u32/i32 and float-coercion call to std.intdiv now emits [implicit-conversion] warnings. Since this operator's signature deliberately unifies u32/i32 and coerces floats, warning on those expected inputs makes each documented usage noisy. Worth confirming the warning noise on intended inputs is desired, vs. keeping the flag (the coercion is inherent to intdiv, not an accidental implicit cast).

Suggested change
export const intdiv = dualImpl({
name: 'intdiv',
signature: (lhs: BaseData, rhs: BaseData) => {
const unified = unify([lhs, rhs], [u32, i32]);
if (!unified) {
throw new SignatureNotSupportedError([lhs, rhs], [u32, i32]);
}
return { argTypes: unified, returnType: unified[0] };
},
normalImpl: cpuIntdiv,
codegenImpl: (ctx, [lhs, rhs]) => ctx.gen.emitBinaryOp(lhs, '/', rhs),
codegenImpl: (ctx, [lhs, rhs]) => ctx.gen.emitBinaryOp(lhs, '/', rhs),
ignoreImplicitCastWarning: true,
sideEffects: false,

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.

3 participants