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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
//------------------------------------------------------------------------------
// GB_macrofy_build: construct all macros for GB_build methods
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB.h"
#include "jitifyer/GB_stringify.h"
void GB_macrofy_build // construct all macros for GB_build
(
// output:
FILE *fp, // target file to write, already open
// input:
uint64_t method_code, // unique encoding of the entire problem
GrB_BinaryOp dup, // dup binary operator to macrofy
GrB_Type ttype, // type of Tx
GrB_Type stype // type of Sx
)
{
//--------------------------------------------------------------------------
// extract the method_code
//--------------------------------------------------------------------------
// 32/64 bit (4 bits, 1 hex digit)
int Ti_is_32 = GB_RSHIFT (method_code, 31, 1) ;
int I_is_32 = GB_RSHIFT (method_code, 30, 1) ;
int K_is_32 = GB_RSHIFT (method_code, 29, 1) ;
int K_is_null = GB_RSHIFT (method_code, 28, 1) ;
// dup, z = f(x,y) (6 hex digits)
int no_dupl = GB_RSHIFT (method_code, 27, 1) ;
// int dup_code = GB_RSHIFT (method_code, 20, 6) ;
// int zcode = GB_RSHIFT (method_code, 16, 4) ;
int xcode = GB_RSHIFT (method_code, 12, 4) ;
// int ycode = GB_RSHIFT (method_code, 8, 4) ;
// types of S and T (2 hex digits)
// int tcode = GB_RSHIFT (method_code, 4, 4) ;
// int scode = GB_RSHIFT (method_code, 0, 4) ;
//--------------------------------------------------------------------------
// describe the operator
//--------------------------------------------------------------------------
ASSERT_BINARYOP_OK (dup, "dup for macrofy build", GB0) ;
GrB_Type xtype = dup->xtype ;
GrB_Type ytype = dup->ytype ;
GrB_Type ztype = dup->ztype ;
const char *xtype_name = xtype->name ;
const char *ytype_name = ytype->name ;
const char *ztype_name = ztype->name ;
const char *ttype_name = ttype->name ;
const char *stype_name = stype->name ;
GB_Opcode dup_opcode = dup->opcode ;
if (xcode == GB_BOOL_code) // && (ycode == GB_BOOL_code)
{
// rename the operator
dup_opcode = GB_boolean_rename (dup_opcode) ;
}
if (dup->hash == 0)
{
// builtin operator
fprintf (fp, "// op: (%s, %s)\n\n", dup->name, xtype_name) ;
}
else
{
// user-defined operator, or created by GB_build
fprintf (fp,
"// op: %s%s, ztype: %s, xtype: %s, ytype: %s\n\n",
(dup_opcode == GB_SECOND_binop_code) ? "2nd_" : "",
dup->name, ztype_name, xtype_name, ytype_name) ;
}
//--------------------------------------------------------------------------
// construct the typedefs
//--------------------------------------------------------------------------
GB_macrofy_typedefs (fp, stype, ttype, NULL, xtype, ytype, ztype) ;
fprintf (fp, "// binary dup operator types:\n") ;
GB_macrofy_type (fp, "Z", "_", ztype_name) ;
GB_macrofy_type (fp, "X", "_", xtype_name) ;
GB_macrofy_type (fp, "Y", "_", ytype_name) ;
fprintf (fp, "\n// Sx and Tx data types:\n") ;
GB_macrofy_type (fp, "Tx", "_", ttype_name) ;
GB_macrofy_type (fp, "Sx", "_", stype_name) ;
//--------------------------------------------------------------------------
// construct macros for the binary operator
//--------------------------------------------------------------------------
int dup_ecode ;
GB_enumify_binop (&dup_ecode, dup_opcode, xcode, false, false) ;
fprintf (fp, "\n// binary dup operator:\n") ;
GB_macrofy_binop (fp, "GB_DUP", false, false, true, false, false,
dup_ecode, false, dup, NULL, NULL, NULL) ;
if (dup_opcode == GB_FIRST_binop_code)
{
fprintf (fp, "#define GB_DUP_IS_FIRST\n") ;
}
fprintf (fp, "\n// build copy/dup methods:\n") ;
// no typecasting if all 5 types are the same
bool nocasting = (ttype == stype) &&
(ttype == xtype) && (ttype == ytype) && (ttype == ztype) ;
if (nocasting)
{
//----------------------------------------------------------------------
// GB_BLD_COPY: Tx [p] = Sx [k]
//----------------------------------------------------------------------
fprintf (fp, "#define GB_BLD_COPY(Tx,p,Sx,k) Tx [p] = Sx [k]\n") ;
//----------------------------------------------------------------------
// GB_BLD_DUP: Tx [p] += Sx [k]
//----------------------------------------------------------------------
fprintf (fp, "#define GB_BLD_DUP(Tx,p,Sx,k)") ;
if (dup_opcode != GB_FIRST_binop_code)
{
fprintf (fp, " GB_UPDATE (Tx [p], Sx [k])") ;
}
fprintf (fp, "\n") ;
}
else
{
//----------------------------------------------------------------------
// GB_BLD_COPY: Tx [p] = (cast) Sx [k]
//----------------------------------------------------------------------
int nargs_s_to_t, nargs_s_to_y, nargs_t_to_x, nargs_z_to_t ;
const char *cast_s_to_t =
GB_macrofy_cast_expression (fp, ttype, stype, &nargs_s_to_t) ;
const char *cast_s_to_y =
GB_macrofy_cast_expression (fp, ytype, stype, &nargs_s_to_y) ;
const char *cast_t_to_x =
GB_macrofy_cast_expression (fp, xtype, ttype, &nargs_t_to_x) ;
const char *cast_z_to_t =
GB_macrofy_cast_expression (fp, ttype, ztype, &nargs_z_to_t) ;
fprintf (fp, "#define GB_BLD_COPY(Tx,p,Sx,k)") ;
if (cast_s_to_t == NULL)
{
fprintf (fp, " Tx [p] = (%s) Sx [k]", ttype_name) ;
}
else if (nargs_s_to_t == 3)
{
fprintf (fp, cast_s_to_t, " Tx [p]", "Sx [k]", "Sx [k]") ;
}
else
{
fprintf (fp, cast_s_to_t, " Tx [p]", "Sx [k]") ;
}
fprintf (fp, "\n") ;
//----------------------------------------------------------------------
// GB_BLD_DUP: Tx [p] += Sx [k], with typecasting
//----------------------------------------------------------------------
fprintf (fp, "#define GB_BLD_DUP(Tx,p,Sx,k) \\\n") ;
// ytype y = (ytype) Sx [k] ;
fprintf (fp, " %s ", ytype_name) ;
if (cast_s_to_y == NULL)
{
fprintf (fp, "y = (%s) Sx [k]", ytype_name) ;
}
else if (nargs_s_to_y == 3)
{
fprintf (fp, cast_s_to_y, "y", "Sx [k]", "Sx [k]") ;
}
else
{
fprintf (fp, cast_s_to_y, "y", "Sx [k]") ;
}
fprintf (fp, " ; \\\n") ;
// xtype x = (xtype) Tx [p] ;
fprintf (fp, " %s ", xtype_name) ;
if (cast_t_to_x == NULL)
{
fprintf (fp, "x = (%s) Tx [p]", xtype_name) ;
}
else if (nargs_t_to_x == 3)
{
fprintf (fp, cast_t_to_x, "x", "Tx [p]", "Tx [p]") ;
}
else
{
fprintf (fp, cast_t_to_x, "x", "Tx [p]") ;
}
fprintf (fp, " ; \\\n") ;
// ztype z = dup (x,y) ;
fprintf (fp, " %s z ; \\\n", ztype_name) ;
fprintf (fp, " GB_DUP (z, x, y) ; \\\n") ;
// Tx [p] = (ttype) z ;
if (cast_z_to_t == NULL)
{
fprintf (fp, " Tx [p] = (%s) z", ttype_name) ;
}
else if (nargs_z_to_t == 3)
{
fprintf (fp, cast_z_to_t, " Tx [p]", "z", "z") ;
}
else
{
fprintf (fp, cast_z_to_t, " Tx [p]", "z") ;
}
fprintf (fp, " ;\n") ;
}
//--------------------------------------------------------------------------
// 32/64 integer arrays
//--------------------------------------------------------------------------
fprintf (fp, "\n// 32/64 integer types:\n") ;
fprintf (fp, "#define GB_Ti_TYPE %s\n", Ti_is_32 ? "int32_t" : "int64_t") ;
fprintf (fp, "#define GB_Ti_BITS %d\n", Ti_is_32 ? 32 : 64) ;
fprintf (fp, "#define GB_I_TYPE %s\n", I_is_32 ? "uint32_t":"uint64_t") ;
fprintf (fp, "#define GB_K_TYPE %s\n", K_is_32 ? "uint32_t":"uint64_t") ;
fprintf (fp, "#define GB_K_WORK(k) %s\n", K_is_null ? "k" : "K_work [k]") ;
fprintf (fp, "#define GB_K_IS_NULL %d\n", K_is_null) ;
fprintf (fp, "#define GB_NO_DUPLICATES %d\n", no_dupl) ;
//--------------------------------------------------------------------------
// include the final default definitions
//--------------------------------------------------------------------------
fprintf (fp, "\n#include \"include/GB_kernel_shared_definitions.h\"\n") ;
}
|