source: xtideuniversalbios/trunk/Assembly_Library/Inc/Math.inc@ 578

Last change on this file since 578 was 445, checked in by krille_n_@…, 12 years ago

Changes:

  • A speed optimization to the eSHL_IM macro for 386 and higher. This change breaks emulation in the sense that the macro will fail when given a memory operand as the first parameter.
  • Memory_SumCXbytesFromESSItoAL now returns with the zero flag set/cleared according to the result.
  • Unrolled all the 8 bit READ transfer loops to do 16 bytes per iteration. Added a new macro (UNROLL_SECTORS_IN_CX_TO_OWORDS) as part of it. Size wise this is expensive but I think it should be worth the ROM space. The WRITE transfer loops were left as is since writes are rare anyway (<10% of all disk I/O IIRC).
  • Minor optimizations and fixes here and there.
File size: 2.3 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Math related macros.
3%ifndef MATH_INC
4%define MATH_INC
5
6FALSE EQU 0
7TRUE EQU 1
8
9
10;--------------------------------------------------------------------
11; MIN_U Unsigned comparison
12; MIN_S Signed comparison
13; Parameters:
14; %1: Operand 1
15; %2: Operand 2
16; Returns:
17; %1: Lesser operand
18; Corrupts registers:
19; Nothing
20;--------------------------------------------------------------------
21%macro MIN_U 2
22 cmp %1, %2 ; Is %1 smaller?
23 jb %%Return ; If so, return
24 mov %1, %2 ; Copy %2 to %1
25ALIGN JUMP_ALIGN
26%%Return:
27%endmacro
28
29%macro MIN_S 2
30 cmp %1, %2 ; Is %1 smaller?
31 jl %%Return ; If so, return
32 mov %1, %2 ; Copy %2 to %1
33ALIGN JUMP_ALIGN
34%%Return:
35%endmacro
36
37
38;--------------------------------------------------------------------
39; MAX_U Unsigned comparison
40; MAX_S Signed comparison
41; Parameters:
42; %1: Operand 1
43; %2: Operand 2
44; Returns:
[181]45; %1: Greater operand
[41]46; Corrupts registers:
47; Nothing
48;--------------------------------------------------------------------
49%macro MAX_U 2
50 cmp %1, %2 ; Is %1 greater?
51 ja %%Return ; If so, return
52 mov %1, %2 ; Copy %2 to %1
53ALIGN JUMP_ALIGN
54%%Return:
55%endmacro
56
57%macro MAX_S 2
58 cmp %1, %2 ; Is %1 greater?
59 jg %%Return ; If so, return
60 mov %1, %2 ; Copy %2 to %1
61ALIGN JUMP_ALIGN
62%%Return:
63%endmacro
64
65
[172]66;--------------------------------------------------------------------
[287]67; SHL_DXAX
68; Parameters:
69; %1: Number of bits to shift
70; Returns:
71; DX:AX Shifted value
72; Corrupts registers:
73; CX
74;--------------------------------------------------------------------
75%macro SHL_DXAX 1
76 %ifnidni %1, cx
77 mov cx, %1
78 %endif
79ALIGN JUMP_ALIGN
80.ShiftNextBit:
[445]81 eSHL_IM ax, 1
[287]82 rcl dx, 1
83 loop .ShiftNextBit
84%endmacro
85
86
87;--------------------------------------------------------------------
[172]88; SHR_DXAX
89; Parameters:
90; %1: Number of bits to shift
91; Returns:
92; DX:AX Shifted value
93; Corrupts registers:
94; CX
95;--------------------------------------------------------------------
96%macro SHR_DXAX 1
97 %ifnidni %1, cx
98 mov cx, %1
99 %endif
100ALIGN JUMP_ALIGN
101.ShiftNextBit:
102 shr dx, 1
103 rcr ax, 1
104 loop .ShiftNextBit
105%endmacro
106
107
[41]108%endif ; MATH_INC
Note: See TracBrowser for help on using the repository browser.