#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
struct float_as_struct
{
unsigned int fraction:23; /* 小数 */
unsigned int exponent:8; /* 指数 + 0x3FF */
unsigned int sign:1; /* 符号 */
};
float f(float _in)
{
float f = _in;
struct float_as_struct t;
assert(sizeof(struct float_as_struct) == sizeof(float));
memcpy(&t, &f, sizeof(float));
t.sign = 1; /* set negative sign */
t.exponent = t.exponent+2; /* multiply d by 2^n (n here is 2) */
memcpy(&f, &t, sizeof(float));
return f;
}
void main()
{
printf("%f\n", f(1.234));
}
#if 0
/*
* intel
*/
0000000000001169 <f>:
1169: f3 0f 1e fa endbr64 // rsp=0x7fffffffe138 rbp=0x7fffffffe140
116d: 55 push %rbp // rsp=0x7fffffffe130 rbp=0x7fffffffe140
116e: 48 89 e5 mov %rsp,%rbp // rsp=0x7fffffffe130 rbp=0x7fffffffe130
1171: 48 83 ec 20 sub $0x20,%rsp // rsp=0x7fffffffe110 rbp=0x7fffffffe130
1175: f3 0f 11 45 ec movss %xmm0,-0x14(%rbp) // (rbp-0x14)=0x7fffffffe11c:0x3f9df3b6
117a: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax // rax=0xb61168defb9cf400
1181: 00 00
1183: 48 89 45 f8 mov %rax,-0x8(%rbp) // (rbp-0x8)=0x7fffffffe128: 0xb61168defb9cf400
1187: 31 c0 xor %eax,%eax
1189: f3 0f 10 45 ec movss -0x14(%rbp),%xmm0 // xmm0=0x3f9df3b6
118e: f3 0f 11 45 f0 movss %xmm0,-0x10(%rbp) // (rbp-0x10)=0x7fffffffe120: 0x000000003f9df3b6
1193: 8b 45 f0 mov -0x10(%rbp),%eax // eax=0x3f9df3b6
1196: 89 45 f4 mov %eax,-0xc(%rbp) // (rbp-0xc)=0x7fffffffe124: 0xfb9cf4003f9df3b6
1199: 0f b6 45 f7 movzbl -0x9(%rbp),%eax // eax=0x3f rbp-0x9=0x7fffffffe127 x/10b $rbp-0xc 0x7fffffffe124: 0xb6 0xf3 0x9d 0x3f 0x00 0xf4 0x9c 0xfb
119d: 83 c8 80 or $0xffffff80,%eax // eax=0xffffffbf
11a0: 88 45 f7 mov %al,-0x9(%rbp) // (rbp-0x9)=0x7fffffffe127: 0xbf al=0xbf
11a3: 0f b7 45 f6 movzwl -0xa(%rbp),%eax // eax=0xbf9d (rbp-0xa)=0x7fffffffe126: 0x9d
11a7: 66 c1 e8 07 shr $0x7,%ax // ax=0x17f
11ab: 80 e4 ff and $0xff,%ah // ah=0x1
11ae: 83 c0 02 add $0x2,%eax // eax=0x181
11b1: 0f b6 c0 movzbl %al,%eax // eax=0x81 al=0x81
11b4: c1 e0 07 shl $0x7,%eax // eax=0x4080
11b7: 89 c2 mov %eax,%edx // edx=0x4080
11b9: 0f b7 45 f6 movzwl -0xa(%rbp),%eax // eax=0xbf9d
11bd: 66 25 7f 80 and $0x807f,%ax // ax=0x801d
11c1: 09 d0 or %edx,%eax // eax=0xc09d
11c3: 66 89 45 f6 mov %ax,-0xa(%rbp) // (rbp-0xa)=0x7fffffffe126: 0x9d ax=0xc09d
11c7: 8b 45 f4 mov -0xc(%rbp),%eax // eax=0xc09df3b6 $rbp-0xc=0x7fffffffe124: 0xfb9cf400c09df3b6
11ca: 89 45 f0 mov %eax,-0x10(%rbp) // (rbp-0x10)=0x7fffffffe120: 0xc09df3b6c09df3b6 eax=0xc09df3b6
11cd: f3 0f 10 45 f0 movss -0x10(%rbp),%xmm0 // xmm0=0xc09df3b6
11d2: 48 8b 45 f8 mov -0x8(%rbp),%rax // rax=0xb61168defb9cf400 (rbp-0x8)=0x7fffffffe128: 0xb61168defb9cf400
11d6: 64 48 33 04 25 28 00 xor %fs:0x28,%rax
11dd: 00 00
11df: 74 05 je 11e6 <f+0x7d>
11e1: e8 7a fe ff ff callq 1060 <__stack_chk_fail@plt>
11e6: c9 leaveq
11e7: c3 retq
00000000000011e8 <main>:
11e8: f3 0f 1e fa endbr64 // rsp=0x7fffffffe148 rbp=0
11ec: 55 push %rbp // rsp=0x7fffffffe140
11ed: 48 89 e5 mov %rsp,%rbp // rbp=0x7fffffffe140
11f0: f3 0f 10 05 10 0e 00 movss 0xe10(%rip),%xmm0 # 2008 <_IO_stdin_used+0x8> xmm0=0x3f9df3b6=1.2339999675750732
11f7: 00
11f8: e8 6c ff ff ff callq 1169 <f> // rsp=0x7fffffffe138 rbp=0x7fffffffe140
11fd: f3 0f 5a c0 cvtss2sd %xmm0,%xmm0 // xmm0=0xc013be76c0000000
1201: 48 8d 3d fc 0d 00 00 lea 0xdfc(%rip),%rdi # 2004 <_IO_stdin_used+0x4>
1208: b8 01 00 00 00 mov $0x1,%eax
120d: e8 5e fe ff ff callq 1070 <printf@plt> // -4.936000
1212: 90 nop
1213: 5d pop %rbp
1214: c3 retq
1215: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
121c: 00 00 00
121f: 90 nop
/*
* arm
*/
000000000040055c <f>:
40055c: d10083ff sub sp, sp, #0x20
400560: bd000fe0 str s0, [sp, #12]
400564: bd400fe0 ldr s0, [sp, #12]
400568: bd001fe0 str s0, [sp, #28]
40056c: b9401fe0 ldr w0, [sp, #28]
400570: b9001be0 str w0, [sp, #24]
400574: 39406fe0 ldrb w0, [sp, #27]
400578: 32196000 orr w0, w0, #0xffffff80
40057c: 39006fe0 strb w0, [sp, #27]
400580: 794037e0 ldrh w0, [sp, #26]
400584: d3473800 ubfx x0, x0, #7, #8
400588: 12001c00 and w0, w0, #0xff
40058c: 11000800 add w0, w0, #0x2
400590: 12001c01 and w1, w0, #0xff
400594: 794037e0 ldrh w0, [sp, #26]
400598: 33191c20 bfi w0, w1, #7, #8
40059c: 790037e0 strh w0, [sp, #26]
4005a0: b9401be0 ldr w0, [sp, #24]
4005a4: b9001fe0 str w0, [sp, #28]
4005a8: bd401fe0 ldr s0, [sp, #28]
4005ac: 910083ff add sp, sp, #0x20
4005b0: d65f03c0 ret
00000000004005b4 <main>:
4005b4: a9bf7bfd stp x29, x30, [sp, #-16]!
4005b8: 910003fd mov x29, sp
4005bc: 529e76c0 mov w0, #0xf3b6 // #62390
4005c0: 72a7f3a0 movk w0, #0x3f9d, lsl #16
4005c4: 1e270000 fmov s0, w0
4005c8: 97ffffe5 bl 40055c <f>
4005cc: 1e22c000 fcvt d0, s0
4005d0: 90000000 adrp x0, 400000 <_init-0x3e8>
4005d4: 911a6000 add x0, x0, #0x698
4005d8: 97ffff9e bl 400450 <printf@plt>
4005dc: d503201f nop
4005e0: a8c17bfd ldp x29, x30, [sp], #16
4005e4: d65f03c0 ret
#endif