[llvm] r175707 - Mips specific standalone assembler addressing mode %hi and %lo.
Jack Carter
jcarter at mips.com
Wed Feb 20 18:09:32 PST 2013
Author: jacksprat
Date: Wed Feb 20 20:09:31 2013
New Revision: 175707
URL: http://llvm.org/viewvc/llvm-project?rev=175707&view=rev
Log:
Mips specific standalone assembler addressing mode %hi and %lo.
The constructs %hi() and %lo() represent the high and low 16
bits of the address.
Because the 16 bit offset field of an LW instruction is
interpreted as signed, if bit 15 of the low part is 1 then the
low part will act as a negative and 1 needs to be added to the
high part.
Contributer: Vladimir Medic
Added:
llvm/trunk/test/MC/Mips/hilo-addressing.s
Modified:
llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
llvm/trunk/test/MC/Mips/mips_directives.s
Modified: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp?rev=175707&r1=175706&r2=175707&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Wed Feb 20 20:09:31 2013
@@ -888,7 +888,12 @@ bool MipsAsmParser::parseRelocOperand(co
if (Str == "lo") {
Val = Val & 0xffff;
} else if (Str == "hi") {
+ int LoSign = Val & 0x8000;
Val = (Val & 0xffff0000) >> 16;
+ //lower part is treated as signed int, so if it is negative
+ //we must add 1 to hi part to compensate
+ if (LoSign)
+ Val++;
}
Res = MCConstantExpr::Create(Val, getContext());
return false;
Added: llvm/trunk/test/MC/Mips/hilo-addressing.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/hilo-addressing.s?rev=175707&view=auto
==============================================================================
--- llvm/trunk/test/MC/Mips/hilo-addressing.s (added)
+++ llvm/trunk/test/MC/Mips/hilo-addressing.s Wed Feb 20 20:09:31 2013
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -show-encoding -triple mips-unknown-unknown %s | FileCheck %s
+
+ .ent hilo_test
+ .equ addr, 0xdeadbeef
+# CHECK: # encoding: [0x3c,0x04,0xde,0xae]
+ lui $4,%hi(addr)
+# CHECK: # encoding: [0x03,0xe0,0x00,0x08]
+ jr $31
+# CHECK: # encoding: [0x80,0x82,0xbe,0xef]
+ lb $2,%lo(addr)($4)
+ .end hilo_test
Modified: llvm/trunk/test/MC/Mips/mips_directives.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/mips_directives.s?rev=175707&r1=175706&r2=175707&view=diff
==============================================================================
--- llvm/trunk/test/MC/Mips/mips_directives.s (original)
+++ llvm/trunk/test/MC/Mips/mips_directives.s Wed Feb 20 20:09:31 2013
@@ -1,5 +1,5 @@
-# RUN: llvm-mc -triple mips-unknown-unknown %s | FileCheck %s
-#this test produces no output so there isS no FileCheck call
+# RUN: llvm-mc -show-encoding -triple mips-unknown-unknown %s | FileCheck %s
+#
$BB0_2:
.ent directives_test
.frame $sp,0,$ra
@@ -17,4 +17,3 @@ $JTI0_0:
.set macro
.set reorder
.set at=$a0
- .end directives_test
More information about the llvm-commits
mailing list