summaryrefslogtreecommitdiff
path: root/packages/libogcfpc/src/ogc/cast.inc
blob: 3fa5df538e412d99480ffd8988d8023f02218927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
{$IFDEF OGC_INTERFACE}

const
//  GQR2 = 914;
//  GQR3 = 915;
//  GQR4 = 916;
//  GQR5 = 917;
//  GQR6 = 918;
//  GQR7 = 919;
  GQR_TYPE_F32 = 0;
  GQR_TYPE_U8 = 4;
  GQR_TYPE_U16 = 5;
  GQR_TYPE_S8 = 6;
  GQR_TYPE_S16 = 7;
  GQR_CAST_U8 = 2;
  GQR_CAST_U16 = 3;
  GQR_CAST_S8 = 4;
  GQR_CAST_S16 = 5;



{$ifdef GEKKO}

procedure __set_gqr(_reg,_val: cint); inline;
procedure CAST_Init(); inline;
procedure CAST_SetGQR2(_type, scale: cuint32); inline;
procedure CAST_SetGQR3(_type, scale: cuint32); inline;
procedure CAST_SetGQR4(_type, scale: cuint32); inline;
procedure CAST_SetGQR5(_type, scale: cuint32); inline;
procedure CAST_SetGQR6(_type, scale: cuint32); inline;
procedure CAST_SetGQR7(_type, scale: cuint32); inline;
function __castu8f32(_in: pcuint8): f32; inline;
function __castu16f32(_in: pcuint16): f32; inline;
function __casts8f32(_in: pcint8): f32; inline
function __casts16f32(register s16 *in): f32; inline;
procedure castu8f32(_in: pcuint8; out _out: pf32); inline;
procedure castu16f32(_in: pcuint16; out _out: pf32); inline;
procedure casts8f32(_in: pcint8; out _out: pf32); inline;
procedure casts16f32(_in: pcint16; out _out: pf32); inline;
function __castf32u8(_in: f32): cuint8; inline;
function __castf32u16(_in: f32): cuint16; inline;
function __castf32s8(_in: f32): cint8; inline;
function __castf32s16(_in: f32): cint16; inline;
procedure castf32u8(_in: pf32; out _out: pcuint8); inline;
procedure castf32u16(_in: pf32; out _out: pcuint16); inline;
procedure castf32s8(_in: pf32; out _out: pcint8); inline;
procedure castf32s16(_in: pf32; out _out: pcint16); inline;

{$endif GEKKO}



{$ENDIF OGC_INTERFACE}

{$IFDEF OGC_IMPLEMENTATION}
{$ifdef GEKKO}

procedure __set_gqr(_reg,_val: cint); inline;
begin
  asm 
    mtspr r3,r4
  end;
end;

// does a default init
procedure CAST_Init(); inline;
begin
  asm
    li		3,0x0004
    oris	3,3,0x0004
    mtspr	914,3
    li		3,0x0005
    oris	3,3,0x0005
    mtspr	915,3
    li		3,0x0006
    oris	3,3,0x0006
    mtspr	916,3
    li		3,0x0007
    oris	3,3,0x0007
    mtspr	917,3
  end;
end;

procedure CAST_SetGQR2(_type, scale: cuint32); inline;
var
  val: cuint32;
begin
  val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type)));
	__set_gqr(GQR2,val);
end;

procedure CAST_SetGQR3(_type, scale: cuint32); inline;
var
  val: cuint32;
begin
	val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type)));
	__set_gqr(GQR3,val);
end;

procedure CAST_SetGQR4(_type, scale: cuint32); inline;
var
  val: cuint32;
begin
	val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type)));
	__set_gqr(GQR4,val);
end;

procedure CAST_SetGQR5(_type, scale: cuint32); inline;
var
  val: cuint32;
begin
	val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type)));
	__set_gqr(GQR5,val);
end;

procedure CAST_SetGQR6(_type, scale: cuint32); inline;
var
  val: cuint32;
begin
	val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type)));
	__set_gqr(GQR6,val);
end;

procedure CAST_SetGQR7(_type, scale: cuint32); inline;
var
  val: cuint32;
begin
	val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type)));
	__set_gqr(GQR7,val);
end;



function __castu8f32(_in: pcuint8): f32; inline;
var
  rval: f32;
begin
  asm
    psq_l	%[rval],0(%[_in]),1,2
  end;
  result := rval;
end;

function __castu16f32(_in: pcuint16): f32; inline;
var
	rval: f32;
begin
  asm
    psq_l	%[rval],0(%[in]),1,3
  end;
	result := rval;
end;

function __casts8f32(_in: pcint8): f32; inline
var
  rval: f32;
begin
  asm
    psq_l	%[rval],0(%[in]),1,4
  end;
	result := rval;
end;

function __casts16f32(register s16 *in): f32; inline;
var
  rval: f32;
begin
  asm
		psq_l	%[rval],0(%[in]),1,5
	end;
	result := rval;
end;

procedure castu8f32(_in: pcuint8; out _out: pf32); inline;
begin
	_out^ := __castu8f32(_in);
end;

procedure castu16f32(_in: pcuint16; out _out: pf32); inline;
begin
	_out^ := __castu16f32(_in);
end;

procedure casts8f32(_in: pcint8; out _out: pf32); inline;
begin
	_out^ := __casts8f32(_in);
end;

procedure casts16f32(_in: pcint16; out _out: pf32); inline;
begin
	_out^ := __casts16f32(_in);
end;

function __castf32u8(_in: f32): cuint8; inline;
var
	a: f32;
	rval: cuint8;
	ptr: pf32;
begin
	ptr := @a;
	asm
    psq_st	%[in],0(%[ptr]),1,2
    lbz	%[out],0(%[ptr])
  end;
	result := rval;
end;

function __castf32u16(_in: f32): cuint16; inline;
var
	a: f32;
	rval: cuint16;
	ptr: pf32;
begin
	ptr := @a;

	asm
    psq_st	%[in],0(%[ptr]),1,3
    lhz	%[out],0(%[ptr])
  end;
	result := rval;
end;

function __castf32s8(_in: f32): cint8; inline;
var
	a: f32;
	rval: cint8;
	ptr: pf32;
begin
	ptr := @a;
  asm
		psq_st	%[in],0(%[ptr]),1,4
		lbz	%[out],0(%[ptr])
  end;
	result := rval;
end;

function __castf32s16(_in: f32): cint16; inline;
var
	a: f32;
	rval: cint16;
	ptr: pf32;
begin
	ptr := @a;

	asm
    psq_st	%[in],0(%[ptr]),1,5
		lha	%[out],0(%[ptr])
  end;
	result := rval;
end;

procedure castf32u8(_in: pf32; out _out: pcuint8); inline;
begin
	_out^ := __castf32u8(_in^);
end;

procedure castf32u16(_in: pf32; out _out: pcuint16); inline;
begin
	_out^ := __castf32u16(_in^);
end;

procedure castf32s8(_in: pf32; out _out: pcint8); inline;
begin
	_out^ := __castf32s8(_in^);
end;

procedure castf32s16(_in: pf32; out _out: pcint16); inline;
begin
	_out^ := __castf32s16(_in^);
end;

{$endif GEKKO}

{$endif OGC_IMPLEMENTATION}