Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include<math.h>
- #include <smmintrin.h>
- float dot_product(const float *A, const float *B, int startA, int endA, int startB, int endB){
- float f[4];
- f[0] = 0.0;
- f[1] = 0.0;
- f[2] = 0.0;
- f[3] = 0.0;
- int i = 5;
- __m128 result = _mm_loadu_ps (f);
- float res = 0;
- while(startA + 3 < endA) {
- __m128 value1 = _mm_loadu_ps (A+startA);
- __m128 value2 = _mm_loadu_ps (B+startB);
- __m128 val = _mm_dp_ps(value1, value2, 0xF1);
- result = _mm_add_ss(result, val);
- startA +=4;
- startB +=4;
- }
- printf("%d\n", i);
- _mm_storeu_ps (&res, result);
- printf("%d\n", i);
- while (startA < endA) {
- // printf("%d %d %d\n", i, t, endA);
- // printf("%f %f\n", A[i], B[t]);
- res += A[startA]*B[startB];
- ++startA;
- ++startB;
- }
- return res;
- }
- void multiply(float*A, float*B, float*res, int N, int M) {
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < N; j++) {
- double value = dot_product(A, B, i*M, (i+1)*M, j*M, (j+1)*M);
- res[i*N+j] = value;
- }
- }
- }
- void Print(float* res, int N, int M) {
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++) {
- printf("%.4f ", res[i*M + j]);
- }
- printf("\n");
- }
- }
- int main() {
- int N, M;
- // scanf("%d %d", &N, &M); //N -количество строк, M - количество столбцов
- for(N = 7; N < 10; ++N) {
- for(M = 1; M < 10; M++) {
- printf("%d %d\n", N, M);
- //float *A = (float*) calloc(N*M, 4); // }
- //float *B = (float*)calloc(N*M, 4);
- //float *res = (float*) calloc(N*M, 4);
- float A[M*N], B[N*M], res[N*M];
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++) {
- A[i*M+j] = i;//scanf("%f", &A[i*M + j]);
- }
- }
- for (int i = 0; i < M; i++) {
- for (int j = 0; j < N; j++) {
- B[j*M + i] = j;// scanf("%f", &B[j*M + i]);
- }
- }
- multiply(A, B,res, N, M);
- //Print(res, N, N);
- //free(A);
- //free(B);
- //free(res);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment