开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 3

xiongying/Halide

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
Halide
/
src
/
Simplify_Mod.cpp
Halide
/
src
/
Simplify_Mod.cpp
Simplify_Mod.cpp 4.59 KB
一键复制 编辑 原始数据 按行查看 历史
#include "Simplify_Internal.h"
namespace Halide {
namespace Internal {
Expr Simplify::visit(const Mod *op, ExprInfo *bounds) {
ExprInfo a_bounds, b_bounds;
Expr a = mutate(op->a, &a_bounds);
Expr b = mutate(op->b, &b_bounds);
// We always combine bounds here, even if not requested, because
// we can use them to simplify down to a constant if the bounds
// are tight enough.
ExprInfo mod_bounds;
if (no_overflow_int(op->type)) {
// The result is at least zero.
mod_bounds.min_defined = true;
mod_bounds.min = 0;
// Mod by produces a result between 0
// and max(0, abs(modulus) - 1). However, if b is unbounded in
// either direction, abs(modulus) could be arbitrarily
// large.
if (b_bounds.max_defined && b_bounds.min_defined) {
mod_bounds.max_defined = true;
mod_bounds.max = 0; // When b == 0
mod_bounds.max = std::max(mod_bounds.max, b_bounds.max - 1); // When b > 0
mod_bounds.max = std::max(mod_bounds.max, -1 - b_bounds.min); // When b < 0
}
// If a is positive, mod can't make it larger
if (a_bounds.min_defined && a_bounds.min >= 0 && a_bounds.max_defined) {
if (mod_bounds.max_defined) {
mod_bounds.max = std::min(mod_bounds.max, a_bounds.max);
} else {
mod_bounds.max_defined = true;
mod_bounds.max = a_bounds.max;
}
}
mod_bounds.alignment = a_bounds.alignment % b_bounds.alignment;
mod_bounds.trim_bounds_using_alignment();
if (bounds) {
*bounds = mod_bounds;
}
}
if (may_simplify(op->type)) {
if (a_bounds.min_defined && a_bounds.min >= 0 &&
a_bounds.max_defined && b_bounds.min_defined && a_bounds.max < b_bounds.min) {
if (bounds) {
*bounds = a_bounds;
}
return a;
}
if (mod_bounds.min_defined && mod_bounds.max_defined && mod_bounds.min == mod_bounds.max) {
return make_const(op->type, mod_bounds.min);
}
int lanes = op->type.lanes();
auto rewrite = IRMatcher::rewriter(IRMatcher::mod(a, b), op->type);
if (rewrite(c0 % c1, fold(c0 % c1)) ||
rewrite(IRMatcher::Overflow() % x, a) ||
rewrite(x % IRMatcher::Overflow(), b) ||
rewrite(0 % x, 0) ||
rewrite(x % x, 0) ||
rewrite(x % 0, 0) ||
(!op->type.is_float() &&
rewrite(x % 1, 0))) {
return rewrite.result;
}
// clang-format off
if (EVAL_IN_LAMBDA
(rewrite(broadcast(x, c0) % broadcast(y, c0), broadcast(x % y, c0)) ||
(no_overflow_int(op->type) &&
(rewrite((x * c0) % c1, (x * fold(c0 % c1)) % c1, c1 > 0 && (c0 >= c1 || c0 < 0)) ||
rewrite((x + c0) % c1, (x + fold(c0 % c1)) % c1, c1 > 0 && (c0 >= c1 || c0 < 0)) ||
rewrite((x * c0) % c1, (x % fold(c1/c0)) * c0, c0 > 0 && c1 % c0 == 0) ||
rewrite((x * c0 + y) % c1, y % c1, c0 % c1 == 0) ||
rewrite((y + x * c0) % c1, y % c1, c0 % c1 == 0) ||
rewrite((x * c0 - y) % c1, (-y) % c1, c0 % c1 == 0) ||
rewrite((y - x * c0) % c1, y % c1, c0 % c1 == 0) ||
rewrite((x - y) % 2, (x + y) % 2) || // Addition and subtraction are the same modulo 2, because -1 == 1
rewrite(ramp(x, c0, c2) % broadcast(c1, c2), broadcast(x, c2) % broadcast(c1, c2), (c0 % c1 == 0)) ||
rewrite(ramp(x, c0, lanes) % broadcast(c1, lanes), ramp(x % c1, c0, lanes),
// First and last lanes are the same when...
can_prove((x % c1 + c0 * (lanes - 1)) / c1 == 0, this)) ||
rewrite(ramp(x * c0, c2, c3) % broadcast(c1, c3), ramp(x * fold(c0 % c1), fold(c2 % c1), c3) % c1, c1 > 0 && (c0 >= c1 || c0 < 0)) ||
rewrite(ramp(x + c0, c2, c3) % broadcast(c1, c3), ramp(x + fold(c0 % c1), fold(c2 % c1), c3) % c1, c1 > 0 && (c0 >= c1 || c0 < 0)) ||
rewrite(ramp(x * c0 + y, c2, c3) % broadcast(c1, c3), ramp(y, fold(c2 % c1), c3) % c1, c0 % c1 == 0) ||
rewrite(ramp(y + x * c0, c2, c3) % broadcast(c1, c3), ramp(y, fold(c2 % c1), c3) % c1, c0 % c1 == 0))))) {
return mutate(rewrite.result, bounds);
}
// clang-format on
}
if (a.same_as(op->a) && b.same_as(op->b)) {
return op;
} else {
return Mod::make(a, b);
}
}
} // namespace Internal
} // namespace Halide
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

MIT计算机科学和人工智能实验室的研究人员创造出一种专门设计简化图像处理的程序语言Halide,源代码托管在GitHub上,目前二进制程序只支持Mac OS X和Ubuntu 12
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/VisionDeveloper/Halide.git
git@gitee.com:VisionDeveloper/Halide.git
VisionDeveloper
Halide
Halide
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /