Skip to content
Snippets Groups Projects
Commit 7764ca63 authored by Russel Arbore's avatar Russel Arbore
Browse files

Use larger alignment for arrays

parent e73e2a97
No related branches found
No related tags found
1 merge request!184Emit align in LLVM
Pipeline #201702 failed
......@@ -507,11 +507,10 @@ impl<'a> CPUContext<'a> {
// load.
write!(
body,
" {} = load {}, ptr {}, align {}\n",
" {} = load {}, ptr {}\n",
self.get_value(id, false),
self.get_type(self_ty),
index_ptr_name,
get_type_alignment(self.types, collect_ty),
)?;
} else {
// If this read doesn't reach a primitive type, just return
......@@ -540,10 +539,9 @@ impl<'a> CPUContext<'a> {
// perform a single store of the data value.
write!(
body,
" store {}, ptr {}, align {}\n",
" store {}, ptr {}\n",
self.get_value(data, true),
index_ptr_name,
get_type_alignment(self.types, collect_ty),
)?;
} else {
// If the data item being written is not a primitive type,
......
......@@ -16,7 +16,7 @@ use std::collections::BTreeMap;
use hercules_ir::*;
pub const LARGEST_ALIGNMENT: usize = 8;
pub const LARGEST_ALIGNMENT: usize = 32;
/*
* The alignment of a type does not depend on dynamic constants.
......@@ -33,7 +33,8 @@ pub fn get_type_alignment(types: &Vec<Type>, ty: TypeID) -> usize {
.map(|id| get_type_alignment(types, *id))
.max()
.unwrap_or(1),
Type::Array(elem, _) => get_type_alignment(types, elem),
// Use a large alignment for arrays to generate better vector code.
Type::Array(_, _) => LARGEST_ALIGNMENT,
}
}
......
......@@ -13,8 +13,10 @@ use std::sync::OnceLock;
* src/rt.rs (the RT backend).
*/
pub const LARGEST_ALIGNMENT: usize = 32;
pub unsafe fn __cpu_alloc(size: usize) -> *mut u8 {
let ptr = alloc(Layout::from_size_align(size, 16).unwrap());
let ptr = alloc(Layout::from_size_align(size, LARGEST_ALIGNMENT).unwrap());
if cfg!(feature = "debug") {
eprintln!("__cpu_alloc: {:?}, {}", ptr, size);
assert!(!ptr.is_null() || size == 0);
......@@ -27,7 +29,7 @@ pub unsafe fn __cpu_dealloc(ptr: *mut u8, size: usize) {
eprintln!("__cpu_dealloc: {:?}, {}", ptr, size);
assert!(!ptr.is_null() || size == 0);
}
dealloc(ptr, Layout::from_size_align(size, 16).unwrap())
dealloc(ptr, Layout::from_size_align(size, LARGEST_ALIGNMENT).unwrap())
}
pub unsafe fn __cpu_zero_mem(ptr: *mut u8, size: usize) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment