Преобразования
Версия от 18:03, 16 марта 2018; Admin (обсуждение | вклад)
Операции преобразования позволяют изменять представление значения, возможность модифицировать их, если указанный тип не может использовать значение исходного типа. Преобразова
Conversion operations allow to change the representation of a value, possibly modifying it if the target type cannot hold the value of the source type. Conversions can extend the precision of a temporary (e.g., from signed 8-bit to 32-bit), or convert a floating point into an integer and vice versa.
extsw, extuw -- l(w) extsh, extuh -- I(ww) extsb, extub -- I(ww) exts -- d(s) truncd -- s(d) stosi -- I(ss) dtosi -- I(dd) swtof -- F(ww) sltof -- F(ll)
Extending the precision of a temporary is done using the ext family of instructions. Because QBE types do not precise the signedness (like in LLVM), extension instructions exist to sign-extend and zero-extend a value. For example, extsb takes a word argument and sign-extend the 8 least-significant bits to a full word or long, depending on the return type.
The instructions exts and truncd are provided to change the precision of a floating point value. When the double argument of truncd cannot be represented as a single-precision floating point, it is truncated towards zero.
Converting between signed integers and floating points is done using stosi (single to signed integer), dtosi (double to signed integer), swtof (signed word to float), and sltof (signed long to float). These instructions only handle signed integers, conversion to and from unsigned types are not yet supported.
Because of Subtyping, there is no need to have an instruction to lower the precision of an integer temporary.
Источник: c9x.me