microsoft / microsoft/STL

`<ranges>`: `_(Add|Mul)_overflow` could be much faster

Open
#3,618 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

New functions (added by #3561) _Add_overflow<Int> and _Multiply_overflow<Int> could be much faster when Int is:

  1. Standard integer type. MSVC should consider implementing Clang's checked arithmetic builtins (__builtin_add_overflow and __builtin_mul_overflow). This would vastly improve performance and codegen.

    Also tracked by DevCom-10326281.

  2. Integer-class type. I believe that it is possible to implement those checked operations directly in _Signed128 and _Unsigned128, for example by modifying already existing functions (overflow could be detected during addition/multiplication?).

    This requires further investigation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing _Add_overflow<Int> and _Multiply_overflow<Int> for standard integer types, then inspect the existing implementations of _Signed128 and _Unsigned128. Compare the generated code and performance of the current paths with checked arithmetic builtins where applicable; done means faster overflow operations with behavior preserved for both integer categories.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.