Browse Source

add util functions for subtraction of const values to Assembly codeblock

Kolja Strohm 3 weeks ago
parent
commit
2d8a1d3f88
6 changed files with 77 additions and 44 deletions
  1. 14 0
      Assembly.cpp
  2. 43 23
      Assembly.h
  3. 8 8
      Cube.cpp
  4. 9 10
      Model3D.cpp
  5. 1 1
      Model3D.h
  6. 2 2
      TextureModel.cpp

+ 14 - 0
Assembly.cpp

@@ -7447,6 +7447,20 @@ void Framework::Assembly::AssemblyBlock::addSubtraction(
             new GPRegisterArgument(source, part)}));
 }
 
+void Framework::Assembly::AssemblyBlock::addSubtraction(
+    GPRegister target, char value, GPRegisterPart part)
+{
+    instructions.add(new Instruction(SUB,
+        {new GPRegisterArgument(target, part), new ConstantArgument(value)}));
+}
+
+void Framework::Assembly::AssemblyBlock::addSubtraction(
+    GPRegister target, int value, GPRegisterPart part)
+{
+    instructions.add(new Instruction(SUB,
+        {new GPRegisterArgument(target, part), new ConstantArgument(value)}));
+}
+
 void Framework::Assembly::AssemblyBlock::addSubtraction(
     FPRegister target, FPRegister source, FPDataType type, FPRegisterPart part)
 {

+ 43 - 23
Assembly.h

@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
 
 #include <vector>
 
@@ -765,8 +765,8 @@ namespace Framework
                 FPDataType type,
                 FPRegisterPart part = Y);
             /**
-             * subtracts the value of the target register from the value of the
-             * source register and stores the result in the target register.
+             * subtracts the value of the source register from the value of the
+             * target register and stores the result in the target register.
              * single operation.
              *
              * \param target the target register
@@ -776,6 +776,26 @@ namespace Framework
             DLLEXPORT void addSubtraction(GPRegister target,
                 GPRegister source,
                 GPRegisterPart part = FULL64);
+            /**
+             * subtracts the given value from the target register and stores the
+             * result in the target register. single operation.
+             *
+             * \param target the target register
+             * \param value the value to subtract
+             * \param part the register part
+             */
+            DLLEXPORT void addSubtraction(
+                GPRegister target, char value, GPRegisterPart part = LOWER8);
+            /**
+             * subtracts the given value from the target register and stores the
+             * result in the target register. single operation.
+             *
+             * \param target the target register
+             * \param value the value to subtract
+             * \param part the register part
+             */
+            DLLEXPORT void addSubtraction(
+                GPRegister target, int value, GPRegisterPart part = LOWER32);
             /**
              * subtracts the value of the target register from the value of the
              * source register and stores the result in the target register.
@@ -925,35 +945,35 @@ namespace Framework
                 GPRegister source,
                 GPRegisterPart part = FULL64);
             /**
-             * writes the specified valueAddress pointer into a register.
+             * writes the value at the specified valueAddress pointer into a
+             * register.
              *
-             * \param valueAddress the pointer to the value witch address should
-             * be stored
-             * \param target the register where the address should be stored
+             * \param valueAddress the pointer to the value
+             * \param target the register where the value should be stored
              */
             DLLEXPORT void addLoadValue(char* valueAddress, GPRegister target);
             /**
-             * writes the specified valueAddress pointer into a register.
+             * writes the value at the specified valueAddress pointer into a
+             * register.
              *
-             * \param valueAddress the pointer to the value witch address should
-             * be stored
-             * \param target the register where the address should be stored
+             * \param valueAddress the pointer to the value
+             * \param target the register where the value should be stored
              */
             DLLEXPORT void addLoadValue(short* valueAddress, GPRegister target);
             /**
-             * writes the specified valueAddress pointer into a register.
+             * writes the value at the specified valueAddress pointer into a
+             * register.
              *
-             * \param valueAddress the pointer to the value witch address should
-             * be stored
-             * \param target the register where the address should be stored
+             * \param valueAddress the pointer to the value
+             * \param target the register where the value should be stored
              */
             DLLEXPORT void addLoadValue(int* valueAddress, GPRegister target);
             /**
-             * writes the specified valueAddress pointer into a register.
+             * writes the value at the specified valueAddress pointer into a
+             * register.
              *
-             * \param valueAddress the pointer to the value witch address should
-             * be stored
-             * \param target the register where the address should be stored
+             * \param valueAddress the pointer to the value
+             * \param target the register where the value should be stored
              */
             DLLEXPORT void addLoadValue(
                 __int64* valueAddress, GPRegister target);
@@ -990,13 +1010,13 @@ namespace Framework
                 double* valueAddress, FPRegister target, GPRegister temp = RAX);
 
             /**
-             * calls a function at a specified memory address.
+             * loads a memory address into a register. Single operation.
              *
-             * \param functionAddress pointet to the address of the function to
-             * call
+             * \param addr the address to load
+             * \param target the register where the address should be stored
              */
             template<typename T>
-            DLLEXPORT void addLoadAddress(T* addr, GPRegister temp = RAX)
+            DLLEXPORT void addLoadAddress(T* addr, GPRegister target = RAX)
             {
                 instructions.add(new Instruction(MOV,
                     {new GPRegisterArgument(temp),

+ 8 - 8
Cube.cpp

@@ -158,24 +158,24 @@ Cube::Cube(float size, GraphicsApi* zApi)
         model->addPolygon(p);
     }
 
-    textur = new Model3DTexture();
+    texture = new Model3DTexture();
 }
 
 // Sets the texture of the cube so that it is the same on all sides
 //  textur: the texture
 void Cube::setTexture(Texture* textur)
 {
-    this->textur->setPolygonTexture(
+    this->texture->setPolygonTexture(
         LINKS, dynamic_cast<Texture*>(textur->getThis()));
-    this->textur->setPolygonTexture(
+    this->texture->setPolygonTexture(
         OBEN, dynamic_cast<Texture*>(textur->getThis()));
-    this->textur->setPolygonTexture(
+    this->texture->setPolygonTexture(
         RECHTS, dynamic_cast<Texture*>(textur->getThis()));
-    this->textur->setPolygonTexture(
+    this->texture->setPolygonTexture(
         UNTEN, dynamic_cast<Texture*>(textur->getThis()));
-    this->textur->setPolygonTexture(
+    this->texture->setPolygonTexture(
         VORNE, dynamic_cast<Texture*>(textur->getThis()));
-    this->textur->setPolygonTexture(HINTEN, textur);
+    this->texture->setPolygonTexture(HINTEN, textur);
     rend = 1;
 }
 
@@ -184,6 +184,6 @@ void Cube::setTexture(Texture* textur)
 //  s: The side to be set
 void Cube::setTexture(Texture* textur, CubeSeite s)
 {
-    this->textur->setPolygonTexture(s, textur);
+    this->texture->setPolygonTexture(s, textur);
     rend = 1;
 }

+ 9 - 10
Model3D.cpp

@@ -1,8 +1,8 @@
 #include "Model3D.h"
 
 #include "Animation3D.h"
-#include "Image.h"
 #include "DXBuffer.h"
+#include "Image.h"
 #include "Model2D.h"
 #include "Texture.h"
 #include "World3D.h"
@@ -728,7 +728,7 @@ Model3D::Model3D()
     : Drawable3D()
 {
     model = 0;
-    textur = 0;
+    texture = 0;
     skelett = 0;
     ambientFactor = 1.f;
     diffusFactor = 0.f;
@@ -739,7 +739,7 @@ Model3D::Model3D()
 Model3D::~Model3D()
 {
     if (model) model->release();
-    if (textur) textur->release();
+    if (texture) texture->release();
     if (skelett) skelett->release();
 }
 
@@ -763,8 +763,8 @@ void Model3D::setModelData(Model3DData* data)
 //  txt: A list of textures assigned to the different polygons
 void Model3D::setModelTextur(Model3DTexture* txt)
 {
-    if (textur) textur->release();
-    textur = txt;
+    if (texture) texture->release();
+    texture = txt;
 }
 
 // Sets the factor by which the ambient light (texture color) is multiplied
@@ -829,13 +829,13 @@ void Model3D::afterRender(
 // Returns the texture
 Model3DTexture* Model3D::getTexture()
 {
-    return textur ? dynamic_cast<Model3DTexture*>(textur->getThis()) : 0;
+    return texture ? dynamic_cast<Model3DTexture*>(texture->getThis()) : 0;
 }
 
 // Returns the texture (without increased reference counter)
 Model3DTexture* Model3D::zTexture()
 {
-    return textur;
+    return texture;
 }
 
 // Returns the model data
@@ -971,11 +971,10 @@ int Model3D::traceRay(
                     float a3
                         = (a - hit).crossProduct(b - hit).getLength() / 2 / a0;
                     Vertex ht = at * a1 + bt * a2 + ct * a3;
-                    Image* tex = textur->zPolygonTexture(index)->zImage();
+                    Image* tex = texture->zPolygonTexture(index)->zImage();
                     if (ht.x >= 0 && ht.y >= 0 && ht.x <= 1 && ht.y <= 1)
                         return tex->getPixel(
-                            (int)(ht.x * ((float)tex->getWidth() - 1.f)
-                                  + 0.5f),
+                            (int)(ht.x * ((float)tex->getWidth() - 1.f) + 0.5f),
                             (int)(ht.y * ((float)tex->getHeight() - 1.f)
                                   + 0.5f));
                     return 0xFF000000;

+ 1 - 1
Model3D.h

@@ -296,7 +296,7 @@ namespace Framework
     protected:
         Skeleton* skelett;
         Model3DData* model;
-        Model3DTexture* textur;
+        Model3DTexture* texture;
         float ambientFactor;
         float diffusFactor;
         float specularFactor;

+ 2 - 2
TextureModel.cpp

@@ -49,7 +49,7 @@ Framework::TextureModel::TextureModel(GraphicsApi* zApi, const char* uniqueName)
 
         model->calculateNormals();
     }
-    textur = new Model3DTexture();
+    texture = new Model3DTexture();
 }
 
 // Sets the texture to be displayed
@@ -57,7 +57,7 @@ Framework::TextureModel::TextureModel(GraphicsApi* zApi, const char* uniqueName)
 void TextureModel::setTexture(Texture* t)
 {
     if (!t) return;
-    this->textur->setPolygonTexture(0, t);
+    this->texture->setPolygonTexture(0, t);
     rend = 1;
 }