📄 sparc.java
字号:
/** subx rs1, rs2, rd */ public int SUBX (String rs1, String rs2, String rd) { return Fmt3 ("10", rd, "001100", rs1, rs2); } /** cmp rs1, imm */ public int CMP (String rs1, int imm) { return SUBcc (rs1, imm, "%g0"); } /** cmp rs1, rs2 */ public int CMP (String rs1, String rs2) { return SUBcc (rs1, rs2, "%g0"); } /** tst rs1 */ public int TST (String rs1) { return CMP (rs1, "%g0"); } /** umul rs1, rs2, rd */ public int UMUL (String rs1, String rs2, String rd) { return Fmt3 ("10", rd, "001010", rs1, rs2); } /** smul rs1, rs2, rd */ public int SMUL (String rs1, String rs2, String rd) { return Fmt3 ("10", rd, "001011", rs1, rs2); } /** rd %y, rd */ public int RDY (String rd) { return Fmt3 ("10", rd, "101000", "%g0", 0); } /** sll rs1, imm, rd */ public int SLL (String rs1, int imm, String rd) { return Fmt3 ("10", rd, "100101", rs1, imm); } /** sll rs1, rs2, rd */ public int SLL (String rs1, String rs2, String rd) { return Fmt3 ("10", rd, "100101", rs1, rs2); } /** srl rs1, rs2, rd */ public int SRL (String rs1, String rs2, String rd) { return Fmt3 ("10", rd, "100110", rs1, rs2); } /** sra rs1, imm, rd */ public int SRA (String rs1, int imm, String rd) { return Fmt3 ("10", rd, "100111", rs1, imm); } /** sra rs1, rs2, rd */ public int SRA (String rs1, String rs2, String rd) { return Fmt3 ("10", rd, "100111", rs1, rs2); } /** sethi %hi(val), rd */ public int SETHI (int val, String rd) { return Fmt2 ("00", rd, "100", (val >>> 10)); } /** nop == sethi 0, %g0 */ public int NOP () { return SETHI (0, "%g0"); } /** or %rd, %lo(val), %rd */ public int SetLo (int val, String rd) { return OR (rd, val & 0x03FF, rd); } /** call disp */ public int CALL (long disp) { /* Sign-extend the shift; may be a negative displacement */ return Fmt1 ("01", ((int) disp) >> 2); } /** unimp ign const22 */ public int UNIMP (int ign, int const22) { return Fmt2 ("00", ign, "000", const22); } /** Bcc disp */ private int Bcc (String annul, String cond, int disp22) { return Fmt2 ("00", annul + cond, "010", disp22); } /** bne label */ public int BNE (int disp) { return Bcc ("0", "1001", disp); } /** be label */ public int BE (int disp) { return Bcc ("0", "0001", disp); } /** ba label */ public int BA (int disp) { return Bcc ("0", "1000", disp); } /** bg label */ public int BG (int disp) { return Bcc ("0", "1010", disp); } /** bl label */ public int BL (int disp) { return Bcc ("0", "0011", disp); } /** bge label */ public int BGE (int disp) { return Bcc ("0", "1011", disp); } /** ble label */ public int BLE (int disp) { return Bcc ("0", "0010", disp); } /** fitos rs2, rd */ public int FiTOs (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "011000100", rs2); } /** fitod rs2, rd */ public int FiTOd (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "011001000", rs2); } /** fstoi rs2, rd */ public int FsTOi (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "011010001", rs2); } /** fstod rs2, rd */ public int FsTOd (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "011001001", rs2); } /** fdtoi rs2, rd */ public int FdTOi (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "011010010", rs2); } /** fdtos rs2, rd */ public int FdTOs (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "011000110", rs2); } /** fmovs rs2, rd */ public int FMOVs (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "000000001", rs2); } /** fnegs rs2, rd */ public int FNEGs (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "000000101", rs2); } /** fabs rs2, rd */ public int FABSs (String rs2, String rd) { return Fmt3FP ("10", rd, "110100", "000001001", rs2); } /** fadds rs1, rs2, rd */ public int FADDs (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001000001", rs2); } /** faddd rs1, rs2, rd */ public int FADDd (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001000010", rs2); } /** fsubs rs1, rs2, rd */ public int FSUBs (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001000101", rs2); } /** fsubd rs1, rs2, rd */ public int FSUBd (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001000110", rs2); } /** fmuls rs1, rs2, rd */ public int FMULs (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001001001", rs2); } /** fmuld rs1, rs2, rd */ public int FMULd (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001001010", rs2); } /** fdivs rs1, rs2, rd */ public int FDIVs (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001001101", rs2); } /** fdivd rs1, rs2, rd */ public int FDIVd (String rs1, String rs2, String rd) { return Fmt3FP ("10", rd, "110100", rs1, "001001110", rs2); } /** fcmps rs1, rs2 */ public int FCMPs (String rs1, String rs2) { return Fmt3FPC ("10", "110101", rs1, "001010001", rs2); } /** fcmpd rs1, rs2 */ public int FCMPd (String rs1, String rs2) { return Fmt3FPC ("10", "110101", rs1, "001010010", rs2); } private int FBcc (String annul, String cond, int disp22) { return Fmt2 ("00", annul + cond, "110", disp22); } /** fbug label */ public int FBUG (int disp) { return FBcc ("0", "0101", disp); } /** fbg label */ public int FBG (int disp) { return FBcc ("0", "0110", disp); } /** fbe label */ public int FBE (int disp) { return FBcc ("0", "1001", disp); } /** NB: Double-word values must be ordered the same in both the * stack and the local variables: i.e., if the high word is in * local i and the low in local i+1, then the high word * must be pushed onto the stack first, followed by the low * word. Otherwise word swapping occurs during parameter passing. * We chose to have the high word in local i and pushed first, with * the low word in local i+1 and pushed second, because that puts * the high and low words into the right position for double-word * SPARC registers. */ /** pull the top word off the evaluation stack into a register * @param reg where value goes * @returns last code generated */ public int popES (String reg) { LD ("%l7", 0, reg); return ADD ("%l7", 4, "%l7"); } /** pull the top double-word off the evaluation stack into a register * @param reg where value goes * @returns last code generated */ public int LpopES (String reg) { int rlen = reg.length(); String lreg = reg.substring(0,rlen-1) + String.valueOf ((char) (1 + reg.charAt(rlen-1))); LD ("%l7", 0, lreg); LD ("%l7", 4, reg); return ADD ("%l7", 8, "%l7"); } /** pull the top word off the evaluation stack into a floating point register * @param reg where value goes * @returns last code generated */ public int FpopES (String reg) { LDF ("%l7", 0, reg); return ADD ("%l7", 4, "%l7"); } /** pull the top double-word float off the evaluation stack into a register * @param reg where value goes * @returns last code generated */ public int DpopES (String reg) { int rlen = reg.length(); String lreg = reg.substring(0,rlen-1) + String.valueOf ((char) (1 + reg.charAt(rlen-1))); LDF ("%l7", 0, lreg); LDF ("%l7", 4, reg); return ADD ("%l7", 8, "%l7"); } /** throw away the top n words of the evaluation stack * @param nw number of words to ditch * @returns code generated */ public int tossES (int na) { return ADD ("%l7", 4 * na, "%l7"); } /** push the value from the given register onto the evaluation stack * @param reg where value comes from * @returns code generated */ public int pushES (String reg) { SUB ("%l7", 4, "%l7"); return ST (reg, "%l7", 0); } /** push the double-word value starting at the given register on to the eval stack * @param reg high-word register of value * @returns last instruction generated */ public int LpushES (String reg) { int rlen = reg.length(); String lreg = reg.substring(0,rlen-1) + String.valueOf ((char) (1 + reg.charAt(rlen-1))); SUB ("%l7", 8, "%l7"); ST (reg, "%l7", 4); return ST (lreg, "%l7", 0); } /** push the value from the given FP register onto the evaluation stack * @param reg where value comes from * @returns code generated */ public int FpushES (String reg) { SUB ("%l7", 4, "%l7"); return STF (reg, "%l7", 0); } /** push the double-word float starting at the given register on to the eval stack * @param reg high-word register of value * @returns last instruction generated */ public int DpushES (String reg) { int rlen = reg.length(); String lreg = reg.substring(0,rlen-1) + String.valueOf ((char) (1 + reg.charAt(rlen-1))); SUB ("%l7", 8, "%l7"); STF (reg, "%l7", 4); return STF (lreg, "%l7", 0); } /** put the value n words down from top of stack into register, without * changing the stack pointer. * @param n how far down to look * @param reg where value should go * @returns code generated */ public int peekES (int n, String reg) { return LD ("%l7", 4 * n, reg); } /** replace the value n words down from top of stack with register, without * changing the stack pointer. * @param n how far down to look * @param reg where new value comes from go * @returns code generated */ public int pokeES (int n, String reg) { return ST (reg, "%l7", 4 * n); } private byte [] int2bytearr (int v) { byte vseq [] = new byte [4]; vseq [0] = (byte) (0xFF & (v >>> 24)); vseq [1] = (byte) (0xFF & (v >>> 16)); vseq [2] = (byte) (0xFF & (v >>> 8)); vseq [3] = (byte) (0xFF & (v >>> 0));/* { StringBuffer sb = new StringBuffer (""); int i; for (i = 0; i < vseq.length; i++) { sb.append ("0x" + Integer.toHexString (vseq [i]) + " "); } System.out.println ("I2BA (" + v + ") -> " + sb); } */ return vseq; } protected byte[] UNIMP (int codeval) { return int2bytearr (UNIMP (0, codeval)); } protected byte[] LOAD_REG (int val, Object oreg) { byte lrseq [] = new byte [8]; String reg = (String) oreg; System.arraycopy (int2bytearr (SETHI (val, reg)), 0, lrseq, 0, 4); System.arraycopy (int2bytearr (SetLo (val, reg)), 0, lrseq, 4, 4);/* { StringBuffer sb = new StringBuffer (""); int i; for (i = 0; i < lrseq.length; i++) { sb.append ("0x" + Integer.toHexString (lrseq [i]) + " "); } System.out.println ("LOAD_REG (" + val + ", " + reg + ") -> " + sb); } */ return lrseq; } protected byte [] RELATIVE_CALL (int offs) { return int2bytearr (CALL (offs)); } protected byte [] RELATIVE_JUMP (int offs) { return int2bytearr (BA (offs >> 2)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -