-
Notifications
You must be signed in to change notification settings - Fork 95
/
bitwiseAND.cc
88 lines (70 loc) · 2.64 KB
/
bitwiseAND.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//===- bitwisaAND.cc --------------------------------------------*- C++ -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (C) 2023, Advanced Micro Devices, Inc.
//
//===----------------------------------------------------------------------===//
#define NOCPP
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define REL_WRITE 0
#define REL_READ 1
#include <aie_api/aie.hpp>
template <typename T, int N>
void bitwiseAND_aie_scalar(const T *in1, const T *in2, T *out,
const int32_t width, const int32_t height) {
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
out[i * width + j] = in1[i * width + j] & in2[i * width + j];
}
template <typename T, int N>
void bitwiseAND_aie(const T *src1, const T *src2, T *dst, const int32_t width,
const int32_t height) {
for (int j = 0; j < width * height; j += N)
chess_prepare_for_pipelining chess_loop_range(
14, ) // loop_range(14) - loop : 1 cycle
{
::aie::vector<T, N> in1 = ::aie::load_v<N>(src1);
src1 += N;
::aie::vector<T, N> in2 = ::aie::load_v<N>(src2);
src2 += N;
::aie::vector<T, N> out;
out = ::aie::bit_and(in1, in2);
::aie::store_v(dst, out);
dst += N;
}
}
extern "C" {
#if BIT_WIDTH == 8
void bitwiseANDLine(uint8_t *in1, uint8_t *in2, uint8_t *out,
int32_t lineWidth) {
bitwiseAND_aie<uint8_t, 64>(in1, in2, out, lineWidth, 1);
}
void bitwiseANDTile(uint8_t *in1, uint8_t *in2, uint8_t *out,
int32_t tileHeight, int32_t tileWidth) {
bitwiseAND_aie<uint8_t, 64>(in1, in2, out, tileWidth, tileHeight);
}
#elif BIT_WIDTH == 16
void bitwiseANDLine(int16_t *in1, int16_t *in2, int16_t *out,
int32_t lineWidth) {
bitwiseAND_aie<int16_t, 32>(in1, in2, out, lineWidth, 1);
}
void bitwiseANDTile(int16_t *in1, int16_t *in2, int16_t *out,
int32_t tileHeight, int32_t tileWidth) {
bitwiseAND_aie<int16_t, 32>(in1, in2, out, tileWidth, tileHeight);
}
#else // 32
void bitwiseANDLine(int32_t *in1, int32_t *in2, int32_t *out,
int32_t lineWidth) {
bitwiseAND_aie<int32_t, 16>(in1, in2, out, lineWidth);
}
void bitwiseANDTile(int32_t *in1, int32_t *in2, int32_t *out,
int32_t tileHeight, int32_t tileWidth) {
bitwiseAND_aie<int32_t, 16>(in1, in2, out, tileWidth, tileHeight);
}
#endif
} // extern "C"