/// <summary> /// Compute the product of this matrix and the given column vector /// </summary> /// /// <param name="V">The vector over GF(2)</param> /// /// <returns>Returns <c>this*vector</c></returns> public override Vector RightMultiply(Vector V) { if (!(V is GF2Vector)) { throw new ArithmeticException("GF2Matrix: Vector is not defined over GF(2)!"); } if (V.Length != ColumnCount) { throw new ArithmeticException("GF2Matrix: Length mismatch!"); } int[] v = ((GF2Vector)V).VectorArray; int[] res = new int[IntUtils.URShift((RowCount + 31), 5)]; for (int i = 0; i < RowCount; i++) { // compute full word scalar products int help = 0; for (int j = 0; j < m_length; j++) { help ^= m_matrix[i][j] & v[j]; } // compute single word scalar product int bitValue = 0; for (int j = 0; j < 32; j++) { bitValue ^= (IntUtils.URShift(help, j)) & 1; } // set result bit if (bitValue == 1) { res[IntUtils.URShift(i, 5)] |= 1 << (i & 0x1f); } } return(new GF2Vector(res, RowCount)); }
public List <EntLog> ObterTodos(String Log, Int32 IdUsuario, Int32 TipoLog, DateTime DateInicio, DateTime DateFim, DbTransaction transaction, Database db) { DbCommand dbCommand = db.GetStoredProcCommand("STP_LogSelecionarTodos"); db.AddInParameter(dbCommand, "@Log", DbType.String, Log); db.AddInParameter(dbCommand, "@IdUsuario", DbType.Int32, IntUtils.ToIntNullProc(IdUsuario)); db.AddInParameter(dbCommand, "@TipoLog", DbType.Int32, IntUtils.ToIntNullProc(TipoLog)); db.AddInParameter(dbCommand, "@DateInicio", DbType.DateTime, DateInicio); db.AddInParameter(dbCommand, "@DateFim", DbType.DateTime, DateFim); dbCommand.CommandTimeout = BdConfig.CommmandTimeout; using (DbDataReader dtrDados = (System.Data.Common.DbDataReader)db.ExecuteReader(dbCommand, transaction)) { if (dtrDados != null && dtrDados.HasRows) { return(this.Popular(dtrDados)); } else { return(new List <EntLog>()); } } }
//must be under lock //tries to allocate the payload size in this segment ant put payload bytes in. // returns -1 when could not find spot. does not do crawl public int Allocate(byte[] payloadBuffer, int serializedSize, int allocPayloadSize, byte serVer, bool isLink) { allocPayloadSize = IntUtils.Align8(allocPayloadSize); var allocSize = allocPayloadSize + CHUNK_HDER_SZ; var fcs = Pile.FreeChunkSizes; //Larger than the largest tracked free chunk if (allocSize > fcs[fcs.Length - 1]) { var address = scanForFreeLarge(allocPayloadSize); if (address < 0) { return(-1);//no space in this segment to fit large payload } allocChunk(address, payloadBuffer, serializedSize, allocPayloadSize, serVer, isLink); return(address); } //else try to get a chunk from size-bucketed list for (var i = 0; i < fcs.Length; i++) { if (allocSize <= fcs[i]) { var freeList = FreeChunks[i]; if (freeList.CurrentIndex >= 0)//slot found { var address = freeList.Addresses[freeList.CurrentIndex]; freeList.CurrentIndex--; allocChunk(address, payloadBuffer, serializedSize, allocPayloadSize, serVer, isLink); return(address); } //slot found } //<fcs } return(-1); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.PopulaTurma(this.Page.Title.ToString()); this.DrpDwnLstEscritorioRegional.Visible = EscritorioRegional; this.DrpDwnLstRegiao.Visible = Regiao; this.DrpDwnLstBairro.Visible = Bairro; this.DrpDwnLstGrupo.Visible = Grupo; this.DrpDwnLstTurma.TabIndex = TabIndex++; this.DrpDwnLstEstado.TabIndex = IntUtils.ToInt16(TabIndex++); this.DrpDwnLstEscritorioRegional.TabIndex = IntUtils.ToInt16(EscritorioRegional ? TabIndex++ : 99); this.DrpDwnLstRegiao.TabIndex = IntUtils.ToInt16(Regiao ? TabIndex++ : 99); this.DrpDwnLstCidade.TabIndex = IntUtils.ToInt16(TabIndex++); this.DrpDwnLstBairro.TabIndex = IntUtils.ToInt16(Bairro ? TabIndex++ : 99); this.DrpDwnLstGrupo.TabIndex = IntUtils.ToInt16(Grupo ? TabIndex++ : 99); this.Obrigatoriedade(); } // this.tdDdlEstado.Width = "100";// DoubleUtils.ToString(this.WidthCampo); }
/// <summary> /// Retorna uma lista de entidade de Escritório Regional /// </summary> /// <autor>Fabio Senziani</autor> /// <param name="transaction">Transaction</param> /// <param name="db">DataBase</param> /// <returns><list type="EntEscritorioRegional">Lista de EntEscritorioRegional</list></returns> public List <EntEscritorioRegional> ObterAtivosPorFiltro(EntEscritorioRegional objEscritorioRegional, Int32 IdUsuario, DbTransaction transaction, Database db) { DbCommand dbCommand = db.GetStoredProcCommand("STP_SelecionaEscritorioRegionalAtivoPorFiltro"); db.AddInParameter(dbCommand, "@sTX_ESCRITORIO_REGIONAL", DbType.String, objEscritorioRegional.EscritorioRegional); db.AddInParameter(dbCommand, "@nCEA_ESTADO", DbType.Int32, IntUtils.ToIntNull(objEscritorioRegional.Estado.IdEstado)); db.AddInParameter(dbCommand, "@nCEA_TURMA", DbType.Int32, objEscritorioRegional.Turma.IdTurma); db.AddInParameter(dbCommand, "@nCEA_PROGRAMA", DbType.Int32, objEscritorioRegional.Turma.Programa.IdPrograma); db.AddInParameter(dbCommand, "@FL_ATIVO", DbType.Boolean, objEscritorioRegional.Ativo); db.AddInParameter(dbCommand, "@nCEA_USUARIO", DbType.Int32, IdUsuario); dbCommand.CommandTimeout = BdConfig.CommmandTimeout; using (DbDataReader dtrDados = (System.Data.Common.DbDataReader)db.ExecuteReader(dbCommand, transaction)) { if (dtrDados != null && dtrDados.HasRows) { return(this.Popular(dtrDados)); } else { return(new List <EntEscritorioRegional>()); } } }
private void PopulaStatus() { ddlStatus.Items.Clear(); ListItem item; //Insere Item Inscritas item = new ListItem(); item.Text = EnumType.Status.Inscrita.ToString(); item.Value = IntUtils.ToString((int)EnumType.Status.Inscrita); ddlStatus.Items.Add(item); //Insere Item Candidata item = new ListItem(); item.Text = EnumType.Status.Candidata.ToString(); item.Value = IntUtils.ToString((int)EnumType.Status.Candidata); ddlStatus.Items.Add(item); //Insere Item Classificada item = new ListItem(); item.Text = EnumType.Status.Classificada.ToString(); item.Value = IntUtils.ToString((int)EnumType.Status.Classificada); ddlStatus.Items.Add(item); //Insere Item Finalista item = new ListItem(); item.Text = EnumType.Status.Finalista.ToString(); item.Value = IntUtils.ToString((int)EnumType.Status.Finalista); ddlStatus.Items.Add(item); //Insere Item Vazio item = new ListItem(); item.Text = "Todos"; item.Value = "0"; item.Selected = true; ddlStatus.Items.Add(item); }
//@Override public override int GetHashCode() { int prime = 31; int result = 1; result = prime * result + B; result = prime * result + N; result = prime * result + ((basisType == null) ? 0 : basisType.GetHashCode()); long temp; temp = IntUtils.floatToIntBits(beta); result = prime * result + (int)(temp ^ (IntUtils.URShift(temp, 32))); temp = IntUtils.floatToIntBits(betaSq); result = prime * result + (int)(temp ^ (IntUtils.URShift(temp, 32))); result = prime * result + bitsF; result = prime * result + d; result = prime * result + d1; result = prime * result + d2; result = prime * result + d3; result = prime * result + ((hashAlg == null) ? 0 : hashAlg.GetHashCode()); result = prime * result + ((keyGenAlg == null) ? 0 : keyGenAlg.GetHashCode()); temp = IntUtils.floatToIntBits(keyNormBound); result = prime * result + (int)(temp ^ (IntUtils.URShift(temp, 32))); temp = IntUtils.floatToIntBits(keyNormBoundSq); result = prime * result + (int)(temp ^ (IntUtils.URShift(temp, 32))); temp = IntUtils.floatToIntBits(normBound); result = prime * result + (int)(temp ^ (IntUtils.URShift(temp, 32))); temp = IntUtils.floatToIntBits(normBoundSq); result = prime * result + (int)(temp ^ (IntUtils.URShift(temp, 32))); result = prime * result + ((polyType == null) ? 0 : polyType.GetHashCode()); result = prime * result + (primeCheck ? 1231 : 1237); result = prime * result + q; result = prime * result + signFailTolerance; result = prime * result + (sparse ? 1231 : 1237); return(result); }
/// <summary> /// Cyclicly shifts a number to the right modulo 2^2^n+1 and returns the result in a new array. /// <para>"Right" means towards the lower array indices and the lower bits; this is equivalent to /// a multiplication by <c>2^(-numBits) modulo 2^2^n+1</c>. The number n is <c>a.Length*32/2</c>; /// in other words, n is half the number of bits in <c>A</c>. /// Both input values are given as <c>int</c> arrays; they must be the same length. /// </para> /// </summary> /// /// <param name="A">A number in base 2^32 starting with the lowest digit; the length must be a power of 2</param> /// <param name="NumBits">The shift amount in bits</param> /// /// <returns>The shifted number</returns> public static int[] CyclicShiftRight(int[] A, int NumBits) { int[] b = new int[A.Length]; int numElements = NumBits / 32; Array.Copy(A, numElements, b, 0, A.Length - numElements); Array.Copy(A, 0, b, A.Length - numElements, numElements); NumBits = NumBits % 32; if (NumBits != 0) { int b0 = b[0]; b[0] = IntUtils.URShift(b[0], NumBits); for (int i = 1; i < b.Length; i++) { b[i - 1] |= b[i] << (32 - NumBits); b[i] = IntUtils.URShift(b[i], NumBits); } b[b.Length - 1] |= b0 << (32 - NumBits); } return(b); }
private static int Create(ServiceCtx context) { long inputPosition = context.Request.GetBufferType0x21().Position; long outputPosition = context.Request.GetBufferType0x22().Position; NvMapCreate args = MemoryHelper.Read <NvMapCreate>(context.Memory, inputPosition); if (args.Size == 0) { Logger.PrintWarning(LogClass.ServiceNv, $"Invalid size 0x{args.Size:x8}!"); return(NvResult.InvalidInput); } int size = IntUtils.AlignUp(args.Size, NvGpuVmm.PageSize); args.Handle = AddNvMap(context, new NvMapHandle(size)); Logger.PrintInfo(LogClass.ServiceNv, $"Created map {args.Handle} with size 0x{size:x8}!"); MemoryHelper.Write(context.Memory, outputPosition, args); return(NvResult.Success); }
private static int Create(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvMapCreate Args = AMemoryHelper.Read <NvMapCreate>(Context.Memory, InputPosition); if (Args.Size == 0) { Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid size 0x{Args.Size:x8}!"); return(NvResult.InvalidInput); } int Size = IntUtils.AlignUp(Args.Size, NvGpuVmm.PageSize); Args.Handle = AddNvMap(Context, new NvMapHandle(Size)); Context.Ns.Log.PrintInfo(LogClass.ServiceNv, $"Created map {Args.Handle} with size 0x{Size:x8}!"); AMemoryHelper.Write(Context.Memory, OutputPosition, Args); return(NvResult.Success); }
/// <summary> /// Constructs a new index generator /// </summary> /// /// <param name="Seed">A seed of arbitrary length to initialize the index generator</param> /// <param name="EncParam">NtruEncrypt parameters</param> public IndexGenerator(byte[] Seed, NTRUParameters EncParam) { _N = EncParam.N; _C = EncParam.CBits; int minCallsR = EncParam.MinIGFHashCalls; _digestEngine = GetDigest(EncParam.Digest); _hashLen = _digestEngine.DigestSize; _Z = Seed; _callCounter = 0; _bitBuffer = new BitString(); while (_callCounter < minCallsR) { byte[] data = new byte[_Z.Length + 4]; Buffer.BlockCopy(_Z, 0, data, 0, _Z.Length); Buffer.BlockCopy(IntUtils.IntToBytes(_callCounter), 0, data, _Z.Length, 4); byte[] H = _digestEngine.ComputeHash(data); _bitBuffer.AppendBits(H); _callCounter++; } _remLen = minCallsR * 8 * _hashLen; }
/// <summary> /// Retorna uma lista de entidade de Empresa não cadastradas na turma informada como parametro /// </summary> /// <autor>Diogo T. Machado</autor> /// <param name="transaction">Transaction</param> /// <param name="db">DataBase</param> /// <returns><list type="EntEmpresa">Lista de EntEmpresa</list></returns> public List <EntEmpresaCadastro> ObterNaoCadastradasNaTurma(String sCpfCnpj, String sNome, Int32 nEstado, int IdTurma, DbTransaction transaction, Database db) { List <EntEmpresaCadastro> listEntReturn = new List <EntEmpresaCadastro>(); DbCommand dbCommand = db.GetStoredProcCommand("STP_SelecionaEmpresaCadastroNaoInscritasPorFiltro"); db.AddInParameter(dbCommand, "@sCpfCnpj", DbType.String, sCpfCnpj); db.AddInParameter(dbCommand, "@sRazaoSocial", DbType.String, sNome); db.AddInParameter(dbCommand, "@nCEA_ESTADO", DbType.Int32, IntUtils.ToIntNull(nEstado)); db.AddInParameter(dbCommand, "@nCEA_TURMA", DbType.Int32, IdTurma); dbCommand.CommandTimeout = BdConfig.CommmandTimeout; using (DbDataReader dtrDados = (System.Data.Common.DbDataReader)db.ExecuteReader(dbCommand, transaction)) { if (dtrDados != null && dtrDados.HasRows) { foreach (DbDataRecord DataRecord in dtrDados) { EntEmpresaCadastro entReturn = new EntEmpresaCadastro(); entReturn.IdEmpresaCadastro = ObjectUtils.ToInt(DataRecord["CDA_EMP_CADASTRO"]); entReturn.RazaoSocial = ObjectUtils.ToString(DataRecord["TX_RAZAO_SOCIAL"]); entReturn.NomeFantasia = ObjectUtils.ToString(DataRecord["TX_NOME_FANTASIA"]); entReturn.CPF_CNPJ = ObjectUtils.ToString(DataRecord["TX_CPF_CNPJ"]); entReturn.Estado.IdEstado = ObjectUtils.ToInt(DataRecord["CEA_ESTADO"]); entReturn.Estado.Estado = ObjectUtils.ToString(DataRecord["TX_ESTADO"]); listEntReturn.Add(entReturn); } return(listEntReturn); } else { return(null); } } }
private void ObjectToPageImportacao(EntInscricoesEmpresa objInscricoesEmpresa) { // Dados da Empresa this.TxtBxRazaoSocial.Text = objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.RazaoSocial; this.TxtBxNomeFantasia.Text = objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.NomeFantasia; if (objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.PessoaJuridica) { this.TxtBxCNPJCPF.Text = FormatUtils.FormatCNPJ(objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.CPF_CNPJ); this.LblCPF_CNPJ.Text = "CNPJ:"; } else { this.TxtBxCNPJCPF.Text = FormatUtils.FormatCPF(objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.CPF_CNPJ); this.LblCPF_CNPJ.Text = "CPF:"; } this.TxtBxDataAbertura.Text = DateUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.AberturaEmpresa); this.TxtBxNumeroEmpregados.Text = ""; this.TxtBxEndereco.Text = ""; this.TxtBxComplemento.Text = ""; this.TxtBxNumero.Text = ""; this.TxtBxCEP.Text = ""; this.TxtBxPrincipalAtividade.Text = objInscricoesEmpresa.TurmaEmpresa.AtividadeEconomicaComplemento; //this.SelecionaListItem(this.DrpDwnLstTipoEmpresa, objInscricoesEmpresa.TurmaEmpresa.TipoEmpresa.IdTipoEmpresa); this.CmbBxTipoEmpresa.SelectedValue = IntUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.TipoEmpresa.IdTipoEmpresa); this.SelecionaListItem(this.CmbBxFaturamento, objInscricoesEmpresa.TurmaEmpresa.Faturamento.IdFaturamento); String ValorPadrao = "<< Selecione uma Opção >>"; WebUtils.PopulaDropDownList(CmbBxCategoria, EnumType.TipoDropDownList.Categoria, ValorPadrao); this.CmbBxCategoria.SelectedValue = IntUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.Categoria.IdCategoria); this.PopulaAtividadeEconomica(new EntAtividadeEconomica()); this.SelecionaListItem(this.CmbBxEstado, 0); if (this.CmbBxEstado.SelectedIndex > 0) { this.CmbBxCidade.Enabled = true; } this.PopulaCidade(0); this.SelecionaListItem(this.CmbBxCidade, 0); if (this.CmbBxCidade.SelectedIndex > 0) { this.CmbBxBairro.Enabled = true; } this.PopulaBairro(0); this.SelecionaListItem(this.CmbBxBairro, 0); // Dados do Contato this.TxtBxNomeCompleto.Text = String.Empty; this.TxtBxCPF.Text = String.Empty; this.TxtBxCelular.Text = String.Empty; this.TxtBxEmail.Text = String.Empty; this.RdBttnLstSexo.SelectedValue = String.Empty; this.TxtBxDtNascimento.Text = String.Empty; this.TxtBxEnderecoCompleto.Text = String.Empty; this.TxtBxComplementoContato.Text = String.Empty; this.TxtBxNumeroContato.Text = String.Empty; this.TxtBxCEPContato.Text = String.Empty; this.TxtBxTelefoneFixo.Text = String.Empty; this.CmbBxNivelEscolaridade.SelectedValue = ""; }
private void ObjectToPage(EntInscricoesEmpresa objInscricoesEmpresa) { this.HddnFldIdProgramaEmpresa.Value = IntUtils.ToString(objInscricoesEmpresa.ProgramaEmpresa.IdProgramaEmpresa); // Dados da Empresa this.TxtBxRazaoSocial.Text = objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.RazaoSocial; this.TxtBxNomeFantasia.Text = objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.NomeFantasia; if (objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.PessoaJuridica) { this.TxtBxCNPJCPF.Text = FormatUtils.FormatCNPJ(objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.CPF_CNPJ); this.LblCPF_CNPJ.Text = "CNPJ:"; } else { this.TxtBxCNPJCPF.Text = FormatUtils.FormatCPF(objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.CPF_CNPJ); this.LblCPF_CNPJ.Text = "CPF:"; } this.TxtBxDataAbertura.Text = DateUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro.AberturaEmpresa); this.TxtBxNumeroEmpregados.Text = IntUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.NumeroFuncionario); this.TxtBxEndereco.Text = objInscricoesEmpresa.TurmaEmpresa.Endereco; this.TxtBxComplemento.Text = objInscricoesEmpresa.TurmaEmpresa.Complemento; this.TxtBxNumero.Text = objInscricoesEmpresa.TurmaEmpresa.NumeroEndereco; this.TxtBxCEP.Text = FormatUtils.FormatCEP(objInscricoesEmpresa.TurmaEmpresa.CEP); this.TxtBxPrincipalAtividade.Text = objInscricoesEmpresa.TurmaEmpresa.AtividadeEconomicaComplemento; //this.SelecionaListItem(this.DrpDwnLstTipoEmpresa, objInscricoesEmpresa.TurmaEmpresa.TipoEmpresa.IdTipoEmpresa); this.CmbBxTipoEmpresa.SelectedValue = IntUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.TipoEmpresa.IdTipoEmpresa); this.SelecionaListItem(this.CmbBxFaturamento, objInscricoesEmpresa.TurmaEmpresa.Faturamento.IdFaturamento); //this.SelecionaListItem(this.DrpDwnLstCategoria, objInscricoesEmpresa.TurmaEmpresa.Categoria.IdCategoria); this.CmbBxCategoria.SelectedValue = IntUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.Categoria.IdCategoria); this.PopulaAtividadeEconomica(objInscricoesEmpresa.TurmaEmpresa.AtividadeEconomica); if (objInscricoesEmpresa.TurmaEmpresa.Estado.IdEstado == 0) { objInscricoesEmpresa.TurmaEmpresa.Estado = objInscricoesEmpresa.ProgramaEmpresa.EmpresaCadastro.Estado; } this.SelecionaListItem(this.CmbBxEstado, objInscricoesEmpresa.TurmaEmpresa.Estado.IdEstado); if (this.CmbBxEstado.SelectedIndex > 0) { this.CmbBxCidade.Enabled = true; } this.PopulaCidade(objInscricoesEmpresa.TurmaEmpresa.Estado.IdEstado); this.SelecionaListItem(this.CmbBxCidade, objInscricoesEmpresa.TurmaEmpresa.Cidade.IdCidade); if (this.CmbBxCidade.SelectedIndex > 0) { this.CmbBxBairro.Enabled = true; } this.PopulaBairro(objInscricoesEmpresa.TurmaEmpresa.Cidade.IdCidade); this.SelecionaListItem(this.CmbBxBairro, objInscricoesEmpresa.TurmaEmpresa.Bairro.IdBairro); // Dados do Contato this.TxtBxNomeCompleto.Text = objInscricoesEmpresa.TurmaEmpresa.NomeContato; this.TxtBxCPF.Text = FormatUtils.FormatCPF(objInscricoesEmpresa.TurmaEmpresa.CPFContato); this.TxtBxCelular.Text = FormatUtils.FormatTelefone(objInscricoesEmpresa.TurmaEmpresa.CelularContato); this.TxtBxEmail.Text = objInscricoesEmpresa.TurmaEmpresa.EmailContato; this.RdBttnLstSexo.SelectedValue = objInscricoesEmpresa.TurmaEmpresa.SexoContato; this.TxtBxDtNascimento.Text = DateUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.NascimentoContato); this.TxtBxEnderecoCompleto.Text = objInscricoesEmpresa.TurmaEmpresa.EnderecoContato; this.TxtBxComplementoContato.Text = objInscricoesEmpresa.TurmaEmpresa.ComplementoContato; this.TxtBxNumeroContato.Text = objInscricoesEmpresa.TurmaEmpresa.NumeroEnderecoContato; this.TxtBxCEPContato.Text = FormatUtils.FormatCEP(objInscricoesEmpresa.TurmaEmpresa.CEPContato); this.TxtBxTelefoneFixo.Text = FormatUtils.FormatTelefone(objInscricoesEmpresa.TurmaEmpresa.TelefoneContato); this.CmbBxCargo.SelectedValue = IntUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.Cargo.IdCargo); this.SelecionaListItem(this.CmbBxEstadoContato, objInscricoesEmpresa.TurmaEmpresa.EstadoContato.IdEstado); if (this.CmbBxEstadoContato.SelectedIndex > 0) { this.CmbBxCidadeContato.Enabled = true; } this.PopulaCidadeContato(objInscricoesEmpresa.TurmaEmpresa.EstadoContato.IdEstado); this.SelecionaListItem(this.CmbBxCidadeContato, objInscricoesEmpresa.TurmaEmpresa.CidadeContato.IdCidade); if (this.CmbBxCidadeContato.SelectedIndex > 0) { this.CmbBxBairroContato.Enabled = true; } this.PopulaBairroContato(objInscricoesEmpresa.TurmaEmpresa.CidadeContato.IdCidade); this.SelecionaListItem(this.CmbBxBairroContato, objInscricoesEmpresa.TurmaEmpresa.BairroContato.IdBairro); this.CmbBxNivelEscolaridade.SelectedValue = IntUtils.ToString(objInscricoesEmpresa.TurmaEmpresa.ContatoNivelEscolaridade.IdContatoNivelEscolaridade); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["IdTurma"] != null) { int IdTurma = int.Parse(Request["IdTurma"]); AlteraTurma(IdTurma); } String cpfCnpj = ""; if (Request["CpfCnpj"] != null) { this.EmpresaLogada = new BllEmpresaCadastro().ObterPorCpfCnpj(Request["CpfCnpj"]); cpfCnpj = StringUtils.trataCpfCnpj(Request["CpfCnpj"]); //this.OrganizaTabIndex(); this.TxtBxRazaoSocial.Focus(); if (StringUtils.OnlyNumbers(cpfCnpj).Length == 14) { this.TxtBxCNPJCPF.Text = FormatUtils.FormatCNPJ(cpfCnpj); this.LblCPF_CNPJ.Text = "CNPJ:"; } else { this.TxtBxCNPJCPF.Text = FormatUtils.FormatCPF(cpfCnpj); this.LblCPF_CNPJ.Text = "CPF:"; } } this.TxtBxCNPJCPF.Text = cpfCnpj; this.TxtBxCNPJCPF.Enabled = false; String ValorPadrao = "<< Selecione uma Opção >>"; //WebUtils.PopulaDropDownList(DrpDwnLstTipoEmpresa, EnumType.TipoDropDownList.TipoEmpresa, ValorPadrao); //WebUtils.PopulaDropDownList(DrpDwnLstCategoria, EnumType.TipoDropDownList.Categoria, true, ValorPadrao); WebUtils.PopulaDropDownList(CmbBxNivelEscolaridade, EnumType.TipoDropDownList.Escolaridade, ValorPadrao); WebUtils.PopulaDropDownList(CmbBxFaturamento, EnumType.TipoDropDownList.Faturamento, ValorPadrao); WebUtils.PopulaDropDownList(CmbBxCargo, EnumType.TipoDropDownList.Cargo, ValorPadrao); WebUtils.PopulaDropDownList(CmbBxTipoEmpresa, EnumType.TipoDropDownList.TipoEmpresa, ValorPadrao); WebUtils.PopulaDropDownList(CmbBxCategoria, EnumType.TipoDropDownList.Categoria, ValorPadrao); //// teste Combobox //this.CmbBxCategoria.Items.Clear(); //this.CmbBxCategoria.DataSource = new BllCategoria().ObterTodos(true); //this.CmbBxCategoria.DataBind(); //if ((!StringUtils.IsEmpty(ValorPadrao)) || (ValorPadrao != null)) //{ // this.CmbBxCategoria.Items.Insert(0, new ListItem(ValorPadrao, "0")); // this.CmbBxCategoria.SelectedIndex = 0; //} this.PopulaEstado(); this.PopulaEstadoContato(); this.PopulaCidade(0); this.PopulaCidadeContato(0); this.PopulaBairro(0); this.PopulaBairroContato(0); if (this.EmpresaLogada != null && this.EmpresaLogada.IdEmpresaCadastro > 0) { EntInscricoesEmpresa objInscricoesEmpresa = new EntInscricoesEmpresa(); EntTurmaEmpresa objTurmaEmpresa = new EntTurmaEmpresa(); objTurmaEmpresa.EmpresaCadastro = EmpresaLogada; objTurmaEmpresa.Turma = objTurma; objTurmaEmpresa = new BllTurmaEmpresa().ObterPorTurmaEmpresa(objTurmaEmpresa); objInscricoesEmpresa.ProgramaEmpresa = new BllProgramaEmpresa().ObterPorProgramaEmpresa(objPrograma.IdPrograma, EmpresaLogada.IdEmpresaCadastro); if (objInscricoesEmpresa.ProgramaEmpresa != null) { this.HddnFldIdProgramaEmpresa.Value = IntUtils.ToString(objInscricoesEmpresa.ProgramaEmpresa.IdProgramaEmpresa); this.HddnFldSenha.Value = objInscricoesEmpresa.ProgramaEmpresa.Senha; } if (objTurmaEmpresa != null) { this.ObjectToPage(new BllInscricoesEmpresa().ObterPorIdEmpresaTurma(objTurmaEmpresa, objPrograma.IdPrograma)); this.HabilitaCampoSenha(false); } else { // objTurmaEmpresa = new BllTurmaEmpresa().ObterTurmaEmpresaAnteriorPorEmpresaCadastro(EmpresaLogada.IdEmpresaCadastro, objPrograma.IdPrograma, objTurma.IdTurma); // objInscricoesEmpresa.TurmaEmpresa = objTurmaEmpresa; // objInscricoesEmpresa.TurmaEmpresa.EmpresaCadastro = EmpresaLogada; // this.ObjectToPageImportacao(objInscricoesEmpresa); this.CmbBxFaturamento.SelectedIndex = 0; this.HabilitaCampoSenha(false); } this.HddnFldIdInscricaoEmpresa.Value = (String)Request.QueryString["IdEmpresaCadastro"]; } //Quando Pessoa Fisica Obrigatóriamente a categoria deve ser AgroNegócio. VerificaCpfCNPJ(); if (Request["CpfCnpj"] != null && (objPrograma.IdPrograma == EntPrograma.PROGRAMA_FGA || objPrograma.IdPrograma == EntPrograma.PROGRAMA_PEG)) { this.TxtBxRazaoSocial.Text = EmpresaLogada.RazaoSocial; this.TxtBxNomeFantasia.Text = EmpresaLogada.NomeFantasia; this.TxtBxDataAbertura.Text = DateUtils.ToString(EmpresaLogada.AberturaEmpresa); this.CmbBxEstado.SelectedValue = EmpresaLogada.Estado.IdEstado.ToString(); this.PopulaCidade(EmpresaLogada.Estado.IdEstado); this.CmbBxCidade.Enabled = true; EntProgramaEmpresa objProgramaEmpresa = new BllProgramaEmpresa().ObterPorProgramaEmpresa(this.objPrograma.IdPrograma, EmpresaLogada.IdEmpresaCadastro); if (objProgramaEmpresa != null) { this.TxtBxNomeCompleto.Text = objProgramaEmpresa.NomeResponsavel; this.TxtBxEmail.Text = objProgramaEmpresa.EmailResponsavel; } } int numeroEmpregados = StringUtils.ToInt(TxtBxNumeroEmpregados.Text); if (numeroEmpregados == -1) { TxtBxNumeroEmpregados.Text = ""; } if (StringUtils.ToDate(TxtBxDtNascimento.Text).Year < 1900) { TxtBxDtNascimento.Text = ""; } } this.UCSelecionaCNAE1.atualizaCampo += this.PopulaAtividadeEconomica; TxtBxCEP.Focus(); }
public List <EntUsuario> ObterTodos(String Usuario, String Email, Int32 Status, DbTransaction transaction, Database db) { DbCommand dbCommand = db.GetStoredProcCommand("STP_UsuarioSelecionarTodos"); db.AddInParameter(dbCommand, StringUtils.TrataParametroProc("Usuario"), DbType.String, Usuario); db.AddInParameter(dbCommand, StringUtils.TrataParametroProc("Email"), DbType.String, Email); db.AddInParameter(dbCommand, StringUtils.TrataParametroProc("Status"), DbType.Boolean, IntUtils.ToBooleanNullProc(Status)); dbCommand.CommandTimeout = BdConfig.CommmandTimeout; using (DbDataReader dtrDados = (System.Data.Common.DbDataReader)db.ExecuteReader(dbCommand, transaction)) { if (dtrDados != null && dtrDados.HasRows) { return(this.Popular(dtrDados)); } else { return(new List <EntUsuario>()); } } }
public Executable(IExecutable Exe, KMemoryManager MemoryManager, AMemory Memory, long ImageBase) { Dynamic = new List <ElfDyn>(); FilePath = Exe.FilePath; if (FilePath != null) { Name = Path.GetFileNameWithoutExtension(FilePath.Replace(Homebrew.TemporaryNroSuffix, "")); } this.Memory = Memory; this.MemoryManager = MemoryManager; this.ImageBase = ImageBase; this.ImageEnd = ImageBase; long TextPosition = ImageBase + (uint)Exe.TextOffset; long ROPosition = ImageBase + (uint)Exe.ROOffset; long DataPosition = ImageBase + (uint)Exe.DataOffset; long TextSize = (uint)IntUtils.AlignUp(Exe.Text.Length, KMemoryManager.PageSize); long ROSize = (uint)IntUtils.AlignUp(Exe.RO.Length, KMemoryManager.PageSize); long DataSize = (uint)IntUtils.AlignUp(Exe.Data.Length, KMemoryManager.PageSize); long DataAndBssSize = (uint)IntUtils.AlignUp(Exe.BssSize, KMemoryManager.PageSize) + DataSize; ImageEnd = DataPosition + DataAndBssSize; MemoryManager.HleMapProcessCode(TextPosition, TextSize + ROSize + DataAndBssSize); MemoryManager.SetProcessMemoryPermission(ROPosition, ROSize, MemoryPermission.Read); MemoryManager.SetProcessMemoryPermission(DataPosition, DataAndBssSize, MemoryPermission.ReadAndWrite); Memory.WriteBytes(TextPosition, Exe.Text); Memory.WriteBytes(ROPosition, Exe.RO); Memory.WriteBytes(DataPosition, Exe.Data); if (Exe.Mod0Offset == 0) { return; } long Mod0Offset = ImageBase + Exe.Mod0Offset; int Mod0Magic = Memory.ReadInt32(Mod0Offset + 0x0); long DynamicOffset = Memory.ReadInt32(Mod0Offset + 0x4) + Mod0Offset; long BssStartOffset = Memory.ReadInt32(Mod0Offset + 0x8) + Mod0Offset; long BssEndOffset = Memory.ReadInt32(Mod0Offset + 0xc) + Mod0Offset; long EhHdrStartOffset = Memory.ReadInt32(Mod0Offset + 0x10) + Mod0Offset; long EhHdrEndOffset = Memory.ReadInt32(Mod0Offset + 0x14) + Mod0Offset; long ModObjOffset = Memory.ReadInt32(Mod0Offset + 0x18) + Mod0Offset; while (true) { long TagVal = Memory.ReadInt64(DynamicOffset + 0); long Value = Memory.ReadInt64(DynamicOffset + 8); DynamicOffset += 0x10; ElfDynTag Tag = (ElfDynTag)TagVal; if (Tag == ElfDynTag.DT_NULL) { break; } Dynamic.Add(new ElfDyn(Tag, Value)); } long StrTblAddr = ImageBase + GetFirstValue(ElfDynTag.DT_STRTAB); long SymTblAddr = ImageBase + GetFirstValue(ElfDynTag.DT_SYMTAB); long SymEntSize = GetFirstValue(ElfDynTag.DT_SYMENT); List <ElfSym> Symbols = new List <ElfSym>(); while ((ulong)SymTblAddr < (ulong)StrTblAddr) { ElfSym Sym = GetSymbol(SymTblAddr, StrTblAddr); Symbols.Add(Sym); SymTblAddr += SymEntSize; } SymbolTable = Array.AsReadOnly(Symbols.OrderBy(x => x.Value).ToArray()); }
/// <summary> /// Compute the product of two polynomials over the field <c>GF(2^m)</c> using a Karatzuba like multiplication /// </summary> /// /// <param name="A">The first polynomial</param> /// <param name="B">The second polynomial</param> /// /// <returns>Returns <c>a * b</c></returns> private static int[] Multiply(int[] A, int[] B, GF2mField GF2) { int[] mult1, mult2; if (ComputeDegree(A) < ComputeDegree(B)) { mult1 = B; mult2 = A; } else { mult1 = A; mult2 = B; } mult1 = NormalForm(mult1); mult2 = NormalForm(mult2); if (mult2.Length == 1) { return(MultWithElement(mult1, mult2[0], GF2)); } int d1 = mult1.Length; int d2 = mult2.Length; int[] result = new int[d1 + d2 - 1]; if (d2 != d1) { int[] res1 = new int[d2]; int[] res2 = new int[d1 - d2]; Array.Copy(mult1, 0, res1, 0, res1.Length); Array.Copy(mult1, d2, res2, 0, res2.Length); res1 = Multiply(res1, mult2, GF2); res2 = Multiply(res2, mult2, GF2); res2 = MultWithMonomial(res2, d2); result = Add(res1, res2, GF2); } else { d2 = IntUtils.URShift((d1 + 1), 1); int d = d1 - d2; int[] firstPartMult1 = new int[d2]; int[] firstPartMult2 = new int[d2]; int[] secondPartMult1 = new int[d]; int[] secondPartMult2 = new int[d]; Array.Copy(mult1, 0, firstPartMult1, 0, firstPartMult1.Length); Array.Copy(mult1, d2, secondPartMult1, 0, secondPartMult1.Length); Array.Copy(mult2, 0, firstPartMult2, 0, firstPartMult2.Length); Array.Copy(mult2, d2, secondPartMult2, 0, secondPartMult2.Length); int[] helpPoly1 = Add(firstPartMult1, secondPartMult1, GF2); int[] helpPoly2 = Add(firstPartMult2, secondPartMult2, GF2); int[] res1 = Multiply(firstPartMult1, firstPartMult2, GF2); int[] res2 = Multiply(helpPoly1, helpPoly2, GF2); int[] res3 = Multiply(secondPartMult1, secondPartMult2, GF2); res2 = Add(res2, res1, GF2); res2 = Add(res2, res3, GF2); res3 = MultWithMonomial(res3, d2); result = Add(res2, res3, GF2); result = MultWithMonomial(result, d2); result = Add(result, res1, GF2); } return(result); }
/// <summary> /// Compute the inverse of this matrix /// </summary> /// /// <returns>Returns the inverse of this matrix</returns> public override Matrix ComputeInverse() { if (RowCount != ColumnCount) { throw new ArithmeticException("GF2Matrix: Matrix is not invertible!"); } // clone this matrix int[][] tmpMatrix = ArrayUtils.CreateJagged <int[][]>(RowCount, _length); for (int i = RowCount - 1; i >= 0; i--) { tmpMatrix[i] = IntUtils.DeepCopy(_matrix[i]); } // initialize inverse matrix as unit matrix int[][] invMatrix = ArrayUtils.CreateJagged <int[][]>(RowCount, _length); for (int i = RowCount - 1; i >= 0; i--) { int q = i >> 5; int r = i & 0x1f; invMatrix[i][q] = 1 << r; } // simultaneously compute Gaussian reduction of tmpMatrix and unit matrix for (int i = 0; i < RowCount; i++) { int q = i >> 5; int bitMask = 1 << (i & 0x1f); // if diagonal element is zero if ((tmpMatrix[i][q] & bitMask) == 0) { bool foundNonZero = false; // find a non-zero element in the same column for (int j = i + 1; j < RowCount; j++) { if ((tmpMatrix[j][q] & bitMask) != 0) { // found it, swap rows ... foundNonZero = true; SwapRows(tmpMatrix, i, j); SwapRows(invMatrix, i, j); // ... and quit searching j = RowCount; continue; } } // if no non-zero element was found the matrix is not invertible if (!foundNonZero) { throw new ArithmeticException("GF2Matrix: Matrix is not invertible!"); } } // normalize all but i-th row for (int j = RowCount - 1; j >= 0; j--) { if ((j != i) && ((tmpMatrix[j][q] & bitMask) != 0)) { AddToRow(tmpMatrix[i], tmpMatrix[j], q); AddToRow(invMatrix[i], invMatrix[j], 0); } } } return(new GF2Matrix(ColumnCount, invMatrix)); }
/// <summary> /// Compute the product of the matrix <c>(Id | this)</c> and a column vector, where <c>Id</c> is a <c>(numRows x numRows)</c> unit matrix. /// </summary> /// /// <param name="V">The vector over GF(2)</param> /// /// <returns>Returns <c>(Id | this)*vector</c></returns> public Vector RightMultiplyRightCompactForm(Vector V) { if (!(V is GF2Vector)) { throw new ArithmeticException("GF2Matrix: Vector is not defined over GF(2)!"); } if (V.Length != ColumnCount + RowCount) { throw new ArithmeticException("GF2Matrix: Length mismatch!"); } int[] v = ((GF2Vector)V).VectorArray; int[] res = new int[IntUtils.URShift((RowCount + 31), 5)]; int q = RowCount >> 5; int r = RowCount & 0x1f; // for all rows for (int i = 0; i < RowCount; i++) { // get vector bit int help = (IntUtils.URShift(v[i >> 5], (i & 0x1f)) & 1); // compute full word scalar products int vInd = q; // if words have to be shifted if (r != 0) { int vw = 0; // process all but last word for (int j = 0; j < _length - 1; j++) { // shift to correct position vw = (IntUtils.URShift(v[vInd++], r)) | (v[vInd] << (32 - r)); help ^= _matrix[i][j] & vw; } // process last word vw = IntUtils.URShift(v[vInd++], r); if (vInd < v.Length) { vw |= v[vInd] << (32 - r); } help ^= _matrix[i][_length - 1] & vw; } else { // no shifting necessary for (int j = 0; j < _length; j++) { help ^= _matrix[i][j] & v[vInd++]; } } // compute single word scalar product int bitValue = 0; for (int j = 0; j < 32; j++) { bitValue ^= help & 1; help = IntUtils.URShift(help, 1); } // set result bit if (bitValue == 1) { res[i >> 5] |= 1 << (i & 0x1f); } } return(new GF2Vector(res, RowCount)); }
/// <summary> /// Compute the product of the matrix <c>(this | Id)</c> and a column vector. /// <para>Where <c>Id</c> is a <c>(numRows x numRows)</c> unit matrix.</para> /// </summary> /// /// <param name="V">The vector over GF(2)</param> /// /// <returns>Returns <c>(this | Id)*vector</c></returns> public Vector LeftMultiplyLeftCompactForm(Vector V) { if (!(V is GF2Vector)) { throw new ArithmeticException("GF2Matrix: Vector is not defined over GF(2)!"); } if (V.Length != RowCount) { throw new ArithmeticException("GF2Matrix: Length mismatch!"); } int[] v = ((GF2Vector)V).VectorArray; int[] res = new int[IntUtils.URShift((RowCount + ColumnCount + 31), 5)]; int words = IntUtils.URShift(RowCount, 5); int row = 0; // process full words of vector for (int i = 0; i < words; i++) { int bitMask = 1; do { int b = v[i] & bitMask; if (b != 0) { // compute scalar product part for (int j = 0; j < _length; j++) { res[j] ^= _matrix[row][j]; } // set last bit int q = IntUtils.URShift((ColumnCount + row), 5); int r = (ColumnCount + row) & 0x1f; res[q] |= 1 << r; } row++; bitMask <<= 1; }while (bitMask != 0); } // process last word of vector int rem = 1 << (RowCount & 0x1f); int bitMask2 = 1; while (bitMask2 != rem) { int b = v[words] & bitMask2; if (b != 0) { // compute scalar product part for (int j = 0; j < _length; j++) { res[j] ^= _matrix[row][j]; } // set last bit int q = IntUtils.URShift((ColumnCount + row), 5); int r = (ColumnCount + row) & 0x1f; res[q] |= 1 << r; } row++; bitMask2 <<= 1; } return(new GF2Vector(res, RowCount + ColumnCount)); }
/// <summary> /// Create a nxn random regular matrix and its inverse /// </summary> /// /// <param name="N">Number of rows (and columns)</param> /// <param name="SecRnd">Source of randomness</param> /// <returns>The created random regular matrix and its inverse</returns> public static GF2Matrix[] CreateRandomRegularMatrixAndItsInverse(int N, IRandom SecRnd) { GF2Matrix[] result = new GF2Matrix[2]; // First part: create regular matrix int length = (N + 31) >> 5; GF2Matrix lm = new GF2Matrix(N, Matrix.MATRIX_TYPE_RANDOM_LT, SecRnd); GF2Matrix um = new GF2Matrix(N, Matrix.MATRIX_TYPE_RANDOM_UT, SecRnd); GF2Matrix rm = (GF2Matrix)lm.RightMultiply(um); Permutation p = new Permutation(N, SecRnd); int[] pVec = p.GetVector(); int[][] matrix = ArrayUtils.CreateJagged <int[][]>(N, length); for (int i = 0; i < N; i++) { Array.Copy(rm._matrix[pVec[i]], 0, matrix[i], 0, length); } result[0] = new GF2Matrix(N, matrix); // Second part: create inverse matrix // inverse to lm GF2Matrix invLm = new GF2Matrix(N, Matrix.MATRIX_TYPE_UNIT); for (int i = 0; i < N; i++) { int rest = i & 0x1f; int q = IntUtils.URShift(i, 5); int r = 1 << rest; for (int j = i + 1; j < N; j++) { int b = (lm._matrix[j][q]) & r; if (b != 0) { for (int k = 0; k <= q; k++) { invLm._matrix[j][k] ^= invLm._matrix[i][k]; } } } } // inverse to um GF2Matrix invUm = new GF2Matrix(N, Matrix.MATRIX_TYPE_UNIT); for (int i = N - 1; i >= 0; i--) { int rest = i & 0x1f; int q = IntUtils.URShift(i, 5); int r = 1 << rest; for (int j = i - 1; j >= 0; j--) { int b = (um._matrix[j][q]) & r; if (b != 0) { for (int k = q; k < length; k++) { invUm._matrix[j][k] ^= invUm._matrix[i][k]; } } } } // inverse matrix result[1] = (GF2Matrix)invUm.RightMultiply(invLm.RightMultiply(p)); return(result); }
private LongPolynomial2 MultRecursive(LongPolynomial2 Poly2) { // Karatsuba multiplication long[] a = Coeffs; long[] b = Poly2.Coeffs; int n = Poly2.Coeffs.Length; if (n <= 32) { int cn = 2 * n; LongPolynomial2 c = new LongPolynomial2(new long[cn]); for (int k = 0; k < cn; k++) { for (int i = Math.Max(0, k - n + 1); i <= Math.Min(k, n - 1); i++) { long c0 = a[k - i] * b[i]; long cu = c0 & 0x7FF000000L + (c0 & 2047); long co = IntUtils.URShift(c0, 48) & 2047; c.Coeffs[k] = (c.Coeffs[k] + cu) & 0x7FF0007FFL; c.Coeffs[k + 1] = (c.Coeffs[k + 1] + co) & 0x7FF0007FFL; } } return(c); } else { int n1 = n / 2; LongPolynomial2 a1 = new LongPolynomial2(a.CopyOf(n1)); LongPolynomial2 a2 = new LongPolynomial2(a.CopyOfRange(n1, n)); LongPolynomial2 b1 = new LongPolynomial2(b.CopyOf(n1)); LongPolynomial2 b2 = new LongPolynomial2(b.CopyOfRange(n1, n)); LongPolynomial2 A = a1.Clone(); A.Add(a2); LongPolynomial2 B = b1.Clone(); B.Add(b2); LongPolynomial2 c1 = a1.MultRecursive(b1); LongPolynomial2 c2 = a2.MultRecursive(b2); LongPolynomial2 c3 = A.MultRecursive(B); c3.Subtract(c1); c3.Subtract(c2); LongPolynomial2 c = new LongPolynomial2(2 * n); for (int i = 0; i < c1.Coeffs.Length; i++) { c.Coeffs[i] = c1.Coeffs[i] & 0x7FF0007FFL; } for (int i = 0; i < c3.Coeffs.Length; i++) { c.Coeffs[n1 + i] = (c.Coeffs[n1 + i] + c3.Coeffs[i]) & 0x7FF0007FFL; } for (int i = 0; i < c2.Coeffs.Length; i++) { c.Coeffs[2 * n1 + i] = (c.Coeffs[2 * n1 + i] + c2.Coeffs[i]) & 0x7FF0007FFL; } return(c); } }
private static int Alloc(ServiceCtx Context) { long InputPosition = Context.Request.GetBufferType0x21().Position; long OutputPosition = Context.Request.GetBufferType0x22().Position; NvMapAlloc Args = AMemoryHelper.Read <NvMapAlloc>(Context.Memory, InputPosition); NvMapHandle Map = GetNvMap(Context, Args.Handle); if (Map == null) { Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Args.Handle:x8}!"); return(NvResult.InvalidInput); } if ((Args.Align & (Args.Align - 1)) != 0) { Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid alignment 0x{Args.Align:x8}!"); return(NvResult.InvalidInput); } if ((uint)Args.Align < NvGpuVmm.PageSize) { Args.Align = NvGpuVmm.PageSize; } int Result = NvResult.Success; if (!Map.Allocated) { Map.Allocated = true; Map.Align = Args.Align; Map.Kind = (byte)Args.Kind; int Size = IntUtils.AlignUp(Map.Size, NvGpuVmm.PageSize); long Address = Args.Address; if (Address == 0) { //When the address is zero, we need to allocate //our own backing memory for the NvMap. if (!Context.Ns.Os.Allocator.TryAllocate((uint)Size, out Address)) { Result = NvResult.OutOfMemory; } } if (Result == NvResult.Success) { Map.Size = Size; Map.Address = Address; } } AMemoryHelper.Write(Context.Memory, OutputPosition, Args); return(Result); }
/// <summary> /// Compute a message representative of a message given as a vector of length <c>n</c> bit and of hamming weight <c>t</c>. /// <para>The result is a byte array of length <c>(s+7)/8</c>, where <c>s = floor[log(n|t)]</c>.</para> /// </summary> /// /// <param name="N">The "n" integer</param> /// <param name="T">The "t" integer</param> /// <param name="M">The message vector as a byte array</param> /// /// <returns>A message representative for <c>m</c></returns> public static byte[] SignConversion(int N, int T, byte[] M) { if (N < T) { throw new ArgumentException("n < t"); } BigInteger bc = BigMath.Binomial(N, T); // finds s = floor[log(binomial(n,t))] int s = bc.BitLength - 1; // s = sq*8 + sr; int sq = s >> 3; int sr = s & 7; if (sr == 0) { sq--; sr = 8; } // n = nq*8+nr; int nq = N >> 3; int nr = N & 7; if (nr == 0) { nq--; nr = 8; } // take s bit from m byte[] data = new byte[nq + 1]; if (M.Length < data.Length) { Array.Copy(M, 0, data, 0, M.Length); for (int i = M.Length; i < data.Length; i++) { data[i] = 0; } } else { Array.Copy(M, 0, data, 0, nq); int h = (1 << nr) - 1; data[nq] = (byte)(h & M[nq]); } BigInteger d = ZERO; int nn = N; int tt = T; for (int i = 0; i < N; i++) { bc = (bc.Multiply(new BigInteger(IntUtils.ToString(nn - tt)))).Divide(new BigInteger(IntUtils.ToString(nn))); nn--; int q = IntUtils.URShift(i, 3); int r = i & 7; r = 1 << r; byte e = (byte)(r & data[q]); if (e != 0) { d = d.Add(bc); tt--; if (nn == tt) { bc = ONE; } else { bc = (bc.Multiply(new BigInteger(IntUtils.ToString(tt + 1)))).Divide(new BigInteger(IntUtils.ToString(nn - tt))); } } } byte[] result = new byte[sq + 1]; byte[] help = d.ToByteArray(); if (help.Length < result.Length) { Array.Copy(help, 0, result, 0, help.Length); for (int i = help.Length; i < result.Length; i++) { result[i] = 0; } } else { Array.Copy(help, 0, result, 0, sq); result[sq] = (byte)(((1 << sr) - 1) & help[sq]); } return(result); }
public static int Clamp(this int value, Range <int> range) { return(IntUtils.Clamp(value, range)); }
public long GetAudioRendererWorkBufferSize(ServiceCtx Context) { AudioRendererParameter Params = GetAudioRendererParameter(Context); int Revision = (Params.Revision - Rev0Magic) >> 24; if (Revision <= Rev) { bool IsSplitterSupported = Revision >= 3; long Size; Size = IntUtils.AlignUp(Params.Unknown8 * 4, 64); Size += Params.MixCount * 0x400; Size += (Params.MixCount + 1) * 0x940; Size += Params.VoiceCount * 0x3F0; Size += IntUtils.AlignUp((Params.MixCount + 1) * 8, 16); Size += IntUtils.AlignUp(Params.VoiceCount * 8, 16); Size += IntUtils.AlignUp( ((Params.SinkCount + Params.MixCount) * 0x3C0 + Params.SampleCount * 4) * (Params.Unknown8 + 6), 64); Size += (Params.SinkCount + Params.MixCount) * 0x2C0; Size += (Params.EffectCount + Params.VoiceCount * 4) * 0x30 + 0x50; if (IsSplitterSupported) { Size += IntUtils.AlignUp(( NodeStatesGetWorkBufferSize(Params.MixCount + 1) + EdgeMatrixGetWorkBufferSize(Params.MixCount + 1)), 16); Size += Params.SplitterDestinationDataCount * 0xE0; Size += Params.SplitterCount * 0x20; Size += IntUtils.AlignUp(Params.SplitterDestinationDataCount * 4, 16); } Size = Params.EffectCount * 0x4C0 + Params.SinkCount * 0x170 + Params.VoiceCount * 0x100 + IntUtils.AlignUp(Size, 64) + 0x40; if (Params.PerformanceManagerCount >= 1) { Size += (((Params.EffectCount + Params.SinkCount + Params.VoiceCount + Params.MixCount + 1) * 16 + 0x658) * (Params.PerformanceManagerCount + 1) + 0x13F) & ~0x3FL; } Size = (Size + 0x1907D) & ~0xFFFL; Context.ResponseData.Write(Size); Context.Device.Log.PrintDebug(LogClass.ServiceAudio, $"WorkBufferSize is 0x{Size:x16}."); return(0); } else { Context.ResponseData.Write(0L); Context.Device.Log.PrintWarning(LogClass.ServiceAudio, $"Library Revision 0x{Params.Revision:x8} is not supported!"); return(MakeError(ErrorModule.Audio, AudErr.UnsupportedRevision)); } }
public static int Clamp(this int value, int min, int max) { return(IntUtils.Clamp(value, min, max)); }
public bool Run(bool NeedsHbAbi = false) { if (Disposed) { throw new ObjectDisposedException(nameof(Process)); } this.NeedsHbAbi = NeedsHbAbi; if (Executables.Count == 0) { return(false); } MakeSymbolTable(); long MainStackTop = MemoryManager.CodeRegionEnd - KMemoryManager.PageSize; long MainStackSize = 1 * 1024 * 1024; long MainStackBottom = MainStackTop - MainStackSize; MemoryManager.HleMapCustom( MainStackBottom, MainStackSize, MemoryState.MappedMemory, MemoryPermission.ReadAndWrite); int Handle = MakeThread(Executables[0].ImageBase, MainStackTop, 0, 44, 0); if (Handle == -1) { return(false); } KThread MainThread = HandleTable.GetData <KThread>(Handle); if (NeedsHbAbi) { HbAbiDataPosition = IntUtils.AlignUp(Executables[0].ImageEnd, KMemoryManager.PageSize); const long HbAbiDataSize = KMemoryManager.PageSize; MemoryManager.HleMapCustom( HbAbiDataPosition, HbAbiDataSize, MemoryState.MappedMemory, MemoryPermission.ReadAndWrite); string SwitchPath = Device.FileSystem.SystemPathToSwitchPath(Executables[0].FilePath); Homebrew.WriteHbAbiData(Memory, HbAbiDataPosition, Handle, SwitchPath); MainThread.Thread.ThreadState.X0 = (ulong)HbAbiDataPosition; MainThread.Thread.ThreadState.X1 = ulong.MaxValue; } MainThread.TimeUp(); return(true); }
/// <summary> /// Copy constructor /// </summary> /// /// <param name="G">The GF2Vector to copy</param> public GF2Vector(GF2Vector G) { this.Length = G.Length; this.m_elements = IntUtils.DeepCopy(G.m_elements); }