File: codegen_sel_method.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (94 lines) | stat: -rw-r--r-- 3,099 bytes parent folder | download | duplicates (2)
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
function codegen_sel_method (opname, func, atype)
%CODEGEN_SEL_METHOD create a selection function, C = select (A,thunk)

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

is_nonzombie_selector = isequal (opname, 'nonzombie') ;
C_iso = isequal (opname, 'eq_thunk') ;

f = fopen ('control.m4', 'w') ;
fprintf (f, 'm4_divert(-1)\n') ;

[aname, ~, ~] = codegen_type (atype) ;

name = sprintf ('%s_%s', opname, aname) ;

if (codegen_contains (opname, 'col'))
    % only bitmap selector is used
    enable_phase1 = false ;
    enable_phase2 = false ;
else
    enable_phase1 = (~is_nonzombie_selector) ;
    enable_phase2 = true ;
end

% function names
if (enable_phase1)
    fprintf (f, 'm4_define(`_sel_phase1'', `_sel_phase1__%s'')\n', name) ;
else
    fprintf (f, 'm4_define(`_sel_phase1'', `_sel_phase1__(none)'')\n') ;
end
if (enable_phase2)
    fprintf (f, 'm4_define(`_sel_phase2'', `_sel_phase2__%s'')\n', name) ;
else
    fprintf (f, 'm4_define(`_sel_phase2'', `_sel_phase2__(none)'')\n', name) ;
end

if isequal (opname, 'nonzombie')
    % no bitmap selectors for nonzombie selectors
    fprintf (f, 'm4_define(`_sel_bitmap'', `_sel_bitmap__(none)'')\n') ;
    fprintf (f, 'm4_define(`if_bitmap'', `-1'')\n') ;
else
    fprintf (f, 'm4_define(`_sel_bitmap'', `_sel_bitmap__%s'')\n', name) ;
    fprintf (f, 'm4_define(`if_bitmap'', `0'')\n') ;
end

% the type of A and y (no typecasting)
fprintf (f, 'm4_define(`GB_atype'',  `#define GB_A_TYPE %s'')\n', atype) ;
fprintf (f, 'm4_define(`GB_ytype'',  `#define GB_Y_TYPE %s'')\n', atype) ;

% create the operator to test the numerical values of the entries
fprintf (f, 'm4_define(`GB_test_value_of_entry'', `#define GB_TEST_VALUE_OF_ENTRY(keep,p) %s'')\n', func) ;

% enable phase1
if (enable_phase1)
    % enable phase1
    fprintf (f, 'm4_define(`if_phase1'', `0'')\n') ;
else
    % disable phase1
    fprintf (f, 'm4_define(`if_phase1'', `-1'')\n') ;
end

% enable phase2
if (enable_phase2)
    % enable phase2
    fprintf (f, 'm4_define(`if_phase2'', `0'')\n') ;
else
    % disable phase2
    fprintf (f, 'm4_define(`if_phase2'', `-1'')\n') ;
end

% for phase2: copy the numerical value of the entry
if (C_iso)
    % create C as iso for all EQ_THUNK ops even when A is not iso, with iso value athunk
    fprintf (f, 'm4_define(`GB_iso_select'', `#define GB_ISO_SELECT 1'')\n') ;
    fprintf (f, 'm4_define(`GB_select_entry'', `#define GB_SELECT_ENTRY(Cx,pC,Ax,pA)'')\n') ;
else
    fprintf (f, 'm4_define(`GB_iso_select'', `'')\n') ;
    fprintf (f, 'm4_define(`GB_select_entry'', `#define GB_SELECT_ENTRY(Cx,pC,Ax,pA) Cx [pC] = Ax [pA]'')\n') ;
end

fprintf (f, 'm4_divert(0)\n') ;
fclose (f) ;

% construct the *.c file
cmd = sprintf ('cat control.m4 Generator/GB_sel.c | m4 -P | awk -f codegen_blank.awk > ../../FactoryKernels/GB_sel__%s.c', name) ;
fprintf ('.') ;
system (cmd) ;

% append to the *.h file
system ('cat control.m4 Generator/GB_sel.h | m4 -P | awk -f codegen_blank.awk | grep -v SPDX >> ../../FactoryKernels/GB_sel__include.h') ;

delete ('control.m4') ;