Closed madmann91 closed 9 years ago
simd[bool * n] is what it should yield.
Then I guess we need some kind of select function for that to be useful.
After some inspection of the code, it seems to be possible to write something insane like :
fn main() -> float {
let t = 1.0f;
let u = 2.78f;
t >> u
}
This is because you have :
case SHL:
case SHR:
case OR:
case XOR:
case AND: {
auto type = sema.check(lhs(), sema.check(rhs(), expected));
sema.expect_num(lhs());
sema.expect_num(rhs());
return type;
}
That should be expect_int right ?
(This typechecks but ultimately segfaults)
yes, that's a bug.
So I have thought a bit about how to add these vectors of booleans and here is my plan:
Currently, the expression a ^ b or a & b doesn't typecheck when a and b are booleans. I would like to allow it, since the meaning is different from && or || (logical operators) which are lazy. This would then allow us to extend it to vectors of booleans.
Ultimately, we could add a select function (as different intrinsics for each vector size, or as a special function - ideal would be special function since its signature would be select([bool * n], [a * n], [a * n]), which is not encodable with the current framework).
Another option would be to extend the sematics of "if" so that it behaves like select when the condition is a vector of booleans.
What are your thoughts about this ?
a
op b
with op = {^
,&
,|
} should work on booleans. That's a bug. And we should also allow that on simd[bool * n]
Regarding select:
If you allow simd[bool * n] as condition of an if-expr, you will get sth like sierra:
sierra-lang.org
I'm not sure whether we want to go that route with Impala.
So, we would need a function select
of type
fn[N: int, T](simd[bool * N], simd[T * N], simd[T * N])
.
But as you pointed out, we currently cannot have that as we don't have dependent types. Workaround would be some functions select4, select8, select16 and so forth.
I get it. Did you mention modulo on booleans, or did you mean & ? What about having a select "function" (syntactic construct) in the language itself (that would also work with booleans, not only vector of booleans) ?
yes %
=&
:) - edited above
regarding select in the language:
I'm not too enthusiastic about that. That would require parsing, type checking, code generation and so forth. Quite a bit for a hack.
I know the select4
, select8
, ... workaround is ugly but it does not require a hack in the frontend.
However, if we had the select
temporarily in the language we could at least remove that from the language again once we have dependent types. So, if you are willing to implement that and this solves an urgent issue, you are welcome to do it.
Alright. It is not really necessary. Particularly if you intend to have dependent types working at some point.
I have a patch ready. Should I create a new branch for you to review or should I push it directly ?
just push it :)
Marked as solved.
Vector comparisons should be forbidden. Or return simd[bool * n].