File: ofi_osd.h

package info (click to toggle)
mpich 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 251,828 kB
  • sloc: ansic: 1,323,147; cpp: 82,869; f90: 72,420; javascript: 40,763; perl: 28,296; sh: 19,399; python: 16,191; xml: 14,418; makefile: 9,468; fortran: 8,046; java: 4,635; pascal: 352; asm: 324; ruby: 176; awk: 27; lisp: 19; php: 8; sed: 4
file content (126 lines) | stat: -rw-r--r-- 3,623 bytes parent folder | download | duplicates (6)
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
/*
 * Copyright (c) 2013-2014 Intel Corporation. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef _OFI_OSD_H_
#define _OFI_OSD_H_

#include <stdint.h>

/* We use macros to create atomic and complex function definitions,
 * and we can't have spaces in function names */
typedef long double long_double;


/* Complex data type support:
 *
 * Complex data types are operating system.  For portability, each osd.h file
 * must define the following datatypes and operations:
 *
 * Datatype:
 * ofi_complex_XXX
 *
 * Operations:
 * ofi_complex_eq_XXX, ofi_complex_sum_XXX, ofi_complex_prod_XXX,
 * ofi_complex_land_XXX, ofi_complex_lor_XXX, ofi_complex_lxor_XXX
 *
 * Where XXX = float, double, or long_double
 */


#ifdef __APPLE__
#include <osx/osd.h>
#include <unix/osd.h>
#elif defined __FreeBSD__
#include <freebsd/osd.h>
#include <unix/osd.h>
#elif defined _WIN32
#include <windows/osd.h>
#else
#include <linux/osd.h>
#include <unix/osd.h>
#endif

#ifdef __GNUC__
#define OFI_LIKELY(x)	__builtin_expect((x), 1)
#define OFI_UNLIKELY(x)	__builtin_expect((x), 0)
#else
#define OFI_LIKELY(x)	(x)
#define OFI_UNLIKELY(x)	(x)
#endif

enum {
	OFI_ENDIAN_UNKNOWN,
	OFI_ENDIAN_BIG,
	OFI_ENDIAN_LITTLE,
	OFI_ENDIAN_BIG_WORD,	/* Middle-endian, Honeywell 316 style */
	OFI_ENDIAN_LITTLE_WORD,	/* Middle-endian, PDP-11 style */
};

static inline uint8_t ofi_detect_endianness(void)
{
	union {
		uint8_t data[sizeof(uint32_t)];
		uint32_t value;
	} checker = {
		.data = { 0x00, 0x01, 0x02, 0x03 },
	};
	switch (checker.value) {
	case 0x00010203UL:
		return OFI_ENDIAN_BIG;
	case 0x03020100UL:
		return OFI_ENDIAN_LITTLE;
	case 0x02030001UL:
		return OFI_ENDIAN_BIG_WORD;
	case 0x01000302UL:
		return OFI_ENDIAN_LITTLE_WORD;
	default:
		return OFI_ENDIAN_UNKNOWN;
	}
}

#define OFI_MAGIC_64 (0x0F1C0DE0F1C0DE64)
#define OFI_MAGIC_PTR ((void *) (uintptr_t) OFI_MAGIC_64)
#define OFI_MAGIC_SIZE_T ((size_t) OFI_MAGIC_64)

#ifndef NDEBUG
#define OFI_DBG_VAR(type, name) type name;
#define OFI_DBG_SET(name, val) name = val
#define OFI_DBG_ADD(name, val) name += val
#define OFI_DBG_CALL(func) func
#else
#define OFI_DBG_VAR(type, name)
#define OFI_DBG_SET(name, val) do {} while (0)
#define OFI_DBG_ADD(name, val) do {} while (0)
#define OFI_DBG_CALL(func) do {} while (0)
#endif

#endif /* _OFI_OSD_H_ */