View Issue Details

IDProjectCategoryView StatusLast Update
0028985FPCRTLpublic2020-04-13 22:19
ReporterRadek Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionno change required 
Product Version2.6.4 
Summary0028985: New version of multiply procedures wiht overflow checks
Description{$ASMMODE INTEL}
{$DEFINE FPC_SYSTEM_HAS_MUL_QWORD}
// multiplies two qwords
// the longbool for checkoverflow avoids a misaligned stack
function fpc_mul_qword(F1,F2:QWord; CheckOverflow:LongBool):QWord;[public,alias:'FPC_MUL_QWORD']; compilerproc;
assembler;asm
        CMP CheckOverflow,0
        JZ @@NoOvr
        CMP DWORD [F1+4],0
        JZ @@MulNumbers
        CMP DWORD [F2+4],0
        JZ @@MulNumbers
        JNZ @@MulOverflow
@@MulNumbers:
        MOV EAX,DWORD [F1+4]
        MUL DWORD [F2+0]
        OR EDX,EDX
        JNZ @@MulOverflow
        MOV ECX,EAX
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+4]
        OR EDX,EDX
        JNZ @@MulOverflow
        ADD ECX,EAX
        JC @@MulOverflow
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+0]
        ADD EDX,ECX
        JC @@MulOverflow
        JMP @@Exit
@@MulOverflow:
        MOV EDX,EBP
        MOV EAX,215
        CALL HandleErrorFrame
@@NoOvr://
        MOV EAX,DWORD [F1+4]
        MUL DWORD [F2+0]
        MOV ECX,EAX
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+4]
        ADD ECX,EAX
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+0]
        ADD EDX,ECX
@@Exit:://
end;

{$DEFINE FPC_SYSTEM_HAS_MUL_INT64}
function fpc_mul_int64(F1,F2:Int64; CheckOverflow:LongBool):Int64;[public,alias:'FPC_MUL_INT64']; compilerproc;
assembler;asm
        PUSH EBX
        CMP CheckOverflow,0
        JZ @@NoOvr
        //
        XOR BL,BL
        BT DWORD [F1+4],31
        JNC @@1
        XOR BL,-1
        MOV EAX,DWORD [F1+0]
        MOV EDX,DWORD [F1+4]
        NOT EAX
        NOT EDX
        ADD EAX,1
        ADC EDX,0
        MOV DWORD [F1+0],EAX
        MOV DWORD [F1+4],EDX
@@1: //
        BT DWORD [F2+4],31
        JNC @@2
        XOR BL,-1
        MOV EAX,DWORD [F2+0]
        MOV EDX,DWORD [F2+4]
        NOT EAX
        NOT EDX
        ADD EAX,1
        ADC EDX,0
        MOV DWORD [F2+0],EAX
        MOV DWORD [F2+4],EDX
@@2: //
        CMP DWORD [F1+4],0
        JZ @@MulNumbers
        CMP DWORD [F2+4],0
        JZ @@MulNumbers
        JNZ @@MulOverflow
@@MulNumbers:
        MOV EAX,DWORD [F1+4]
        MUL DWORD [F2+0]
        OR EDX,EDX
        JNZ @@MulOverflow
        MOV ECX,EAX
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+4]
        OR EDX,EDX
        JNZ @@MulOverflow
        ADD ECX,EAX
        JC @@MulOverflow
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+0]
        ADD EDX,ECX
        JC @@MulOverflow
        OR BL,BL
        JZ @@MulOK
        NOT EAX
        NOT EDX
        ADD EAX,1
        ADC EDX,0
@@MulOK:JMP @@Exit
@@MulOverflow:
        MOV EDX,EBP
        MOV EAX,215
        CALL HandleErrorFrame
@@NoOvr://
        MOV EAX,DWORD [F1+4]
        MUL DWORD [F2+0]
        MOV ECX,EAX
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+4]
        ADD ECX,EAX
        MOV EAX,DWORD [F1+0]
        MUL DWORD [F2+0]
        ADD EDX,ECX
@@Exit: POP EBX
end;

{$ASMMODE ATT}

TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Marco van de Voort

2017-05-25 19:16

manager   ~0100677

I miss a bit context here, but it seems that 3.1.1 already has qword*qword (and an overflow) variant.

Your routines seem to check for overflow runtime, while in practice the compiler calls an overflow version or not depending on the flags state at the exact line being compiled.

Please test if 3.1.1. achieves what you want, and if not, what you exactly want to improve.

Bart Broersma

2019-02-12 23:33

reporter   ~0114061

No feedback in > 1.5 year.
Resolve as no change required?

J. Gareth Moreton

2019-02-16 03:01

developer   ~0114165

Presumably this is for i386, since for x64, all you have to do is use MUL and then test to see if RDX is zero or not.

If, as Marco states, an overflow version is already called, then the proposed function above seems unnecessary unless we're missing something. (Speed?)

Bart Broersma

2020-04-13 13:24

reporter   ~0122116

Again: no feedback in > 1 year since last request by J. Gareth Moreton.
Resolve as no change required?

Florian

2020-04-13 13:35

administrator   ~0122120

Resolved as proposed by Bart.

Issue History

Date Modified Username Field Change
2015-11-09 14:40 Radek New Issue
2017-05-25 19:16 Marco van de Voort Note Added: 0100677
2017-05-25 19:16 Marco van de Voort Status new => feedback
2019-02-12 23:33 Bart Broersma Note Added: 0114061
2019-02-16 03:01 J. Gareth Moreton Note Added: 0114165
2020-04-13 13:24 Bart Broersma Note Added: 0122116
2020-04-13 13:35 Florian Assigned To => Florian
2020-04-13 13:35 Florian Status feedback => resolved
2020-04-13 13:35 Florian Resolution open => no change required
2020-04-13 13:35 Florian FPCTarget => -
2020-04-13 13:35 Florian Note Added: 0122120