Browse Source

separate req_padding() from other functions

Ioannis Koutras 12 years ago
parent
commit
28714a5af8
6 changed files with 88 additions and 31 deletions
  1. 0 5
      private-include/other.h
  2. 31 0
      private-include/padding.h
  3. 1 0
      src/CMakeLists.txt
  4. 1 1
      src/freelist/malloc.c
  5. 0 25
      src/other.c
  6. 55 0
      src/padding.c

+ 0 - 5
private-include/other.h

@@ -24,13 +24,8 @@
 
 #ifndef OTHER_H
 #define OTHER_H
-#include <inttypes.h>
-
-#include "dmmlib/config.h"
 #include "dmmlib/raw_block.h"
 
 raw_block_header_t * find_raw_block_owner(struct rb_head_s head, void* ptr);
 
-size_t req_padding(size_t size);
-
 #endif /* OTHER_H */

+ 31 - 0
private-include/padding.h

@@ -0,0 +1,31 @@
+/*
+ *   Copyright Institute of Communication and Computer Systems (ICCS)
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+/**
+ * @file   padding.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   March 2013
+ * @brief  Padding for alignment
+ */
+
+#ifndef PADDING_H
+#define PADDING_H
+#include <stddef.h>
+
+size_t req_padding(size_t size);
+
+#endif /* PADDING_H */

+ 1 - 0
src/CMakeLists.txt

@@ -25,6 +25,7 @@ if (WITH_STATIC_LIB)
 endif (WITH_STATIC_LIB)
 
 set(dmmlib_SRCS
+  padding.c
   raw_block.c
   )
 

+ 1 - 1
src/freelist/malloc.c

@@ -29,7 +29,7 @@
 
 #include "dmmlib/freelist/freelist.h"
 
-#include "other.h"
+#include "padding.h"
 #include "statistics.h"
 #include "trace.h"
 

+ 0 - 25
src/other.c

@@ -25,31 +25,6 @@
 
 #include "other.h"
 
-/** Tries to align the input to 32, 64, 128, 256 or to a multiple of processor
- * word width if it is larger.
- *
- * @param size The input number.
- */
-size_t req_padding(size_t size) {
-    size_t align;
-
-    if(size <= 32)
-        return 32;
-    if(size <= 64)
-        return 64;
-    if(size <= 128)
-        return 128;
-    if(size <= 256)
-        return 256;
-
-    align = size % DMM_DATA_ALIGNMENT;
-    if(align != 0) {
-        size += (DMM_DATA_ALIGNMENT - align);
-    }
-
-    return size;
-}
-
 /** Finds the raw block owner of a certain pointer */
 raw_block_header_t * find_raw_block_owner(struct rb_head_s head, void* ptr) {
     raw_block_header_t *current_block, *owner;

+ 55 - 0
src/padding.c

@@ -0,0 +1,55 @@
+/*
+ *   Copyright Institute of Communication and Computer Systems (ICCS) 
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+/**
+ * @file   src/padding.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   March 2013
+ *
+ * @brief  Implementation of padding for alignment.
+ */
+
+#include "padding.h"
+
+#include "dmmlib/config.h"
+
+/** Tries to align the input to 32, 64, 128, 256 or to a multiple of processor
+ * word width if it is larger.
+ *
+ * @param size The input number.
+ */
+size_t req_padding(size_t size) {
+    size_t align;
+
+    if(size <= 32)
+        return 32;
+    if(size <= 64)
+        return 64;
+    if(size <= 128)
+        return 128;
+    if(size <= 256)
+        return 256;
+
+    align = size % DMM_DATA_ALIGNMENT;
+    if(align != 0) {
+        size += (DMM_DATA_ALIGNMENT - align);
+    }
+
+    return size;
+}
+
+