feat: std.intdiv - #2849
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 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 ( |
| std_length.ts | 69.67 kB ( |
| std_distance.ts | 69.67 kB ( |
| std_dot4U8Packed.ts | 69.67 kB ( |
| std_fract.ts | 69.67 kB ( |
| std_frexp.ts | 69.67 kB ( |
| std_mix.ts | 69.67 kB ( |
| std_modf.ts | 69.67 kB ( |
| std_abs.ts | 69.68 kB ( |
| std_acos.ts | 69.68 kB ( |
| std_acosh.ts | 69.68 kB ( |
| std_asin.ts | 69.68 kB ( |
| std_asinh.ts | 69.68 kB ( |
| std_atan.ts | 69.68 kB ( |
| std_atan2.ts | 69.68 kB ( |
| std_atanh.ts | 69.68 kB ( |
| std_ceil.ts | 69.68 kB ( |
| std_clamp.ts | 69.68 kB ( |
| std_cos.ts | 69.68 kB ( |
| std_cosh.ts | 69.68 kB ( |
| std_countLeadingZeros.ts | 69.68 kB ( |
| std_countOneBits.ts | 69.68 kB ( |
| std_countTrailingZeros.ts | 69.68 kB ( |
| std_cross.ts | 69.68 kB ( |
| std_degrees.ts | 69.68 kB ( |
| std_determinant.ts | 69.68 kB ( |
| std_dot4I8Packed.ts | 69.68 kB ( |
| std_exp.ts | 69.68 kB ( |
| std_exp2.ts | 69.68 kB ( |
| std_extractBits.ts | 69.68 kB ( |
| std_faceForward.ts | 69.68 kB ( |
| std_firstLeadingBit.ts | 69.68 kB ( |
| std_firstTrailingBit.ts | 69.68 kB ( |
| std_floor.ts | 69.68 kB ( |
| std_fma.ts | 69.68 kB ( |
| std_insertBits.ts | 69.68 kB ( |
| std_inverseSqrt.ts | 69.68 kB ( |
| std_ldexp.ts | 69.68 kB ( |
| std_log.ts | 69.68 kB ( |
| std_log2.ts | 69.68 kB ( |
| std_max.ts | 69.68 kB ( |
| std_min.ts | 69.68 kB ( |
| std_normalize.ts | 69.68 kB ( |
| std_pow.ts | 69.68 kB ( |
| std_quantizeToF16.ts | 69.68 kB ( |
| std_radians.ts | 69.68 kB ( |
| std_reflect.ts | 69.68 kB ( |
| std_refract.ts | 69.68 kB ( |
| std_reverseBits.ts | 69.68 kB ( |
| std_round.ts | 69.68 kB ( |
| std_saturate.ts | 69.68 kB ( |
| std_sign.ts | 69.68 kB ( |
| std_sin.ts | 69.68 kB ( |
| std_sinh.ts | 69.68 kB ( |
| std_smoothstep.ts | 69.68 kB ( |
| std_sqrt.ts | 69.68 kB ( |
| std_step.ts | 69.68 kB ( |
| std_tan.ts | 69.68 kB ( |
| std_tanh.ts | 69.68 kB ( |
| std_transpose.ts | 69.68 kB ( |
| std_trunc.ts | 69.68 kB ( |
| 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 ( |
| tgpu_initFromDevice.ts | 274.34 kB ( |
| tgpu_resolve.ts | 175.17 kB ( |
| tgpu_resolveWithContext.ts | 175.11 kB ( |
| tgpu_bindGroupLayout.ts | 74.49 kB ( |
| tgpu_mutableAccessor.ts | 69.21 kB ( |
| tgpu_accessor.ts | 69.21 kB ( |
| tgpu_privateVar.ts | 67.90 kB ( |
| tgpu_workgroupVar.ts | 67.90 kB ( |
| tgpu_const.ts | 67.32 kB ( |
| tgpu_lazy.ts | 67.12 kB ( |
| tgpu_fragmentFn.ts | 39.65 kB ( |
| tgpu_fn.ts | 39.60 kB ( |
| tgpu_vertexFn.ts | 39.47 kB ( |
| tgpu_computeFn.ts | 39.17 kB ( |
| tgpu_vertexLayout.ts | 28.30 kB ( |
| tgpu_comptime.ts | 15.91 kB ( |
| tgpu_unroll.ts | 1.75 kB ( |
| tgpu_slot.ts | 1.70 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
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]
---
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]
---
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]
|
There was a problem hiding this comment.
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.intdivas adualImplinpackages/typegpu/src/std/numeric.ts. - Re-exports
intdivfrompackages/typegpu/src/std/index.tsfor public consumption. - Adds
packages/typegpu/tests/std/numeric/intdiv.test.tsto 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 tofn:intdivto 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.
There was a problem hiding this comment.
ℹ️ 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— addscpuIntdivand theintdivdualImpl(signatureunifyto[u32, i32],codegenImplemitting/,ignoreImplicitCastWarning,sideEffects: false).packages/typegpu/src/std/index.ts— exportsintdivfrom thestdbarrel.packages/typegpu/tests/std/numeric/intdiv.test.ts— 5 tests coveringi32,u32, mixedu32/i32, float coercion, and vector rejection via inline snapshots.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
9baee40 to
0d4c02d
Compare
0d4c02d to
f012224
Compare
There was a problem hiding this comment.
✅ 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:
cpuIntdivreusesdivInteger— the CPU path now delegates to the shareddivIntegerhelper indata/numberOps.ts, inheriting itsrhs === 0 → lhsguard 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 forintdivnow report asfn:intdivinstead of colliding withstd.div. Test snapshots updated accordingly.data/numberOps.ts—divIntegerconverted 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ 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: truefrom theintdivdualImplinpackages/typegpu/src/std/numeric.ts:1325— mixedu32/i32and 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| 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), |
There was a problem hiding this comment.
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).
| 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, |

No description provided.