New version DRDOS 7.01.7 & 7.01.8 (Announce)
> > I first thought that the xor cx,cx can be eliminated too, by clearing
> the
> > result after the xor dx,dx. But the xor cx,cx leaves the flags in a
> defined
> > state, which the div does not. So I think it is safer to leave this xor
> > cx,cx in.
>
> It probably IS save. Because everytime div32 is used in the source, an
> addition follows that sets the flags anyway. So I will try to further
> optimize this and incorporate your suggestion regarding the two divisions
> on 16-bit divisor.
You can convert the code below for Int64 to Int32 and replace the 32-bit registers with 16-bit registers to skip the 32-time loop.
function ModU(const A,B:Int64):Int64;
assembler;{&FRAME-}{&USES EBX,ESI,EDI}
var
I:Int64;
J:Int64;
asm
MOV EBX,A
MOV EAX,[EBX+0]
MOV EDX,[EBX+4]
MOV DWORD [I+0],EAX
MOV DWORD [I+4],EDX
MOV EBX,B
MOV ECX,[EBX+4]
MOV EBX,[EBX+0]
MOV DWORD [J+0],EBX
MOV DWORD [J+4],ECX
MOV EAX,EBX
OR EAX,ECX
JZ DivisionByZero
MOV EAX,DWORD [I+0]
TEST ECX,ECX
JNZ @@BigDivisor
CMP EDX,EBX
JAE @@TwoDivs
DIV EBX
MOV EAX,EDX
MOV EDX,ECX
JMP @@Done
@@TwoDivs:
MOV ECX,EAX
MOV EAX,EDX
XOR EDX,EDX
DIV EBX
MOV EAX,ECX
DIV EBX
MOV EAX,EDX
XOR EDX,EDX
JMP @@Done
@@BigDivisor:
MOV EDI,ECX
SHR EDX,1
RCR EAX,1
ROR EDI,1
RCR EBX,1
BSR ECX,ECX
SHRD EBX,EDI,CL
SHRD EAX,EDX,CL
SHR EDX,CL
ROL EDI,1
DIV EBX
MOV EBX,DWORD [I+4]
MOV ECX,EAX
IMUL EDI,EAX
MUL DWORD [J+0]
ADD EDX,EDI
SUB EBX,EAX
MOV ECX,DWORD [I+4]
MOV EAX,DWORD [J+0]
SBB ECX,EDX
SBB EDX,EDX
AND EAX,EDX
AND EDX,DWORD [J+4]
ADD EAX,EBX
ADC EDX,ECX
@@Done: MOV ECX,@Result
MOV [ECX+0],EAX
MOV [ECX+4],EDX
end;
function DivU(const A,B:Int64):Int64;
assembler;{&FRAME-}{&USES EBX,ESI,EDI}
var
I:Int64;
J:Int64;
asm
MOV EBX,A
MOV EAX,[EBX+0]
MOV EDX,[EBX+4]
MOV DWORD [I+0],EAX
MOV DWORD [I+4],EDX
MOV EBX,B
MOV ECX,[EBX+4]
MOV EBX,[EBX+0]
MOV DWORD [J+0],EBX
MOV DWORD [J+4],ECX
MOV EAX,EBX
OR EAX,ECX
JZ DivisionByZero
MOV EAX,DWORD [I+0]
TEST ECX,ECX
JNZ @@BigDivisor
CMP EDX,EBX
JAE @@TwoDivs
DIV EBX
MOV EDX,ECX
JMP @@Done
@@TwoDivs:
MOV ECX,EAX
MOV EAX,EDX
XOR EDX,EDX
DIV EBX
XCHG EAX,ECX
DIV EBX
MOV EDX,ECX
JMP @@Done
@@BigDivisor:
MOV EDI,ECX
SHR EDX,1
RCR EAX,1
ROR EDI,1
RCR EBX,1
BSR ECX,ECX
SHRD EBX,EDI,CL
SHRD EAX,EDX,CL
SHR EDX,CL
ROL EDI,1
DIV EBX
MOV EBX,DWORD [I+0]
MOV ECX,EAX
IMUL EDI,EAX
MUL DWORD [J+0]
ADD EDX,EDI
SUB EBX,EAX
MOV EAX,ECX
MOV ECX,DWORD [I+4]
SBB ECX,EDX
SBB EAX,0
XOR EDX,EDX
@@Done: MOV ECX,@Result
MOV [ECX+0],EAX
MOV [ECX+4],EDX
end;
Complete thread:
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 21.07.2023, 15:40 (Announce)
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 21.07.2023, 20:13
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 21.07.2023, 20:27
- New version DRDOS 7.01.7 & 7.01.8 - fritz.mueller, 21.07.2023, 20:29
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 21.07.2023, 20:34
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 21.07.2023, 22:18
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 21.07.2023, 22:45
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 22.07.2023, 09:40
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 22.07.2023, 23:06
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 22.07.2023, 09:40
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 21.07.2023, 22:45
- New version DRDOS 7.01.7 & 7.01.8 - fritz.mueller, 21.07.2023, 20:29
- New version DRDOS 7.01.7 & 7.01.8 - Guti, 24.07.2023, 11:08
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 25.07.2023, 15:04
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 26.07.2023, 15:19
- New version DRDOS 7.01.7 & 7.01.8 - Guti, 30.07.2023, 11:12
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 26.07.2023, 15:19
- New version DRDOS 7.01.7 & 7.01.8 - DieTotenByte, 30.07.2023, 01:09
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 30.07.2023, 10:55
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 03.08.2023, 21:46
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 10.08.2023, 11:09
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 10.08.2023, 15:52
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 10.08.2023, 19:21
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 11.08.2023, 10:47
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 12.08.2023, 21:13
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 11:16
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 13:59
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 14:39
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 19:23
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 21:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 22:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 23:18
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 23:51
- EDR-DOS development - ecm, 14.08.2023, 07:18
- EDR-DOS development - CandyMan, 14.08.2023, 09:43
- EDR-DOS development - ecm, 15.08.2023, 20:49
- EDR-DOS development - ecm, 15.08.2023, 20:51
- EDR-DOS development - ecm, 19.08.2023, 19:56
- EDR-DOS development - ecm, 15.08.2023, 20:49
- EDR-DOS development - CandyMan, 14.08.2023, 14:35
- EDR-DOS development - bretjohn, 14.08.2023, 21:12
- EDR-DOS development - CandyMan, 15.08.2023, 11:49
- EDR-DOS development - bretjohn, 14.08.2023, 21:12
- EDR-DOS development - CandyMan, 14.08.2023, 09:43
- EDR-DOS development - ecm, 15.08.2023, 20:46
- EDR-DOS development - CandyMan, 15.08.2023, 22:29
- EDR-DOS development - ecm, 16.08.2023, 10:06
- EDR-DOS development - CandyMan, 16.08.2023, 12:54
- EDR-DOS development - ecm, 16.08.2023, 18:19
- EDR-DOS development - CandyMan, 16.08.2023, 18:55
- EDR-DOS development - ecm, 16.08.2023, 18:19
- EDR-DOS development - CandyMan, 16.08.2023, 12:54
- EDR-DOS development - ecm, 16.08.2023, 10:06
- EDR-DOS development - CandyMan, 15.08.2023, 22:29
- EDR-DOS development - ecm, 20.08.2023, 01:35
- EDR-DOS development - CandyMan, 21.08.2023, 00:27
- EDR-DOS development - ecm, 21.08.2023, 22:54
- EDR-DOS development - ecm, 29.08.2023, 17:49
- EDR-DOS development - ecm, 29.08.2023, 18:26
- EDR-DOS development - ecm, 29.08.2023, 18:32
- EDR-DOS development - ecm, 29.08.2023, 18:49
- EDR-DOS development - ecm, 29.08.2023, 18:32
- EDR-DOS development - Rugxulo, 29.08.2023, 23:28
- EDR-DOS development - ecm, 30.08.2023, 09:47
- EDR-DOS development - ecm, 29.08.2023, 18:26
- EDR-DOS development - roytam, 29.12.2023, 15:33
- EDR-DOS development - CandyMan, 21.08.2023, 00:27
- EDR-DOS development - ecm, 14.08.2023, 07:18
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 23:51
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 23:18
- EDR-DOS repository - Ro2003, 10.10.2023, 16:24
- EDR-DOS repository - ecm, 12.10.2023, 19:04
- EDR-DOS repository - Ro2003, 13.10.2023, 08:23
- EDR-DOS repository - nico7550, 13.10.2023, 15:53
- EDR-DOS repository - Single-file kernel load - ecm, 13.10.2023, 18:16
- EDR-DOS repository - Single-file kernel load - ecm, 13.10.2023, 18:23
- EDR-DOS repository - Ro2003, 13.10.2023, 08:23
- EDR-DOS repository - ecm, 12.10.2023, 19:04
- EDR-DOS version number - Ro2003, 10.10.2023, 16:32
- EDR-DOS version number - ecm, 12.10.2023, 19:08
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 22:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 21:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 13:59
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 11:16
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 12.08.2023, 21:13
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 10.08.2023, 15:52
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 13.08.2023, 22:19
- What ever happened to Udo ? - glennmcc, 29.08.2023, 23:04
- New version DRDOS 7.01.7 & 7.01.8 - Ro2003, 10.10.2023, 16:10
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 10.10.2023, 21:35
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 17:04
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 12.12.2023, 18:47
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:15
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:27
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 13.12.2023, 16:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 14.12.2023, 18:00
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 14.12.2023, 20:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 16.12.2023, 21:52
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 30.12.2023, 14:27
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 01.01.2024, 13:57
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 30.12.2023, 14:27
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 16.12.2023, 21:52
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 14.12.2023, 20:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 14.12.2023, 18:00
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 13.12.2023, 16:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:27
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:15
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 12.12.2023, 18:47