Standard library functions
The runtime service library comes along with a subset of the C standard library, complying with ISO C11 specifications.
The next table summarizes the available functions and definitions:
Header file
Available in the runtime service library
assert.h
assert- Upon assertion failure as described in Exceptions
ctype.hAll the functions defined by the standard
errno.hStandard error constants and functions to report errors
inttypes.hCharacter literals for formal string format
iso646.hAll the macros defined by the standard
limits.hMinimum and maximum for elementary C types
stdalign.hAlign and offset convenience macros
stdarg.hVariadic function arguments support
stdbool.hThe boolean type, as defined by the standard
stddef.hAll the types defined by the standard
stdint.hSigned and unsigned integers on 8,16 and 32 bits
stdlib.hC standard library support
stdnoreturn.hConvenience macro for non-returning functions
string.hAll the functions defined by the standard
stdio.h
printf,puts,putcharfunctions
Other standard definitions are not available, since they do not fit with the context of UPMEM DPU.
The include files are located in $UPMEM_HOME/share/upmem/include/stdlib and contain a brief
explanation of each function. Next is an overview of the include files.
assert.h
Standard assertions are disabled when the source code is compiled with NDEBUG defined.
By default, the assert macro executes a given expression and issues an assertion failure
(see Exceptions) if the expression is not true.
ctype.h
This include contains a collection of utilities to test characters properties:
isdigit: character is a digit, i.e. in the range [‘0’,’9’]
islower: character is a lower-case letter, i.e. in the range [‘a’,’z’]
isupper: character is an upper-case letter, i.e. in the range [‘A’,’Z’]
isalpha: character is a letter, i.e. either a lower or upper-case letter
isalnum: character is alpha-numeric, i.e. either a letter or a digit
iscntrl: character is a control character, i.e. lower than the space character or0x7f
isprint: character is not a control character, implying that it is printable
isgraph: character has a locale representation, i.e. it is printable and is not a space
ispunct: character is a printable, non alpha-numeric character
isspace: character is a space, i.e. one of ‘\t’, ‘\n’, ‘\v’, ‘\f’, ‘\r’ or a space
isxdigit: character is an hexa-decimal digit, i.e. in one of the ranges [‘0’,’9’], [‘a’,’f’] or [‘A’,’F’]
isblank: character is a common space, i.e. either a space or ‘\t’
Also, the following conversion functions are provided:
tolower: if the character is a lower-case letter, converts it to its upper-case value
toupper: if the character is an upper-case letter, converts it to its lower-case value
errno.h
Because of the native multi-threaded nature of DPU programs, this implementation of error numbers
exposes the last error as a thread-local global variable errno
The file also defines the standard C error codes specified by default:
Constant name
Value
E2BIG
1
EACCES
2
EADDRINUSE
3
EADDRNOTAVAIL
4
EAFNOSUPPORT
5
EAGAIN
6
EALREADY
7
EBADF
8
EBADMSG
9
EBUSY
10
ECANCELED
11
ECHILD
12
ECONNABORTED
13
ECONNREFUSED
14
ECONNRESET
15
EDEADLK
16
EDESTADDRREQ
17
EDOM
18
EDQUOT
19
EEXIST
20
EFAULT
21
EFBIG
22
EHOSTUNREACH
23
EIDRM
24
EILSEQ
25
EINPROGRESS
26
EINTR
27
EINVAL
28
EIO
29
EISCONN
30
EISDIR
31
ELOOP
32
EMFILE
33
EMLINK
34
EMSGSIZE
35
EMULTIHOP
36
ENAMETOOLONG
37
ENETDOWN
38
ENETRESET
39
ENETUNREACH
40
ENFILE
41
ENOBUFS
42
ENODATA
43
ENODEV
44
ENOENT
45
ENOEXEC
46
ENOLCK
47
ENOLINK
48
ENOMEM
49
ENOMSG
50
ENOPROTOOPT
51
ENOSPC
52
ENOSR
53
ENOSTR
54
ENOSYS
55
ENOTCONN
56
ENOTDIR
57
ENOTEMPTY
58
ENOTRECOVERABLE
59
ENOTSOCK
60
ENOTSUP
61
ENOTTY
62
ENXIO
63
EOPNOTSUPP
ENOTSUP
EOVERFLOW
65
EOWNERDEAD
66
EPERM
67
EPIPE
68
EPROTO
69
EPROTONOSUPPORT
70
EPROTOTYPE
71
ERANGE
72
EROFS
73
ESPIPE
74
ESRCH
75
ESTALE
76
ETIME
77
ETIMEDOUT
78
ETXTBSY
79
EWOULDBLOCK
ENOTSUP
EXDEV
81
inttypes.h
This extension of stdint.h defines convenience functions imaxabs and imaxdiv and
the normalized string prefixes to represent integers in string formatters.
iso646.h
The C90 standard introduced logical operators represented by bitwise operations:
and: stands for&&
and_eq: stands for&=
bitand: stands for&
bitor: stands for|
compl: stands for~
not: stands for!
not_eq: stands for!=
or: stands for||
or_eq: stands for|=
xor: stands for^
xor_eq: stands for^=
limits.h
Defines the standard limits of elementary types:
SCHAR_MIN
SCHAR_MAX
UCHAR_MAX
SHRT_MIN
SHRT_MAX
USHRT_MAX
INT_MIN
INT_MAX
UINT_MAX
LONG_MIN
LONG_MAX
ULONG_MAX
stdalign.h
Defines the macros:
alignasto specify the alignment of a variable (e.g.struct alignas(8) X {...}, to align on 64-bits)
alignofto fetch the alignment of a given data type
stdarg.h
Defines the standard type va_list and the associated standard macros:
va_start(ap, param)
va_end(ap)
va_arg(ap, type)
va_copy(dest, src)
stdbool.h
This include file defines the normalized type bool and values true and false, equal to 1 and 0, respectively.
stddef.h
Defines standard common types and helpers:
The
NULLpointerThe standard types:
ptrdiff_t
size_t
max_align_t
wchar_t
offsetof, to get the offset of a field within a structure
stdint.h
Defines the integer types implemented by the DPU, in particular:
int8_t,int16_t,int32_tandint64_tfor signed integers of 8, 16, 32 and 64 bits, respectively
uint8_t,uint16_t,uint32_tanduint64_tfor unsigned integers of 8, 16, 32 and 64 bits, respectively
stdlib.h
Defines the following functions of the C standard library:
abort(): sets the DPU into fault, so that the whole processor execution terminates
exit(): aborts the execution of the invoking thread
getenv(): returnsNULL
abs,labsandllabs: the absolute value of integers, longs and long longs
div,ldivandlldiv: return the numerator and denominator of a division
atoiandatol: convert strings to integers and longs
Note: stdlib function strtol is not implemented.
stdnoreturn.h
Defines the noreturn macro, which can be used to specify that a function does not return.
string.h
The common string and buffer operations (only for WRAM pointers if not specified otherwise):
memcmp(area1, area2, size): comparessizebytes of the buffers pointed byarea1andarea2
memset(area, value, size): fills insizebytes of the buffer pointed byareawithvalue(for both WRAM and MRAM pointer)
memchr(area, character, size): returns the first position ofcharacterwithin thesizebytes of the buffer pointed byarea, orNULL
memcpy(destination, source, size): copiessizebytes of the buffer pointed bysourceinto the buffer pointed bydestination(for both WRAM and MRAM pointer)
memmove: a safer (but slower) version ofmemcpy, considering overlapping buffers (for both WRAM and MRAM pointer)
strlen(string): returns the length ofstring
strnlen(string, size): returns the maximum betweensizeand the length ofstring
strcmp(string1, string2): comparesstring1withstring2
strncmp(string1, string2, size): comparessizebytes ofstring1withstring2
strcat(destination, source): appends the stringsourcetodestination
strncat(destination, source, size): appends the firstsizebytes ofsourcetodestination
strchr(string, character): returns the first occurrence ofcharacterwithinstring, orNULL
strrchr(string, character): returns the last occurrence ofcharacterwithinstring, orNULL
strcpy(destination, source): copies the stringsourceinto the buffer pointed bydestination
stpcpy(destination, source): copies the stringsourceinto the buffer pointed bydestination
strncpy(destination, source, size): copies at mostsizebytes ofsourceinto the buffer pointed bydestination
stpncpy(destination, source, size): copies at mostsizebytes ofsourceinto the buffer pointed bydestination
strcollis an alias ofstrcmp, since there is no notion of locale in the runtime environment
strxfrmis an alias ofstrncpy, since there is no notion of locale in the runtime environment
strlwr(string): convertsstringto lowercase characters
strupr(string): convertsstringto uppercase characters
strrev(string): reverses the characters ofstring
strerr(errnum): gives a description of the error corresponding to error numbererrnum
strdup(string): creates a duplicate ofstring
strndup(string, size): creates a duplicate of at mostsizebytes ofstring
strspn(string, accept): computes the length of the longest prefix ofstringwhich consists entirely of bytes inaccept
strcspn(string, reject): computes the length of the longest prefix ofstringwhich consists entirely of bytes not inreject
strpbrk(string, accept): locates the first occurrence instringof any of the bytes inaccept
strstr(haystack, needle): finds the first occurrence ofneedleinhaystack
strtok_r(string, separator, save): extract a token delimited byseparatorfromstring
strsep(string, separator): extract a token delimited byseparatorfromstring
stdio.h
- It defines the following standard functions:
printfputsputchar
For more information about logging see Section Logging.
Not-supported headers
- The following headers are not implemented in the DPU standard library:
complex.hlocale.hmath.hsetjmp.hsignal.hstdatomic.htgmath.hthreads.htime.h
Floating point support
The system library re-uses the LLVM floating-point emulation functions so that floating points can be used natively in C. However, this is pure software emulation, giving very poor performance results: floating points shall be used for very specific non-time-critical operations.