Skip to content

Commit 52561ff

Browse files
committed
Push the floating-point test into a separate file.
Hopefully, that will make sure we don't optimize away anything that will, for example, cause us not to do things differently on 32-bit x86 using the x87 instructions.
1 parent aa2650e commit 52561ff

File tree

5 files changed

+89
-10
lines changed

5 files changed

+89
-10
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
11101110
set_target_properties(netdissect PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
11111111
endif()
11121112

1113-
set(TCPDUMP_SOURCE_LIST_C tcpdump.c)
1113+
set(TCPDUMP_SOURCE_LIST_C fptype.c tcpdump.c)
11141114

11151115
if(NOT HAVE_BPF_DUMP)
11161116
set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
7070
@rm -f $@
7171
$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
7272

73-
CSRC = tcpdump.c
73+
CSRC = fptype.c tcpdump.c
7474

7575
LIBNETDISSECT_SRC=\
7676
addrtoname.c \

fptype.c

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 1982, 1986, 1993
3+
* The Regents of the University of California. All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. All advertising materials mentioning features or use of this software
14+
* must display the following acknowledgement:
15+
* This product includes software developed by the University of
16+
* California, Berkeley and its contributors.
17+
* 4. Neither the name of the University nor the names of its contributors
18+
* may be used to endorse or promote products derived from this software
19+
* without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31+
* SUCH DAMAGE.
32+
*/
33+
34+
#include <stdio.h>
35+
36+
#include "netdissect-stdinc.h"
37+
38+
#include "fptype.h"
39+
40+
void
41+
float_type_check(uint32_t in)
42+
{
43+
union { /* int to float conversion buffer */
44+
float f;
45+
uint32_t i;
46+
} f;
47+
48+
f.i = in;
49+
printf("%.3f\n", f.f*8/1000000);
50+
}

fptype.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 1982, 1986, 1993
3+
* The Regents of the University of California. All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. All advertising materials mentioning features or use of this software
14+
* must display the following acknowledgement:
15+
* This product includes software developed by the University of
16+
* California, Berkeley and its contributors.
17+
* 4. Neither the name of the University nor the names of its contributors
18+
* may be used to endorse or promote products derived from this software
19+
* without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31+
* SUCH DAMAGE.
32+
*/
33+
34+
extern void float_type_check(uint32_t);

tcpdump.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ The Regents of the University of California. All rights reserved.\n";
150150

151151
#include "print.h"
152152

153+
#include "fptype.h"
154+
153155
#ifndef PATH_MAX
154156
#define PATH_MAX 1024
155157
#endif
@@ -1901,14 +1903,7 @@ main(int argc, char **argv)
19011903
* may differ (e.g., it might be 32-bit, 64-bit,
19021904
* or 80-bit).
19031905
*/
1904-
{
1905-
union { /* int to float conversion buffer */
1906-
float f;
1907-
uint32_t i;
1908-
} f;
1909-
f.i = 0x4e93312d;
1910-
printf("%.3f\n", f.f*8/1000000);
1911-
}
1906+
float_type_check(0x4e93312d);
19121907
return 0;
19131908

19141909
default:

0 commit comments

Comments
 (0)