Skip to content

Commit

Permalink
Clarifications and alignment of vector truncations (#301)
Browse files Browse the repository at this point in the history
Previously the spec had allowed trunction conversions to produce
cxvalues which enabled them to be used in output arguments. This is
inconsistent with the DXC and FXC implementation, which disallows
binding trunctions to output arguments.

The spec also previously did not allow trunction to scalar values.
Initially that was excluded due to discussions around truncations and
extensions of output arguments. Since DXC and FXC both disallow
trunction in output arguments, it seems safe to support truncation to
scalar here with a cooresponding warning.

This will allow the spec to more consistently align with the reference
implementations.

This has no change to overload resolution except that a vector argument
can be truncated to a scalar producing a Trunctaion, Truncation
Promotion, or Truncation Conversion implicit conversion sequence.
  • Loading branch information
llvm-beanz authored Aug 29, 2024
1 parent 9c42e27 commit af243b0
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions specs/language/conversions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,33 @@

\Sec{Vector and matrix truncation conversion}{Conv.vtrunc}

\p A glvalue of type \texttt{vector<T,x>} can be converted to a cxvalue of type
\texttt{vector<T,y>}, or a prvalue of type \texttt{vector<T,x>} can be converted
to a prvalue of type \texttt{vector<T,y>} only if \( y < x \). The resulting
value is comprised of elements \( [0..y) \), dropping elements [y+1..x).

\p A glvalue of type \texttt{matrix<T,x,y>} can be converted to a cxvalue of type
\texttt{matrix<T,z,w>}, or a prvalue of type \texttt{matrix<T,x,y>} can be
converted to a prvalue of type \texttt{matrix<T,z,w>} only if \( x \leq z \)
and \(y \leq w \). Matrix truncation is performed on each row and column
dimension separately. The resulting value is comprised of vectors \( [0..z) \)
which are each separately comprised of elements \( [0..w) \). Trailing vectors
and elements are dropped.
\p A prvalue of type \texttt{vector<T,x>} can be converted to a prvalue of type:
\begin{itemize}
\item \texttt{vector<T,y>} only if \( y < x \), or
\item \texttt{T}
\end{itemize}

\p The resulting value of vector truncation is comprised of elements \( [0..y)
\), dropping elements \( [y..x) \).

\p A prvalue of type \texttt{matrix<T,x,y>} can be converted to a prvalue of
type:
\begin{itemize}
\item \texttt{matrix<T,z,w>} only if \( x \geq z \) and \(y \geq w \),
\item \texttt{vector<T,z>} only if \( x \geq z \), or
\item \texttt{T}.
\end{itemize}

\p Matrix truncation is performed on each row and column dimension separately.
The resulting value is comprised of vectors \( [0..z) \) which are each
separately comprised of elements \( [0..w) \). Trailing vectors and elements are
dropped.

\p Reducing the dimension of a vector to one (\texttt{vector<T,1>}), can produce
either a single element vector or a scalar of type \texttt{T}. Reducing the
rows of a matrix to one (\texttt{matrix<T,x,1>}), can produce either a single
row matrix, a vector of type \texttt{vector<T,x>}, or a scalar of type
\texttt{T}.

\Sec{Component-wise conversions}{Conv.cwise}

Expand Down

0 comments on commit af243b0

Please sign in to comment.