comparison gen/genlib.h @ 45:7955bed1d169 default tip

*: add preliminary floating point support no x86 intrinsics just yet, but I did add altivec since it's (arguably) the simplest :)
author Paper <paper@tflc.us>
date Wed, 30 Apr 2025 18:36:38 -0400
parents
children
comparison
equal deleted inserted replaced
44:b0a3f0248ecc 45:7955bed1d169
1 /**
2 * vec - a tiny SIMD vector library in C99
3 *
4 * Copyright (c) 2024-2025 Paper
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 **/
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 enum {
30 OP_SPLAT,
31 OP_LOAD_ALIGNED,
32 OP_LOAD,
33 OP_STORE_ALIGNED,
34 OP_STORE,
35 OP_ADD,
36 OP_SUB,
37 OP_MUL,
38 OP_DIV,
39 OP_MOD,
40 OP_AVG,
41 OP_AND,
42 OP_OR,
43 OP_XOR,
44 OP_NOT,
45 OP_CMPLT,
46 OP_CMPEQ,
47 OP_CMPGT,
48 OP_CMPLE, /* these are after the other ones to make */
49 OP_CMPGE, /* implementing them as simple as NOT(CMPLT|CMPGT) */
50 OP_MIN,
51 OP_MAX,
52 OP_RSHIFT,
53 OP_LRSHIFT,
54 OP_LSHIFT,
55
56 /* use this for array sizes and the like */
57 OP_FINAL_,
58 };
59
60 enum {
61 TYPE_INT, /* signed int */
62 TYPE_UINT, /* unsigned int */
63 TYPE_FLOAT, /* IEEE float */
64 };
65
66 struct op_info {
67 const char *u;
68 const char *l;
69
70 /* print return type to stdout */
71 void (*pret)(int op, int type, int bits, int size);
72
73 /* print params type to stdout */
74 void (*pparam)(int op, int type, int bits, int size);
75 };
76
77 struct strs {
78 const char *l;
79 const char *u;
80 };
81
82 extern struct strs type_str[];
83
84 struct op_info *gen_op_info(int op);
85
86 struct op_impl {
87 /* return 1 if it's implemented for a specific set of
88 * inputs :)
89 *
90 * if this function is not implemented, and `pbody`
91 * is not NULL, then it is assumed that there are
92 * no restrictions on what type, bits, or size can
93 * be used. beware! */
94 int (*check)(int op, int type, int bits, int size);
95
96 /* prints any additional preprocessor checks needed
97 * should start with a conditional, usually && */
98 void (*ppcheck)(int op, int type, int bits, int size);
99
100 /* sherman?
101 * (this prints the actual body of the function...) */
102 void (*pbody)(int op, int type, int bits, int size);
103 };
104
105 int gen(struct op_impl op_impl[OP_FINAL_], const char *name);
106
107 void gen_print_vtype(int type, int bits, int size);
108 void gen_print_stype(int type, int bits);