github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/mult/mult.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mult 16 17 /* 18 #include "mo.h" 19 20 #cgo CFLAGS: -I../../../cgo 21 #cgo LDFLAGS: -L../../../cgo -lmo -lm 22 */ 23 import "C" 24 25 import ( 26 "unsafe" 27 28 "github.com/matrixorigin/matrixone/pkg/common/moerr" 29 "github.com/matrixorigin/matrixone/pkg/container/nulls" 30 "github.com/matrixorigin/matrixone/pkg/container/vector" 31 "golang.org/x/exp/constraints" 32 ) 33 34 const ( 35 LEFT_IS_SCALAR = 1 36 RIGHT_IS_SCALAR = 2 37 ) 38 39 func NumericMultSigned[T constraints.Signed](xs, ys, rs *vector.Vector) error { 40 xt, yt, rt := vector.MustTCols[T](xs), vector.MustTCols[T](ys), vector.MustTCols[T](rs) 41 flag := 0 42 if xs.IsScalar() { 43 flag |= LEFT_IS_SCALAR 44 } 45 if ys.IsScalar() { 46 flag |= RIGHT_IS_SCALAR 47 } 48 49 rc := C.SignedInt_VecMul(unsafe.Pointer(&rt[0]), unsafe.Pointer(&xt[0]), unsafe.Pointer(&yt[0]), 50 C.uint64_t(len(rt)), (*C.uint64_t)(nulls.Ptr(rs.Nsp)), C.int32_t(flag), C.int32_t(rs.Typ.TypeSize())) 51 if rc != 0 { 52 return moerr.NewOutOfRangeNoCtx("int", "int MUL") 53 } 54 return nil 55 } 56 57 func NumericMultUnsigned[T constraints.Unsigned](xs, ys, rs *vector.Vector) error { 58 xt, yt, rt := vector.MustTCols[T](xs), vector.MustTCols[T](ys), vector.MustTCols[T](rs) 59 flag := 0 60 if xs.IsScalar() { 61 flag |= LEFT_IS_SCALAR 62 } 63 if ys.IsScalar() { 64 flag |= RIGHT_IS_SCALAR 65 } 66 67 rc := C.UnsignedInt_VecMul(unsafe.Pointer(&rt[0]), unsafe.Pointer(&xt[0]), unsafe.Pointer(&yt[0]), 68 C.uint64_t(len(rt)), (*C.uint64_t)(nulls.Ptr(rs.Nsp)), C.int32_t(flag), C.int32_t(rs.Typ.TypeSize())) 69 if rc != 0 { 70 return moerr.NewOutOfRangeNoCtx("unsigned", "unsigned int MUL") 71 } 72 return nil 73 } 74 75 func NumericMultFloat[T constraints.Float](xs, ys, rs *vector.Vector) error { 76 xt, yt, rt := vector.MustTCols[T](xs), vector.MustTCols[T](ys), vector.MustTCols[T](rs) 77 flag := 0 78 if xs.IsScalar() { 79 flag |= LEFT_IS_SCALAR 80 } 81 if ys.IsScalar() { 82 flag |= RIGHT_IS_SCALAR 83 } 84 85 rc := C.Float_VecMul(unsafe.Pointer(&rt[0]), unsafe.Pointer(&xt[0]), unsafe.Pointer(&yt[0]), 86 C.uint64_t(len(rt)), (*C.uint64_t)(nulls.Ptr(rs.Nsp)), C.int32_t(flag), C.int32_t(rs.Typ.TypeSize())) 87 if rc != 0 { 88 return moerr.NewOutOfRangeNoCtx("float", "float MUL") 89 } 90 return nil 91 }