/usr/include/allegro/platform/al386gcc.h is in liballegro4-dev 2:4.4.2-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | /* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* Inline functions (gcc style 386 asm).
*
* By Shawn Hargreaves.
*
* See readme.txt for copyright information.
*/
#if (!defined ALLEGRO_GCC) || (!defined ALLEGRO_I386)
#error bad include
#endif
#ifdef ALLEGRO_IMPORT_GFX_ASM
/* _default_ds:
* Return a copy of the current %ds selector.
*/
AL_INLINE(int, _default_ds, (void),
{
short result;
__asm__ (
" movw %%ds, %0 "
: "=r" (result)
);
return result;
})
/* bmp_write_line:
* Bank switch function.
*/
AL_INLINE(uintptr_t, bmp_write_line, (BITMAP *bmp, int lyne),
{
uintptr_t result;
__asm__ volatile (
" call *%3 "
: "=a" (result) /* result in eax */
: "d" (bmp), /* bitmap in edx */
"0" (lyne), /* line number in eax */
"r" (bmp->write_bank) /* the bank switch routine */
);
return result;
})
/* bmp_read_line:
* Bank switch function.
*/
AL_INLINE(uintptr_t, bmp_read_line, (BITMAP *bmp, int lyne),
{
uintptr_t result;
__asm__ volatile (
" call *%3 "
: "=a" (result) /* result in eax */
: "d" (bmp), /* bitmap in edx */
"0" (lyne), /* line number in eax */
"r" (bmp->read_bank) /* the bank switch routine */
);
return result;
})
/* bmp_unwrite_line:
* Terminate bank switch function.
*/
AL_INLINE(void, bmp_unwrite_line, (BITMAP *bmp),
{
__asm__ volatile (
" call *%1 "
:
: "d" (bmp), /* bitmap in edx */
"r" (bmp->vtable->unwrite_bank) /* the bank switch routine */
);
})
#endif /* ALLEGRO_IMPORT_GFX_ASM */
#ifdef ALLEGRO_IMPORT_MATH_ASM
/* Helper macro that makes the compiler reduce fixadd(), fixsub(), fixmul() and
fixdiv() calls to a single constant if both operands are constant. Since
this doesn't work unless we compile with optimization, it's better to skip
the test then. */
#if (defined __OPTIMIZE__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)))
#define __PRECALCULATE_CONSTANTS(calc) \
if(__builtin_constant_p(x) && __builtin_constant_p(y)) { \
if((calc) > (double)0x7FFFFFFF) { \
*allegro_errno = ERANGE; \
return 0x7FFFFFFF; \
} \
else if(-(calc) > (double)0x7FFFFFFF) { \
*allegro_errno = ERANGE; \
return -0x7FFFFFFF; \
} \
else \
return (fixed)(calc); \
} \
else
#else
#define __PRECALCULATE_CONSTANTS(calc)
#endif
/* fixadd:
* Fixed point (16.16) addition.
*/
AL_INLINE(fixed, fixadd, (fixed x, fixed y),
{
fixed result;
__PRECALCULATE_CONSTANTS(x + (double)y)
{
__asm__ (
" addl %2, %0 ; " /* do the addition */
" jno 0f ; " /* check for overflow */
" movl %4, %0 ; " /* on overflow, set errno */
" movl %3, (%0) ; "
" movl $0x7FFFFFFF, %0 ; " /* and return MAXINT */
" cmpl $0, %2 ; "
" jg 0f ; "
" negl %0 ; "
" 0: " /* finished */
: "=r" (result) /* result in a register */
: "0" (x), /* x in the output register */
"rm" (y), /* y can go in register or memory */
"i" (ERANGE),
"m" (allegro_errno)
: "%cc", "memory" /* clobbers flags and errno */
);
return result;
}
})
/* fixsub:
* Fixed point (16.16) subtraction.
*/
AL_INLINE(fixed, fixsub, (fixed x, fixed y),
{
fixed result;
__PRECALCULATE_CONSTANTS(x - (double)y)
{
__asm__ (
" subl %2, %0 ; " /* do the subtraction */
" jno 0f ; " /* check for overflow */
" movl %4, %0 ; " /* on overflow, set errno */
" movl %3, (%0) ; "
" movl $0x7FFFFFFF, %0 ; " /* and return MAXINT */
" cmpl $0, %2 ; "
" jl 0f ; "
" negl %0 ; "
" 0: " /* finished */
: "=r" (result) /* result in a register */
: "0" (x), /* x in the output register */
"rm" (y), /* y can go in register or memory */
"i" (ERANGE),
"m" (allegro_errno)
: "%cc", "memory" /* clobbers flags and errno */
);
return result;
}
})
/* fixmul:
* Fixed point (16.16) multiplication.
*/
AL_INLINE(fixed, fixmul, (fixed x, fixed y),
{
fixed edx __attribute__ ((__unused__));
fixed result;
__PRECALCULATE_CONSTANTS(x / 65536.0 * y)
{
__asm__ (
" movl %2, %%eax ; "
" imull %3 ; " /* do the multiply */
" shrdl $16, %%edx, %%eax ; "
" sarl $15, %%edx ; " /* check for overflow */
" jz 0f ; "
" cmpl $-1, %%edx ; "
" je 0f ; "
" movl %5, %%eax ; " /* on overflow, set errno */
" movl %4, (%%eax) ; "
" movl $0x7FFFFFFF, %%eax ; " /* and return MAXINT */
" cmpl $0, %2 ; "
" jge 1f ; "
" negl %%eax ; "
" 1: "
" cmpl $0, %3 ; "
" jge 0f ; "
" negl %%eax ; "
" .balign 4, 0x90 ; "
" 0: " /* finished */
: "=&a" (result), /* the result has to go in eax */
"=&d" (edx) /* reliably reserve edx */
: "mr" (x), /* x and y can be regs or mem */
"mr" (y),
"i" (ERANGE),
"m" (allegro_errno)
: "%cc", "memory" /* clobbers flags and errno */
);
return result;
}
})
/* fixdiv:
* Fixed point (16.16) division.
*/
AL_INLINE(fixed, fixdiv, (fixed x, fixed y),
{
fixed edx __attribute__ ((__unused__));
fixed reg __attribute__ ((__unused__));
fixed result;
__PRECALCULATE_CONSTANTS(x * 65536.0 / y)
{
__asm__ (
" testl %%eax, %%eax ; " /* test sign of x */
" js 3f ; "
" testl %2, %2 ; " /* test sign of y */
" jns 4f ; "
" negl %2 ; "
" 0: " /* result will be negative */
" movl %%eax, %%edx ; " /* check the range is ok */
" shrl $16, %%edx ; "
" shll $16, %%eax ; "
" cmpl %2, %%edx ; "
" jae 1f ; "
" divl %2 ; " /* do the divide */
" testl %%eax, %%eax ; "
" jns 2f ; "
" 1: "
" movl %6, %%eax ; " /* on overflow, set errno */
" movl %5, (%%eax) ; "
" movl $0x7FFFFFFF, %%eax ; " /* and return MAXINT */
" 2: "
" negl %%eax ; " /* fix up the sign of the result */
" jmp 6f ; "
" .balign 4, 0x90 ; "
" 3: " /* x is negative */
" negl %%eax ; "
" testl %2, %2 ; " /* test sign of y */
" jns 0b ; "
" negl %2 ; "
" 4: " /* result will be positive */
" movl %%eax, %%edx ; " /* check the range is ok */
" shrl $16, %%edx ; "
" shll $16, %%eax ; "
" cmpl %2, %%edx ; "
" jae 5f ; "
" divl %2 ; " /* do the divide */
" testl %%eax, %%eax ; "
" jns 6f ; "
" 5: "
" movl %6, %%eax ; " /* on overflow, set errno */
" movl %5, (%%eax) ; "
" movl $0x7FFFFFFF, %%eax ; " /* and return MAXINT */
" 6: " /* finished */
: "=a" (result), /* the result has to go in eax */
"=&d" (edx), /* reliably reserve edx */
"=r" (reg) /* input operand will be clobbered */
: "0" (x), /* x in eax */
"2" (y), /* y in register */
"i" (ERANGE),
"m" (allegro_errno)
: "%cc", "memory" /* clobbers flags and memory */
);
return result;
}
})
/* fixfloor:
* Fixed point version of floor().
* Note that it returns an integer result (not a fixed one)
*/
AL_INLINE(int, fixfloor, (fixed x),
{
int result;
__asm__ (
" sarl $16, %0 " /* convert to int */
: "=r" (result) /* result in a register */
: "0" (x) /* x in the output register */
);
return result;
})
/* fixceil:
* Fixed point version of ceil().
* Note that it returns an integer result (not a fixed one)
*/
AL_INLINE(int, fixceil, (fixed x),
{
int result;
__asm__ (
" addl $0xFFFF, %0 ;" /* ceil () */
" jns 0f ;"
" jo 1f ;"
"0:"
" sarl $16, %0 ;" /* convert to int */
" jmp 2f ;"
"1:"
" movl %3, %0 ;" /* on overflow, set errno */
" movl %2, (%0) ;"
" movl $0x7FFF, %0 ;" /* and return large int */
"2:"
: "=r" (result) /* result in a register */
: "0" (x), /* x in the output register */
"i" (ERANGE),
"m" (allegro_errno)
: "%cc", "memory" /* clobbers flags and errno */
);
return result;
})
#undef __PRECALCULATE_CONSTANTS
#endif /* ALLEGRO_IMPORT_MATH_ASM */
|