Rev 2215 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2210 | art_zh | 1 | ;======================================================================== |
2 | ;= = |
||
3 | ;= Fast Hartley Transform demo for KolibriOS = |
||
4 | ;= = |
||
5 | ;= Copyright (C) 2010, Artem Jerdev |
||
6 | ;= = |
||
7 | ;= refer to wiki.kolibtios.org for all details = |
||
8 | ;= = |
||
9 | ;======================================================================== |
||
10 | |||
11 | |||
12 | |||
13 | |||
14 | use32 |
||
15 | |||
16 | org 0x0 |
||
17 | |||
18 | db 'MENUET01' ; 8 byte id |
||
19 | dd 0x01 ; header version |
||
20 | dd START ; start of code |
||
21 | dd I_END ; size of image |
||
22 | dd 0x100000 ; memory for app |
||
23 | dd 0xbfffc ; esp |
||
24 | dd 0x0 , 0x0 ; I_Param , I_Icon |
||
25 | |||
26 | include '../../macros.inc' |
||
3013 | dunkaist | 27 | include '../../debug.inc' |
2215 | art_zh | 28 | include 'fht4code.asm' |
2210 | art_zh | 29 | |
30 | |||
31 | START: ; start of execution |
||
32 | |||
33 | call main |
||
34 | |||
35 | |||
36 | mov eax,-1 ; close this program |
||
37 | int 0x40 |
||
38 | |||
39 | |||
40 | ;============================================================= |
||
41 | ;Func: calculates a simple function |
||
42 | ; ff = (512*2^(-t) * cos (2.5*t)) |
||
43 | ; uses: eax, ebx |
||
44 | ;------------ |
||
45 | Func: |
||
46 | |||
47 | ; 9 : { |
||
48 | |||
49 | ; 10 : double x,t; |
||
50 | ; 11 : int f; |
||
51 | ; 12 : |
||
52 | ; 13 : x = (i < N2) ? i : i - NUM_POINTS; |
||
53 | mov eax, [ii] |
||
54 | cmp eax, 512 |
||
55 | jge .index_negative |
||
56 | jmp .index_correct |
||
57 | .index_negative: |
||
58 | sub eax, 1024 |
||
59 | .index_correct: |
||
60 | mov [temp], eax |
||
61 | ; fild [temp] |
||
62 | |||
63 | ; 14 : t = x / 16.0; |
||
64 | ; f2xm1 argument (abs) must be less than 1, so |
||
65 | mov [t_mod], eax |
||
66 | and [t_mod], 0x0F ; x % 16 |
||
67 | shr eax, 4 ; x / 16 |
||
68 | mov [t_div], eax |
||
69 | fild [temp] |
||
70 | |||
71 | ; 15 : if (t<0) t = -t; |
||
72 | fabs |
||
73 | exp_ok: |
||
74 | ; 16 : f = (512*2^(-t) * cos (2.5*t)); |
||
75 | fchs |
||
76 | f2xm1 |
||
77 | fmul [f500] |
||
78 | fstp [tv93] |
||
79 | fld [f2_5] |
||
80 | fmul [tt] |
||
81 | fcos |
||
82 | fmul [tv93] |
||
83 | fstp [tt] |
||
84 | mov bx, word[tt+6] |
||
85 | shr bx,4 |
||
86 | and bx,0x07FF |
||
87 | add ax,bx |
||
88 | shl ax,4 |
||
89 | and word[tt+6], 0x800F |
||
90 | or word[tt+6], ax |
||
91 | fld [tt] |
||
92 | fstp [ff] |
||
93 | |||
94 | ; 17 : return f; |
||
95 | ; 18 : } |
||
96 | ret |
||
97 | ;--------------------------------------------------------- |
||
98 | ; test data filler |
||
99 | ; |
||
100 | ; uses eax, ebx, ecx |
||
101 | FillData: |
||
102 | ; 29 : for (i=0; i |
||
103 | ; here : ecx = i |
||
104 | xor ecx, ecx |
||
105 | .funcloop: |
||
106 | ; 30 : { |
||
107 | ; 31 : ia[i] = Func(i); |
||
108 | mov [ii], ecx |
||
109 | call Func |
||
110 | fld [ff] |
||
111 | fstp qword [edx+ecx*8] |
||
112 | ; 32 : } |
||
113 | inc ecx |
||
114 | cmp ecx, [_in] ; ecx == N ? |
||
115 | jne .funcloop |
||
116 | ret |
||
117 | |||
118 | ;==================================================================== |
||
119 | ; main |
||
120 | ;==================================================================== |
||
121 | |||
122 | _ia dd 0 |
||
123 | _ii dd 0 |
||
124 | _ip dd 0 |
||
125 | _in dd 0 |
||
126 | _it dd 0 |
||
127 | ;----------------- |
||
128 | |||
129 | main: |
||
130 | mov eax, 68 |
||
131 | mov ebx, 11 |
||
132 | int 0x40 |
||
133 | fninit |
||
134 | mov cl, 2 ; power of 4 |
||
135 | mov byte[_ip], cl |
||
136 | mov eax, 1 |
||
137 | shl eax, cl |
||
138 | shl eax, cl |
||
139 | mov [_in], eax |
||
140 | mov dl, cl |
||
141 | call CreateSinCosTable |
||
142 | mov [_it], edx |
||
143 | mov ecx, [_in] |
||
144 | shl ecx, 3 |
||
145 | mov ebx, 12 |
||
146 | mov eax, 68 |
||
147 | int 0x40 |
||
148 | mov [_ia], eax |
||
149 | mov edx, eax |
||
150 | |||
151 | call FillData |
||
152 | |||
153 | cpuid |
||
154 | rdtsc |
||
155 | mov [t_0], eax |
||
156 | |||
157 | push [_it] |
||
158 | push [_ia] |
||
159 | push [_ip] |
||
160 | push [_in] |
||
161 | call FHT_4 |
||
162 | add esp, 16 |
||
163 | cpuid |
||
164 | rdtsc |
||
165 | mov [t_1], eax |
||
166 | |||
167 | sub eax, [t_0] |
||
168 | debug_print_hex eax |
||
169 | print '<- fht time' |
||
170 | |||
171 | mov edx, [_it] |
||
172 | call DestroySinCosTable |
||
173 | mov ecx, [_ia] |
||
174 | mov ebx, 13 |
||
175 | mov eax, 68 |
||
176 | int 0x40 |
||
177 | ret |
||
178 | |||
179 | |||
180 | ; ======================================================== |
||
181 | ; static data |
||
182 | ;---------------- |
||
183 | |||
184 | align 8 |
||
185 | |||
186 | ;f18 dq 0x4032000000000000 |
||
187 | f256 dq 256.01f |
||
188 | f14_2 dq 14.2f |
||
189 | f500 dq 0x407f400000000000 |
||
190 | f2_5 dq 0x4004000000000000 |
||
191 | tt dq ? |
||
192 | tv93 dq ? |
||
193 | t_div dd ? |
||
194 | t_mod dd ? |
||
195 | temp dd ? |
||
196 | ff dq ? ; return value (int) |
||
197 | ii dd ? ; argument (int) = array index |
||
198 | t_1 dd ? |
||
199 | t_0 dd ? |
||
200 | fcontrol dw 0x0037f |
||
201 | title db ' Fast Hartley Transform Test - A.Jerdev 2010' |
||
202 | |||
203 | I_END:->0)>> |