#!/bin/sh set -ex trap 'rm o' 0 cflags=$(pkg-config --cflags --libs libhwy) c++ -x c++ - -o o -static-libasan -fsanitize=address -Wall -Wextra -Wpedantic $cflags < #include #include #include #include namespace hn = hwy::HWY_NAMESPACE; using T = int; void MulAddLoop(const T* HWY_RESTRICT mul_array, const T* HWY_RESTRICT add_array, const size_t size, T* HWY_RESTRICT x_array) { const hn::ScalableTag d; for (size_t i = 0; i < size; i += hn::Lanes(d)) { const auto mul = hn::Load(d, mul_array + i); const auto add = hn::Load(d, add_array + i); auto x = hn::Load(d, x_array + i); x = hn::MulAdd(mul, x, add); hn::Store(x, d, x_array + i); } } int main(){ /* Initialize arrays with random small integers. */ srand(time(NULL)); const hn::ScalableTag d; size_t size = hn::Lanes(d)*3; T *a = (T*)malloc(size*sizeof(T)); T *b = (T*)malloc(size*sizeof(T)); T *c = (T*)malloc(size*sizeof(T)); T *c_orig = (T*)malloc(size*sizeof(T)); for(size_t i=0; i