Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split _chk and _unchecked at compile-time #48

Open
rurban opened this issue Feb 17, 2018 · 0 comments
Open

split _chk and _unchecked at compile-time #48

rurban opened this issue Feb 17, 2018 · 0 comments
Assignees

Comments

@rurban
Copy link
Owner

rurban commented Feb 17, 2018

with all or most arguments already checked at compile-time, we can split up the function into a fast unchecked worker (evtl. even using the unsafe variant without _s), and the slow _chk function, which does the preliminary arg checks of those args which are not known at compile-time. currently for clang-5+ only.
memcpy_s is 10% faster if all 4 args are known, and the _chk function can be bypassed.

evtl. using static_assert for gcc, which does not have diagnose_if.
we need both, diagnose_if from #40 to be able to test it, by changing error to warning via -DTEST_BOS and the tests-bos target.
we cannot test the static assertions via gcc.

gcc has several limitations over clang:

  • there's no constexpr, only const statements checks. so we cannot check the args, we can only check inside the _s function, which needs to be inlined then. or roll our own static_assert expr, usable for comma expressions, returning the checked value.
  • the object_size size is NOT known for choose_expr, the compile-time check if we can use the fast or slow function.
  • const or literal integer values are not checkable via constant_p, they throw errors.
@rurban rurban self-assigned this Feb 17, 2018
@rurban rurban added this to the 3.3 milestone Feb 17, 2018
@rurban rurban changed the title Add static_assert split _chk and _unchecked at compile-time Feb 27, 2018
rurban added a commit that referenced this issue Feb 27, 2018
Probe for static_assert in CXX11 or C11

If args are compile-time constants and satisfy a constant expr,
call the func, otherwise produce a compile-time error.
But static_assert cannot be used inside args, only as statement.

See #48
rurban added a commit that referenced this issue Feb 27, 2018
skip run-time checks when already checked at compile-time.
split functions into two: unchecked and checked, depending
on the already done compile-time check.

currently only useful for clang-5+
gcc cannot not handle BOS as compile-time constant, how lame.

shaves off 10% p_memcpy_s, when all 4 args are of known size + constant len.
See #48
rurban added a commit that referenced this issue Feb 27, 2018
no _real, static inline _unchecked worker, and
2 exported funcs: _s (already checked) and _s_chk (some unchecked,
deferred to run-time checks)

See #48
rurban added a commit that referenced this issue Feb 27, 2018
Probe for static_assert in CXX11 or C11

If args are compile-time constants and satisfy a constant expr,
call the func, otherwise produce a compile-time error.
But static_assert cannot be used inside args, only as statement.

See #48
rurban added a commit that referenced this issue Feb 27, 2018
skip run-time checks when already checked at compile-time.
split functions into two: unchecked and checked, depending
on the already done compile-time check.

currently only useful for clang-5+
gcc cannot not handle BOS as compile-time constant, how lame.

shaves off 10% p_memcpy_s, when all 4 args are of known size + constant len.
See #48
rurban added a commit that referenced this issue Feb 27, 2018
no _real, static inline _unchecked worker, and
2 exported funcs: _s (already checked) and _s_chk (some unchecked,
deferred to run-time checks)

See #48
rurban added a commit that referenced this issue Feb 28, 2018
Probe for static_assert in CXX11 or C11

If args are compile-time constants and satisfy a constant expr,
call the func, otherwise produce a compile-time error.
But static_assert cannot be used inside args, only as statement.

See #48
rurban added a commit that referenced this issue Feb 28, 2018
skip run-time checks when already checked at compile-time.
split functions into two: unchecked and checked, depending
on the already done compile-time check.

currently only useful for clang-5+
gcc cannot not handle BOS as compile-time constant, how lame.

shaves off 10% p_memcpy_s, when all 4 args are of known size + constant len.
See #48
rurban added a commit that referenced this issue Feb 28, 2018
no _real, static inline _unchecked worker, and
2 exported funcs: _s (already checked) and _s_chk (some unchecked,
deferred to run-time checks)

See #48
@rurban rurban removed this from the 3.3 milestone Feb 28, 2018
rurban added a commit that referenced this issue Mar 8, 2024
Probe for static_assert in CXX11 or C11

If args are compile-time constants and satisfy a constant expr,
call the func, otherwise produce a compile-time error.
But static_assert cannot be used inside args, only as statement.

See #48
rurban added a commit that referenced this issue Mar 8, 2024
skip run-time checks when already checked at compile-time.
split functions into two: unchecked and checked, depending
on the already done compile-time check.

currently only useful for clang-5+
gcc cannot not handle BOS as compile-time constant, how lame.

shaves off 10% p_memcpy_s, when all 4 args are of known size + constant len.
See #48
rurban added a commit that referenced this issue Mar 8, 2024
no _real, static inline _unchecked worker, and
2 exported funcs: _s (already checked) and _s_chk (some unchecked,
deferred to run-time checks)

See #48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant