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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
//------------------------------------------------------------------------------
// GB_cast_int: parallel memcpy or int32_t/int64_t/uint32_t/uint64_t type cast
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB.h"
void GB_cast_int // parallel memcpy/cast of integer arrays
(
void *dest, // destination
GB_Type_code dest_code, // destination type: int32/64, or uint32/64
const void *src, // source
GB_Type_code src_code, // source type: int32/64, or uint32/64
size_t n, // # of entries to copy
int nthreads_max // max # of threads to use
)
{
//--------------------------------------------------------------------------
// get the # of threads
//--------------------------------------------------------------------------
int nthreads = GB_nthreads (n, GB_CHUNK_DEFAULT, nthreads_max) ;
int64_t k ;
//--------------------------------------------------------------------------
// copy/cast the integer array
//--------------------------------------------------------------------------
switch (dest_code)
{
//----------------------------------------------------------------------
// destination is int32_t
//----------------------------------------------------------------------
case GB_INT32_code :
switch (src_code)
{
case GB_INT32_code :
case GB_UINT32_code :
GB_memcpy (dest, src, n * sizeof (uint32_t), nthreads) ;
break ;
case GB_INT64_code :
{
int32_t *restrict Dest = (int32_t *) dest ;
const int64_t *restrict Src = (int64_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
case GB_UINT64_code :
{
int32_t *restrict Dest = (int32_t *) dest ;
const uint64_t *restrict Src = (uint64_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
default: ;
}
break ;
//----------------------------------------------------------------------
// destination is uint32_t
//----------------------------------------------------------------------
case GB_UINT32_code :
switch (src_code)
{
case GB_INT32_code :
case GB_UINT32_code :
GB_memcpy (dest, src, n * sizeof (uint32_t), nthreads) ;
break ;
case GB_INT64_code :
{
uint32_t *restrict Dest = (uint32_t *) dest ;
const int64_t *restrict Src = (int64_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
case GB_UINT64_code :
{
uint32_t *restrict Dest = (uint32_t *) dest ;
const uint64_t *restrict Src = (uint64_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
default: ;
}
break ;
//----------------------------------------------------------------------
// destination is int64_t
//----------------------------------------------------------------------
case GB_INT64_code :
switch (src_code)
{
case GB_INT32_code :
{
int64_t *restrict Dest = (int64_t *) dest ;
const int32_t *restrict Src = (int32_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
case GB_UINT32_code :
{
int64_t *restrict Dest = (int64_t *) dest ;
const uint32_t *restrict Src = (uint32_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
case GB_INT64_code :
case GB_UINT64_code :
GB_memcpy (dest, src, n * sizeof (uint64_t), nthreads) ;
break ;
default: ;
}
break ;
//----------------------------------------------------------------------
// destination is uint64_t
//----------------------------------------------------------------------
case GB_UINT64_code :
switch (src_code)
{
case GB_INT32_code :
{
uint64_t *restrict Dest = (uint64_t *) dest ;
const int32_t *restrict Src = (int32_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
case GB_UINT32_code :
{
uint64_t *restrict Dest = (uint64_t *) dest ;
const uint32_t *restrict Src = (uint32_t *) src ;
#include "cast/factory/GB_cast_int_template.c"
}
break ;
case GB_INT64_code :
case GB_UINT64_code :
GB_memcpy (dest, src, n * sizeof (uint64_t), nthreads) ;
break ;
default: ;
}
break ;
default: ;
}
}
|