Exemplo n.º 1
0
        protected int Moveq(int opcode)
        {
            int reg  = (opcode >> 9 & 0x07);
            int data = CpuUtils.SignExtendWord(CpuUtils.SignExtendByte(opcode & 0xff));

            cpu.SetDataRegisterLong(reg, data);
            if (data < 0)
            {
                cpu.SetFlags(cpu.NFlag);
            }
            else
            {
                cpu.ClrFlags(cpu.NFlag);
            }

            if (data == 0)
            {
                cpu.SetFlags(cpu.ZFlag);
            }
            else
            {
                cpu.ClrFlags(cpu.ZFlag);
            }

            cpu.ClrFlags(cpu.CFlag | cpu.VFlag);
            return(4);
        }
Exemplo n.º 2
0
        protected int BxxByte(int opcode)
        {
            int dis = CpuUtils.SignExtendByte(opcode & 0xff);
            int cc  = (opcode >> 8) & 0x0f;
            int pc  = cpu.GetPC();
            int time;

            if (cc == 1)
            {
                cpu.PushLong(pc);
                cpu.SetPC(pc + dis);
                time = 18;
            }
            else
            {
                if (cpu.TestCC(cc))
                {
                    cpu.SetPC(pc + dis);
                    time = 10;
                }
                else
                {
                    time = 8;
                }
            }

            return(time);
        }
Exemplo n.º 3
0
        private static void TransformFeatures(IHost host, ref VBuffer <Float> src, ref VBuffer <Float> dst, TransformInfo transformInfo,
                                              AlignedArray featuresAligned, AlignedArray productAligned)
        {
            Contracts.AssertValue(host, "host");
            host.Check(src.Length == transformInfo.SrcDim, "column does not have the expected dimensionality.");

            var   values = dst.Values;
            Float scale;

            if (transformInfo.RotationTerms != null)
            {
                if (Utils.Size(values) < transformInfo.NewDim)
                {
                    values = new Float[transformInfo.NewDim];
                }
                scale = MathUtils.Sqrt((Float)2.0 / transformInfo.NewDim);
            }
            else
            {
                if (Utils.Size(values) < 2 * transformInfo.NewDim)
                {
                    values = new Float[2 * transformInfo.NewDim];
                }
                scale = MathUtils.Sqrt((Float)1.0 / transformInfo.NewDim);
            }

            if (src.IsDense)
            {
                featuresAligned.CopyFrom(src.Values, 0, src.Length);
                CpuUtils.MatTimesSrc(false, false, transformInfo.RndFourierVectors, featuresAligned, productAligned,
                                     transformInfo.NewDim);
            }
            else
            {
                // This overload of MatTimesSrc ignores the values in slots that are not in src.Indices, so there is
                // no need to zero them out.
                featuresAligned.CopyFrom(src.Indices, src.Values, 0, 0, src.Count, zeroItems: false);
                CpuUtils.MatTimesSrc(false, false, transformInfo.RndFourierVectors, src.Indices, featuresAligned, 0, 0,
                                     src.Count, productAligned, transformInfo.NewDim);
            }

            for (int i = 0; i < transformInfo.NewDim; i++)
            {
                var dotProduct = productAligned[i];
                if (transformInfo.RotationTerms != null)
                {
                    values[i] = (Float)MathUtils.Cos(dotProduct + transformInfo.RotationTerms[i]) * scale;
                }
                else
                {
                    values[2 * i]     = (Float)MathUtils.Cos(dotProduct) * scale;
                    values[2 * i + 1] = (Float)MathUtils.Sin(dotProduct) * scale;
                }
            }

            dst = new VBuffer <Float>(transformInfo.RotationTerms == null ? 2 * transformInfo.NewDim : transformInfo.NewDim,
                                      values, dst.Indices);
        }
Exemplo n.º 4
0
        protected int CmpiByte(int opcode)
        {
            int      s  = CpuUtils.SignExtendByte(cpu.FetchPCWord());
            IOperand op = cpu.ResolveDstEA((opcode >> 3) & 0x07, (opcode & 0x07), Size.Byte);
            int      d  = op.GetByteSigned();
            int      r  = d - s;

            cpu.CalcFlags(InstructionType.CMP, s, d, r, Size.Byte);
            return(op.IsRegisterMode() ? 8 : 8 + op.GetTiming());
        }
Exemplo n.º 5
0
        protected int SubiByte(int opcode)
        {
            int      s   = CpuUtils.SignExtendByte(cpu.FetchPCWord());
            IOperand dst = cpu.ResolveDstEA((opcode >> 3) & 0x07, opcode & 0x07, Size.Byte);
            int      d   = dst.GetByteSigned();
            int      r   = d - s;

            dst.SetByte(r);
            cpu.CalcFlags(InstructionType.SUB, s, d, r, Size.Byte);
            return(dst.IsRegisterMode() ? 8 : 12 + dst.GetTiming());
        }
Exemplo n.º 6
0
        public static List <CpuComputeDevice> QueryCpus(out bool failed64Bit, out bool failedCpuCount)
        {
            Helpers.ConsolePrint(Tag, "QueryCpus START");
            // get all CPUs
            var cpuCount = CpuID.GetPhysicalProcessorCount();

            Helpers.ConsolePrint(Tag,
                                 CpuID.IsHypeThreadingEnabled()
                    ? "HyperThreadingEnabled = TRUE"
                    : "HyperThreadingEnabled = FALSE");

            // get all cores (including virtual - HT can benefit mining)
            var threadsPerCpu = CpuID.GetVirtualCoresCount() / cpuCount;

            failed64Bit    = !Helpers.Is64BitOperatingSystem;
            failedCpuCount = threadsPerCpu * cpuCount > 64;

            // TODO important move this to settings
            var threadsPerCpuMask = threadsPerCpu;

            Globals.ThreadsPerCpu = threadsPerCpu;

            var cpus = new List <CpuComputeDevice>();

            if (CpuUtils.IsCpuMiningCapable() && !failed64Bit && !failedCpuCount)
            {
                if (cpuCount == 1)
                {
                    cpus.Add(new CpuComputeDevice(0, "CPU0", CpuID.GetCpuName().Trim(), threadsPerCpu, 0, 1));
                }
                else if (cpuCount > 1)
                {
                    for (var i = 0; i < cpuCount; i++)
                    {
                        cpus.Add(
                            new CpuComputeDevice(i, "CPU" + i, CpuID.GetCpuName().Trim(), threadsPerCpu,
                                                 CpuID.CreateAffinityMask(i, threadsPerCpuMask), i + 1)
                            );
                    }
                }
            }

            Helpers.ConsolePrint(Tag, "QueryCpus END");

            return(cpus);
        }
Exemplo n.º 7
0
        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.Filters.Add(new LoadAttribute(100, 20));

            //Local config
            var commandDispatcher = new Dispatcher <ICommand, Task>();

            var availableGames = new AvailableGames();
            var endedGames     = new EndendGames();

            //TODO log to trace
            //http://blog.amitapple.com/post/2014/06/azure-website-logging/#.VC6_jvmSyPY
            var eventPublisher = new EventPublisher(Console.WriteLine, new ProjectionEventListener(availableGames, endedGames));
            var eventStore     = new PublishingEventStore(new InMemoryEventStore(() => new InMemoryEventStream()), eventPublisher);

            commandDispatcher.Register <IGameCommand>(
                command => ApplicationService.UpdateAsync <Game.Domain.Game, GameState>(
                    state => new Game.Domain.Game(state), eventStore, command, game =>
            {
                CpuUtils.Slow(1500);
                return(game.Handle(command));
            }));

            var cb = new ContainerBuilder();

            cb.RegisterInstance(commandDispatcher).AsSelf().SingleInstance();
            cb.RegisterType <ReadService>().AsImplementedInterfaces();
            cb.RegisterInstance(availableGames).AsSelf().SingleInstance();
            cb.RegisterInstance(endedGames).AsSelf().SingleInstance();
            cb.RegisterApiControllers(Assembly.GetExecutingAssembly());

            config.DependencyResolver = new AutofacWebApiDependencyResolver(cb.Build());

            app.UseWebApi(config);

            app.Run(context =>
            {
                context.Response.ContentType = "text/plain";
                return(context.Response.WriteAsync("Welcome to RPS APi."));
            });
        }
        public void TestMethod1()
        {
            var cpuProcessor = CpuUtils.CreateCpuProcessor();

            var dynarecFunction = cpuProcessor.DynarecFunctionCompiler.CreateFunction(
                new InstructionArrayReader(MipsAssembler.StaticAssembleInstructions(@"
					addi r1, r1, 1
					jr r31
					nop
				"                ).Instructions),
                0, checkValidAddress: false
                );

            var cpuThreadState = new CpuThreadState(cpuProcessor);

            Assert.Equal(0, cpuThreadState.Gpr[1]);
            dynarecFunction.Delegate(cpuThreadState);
            Assert.Equal(1, cpuThreadState.Gpr[1]);
        }
Exemplo n.º 9
0
        protected DisassembledInstruction DisassembleOp(int address, int opcode)
        {
            DisassembledOperand op;
            int    cc  = (opcode >> 8) & 0x0f;
            int    dis = CpuUtils.SignExtendByte(opcode & 0xff);
            string name;

            if (dis != 0)
            {
                op   = new DisassembledOperand($"{(dis + address + 2).ToString("x8", CultureInfo.InvariantCulture)}");
                name = $"{names[cc]}.s";
            }
            else
            {
                dis  = cpu.ReadMemoryWordSigned(address + 2);
                op   = new DisassembledOperand($"{(dis + address + 2).ToString("x8", CultureInfo.InvariantCulture)}", 2, dis);
                name = $"{names[cc]}.w";
            }

            return(new DisassembledInstruction(address, opcode, name, op));
        }
                public static void QueryCpus()
                {
                    Helpers.ConsolePrint(Tag, "QueryCpus START");
                    // get all CPUs
                    Available.CpusCount = CpuID.GetPhysicalProcessorCount();
                    Available.IsHyperThreadingEnabled = CpuID.IsHypeThreadingEnabled();

                    Helpers.ConsolePrint(Tag,
                                         Available.IsHyperThreadingEnabled
                            ? "HyperThreadingEnabled = TRUE"
                            : "HyperThreadingEnabled = FALSE");

                    // get all cores (including virtual - HT can benefit mining)
                    var threadsPerCpu = CpuID.GetVirtualCoresCount() / Available.CpusCount;

                    if (!Helpers.Is64BitOperatingSystem)
                    {
                        if (ConfigManager.GeneralConfig.ShowDriverVersionWarning)
                        {
                            MessageBox.Show(Tr("NiceHash Miner Legacy works only on 64-bit version of OS for CPU mining. CPU mining will be disabled."),
                                            Tr("Warning!"),
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        Available.CpusCount = 0;
                    }

                    if (threadsPerCpu * Available.CpusCount > 64)
                    {
                        if (ConfigManager.GeneralConfig.ShowDriverVersionWarning)
                        {
                            MessageBox.Show(Tr("NiceHash Miner Legacy does not support more than 64 virtual cores. CPU mining will be disabled."),
                                            Tr("Warning!"),
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        Available.CpusCount = 0;
                    }

                    // TODO important move this to settings
                    var threadsPerCpuMask = threadsPerCpu;

                    Globals.ThreadsPerCpu = threadsPerCpu;

                    if (CpuUtils.IsCpuMiningCapable())
                    {
                        if (Available.CpusCount == 1)
                        {
                            Available.Devices.Add(
                                new CpuComputeDevice(0, "CPU0", CpuID.GetCpuName().Trim(), threadsPerCpu, 0,
                                                     ++CpuCount)
                                );
                        }
                        else if (Available.CpusCount > 1)
                        {
                            for (var i = 0; i < Available.CpusCount; i++)
                            {
                                Available.Devices.Add(
                                    new CpuComputeDevice(i, "CPU" + i, CpuID.GetCpuName().Trim(), threadsPerCpu,
                                                         CpuID.CreateAffinityMask(i, threadsPerCpuMask), ++CpuCount)
                                    );
                            }
                        }
                    }

                    Helpers.ConsolePrint(Tag, "QueryCpus END");
                }