[PATCH] D84054: [lld][ELF] Add LOG2CEIL builtin ldscript function

Isaac Richter via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 08:55:43 PDT 2020


irichter updated this revision to Diff 280150.
irichter set the repository for this revision to rG LLVM Github Monorepo.
irichter added a comment.
Herald added a subscriber: llvm-commits.

Added comment to source noting that LOG2CEIL(0) returns 0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84054/new/

https://reviews.llvm.org/D84054

Files:
  lld/ELF/ScriptParser.cpp
  lld/test/ELF/linkerscript/operators.test


Index: lld/test/ELF/linkerscript/operators.test
===================================================================
--- lld/test/ELF/linkerscript/operators.test
+++ lld/test/ELF/linkerscript/operators.test
@@ -38,6 +38,14 @@
   minus_abs = _end - _start;
   max = MAX(11, 22);
   min = MIN(11, 22);
+  log2ceil0 = LOG2CEIL(0);
+  log2ceil1 = LOG2CEIL(1);
+  log2ceil2 = LOG2CEIL(2);
+  log2ceil3 = LOG2CEIL(3);
+  log2ceil4 = LOG2CEIL(4);
+  log2ceil0ff = LOG2CEIL(0x0ff);
+  log2ceil100 = LOG2CEIL(0x100);
+  log2ceil1ff = LOG2CEIL(0x1ff);
   logicaland1 = 0 && 0;
   logicaland2 = 0 && 1;
   logicaland3 = 1 && 0;
@@ -78,6 +86,14 @@
 # CHECK-NEXT: 0000000000fff0 A minus_abs
 # CHECK-NEXT: 00000000000016 A max
 # CHECK-NEXT: 0000000000000b A min
+# CHECK-NEXT: 0000000000000000 A log2ceil0
+# CHECK-NEXT: 0000000000000000 A log2ceil1
+# CHECK-NEXT: 0000000000000001 A log2ceil2
+# CHECK-NEXT: 0000000000000002 A log2ceil3
+# CHECK-NEXT: 0000000000000002 A log2ceil4
+# CHECK-NEXT: 0000000000000008 A log2ceil0ff
+# CHECK-NEXT: 0000000000000008 A log2ceil100
+# CHECK-NEXT: 0000000000000009 A log2ceil1ff
 # CHECK-NEXT: 00000000000000 A logicaland1
 # CHECK-NEXT: 00000000000000 A logicaland2
 # CHECK-NEXT: 00000000000000 A logicaland3
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -1329,6 +1329,15 @@
       return cmd->getLMA();
     };
   }
+  if (tok == "LOG2CEIL") {
+    expect("(");
+    Expr a = readExpr();
+    expect(")");
+    return [=] {
+      /* LOG2CEIL(0) is defined to be 0 */
+      return std::ceil(std::log2(std::max(a().getValue(), 1UL)));
+    };
+  }
   if (tok == "MAX" || tok == "MIN") {
     expect("(");
     Expr a = readExpr();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84054.280150.patch
Type: text/x-patch
Size: 1777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200723/1e656edc/attachment.bin>


More information about the llvm-commits mailing list