/* * if (enabled && prefix.enabled) { * foreach (i, value; src) { * if (prefix.mask(i)) continue; * * switch (prefix.saturation(i)) { * case 1: value = clamp!(float)(value, 0.0, 1.0); break; * case 3: value = clamp!(float)(value, -1.0, 1.0); break; * default: break; * } * * dst[i] = value; * } * prefix.enabled = false; * } else { * foreach (i, value; src) *dst[i] = value; * } */ private void VfpuSave_Register(uint Register, int Index, uint VectorSize, VfpuPrefix Prefix, Action Action, bool Debug = false) { CheckPrefixUsage(ref Prefix); _VfpuLoadVectorWithIndexPointer(Register, (uint)Index, VectorSize, Debug); { Action(); if (Prefix.Enabled) { if (!Prefix.DestinationMask(Index)) { float Min = 0, Max = 0; bool DoClamp = false; switch (Prefix.DestinationSaturation(Index)) { case 1: DoClamp = true; Min = 0.0f; Max = 1.0f; break; case 3: DoClamp = true; Min = -1.0f; Max = 1.0f; break; default: break; } if (DoClamp) { MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldc_R4, Min); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldc_R4, Max); MipsMethodEmiter.CallMethod(typeof(MathFloat), "Clamp"); } } } } MipsMethodEmiter.ILGenerator.Emit(OpCodes.Stind_R4); }
/* * if (enabled && prefix.enabled) { * foreach (i, ref value; dst) { * // Constant. * if (prefix.constant(i)) { * final switch (prefix.index(i)) { * case 0: value = prefix.absolute(i) ? (3.0f ) : (0.0f); break; * case 1: value = prefix.absolute(i) ? (1.0f / 3.0f) : (1.0f); break; * case 2: value = prefix.absolute(i) ? (1.0f / 4.0f) : (2.0f); break; * case 3: value = prefix.absolute(i) ? (1.0f / 6.0f) : (0.5f); break; * } * } * // Value * else { * value = *src[prefix.index(i)]; * } * * if (prefix.absolute(i)) value = abs(value); * if (prefix.negate (i)) value = -value; * } * prefix.enabled = false; * } else { * foreach (n, ref value; dst) value = *src[n]; * } */ private void VfpuLoad_Register(uint Register, int Index, uint VectorSize, ref VfpuPrefix Prefix, bool Debug = false) { //Console.Error.WriteLine("{0:X}", PC); CheckPrefixUsage(ref Prefix); //Console.Error.WriteLine("PREFIX [1]!" + Index); 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()); } //Console.Error.WriteLine("VALUE:: " + Value); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldc_R4, Value); } // Value. else { _VfpuLoadVectorWithIndexPointer(Register, (uint)Prefix.SourceIndex(Index), VectorSize, Debug); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldind_R4); } if (Prefix.SourceAbsolute(Index)) { //MipsMethodEmiter.ILGenerator.Emit(OpCodes); MipsMethodEmiter.CallMethod(typeof(MathFloat), "Abs"); } if (Prefix.SourceNegate(Index)) { MipsMethodEmiter.ILGenerator.Emit(OpCodes.Neg); } } else { _VfpuLoadVectorWithIndexPointer(Register, (uint)Index, VectorSize, Debug); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldind_R4); } }
private void CheckPrefixUsage(ref VfpuPrefix Prefix, bool Debug = true) { // Disable the prefix once it have been used. if (Prefix.Enabled) { /* * if (Prefix.UsedCount > 0 && Prefix.UsedPC != PC) * { * throw (new InvalidOperationException( * String.Format( * "[0] Prefix not used or not applied to the next instruction Prefix={0}, PC=0x{1:X}", * Prefix, PC * ) * )); * } */ if (Prefix.UsedCount > 0 && Prefix.UsedPC != PC) { Prefix.Enabled = false; } /* * // Additional consideration. * if (PC != Prefix.DeclaredPC + 4) * { * if (Prefix.UsedCount == 0) * { * throw (new InvalidOperationException( * String.Format( * "[1] Prefix not used or not applied to the next instruction Prefix={0}, PC=0x{1:X}", * Prefix, PC * ) * )); * } * Prefix.Enabled = false; * } */ } }
private void VfpuSave_Register(uint Register, int Index, uint VectorSize, VfpuPrefix Prefix, Action Action, bool Debug = false, bool AsInteger = false) { CheckPrefixUsage(ref Prefix); _VfpuLoadVectorWithIndexPointer(Register, (uint)Index, VectorSize, Debug); { Action(); if (Prefix.Enabled) { if (!Prefix.DestinationMask(Index)) { float Min = 0, Max = 0; bool DoClamp = false; switch (Prefix.DestinationSaturation(Index)) { case 1: DoClamp = true; Min = 0.0f; Max = 1.0f; break; case 3: DoClamp = true; Min = -1.0f; Max = 1.0f; break; default: break; } if (DoClamp) { if (AsInteger) { SafeILGenerator.Push((int)Min); SafeILGenerator.Push((int)Max); MipsMethodEmiter.CallMethod((Func<int, int, int, int>)MathFloat.ClampInt); } else { SafeILGenerator.Push((float)Min); SafeILGenerator.Push((float)Max); MipsMethodEmiter.CallMethod((Func<float, float, float, float>)MathFloat.Clamp); } } } } } if (AsInteger) { SafeILGenerator.StoreIndirect<int>(); } else { SafeILGenerator.StoreIndirect<float>(); } }
/* if (enabled && prefix.enabled) { foreach (i, ref value; dst) { // Constant. if (prefix.constant(i)) { final switch (prefix.index(i)) { case 0: value = prefix.absolute(i) ? (3.0f ) : (0.0f); break; case 1: value = prefix.absolute(i) ? (1.0f / 3.0f) : (1.0f); break; case 2: value = prefix.absolute(i) ? (1.0f / 4.0f) : (2.0f); break; case 3: value = prefix.absolute(i) ? (1.0f / 6.0f) : (0.5f); break; } } // Value else { value = *src[prefix.index(i)]; } if (prefix.absolute(i)) value = abs(value); if (prefix.negate (i)) value = -value; } prefix.enabled = false; } else { foreach (n, ref value; dst) value = *src[n]; } */ private void VfpuLoad_Register(uint Register, int Index, uint VectorSize, ref VfpuPrefix Prefix, bool Debug = false, bool AsInteger = false) { //Console.Error.WriteLine("{0:X}", PC); CheckPrefixUsage(ref Prefix); //Console.Error.WriteLine("PREFIX [1]!" + Index); 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()); } //Console.Error.WriteLine("VALUE:: " + Value); if (AsInteger) { SafeILGenerator.Push((int)MathFloat.ReinterpretFloatAsInt(Value)); } else { SafeILGenerator.Push((float)Value); } } // Value. else { _VfpuLoadVectorWithIndexPointer(Register, (uint)Prefix.SourceIndex(Index), VectorSize, Debug); if (AsInteger) { SafeILGenerator.LoadIndirect<int>(); } else { SafeILGenerator.LoadIndirect<float>(); } } if (Prefix.SourceAbsolute(Index)) { //MipsMethodEmiter.ILGenerator.Emit(OpCodes); MipsMethodEmiter.CallMethod((Func<float, float>)MathFloat.Abs); } if (Prefix.SourceNegate(Index)) { SafeILGenerator.UnaryOperation(SafeUnaryOperator.Negate); } } else { _VfpuLoadVectorWithIndexPointer(Register, (uint)Index, VectorSize, Debug); if (AsInteger) { SafeILGenerator.LoadIndirect<int>(); } else { SafeILGenerator.LoadIndirect<float>(); } } }
private void CheckPrefixUsage(ref VfpuPrefix Prefix, bool Debug = true) { // Disable the prefix once it have been used. if (Prefix.Enabled) { /* if (Prefix.UsedCount > 0 && Prefix.UsedPC != PC) { throw (new InvalidOperationException( String.Format( "[0] Prefix not used or not applied to the next instruction Prefix={0}, PC=0x{1:X}", Prefix, PC ) )); } */ if (Prefix.UsedCount > 0 && Prefix.UsedPC != PC) { Prefix.Enabled = false; } /* // Additional consideration. if (PC != Prefix.DeclaredPC + 4) { if (Prefix.UsedCount == 0) { throw (new InvalidOperationException( String.Format( "[1] Prefix not used or not applied to the next instruction Prefix={0}, PC=0x{1:X}", Prefix, PC ) )); } Prefix.Enabled = false; } */ } }
/* if (enabled && prefix.enabled) { foreach (i, value; src) { if (prefix.mask(i)) continue; switch (prefix.saturation(i)) { case 1: value = clamp!(float)(value, 0.0, 1.0); break; case 3: value = clamp!(float)(value, -1.0, 1.0); break; default: break; } *dst[i] = value; } prefix.enabled = false; } else { foreach (i, value; src) *dst[i] = value; } */ private void VfpuSave_Register(uint Register, int Index, uint VectorSize, VfpuPrefix Prefix, Action Action, bool Debug = false) { CheckPrefixUsage(ref Prefix); _VfpuLoadVectorWithIndexPointer(Register, (uint)Index, VectorSize, Debug); { Action(); if (Prefix.Enabled) { if (!Prefix.DestinationMask(Index)) { float Min = 0, Max = 0; bool DoClamp = false; switch (Prefix.DestinationSaturation(Index)) { case 1: DoClamp = true; Min = 0.0f; Max = 1.0f; break; case 3: DoClamp = true; Min = -1.0f; Max = 1.0f; break; default: break; } if (DoClamp) { MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldc_R4, Min); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldc_R4, Max); MipsMethodEmiter.CallMethod(typeof(MathFloat), "Clamp"); } } } } MipsMethodEmiter.ILGenerator.Emit(OpCodes.Stind_R4); }
/* if (enabled && prefix.enabled) { foreach (i, ref value; dst) { // Constant. if (prefix.constant(i)) { final switch (prefix.index(i)) { case 0: value = prefix.absolute(i) ? (3.0f ) : (0.0f); break; case 1: value = prefix.absolute(i) ? (1.0f / 3.0f) : (1.0f); break; case 2: value = prefix.absolute(i) ? (1.0f / 4.0f) : (2.0f); break; case 3: value = prefix.absolute(i) ? (1.0f / 6.0f) : (0.5f); break; } } // Value else { value = *src[prefix.index(i)]; } if (prefix.absolute(i)) value = abs(value); if (prefix.negate (i)) value = -value; } prefix.enabled = false; } else { foreach (n, ref value; dst) value = *src[n]; } */ private void VfpuLoad_Register(uint Register, int Index, uint VectorSize, ref VfpuPrefix Prefix, bool Debug = false) { //Console.Error.WriteLine("{0:X}", PC); CheckPrefixUsage(ref Prefix); //Console.Error.WriteLine("PREFIX [1]!" + Index); 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()); } //Console.Error.WriteLine("VALUE:: " + Value); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldc_R4, Value); } // Value. else { _VfpuLoadVectorWithIndexPointer(Register, (uint)Prefix.SourceIndex(Index), VectorSize, Debug); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldind_R4); } if (Prefix.SourceAbsolute(Index)) { //MipsMethodEmiter.ILGenerator.Emit(OpCodes); MipsMethodEmiter.CallMethod(typeof(MathFloat), "Abs"); } if (Prefix.SourceNegate(Index)) { MipsMethodEmiter.ILGenerator.Emit(OpCodes.Neg); } } else { _VfpuLoadVectorWithIndexPointer(Register, (uint)Index, VectorSize, Debug); MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldind_R4); } }