/packages/libogcfpc/src/ogc/cast.inc
Pascal | 275 lines | 219 code | 41 blank | 15 comment | 0 complexity | 848de6935529807be91af39685f15f25 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
1{$IFDEF OGC_INTERFACE} 2 3const 4// GQR2 = 914; 5// GQR3 = 915; 6// GQR4 = 916; 7// GQR5 = 917; 8// GQR6 = 918; 9// GQR7 = 919; 10 GQR_TYPE_F32 = 0; 11 GQR_TYPE_U8 = 4; 12 GQR_TYPE_U16 = 5; 13 GQR_TYPE_S8 = 6; 14 GQR_TYPE_S16 = 7; 15 GQR_CAST_U8 = 2; 16 GQR_CAST_U16 = 3; 17 GQR_CAST_S8 = 4; 18 GQR_CAST_S16 = 5; 19 20 21 22{$ifdef GEKKO} 23 24procedure __set_gqr(_reg,_val: cint); inline; 25procedure CAST_Init(); inline; 26procedure CAST_SetGQR2(_type, scale: cuint32); inline; 27procedure CAST_SetGQR3(_type, scale: cuint32); inline; 28procedure CAST_SetGQR4(_type, scale: cuint32); inline; 29procedure CAST_SetGQR5(_type, scale: cuint32); inline; 30procedure CAST_SetGQR6(_type, scale: cuint32); inline; 31procedure CAST_SetGQR7(_type, scale: cuint32); inline; 32function __castu8f32(_in: pcuint8): f32; inline; 33function __castu16f32(_in: pcuint16): f32; inline; 34function __casts8f32(_in: pcint8): f32; inline 35function __casts16f32(register s16 *in): f32; inline; 36procedure castu8f32(_in: pcuint8; out _out: pf32); inline; 37procedure castu16f32(_in: pcuint16; out _out: pf32); inline; 38procedure casts8f32(_in: pcint8; out _out: pf32); inline; 39procedure casts16f32(_in: pcint16; out _out: pf32); inline; 40function __castf32u8(_in: f32): cuint8; inline; 41function __castf32u16(_in: f32): cuint16; inline; 42function __castf32s8(_in: f32): cint8; inline; 43function __castf32s16(_in: f32): cint16; inline; 44procedure castf32u8(_in: pf32; out _out: pcuint8); inline; 45procedure castf32u16(_in: pf32; out _out: pcuint16); inline; 46procedure castf32s8(_in: pf32; out _out: pcint8); inline; 47procedure castf32s16(_in: pf32; out _out: pcint16); inline; 48 49{$endif GEKKO} 50 51 52 53{$ENDIF OGC_INTERFACE} 54 55{$IFDEF OGC_IMPLEMENTATION} 56{$ifdef GEKKO} 57 58procedure __set_gqr(_reg,_val: cint); inline; 59begin 60 asm 61 mtspr r3,r4 62 end; 63end; 64 65// does a default init 66procedure CAST_Init(); inline; 67begin 68 asm 69 li 3,0x0004 70 oris 3,3,0x0004 71 mtspr 914,3 72 li 3,0x0005 73 oris 3,3,0x0005 74 mtspr 915,3 75 li 3,0x0006 76 oris 3,3,0x0006 77 mtspr 916,3 78 li 3,0x0007 79 oris 3,3,0x0007 80 mtspr 917,3 81 end; 82end; 83 84procedure CAST_SetGQR2(_type, scale: cuint32); inline; 85var 86 val: cuint32; 87begin 88 val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type))); 89 __set_gqr(GQR2,val); 90end; 91 92procedure CAST_SetGQR3(_type, scale: cuint32); inline; 93var 94 val: cuint32; 95begin 96 val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type))); 97 __set_gqr(GQR3,val); 98end; 99 100procedure CAST_SetGQR4(_type, scale: cuint32); inline; 101var 102 val: cuint32; 103begin 104 val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type))); 105 __set_gqr(GQR4,val); 106end; 107 108procedure CAST_SetGQR5(_type, scale: cuint32); inline; 109var 110 val: cuint32; 111begin 112 val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type))); 113 __set_gqr(GQR5,val); 114end; 115 116procedure CAST_SetGQR6(_type, scale: cuint32); inline; 117var 118 val: cuint32; 119begin 120 val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type))); 121 __set_gqr(GQR6,val); 122end; 123 124procedure CAST_SetGQR7(_type, scale: cuint32); inline; 125var 126 val: cuint32; 127begin 128 val := (((((scale) shl 8) or (_type)) shl 16) or (((scale) shl 8) or (_type))); 129 __set_gqr(GQR7,val); 130end; 131 132 133 134function __castu8f32(_in: pcuint8): f32; inline; 135var 136 rval: f32; 137begin 138 asm 139 psq_l %[rval],0(%[_in]),1,2 140 end; 141 result := rval; 142end; 143 144function __castu16f32(_in: pcuint16): f32; inline; 145var 146 rval: f32; 147begin 148 asm 149 psq_l %[rval],0(%[in]),1,3 150 end; 151 result := rval; 152end; 153 154function __casts8f32(_in: pcint8): f32; inline 155var 156 rval: f32; 157begin 158 asm 159 psq_l %[rval],0(%[in]),1,4 160 end; 161 result := rval; 162end; 163 164function __casts16f32(register s16 *in): f32; inline; 165var 166 rval: f32; 167begin 168 asm 169 psq_l %[rval],0(%[in]),1,5 170 end; 171 result := rval; 172end; 173 174procedure castu8f32(_in: pcuint8; out _out: pf32); inline; 175begin 176 _out^ := __castu8f32(_in); 177end; 178 179procedure castu16f32(_in: pcuint16; out _out: pf32); inline; 180begin 181 _out^ := __castu16f32(_in); 182end; 183 184procedure casts8f32(_in: pcint8; out _out: pf32); inline; 185begin 186 _out^ := __casts8f32(_in); 187end; 188 189procedure casts16f32(_in: pcint16; out _out: pf32); inline; 190begin 191 _out^ := __casts16f32(_in); 192end; 193 194function __castf32u8(_in: f32): cuint8; inline; 195var 196 a: f32; 197 rval: cuint8; 198 ptr: pf32; 199begin 200 ptr := @a; 201 asm 202 psq_st %[in],0(%[ptr]),1,2 203 lbz %[out],0(%[ptr]) 204 end; 205 result := rval; 206end; 207 208function __castf32u16(_in: f32): cuint16; inline; 209var 210 a: f32; 211 rval: cuint16; 212 ptr: pf32; 213begin 214 ptr := @a; 215 216 asm 217 psq_st %[in],0(%[ptr]),1,3 218 lhz %[out],0(%[ptr]) 219 end; 220 result := rval; 221end; 222 223function __castf32s8(_in: f32): cint8; inline; 224var 225 a: f32; 226 rval: cint8; 227 ptr: pf32; 228begin 229 ptr := @a; 230 asm 231 psq_st %[in],0(%[ptr]),1,4 232 lbz %[out],0(%[ptr]) 233 end; 234 result := rval; 235end; 236 237function __castf32s16(_in: f32): cint16; inline; 238var 239 a: f32; 240 rval: cint16; 241 ptr: pf32; 242begin 243 ptr := @a; 244 245 asm 246 psq_st %[in],0(%[ptr]),1,5 247 lha %[out],0(%[ptr]) 248 end; 249 result := rval; 250end; 251 252procedure castf32u8(_in: pf32; out _out: pcuint8); inline; 253begin 254 _out^ := __castf32u8(_in^); 255end; 256 257procedure castf32u16(_in: pf32; out _out: pcuint16); inline; 258begin 259 _out^ := __castf32u16(_in^); 260end; 261 262procedure castf32s8(_in: pf32; out _out: pcint8); inline; 263begin 264 _out^ := __castf32s8(_in^); 265end; 266 267procedure castf32s16(_in: pf32; out _out: pcint16); inline; 268begin 269 _out^ := __castf32s16(_in^); 270end; 271 272{$endif GEKKO} 273 274{$endif OGC_IMPLEMENTATION} 275