2016년 5월 21일 토요일

Explicit-Formulas Database
Ordinary genus-1 curves over binary fields
Short Weierstrass curves

Lopez-Dahab coordinates with a2=1 for short Weierstrass curves

An elliptic curve in short Weierstrass form [more information] has parameters a2 a6 and coordinates x y satisfying the following equations:
  y2+x*y=x3+a2*x2+a6
Lopez-Dahab coordinates with a2=1 [database entry] make the additional assumptions
  a2=1
and represent x y as X Y Z satisfying the following equations:
  x=X/Z
  y=Y/Z2

Best operation counts

Smallest multiplication counts assuming I=10M, S=0M, *param=0M, add=0M, *const=0M:
Smallest multiplication counts assuming I=10M, S=0.2M, *param=0M, add=0M, *const=0M:

Summary of all explicit formulas

OperationAssumptionsCostReaddition cost
additionZ1=1 and Z2=15M + 3S + 1*a25M + 3S + 1*a2
additionZ2=18M + 5S + 1*a28M + 5S + 1*a2
addition13M + 4S13M + 3S
doublingZ1=11M + 3S + 1*a2 + 1*a6
doublingsqrta62=a63M + 5S + 1*sqrta6
doubling3M + 5S + 1*a2 + 1*a6
doubling4M + 4S + 1*a2

Explicit formulas for addition

The "mmadd-2005-dl" addition formulas [database entrySage verification scriptSage outputthree-operand code]:
  • Assumptions: Z1=1 and Z2=1.
  • Cost: 5M + 3S + 1*a2 + 9add.
  • Cost: 5M + 3S + 1*a2 + 8add dependent upon the first point.
  • Source: 2005 Doche–Lange.
  • Explicit formulas:
          A = Y1+Y2
          B = X1+X2
          Z3 = B2
          D = X2*Z3
          X3 = A2+B*(A+Z3+a2*B)
          Y3 = (D+X3)*(A*B+Z3)+(Y2+X2)*Z32
    

The "madd-2005-dl" addition formulas [database entrySage verification scriptSage outputthree-operand code]:
  • Assumptions: Z2=1.
  • Cost: 8M + 5S + 1*a2 + 9add.
  • Cost: 8M + 5S + 1*a2 + 8add dependent upon the first point.
  • Source: 2005 Doche–Lange / Al-Daoud et al 2002.
  • Explicit formulas:
          A = Y1+Y2*Z12
          B = X1+X2*Z1
          C = B*Z1
          Z3 = C2
          D = X2*Z3
          X3 = A2+C*(A+B2+a2*C)
          Y3 = (D+X3)*(A*C+Z3)+(Y2+X2)*Z32
    

The "add-2005-dl" addition formulas [database entrySage verification scriptSage outputthree-operand code]:
  • Cost: 13M + 4S + 9add.
  • Cost: 13M + 3S + 9add dependent upon the first point.
  • Source: 2005 Doche–Lange / Higuchi Takagi.
  • Explicit formulas:
          A = X1*Z2
          B = X2*Z1
          C = A2
          D = B2
          E = A+B
          F = C+D
          G = Y1*Z22
          H = Y2*Z12
          I = G+H
          J = I*E
          Z3 = F*Z1*Z2
          X3 = A*(H+D)+B*(C+G)
          Y3 = (A*J+F*G)*F+(J+Z3)*X3
    

Explicit formulas for doubling

The "mdbl-2005-dl" doubling formulas [database entrySage verification scriptSage outputthree-operand code]:
  • Assumptions: Z1=1.
  • Cost: 1M + 3S + 1*a2 + 1*a6 + 4add.
  • Source: 2005 Doche–Lange.
  • Explicit formulas:
          C = X12
          Z3 = C
          X3 = C2+a6
          Y3 = (Y12+a2*Z3+a6)*X3+a6*Z3
    

The "dbl-2005-dl-a2-1" doubling formulas [database entrySage verification scriptSage outputthree-operand code]:
  • Assumptions: sqrta62=a6.
  • Cost: 3M + 5S + 1*sqrta6 + 4add.
  • Source: 2005 Doche–Lange, following Lopez-Dahab.
  • Explicit formulas:
          A = X12
          B = sqrta6*Z12
          C = X1*Z1
          Z3 = C2
          X3 = (A+B)2
          Y3 = (A*C+(Y1+B)*(A+B))2
    

The "dbl-2005-dl" doubling formulas [database entrySage verification scriptSage outputthree-operand code]:
  • Cost: 3M + 5S + 1*a2 + 1*a6 + 4add.
  • Source: 2005 Doche–Lange, following Lopez-Dahab 1998.
  • Explicit formulas:
          A = Z12
          B = a6*A2
          C = X12
          Z3 = A*C
          X3 = C2+B
          Y3 = (Y12+a2*Z3+B)*X3+Z3*B
    

The "dbl-2005-l" doubling formulas [database entrySage verification scriptSage outputthree-operand code]:
  • Cost: 4M + 4S + 1*a2 + 5add.
  • Source: 2005 Lange.
  • Explicit formulas:
          A = X1*Z1
          B = X12
          C = B+Y1
          D = A*C
          Z3 = A2
          X3 = C2+D+a2*Z3
          Y3 = (Z3+D)*X3+B2*Z3
    

Explicit formulas for tripling

Explicit formulas for differential addition

Explicit formulas for differential addition and doubling

Explicit formulas for scaling

2016년 5월 8일 일요일

https://computing.llnl.gov/tutorials/openMP/exercise.html

http://www.globalnerdy.com/2013/06/17/mobile-is-eating-the-world/

모바일 디바이스의 숫자가 많아짐.

2016년 5월 7일 토요일

The NDK supports all these architectures, with openmp as well since its 9th version. Use gcc (it's the compiler by default), and add -fopenmp to your NDK module's CFLAGS and LDFLAGS in yourAndroid.mk Makefile:
include $(CLEAR_VARS)
LOCAL_MODULE := yourmodule
LOCAL_SRC_FILES := yourmodule.c
LOCAL_CFLAGS += -fopenmp
LOCAL_LDFLAGS += -fopenmp
include $(BUILD_SHARED_LIBRARY)
shareimprove this answer

2016년 4월 28일 목요일

Here's an example project that follows the KennyTM's answer. You can create it from scratch or modify another project, for example, hello-jni in the NDK samples.
jni/main.c:
#include 
int main() {
    printf("hello\n");
    return 0;
}
jni/Application.mk:
#APP_ABI := all
APP_ABI := armeabi-v7a
jni/Android.mk:
LOCAL_PATH := $(call my-dir)

# first target: the hello-jni example
# it shows how to build multiple targets
# {{ you may comment it out
include $(CLEAR_VARS)

LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/lib -lmystuff # link to libmystuff.so

include $(BUILD_SHARED_LIBRARY)
#}} you may comment it out


# second target
include $(CLEAR_VARS)

LOCAL_MODULE := hello
LOCAL_SRC_FILES := main.c

include $(BUILD_EXECUTABLE)    # <-- an="" build="" executable.="" span="" this="" to="" use="">
I have to note that you will not see any logging in the stdout output, you will have to use adb logcatto see it.
So if you want logging:
jni/main.c:
#include 
#include 
int main() {
    printf("hello\n");
    __android_log_print(ANDROID_LOG_DEBUG  , "~~~~~~", "log %i", 0); // the 3rd arg is a printf-style format string
    return 0;
}
and the corresponding section in jni/Android.mk becomes:
LOCAL_PATH := $(call my-dir)

#...

include $(CLEAR_VARS)

LOCAL_MODULE := hello
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS := -llog   # no need to specify path for liblog.so

include $(BUILD_EXECUTABLE)    # <-- an="" build="" executable.="" span="" this="" to="" use="">

2016년 4월 15일 금요일

Caller/Callee Saved Registers

Visual Studio 2015
 
The registers RAX, RCX, RDX, R8, R9, R10, R11 are considered volatile and must be considered destroyed on function calls (unless otherwise safety-provable by analysis such as whole program optimization).
The registers RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15 are considered nonvolatile and must be saved and restored by a function that uses them.

2016년 3월 31일 목요일

Set Up a Debugging Session


  1. On the handheld, open the Android Wear companion app.
  2. Tap the menu on the top right and select Settings.
  3. Enable Debugging over Bluetooth. You should see a tiny status summary appear under the option:
    Host: disconnectedTarget: connected
  4. Connect the handheld to your machine over USB and run:
    adb forward tcp:4444 localabstract:/adb-hub
    adb connect localhost:4444
    Note: You can use any available port that you have access to.
In the Android Wear companion app, you should see the status change to:
Host: connectedTarget: connected

2016년 3월 9일 수요일


If you ask the C compiler to generate an assembly language listing from your source, you'll see how it handles pushing data on the stack for ARMv8. This might not be the only way to do it, but GCC does it this way:
   sub  sp, sp, #32     \\ Open up some temp stack space
   stp  x19, x20, [sp]  \\ save 2 pairs of registers
   stp  x21, x30, [sp,#16]
 
   ldp  x19, x20, [sp]  \\ restore 2 pairs of registers
   ldp  x21, x30, [sp,#16]
   add  sp, sp, #32     \\ "free" the temp stack space