{"id":5333,"date":"2025-01-26T11:23:37","date_gmt":"2025-01-26T10:23:37","guid":{"rendered":"https:\/\/www.islandwalking.com\/wordpress\/?p=5333"},"modified":"2025-01-26T11:25:01","modified_gmt":"2025-01-26T10:25:01","slug":"llvm-exercise-iii","status":"publish","type":"post","link":"https:\/\/www.islandwalking.com\/wordpress\/llvm-exercise-iii\/","title":{"rendered":"LLVM Exercise III"},"content":{"rendered":"<p>Let us return a larger constant:<\/p>\n<blockquote>\n<pre>int foo() {\r\n    return 0xFF;\r\n}\r\n<\/pre>\n<\/blockquote>\n<p>For numbers up to 12 bits we can use the <code>LDI S&amp;X<\/code> instruction. Some code snippets:<\/p>\n<blockquote>\n<pre>def immSExt12 : PatLeaf&lt;(imm),\r\n                    [{ return isInt&lt;12&gt;(N-&gt;getSExtValue()); }]&gt;;\r\n\r\ndef : Pat&lt;(i32 immSExt12:$in), (LDI imm:$in)&gt;;\r\n\r\ndef LDI : HP41MCODEInst&lt;0x130, (outs RC:$r), (ins i32imm:$sx),\r\n                        \"LDI S&amp;X HEX: $sx\",\r\n                        [(set RC:$r, (i32 immSExt12:$sx))]&gt;;\r\n<\/pre>\n<\/blockquote>\n<p>This produces:<\/p>\n<blockquote>\n<pre>\t.file\t\"hello.c\"\r\n\t.text\r\n\t.globl\tfoo                     ! -- Begin function foo\r\n\t.type\tfoo,@function\r\nfoo:                                    ! @foo\r\n! %bb.0:                                ! %entry\r\n\tLDI S&amp;X HEX: 0FF\r\n\tRTN\r\n.Lfunc_end0:\r\n\t.size\tfoo, .Lfunc_end0-foo\r\n                                        ! -- End function\r\n\t.ident\t\"clang version 20.0.0git (https:\/\/github.com\/llvm\/llvm-project.git ea1dfd50bfdfbd75969fd7653bc71c81f2a2350f)\"\r\n\t.section\t\".note.GNU-stack\"\r\n\t.addrsig\r\n\r\n<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Let us return a larger constant: int foo() { return 0xFF; } For numbers up to 12 bits we can use the LDI S&amp;X instruction. Some code snippets: def immSExt12 : PatLeaf&lt;(imm), [{ return isInt&lt;12&gt;(N-&gt;getSExtValue()); }]&gt;; def : Pat&lt;(i32 immSExt12:$in), (LDI imm:$in)&gt;; def LDI : HP41MCODEInst&lt;0x130, (outs RC:$r), (ins i32imm:$sx), &#8220;LDI S&amp;X HEX: $sx&#8221;, [(set &hellip; <a class=\"read-excerpt\" href=\"https:\/\/www.islandwalking.com\/wordpress\/llvm-exercise-iii\/\">Continue reading <span class=\"meta-nav\">&raquo;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5333","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/posts\/5333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/comments?post=5333"}],"version-history":[{"count":3,"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/posts\/5333\/revisions"}],"predecessor-version":[{"id":5336,"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/posts\/5333\/revisions\/5336"}],"wp:attachment":[{"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.islandwalking.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}