test of wasm

update-fork
MITSUNARI Shigeo 4 years ago
parent c1bcf317a1
commit 8d64a0cfed
  1. 18
      src/fp.cpp
  2. 67
      src/low_funct.hpp

@ -3,6 +3,10 @@
#include <cybozu/sha2.hpp> #include <cybozu/sha2.hpp>
#include <cybozu/endian.hpp> #include <cybozu/endian.hpp>
#include <mcl/conversion.hpp> #include <mcl/conversion.hpp>
#if defined(__EMSCRIPTEN__) && MCL_SIZEOF_UNIT == 4
#define FOR_WASM
#include "low_funct.hpp"
#endif
#if defined(MCL_STATIC_CODE) || defined(MCL_USE_XBYAK) || (defined(MCL_USE_LLVM) && (CYBOZU_HOST == CYBOZU_HOST_INTEL)) #if defined(MCL_STATIC_CODE) || defined(MCL_USE_XBYAK) || (defined(MCL_USE_LLVM) && (CYBOZU_HOST == CYBOZU_HOST_INTEL))
@ -268,6 +272,20 @@ void setOp2(Op& op)
} else { } else {
op.fp_add = Add<N, false, Tag>::f; op.fp_add = Add<N, false, Tag>::f;
op.fp_sub = Sub<N, false, Tag>::f; op.fp_sub = Sub<N, false, Tag>::f;
#ifdef FOR_WASM
switch (N) {
case 8:
op.fp_add = mcl::addModT<8>;
op.fp_sub = mcl::subModT<8>;
break;
case 12:
op.fp_add = mcl::addModT<12>;
op.fp_sub = mcl::subModT<12>;
break;
default:
break;
}
#endif
} }
if (op.isMont) { if (op.isMont) {
if (op.isFullBit) { if (op.isFullBit) {

@ -0,0 +1,67 @@
#pragma once
/**
@file
@author MITSUNARI Shigeo(@herumi)
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#include <stdint.h>
#include <stdlib.h>
// for 32bit not full version
namespace mcl {
template<size_t N>
void copyT(uint32_t *y, const uint32_t *x)
{
for (size_t i = 0; i < N; i++) {
y[i] = x[i];
}
}
template<size_t N>
void addT(uint32_t *z, const uint32_t *x, const uint32_t *y)
{
bool c = false;
for (size_t i = 0; i < N; i++) {
uint64_t v = uint64_t(x[i]) + y[i] + c;
z[i] = uint32_t(v);
c = (v >> 32) != 0;
}
}
template<size_t N>
bool subT(uint32_t *z, const uint32_t *x, const uint32_t *y)
{
bool c = false;
for (size_t i = 0; i < N; i++) {
uint64_t v = uint64_t(x[i]) - y[i] - c;
z[i] = uint32_t(v);
c = (v >> 32) != 0;
}
return c;
}
template<size_t N>
void addModT(uint32_t *z, const uint32_t *x, const uint32_t *y, const uint32_t *p)
{
uint32_t t[N];
addT<N>(z, x, y);
bool c = subT<N>(t, z, p);
if (!c) {
copyT<N>(z, t);
}
}
template<size_t N>
void subModT(uint32_t *z, const uint32_t *x, const uint32_t *y, const uint32_t *p)
{
bool c = subT<N>(z, x, y);
if (c) {
addT<N>(z, z, p);
}
}
} // mcl
Loading…
Cancel
Save