digitalmars.D.ldc - core.checkedint?
- bearophile (5/5) Oct 31 2014 Do you want to make LDC2 recognize core.checkedint functions and
- David Nadlinger via digitalmars-d-ldc (5/8) Oct 31 2014 Sure, it maps very directly to the corresponding LLVM intrinsics
- Kai Nacke (5/14) Nov 01 2014 See https://github.com/ldc-developers/ldc/pull/772
- safety0ff (23/23) Nov 01 2014 I'm not terribly interested in preparing a PR for this, but I
- bearophile (5/9) Nov 01 2014 Good.
- safety0ff (3/12) Nov 01 2014 They're intrinsics:
- bearophile (4/6) Nov 01 2014 Sorry, I meant the functions like mulu, etc.
Do you want to make LDC2 recognize core.checkedint functions and implement them efficiently reading the overflow/carry flags of the CPU? Bye, bearophile
Oct 31 2014
On 1 Nov 2014, at 1:58, bearophile via digitalmars-d-ldc wrote:Do you want to make LDC2 recognize core.checkedint functions and implement them efficiently reading the overflow/carry flags of the CPU?Sure, it maps very directly to the corresponding LLVM intrinsics (conditionally setting the by-ref parameter has to be done in a small wrapper, though). Pull request are very welcome. ;) David
Oct 31 2014
On Saturday, 1 November 2014 at 04:04:48 UTC, David Nadlinger via digitalmars-d-ldc wrote:On 1 Nov 2014, at 1:58, bearophile via digitalmars-d-ldc wrote:See https://github.com/ldc-developers/ldc/pull/772 Regards, KaiDo you want to make LDC2 recognize core.checkedint functions and implement them efficiently reading the overflow/carry flags of the CPU?Sure, it maps very directly to the corresponding LLVM intrinsics (conditionally setting the by-ref parameter has to be done in a small wrapper, though). Pull request are very welcome. ;) David
Nov 01 2014
I'm not terribly interested in preparing a PR for this, but I
believe the code should be something like this (untested):
ldc/src/core/checkedint.d:
uint mulu(uint x, uint y, ref bool overflow)
{
+ version (LDC)
+ {
+ auto res = llvm_umul_with_overflow(x, y);
+ overflow |= res.overflow;
+ return res.result;
+ }
+ else
+ {
ulong r = ulong(x) * ulong(y);
if (r > uint.max)
overflow = true;
return cast(uint)r;
+ }
}
Rinse and repeat with:
llvm_uadd_with_overflow, llvm_sadd_with_overflow,
llvm_usub_with_overflow, llvm_ssub_with_overflow,
llvm_smul_with_overflow.
Nov 01 2014
safety0ff:Rinse and repeat with: llvm_uadd_with_overflow, llvm_sadd_with_overflow, llvm_usub_with_overflow, llvm_ssub_with_overflow, llvm_smul_with_overflow.Good. Is it 100% guaranteed ldc2 will inline this function? Bye, bearophile
Nov 01 2014
On Saturday, 1 November 2014 at 18:06:41 UTC, bearophile wrote:safety0ff:They're intrinsics: https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/intrinsics.di#L462Rinse and repeat with: llvm_uadd_with_overflow, llvm_sadd_with_overflow, llvm_usub_with_overflow, llvm_ssub_with_overflow, llvm_smul_with_overflow.Good. Is it 100% guaranteed ldc2 will inline this function? Bye, bearophile
Nov 01 2014
safety0ff:They're intrinsics: https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/intrinsics.di#L462Sorry, I meant the functions like mulu, etc. Bye, bearophile
Nov 01 2014









"Kai Nacke" <kai redstar.de> 