|
Listing 1: GCC double to signed integer support function
/* fixdfsi.s: Copyright (c) 1990 William Jolitz. All rights reserved.
* Written by William Jolitz 1/90
* Redistribution and use in source and binary forms are freely permitted
* provided that the above copyright notice and attribution and date of work
* and this paragraph are duplicated in all such forms.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* GCC compiler support function, truncates a double float into a signed long.
*/
.globl ___fixdfsi
___fixdfsi:
pushl $0xe7f /* truncate, long real, mask all */
fnstcw 2(%esp) /* save my old control word */
fldcw (%esp) /* load truncating one */
fldl 8(%esp) /* load double */
fistpl 8(%esp) /* store back as an integer */
fldcw 2(%esp) /* load prior control word */
popl %eax
movl 4(%esp),%eax
ret
Listing 2: GCC double to unsigned support function
/* fixunsdfsi.s: Copyright (c) 1990 William Jolitz. All rights reserved.
* Written by William Jolitz 4/90
* Redistribution and use in source and binary forms are freely permitted
* provided that the above copyright notice and attribution and date of work
* and this paragraph are duplicated in all such forms.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* GCC compiler support function, truncates a double float into unsigned long.
*/
.globl ___fixunsdfsi
___fixunsdfsi:
pushl $0xe7f /* truncate, long real, mask all */
fnstcw 2(%esp) /* save my old control word */
fldcw (%esp) /* load truncating one */
fldl 8(%esp) /* argument double to accum stack */
frndint /* create integer */
fcoml fbiggestsigned /* bigger than biggest signed? */
fstsw %ax
sahf
jnb 1f
fistpl 8(%esp)
fldcw 2(%esp) /* load prior control word */
popl %eax
movl 4(%esp),%eax
ret
1: fsubl fbiggestsigned /* reduce for proper conversion */
fistpl 8(%esp) /* convert */
fldcw 2(%esp) /* load prior control word */
popl %eax
movl 4(%esp),%eax
addl $2147483648,%eax /* restore bias of 2^31 */
ret
fbiggestsigned: .double 0r2147483648.0 /* 2^31 */
|