Subversion Repositories Kolibri OS

Rev

Rev 2215 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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