From 33fa211b8497b5f8d3b9511e4c29ef8d888873e5 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 17 Dec 2019 21:54:47 +0000 Subject: [PATCH] + x86-64: assembler implementation for u128_div_u64_to_u64 for SysV ABI * reminder => remainder (thanks to Stefan Kanthak for pointing it out) git-svn-id: trunk@43695 - --- rtl/inc/flt_core.inc | 6 ++++-- rtl/x86_64/x86_64.inc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/rtl/inc/flt_core.inc b/rtl/inc/flt_core.inc index eae3950f96..d1911835bc 100644 --- a/rtl/inc/flt_core.inc +++ b/rtl/inc/flt_core.inc @@ -1276,6 +1276,7 @@ begin end; {$if defined(VALREAL_80) or defined(VALREAL_128)} +{$ifndef FPC_SYSTEM_HAS_U128_DIV_U64_TO_U64} (*------------------------------------------------------- | u128_div_u64_to_u64 [local] | @@ -1286,7 +1287,7 @@ end; | 128-bit integer into two 64-bit ones before converting it to ASCII. | *-------------------------------------------------------*) -function u128_div_u64_to_u64( const xh, xl: qword; const y: qword; out quotient, reminder: qword ): boolean; +function u128_div_u64_to_u64( const xh, xl: qword; const y: qword; out quotient, remainder: qword ): boolean; var b, // Number base v, // Norm. divisor @@ -1342,10 +1343,11 @@ begin break; end; // Result - reminder := ( un21 * b + un0 - q0 * v ) shr s; + remainder := ( un21 * b + un0 - q0 * v ) shr s; quotient := q1 * b + q0; u128_div_u64_to_u64 := true; end; +{$endif FPC_SYSTEM_HAS_U128_DIV_U64_TO_U64} {$endif VALREAL_80 | VALREAL_128} (*------------------------------------------------------- diff --git a/rtl/x86_64/x86_64.inc b/rtl/x86_64/x86_64.inc index c66783f9ba..a8edf06bc3 100644 --- a/rtl/x86_64/x86_64.inc +++ b/rtl/x86_64/x86_64.inc @@ -1073,3 +1073,33 @@ asm {$endif win64} bswap %rax end; + + +{$ifndef win64} +{$define FPC_SYSTEM_HAS_U128_DIV_U64_TO_U64} +function u128_div_u64_to_u64( const xh, xl: qword; const y: qword; out quotient, remainder: qword ): boolean;nostackframe;assembler; +{ + SysV: + xh: RDI + xl: RSI + y: RDX + quotient: RCX + remainder: R8 +} +label + dodiv; +asm + cmpq %rdi,%rdx + ja dodiv + xorl %eax,%eax + ret +dodiv: + movq %rdx,%r9 + movq %rsi,%rax + movq %rdi,%rdx + divq %r9 + movq %rax,(%rcx) + movq %rdx,(%r8) + movl $1,%eax +end; +{$endif win64}