|
@@ -1922,126 +1922,6 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
|
|
|
|
|
|
ir_emit_comment(proc, str_lit("complex.end.begin"));
|
|
ir_emit_comment(proc, str_lit("complex.end.begin"));
|
|
return ir_emit_load(proc, res);
|
|
return ir_emit_load(proc, res);
|
|
- } else if (is_type_quaternion(t_left)) {
|
|
|
|
- ir_emit_comment(proc, str_lit("quaternion.arith.begin"));
|
|
|
|
- Type *ft = base_quaternion_elem_type(t_left);
|
|
|
|
-
|
|
|
|
- irValue *res = ir_add_local_generated(proc, type);
|
|
|
|
- irValue *a = ir_emit_struct_ev(proc, left, 0);
|
|
|
|
- irValue *b = ir_emit_struct_ev(proc, left, 1);
|
|
|
|
- irValue *c = ir_emit_struct_ev(proc, left, 2);
|
|
|
|
- irValue *d = ir_emit_struct_ev(proc, left, 3);
|
|
|
|
-
|
|
|
|
- irValue *e = ir_emit_struct_ev(proc, right, 0);
|
|
|
|
- irValue *f = ir_emit_struct_ev(proc, right, 1);
|
|
|
|
- irValue *g = ir_emit_struct_ev(proc, right, 2);
|
|
|
|
- irValue *h = ir_emit_struct_ev(proc, right, 3);
|
|
|
|
-
|
|
|
|
- irValue *real = NULL;
|
|
|
|
- irValue *imag = NULL;
|
|
|
|
- irValue *jmag = NULL;
|
|
|
|
- irValue *kmag = NULL;
|
|
|
|
-
|
|
|
|
- switch (op) {
|
|
|
|
- case Token_Add:
|
|
|
|
- real = ir_emit_arith(proc, Token_Add, a, e, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Add, b, f, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Add, c, g, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Add, d, h, ft);
|
|
|
|
- break;
|
|
|
|
- case Token_Sub:
|
|
|
|
- real = ir_emit_arith(proc, Token_Sub, a, e, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Sub, b, f, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Sub, c, g, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Sub, d, h, ft);
|
|
|
|
- break;
|
|
|
|
- case Token_Mul: {
|
|
|
|
- irValue *r0 = ir_emit_arith(proc, Token_Mul, a, e, ft);
|
|
|
|
- irValue *r1 = ir_emit_arith(proc, Token_Mul, b, f, ft);
|
|
|
|
- irValue *r2 = ir_emit_arith(proc, Token_Mul, c, h, ft);
|
|
|
|
- irValue *r3 = ir_emit_arith(proc, Token_Mul, d, g, ft);
|
|
|
|
- real = ir_emit_arith(proc, Token_Add, r0, r1, ft);
|
|
|
|
- real = ir_emit_arith(proc, Token_Add, real, r2, ft);
|
|
|
|
- real = ir_emit_arith(proc, Token_Add, real, r3, ft);
|
|
|
|
-
|
|
|
|
- irValue *i0 = ir_emit_arith(proc, Token_Mul, a, g, ft);
|
|
|
|
- irValue *i1 = ir_emit_arith(proc, Token_Mul, b, h, ft);
|
|
|
|
- irValue *i2 = ir_emit_arith(proc, Token_Mul, c, e, ft);
|
|
|
|
- irValue *i3 = ir_emit_arith(proc, Token_Mul, d, f, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Sub, i0, i1, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Add, imag, i2, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Add, imag, i3, ft);
|
|
|
|
-
|
|
|
|
- irValue *j0 = ir_emit_arith(proc, Token_Mul, a, h, ft);
|
|
|
|
- irValue *j1 = ir_emit_arith(proc, Token_Mul, b, g, ft);
|
|
|
|
- irValue *j2 = ir_emit_arith(proc, Token_Mul, c, f, ft);
|
|
|
|
- irValue *j3 = ir_emit_arith(proc, Token_Mul, d, e, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Add, j0, j1, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Sub, imag, j2, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Sub, imag, j3, ft);
|
|
|
|
-
|
|
|
|
- irValue *k0 = ir_emit_arith(proc, Token_Mul, a, e, ft);
|
|
|
|
- irValue *k1 = ir_emit_arith(proc, Token_Mul, b, f, ft);
|
|
|
|
- irValue *k2 = ir_emit_arith(proc, Token_Mul, c, g, ft);
|
|
|
|
- irValue *k3 = ir_emit_arith(proc, Token_Mul, d, h, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Sub, j0, j1, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Sub, imag, j2, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Sub, imag, j3, ft);
|
|
|
|
- } break;
|
|
|
|
- case Token_Quo: {
|
|
|
|
- irValue *s0 = ir_emit_arith(proc, Token_Mul, e, e, ft);
|
|
|
|
- irValue *s1 = ir_emit_arith(proc, Token_Mul, f, f, ft);
|
|
|
|
- irValue *s2 = ir_emit_arith(proc, Token_Mul, g, g, ft);
|
|
|
|
- irValue *s3 = ir_emit_arith(proc, Token_Mul, h, h, ft);
|
|
|
|
- irValue *s = ir_emit_arith(proc, Token_Add, s0, s1, ft);
|
|
|
|
- s = ir_emit_arith(proc, Token_Add, s, s2, ft);
|
|
|
|
- s = ir_emit_arith(proc, Token_Add, s, s3, ft);
|
|
|
|
-
|
|
|
|
- irValue *r0 = ir_emit_arith(proc, Token_Mul, a, e, ft);
|
|
|
|
- irValue *r1 = ir_emit_arith(proc, Token_Mul, b, f, ft);
|
|
|
|
- irValue *r2 = ir_emit_arith(proc, Token_Mul, c, h, ft);
|
|
|
|
- irValue *r3 = ir_emit_arith(proc, Token_Mul, d, g, ft);
|
|
|
|
- real = ir_emit_arith(proc, Token_Add, r0, r1, ft);
|
|
|
|
- real = ir_emit_arith(proc, Token_Add, real, r2, ft);
|
|
|
|
- real = ir_emit_arith(proc, Token_Add, real, r3, ft);
|
|
|
|
- real = ir_emit_arith(proc, Token_Quo, real, s, ft);
|
|
|
|
-
|
|
|
|
- irValue *i0 = ir_emit_arith(proc, Token_Mul, a, f, ft);
|
|
|
|
- irValue *i1 = ir_emit_arith(proc, Token_Mul, b, e, ft);
|
|
|
|
- irValue *i2 = ir_emit_arith(proc, Token_Mul, c, h, ft);
|
|
|
|
- irValue *i3 = ir_emit_arith(proc, Token_Mul, d, g, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Sub, i1, i0, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Sub, imag, i2, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Add, imag, i3, ft);
|
|
|
|
- imag = ir_emit_arith(proc, Token_Quo, imag, s, ft);
|
|
|
|
-
|
|
|
|
- irValue *j0 = ir_emit_arith(proc, Token_Mul, a, g, ft);
|
|
|
|
- irValue *j1 = ir_emit_arith(proc, Token_Mul, b, h, ft);
|
|
|
|
- irValue *j2 = ir_emit_arith(proc, Token_Mul, c, e, ft);
|
|
|
|
- irValue *j3 = ir_emit_arith(proc, Token_Mul, d, f, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Sub, j1, j0, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Add, imag, j2, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Sub, imag, j3, ft);
|
|
|
|
- jmag = ir_emit_arith(proc, Token_Quo, jmag, s, ft);
|
|
|
|
-
|
|
|
|
- irValue *k0 = ir_emit_arith(proc, Token_Mul, a, h, ft);
|
|
|
|
- irValue *k1 = ir_emit_arith(proc, Token_Mul, b, g, ft);
|
|
|
|
- irValue *k2 = ir_emit_arith(proc, Token_Mul, c, f, ft);
|
|
|
|
- irValue *k3 = ir_emit_arith(proc, Token_Mul, d, e, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Add, k2, k3, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Sub, imag, k0, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Sub, imag, k1, ft);
|
|
|
|
- kmag = ir_emit_arith(proc, Token_Quo, kmag, s, ft);
|
|
|
|
- } break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 0), real);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 1), imag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 2), jmag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 3), kmag);
|
|
|
|
-
|
|
|
|
- ir_emit_comment(proc, str_lit("quaternion.end.begin"));
|
|
|
|
- return ir_emit_load(proc, res);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -2319,14 +2199,6 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) {
|
|
case 0: result_type = make_type_pointer(a, ft); break;
|
|
case 0: result_type = make_type_pointer(a, ft); break;
|
|
case 1: result_type = make_type_pointer(a, ft); break;
|
|
case 1: result_type = make_type_pointer(a, ft); break;
|
|
}
|
|
}
|
|
- } else if (is_type_quaternion(t)) {
|
|
|
|
- Type *ft = base_quaternion_elem_type(t);
|
|
|
|
- switch (index) {
|
|
|
|
- case 0: result_type = make_type_pointer(a, ft); break;
|
|
|
|
- case 1: result_type = make_type_pointer(a, ft); break;
|
|
|
|
- case 2: result_type = make_type_pointer(a, ft); break;
|
|
|
|
- case 3: result_type = make_type_pointer(a, ft); break;
|
|
|
|
- }
|
|
|
|
} else if (is_type_slice(t)) {
|
|
} else if (is_type_slice(t)) {
|
|
switch (index) {
|
|
switch (index) {
|
|
case 0: result_type = make_type_pointer(a, make_type_pointer(a, t->Slice.elem)); break;
|
|
case 0: result_type = make_type_pointer(a, make_type_pointer(a, t->Slice.elem)); break;
|
|
@@ -2396,14 +2268,6 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) {
|
|
case 0: result_type = ft; break;
|
|
case 0: result_type = ft; break;
|
|
case 1: result_type = ft; break;
|
|
case 1: result_type = ft; break;
|
|
}
|
|
}
|
|
- } else if (is_type_quaternion(t)) {
|
|
|
|
- Type *ft = base_quaternion_elem_type(t);
|
|
|
|
- switch (index) {
|
|
|
|
- case 0: result_type = ft; break;
|
|
|
|
- case 1: result_type = ft; break;
|
|
|
|
- case 2: result_type = ft; break;
|
|
|
|
- case 3: result_type = ft; break;
|
|
|
|
- }
|
|
|
|
} else if (is_type_slice(t)) {
|
|
} else if (is_type_slice(t)) {
|
|
switch (index) {
|
|
switch (index) {
|
|
case 0: result_type = make_type_pointer(a, t->Slice.elem); break;
|
|
case 0: result_type = make_type_pointer(a, t->Slice.elem); break;
|
|
@@ -2744,8 +2608,6 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
|
ev = exact_value_to_float(ev);
|
|
ev = exact_value_to_float(ev);
|
|
} else if (is_type_complex(dst)) {
|
|
} else if (is_type_complex(dst)) {
|
|
ev = exact_value_to_complex(ev);
|
|
ev = exact_value_to_complex(ev);
|
|
- } else if (is_type_quaternion(dst)) {
|
|
|
|
- ev = exact_value_to_quaternion(ev);
|
|
|
|
} else if (is_type_string(dst)) {
|
|
} else if (is_type_string(dst)) {
|
|
// Handled elsewhere
|
|
// Handled elsewhere
|
|
GB_ASSERT(ev.kind == ExactValue_String);
|
|
GB_ASSERT(ev.kind == ExactValue_String);
|
|
@@ -2821,20 +2683,6 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
|
return ir_emit_load(proc, gen);
|
|
return ir_emit_load(proc, gen);
|
|
}
|
|
}
|
|
|
|
|
|
- if (is_type_quaternion(src) && is_type_quaternion(dst)) {
|
|
|
|
- Type *ft = base_quaternion_elem_type(dst);
|
|
|
|
- irValue *gen = ir_add_local_generated(proc, dst);
|
|
|
|
- irValue *real = ir_emit_conv(proc, ir_emit_struct_ev(proc, value, 0), ft);
|
|
|
|
- irValue *imag = ir_emit_conv(proc, ir_emit_struct_ev(proc, value, 1), ft);
|
|
|
|
- irValue *jmag = ir_emit_conv(proc, ir_emit_struct_ev(proc, value, 2), ft);
|
|
|
|
- irValue *kmag = ir_emit_conv(proc, ir_emit_struct_ev(proc, value, 3), ft);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, gen, 0), real);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, gen, 1), imag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, gen, 2), jmag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, gen, 3), kmag);
|
|
|
|
- return ir_emit_load(proc, gen);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// float <-> integer
|
|
// float <-> integer
|
|
if (is_type_float(src) && is_type_integer(dst)) {
|
|
if (is_type_float(src) && is_type_integer(dst)) {
|
|
irConvKind kind = irConv_fptosi;
|
|
irConvKind kind = irConv_fptosi;
|
|
@@ -3032,8 +2880,6 @@ bool ir_is_type_aggregate(Type *t) {
|
|
|
|
|
|
case Basic_complex64:
|
|
case Basic_complex64:
|
|
case Basic_complex128:
|
|
case Basic_complex128:
|
|
- case Basic_quaternion128:
|
|
|
|
- case Basic_quaternion256:
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -4476,27 +4322,6 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
|
return ir_emit_load(proc, dst);
|
|
return ir_emit_load(proc, dst);
|
|
} break;
|
|
} break;
|
|
|
|
|
|
- case BuiltinProc_quaternion: {
|
|
|
|
- ir_emit_comment(proc, str_lit("quaternion"));
|
|
|
|
- irValue *real = ir_build_expr(proc, ce->args.e[0]);
|
|
|
|
- irValue *imag = ir_build_expr(proc, ce->args.e[1]);
|
|
|
|
- irValue *jmag = ir_build_expr(proc, ce->args.e[2]);
|
|
|
|
- irValue *kmag = ir_build_expr(proc, ce->args.e[3]);
|
|
|
|
- irValue *dst = ir_add_local_generated(proc, tv.type);
|
|
|
|
-
|
|
|
|
- Type *ft = base_quaternion_elem_type(tv.type);
|
|
|
|
- real = ir_emit_conv(proc, real, ft);
|
|
|
|
- imag = ir_emit_conv(proc, imag, ft);
|
|
|
|
- jmag = ir_emit_conv(proc, jmag, ft);
|
|
|
|
- kmag = ir_emit_conv(proc, kmag, ft);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, dst, 0), real);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, dst, 1), imag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, dst, 2), jmag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, dst, 3), kmag);
|
|
|
|
-
|
|
|
|
- return ir_emit_load(proc, dst);
|
|
|
|
- } break;
|
|
|
|
-
|
|
|
|
case BuiltinProc_real: {
|
|
case BuiltinProc_real: {
|
|
ir_emit_comment(proc, str_lit("real"));
|
|
ir_emit_comment(proc, str_lit("real"));
|
|
irValue *val = ir_build_expr(proc, ce->args.e[0]);
|
|
irValue *val = ir_build_expr(proc, ce->args.e[0]);
|
|
@@ -4509,18 +4334,6 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
|
irValue *imag = ir_emit_struct_ev(proc, val, 1);
|
|
irValue *imag = ir_emit_struct_ev(proc, val, 1);
|
|
return ir_emit_conv(proc, imag, tv.type);
|
|
return ir_emit_conv(proc, imag, tv.type);
|
|
} break;
|
|
} break;
|
|
- case BuiltinProc_jmag: {
|
|
|
|
- ir_emit_comment(proc, str_lit("jmag"));
|
|
|
|
- irValue *val = ir_build_expr(proc, ce->args.e[0]);
|
|
|
|
- irValue *jmag = ir_emit_struct_ev(proc, val, 2);
|
|
|
|
- return ir_emit_conv(proc, jmag, tv.type);
|
|
|
|
- } break;
|
|
|
|
- case BuiltinProc_kmag: {
|
|
|
|
- ir_emit_comment(proc, str_lit("kmag"));
|
|
|
|
- irValue *val = ir_build_expr(proc, ce->args.e[0]);
|
|
|
|
- irValue *kmag = ir_emit_struct_ev(proc, val, 3);
|
|
|
|
- return ir_emit_conv(proc, kmag, tv.type);
|
|
|
|
- } break;
|
|
|
|
|
|
|
|
case BuiltinProc_conj: {
|
|
case BuiltinProc_conj: {
|
|
ir_emit_comment(proc, str_lit("conj"));
|
|
ir_emit_comment(proc, str_lit("conj"));
|
|
@@ -4534,19 +4347,6 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
|
imag = ir_emit_unary_arith(proc, Token_Sub, imag, ir_type(imag));
|
|
imag = ir_emit_unary_arith(proc, Token_Sub, imag, ir_type(imag));
|
|
ir_emit_store(proc, ir_emit_struct_ep(proc, res, 0), real);
|
|
ir_emit_store(proc, ir_emit_struct_ep(proc, res, 0), real);
|
|
ir_emit_store(proc, ir_emit_struct_ep(proc, res, 1), imag);
|
|
ir_emit_store(proc, ir_emit_struct_ep(proc, res, 1), imag);
|
|
- } else if (is_type_quaternion(t)) {
|
|
|
|
- res = ir_add_local_generated(proc, tv.type);
|
|
|
|
- irValue *real = ir_emit_struct_ev(proc, val, 0);
|
|
|
|
- irValue *imag = ir_emit_struct_ev(proc, val, 1);
|
|
|
|
- irValue *jmag = ir_emit_struct_ev(proc, val, 2);
|
|
|
|
- irValue *kmag = ir_emit_struct_ev(proc, val, 3);
|
|
|
|
- imag = ir_emit_unary_arith(proc, Token_Sub, imag, ir_type(imag));
|
|
|
|
- jmag = ir_emit_unary_arith(proc, Token_Sub, jmag, ir_type(jmag));
|
|
|
|
- kmag = ir_emit_unary_arith(proc, Token_Sub, kmag, ir_type(kmag));
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 0), real);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 1), imag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 2), jmag);
|
|
|
|
- ir_emit_store(proc, ir_emit_struct_ep(proc, res, 3), kmag);
|
|
|
|
}
|
|
}
|
|
return ir_emit_load(proc, res);
|
|
return ir_emit_load(proc, res);
|
|
} break;
|
|
} break;
|
|
@@ -4619,16 +4419,6 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
|
case 128: return ir_emit_global_call(proc, "__abs_complex128", args, 1);
|
|
case 128: return ir_emit_global_call(proc, "__abs_complex128", args, 1);
|
|
}
|
|
}
|
|
GB_PANIC("Unknown complex type");
|
|
GB_PANIC("Unknown complex type");
|
|
- } else if (is_type_quaternion(t)) {
|
|
|
|
- gbAllocator a = proc->module->allocator;
|
|
|
|
- i64 sz = 8*type_size_of(a, t);
|
|
|
|
- irValue **args = gb_alloc_array(a, irValue *, 1);
|
|
|
|
- args[0] = x;
|
|
|
|
- switch (sz) {
|
|
|
|
- case 128: return ir_emit_global_call(proc, "__abs_quaternion128", args, 1);
|
|
|
|
- case 256: return ir_emit_global_call(proc, "__abs_quaternion256", args, 1);
|
|
|
|
- }
|
|
|
|
- GB_PANIC("Unknown quaternion type");
|
|
|
|
}
|
|
}
|
|
irValue *zero = ir_emit_conv(proc, v_zero, t);
|
|
irValue *zero = ir_emit_conv(proc, v_zero, t);
|
|
irValue *cond = ir_emit_comp(proc, Token_Lt, x, zero);
|
|
irValue *cond = ir_emit_comp(proc, Token_Lt, x, zero);
|
|
@@ -7566,11 +7356,6 @@ void ir_gen_tree(irGen *s) {
|
|
tag = ir_emit_conv(proc, ti_ptr, t_type_info_complex_ptr);
|
|
tag = ir_emit_conv(proc, ti_ptr, t_type_info_complex_ptr);
|
|
} break;
|
|
} break;
|
|
|
|
|
|
- case Basic_quaternion128:
|
|
|
|
- case Basic_quaternion256: {
|
|
|
|
- tag = ir_emit_conv(proc, ti_ptr, t_type_info_quaternion_ptr);
|
|
|
|
- } break;
|
|
|
|
-
|
|
|
|
case Basic_rawptr:
|
|
case Basic_rawptr:
|
|
tag = ir_emit_conv(proc, ti_ptr, t_type_info_pointer_ptr);
|
|
tag = ir_emit_conv(proc, ti_ptr, t_type_info_pointer_ptr);
|
|
break;
|
|
break;
|