void ellpack(double nzval[][(1 << 9)], short cols[][(1 << 9)], double *vec,
             double *out, int num_rows) {
#pragma HLS inline off
  for (int k = 0; k < ((128 + 4 - 1) / 4); k++) {
#pragma HLS pipeline
    out[k] = 0.0;
  }
ellpack_2:
  for (int j = 0; j < (1 << 9); j++) {
  ellpack_1:
    for (int i = 0; i < ((128 + 4 - 1) / 4); i++) {
#pragma HLS pipeline
      if (i < num_rows) {
        out[i] += nzval[i][j] * vec[cols[i][j]];
      }
    }
  }
}


x86 assembly (clang, -O0):
<ellpack>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x20,-0x28(%rbp)
jge    1147 <ellpack+0x47>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    111f <ellpack+0x1f>
jmp    114c <ellpack+0x4c>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x200,-0x2c(%rbp)
jge    11fb <ellpack+0xfb>
jmp    1165 <ellpack+0x65>
movl   $0x0,-0x30(%rbp)
cmpl   $0x20,-0x30(%rbp)
jge    11e8 <ellpack+0xe8>
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d5 <ellpack+0xd5>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
shl    $0xc,%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x30(%rbp),%rdx
shl    $0xa,%rdx
add    %rdx,%rcx
movslq -0x2c(%rbp),%rdx
movswq (%rcx,%rdx,2),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11da <ellpack+0xda>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116c <ellpack+0x6c>
jmp    11ed <ellpack+0xed>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1153 <ellpack+0x53>
pop    %rbp
ret

x86 assembly (clang, -O2):
<ellpack>:
xorpd  %xmm0,%xmm0
movupd %xmm0,0xf0(%rcx)
movupd %xmm0,0xe0(%rcx)
movupd %xmm0,0xd0(%rcx)
movupd %xmm0,0xc0(%rcx)
movupd %xmm0,0xb0(%rcx)
movupd %xmm0,0xa0(%rcx)
movupd %xmm0,0x90(%rcx)
movupd %xmm0,0x80(%rcx)
movupd %xmm0,0x70(%rcx)
movupd %xmm0,0x60(%rcx)
movupd %xmm0,0x50(%rcx)
movupd %xmm0,0x40(%rcx)
movupd %xmm0,0x30(%rcx)
movupd %xmm0,0x20(%rcx)
movupd %xmm0,0x10(%rcx)
movupd %xmm0,(%rcx)
movslq %r8d,%r9
xor    %r8d,%r8d
jmp    1195 <ellpack+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r8
add    $0x8,%rdi
add    $0x2,%rsi
cmp    $0x200,%r8
je     11d4 <ellpack+0xd4>
xor    %r10d,%r10d
xor    %r11d,%r11d
jmp    11b1 <ellpack+0xb1>
nopl   (%rax)
add    $0x1,%r11
add    $0x400,%r10
cmp    $0x20,%r11
je     1180 <ellpack+0x80>
cmp    %r9,%r11
jge    11a0 <ellpack+0xa0>
movsd  (%rdi,%r10,4),%xmm0
movswq (%rsi,%r10,1),%rax
mulsd  (%rdx,%rax,8),%xmm0
addsd  (%rcx,%r11,8),%xmm0
movsd  %xmm0,(%rcx,%r11,8)
jmp    11a0 <ellpack+0xa0>
ret

LLVM IR (-O0):
define void @ellpack([512 x double]* %0, [512 x i16]* %1, double* %2, double* %3, i32 %4) {
%6 = alloca [512 x double]*
%7 = alloca [512 x i16]*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store [512 x double]* %0, [512 x double]** %6
store [512 x i16]* %1, [512 x i16]** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %22, %5
%15 = load i32, i32* %11
%16 = icmp slt i32 %15, 32
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load double*, double** %9
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
store double 0.000000e+00, double* %21
br label %22
22: ; preds = %17
%23 = load i32, i32* %11
%24 = add nsw i32 %23, 1
store i32 %24, i32* %11
br label %14
25: ; preds = %14
br label %26
26: ; preds = %25
store i32 0, i32* %12
br label %27
27: ; preds = %71, %26
%28 = load i32, i32* %12
%29 = icmp slt i32 %28, 512
br i1 %29, label %30, label %74
30: ; preds = %27
br label %31
31: ; preds = %30
store i32 0, i32* %13
br label %32
32: ; preds = %67, %31
%33 = load i32, i32* %13
%34 = icmp slt i32 %33, 32
br i1 %34, label %35, label %70
35: ; preds = %32
%36 = load i32, i32* %13
%37 = load i32, i32* %10
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %66
39: ; preds = %35
%40 = load [512 x double]*, [512 x double]** %6
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [512 x double], [512 x double]* %40, i64 %42
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [512 x double], [512 x double]* %43, i64 0, i64 %45
%47 = load double, double* %46
%48 = load double*, double** %8
%49 = load [512 x i16]*, [512 x i16]** %7
%50 = load i32, i32* %13
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [512 x i16], [512 x i16]* %49, i64 %51
%53 = load i32, i32* %12
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [512 x i16], [512 x i16]* %52, i64 0, i64 %54
%56 = load i16, i16* %55
%57 = sext i16 %56 to i64
%58 = getelementptr inbounds double, double* %48, i64 %57
%59 = load double, double* %58
%60 = load double*, double** %9
%61 = load i32, i32* %13
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = call double @llvm.fmuladd.f64(double %47, double %59, double %64)
store double %65, double* %63
br label %66
66: ; preds = %39, %35
br label %67
67: ; preds = %66
%68 = load i32, i32* %13
%69 = add nsw i32 %68, 1
store i32 %69, i32* %13
br label %32
70: ; preds = %32
br label %71
71: ; preds = %70
%72 = load i32, i32* %12
%73 = add nsw i32 %72, 1
store i32 %73, i32* %12
br label %27
74: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @ellpack([512 x double]* nocapture %0, [512 x i16]* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4) {
%6 = bitcast double* %3 to i8*
%7 = sext i32 %4 to i64
br label %8
8: ; preds = %5, %11
%9 = phi i64 [ 0, %5 ], [ %12, %11 ]
br label %14
10: ; preds = %11
ret void
11: ; preds = %28
%12 = add nuw nsw i64 %9, 1
%13 = icmp eq i64 %12, 512
br i1 %13, label %10, label %8
14: ; preds = %8, %28
%15 = phi i64 [ 0, %8 ], [ %29, %28 ]
%16 = icmp slt i64 %15, %7
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = getelementptr inbounds [512 x double], [512 x double]* %0, i64 %15, i64 %9
%19 = load double, double* %18
%20 = getelementptr inbounds [512 x i16], [512 x i16]* %1, i64 %15, i64 %9
%21 = load i16, i16* %20
%22 = sext i16 %21 to i64
%23 = getelementptr inbounds double, double* %2, i64 %22
%24 = load double, double* %23
%25 = getelementptr inbounds double, double* %3, i64 %15
%26 = load double, double* %25
%27 = tail call double @llvm.fmuladd.f64(double %19, double %24, double %26)
store double %27, double* %25
br label %28
28: ; preds = %14, %17
%29 = add nuw nsw i64 %15, 1
%30 = icmp eq i64 %29, 32
br i1 %30, label %11, label %14
}