diff options
author | Andrzej Janik <[email protected]> | 2024-09-03 18:11:09 +0200 |
---|---|---|
committer | Andrzej Janik <[email protected]> | 2024-09-03 18:11:09 +0200 |
commit | 3f31069e1bcd68bee2c0761dc2e817b9fc65579d (patch) | |
tree | 5dc05f3401071c44652b8b4797682bd06532e8c1 /ptx_parser/src | |
parent | 6a7c871b252ee3b9d9ec49000ac779487d8ee8b8 (diff) | |
download | ZLUDA-3f31069e1bcd68bee2c0761dc2e817b9fc65579d.tar.gz ZLUDA-3f31069e1bcd68bee2c0761dc2e817b9fc65579d.zip |
Allow ftz and saturated conversions
Diffstat (limited to 'ptx_parser/src')
-rw-r--r-- | ptx_parser/src/ast.rs | 17 | ||||
-rw-r--r-- | ptx_parser/src/lib.rs | 26 |
2 files changed, 33 insertions, 10 deletions
diff --git a/ptx_parser/src/ast.rs b/ptx_parser/src/ast.rs index f0d7f9f..f5e65b4 100644 --- a/ptx_parser/src/ast.rs +++ b/ptx_parser/src/ast.rs @@ -1384,8 +1384,8 @@ impl CvtDetails { dst: ScalarType,
src: ScalarType,
) -> Self {
- if saturate {
- errors.push(PtxError::Todo);
+ if saturate && dst.kind() == ScalarKind::Float {
+ errors.push(PtxError::SyntaxError);
}
// Modifier .ftz can only be specified when either .dtype or .atype is .f32 and applies only to single precision (.f32) inputs and results.
let flush_to_zero = match (dst, src) {
@@ -1432,6 +1432,18 @@ impl CvtDetails { },
(ScalarKind::Float, ScalarKind::Unsigned) => CvtMode::FPFromUnsigned(unwrap_rounding()),
(ScalarKind::Float, ScalarKind::Signed) => CvtMode::FPFromSigned(unwrap_rounding()),
+ (ScalarKind::Signed, ScalarKind::Unsigned) if saturate => {
+ CvtMode::SaturateUnsignedToSigned
+ }
+ (ScalarKind::Unsigned, ScalarKind::Signed) if saturate => {
+ CvtMode::SaturateSignedToUnsigned
+ }
+ (ScalarKind::Unsigned, ScalarKind::Signed)
+ | (ScalarKind::Signed, ScalarKind::Unsigned)
+ if dst.size_of() == src.size_of() =>
+ {
+ CvtMode::Bitcast
+ }
(ScalarKind::Unsigned, ScalarKind::Unsigned)
| (ScalarKind::Signed, ScalarKind::Signed) => match dst.size_of().cmp(&src.size_of()) {
Ordering::Less => CvtMode::Truncate,
@@ -1444,6 +1456,7 @@ impl CvtDetails { }
}
},
+ (ScalarKind::Unsigned, ScalarKind::Signed) => CvtMode::SaturateSignedToUnsigned,
(_, _) => {
errors.push(PtxError::SyntaxError);
CvtMode::Bitcast
diff --git a/ptx_parser/src/lib.rs b/ptx_parser/src/lib.rs index 357304b..b81d826 100644 --- a/ptx_parser/src/lib.rs +++ b/ptx_parser/src/lib.rs @@ -289,7 +289,12 @@ pub fn parse_module_unchecked<'input>(text: &'input str) -> Option<ast::Module<' state, input: &input[..], }; - module.parse(parser).ok() + let parsing_result = module.parse(parser).ok(); + if !errors.is_empty() { + None + } else { + parsing_result + } } pub fn parse_module_checked<'input>( @@ -314,19 +319,24 @@ pub fn parse_module_checked<'input>( if !errors.is_empty() { return Err(errors); } - let parse_error = { + let parse_result = { let state = PtxParserState::new(&mut errors); let parser = PtxParser { state, input: &tokens[..], }; - match module.parse(parser) { - Ok(ast) => return Ok(ast), - Err(err) => PtxError::Parser(err.into_inner()), - } + module + .parse(parser) + .map_err(|err| PtxError::Parser(err.into_inner())) }; - errors.push(parse_error); - Err(errors) + match parse_result { + Ok(result) if errors.is_empty() => Ok(result), + Ok(_) => Err(errors), + Err(err) => { + errors.push(err); + Err(errors) + } + } } fn module<'a, 'input>(stream: &mut PtxParser<'a, 'input>) -> PResult<ast::Module<'input>> { |