-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ImportVerilog]Support real math functions. #8192
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -751,15 +751,15 @@ struct RvalueExprVisitor { | |
const auto &subroutine = *info.subroutine; | ||
auto args = expr.arguments(); | ||
|
||
if (subroutine.name == "$signed" || subroutine.name == "$unsigned") | ||
return context.convertRvalueExpression(*args[0]); | ||
|
||
if (subroutine.name == "$clog2") { | ||
auto value = context.convertToSimpleBitVector( | ||
context.convertRvalueExpression(*args[0])); | ||
if (args.size() == 1) { | ||
auto value = context.convertRvalueExpression(*args[0]); | ||
if (!value) | ||
return {}; | ||
return builder.create<moore::Clog2BIOp>(loc, value); | ||
auto result = context.convertSystemCallArity1(subroutine, loc, value); | ||
if (failed(result)) | ||
return {}; | ||
if (*result) | ||
return *result; | ||
} | ||
|
||
mlir::emitError(loc) << "unsupported system call `" << subroutine.name | ||
|
@@ -773,6 +773,12 @@ struct RvalueExprVisitor { | |
return builder.create<moore::StringConstantOp>(loc, type, expr.getValue()); | ||
} | ||
|
||
/// Handle real literals. | ||
Value visit(const slang::ast::RealLiteral &expr) { | ||
return builder.create<moore::RealLiteralOp>( | ||
loc, builder.getF64FloatAttr(expr.getValue())); | ||
} | ||
|
||
/// Handle assignment patterns. | ||
Value visitAssignmentPattern( | ||
const slang::ast::AssignmentPatternExpressionBase &expr, | ||
|
@@ -1310,3 +1316,96 @@ Value Context::materializeConversion(Type type, Value value, bool isSigned, | |
value = builder.create<moore::ConversionOp>(loc, type, value); | ||
return value; | ||
} | ||
|
||
FailureOr<Value> | ||
Context::convertSystemCallArity1(const slang::ast::SystemSubroutine &subroutine, | ||
Location loc, Value value) { | ||
auto systemCallRes = | ||
llvm::StringSwitch<std::function<FailureOr<Value>()>>(subroutine.name) | ||
// Signed and unsigned system functions. | ||
.Case("$signed", [&]() { return value; }) | ||
.Case("$unsigned", [&]() { return value; }) | ||
|
||
// Math functions in SystemVerilog. | ||
.Case("$clog2", | ||
[&]() -> FailureOr<Value> { | ||
value = convertToSimpleBitVector(value); | ||
if (!value) | ||
return failure(); | ||
return (Value)builder.create<moore::Clog2BIOp>(loc, value); | ||
}) | ||
Comment on lines
+1330
to
+1336
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this is reasonable? First time to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! 😃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Greatly appreciate your guidance! |
||
.Case("$ln", | ||
[&]() -> Value { | ||
return builder.create<moore::LnBIOp>(loc, value); | ||
}) | ||
.Case("$log10", | ||
[&]() -> Value { | ||
return builder.create<moore::Log10BIOp>(loc, value); | ||
}) | ||
.Case("$sin", | ||
[&]() -> Value { | ||
return builder.create<moore::SinBIOp>(loc, value); | ||
}) | ||
.Case("$cos", | ||
[&]() -> Value { | ||
return builder.create<moore::CosBIOp>(loc, value); | ||
}) | ||
.Case("$tan", | ||
[&]() -> Value { | ||
return builder.create<moore::TanBIOp>(loc, value); | ||
}) | ||
.Case("$exp", | ||
[&]() -> Value { | ||
return builder.create<moore::ExpBIOp>(loc, value); | ||
}) | ||
.Case("$sqrt", | ||
[&]() -> Value { | ||
return builder.create<moore::SqrtBIOp>(loc, value); | ||
}) | ||
.Case("$floor", | ||
[&]() -> Value { | ||
return builder.create<moore::FloorBIOp>(loc, value); | ||
}) | ||
.Case("$ceil", | ||
[&]() -> Value { | ||
return builder.create<moore::CeilBIOp>(loc, value); | ||
}) | ||
.Case("$asin", | ||
[&]() -> Value { | ||
return builder.create<moore::AsinBIOp>(loc, value); | ||
}) | ||
.Case("$acos", | ||
[&]() -> Value { | ||
return builder.create<moore::AcosBIOp>(loc, value); | ||
}) | ||
.Case("$atan", | ||
[&]() -> Value { | ||
return builder.create<moore::AtanBIOp>(loc, value); | ||
}) | ||
.Case("$sinh", | ||
[&]() -> Value { | ||
return builder.create<moore::SinhBIOp>(loc, value); | ||
}) | ||
.Case("$cosh", | ||
[&]() -> Value { | ||
return builder.create<moore::CoshBIOp>(loc, value); | ||
}) | ||
.Case("$tanh", | ||
[&]() -> Value { | ||
return builder.create<moore::TanhBIOp>(loc, value); | ||
}) | ||
.Case("$asinh", | ||
[&]() -> Value { | ||
return builder.create<moore::AsinhBIOp>(loc, value); | ||
}) | ||
.Case("$acosh", | ||
[&]() -> Value { | ||
return builder.create<moore::AcoshBIOp>(loc, value); | ||
}) | ||
.Case("$atanh", | ||
[&]() -> Value { | ||
return builder.create<moore::AtanhBIOp>(loc, value); | ||
}) | ||
.Default([&]() -> Value { return {}; }); | ||
return systemCallRes(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Borrow from #8020 .