〔リスト1〕-fsignaling-nansオプションを使う例(test233.c)
|
//-fsignaling-nansオプションを使う例
#define _GNU_SOURCE
#include <stdio.h>
#include <math.h>
const float f1 = 3.1212312312312312f;
const float f2 = 6.5432165432165432f;
float x;
float y;
float func(float a)
{
x = 10;
x = NAN * x;
y = x * f1;
return a * f1 / f2;
}
|
|
〔リスト2〕-fsignaling-nansオプションを付けて生成されたアセンブラ・ソース(test233a.s)
|
.file "test233.c"
.globl f1
.section .rodata
.align 4
.type f1, @object
.size f1, 4
f1:
.long 1078444609
.globl f2
.align 4
.type f2, @object
.size f2, 4
f2:
.long 1087463944
.section .rodata.cst4,"aM",@progbits,4
.align 4
.LC11:
.long 1078444609
.align 4
.LC12:
.long 1087463944
.text
.p2align 2,,3
.globl func
.type func, @function
func:
flds 4(%esp)
fmuls .LC11
movl $0x7fc00000, %edx
fdivs .LC12
movl %edx, x
movl %edx, y
ret
.size func, .-func
.comm x,4,4
.comm y,4,4
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト3〕-fsignaling-nansオプションを否定して生成されたアセンブラ・ソース(test233.s)
|
.file "test233.c"
.globl f1
.section .rodata
.align 4
.type f1, @object
.size f1, 4
f1:
.long 1078444609
.globl f2
.align 4
.type f2, @object
.size f2, 4
f2:
.long 1087463944
.section .rodata.cst4,"aM",@progbits,4
.align 4
.LC99:
.long 1056193456
.text
.p2align 2,,3
.globl func
.type func, @function
func:
flds 4(%esp)
movl $0x7fc00000, %edx
fmuls .LC99
movl %edx, x
movl %edx, y
ret
.size func, .-func
.comm x,4,4
.comm y,4,4
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト4〕-fsingle-precision-constantオプションを使う例(test234.c)
|
//浮動小数の定数を単精度として扱う例
#include <stdio.h>
#include <math.h>
const double f1 = 1.79769e308;
const double f2 = 6.5432165432165432f;
main()
{
double f3 = f1 / 1.79769e300;
printf("%E\n",f1);
printf("%E\n",f2);
printf("%E\n",f3);
}
|
|
〔リスト5〕-fsingle-precision-constantオプションを付けて生成されたアセンブラ・ソース(test234a.s)
|
.file "test234.c"
.globl f1
.section .rodata
.align 8
.type f1, @object
.size f1, 8
f1:
.long 0
.long 2146435072
.globl f2
.align 8
.type f2, @object
.size f2, 8
f2:
.long 0
.long 1075457089
.LC1:
.string "%E\n"
.align 8
.LC0:
.long 0
.long 2146435072
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
fldl f1
fldl .LC0
fdivrp %st, %st(1)
fstpl -8(%ebp)
subl $4, %esp
pushl f1+4
pushl f1
pushl $.LC1
call printf
addl $16, %esp
subl $4, %esp
pushl f2+4
pushl f2
pushl $.LC1
call printf
addl $16, %esp
subl $4, %esp
pushl -4(%ebp)
pushl -8(%ebp)
pushl $.LC1
call printf
addl $16, %esp
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト6〕-fsingle-precision-constantオプションなしで生成されたアセンブラ・ソース(test234.s)
|
.file "test234.c"
.globl f1
.section .rodata
.align 8
.type f1, @object
.size f1, 8
f1:
.long 1472889518
.long 2146435068
.globl f2
.align 8
.type f2, @object
.size f2, 8
f2:
.long 0
.long 1075457089
.LC1:
.string "%E\n"
.align 8
.LC0:
.long 1843991411
.long 2118482316
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
fldl f1
fldl .LC0
fdivrp %st, %st(1)
fstpl -8(%ebp)
subl $4, %esp
pushl f1+4
pushl f1
pushl $.LC1
call printf
addl $16, %esp
subl $4, %esp
pushl f2+4
pushl f2
pushl $.LC1
call printf
addl $16, %esp
subl $4, %esp
pushl -4(%ebp)
pushl -8(%ebp)
pushl $.LC1
call printf
addl $16, %esp
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト7〕-fstrict-aliasingオプションを使う例(test234.c)
|
//-fstrict-aliasingの例
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
double pi;
unsigned int *ipt;
pi=3.1415926535897;
printf("%e\n",pi);
ipt=(unsigned int *)π
ipt++ ;
*ipt |= 0x80000000;
printf("%e\n",pi);
}
|
|
〔リスト8〕-fstrict-aliasingオプションを付けて生成されたアセンブラ・ソース(test235a.s)
|
.file "test235.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC1:
.string "%e\n"
.text
.p2align 2,,3
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $1074340347, %edx
pushl %ecx
pushl %edx
movl $1413753926, %eax
pushl %eax
pushl $.LC1
movl %edx, -4(%ebp)
movl %eax, -8(%ebp)
call printf
addl $12, %esp
pushl -4(%ebp)
pushl -8(%ebp)
pushl $.LC1
orl $-2147483648, -4(%ebp)
call printf
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト9〕-fno-strict-aliasingオプションを付けて生成されたアセンブラ・ソース(test235.s)
|
.file "test235.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC1:
.string "%e\n"
.text
.p2align 2,,3
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $1074340347, %edx
pushl %ecx
pushl %edx
movl $1413753926, %eax
pushl %eax
pushl $.LC1
movl %edx, -4(%ebp)
movl %eax, -8(%ebp)
call printf
addl $12, %esp
orl $-2147483648, -4(%ebp)
pushl -4(%ebp)
pushl -8(%ebp)
pushl $.LC1
call printf
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
 記事内インデックス 連載インデックスはこちら Interfaceのトップ |
|
|
Copyright 2004 岸 哲夫
Copyright 1997-2004 CQ Publishing Co.,Ltd.
|