SourceIndex() public method

public SourceIndex ( int i ) : uint
i int
return uint
Example #1
0
        public static void ParseAndUpdateVfprSourceTargetPrefix(int Index, string RegisterName, ref VfpuPrefix VfpuPrefix)
        {
            int SetIndex = Index;
            bool IsConstant;

            RegisterName = RegisterName.Replace(" ", "");

            if (RegisterName.StartsWith("-"))
            {
                RegisterName = RegisterName.Substr(1);
                VfpuPrefix.SourceNegate(Index, true);
            }

            if (RegisterName.StartsWith("|") && RegisterName.EndsWith("|"))
            {
                RegisterName = RegisterName.Substr(1, -1);
                VfpuPrefix.SourceAbsolute(Index, true);
            }

            switch (RegisterName)
            {
                case "x": IsConstant = false; SetIndex = 0; break;
                case "y": IsConstant = false; SetIndex = 1; break;
                case "z": IsConstant = false; SetIndex = 2; break;
                case "w": IsConstant = false; SetIndex = 3; break;
                case "3": IsConstant = true; SetIndex = 0; VfpuPrefix.SourceAbsolute(Index, true); break;
                case "0": IsConstant = true; SetIndex = 0; VfpuPrefix.SourceAbsolute(Index, false); break;
                case "1/3": IsConstant = true; SetIndex = 1; VfpuPrefix.SourceAbsolute(Index, true); break;
                case "1": IsConstant = true; SetIndex = 1; VfpuPrefix.SourceAbsolute(Index, false); break;
                case "1/4": IsConstant = true; SetIndex = 2; VfpuPrefix.SourceAbsolute(Index, true); break;
                case "2": IsConstant = true; SetIndex = 2; VfpuPrefix.SourceAbsolute(Index, false); break;
                case "1/6": IsConstant = true; SetIndex = 3; VfpuPrefix.SourceAbsolute(Index, true); break;
                case "1/2": IsConstant = true; SetIndex = 3; VfpuPrefix.SourceAbsolute(Index, false); break;
                default: throw(new NotImplementedException(String.Format("Invalid RegisterName {0}", RegisterName)));
            }

            VfpuPrefix.SourceConstant(Index, IsConstant);
            VfpuPrefix.SourceIndex(Index, (uint)SetIndex);
        }
		//private void VfpuLoad_Register(uint Register, int Index, uint VectorSize, ref VfpuPrefix Prefix, bool Debug = false, bool AsInteger = false)

		private AstNodeExpr AstLoadVfpuReg(uint Register, int Index, uint VectorSize, ref VfpuPrefix Prefix, bool AsInteger = false)
		{
			CheckPrefixUsage(ref Prefix);

			var RegisterIndices = VfpuUtils.GetIndices(VectorSize, VfpuUtils.RegisterType.Vector, Register);
			AstNodeExpr AstNodeExpr;

			if (Prefix.Enabled)
			{
				//Console.Error.WriteLine("PREFIX [2]!" + Index);
				Prefix.UsedPC = PC;
				Prefix.UsedCount++;

				// Constant.
				if (Prefix.SourceConstant(Index))
				{
					float Value = 0.0f;
					switch (Prefix.SourceIndex(Index))
					{
						case 0: Value = Prefix.SourceAbsolute(Index) ? (3.0f) : (0.0f); break;
						case 1: Value = Prefix.SourceAbsolute(Index) ? (1.0f / 3.0f) : (1.0f); break;
						case 2: Value = Prefix.SourceAbsolute(Index) ? (1.0f / 4.0f) : (2.0f); break;
						case 3: Value = Prefix.SourceAbsolute(Index) ? (1.0f / 6.0f) : (0.5f); break;
						default: throw (new InvalidOperationException());
					}

					if (AsInteger)
					{
						AstNodeExpr = ast.Immediate((int)MathFloat.ReinterpretFloatAsInt(Value));
					}
					else
					{
						AstNodeExpr = ast.Immediate((float)Value);
					}
				}
				// Value.
				else
				{
					if (AsInteger)
					{
						throw(new NotImplementedException());
					}
					else
					{
						AstNodeExpr = VFR(RegisterIndices[Prefix.SourceIndex(Index)]);
					}
					if (Prefix.SourceAbsolute(Index)) AstNodeExpr = ast.CallStatic((Func<float, float>)MathFloat.Abs, AstNodeExpr);
				}

				if (Prefix.SourceNegate(Index)) AstNodeExpr = -AstNodeExpr;
			}
			else
			{
				
				AstNodeExpr = VFR(RegisterIndices[Index]);
			}

			return AstNodeExpr;
		}