It is sometimes useful to return two values from a function. By exploiting the EABI for 64-bit integer values, we can efficiently return two 32-bit values, in ‘C’.
More...
#include "stdint.h"
Go to the source code of this file.
|
#define | pair(x, y) __pair((void*)(x), (void*)(y)) |
| Create a pair, with automatic casting.
|
|
|
typedef uint64_t | pair_t |
| Give a useful name to the return type, indicating it's use.
|
|
|
static pair_t | __pair (void *x, void *y) |
| Create a pair from two generic 32-bit objects.
|
|
static void * | fst (pair_t p) |
| Return the first component of a pair.
|
|
static void * | snd (pair_t p) |
| Return the second component of a pair.
|
|
It is sometimes useful to return two values from a function. By exploiting the EABI for 64-bit integer values, we can efficiently return two 32-bit values, in ‘C’.
The returned values are in r0, and r1 respectively. This obviates the need to use pointers to return pairs of values.
- Author
- Dave Lester (david.nosp@m..r.l.nosp@m.ester.nosp@m.@man.nosp@m.chest.nosp@m.er.a.nosp@m.c.uk)
- Copyright
- Copyright © Dave Lester and The University of Manchester, 2014. All rights reserved.
SpiNNaker Project
Advanced Processor Technologies Group
School of Computer Science
The University of Manchester
Manchester M13 9PL, UK
- Date
- 27 April, 2014
◆ pair_union_t
The implementation of a pair.
◆ pair_union_t.__unnamed1__
struct pair_union_t.__unnamed1__ |
Data Fields |
void * |
lo |
Low word of the pair. |
void * |
hi |
High word of the pair. |
◆ __pair()
static pair_t __pair |
( |
void * |
x, |
|
|
void * |
y |
|
) |
| |
|
inlinestatic |
Create a pair from two generic 32-bit objects.
- Parameters
-
[in] | x | is a void* object |
[in] | y | is a void* object |
- Returns
- A pair of values as a 64-bit unsigned int (pair_t).
◆ fst()
Return the first component of a pair.
- Parameters
-
- Returns
- The first component: n.b. this is void*, so will need casting.
◆ snd()
Return the second component of a pair.
- Parameters
-
- Returns
- The second component: n.b. this is void*, so will need casting.