Factor out arch-independent ScaleFactor definition.

Bug: 65872996
Test: m test-art-host-gtest
Test: art/test.py --host -r --optimizing
Change-Id: I27763286847b45a5a3a493c3dba48418575b3eb6
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 886cabb..a096338 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -1830,4 +1830,28 @@
   UNREACHABLE();
 }
 
+ScaleFactor CodeGenerator::ScaleFactorForType(DataType::Type type) {
+  switch (type) {
+    case DataType::Type::kBool:
+    case DataType::Type::kUint8:
+    case DataType::Type::kInt8:
+      return TIMES_1;
+    case DataType::Type::kUint16:
+    case DataType::Type::kInt16:
+      return TIMES_2;
+    case DataType::Type::kInt32:
+    case DataType::Type::kUint32:
+    case DataType::Type::kFloat32:
+    case DataType::Type::kReference:
+      return TIMES_4;
+    case DataType::Type::kInt64:
+    case DataType::Type::kUint64:
+    case DataType::Type::kFloat64:
+      return TIMES_8;
+    case DataType::Type::kVoid:
+      LOG(FATAL) << "Unreachable type " << type;
+      UNREACHABLE();
+  }
+}
+
 }  // namespace art
diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h
index 338aac0..99de61d 100644
--- a/compiler/optimizing/code_generator.h
+++ b/compiler/optimizing/code_generator.h
@@ -36,6 +36,7 @@
 #include "optimizing_compiler_stats.h"
 #include "read_barrier_option.h"
 #include "stack.h"
+#include "utils/assembler.h"
 #include "utils/label.h"
 
 namespace art {
@@ -701,6 +702,7 @@
   virtual void GenerateNop() = 0;
 
   static QuickEntrypointEnum GetArrayAllocationEntrypoint(HNewArray* new_array);
+  static ScaleFactor ScaleFactorForType(DataType::Type type);
 
  protected:
   // Patch info used for recording locations of required linker patches and their targets,
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index 51444af..52852f2 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -6159,30 +6159,6 @@
   }
 }
 
-static ScaleFactor ScaleFactorForType(DataType::Type type) {
-  switch (type) {
-    case DataType::Type::kBool:
-    case DataType::Type::kUint8:
-    case DataType::Type::kInt8:
-      return TIMES_1;
-    case DataType::Type::kUint16:
-    case DataType::Type::kInt16:
-      return TIMES_2;
-    case DataType::Type::kInt32:
-    case DataType::Type::kUint32:
-    case DataType::Type::kFloat32:
-    case DataType::Type::kReference:
-      return TIMES_4;
-    case DataType::Type::kInt64:
-    case DataType::Type::kUint64:
-    case DataType::Type::kFloat64:
-      return TIMES_8;
-    case DataType::Type::kVoid:
-      LOG(FATAL) << "Unreachable type " << type;
-      UNREACHABLE();
-  }
-}
-
 void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) {
   LocationSummary* locations = instruction->GetLocations();
   Location obj_loc = locations->InAt(0);
@@ -6237,7 +6213,8 @@
     __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset));
     __ Bind(&done);
   } else {
-    Address src = CodeGeneratorX86::ArrayAddress(obj, index, ScaleFactorForType(type), data_offset);
+    ScaleFactor scale = CodeGenerator::ScaleFactorForType(type);
+    Address src = CodeGeneratorX86::ArrayAddress(obj, index, scale, data_offset);
     codegen_->LoadFromMemoryNoBarrier(type, out_loc, src, instruction);
   }
 }
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index f543dd4..8076221 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -5348,30 +5348,6 @@
   }
 }
 
-static ScaleFactor ScaleFactorForType(DataType::Type type) {
-  switch (type) {
-    case DataType::Type::kBool:
-    case DataType::Type::kUint8:
-    case DataType::Type::kInt8:
-      return TIMES_1;
-    case DataType::Type::kUint16:
-    case DataType::Type::kInt16:
-      return TIMES_2;
-    case DataType::Type::kInt32:
-    case DataType::Type::kUint32:
-    case DataType::Type::kFloat32:
-    case DataType::Type::kReference:
-      return TIMES_4;
-    case DataType::Type::kInt64:
-    case DataType::Type::kUint64:
-    case DataType::Type::kFloat64:
-      return TIMES_8;
-    case DataType::Type::kVoid:
-      LOG(FATAL) << "Unreachable type " << type;
-      UNREACHABLE();
-  }
-}
-
 void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) {
   LocationSummary* locations = instruction->GetLocations();
   Location obj_loc = locations->InAt(0);
@@ -5427,7 +5403,7 @@
       __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset));
       __ Bind(&done);
     } else {
-      ScaleFactor scale = ScaleFactorForType(type);
+      ScaleFactor scale = CodeGenerator::ScaleFactorForType(type);
       Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, scale, data_offset);
       codegen_->LoadFromMemoryNoReference(type, out_loc, src);
     }