List of usage examples for java.math BigInteger multiply
BigInteger multiply(long v)
From source file:edu.hku.sdb.rewrite.SdbSchemeRewriter.java
protected Expr rewriteMultiplyEC(Expr leftExpr, Expr rightExpr) throws UnSupportedException { LOG.debug("Rewriting EC mode multiplication"); Expr E;//from ww w .j av a2s.co m Expr C; if (leftExpr instanceof IntLiteral || leftExpr instanceof FloatLiteral) { E = rightExpr; C = leftExpr; } else if (rightExpr instanceof IntLiteral || rightExpr instanceof FloatLiteral) { E = leftExpr; C = rightExpr; } else { throw new UnSupportedException("Unsupported Data Type in EC mode " + "multiplication!"); } // Scale = 0 if it is an integer int scale = 0; BigInteger cValue = null; if (C instanceof IntLiteral) { cValue = BigInteger.valueOf(((IntLiteral) C).getValue()); } // Scale the float data to be an integer. else if (C instanceof FloatLiteral) { float valueF = ((FloatLiteral) C).getValue(); String[] splitter = String.valueOf(valueF).split("\\."); scale = splitter[1].length(); assert (scale >= 1); long valueL = (long) (valueF * Math.pow(10, scale)); cValue = BigInteger.valueOf(valueL); } // For EC multiplication, we only need to multiply the m part of column key BigInteger m = cValue.multiply(E.getSdbColKey().getM()).mod(n); BigInteger x = E.getSdbColKey().getX(); SdbColumnKey colKey = new SdbColumnKey(m, x); Expr resultExpr; if (E instanceof FieldLiteral) { resultExpr = new FieldLiteral((FieldLiteral) E); } else if (E instanceof SdbArithmeticExpr) { resultExpr = new SdbArithmeticExpr((SdbArithmeticExpr) E); } else if (E instanceof SdbKeyUpdateExpr) { resultExpr = new SdbKeyUpdateExpr((SdbKeyUpdateExpr) E); } else { throw new UnSupportedException( "Unsupported Expression " + E.getClass().getCanonicalName() + " in EC mode multiplication!"); } resultExpr.setSdbColKey(colKey); // It will become a Decimal type from now on. if (scale >= 1) { if (((ScalarType) E.getType()).getScale() > 0) resultExpr.setType(ScalarType.createDecimalType(ScalarType.DEFAULT_PRECISION, scale + ((ScalarType) E.getType()).getScale())); else resultExpr.setType(ScalarType.createDecimalType(ScalarType.DEFAULT_PRECISION, scale)); } return resultExpr; }
From source file:com.peterbochs.PeterBochsDebugger.java
private void jRefreshAddressTranslateButtonActionPerformed(ActionEvent evt) { AddressTranslateTableModel model = (AddressTranslateTableModel) this.jAddressTranslateTable2.getModel(); if (jSearchAddressRadioButton1.isSelected()) { if (!this.jAddressTextField.getText().contains(":") || this.jAddressTextField.getText().replaceAll("[^:]", "").length() != 1) { JOptionPane.showMessageDialog(this, "Error, please input <segment selector>:<offset>\n\ne.g. : 0x10:0x12345678", "Error", JOptionPane.ERROR_MESSAGE); return; }//w w w.ja v a 2 s . c o m BigInteger segSelector = CommonLib.string2BigInteger(this.jAddressTextField.getText().split(":")[0]); BigInteger address = CommonLib.string2BigInteger(this.jAddressTextField.getText().split(":")[1]); // for (int x = 0; x < model.getRowCount(); x++) { // if (model.searchType.get(x).equals(1) && // model.searchSegSelector.get(x).equals(segSelector) && // model.searchAddress.get(x).equals(address)) { // return; // } // } model.searchType.add(1); model.searchSegSelector.add(segSelector); model.searchAddress.add(address); model.virtualAddress.add(address); BigInteger segNo = segSelector.shiftRight(3); model.segNo.add(segNo); // read GDT descriptor int descriptor[] = PeterBochsCommonLib .getMemoryFromBochs(CommonLib.string2BigInteger(this.registerPanel.jGDTRTextField.getText()) .add(segNo.multiply(BigInteger.valueOf(8))), 8); BigInteger baseAddress = CommonLib.getBigInteger(descriptor[2], descriptor[3], descriptor[4], descriptor[7], 0, 0, 0, 0); BigInteger linearAddress = baseAddress.add(address); model.baseAddress.add(baseAddress); model.linearAddress.add(linearAddress); BigInteger pdNo = CommonLib.getBigInteger(linearAddress, 31, 22); model.pdNo.add(pdNo); int pdeBytes[] = PeterBochsCommonLib .getMemoryFromBochs(CommonLib.string2BigInteger(this.registerPanel.jCR3TextField.getText()) .add(pdNo.multiply(BigInteger.valueOf(4))), 4); BigInteger pde = CommonLib.getBigInteger(pdeBytes, 0); model.pde.add(pde); BigInteger ptNo = CommonLib.getBigInteger(linearAddress, 21, 12); model.ptNo.add(ptNo); BigInteger pageTableBaseAddress = pde.and(CommonLib.string2BigInteger("0xfffff000")); int pteBytes[] = PeterBochsCommonLib .getMemoryFromBochs(pageTableBaseAddress.add(ptNo.multiply(BigInteger.valueOf(4))), 4); BigInteger pte = CommonLib.getBigInteger(pteBytes, 0); BigInteger pagePhysicalAddress = pte.and(CommonLib.string2BigInteger("0xfffff000")); model.pte.add(pte); BigInteger physicalAddress = pagePhysicalAddress.add(CommonLib.getBigInteger(linearAddress, 11, 0)); model.physicalAddress.add(physicalAddress); int bytesAtPhysicalAddress[] = PeterBochsCommonLib.getMemoryFromBochs(physicalAddress, 8); model.bytes.add(PeterBochsCommonLib.convertToString(bytesAtPhysicalAddress)); model.fireTableDataChanged(); } else if (jSearchAddressRadioButton2.isSelected()) { // for (int x = 0; x < model.getRowCount(); x++) { // if (model.searchType.get(x).equals(2) && // model.searchAddress.get(x).equals(CommonLib.string2long(this.jAddressTextField.getText()))) // { // return; // } // } BigInteger address = CommonLib.string2BigInteger(this.jAddressTextField.getText()); model.searchType.add(2); model.searchAddress.add(address); BigInteger baseAddress = BigInteger.ZERO; BigInteger linearAddress = baseAddress.add(address); model.baseAddress.add(baseAddress); model.linearAddress.add(linearAddress); BigInteger pdNo = CommonLib.getBigInteger(linearAddress, 31, 22); model.pdNo.add(pdNo); int pdeBytes[] = PeterBochsCommonLib .getMemoryFromBochs(CommonLib.string2BigInteger(this.registerPanel.jCR3TextField.getText()) .add(pdNo.multiply(BigInteger.valueOf(4))), 4); BigInteger pde = CommonLib.getBigInteger(pdeBytes, 0); model.pde.add(pde); BigInteger ptNo = CommonLib.getBigInteger(linearAddress, 21, 12); model.ptNo.add(ptNo); BigInteger pageTableBaseAddress = pde.and(CommonLib.string2BigInteger("0xfffff000")); int pteBytes[] = PeterBochsCommonLib .getMemoryFromBochs(pageTableBaseAddress.add(ptNo.multiply(BigInteger.valueOf(4))), 4); BigInteger pte = CommonLib.getBigInteger(pteBytes, 0); BigInteger pagePhysicalAddress = pte.and(CommonLib.string2BigInteger("0xfffff000")); model.pte.add(pte); BigInteger physicalAddress = pagePhysicalAddress.add(CommonLib.getBigInteger(linearAddress, 11, 0)); model.physicalAddress.add(physicalAddress); int bytesAtPhysicalAddress[] = PeterBochsCommonLib.getMemoryFromBochs(physicalAddress, 8); model.bytes.add(PeterBochsCommonLib.convertToString(bytesAtPhysicalAddress)); model.fireTableDataChanged(); } else if (jSearchAddressRadioButton3.isSelected()) { for (int x = 0; x < model.getRowCount(); x++) { if (model.searchType.get(x).equals(3) && model.searchAddress.get(x) .equals(CommonLib.string2long(this.jAddressTextField.getText()))) { return; } } BigInteger addr = CommonLib.string2BigInteger(this.jAddressTextField.getText()); model.searchType.add(3); model.searchSegSelector.add(BigInteger.ZERO); model.searchAddress.add(addr); model.virtualAddress.add(BigInteger.ZERO); model.segNo.add(BigInteger.ZERO); model.linearAddress.add(BigInteger.ZERO); model.pdNo.add(BigInteger.ZERO); model.ptNo.add(BigInteger.ZERO); model.physicalAddress.add(BigInteger.ZERO); model.bytes.add(""); model.fireTableDataChanged(); } }