diff --git a/examples/asm_examples/ex_aligned_data_in_code/ex_original.s b/examples/asm_examples/ex_aligned_data_in_code/ex_original.s index 65a2ddfa..dd242e55 100644 --- a/examples/asm_examples/ex_aligned_data_in_code/ex_original.s +++ b/examples/asm_examples/ex_aligned_data_in_code/ex_original.s @@ -19,7 +19,9 @@ main: lea data128.2(%rip), %rax movdqa 0(%rax), %xmm1 - # Load data into YMM register using movdqa: `data256` needs to be aligned. + # Load data into XMM and YMM using vmovapd: `data256` needs to be 32-bit + # aligned (YMM) instead of being 16-bit aligned (XMM). + vmovapd data256(%rip), %xmm0 vmovapd data256(%rip), %ymm0 # Load data into YMM register using vmovups: `data256u` does not need to be aligned. diff --git a/src/datalog/main.dl b/src/datalog/main.dl index f2446937..503a16e6 100644 --- a/src/datalog/main.dl +++ b/src/datalog/main.dl @@ -689,16 +689,14 @@ halt(EA):- instruction_get_operation(EA,Operation). /** -Information about alignment in bits for a given address +Auxiliary predicate that builds initial alignments from `alignment_required`: +the max alignment is picked for an EA later. */ -.decl alignment(EA:address,AlignInBits:unsigned) -.output alignment - -alignment(0,0):- false. +.decl alignment_candidate(EA:address,AlignInBits:unsigned) // Data in code needs to be aligned when referenced by instruction that // requires aligned memory: e.g., some SIMD instructions -alignment(DataEA, AlignInBits):- +alignment_candidate(DataEA, AlignInBits):- arch.alignment_required(EA,AlignInBits), ( pc_relative_operand(EA,_,DataEA); @@ -708,6 +706,16 @@ alignment(DataEA, AlignInBits):- DataEA >= Begin, DataEA < End. +/** +Information about alignment in bits for a given address +*/ +.decl alignment(EA:address,AlignInBits:unsigned) +.output alignment + +alignment(DataEA, AlignInBits):- + alignment_candidate(DataEA, AlignInBits), + AlignInBits = max X: {alignment_candidate(DataEA, X)}. + ////////////////////////////////////////////////////////////////////////////////// // Operations to abstract features of instructions