当前位置: 首页 > news >正文

CANN/pto-isa标量算术操作

标量算术操作

【免费下载链接】pto-isaParallel Tile Operation (PTO) is a virtual instruction set architecture designed by Ascend CANN, focusing on tile-level operations. This repository offers high-performance, cross-platform tile operations across Ascend platforms.项目地址: https://gitcode.com/cann/pto-isa

本文档描述来自 MLIRarith方言的标量算术操作。

重要:PTO AS 仅支持 arith 方言的标量操作。不支持向量和张量操作。

操作总数:47

注意:操作arith.scaling_extfarith.scaling_truncf未包含在内,因为它们在 PTO AS 中不受支持。


整数算术操作

arith.addi - 整数加法

描述:整数加法,可选溢出标志。

语法:

%result = arith.addi %lhs, %rhs : i32 %result = arith.addi %lhs, %rhs overflow<nsw, nuw> : i32

示例:

// 标量加法 %a = arith.addi %b, %c : i64

arith.subi - 整数减法

语法:

%result = arith.subi %lhs, %rhs : i32

示例:

// 标量减法 %a = arith.subi %b, %c : i32

arith.muli - 整数乘法

语法:

%result = arith.muli %lhs, %rhs : i32

示例:

// 标量乘法 %a = arith.muli %b, %c : i64

arith.divsi - 有符号整数除法

描述:有符号整数除法,向零舍入。

语法:

%result = arith.divsi %lhs, %rhs : i32

示例:

// 标量有符号除法 %a = arith.divsi %b, %c : i32

arith.divui - 无符号整数除法

语法:

%result = arith.divui %lhs, %rhs : i32

示例:

// 标量无符号除法 %a = arith.divui %b, %c : i32

arith.remsi - 有符号整数取余

语法:

%result = arith.remsi %lhs, %rhs : i32

示例:

// 标量有符号取余 %a = arith.remsi %b, %c : i32

arith.remui - 无符号整数取余

语法:

%result = arith.remui %lhs, %rhs : i32

示例:

// 标量无符号取余 %a = arith.remui %b, %c : i32

arith.ceildivsi - 向上取整除法(有符号)

描述:有符号整数除法,向正无穷舍入。

语法:

%result = arith.ceildivsi %lhs, %rhs : i32

示例:

// 标量向上取整除法 %a = arith.ceildivsi %b, %c : i32

arith.ceildivui - 向上取整除法(无符号)

语法:

%result = arith.ceildivui %lhs, %rhs : i32

示例:

// 标量向上取整除法(无符号) %a = arith.ceildivui %b, %c : i32

arith.floordivsi - 向下取整除法(有符号)

描述:有符号整数除法,向负无穷舍入。

语法:

%result = arith.floordivsi %lhs, %rhs : i32

示例:

// 标量向下取整除法 %a = arith.floordivsi %b, %c : i32

浮点算术操作

arith.addf - 浮点加法

语法:

%result = arith.addf %lhs, %rhs : f32 %result = arith.addf %lhs, %rhs fastmath<fast> : f32

示例:

// 标量加法 %a = arith.addf %b, %c : f64

arith.subf - 浮点减法

语法:

%result = arith.subf %lhs, %rhs : f32

示例:

// 标量减法 %a = arith.subf %b, %c : f32

arith.mulf - 浮点乘法

语法:

%result = arith.mulf %lhs, %rhs : f32

示例:

// 标量乘法 %a = arith.mulf %b, %c : f64

arith.divf - 浮点除法

语法:

%result = arith.divf %lhs, %rhs : f32

示例:

// 标量除法 %a = arith.divf %b, %c : f32

arith.remf - 浮点取余

语法:

%result = arith.remf %lhs, %rhs : f32

示例:

// 标量取余 %a = arith.remf %b, %c : f64

arith.negf - 浮点取负

语法:

%result = arith.negf %operand : f32

示例:

// 标量取负 %a = arith.negf %b : f32

位运算操作

arith.andi - 按位与

语法:

%result = arith.andi %lhs, %rhs : i32

示例:

// 标量按位与 %a = arith.andi %b, %c : i32

arith.ori - 按位或

语法:

%result = arith.ori %lhs, %rhs : i32

示例:

// 标量按位或 %a = arith.ori %b, %c : i64

arith.xori - 按位异或

语法:

%result = arith.xori %lhs, %rhs : i32

示例:

// 标量按位异或 %a = arith.xori %b, %c : i32

移位操作

arith.shli - 左移

语法:

%result = arith.shli %lhs, %rhs : i32

示例:

// 标量左移 %a = arith.shli %b, %c : i32

arith.shrsi - 算术右移(有符号)

描述:算术右移(符号扩展)。

语法:

%result = arith.shrsi %lhs, %rhs : i32

示例:

// 标量算术右移 %a = arith.shrsi %b, %c : i32

arith.shrui - 逻辑右移(无符号)

描述:逻辑右移(零扩展)。

语法:

%result = arith.shrui %lhs, %rhs : i32

示例:

// 标量逻辑右移 %a = arith.shrui %b, %c : i32

比较操作

arith.cmpi - 整数比较

描述:使用指定谓词比较两个整数。

语法:

%result = arith.cmpi <predicate>, %lhs, %rhs : i32

谓词:

  • 有符号:sltslesgtsge
  • 无符号:ultuleugtuge
  • 相等性:eqne

示例:

// 标量比较 %cmp = arith.cmpi slt, %a, %b : i32 %eq = arith.cmpi eq, %x, %y : i64

arith.cmpf - 浮点比较

描述:使用指定谓词比较两个浮点数。

语法:

%result = arith.cmpf <predicate>, %lhs, %rhs : f32

谓词:

  • 有序:oeqoneoltoleogtogeord
  • 无序:uequneultuleugtugeuno
  • 总是:truefalse

示例:

// 标量比较 %cmp = arith.cmpf olt, %a, %b : f32 %eq = arith.cmpf oeq, %x, %y : f64

最小/最大操作

arith.minsi - 最小值(有符号整数)

语法:

%result = arith.minsi %lhs, %rhs : i32

示例:

// 标量最小值 %min = arith.minsi %a, %b : i32

arith.minui - 最小值(无符号整数)

语法:

%result = arith.minui %lhs, %rhs : i32

示例:

// 标量最小值(无符号) %min = arith.minui %a, %b : i32

arith.maxsi - 最大值(有符号整数)

语法:

%result = arith.maxsi %lhs, %rhs : i32

示例:

// 标量最大值 %max = arith.maxsi %a, %b : i32

arith.maxui - 最大值(无符号整数)

语法:

%result = arith.maxui %lhs, %rhs : i32

示例:

// 标量最大值(无符号) %max = arith.maxui %a, %b : i32

arith.minimumf - 最小值(浮点,传播 NaN)

语法:

%result = arith.minimumf %lhs, %rhs : f32

示例:

// 标量最小值(传播 NaN) %min = arith.minimumf %a, %b : f32

arith.maximumf - 最大值(浮点,传播 NaN)

语法:

%result = arith.maximumf %lhs, %rhs : f32

示例:

// 标量最大值(传播 NaN) %max = arith.maximumf %a, %b : f32

arith.minnumf - 最小值(浮点,忽略 NaN)

语法:

%result = arith.minnumf %lhs, %rhs : f32

示例:

// 标量最小值(忽略 NaN) %min = arith.minnumf %a, %b : f64

arith.maxnumf - 最大值(浮点,忽略 NaN)

语法:

%result = arith.maxnumf %lhs, %rhs : f32

示例:

// 标量最大值(忽略 NaN) %max = arith.maxnumf %a, %b : f64

类型转换操作

arith.extsi - 符号扩展

描述:将整数符号扩展到更宽的类型。

语法:

%result = arith.extsi %in : i32 to i64

示例:

// 标量符号扩展 %wide = arith.extsi %narrow : i32 to i64

arith.extui - 零扩展

描述:将整数零扩展到更宽的类型。

语法:

%result = arith.extui %in : i32 to i64

示例:

// 标量零扩展 %wide = arith.extui %narrow : i32 to i64

arith.trunci - 截断整数

描述:将整数截断到更窄的类型。

语法:

%result = arith.trunci %in : i64 to i32

示例:

// 标量截断 %narrow = arith.trunci %wide : i64 to i32

arith.extf - 扩展浮点

描述:将浮点数扩展到更宽的类型。

语法:

%result = arith.extf %in : f32 to f64

示例:

// 标量浮点扩展 %double = arith.extf %single : f32 to f64

arith.truncf - 截断浮点

描述:将浮点数截断到更窄的类型。

语法:

%result = arith.truncf %in : f64 to f32

示例:

// 标量浮点截断 %single = arith.truncf %double : f64 to f32

arith.sitofp - 有符号整数转浮点

语法:

%result = arith.sitofp %in : i32 to f32

示例:

// 标量整数转浮点 %fp = arith.sitofp %int : i32 to f32

arith.uitofp - 无符号整数转浮点

语法:

%result = arith.uitofp %in : i32 to f32

示例:

// 标量无符号整数转浮点 %fp = arith.uitofp %uint : i32 to f32

arith.fptosi - 浮点转有符号整数

描述:将浮点数转换为有符号整数(向零舍入)。

语法:

%result = arith.fptosi %in : f32 to i32

示例:

// 标量浮点转整数 %int = arith.fptosi %fp : f32 to i32

arith.fptoui - 浮点转无符号整数

语法:

%result = arith.fptoui %in : f32 to i32

示例:

// 标量浮点转无符号整数 %uint = arith.fptoui %fp : f32 to i32

arith.bitcast - 位转换

描述:将位重新解释为不同类型(相同位宽)。

语法:

%result = arith.bitcast %in : f32 to i32

示例:

// 标量位转换 %bits = arith.bitcast %fp : f32 to i32

arith.index_cast - 索引转换(有符号)

描述:index类型和整数类型之间转换(符号扩展)。

语法:

%result = arith.index_cast %in : i32 to index %result = arith.index_cast %in : index to i64

示例:

// 标量索引转换 %idx = arith.index_cast %int : i32 to index %int = arith.index_cast %idx : index to i64

arith.index_castui - 索引转换(无符号)

描述:index类型和整数类型之间转换(零扩展)。

语法:

%result = arith.index_castui %in : i32 to index

示例:

// 标量索引转换(无符号) %idx = arith.index_castui %uint : i32 to index

特殊操作

arith.select - 条件选择

语法:

%result = arith.select %condition, %true_value, %false_value : i32

示例:

// 标量选择 %result = arith.select %cond, %a, %b : i32 %fp_result = arith.select %cond, %x, %y : f32

arith.constant - 常量值

语法:

%result = arith.constant <value> : <type>

示例:

// 标量常量 %c0 = arith.constant 0 : i32 %c1 = arith.constant 1 : i64 %pi = arith.constant 3.14159 : f32 %true = arith.constant true

扩展算术操作

arith.addui_extended - 扩展无符号加法

描述:带溢出标志的无符号加法。

语法:

%sum, %overflow = arith.addui_extended %lhs, %rhs : i32, i1

示例:

// 标量扩展加法 %sum, %overflow = arith.addui_extended %a, %b : i32, i1

arith.mulsi_extended - 扩展有符号乘法

描述:有符号乘法,返回低位和高位。

语法:

%low, %high = arith.mulsi_extended %lhs, %rhs : i32

示例:

// 标量扩展乘法 %low, %high = arith.mulsi_extended %a, %b : i32

arith.mului_extended - 扩展无符号乘法

语法:

%low, %high = arith.mului_extended %lhs, %rhs : i32

示例:

// 标量扩展乘法(无符号) %low, %high = arith.mului_extended %a, %b : i32

【免费下载链接】pto-isaParallel Tile Operation (PTO) is a virtual instruction set architecture designed by Ascend CANN, focusing on tile-level operations. This repository offers high-performance, cross-platform tile operations across Ascend platforms.项目地址: https://gitcode.com/cann/pto-isa

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

http://www.jsqmd.com/news/783707/

相关文章:

  • 从C语言到机器码:用RV32I指令集手写一个简单的加法函数(附完整汇编代码)
  • 2026年原创视频素材平台清单:个人、企业和专业团队适用 - Fzzf_23
  • DAO治理自动化引擎:tomorrowDAO-skill架构解析与安全实践
  • CANN ops-math安全声明
  • 2026年罐用清洗球品牌推荐排行榜:旋转式、固定式、喷洒形、扇形清洗球优质之选! - 速递信息
  • 保姆级教程:用Python+Flask快速搭建一个边云协同推理的Demo(附代码)
  • CANN Exp算子API描述
  • 2026届学术党必备的降AI率工具横评
  • 山东汇鑫利商贸:南京不锈钢材料哪家专业 - LYL仔仔
  • CANN技能并行层替换代码示例
  • CANN/torchtitan-npu MTP特性
  • 深圳市鸿鑫隆再生资源回收有限公司|深圳全域再生资源回收服务商 - 新闻快传
  • AI公平性评估:从量化指标到标准化认证的实践指南
  • U-Mail自建邮箱服务器方案 - U-Mail邮件系统
  • 2026国内铸铝门厂家实战盘点:行业靠谱机构TOP排名 - 企业品牌优选推荐官
  • 终极网盘直链下载助手:一键解锁9大云盘高速下载,告别限速烦恼
  • CANN/hcomm 端点描述获取
  • 2026最新公关公司/整合营销服务商/品牌传播公司推荐!国内优质权威榜单发布,专业靠谱实力突出 - 博客万
  • SAP ABAP开发避坑:WS_DELIVERY_UPDATE函数调用时,COMMIT和NO_MESSAGES_UPDATE参数到底怎么设?
  • 深圳再生资源回收服务商|鸿鑫隆|工厂废铁批量回收|30 分钟上门 - 新闻快传
  • 2026年广州格兰富泵类代理商推荐:潜污泵、深井泵、隔膜泵、密封泵、多级管道泵优质之选 - 速递信息
  • 2026年北京消防排烟风机与工业通风源头厂家深度选型指南 - 优质企业观察收录
  • Ray LLM API演进:一站式部署与数据处理工具链解析
  • Python字符串搜索替换的语义陷阱与工程决策树
  • 2026年合肥杀虫公司TOP5测评 优选合肥虫克星 - 资讯焦点
  • 2026 年 5 月网络地板厂家权威排行榜 TOP6(专业数据版) - 小艾信息发布
  • 单北斗变形监测应用在GNSS位移监测中的创新与实践
  • 支付宝红包套装回收攻略 - 抖抖收
  • 命令行AI绘画工具nanobanana:用Gemini API提升开发效率
  • 别再只盯着告警了:从Pikachu靶场搭建看SRE可观测性的实战落地(含日志与调用链配置)